rocketscream / Low-Power

Low Power Library for Arduino
www.rocketscream.com
1.26k stars 345 forks source link

the clock ( millis() ) seems not to work in a wakeup function #109

Closed dan-bel closed 3 years ago

dan-bel commented 3 years ago

TimeStandingStillAfterWakingUp.txt

Hi,

I experienced that the millis() is always returning the same value when run in a function which is triggered after waking up.

Unfortunately, I lack the skills to dig deeper :(

Attached a sample code. After 10 sec, the Arduino will go to sleep and is woken up by connecting pin 2 to ground. The function wakeUp() is run, and it seems that time stays still, millis() always returns the same value. Tested on Arduino nano, and LowPower version 1.81

Thank you

Dan

rocketscream commented 3 years ago

All clock are stopped during power down. millis() only run during active state.

dan-bel commented 3 years ago

that makes sense, but I would expect the wakeup function to be an active state since things are happening?

rocketscream commented 3 years ago

The millis() stops during sleep and upon waking up it will continue to run, hence the millis() will stop to count during the sleep period. If just prior to sleep the millis() count is 1000 ms, it will be 1000 ms upon waking up despite sleeping for example 8 seconds.

dan-bel commented 3 years ago

Thank you, I now realized that time never runs in interrupt handlers, so it would also not run here. Thank you for your input and clarification.