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.

TM4C123GE6PM: How to set up a timer to measure edge interval

Part Number: TM4C123GE6PM
Other Parts Discussed in Thread: EK-TM4C1294XL

Hi,

I am having some problems in understanding how to set up a timer to measure the interval between two edges of an input frequency. In the device datasheet it says  " In Edge-Time mode, the timer is configured as a 24-bit or 48-bit up- or down-counter..."  inferring that the counters used are either 32 or 64bit. However in the Tiva Driver User guide the only options I can find for time measurement are

TIMER_CFG_A_CAP_TIME - Half-width edge time capture

and

TIMER_CFG_A_CAP_TIME_UP - Half-width edge time capture that counts up instead of
down (not available on all parts)

These suggest 16 or 32 bit. There doesn't appear to be an option to do a full width time measurement.

How do I set this up?

  • Hello Andy,

    First off, I think you are looking to do something like catching the rising and falling edge to measure the length of a period right?

    If so we have an example that does this for our EK-TM4C1294XL LaunchPad in the latest TivaWare release.

    The example is located at [Install Path]\TivaWare_C_Series-2.2.0.295\examples\boards\ek-tm4c1294xl\timer_edge_capture

    Such a project could be ported to the TM4C123x family without much trouble, and I think that is what you are looking for and would help you with development. If you have issues with the porting let me know.

    Now then regarding the questions here...

    Andy Worsley89 said:
    " In Edge-Time mode, the timer is configured as a 24-bit or 48-bit up- or down-counter..."  inferring that the counters used are either 32 or 64bit. However in the Tiva Driver User guide the only options I can find for time measurement are

    24-bit and 48-bit nomenclature is assuming the use of the pre-scaler to bump 16-bit to 24-bit with the 8-bit prescaler in GPTM mode, or from 32-bit to 48-bit using the 16-bit prescaler in wide GPTM mode. Table 11-3 shows the timers w/ pre-scalers included.

    Andy Worsley89 said:
    These suggest 16 or 32 bit. There doesn't appear to be an option to do a full width time measurement.

    Table 11-3 also lines out that the concatenated timers for 32/64 bit only support One-shot and Periodic measurements. So you are limited to the 24-bit (16+8 bit prescale) or 48-bit (32+16 bit prescale) options for edge capture mode which is what is reflected in driverlib.

  • Hi,

    thanks for your response. I took the example and ported it to the variant I am using. I didn't like the idea of using two channels to do one frequency measurement so I changed it to detect either edge and just subtract the current one from the previous one. This basically works, but I found that it was running way too fast. I had used the following driver function:

        TimerClockSourceSet( WTIMER2_BASE, TIMER_CLOCK_PIOSC );

    but when I did a measurement it works out that the clock frequency is running at 80MHz, which is the system clock frequency not the Precision Internal Oscillator frequency. Looking at the datasheet for this variant it seems this clock option is not available. I can't see from the website which variants do have this option. How do I know which ones have it and which ones don't?

  • Andy Worsley89 said:
    How do I know which ones have it and which ones don't?

    There is the following table in Differences Between Tiva™ C Series TM4C Microcontrollers :

    Andy Worsley89 said:

    I had used the following driver function:

        TimerClockSourceSet( WTIMER2_BASE, TIMER_CLOCK_PIOSC );

    The TimerClockSourceSet function changes the ALTCLK bit in the GPTM Clock Configuration (GPTMCC), offset 0xFC8 register (only present in TM4C129 devices). While the TIMER_CLOCK_PIOSC constant is documented as selecting the precision internal oscillator, it actually selects the Alternate clock source. While the Alternate clock source defaults to the PIOSC, the Alternate clock source can be changed by SysCtlAltClkConfig to be either the PIOSC, RTCOSC or LFIOSC.