Go Down

### Topic: Exact overflow value for micros() function? (Read 1 time)previous topic - next topic

#### cd_lux

##### Apr 05, 2011, 03:02 am
Hi,

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.

#### retrolefty

#1
##### Apr 05, 2011, 04:19 am
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.

Lefty

#### davekw7x

#2
##### Apr 05, 2011, 04:56 amLast Edit: Apr 05, 2011, 05:01 am by davekw7x Reason: 1

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

So...

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

However...

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.

Regards,

Dave
Footnote:
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.

#### Korman

#3
##### Apr 05, 2011, 09:13 am

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 http://arduino.cc/forum/index.php/topic,57562.msg413942.html#msg413942

Korman

Go Up

Please enter a valid email to subscribe