 | Discussion Forum |  |
|
|
interrupt vs. polling - different resultsNext Thread | Thread List | Previous Thread Start a Thread | Settings | Details | Message |
|---|
Read-Only Author Peter Silon Posted 25-Feb-2007 21:43 GMT Toolset C51 |  interrupt vs. polling - different results Peter Silon 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).
| | Read-Only Author Dan Henry Posted 25-Feb-2007 22:08 GMT Toolset C51 |  RE: interrupt vs. polling - different results Dan Henry Comparing using simulation runtime time is not valid. Compare each for 5 seconds of runtime in actual target hardware. | | Read-Only Author Peter Silon Posted 25-Feb-2007 22:36 GMT Toolset C51 |  RE: interrupt vs. polling - different results Peter Silon 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. | | Read-Only Author Dan Henry Posted 25-Feb-2007 22:53 GMT Toolset C51 |  RE: interrupt vs. polling - different results Dan Henry "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". | | Read-Only Author Peter Silon Posted 25-Feb-2007 23:09 GMT Toolset C51 |  RE: interrupt vs. polling - different results Peter Silon Interrupt ver: states = 122343383 Polling ver: states = 4650183 | | Read-Only Author Dan Henry Posted 25-Feb-2007 23:15 GMT Toolset C51 |  RE: interrupt vs. polling - different results Dan Henry Well there you go! That's proof positive that the simulator working >20x harder to simulate the polling version. | | Read-Only Author Dan Henry Posted 25-Feb-2007 23:17 GMT Toolset C51 |  RE: interrupt vs. polling - different results Dan Henry You'd have to let the simulator run >20x longer for the polling version to simulate the same number of instruction cycles (states). | |
Next Thread | Thread List | Previous Thread Start a Thread | Settings |
|