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 us prescale of Timer on lm4f120 launchpad?

Other Parts Discussed in Thread: TM4C1233H6PM

Hi~~thanks~

Now i need a waveform with 20ms period and 0.5ms~2ms duty cycle.

But the Sysclock of lm4f120 is 80MHZ(I need the highest speed to process the PID).so timer0~timer5(16/32 bit timer) 's max period is :12.5ns*0xffff(65535)=0.819ms,that can't reach 20ms..

I also see the prescale function of timer, but how to use it to achieve clock division??confusing.....

  • Hi Zheng,

    So you have three options here, but first some math

    the clock is 80Mhz, so there is a tick every 1/80,000,000 = 0.000,000,012,5 seconds. assuming you want to use a 16bit timer then the max value it could hold would be 2^16 = 65536 so the maximum length of a standard 16bit timer would be 0.000,000,0125 * 65536 = 0.0008192 seconds. you are asking for something that at a minimum can count 2ms = 0.002s and at a max 20ms = 0x020s. Thus I see three options

    Option 1: use a larger timer.
    use the 32bit timer, for this you can use the full width 32 bit timer, or the 64bit timer in split mode.

    Option 2: use counters
    keep global values that keep track of the number of times a timer has executed. say we set the timer to go off ever 0.0001 seconds, then you would have a global variable that would incriment every time the timer executes. So when the global value reaches 20 then .002s would have passed. 200 for .02s . use a polling function to keep checking the values and update the GPIO pin accordingly.

    Option 3: Use Prescaler
    There are two ways to think about how the prescaler works. Either it makes each tick take more time, or it gives the counter more digits of precision. I reccomend looking at http://www.ti.com/lit/ds/symlink/tm4c1233h6pm.pdf Table 11-5 on page 682.
    also you can look at the code implemented by Jordan Wills at

    https://github.com/EuphonistiHack/marble-maze/blob/master/TivaWare_c_Series-1.0/examples/boards/ek-tm4c123gxl-boostxl-senshub/maze_receiver/maze_receiver.c
    line 293 and 300 for the prescaler in  use.

    And if you still cant figure it out look at the TimerPrescaleSet() function in Timer.c in driverlib.

    Best of Luck!

    -Austin