arduino-libraries / RTCZero

RTC Library for SAMD21 based boards
http://arduino.cc/en/Reference/RTC
GNU Lesser General Public License v2.1
78 stars 78 forks source link

sleep one extra second? #52

Open ravelab opened 5 years ago

ravelab commented 5 years ago

I set it up like this:

setup() { rtc.begin(); rtc.setAlarmSeconds(59); rtc.enableAlarm(rtc.MATCH_SS); Watchdog.enable() }

loop() { Watchdog.reset(); LED OFF rtc.setSeconds(58); rtc.standbyMode(); LED ON }

I'm expecting it to sleep 1 second, but it actually sleeps 2 seconds. I'm also using Adafruit_SleepyDog for watchdog. Don't know if that matters.

Thanks

moeskerv commented 4 years ago

I can confirm this. Basically sleeping for some seconds only seems to always add 1s extra:

rtc.setSeconds(0); rtc.setAlarmSeconds(0); rtc.enableAlarm(rtc.MATCH_SS); rtc.standbyMode();

-> Above results in a sleep for 1s.

rtc.setSeconds(0); rtc.setAlarmSeconds(1); rtc.enableAlarm(rtc.MATCH_SS); rtc.standbyMode();

-> Above results in a sleep for 2 seconds. And so on. I'm using version RTCZero 1.6.0 on an Adafruit Feather M0. No SleepyDog in use.

moeskerv commented 4 years ago

Interestingly the ArduinoLowPower (which uses the RTC too) lib does the same on my Feather M0

LowPower.sleep(0); -> sleeps for 1s LowPower.sleep(1000); -> sleeps for 2s

I tested with the TimedWakeup example: https://www.arduino.cc/en/Tutorial/LowPowerTimedWakeup

moeskerv commented 4 years ago

Might be a special behavior of the Adafruit M0 based Feathers?