Sign in

username:

password:



Not a member?

Search msp430



Search tips

Subscribe to msp430



Ads

Discussion Groups

See Also

DSPFPGAElectronics

Discussion Groups | MSP430 | Timer in capture mode... code error


Advertise Here

The purpose of this group is to foster exchange of information on the Texas Instruments MSP430 family of microcontrollers and related tools. Everyone welcome, all levels of familiarity/expertise.

Timer in capture mode... code error - Gustavo Lima - Aug 6 21:48:38 2009

Hi,

I'm using the ez430RF2500 (MSP430 2274 + ZigBee module) and I need to
measure the time interval between input pulse signals. I
tried to implement a timer interrupt in capture mode but it don't
works. Someone can help-me? (my code with comments of the
configurations used is following)

Thanks
Gustavo

#include "msp430x22x4.h"
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer

//LED CONFIGURATION
P1DIR |= BIT0+BIT1; // Set P1.0 & P1.1 to
output direction
P1OUT = BIT0+BIT1; // Led on

//SIGNAL PORT
P2DIR = 0xF7; //P2.3 -> input
P2SEL = 0x08; //Select TA1

/*
5 pin - P2.2 / TA0 / Timer_A, capture: CCI0B input
6 pin - P2.3 / TA1 / Timer_A, capture: CCI1B input
8 pin - P4.3 / TB0 / Timer_B, capture: CCI0B input
9 pin - P4.4 / TB1 / Timer_B, capture: CCI1B input
*/

TACCTL1 = CM_3 + SCS + CCIS_1 + CAP + CCIE;

/*
CMx Bit - Capture mode
00 No capture
01 Capture on rising edge
10 Capture on falling edge
11 Capture on both rising and falling edges

SCS Bit 11 Synchronize capture source.
0 Asynchronous capture
1 Synchronous capture

CCISx Bit - Capture/compare input select.
00 CCIxA
01 CCIxB
10 GND
11 Vcc

CAP Bit - Capture mode
0 Compare mode
1 Capture mode

CCIE - Capture/compare interrupt enable.
0 Interrupt disabled
1 Interrupt enabled
*/

TACTL = TASSEL_2 + MC_1;

/*
TASSELx Bits - Timer_A clock source select
00 TACLK
01 ACLK
10 SMCLK
11 INCLK

MCx Bits - Mode control.
00 Stop mode: the timer is halted.
01 Up mode: the timer counts up to TACCR0.
10 Continuous mode: the timer counts up to 0FFFFh.
11 Up/down mode: the timer counts up to TACCR0 then down to 0000h.
*/

__bis_SR_register(GIE); // Wait interrupt
}

// Timer A0 interrupt service routine
#pragma vector=TIMERA1_VECTOR
__interrupt void Timer_A (void)
{
P1OUT ^= BIT0; //Toggle LED
}
------------------------------------

______________________________
Stellaris® MCU Family: New Parts, New Package, New Price.


(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )


Re: Timer in capture mode... code error - old_cow_yellow - Aug 6 23:04:26 2009

I did not check the details. But I noticed at least one mistake.

After you enabled interrupts, your main() ended right away. You should wait at least a while to let the interrupts happen. Usually, people put an endless loop there.

--- In m...@yahoogroups.com, Gustavo Lima wrote:
>
> Hi,
>
> I'm using the ez430RF2500 (MSP430 2274 + ZigBee module) and I need to
> measure the time interval between input pulse signals. I
> tried to implement a timer interrupt in capture mode but it don't
> works. Someone can help-me? (my code with comments of the
> configurations used is following)
>
> Thanks
> Gustavo
>
> #include "msp430x22x4.h"
> void main(void)
> {
> WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
>
> //LED CONFIGURATION
> P1DIR |= BIT0+BIT1; // Set P1.0 & P1.1 to
> output direction
> P1OUT = BIT0+BIT1; // Led on
>
> //SIGNAL PORT
> P2DIR = 0xF7; //P2.3 -> input
> P2SEL = 0x08; //Select TA1
>
> /*
> 5 pin - P2.2 / TA0 / Timer_A, capture: CCI0B input
> 6 pin - P2.3 / TA1 / Timer_A, capture: CCI1B input
> 8 pin - P4.3 / TB0 / Timer_B, capture: CCI0B input
> 9 pin - P4.4 / TB1 / Timer_B, capture: CCI1B input
> */
>
> TACCTL1 = CM_3 + SCS + CCIS_1 + CAP + CCIE;
>
> /*
> CMx Bit - Capture mode
> 00 No capture
> 01 Capture on rising edge
> 10 Capture on falling edge
> 11 Capture on both rising and falling edges
>
> SCS Bit 11 Synchronize capture source.
> 0 Asynchronous capture
> 1 Synchronous capture
>
> CCISx Bit - Capture/compare input select.
> 00 CCIxA
> 01 CCIxB
> 10 GND
> 11 Vcc
>
> CAP Bit - Capture mode
> 0 Compare mode
> 1 Capture mode
>
> CCIE - Capture/compare interrupt enable.
> 0 Interrupt disabled
> 1 Interrupt enabled
> */
>
> TACTL = TASSEL_2 + MC_1;
>
> /*
> TASSELx Bits - Timer_A clock source select
> 00 TACLK
> 01 ACLK
> 10 SMCLK
> 11 INCLK
>
> MCx Bits - Mode control.
> 00 Stop mode: the timer is halted.
> 01 Up mode: the timer counts up to TACCR0.
> 10 Continuous mode: the timer counts up to 0FFFFh.
> 11 Up/down mode: the timer counts up to TACCR0 then down to 0000h.
> */
>
> __bis_SR_register(GIE); // Wait interrupt
> }
>
> // Timer A0 interrupt service routine
> #pragma vector=TIMERA1_VECTOR
> __interrupt void Timer_A (void)
> {
> P1OUT ^= BIT0; //Toggle LED
> }
>
------------------------------------



