Hi Flemming,
I think you should disable intrerupts for the time
of comparing. 16 bit compare (load) is not atomic.
This is your code compiled by me (you better use
volatile if don`t want the whole loop to be optimized away).
volatile unsigned short RotCount; void test(void){
while (1){
RotCount = 0; aa8: 10 92 17 01 sts 0x0117,
r1 aac: 10 92 16 01 sts 0x0116,
r1
while (RotCount < 1000) {} ab0: 80 91 16 01
lds r24, 0x0116 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
intrerupt can happen here, I`m curios too exactly what hapens
than...
ab4: 90 91 17 01 lds r25,
0x0117 ab8: 88 5e
subi r24, 0xE8 ; 232 aba: 93 40
sbci r25, 0x03 ; 3 abc: c8
f3
brcs .-14 ;
0xab0
RotCount = 0; abe: 10 92 17 01 sts 0x0117,
r1 ac2: 10 92 16 01 sts 0x0116,
r1
while (RotCount < 2000) {} ac6: 80 91 16 01
lds r24, 0x0116 aca: 90 91 17 01 lds r25,
0x0117 ace: 80 5d
subi r24, 0xD0 ; 208 ad0: 97
40 sbci r25, 0x07 ;
7 ad2: c8 f3
brcs .-14 ; 0xac6 ad4: e9
cf
rjmp .-46 ; 0xaa8
stay in touch,
Andras
----- Original Message -----
Sent: Wednesday, January 18, 2006 4:47
PM
Subject: [avr-gcc-list] BUG? Comparing of
words error.
Hi,
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;
0000 0011 1110 1000 = 1000 0000
0011 0000 0000 = 0768
0000 0111 1101 0000 = 2000 0000 0111 0000
0000 = 1792
As can be seen, it appears that the while() exists when
the high byte of the two words matches.
I didn't check the assembler
output yet to see what might be happening, but thought I'd ask you guys first.
Any idear what might be at play here?
Best regards,
Flemming
View this message in context: BUG?
Comparing of words error. Sent from the AVR - gcc forum at
Nabble.com. !DSPAM:43ce8a5d194709637414539!
_______________________________________________ AVR-GCC-list mailing
list address@hidden http://lists.nongnu.org/mailman/listinfo/avr-gcc-list
!DSPAM:43ce8a5d194709637414539!
|