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.

How to properly read from and set up 24 bit timer in TM4C1294 with prescaler



Hello everyone,

I have a question regarding how to properly read from and set up a timer -- a 16 bit timer base, that is -- when using the prescaler to extend it.

So I'm using Timer A in its edge time count mode, counting upwards. I'm using the tivaware driver library for timer's. I know that if I just use TimerLoadSet and timerValueGet, I just put in and get back out a 16 bit value.

I'm a bit confused as to implementing the prescaler -- I assume that, when setting up the timer, I use TimerLoadSet to put in the 16 lSB's and then use TimerPrescalerSet (or whatever it's called) to put in the 8 MSB's, so that the timer will then count up the full 24 bit load before resetting.

In that case, how do I then read correctly what the timer value is when I receive an edge and record what the clocked value was? If I try using TimerValueGet to get the first 16 bits of the value the timer had when the edge was received, do I use TimerPrescalerGet to get the last 8 bits of the time the timer had when the edge was received? Or will calling TimerPrescalerGet just get me back the load value, and not the timer captured value? In that case, how am I to properly read the 24 bit time for when the edge was captured?

Thanks

  • Hello Drue,

    When an edge occurs the time of the edge is captured in the GPTMTnR and GPTMTnPS register. Here n is A or B based on which sub-timer is being used. The API for reading GPTMTnPS is not there. In other words once you get the timer value, a HWREG of the corresponding GPTMTnPS needs to be done in the application.
  • Thank you for the reply.

    So if I'm understanding right, the procedure for doing what I want can be psuedocoded like this, yes?

    setup:
    --set timer into its proper mode, turn on the relevant interrupts--

    TimerLoadSet(first 16 bits of its timeout value)
    TimerPrescaleSet(most significant 8 bits of its timeout value)

    --enable timer--


    At this point, the timer runs in the background and captures an edge and puts the time it received them into its GPTMnR and GPTMTnPS registers.

    So over in the interrupt routine, to read out the values correctly I do:
    first16Bits = read from GPTMnR
    last8Bits = readFromGPTMTnPS

    put bits together --> total timer value

    and I need to use HWREG to read from GPTMTnPS. Is GPTMnR the value read when I call TimerValueGet, or do I need to use HWREG for that too
  • Hello Drue

    You don't need HWREG to read GPTMTnR register. That is done by the API. But to be on the safer side check the driverlib file for timer.c