-
-
Notifications
You must be signed in to change notification settings - Fork 127
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
Add API to advance millis() and micros() #69
Comments
The solution to the problem is not simple. |
Adding the ability to add/subtract would also make it easier to test for issues that may only occur after days. I think an addTime() function with a signed integer microseconds value is the best way to go, but additional setMillis and setMicros would also be useful. Putting sleep/idle in the core is great, but doesn't address the use case of correcting millis frequency offset, to simplify RTC libraries, or using an external RTC to measure the elapsed sleep time when waking up via interrupt from an unknown source, etc. On some processors, delay() itself could probably use a low power idle without breaking anything, but that doesn't address deep sleep and probaby can't be safely done on many chips. |
When an AVR MCU sleeps in power-down mode, it's clock stops running. Typically time is being kept using the watchdog timer, or an asynchronous timer2, to allow waking up after a specified time. However, the
millis()
andmicros()
counters are not updated during sleep, meaning that the sketch needs to jump through hoops (manually offsetting these counters, or modifying Arduino's global variables) to make various timing work. The former only works with sketch code, not libraries that rely on both counters, and the latter is obviously very ugly and non-portable.Ideally, there would be an API that allows modifying the millis() and micros() timers by adding (or perhaps also subtracting?) a specified time from both. Most obvious would be an int32_t specifying the number of microseconds. This allows offsetting the time by about 35 minutes in one call. Alternatively, specifying both millis and micros separately would increase the range, but also complicate the code a bit (needing actual division instead of just bitshifting, I think). In either case, I'd say that both counters are always updated at the same time and stay in sync, not being updated individually.
The text was updated successfully, but these errors were encountered: