Thanks Galen, Right on the nail! Integer promotion rules: One operand (TCNT3) has unsigned int type -> The other operand (when) is converted to unsigned int. I fell asleep :-)
Enoch. Galen Seitz wrote: > Enoch H. Wexler <[EMAIL PROTECTED]> wrote: > > >> Hi Paulo, >> >> >> Strange, the problem does not show in my simplified test... but here's >> some real code excerpt and its disassembly (compiled with -Os using >> avr-gcc 4.1.0): >> >> (1) Using TCNT3 directly: >> >> when = TCNT3 + (7200 / 9 * 10 - 1); /* > 1 sec delay */ >> while (when - TCNT3 >= 0) >> UDR1; >> >> 000013ce <kuku>: >> 13ce: 80 91 88 00 lds r24, 0x0088 >> 13d2: 90 91 89 00 lds r25, 0x0089 >> 13d6: 80 91 88 00 lds r24, 0x0088 >> 13da: 90 91 89 00 lds r25, 0x0089 >> 13de: 83 b1 in r24, 0x03 ; 3 >> 13e0: fa cf rjmp .-12 ; 0x13d6 <kuku+0x8> >> >> > > > The type of TCNT3 is unsigned, so the expression (when - TCNT3 >= 0) > is always true due to C type conversion rules. You should cast > TCNT3 to int16_t. > > galen > > _______________________________________________ AVR-libc-dev mailing list [email protected] http://lists.nongnu.org/mailman/listinfo/avr-libc-dev
