Discussion Forum

interrupt vs. polling - different results

Next Thread | Thread List | Previous Thread Start a Thread | Settings

DetailsMessage
Read-Only
Author
Peter Silon
Posted
25-Feb-2007 21:43 GMT
Toolset
C51
New! interrupt vs. polling - different results

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
New! RE: interrupt vs. polling - different results

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
New! RE: interrupt vs. polling - different results

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
New! RE: interrupt vs. polling - different results

"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
New! RE: interrupt vs. polling - different results

Interrupt ver: states = 122343383
Polling ver: states = 4650183

Read-Only
Author
Dan Henry
Posted
25-Feb-2007 23:15 GMT
Toolset
C51
New! RE: interrupt vs. polling - different results

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
New! RE: interrupt vs. polling - different results

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