Max value for elapsedMillis?

Status
Not open for further replies.

DaQue

Well-known member
Stuck at work with no network today but my phone. Trying to blockout a teensy project I'm going to write here tomorrow but I'm not sure how long elapsedMillis can run. Is it longer than a few hours? I found one thing about millis being good for something like 49 days before rollover with Google. FWIW project is to monitor a battery voltage and compute maH before VBat drops to 90% and log it and voltages to the serial port once a minute but compute maH once a second. Expected elapsed time is up to 6.5 hours. Last time I had to sit and wait with a voltmeter and a pencile and got lots less data than I hope to this time. Thanks if any can answer on elapsedMillis max value.
 
Looking at the elapsedMillis.h file, the data type used is an unsigned long. So it should be 49.7 days before rolling over.

Brian
 
Thanks. It was hard to get to any headers today here. Looks like I can use it for what I need easy. Battery voltage manual test is at 4 hours and it's starting to show some voltage drop.
 
If you need longer measurements, you can still wrap elapsedMillis in an elapsedSeconds class or something similar
 
6.5 hours is fine.

elapsedMillis does properly handle the situation where the internal millis() rolls over every 49.7 days. In other words, if your 6.5 hour time falls within that moment 49.7 days after the board started, your 6.5 hour time will work properly.

As a general guideline, elapsedMillis should not normally be used for more than 2^31 milliseconds, or 24.85 days, because the compiler will default to signed 32 bit integers for many common expressions. With great care, you could use it for times up the 49.7 days.
 
The breadboarded project is working. I was worried the max value for elaspedMills would be 16bit. I took the example codemethod to reset it once it counts up enough. I hadn't thought about it but assumed it would only continue to count up once started. I only used AnalogRead so resolution is 10 bit but it's plenty good. Next revision I will use the ADC library. I took the time to calibrate the adc/resistor divider and it's pretty cool that I can look back after it's drained at the final few minutes of data by the second.
 
The breadboarded project is working. I was worried the max value for elaspedMills would be 16bit. I took the example codemethod to reset it once it counts up enough. I hadn't thought about it but assumed it would only continue to count up once started. I only used AnalogRead so resolution is 10 bit but it's plenty good. Next revision I will use the ADC library. I took the time to calibrate the adc/resistor divider and it's pretty cool that I can look back after it's drained at the final few minutes of data by the second.

You can just use analogReadResolution(bits) to change the resolution without switching to the ADC library.

Brian
 
Thanks. There is a lot to lear. Until the current 4-8 tests are done I have to leave working good enough alone. The slow drain tests may take a week each and I need at least 2 if not 4.
 
Of course, you can always use the rollover to set a counter and go as long as you want. Won't need to with your specs, though.

best,
Michael
 
Status
Not open for further replies.
Back
Top