Implement RTC_Micros with tunable drift #112
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Most Arduinos are clocked off a ceramic resonator which is notably inaccurate for timekeeping. Drift rates can be of the order of 1,000 ppm, i.e. more than a minute per day. This severely limits the usefulness of
RTC_Millis
. However, if the user can measure the drift rate of his Arduino's clock, the software could in principle use this measurement to compensate and “calibrate out” the drift.This pull request implements a variation on the
RTC_Millis
idea with adjustable drift, but based onmicros()
instead ofmillis()
. It provides the methodthat can be used to tune the drift with 1 ppm resolution. A finer resolution would not be useful, as the frequency of the ceramic resonator is not very stable and can change by more than 1 ppm in just an hour.
The only drawback of this
RTC_Micros
class is that thenow()
method has to be called at least once every 71.58 minutes in order to prevent rollover issues.Note that this pull request depends on #92: Make RTC_Millis immune to millis() rollover events. The reason is that it is essential for
RTC_Micros
to be immune to rollover events, and it would make little sense to have this class alongside anRTC_Millis
that suffers from a rollover bug.