From Wiring

Jump to: navigation, search
This page is intended as a reference for core developers only, and the content is only changed after a consensus has been reached through discussion of any such changes. Please use the Discussion page to talk about any changes or issues you have with the current implementation.
Classification Delay and Timing Control
Suggested location WDelay.h
C++ required No
Timing constraints None
Version introduced 1.0 (0100)
Framework dependencies None
unsigned long micros()
Required? Yes
Issues None



Returns the number of microseconds (millionths of a second) since starting an application. This information is often used for timing sequences.

Black Box Input

No input.

Black Box Output

Long. The number of microseconds (millionths of a second) since starting the application.


None. Single signature only.


There are 1000000 microseconds in a second.

Because micros() returns a long integer (32 bits), the value will "roll-over" (overflow) and go back to zero after approximately every hour. Here's why:

2^32 = 4,294,967,296 (largest number for a long int)
/ 1000000 = 4,294.967296 (seconds)
/ 60 = 71.582 (floor number of minutes)
/ 60 = 1.193 (floor number of hours)

But differential math on micros() will always result in correct calculations. For example:

start  = micros() = 0xfffffff0 (4,294,967,280 - just before overflow)
finish = micros() = 0x00000012 (12 - just after overflow)
finish - start = 0x00000012 - 0xfffffff0
               = 0x00000012 + (0x00000010) (two's complement)
               = 0x00000022

Which yields the correct result. This works for single "roll-over" only.

Proposed Changes

Personal tools