Content originally posted in LPCWare by ElectroNerd on Sun Feb 03 18:55:12 MST 2013
Quote: Rob65
You are not the first to note a bug - and yes, I too think this is a bug (although I have not tested this).
Also note the difference between library and example ...
There is no timer library, just a timer example and that does not even use the delayMs function.
I think that, at some point in time, there was an example setting PCLK to CCLK/8 and then it all fits.
The 'fun' thing is that in that same timer.c file, the init_timer function does take into account that PCLK can be either CCLK/1, /2, /4 or /8 ...
Yes - it's just too bad that these examples (the timer is not the only one) contains bugs making us wonder if we have a problem interpreting the user manual or if there is a bug in the code...
By the way: it's easier to use the systick timer for this kind of delays.
Rob
P.s: you'll find other files named timer.c in the other projects containing a somewhat, yet not completely, similar implementation :confused:
It seems as if there is no bug after all. I went ahead and configured TIMER0 for a theoretical 1 ms period and my o'scope showed a 2 ms period! Attached you will find the code that correctly gives 1 ms.
Where does this come in for the calculations?
Rob, I am in the process of creating a timer library for my application, but I may consider using SysTick as a feature.