Pages: [1]   Go Down
Author Topic: Exact overflow value for micros() function?  (Read 595 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


I would need to know what is the EXACT overflow value of the micros() function on the Arduino Uno. In the language reference it only says that this number will overflow (go back to zero) after APPROXIMATELY 70 minutes. Anyone knows what is the exact value. Thanks in advance.

Left Coast, CA (USA)
Offline Offline
Brattain Member
Karma: 361
Posts: 17303
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Simple, micros() returns a unsigned 32 bit long interger so it rolls over at 0xFFFFFFFF or 4,294,967,295 if you are a decimal fan.



Left Coast, USA
Offline Offline
Sr. Member
Karma: 7
Posts: 499
Sometimes I just can't help myself.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

...the EXACT overflow value of the micros() ...

Well, let's do a little arithmetic.  The return data type of micros() is an unsigned long integer (32 bits).  Now, 2 to the power 32 is equal to EXACTLY 4294967296, and the variable would overflow if it were incremented from a count of 429467295.  See Footnote.


If the return value represents microseconds, it overflows at a value of

EXACTLY 4294.967296 seconds.

This is EXACTLY 71.58728827 minutes or EXACTLY 71 Minutes, 34.967396 seconds


The clock may not be EXACTLY 16 MHz.  In fact reports of Uno boards supplied with resonators seem to indicate that the clock may be off by something over 1000 parts per million, or 0.1%  Official Duemilanove boards with crystals that I have personally measured have shown variations on the order of 100-200 parts per million (0.01%-0.02%). Some people are surprised, since crystals are typically specified to be accurate to a few tens of parts per million.  That's at a given temperature and with a particular load capacitance (input capacitance of the Arduino clock pins plus "stray" circuit capacitance).

There are two sources of uncertainty:

1.  We have no way of knowing EXACTLY what the specified crystal tolerances are for parts supplied with the boards.

2.  Atmel data sheets don't actually give a precise specification of the EXACT input capacitance of the clock pins to which the crystal (or resonator) is attached.  That's typical for many (most) microprocessors and other basically digital circuits:  The on-chip oscillator circuit consists of a few transistors whose exact parameters are not especially tightly controlled (or specified) by the manufacturer.

Bottom line: No, I can't tell you EXACTLY when the micros() return value overflows to zero, since that depends on your board (and the temperature and the exact operating voltage, etc. etc.), but it's APPROXIMATELY 71 minutes and 34.967396 seconds.


In fact, the return value from micros() is always a multiple of 4, so the overflow to zero occurs when the return value is incremented (by a value of 4) from 4294967292.  But who's counting? Bottom line, it's still about 70 minutes.
« Last Edit: April 04, 2011, 10:01:45 pm by davekw7x » Logged

Central Europe
Offline Offline
Edison Member
Karma: 7
Posts: 1220
Use the Source, Luke.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I would need to know what is the EXACT overflow value of the micros() function on the Arduino Uno.

That sounds very unlikely. It's very hard to imagine a reasonable use-case where you'd need to know the exact value and about 70 minutes isn't good enough. 100% of people asking such a questions are usually trying to solve the problem of the overflow in an incorrect way. For one of many posts how it's done correctly check posting,57562.msg413942.html#msg413942


Pages: [1]   Go Up
Jump to: