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.

DMTimer TLDR value calculation - TRM conflicts with with StarterWare code?



I've got a dmtimer running (with interrupts), but I'm having some trouble verifying my configuration and there seems to be a difference between the StarterWare code and the TRM.

The TRM states that the clock rate is calculated as: (0xFFFFFFFF - TLDR + 1) * clock_period * prescaler_val

However, the sysdelay code in the StarterWare (which uses the 24MHz input clock with prescaler disabled) sets the TLDR value to 0x5DC0 (24000) exactly rather than 0x5DBF (23999) which I would expect if you wanted the equation in the TRM to give you 0.001 seconds exactly.

I realize that the difference is 24 millionths of a second, however I don't want this off-by-one to bite me if I start working with other clock inputs/prescalers in the future. I tried to measure it using a gpio/oscilloscope, however it doesn't have enough accuracy to detect the difference between the two possible values. 

I tried setting up the 32.768kHz internal clock source where the difference would be more obvious, however the interrupt only goes off once (and then never again) and I can't figure out why, so that's not helping either.

If somebody could clarify this I would greatly appreciate it. I'm running on a beaglebone black, rev A5B.

Matt T

  • I'm going to answer this so that anybody else looking for the answer to this question can hopefully find it. I'm pretty sure I'm correct, unless somebody from TI wants to contradict me with evidence.

    The StarterWare sysdelay code is incorrect. The code in the Sysdelay function should be:

    unsigned int countVal = TIMER_OVERFLOW - (milliSec * TIMER_1MS_COUNT - 1);

    where the minus one is the part that's currently missing.

    To verify this, I set up my thread to delay for 500 milliseconds at a time (my RTOS clock ticks every millisecond). Every time my thread wakes back up, I read the value of a second DMTimer which I configured to run with sub-microsecond resolution and convert to microseconds. Without the minus one, the difference in the second timer is consistently 500020 +/- 1 us. That is exactly what I would expect to see if there were 500 * (1/24000000) extra clock pulses happening every half second. If I subtract one from the TLDR value as stated in the TRM, the time difference comes out to be 500000 +/- 1 us which is bang on. 

    Hope other people find this useful.

    Matt T