[En-Nut-Discussion] NutGetMillis overflow documentation

Ole Reinhardt ole.reinhardt at embedded-it.de
Mon Feb 8 18:04:11 CET 2010


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 

-- 

Thermotemp GmbH, Embedded-IT

Embedded Hard-/ Software and Open Source Development, 
Integration and Consulting

Geschäftsstelle Siegen - Steinstraße 67 - D-57072 Siegen - 
tel +49 (0)271 5513597, +49 (0)271-73681 - fax +49 (0)271 736 97

Hauptsitz - Hademarscher Weg 7 - 13503 Berlin
Tel +49 (0)30 4315205 - Fax +49 (0)30 43665002
Geschäftsführer: Jörg Friedrichs, Ole Reinhardt
Handelsregister Berlin Charlottenburg HRB 45978 UstID DE 156329280 




More information about the En-Nut-Discussion mailing list