Hello,
can someone suggest the corrections needed in the below frequency measurement code if I want to measure the frequency of the signal read by ADC.I am uisng cc430f5137 with CCS.
#include <msp430.h>
volatile int ccr_current=0,ccr_previous=0,y=0,freq1[3],freq=0,freq_needed=0;
//Timer Interrupt
#pragma vector=TIMER0_A0_VECTOR
__interrupt void TIMER0_A0_ISR(void)
{
//__bic_SR_register_on_exit(CPUOFF);//wakes up CPU from OFF
}
#pragma vector=TIMER0_A1_VECTOR
__interrupt void TIMER0_A1_ISR(void)
{
unsigned int ccr_current;
ccr_current = TA0CCR1;
if(ccr_current < ccr_previous) {
freq = 32768 / (ccr_current + 65536 - ccr_previous);
} else {
freq = 32768 / (ccr_current - ccr_previous);
}
ccr_previous = ccr_current;
y=y+1;
freq1[y]=freq;
//__bic_SR_register_on_exit(CPUOFF);//wakes up CPU from OFF
}
int main(void)
{
WDTCTL = WDTPW | WDTHOLD;
//TA0CCR0: Reference clock
TA0CTL = TASSEL_1;
TA0CCTL0 = CCIE; // interrupt enabled
TA0CCR0=32768;
TA0CTL |= MC_1;// set timer in up mode
TA0CTL |= MC0; // start timer
//TA0CCR1: It will read the input pulse signal
P3SEL |= BIT2; //it is connected to TA0CCR1A
TA0CCTL1|=CAP; //for capture mode
TA0CCTL1|=CM_1; //capture on rising edge
while(1)
{
if(y==2) //calculate freq if two rising edges were captured
{
freq_needed=freq1[1]+freq1[2];
//transmit freq_needed through UART to the terminal
y=0;
}
__bis_SR_register(CPUOFF + GIE);//makes CPU OFF and enables interrupts
}
}
thankyou.