[En-Nut-Discussion] NutGetMillis overflow documentation
uprinz2 at netscape.net
uprinz2 at netscape.net
Tue Feb 9 10:44:50 CET 2010
Thanks Ole, you are right!
Never thought about that. The problem some delay routines have is that the
calculation for the time may shift out to much bits if the width of the
registers is not obeyed. But if you stay wwithin the limits, like
NutGetMillis() does, the value is also precise if an overflow / trunkation
is done.
Best regards, Ulrich
On Mon, 08 Feb 2010 18:04:11 +0100, Ole Reinhardt
<ole.reinhardt at embedded-it.de> wrote:
> Hi!
>
>> Normally you do timespan calculations that look like this:
>>
>> if( now-past < span) { wait a bit }
>>
>> These type of call will result in a jitter with every overflow.
>
> That's not correct. As long as now and past are both uint32_t this
> calculation will work correctly even if there was an overflow between
> past and now. That's a nice effect of unsigned calculations :)
>
> Example (8 bit)
>
> Now = 10 = 0x0A
> Past = 245 = 0xF5
>
> now - past = 0x(ffffff)15 => truncated to 8 Bit = 0x15 = 21 (which is
> totaly correct)
>
> Regards,
>
> Ole
More information about the En-Nut-Discussion
mailing list