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()
411
411
#### Parameters
412
412
413
413
None
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
54
54
55
55
standbyMode KEYWORD2
56
56
57
+ setFrequencyCorrection KEYWORD2
58
+
57
59
#######################################
58
60
# Constants (LITERAL1)
59
61
#######################################
Original file line number Diff line number Diff line change @@ -464,6 +464,34 @@ void RTCZero::configureClock() {
464
464
;
465
465
}
466
466
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
+
467
495
/*
468
496
* Private Utility Functions
469
497
*/
Original file line number Diff line number Diff line change 22
22
23
23
#include " Arduino.h"
24
24
25
+ #define RTCZERO_FREQCORR (_CORR_ ) (_CORR_ * 240 * 4096 )
26
+
25
27
typedef void (*voidFuncPtr)(void );
26
28
27
29
class RTCZero {
@@ -88,6 +90,8 @@ class RTCZero {
88
90
void setAlarmMonth (uint8_t month);
89
91
void setAlarmYear (uint8_t year);
90
92
void setAlarmDate (uint8_t day, uint8_t month, uint8_t year);
93
+
94
+ void setFrequencyCorrection (int8_t correction);
91
95
92
96
/* Epoch Functions */
93
97
You can’t perform that action at this time.
0 commit comments