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?
The actual instruction timing may be off, because it is hard to emulate the exact number of wait states introduced in the processor pipeline for different memory access situations.
But the timer itself should tick at the correct speed, if you have configured the simulator to use the correct virtual crystal - if your source code sets up the timer for one crystal frequency while the simulator things you are emulting using a different crystal frequency then you would get lots of errors.
Have you made sure you don't have the traditional off-by-one error that lots of people manage when programming NXP chips, because they do not actually read the full information in the datasheet?
So to divide from 12MHz into 1ms you shouldn't divide by 12000 but with 12000-1.
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.