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.

Help with the frequency measurement of the ADC read signal

Other Parts Discussed in Thread: CC430F5137

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.

  • To measure the frequency spectrum of an analog signal, you could digitize it at a sampling rate at lease twice (preferably mush faster than twice) the highest frequency of the signal. And then you need to perform a Fourier Transformation. You cannot use the Timer to measure the frequencies of an analog signal.

  • Sorry, for not explaining it clearly. I want to calculate the frequency of the digital waveform (signal) which was converted from analog signal into pulse signal (of 0’s and 1’s) depending on some threshold.

    The ADC sample value obtained will be changed to 0 or 1 depending on the threshold

    (if ADC_sample_value>threshold

          Pulse_signal_value=1

     else

        Pulse_signal_value=0)

    Now I want to calculate the frequency of this resultant pulse signal which is a digitized version of the original ADC sampled signal.

    thanks.

  • Maybe you think you need to digitize analog signal to measure it's frequency. Most frequency meters does not digitize, just use AC-coupled comparator on input

  • Sorry, I am not digitizing the ADC read signal for the specific reason of frequency measurement but my analog pulse signal consists of pulse signals of different amplitudes but I want to eliminate(supress) the pulse signals that are less than threshold amplitude and want to allow the pulse signals greater than this threshold amplitude. In this process of removing lesser amplitude pulse signals will digitize the resultant thus resulting in a digital pulse signal.

    Finally, I want to calculate the frequency of this resultant pulse signal.

  • Did you consider changing your plans to project you have better chances to finish?

  • From the starting I was planning to measure the frequency of a pulse signal but then there were some issues with the hardware board I got. The main idea was to measure frequency of the sensor signal read by the ADC channel.

    So, I have to measure the frequency of the resultant pulse signal of the sensor.

    I think that you are not willing to help me in solving this.

  • Govardhan Reddy Patancheru said:
    I think that you are not willing to help me in solving this.

    This is the part you understood surprisingly well :) I am willing to do something only when I am interested in subject or progress of apprentice.

    Hopefully somebody else will have enough patience here.

**Attention** This is a public forum