PaulStoffregen / Time

Time library for Arduino
http://playground.arduino.cc/code/time
1.25k stars 666 forks source link

Is this library compatible with any deep-sleep mode #118

Open Jorfuenst opened 5 years ago

Jorfuenst commented 5 years ago

For example, ESP32 deep-sleep.

Thanks a lot.

ghost commented 5 years ago

Hi can you suggest me an Arduino board which has the clock frequency at least 48 Mhz from the Arduino AVR families? Raju KC

On Tue, Feb 26, 2019 at 10:07 AM Jorfuenst notifications@github.com wrote:

For example, ESP32 deep-sleep.

Thanks a lot.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/PaulStoffregen/Time/issues/118, or mute the thread https://github.com/notifications/unsubscribe-auth/AiC9nG5mYJobLrsY7PKkjMf8KxP5f1Viks5vRU2_gaJpZM4bSZAe .

kolen commented 5 years ago

It relies on millis()

https://github.com/PaulStoffregen/Time/blob/6d0fc5e6f9d1b8bb9462ee7944d2624abb5187ae/Time.cpp#L250-L253

which in turn uses:

Both functions return time that is reset on deep sleep. So no, it's incompatible, you can use it, but it resets after deep sleep.

As "rtc clock", which continues to work in deep sleep mode, is too imprecise and unreliable (quartz oscillator is disabled in deep sleep), it requires sophisticated handling. Nodemcu has implementation for it, and it's quite complex.

VinceKezel commented 4 years ago

I am having great luck using this time library with pwrDownMode() from Sleep_n0m1 library. I go into pwrDownMode ( "deep sleep" ) for 10 seconds and then I ADVANCE the millis() timer directly to account for the milliseconds lost during the sleep. Some forum posts say it's bad to do that, but it works in practice for me. YMMV


  extern volatile unsigned long timer0_millis; //<<this line before setup() !
  #include <Sleep_n0m1.h> //<<this line before setup() !
  Sleep cpu_sleep; //<<this line before setup() !
//following in setup/loop:
  cpu_sleep.pwrDownMode(); //set sleep mode
  cpu_sleep.sleepDelay(10000); //actual sleep
  noInterrupts ();
  timer0_millis = millis()+9988L; //long int 9988
  interrupts ();