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.

TM4C129 Timer Capture with TI_RTOS

I was trying to add a simple frequency measurement to my TI_RTOS project running on EK-TM4C129. There are many discussions on this subject, most of it based on TivaWare lib and TM4C123 chip, so I'm adding my observations here. I was struggling for several hours to implement this functionality in my quite large project, mostly because the readouts were only 16bit values, so then decided to create a simple project with TI_RTOS, where once started, the timer 3A is initialized as split pair, edge time capture, generating HW interrupt on capture event (edge), storing values of the first and the second edge in an array. Once there are 8 sample pairs collected, timer is stopped and a SW interrupt function is posted to calculate an average and the measured frequency.

There is couple of tricks to it. From the datasheet it seems that the 8bit prescaler is automatically included to extend the timer to 24bits. However to include it needs to be written during the initialization using the TimerPrescaleSet library function, but the pre-load value must not be 0. The best results (least frequency errors) I got with 0xff. Obviously if we are pre-loading part of the counter with 0xff, it makes sense to count down, so the direction was changed to TIMER_CFG_A_CAP_TIME. There were discussions how to read the 24bit value, suggesting to set the TxSNAPS bit to drive it in a snapshot mode. This has shown as not true, the 24bit value is read correctly using the TimerValueGet function.

Regards,

Dalibor

  • Hello Dalibor,

    Yes, the following thread also captures the same.

    e2e.ti.com/.../1388446

    Regards
    Amit
  • Hello Amit, I know, I was trying to be specific about TI_RTOS and TM4C129, in the case there is some difference.

    I needed to implement another feature - detection of overflow/timeout. The timeout interrupt is not supported in the time capture mode, so I have utilized the second 16/24 bit timer, configured as TIMER_CFG_B_ONE_SHOT with TIMER_TIMB_TIMEOUT interrupt and restarting this timer every time there is a TIMER_A capture event.

    One more note, to restart the timer in the split mode, it is better to use TimerLoadSet function when previously set

    TimerUpdateMode(TIMER3_BASE, TIMER_B, TIMER_UP_LOAD_IMMEDIATE), as clearing the counters using TimerDisable/TimerEnable is messing with the TIMER_A functionality, so it is better to let both timers free-running during the process.

    Regards,

    Dalibor

  • Hello Dalibor

    Yes, you are correct there as well. I have seen an issue where not setting up the Timer Load value when it is stopped and restarted creates all sorts of issues on the output w.r.t waveform generation

    Regards
    Amit