Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Oscillator disabled after 1st sleep (except idleMode) ? #20

Closed
fishBone000 opened this issue Apr 10, 2021 · 1 comment
Closed

Oscillator disabled after 1st sleep (except idleMode) ? #20

fishBone000 opened this issue Apr 10, 2021 · 1 comment

Comments

@fishBone000
Copy link

I wrote a program to let Arduino UNO blink for 2 secs, display millis() on an OLED screen, sleep for 5 sec, and then loop it again and again.
However I noticed that except idleMode, in other modes the displayed time difference of 1st loop is about 7 seconds, but in later loops it is about 2 seconds. It seems that millis() didn't count the past time during later sleep periods.
In idleMode, the difference is always about 7 seconds.
I expected it to display same difference since the UNO had only entered the same sleep mode, which should have the same result.
Perhaps the external oscillator is disabled in later sleep times than the 1st time?
Note that I don't have that much knowledge about sleep modes...Just happened to get to know it to save some power for my battery driven device.

@nullboundary
Copy link
Collaborator

Hi fishBone000, sorry for the slow response. I don't recall all of the details right now (its been awhile since I have worked with sleep mode on the arduino). However I do know some of the sleep modes disable the timer that millis() depends on. The Sleep_n0m1 library uses the watchdog timer to wake itself up, but the millis function uses a different timer which disabled in some sleep modes so it won't count correctly. The idleMode is different because that one doesn't disable timers and so doesn't save much power. Also the first loop is always 7 seconds because the way the library works is it uses the first loop to calibrate the sleep times. So it only does idleMode sleep on the first cycle (and every 100th cycle) while calibrating regardless of what mode you set it in. After its finished calibrating in the first cycle it will switch to the sleep mode you set. I think if you use a stop watch on your phone or something you will see that it should be keeping a 7 second time cycle for all loops with any sleep mode. Just the millis display is wrong. I hope that helps!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants