SPRUJD4A December 2024 – November 2025 AM62D-Q1
In order to compensate for any inaccuracy of the 32768Hz oscillator, the host processor can calibrate the oscillator frequency and program a compensation value in order to adjust for any individual characteristics of the oscillator crystal. If automatic crystal compensation is enabled by programming a non-zero value to the RTC_COMP register, then some seconds are extended or shortened by a number of counts of the 32KHz clock. The compensation value is used every 4096 seconds, just before or just after letting the sub-second time counter roll over. The overall function of this is to add or subtract up to 32766 periods of the 32KHz clock from the evaluated duration of 4096 seconds. This lets the compensation add or subtract counts to deal with up to a 0.024% defect in crystal frequency, or about one second per hour.
If compensation is enabled and the sub-second time counter is about to roll over at a 4096th count of the seconds counter, then the compensation value is evaluated. If the compensation value is a positive two’s complement value (0x0001 to 0x7FFE), then time will jump from (N seconds plus 0x7FFF sub-seconds) to (N+1 seconds plus COMP sub-seconds). This means that a positive compensation value makes the time value “skip forwards”. The compensated sub-second count is subtracted from the next second. If the compensation value is a negative two’s complement value (0x8001 to 0xFFFF), then time will “hold back” instead. In that case, time will go from (N seconds plus 0x7FFF sub-seconds) to (N seconds plus COMP[15:0] sub-seconds). The compensated sub-second count is added to the second currently in progress.
If using RTC to measure a time interval of less than two seconds, there may be an uncertainty of up to one second if the time interval includes an evaluation of the crystal compensation value. Software should be aware of the crystal compensation settings when programming the RTC OFF_ON and ON_OFF timers so that these timers expire close to the intended time instead of being affected by the compensation settings.