Tool/software: Code Composer Studio
Hallo Everyone,
My goal is to read/detect the frequency of an external source via the RF430frl152h microcontroller.
I've found a code that use timer(Capture Compare) to find out what's the value of the period of my external signal.
Unfortunately, it doesn't work(value of period always 0, it seems the timer is not working..I checked and I'm always in the "default case".). I don't understand if I've done some mistakes in configuration or where else..
If anyone knows how to figure out the problem or had any other options, please tell me.
Best Regards.
Giuliano
// RF430frl152h
// -----------------
// /|\| |
// | | |
// --|RST |
// | |
// | P1.0/TA0.1|<-- CCI1A <-(external frequency source to measure via capture compare timer)
// | |
// | |
// | |
#include <msp430.h>
#include <rf430frl152h.h>
unsigned int Count;
unsigned int REdge1, REdge2;
unsigned int Period;
int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
// Configure Port Pins
P1DIR &= ~BIT0; // P1.0/TA0.1 Input Capture
P1SEL0 |= BIT0; // TA0.1 option select
P1SEL1 |= BIT0; // TA0.1 option select
// Configure the TA0CCR1 to do input capture
TA0CCTL1 = CAP + CM_1 + CCIE + SCS + CCIS_0;
// TA0CCR1 Capture mode; CCI1A; Both
// Rising and Falling Edge; interrupt enable
TA0CTL |= TASSEL_2 + MC_2 + TACLR + TAIE; // SMCLK, Cont Mode; start timer
// Variable Initialization
Count = 0;
while(1)
{
__bis_SR_register(LPM0_bits + GIE); // Enter LPM0
__no_operation(); // For debugger
// On exiting LPM0
if (TA0CCTL1 & COV) // Check for Capture Overflow
while(1); // Loop Forever
Period = REdge2 - REdge1; // Calculate Period
}
}
// TA0_A1 Interrupt vector
#pragma vector = TIMER0_A1_VECTOR
__interrupt void TIMER0_A1_ISR (void){
switch(__even_in_range(TA0IV,0x0A))
{
case TA0IV_TACCR1: // Vector 2: TACCR1 CCIFG
if (TA0CCTL1 & CCI){ // Capture Input Pin Status
if (!Count){ // Rising Edge was captured
REdge1 = TA0CCR1;
Count++;
}
else{
REdge2 = TA0CCR1;
Count=0;
__bic_SR_register_on_exit(LPM0_bits + GIE); // Exit LPM0 on return to main
}
}
else{}
break;
case TA0IV_TACCR2: break; // Vector 4: TACCR2 CCIFG
default: break;
}
}