avr-libc-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-libc-dev] Optimization safe access to the timers


From: Enoch H. Wexler
Subject: Re: [avr-libc-dev] Optimization safe access to the timers
Date: Thu, 21 Sep 2006 23:31:14 -0400
User-agent: Thunderbird 1.5.0.7 (X11/20060914)

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 <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
>
>   





reply via email to

[Prev in Thread] Current Thread [Next in Thread]