Testing millis() overflow

The RTC uses the millis() counter to keep time as shown below. This code is defined in Time.cpp

Since the millis() counter runs even during sleep( and I want it to run because I am using the RTC to wake), it will overflow after about 50 days. I want my device to last for a few years.

Now if the framework is implemented properly, then the code above would still work after a millis() overflow as laid out bye Nick Gammon here.

Even so, I want to test it by assigning a large value to the millis counter(). On regular Arduino’s I use an atomic block.

But the Heltech cubecell does not support this. Is there a way for me to test the millis() counter overflow?
Thanks =D

1 Like


did you find any solution to this? Would be interested to try something similar but I don’t want to wait for 50 days ^^

millis() return a 32bit unsigned data. I think you can set some paras check if it is overflowed :

set two global paras:
uint32_t lastmillis = 0;
uint32_t overflowtimes = 0;

when you want to use millis(), do like this:

uint32_t temp = millis();
if(temp < lastmillis )
overflowtimes ++;
lastmillis = temp;
uint64_t millis_64 = overflowtimes * 0x100000000 + temp;

1 Like