EmbeddedRelated.com
Forums

TimerA - Capture mode code error...

Started by Gustavo Lima August 6, 2009
Hi,

I'm using the ez430RF2500 (MSP430 2274 + ZigBee module) and I need to
measure the time interval between input pulse signals (0V to 3.6V) . 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
}

Beginning Microcontrollers with the MSP430

P2.3 interrupt, Capture on both rising and falling edges
every timer interrupt, timer_count+1;
P2.3 interrupt P2.3 interrupt
P2.3 interrupt P2.3 interrupt
|-----------| |--------------|
______________| |________________| |________
Timer begin | | |
Timer_count=0 Timer_count=0 | ....
| |
T=timer_cout T=timer_count
output T output T

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

2009/8/9 chenli1976

> P2.3 interrupt, Capture on both rising and falling edges
> every timer interrupt, timer_count+1;
>
> P2.3 interrupt P2.3 interrupt
> P2.3 interrupt P2.3 interrupt
> |-----------| |--------------|
> ______________| |________________| |________
> Timer begin | | |
> Timer_count=0 Timer_count=0 | ....
> | |
> T=timer_cout T=timer_count
> output T output T
>