[En-Nut-Discussion] NutGetMillis overflow documentation

Nathan Moore nategoose at gmail.com
Mon Feb 8 19:37:32 CET 2010


On Mon, Feb 8, 2010 at 12:04 PM, 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 :)

I think that there can be overflow jitter when the tick period is not
1 millisecond,
but this jitter is introduced by converting between ticks and milliseconds.

Otherwise when you do the math it is always as though there is some more
digits to the left of the most significant bit to borrow from.
Problems come in when you want do calculations that involve enough of a time
span that it raps around again, or in some cases just involves the
result looking
negative when interpreted as a signed value.
In general though, treat time the same way you treat a wall clock
(with hands). They overflow
twice a day.

Nathan



More information about the En-Nut-Discussion mailing list