(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )

Re: Timer in capture mode... code error - tintronic - Aug 7 11:44:29 2009

You're also not clearing the TA1 interrupt flag, so your program will stay in a loop executing Timer_A() once the first interrupt occurs. Your P1.0 LED will toggle so fast you will see as if it was constantly on. Take an osciloscope and watch the P1.0 signal.
Many of your comments are wrong, which difficults understanding and debugging your program.

Regards,
Michael K.

--- In m...@yahoogroups.com, "old_cow_yellow" wrote:
>
> I did not check the details. But I noticed at least one mistake.
>
> After you enabled interrupts, your main() ended right away. You should wait at least a while to let the interrupts happen. Usually, people put an endless loop there.
>
> --- In m...@yahoogroups.com, Gustavo Lima wrote:
> >
> > Hi,
> >
> > I'm using the ez430RF2500 (MSP430 2274 + ZigBee module) and I need to
> > measure the time interval between input pulse signals. I
> > tried to implement a timer interrupt in capture mode but it don't
> > works. Someone can help-me? (my code with comments of the
> > configurations used is following)
> >
> > Thanks
> > Gustavo
> >
> > #include "msp430x22x4.h"
> > void main(void)
> > {
> > WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
> >
> > //LED CONFIGURATION
> > P1DIR |= BIT0+BIT1; // Set P1.0 & P1.1 to
> > output direction
> > P1OUT = BIT0+BIT1; // Led on
> >
> > //SIGNAL PORT
> > P2DIR = 0xF7; //P2.3 -> input
> > P2SEL = 0x08; //Select TA1
> >
> > /*
> > 5 pin - P2.2 / TA0 / Timer_A, capture: CCI0B input
> > 6 pin - P2.3 / TA1 / Timer_A, capture: CCI1B input
> > 8 pin - P4.3 / TB0 / Timer_B, capture: CCI0B input
> > 9 pin - P4.4 / TB1 / Timer_B, capture: CCI1B input
> > */
> >
> > TACCTL1 = CM_3 + SCS + CCIS_1 + CAP + CCIE;
> >
> > /*
> > CMx Bit - Capture mode
> > 00 No capture
> > 01 Capture on rising edge
> > 10 Capture on falling edge
> > 11 Capture on both rising and falling edges
> >
> > SCS Bit 11 Synchronize capture source.
> > 0 Asynchronous capture
> > 1 Synchronous capture
> >
> > CCISx Bit - Capture/compare input select.
> > 00 CCIxA
> > 01 CCIxB
> > 10 GND
> > 11 Vcc
> >
> > CAP Bit - Capture mode
> > 0 Compare mode
> > 1 Capture mode
> >
> > CCIE - Capture/compare interrupt enable.
> > 0 Interrupt disabled
> > 1 Interrupt enabled
> > */
> >
> > TACTL = TASSEL_2 + MC_1;
> >
> > /*
> > TASSELx Bits - Timer_A clock source select
> > 00 TACLK
> > 01 ACLK
> > 10 SMCLK
> > 11 INCLK
> >
> > MCx Bits - Mode control.
> > 00 Stop mode: the timer is halted.
> > 01 Up mode: the timer counts up to TACCR0.
> > 10 Continuous mode: the timer counts up to 0FFFFh.
> > 11 Up/down mode: the timer counts up to TACCR0 then down to 0000h.
> > */
> >
> > __bis_SR_register(GIE); // Wait interrupt
> > }
> >
> > // Timer A0 interrupt service routine
> > #pragma vector=TIMERA1_VECTOR
> > __interrupt void Timer_A (void)
> > {
> > P1OUT ^= BIT0; //Toggle LED
> > }
>

