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

Implement RTC_Micros with tunable drift #112

Merged
merged 4 commits into from Jul 1, 2019
Merged

Implement RTC_Micros with tunable drift #112

merged 4 commits into from Jul 1, 2019

Conversation

edgar-bonet
Copy link
Contributor

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 on micros() instead of millis(). It provides the method

void RTC_Micros::adjustDrift(int ppm);

that 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 the now() 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 an RTC_Millis that suffers from a rollover bug.

This is identical to RTC_Millis, except for:

 * The method now() has to be called more often than once every 71.6
   minutes.
 * The clock can be syntonized (i.e. its drift tuned) with a 1 ppm
   resolution using adjustDrift(): a positive adjustment makes the clock
   faster.

Note that syntonization does not introduce time discontinuities.
@drak7 drak7 merged commit 3f7d2e2 into adafruit:master Jul 1, 2019
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

Successfully merging this pull request may close these issues.

None yet

2 participants