Other Parts Discussed in Thread: SIMPLICITI
I'm using an MSP430 F2274 on the RF2500 kit, and I'd like to be able to measure the frequency/speed of an external signal, like that from a function/signal generator. The resources on this forum and elsewhere indicated that the best way to do this was by using a Timer's capture function, and so I have written a rough draft of code (given below) to do so:
double freq[2];
int i = 0;
__interrupt void Timer_A (void);
void main (void)
{
P2SEL |= 0x08; // P2.3 (Ext. pin 6) set as TACCI1B
P2DIR &= ~0x08; // P2.3 set as input
BCSCTL1 = CALBC1_1MHZ; // Set SMCLK to 1 MHz
DCOCTL = CALDCO_1MHZ;
TACCTL0 |= CM1 + CCIS1 + CAP + SCS + CCIE;
// Rising Edge, Input 1, Capture, Synchronize, IE
TACTL |= TASSEL_2 + MC_2; // SMCLK, Continuous Mode
// Whenever input signal hits rising edge, timer value is copied into TACCR0
// and interrupt flag is set.
_BIS_SR(LPM0_bits + GIE);
}
/*-------------------------------------------
* Timer A interrupt service routine
*-----------------------------------------*/
#pragma vector = TimerA0_VECTOR
__interrupt void Timer_A (void)
{
// Flag cleared automatically
freq[i++] = TACCR0;
if (i == 2)
{
i = 0;
TACCTL0 &= ~CCIE;
LPM0_EXIT;
}
}
My intention would be to take two (or 3 or 4) consecutive rising edge mesaurements of the input signal, and then do some calculations (not shown in the code yet) to find the frequency/speed of that signal. However, as far as I can tell, the above code will be constantly checking the input signal for rising edges, and will therefore be constantly getting the next Timestamp, which I do not want to do. My question is: How can I modify/add to the code above so that it stays in LPM0 for, say, 0.5 seconds, then wakes up to take the timestamp of 2 or 3 or 4 consecutive rising edge measurements and calculate the frequency, and then goes back into LPM0 for another 0.5 s, and so on?