Go Down

Topic: how to convert micros() to seconds (Read 3086 times) previous topic - next topic


I just want to convert the micros() function output to actual seconds, but don't quite understand the reference page.  I'm using Arduino Uno, which has a 16MHz oscillator, so according to the micros() reference page:
On 16 MHz Arduino boards (e.g. Duemilanove and Nano), this function has a resolution of four microseconds (i.e. the value returned is always a multiple of four).

When I run some simple print code (below) I get this as the first few lines of output:

So how many seconds is 1064 micros()?  If it's a multiple of 4 as indicated in the quote, that means
1064 micros() = 1064/4 microseconds  = 266 microseconds  = 0.000266 seconds
?  This doesn't feel right.  However, I'm not sure how to translate "resolution of four microseconds" quoted above.

Coding Badly

micros returns the number of microseconds.  The granularity (4) is irrelevant.  To convert to seconds divide by one million.


Thanks! But can you explain more? I don't understand why The granularity (4) is irrelevant.


All it means is that, in effect, instead of incrementing a variable by one every microsecond, the variable is incremented by four every four microseconds.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.


ooohhhh okay great, thanks so much for such a quick reply!

Go Up