Hello,
I have a two source codes that may return the same result but they dont.
1.interrupt version:
#include <AT892051.H> unsigned long timer0_tick; void timer0_isr (void) interrupt 1 { timer0_tick++; } int main (void) { TMOD |= 0x1; // 16b mode timer 0 ET0 = 1; timer0_tick = 0; TL0 = 0x0; TH0 = 0x0; TR0 = 1; EA = 1; while (1) ; }
After 5 seconds simulating, timer0_tick is about 1970 (ticks)
2.polling version
#include <AT892051.H> unsigned long timer0_tick; int main (void) { TMOD |= 0x1; // 16b mode timer 0 timer0_tick = 0; TL0 = 0x0; TH0 = 0x0; TR0 = 1; while (1) { while (TF0 == 0) ; TF0 = 0; timer0_tick++; } }
In this case, after 5 seconds simulating timer0_tick is about 79(ticks).
Comparing using simulation runtime time is not valid. Compare each for 5 seconds of runtime in actual target hardware.
But is it possible to have such different values?
79 ticks in polling version is:
79 * 0xFFFF = 4,9 sec.
1970 ticks in interrupr verision is
1970 * 0xFFFF = 129 sec.
"But is it possible to have such different values?"
Let's look for the difference using another measurement. What is the 'states' value after 5 simulation-seconds in both cases? It is displayed in the "Regs" pane by expanding "Sys".
Interrupt ver: states = 122343383 Polling ver: states = 4650183
Well there you go! That's proof positive that the simulator working >20x harder to simulate the polling version.
You'd have to let the simulator run >20x longer for the polling version to simulate the same number of instruction cycles (states).