[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-libc-dev] Optimization safe access to the timers
From: |
Galen Seitz |
Subject: |
Re: [avr-libc-dev] Optimization safe access to the timers |
Date: |
Thu, 21 Sep 2006 19:30:01 -0700 |
Enoch H. Wexler <address@hidden> 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