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.

measure frequency deviation of analog input using TM4C123GH6PM kit

Other Parts Discussed in Thread: TM4C123GH6PM

How  can frequency deviation (normally 50Hz, deviation means <50Hz) of an analog signal can be measured with timers and counters?

  • Measure zero-crossings distance with timers, or calculate the spectrum (FFT), and find the centre frequency.

  • Hi,

    Make the signal digital and measure the period with timer set for capture timer. Apply the signal to the capture pin.

    What micro do you use?

    Petrei

  • I have an idea to measure frequency by counting number of positive edges of input for 1sec. But I have a doubt that, is it possible to count number of positive edges of analog input signal?.

  • Hello M.Mary,

    Analog signals may move up and down multiple times, causing the edge detection circuit to see a high frequency instead of a low frequency signal. The TM4C GPIO has hysteresis guard band, but if the same is not more than the noise immunity you want, then an external Schmitt Trigger would need to be done that can process the Analog signal to clean it up for TM4C.

    Regards

    Amit

  • Feed your anaolg input signal to a window discriminator (with the limits set close to the zero crossings values), and you get an impulse for each zero crossing. Count the time from impulse to impulse. Average over several mains cycles, since EMI effects will introduce some noise (i.e. jitter).

  • I am supposed to only use the micro controller(TM4C123GH6PM) to measure frequency of analog input for my application. Here is my code to detect frequency deviation.

    int i=1;
    int y;



    int main(void)
    {
        SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);

        volatile uint32_t ui32Z;

        TimerConfigure(TIMER0_BASE,     TIMER_CFG_B_CAP_COUNT);
        TimerConfigure(TIMER0_BASE,TIMER_CFG_A_PERIODIC);
        
        TimerEnable(TIMER0_BASE, TIMER_B);
        TimerEnable(TIMER_CFG_A_PERIODIC,    TIMER_A);  

            //GPIODirModeSet(GPIO_PORTF_BASE, GPIO_PIN_1, GPIO_DIR_MODE_IN);
            GPIOPadConfigSet(GPIO_PORTB_BASE,GPIO_PIN_5,GPIO_STRENGTH_8MA,GPIO_PIN_TYPE_STD);
            GPIOPinTypeADC(GPIO_PORTB_BASE, GPIO_PIN_5);
            GPIOPinConfigure(0x40005020);
            GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_5);

        TimerControlEvent(TIMER0_BASE, TIMER_B, TIMER_EVENT_POS_EDGE);
       
        TimerMatchSet(TIMER_CFG_B_CAP_COUNT_UP,TIMER_B,50);
        TimerIntEnable(TIMER_CFG_B_CAP_COUNT_UP,TIMER_CAPB_MATCH);
     
          while (1)

        {
        TimerLoadSet(TIMER_CFG_B_CAP_COUNT,TIMER_B,1);
        TimerLoadSet(TIMER_CFG_A_PERIODIC,TIMER_A,0);
        SysCtlDelay(2000000);
        ui32Z=TimerLoadGet(TIMER_CFG_B_CAP_COUNT,TIMER_B);

        TimerControlTrigger(TIMER0_BASE,    TIMER_A,    0xFFFFFFFF);

        ui32Z= TimerValueGet(TIMER_CFG_A_PERIODIC,TIMER_A);
        ui32Y= TimerValueGet(TIMER_CFG_B_CAP_COUNT,TIMER_B);

        if(ui32Z&&ui32Y)    ui32Dev=0;
        else ui32Dev=1;
    }
    }

    But that runs infinitely. And i don't know that, this code is right or wrong. If you correct the code to measure number of pulses per second that is very useful to me. Thank you.

  • Hi,

    No, no, if you need to measure the frequency of an anlog signal, then you must add some circuitry to obtain a digital form of that signal. Both posters Amit and f.m. give you some ideas of what that should be. These are the simplest forms. Some other idea could also be used.

    As for measurements - see an worked example at the end of this thread:

    http://e2e.ti.com/support/microcontrollers/tiva_arm/f/908/t/374380.aspx?pi307171=2

    Petrei

  • Perhaps the teacher can clarify your assignment?  (thus easing the efforts of those here...)

  • Hello M. Mary,

    May be you need to look at the API's to understand the structure as well. In the first few lines I saw

        TimerEnable(TIMER0_BASE, TIMER_B);
        TimerEnable(TIMER_CFG_A_PERIODIC,    TIMER_A);  

    In one case the timer base is being parsed and in the next line the configuration is being parsed to the same field!!!

    Regards

    Amit