This is my first post to this forum. I'm not even sure it's the right place to post, but I think so.
I'm trying this with an ATmega8, with a 500Hz oscillator connected at INT0, using WinAVR (avr-gcc 3.4.3).
I noticed the problem using this code:
------------
unsigned short RotCount;
SIGNAL(SIG_INTERRUPT0){
RotCount++;
}
void test(void){
while (1){
RotCount = 0;
while (RotCount < 1000) {}
RotCount = 0;
while (RotCount < 2000) {}
}
}
------------
My problem is that the two inner whiles sometimes exists prematurly.
The one counting to 1000 sometimes exists at 768.
The one counting to 2000 sometimes exists at 1792.
Sometimes, means once every 5 to 20 loops.
Looking at the numbers bineary, seems to give a pointer to an explanation;