File tree Expand file tree Collapse file tree 4 files changed +48
-0
lines changed Expand file tree Collapse file tree 4 files changed +48
-0
lines changed Original file line number Diff line number Diff line change @@ -411,3 +411,17 @@ rtc.standbyMode()
411411#### Parameters
412412
413413None
414+
415+ ### ` setFrequencyCorrection() `
416+
417+ Set the RTC frequency correction value. A positive value reduces the frequency, a negative value will increase the frequency.
418+
419+ #### Syntax
420+
421+ ``` arduino
422+ rtc.setFrequencyCorrection(int8_t correction)
423+ ```
424+
425+ #### Parameters
426+
427+ - correction: the number of counts to be increased or decreasd periodically by the RTC frequency correction module.
Original file line number Diff line number Diff line change @@ -54,6 +54,8 @@ disableAlarm KEYWORD2
5454
5555standbyMode KEYWORD2
5656
57+ setFrequencyCorrection KEYWORD2
58+
5759#######################################
5860# Constants (LITERAL1)
5961#######################################
Original file line number Diff line number Diff line change @@ -464,6 +464,34 @@ void RTCZero::configureClock() {
464464 ;
465465}
466466
467+ /*
468+ * From: SAM D21 Family Datasheet - Chapter 19.6.9.2
469+ * ============================================================================
470+ * Correction[ppm] = (FREQCORR.VALUE / 4096 * 240) * 10^6 ppm
471+ *
472+ * FREQCORR.VALUE = (correction[ppm] * 4096 * 240) / 10^6 = correction * 4096 * 240
473+ *
474+ * Example:
475+ * Correction = 1s / 24h = 1s / 86400s = 1/86400
476+ * FREQCORR.VALUE = 1/86400 * 4096 * 240 = 11
477+ */
478+
479+ void RTCZero::setFrequencyCorrection (int8_t correction)
480+ {
481+ if (correction == 0 || correction == -128 ) {
482+ return ;
483+ }
484+
485+ uint8_t sign = (correction & 0x80 );
486+
487+ if (correction < 0 ) {
488+ correction *= -1 ;
489+ }
490+
491+ while (RTC->MODE2 .STATUS .bit .SYNCBUSY );
492+ RTC->MODE2 .FREQCORR .reg = sign | correction;
493+ }
494+
467495/*
468496 * Private Utility Functions
469497 */
Original file line number Diff line number Diff line change 2222
2323#include " Arduino.h"
2424
25+ #define RTCZERO_FREQCORR (_CORR_ ) (_CORR_ * 240 * 4096 )
26+
2527typedef void (*voidFuncPtr)(void );
2628
2729class RTCZero {
@@ -88,6 +90,8 @@ class RTCZero {
8890 void setAlarmMonth (uint8_t month);
8991 void setAlarmYear (uint8_t year);
9092 void setAlarmDate (uint8_t day, uint8_t month, uint8_t year);
93+
94+ void setFrequencyCorrection (int8_t correction);
9195
9296 /* Epoch Functions */
9397
You can’t perform that action at this time.
0 commit comments