Other Parts Discussed in Thread: MSP430G2231
i m trying to make the timer a work in capture mode on both rising and falling edge
i use the following code to implement it.....i am generating a wave at port p1.4 and connect it to pin p1.1 which is capture input to timer. i am glowing the red led at the rising edge to indicate start of the capture..then i switch off red and glow green led to incate falling edge then i am glowing red if the CCIFG flag is set...but oly red is glowing all the time
is this logic correct ???
please help me..iam using MSP430G2231 launchpad.i am new to launch pad.
code:
#include <msp430g2231.h>
void main (void)
{
WDTCTL = WDTPW + WDTHOLD; // stop watchdog timer
P1SEL = BIT1; // take capture input at p1.1
TACTL = TASSEL_2 + MC_2; // SMCLK , mode=2
TACTL = TACLR;
P1DIR = 0x51; //set p1.0,p1.4,p1.6 as output port
P1OUT = 0x00; // all off initially
TACCTL0 = CM_3 + SCS + CCIS_0 + CAP + CCIE; // setup the timer in capture mode
P1OUT = 0x01; //glow red led
volatile int j;
while( j < 50000) // wait for some random time
{
j ++;
}
P1OUT = 0x10; //make p1.4 high
//if(BIT4)
//{
// if(j == 50000)
// {
P1OUT = 0x40;
// }
//}
volatile int i=0;
while(i<50000) //wait for random time
{
i++;
}
P1OUT ^= 0x10; //toggle p1.4
_BIS_SR(GIE); // enable interrupt
}
#pragma vector=TIMERA0_VECTOR
__interrupt void TIMERA(void)
{
TACCTL0&=~COV; // clear overflow flag
TACCTL0 &= ~CCIFG; // clear CCIFG flag
if(CCIFG)
{
P1OUT = 0x01; // if capture done glow red led
}
}