Hi all,
I am a newbie to MSP430. The controller I am using is MSP430 2252.
Currently I am trying to measure input frequency of the range 40 - 70 Hz at pin 1.2 (Timer A1).
The problem is even though I vary the frequency from 40 till 70 Hz, I always end up getting values of approx 19900 in the buffer[] array.
I am using the following code from one of the forum post.
#include <msp430x22x2.h>
#define CLRBIT(dest,mask) ((dest) &= ~(mask))
#define CLEAR_INTERRUPT_FLAG() (CLRBIT(TACCTL1,CCIFG))
unsigned int buffer[100];
unsigned int i=0;
unsigned int Current_Edge_Time;
unsigned int Previous_Edge_Time;
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
BCSCTL1 = CALBC1_1MHZ; // Set DCO to 1MHz
DCOCTL = CALDCO_1MHZ;
P1DIR &= ~BIT2; //Port 1.2 - Input
P1SEL |= BIT2;
TACTL = TASSEL_2 + MC_2; // SMCLK = 1 Mhz, continuous mode
TACCTL1 = CM_1+CCIS_0+SCS+CAP+CCIE;
_BIS_SR(GIE);
}
// Timer A1 interrupt service routine
#pragma vector=TIMERA1_VECTOR
__interrupt void Timer_A (void)
{
Current_Edge_Time = TACCR1;
if(Current_Edge_Time < Previous_Edge_Time)
{
buffer[i++] = ((0xFFFF - Previous_Edge_Time) + Current_Edge_Time);
}
else
{
buffer[i++] = Current_Edge_Time - Previous_Edge_Time;
}
Previous_Edge_Time = Current_Edge_Time;
if (i>100)
__no_operation(); // PLACE BREAKPOINT HERE
CLEAR_INTERRUPT_FLAG();
}
Could somebody please help me out and let me know if I am doing anything wrong.