------------------------------------

______________________________
Stellaris® MCU Family: New Parts, New Package, New Price.


(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )

Re: Re: Timer in capture mode... code error - Gustavo Lima - Aug 11 8:24:52 2009

Now my code is working... thanks for the help!

2009/8/7 tintronic

> You're also not clearing the TA1 interrupt flag, so your program will stay
> in a loop executing Timer_A() once the first interrupt occurs. Your P1.0 LED
> will toggle so fast you will see as if it was constantly on. Take an
> osciloscope and watch the P1.0 signal.
> Many of your comments are wrong, which difficults understanding and
> debugging your program.
>
> Regards,
> Michael K.
> --- In m...@yahoogroups.com , "old_cow_yellow"
> wrote:
> >
> > I did not check the details. But I noticed at least one mistake.
> >
> > After you enabled interrupts, your main() ended right away. You should
> wait at least a while to let the interrupts happen. Usually, people put an
> endless loop there.
> >
> > --- In m...@yahoogroups.com , Gustavo Lima <
> gustavolima.bh@> wrote:
> > >
> > > Hi,
> > >
> > > I'm using the ez430RF2500 (MSP430 2274 + ZigBee module) and I need to
> > > measure the time interval between input pulse signals. I
> > > tried to implement a timer interrupt in capture mode but it don't
> > > works. Someone can help-me? (my code with comments of the
> > > configurations used is following)
> > >
> > > Thanks
> > > Gustavo
> > >
> > > #include "msp430x22x4.h"
> > > void main(void)
> > > {
> > > WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
> > >
> > > //LED CONFIGURATION
> > > P1DIR |= BIT0+BIT1; // Set P1.0 & P1.1 to
> > > output direction
> > > P1OUT = BIT0+BIT1; // Led on
> > >
> > > //SIGNAL PORT
> > > P2DIR = 0xF7; //P2.3 -> input
> > > P2SEL = 0x08; //Select TA1
> > >
> > > /*
> > > 5 pin - P2.2 / TA0 / Timer_A, capture: CCI0B input
> > > 6 pin - P2.3 / TA1 / Timer_A, capture: CCI1B input
> > > 8 pin - P4.3 / TB0 / Timer_B, capture: CCI0B input
> > > 9 pin - P4.4 / TB1 / Timer_B, capture: CCI1B input
> > > */
> > >
> > > TACCTL1 = CM_3 + SCS + CCIS_1 + CAP + CCIE;
> > >
> > > /*
> > > CMx Bit - Capture mode
> > > 00 No capture
> > > 01 Capture on rising edge
> > > 10 Capture on falling edge
> > > 11 Capture on both rising and falling edges
> > >
> > > SCS Bit 11 Synchronize capture source.
> > > 0 Asynchronous capture
> > > 1 Synchronous capture
> > >
> > > CCISx Bit - Capture/compare input select.
> > > 00 CCIxA
> > > 01 CCIxB
> > > 10 GND
> > > 11 Vcc
> > >
> > > CAP Bit - Capture mode
> > > 0 Compare mode
> > > 1 Capture mode
> > >
> > > CCIE - Capture/compare interrupt enable.
> > > 0 Interrupt disabled
> > > 1 Interrupt enabled
> > > */
> > >
> > > TACTL = TASSEL_2 + MC_1;
> > >
> > > /*
> > > TASSELx Bits - Timer_A clock source select
> > > 00 TACLK
> > > 01 ACLK
> > > 10 SMCLK
> > > 11 INCLK
> > >
> > > MCx Bits - Mode control.
> > > 00 Stop mode: the timer is halted.
> > > 01 Up mode: the timer counts up to TACCR0.
> > > 10 Continuous mode: the timer counts up to 0FFFFh.
> > > 11 Up/down mode: the timer counts up to TACCR0 then down to 0000h.
> > > */
> > >
> > > __bis_SR_register(GIE); // Wait interrupt
> > > }
> > >
> > > // Timer A0 interrupt service routine
> > > #pragma vector=TIMERA1_VECTOR
> > > __interrupt void Timer_A (void)
> > > {
> > > P1OUT ^= BIT0; //Toggle LED
> > > }
> > >
> >
>
[Non-text portions of this message have been removed]

------------------------------------

______________________________
Stellaris® MCU Family: New Parts, New Package, New Price.


(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )