This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS/RF430FRL152H: Frequency detection using Timer CC

Part Number: RF430FRL152H


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;
  }
}

  • Hello Giuliano,

    We've not used the timer for such an application. It is based on MSP430 timer module, so I would recommend reviewing documentation for MSP430. I have doubts you'd be able to do a lot with it though, the device isn't meant to be used a general purpose MCU but rather intended to talk with sensors. Basically peripherals like timers are more for managing the application flow, not measurement of signals. That said if the signal you are measuring is not too fast and fairly simple like a square wave, then I could see it working.

    All that said, this isn't really an application of our device that we are looking to support, so looking into MSP430 documentation would be your best path forward.
  • Hallo Ralph,

    That's right, the signals I have to measure are square wave and frequency between 1-20kHz. So is it possible?!
    In the meantime I'm already looking at how to do it with the MSP430, in fact I'm taking hints from that.

    Thank you so much for your help.

    Best.
    Giuliano