Im using LPC1778 uC to generate a pulse of 500Hz from the timer interrupt routine. I have configured the interrupt to interrupt every 200uS. It enters the ISR on time. But what i want to know is the accuracy of the keil simulation time shown? Will it vary when actually executed on the hardware.Because the Logic analyser shows a pulse that slightly off than whats expected. How reliable is the logic analyser graph,which depends on the keil sim time shown?
MR0 = 200 * (120000000 / 1000000 -1)
Intended time period => 2ms Obtained time period in Logic Analyser => 1.98342ms
MR0 = 200 * (120000000 / 1000000)
Intended time period => 2ms Obtained time period in Logic Analyser => 2.00008ms
If i subtract 1 as you said for NXP Chips,i get an error.
Learn to do math MR0 = (200 * (120000000 / 1000000)) - 1; // Count is N-1, ie N ticks in 0..N-1
Sorry my bad. Now, without "-1" -> 2.000075ms With "-1" -> 1.99999ms
200 * (120000000 / 1000000 -1)
But this is not an N-1 formula.
Your formula gives the value 23800, since you included the -1 inside the parentheses and so multiplied it by 200.
The above would give (23801 / 12000000) = 0.001983 seconds period time. Seems to agree with the logic analyzer output...
Shouldn't you compute:
200 * (120000000 / 1000000) -1
which would give the value 23999.
And 0, 1, 2, ... 23998, 23999, 0, 1, 2, ... represents a series of 24000 values. Hence the N-1 rule.
And an event every 24000 ticks would - if assuming 12MHz input frequency - give 12000000/24000 = 500 events/second or one every 2ms.