What To Do When RTC Clock Experiences Delays or Timeouts?

Introduction

When an embedded system is running, the RTC clock can be affected by various factors leading to delays or timeouts, impacting system time synchronization and functionality stability. This article will propose a comprehensive solution ranging from hardware adaptation to software algorithm optimization to address this issue, ensuring the accuracy and reliability of the RTC clock.

The main reason for delays and timeouts is that the reference frequency of 32.768 kHz used by the timing system is not accurate enough.
The RTC function circuit integrated within the MCU generally has poor measurement accuracy and high power consumption due to the influence of chip integration technology. Therefore, when high clock accuracy is required, it is recommended to directly use external dedicated RTC clock chips, such as PCF8563/PCF85063. The table below lists the clock accuracy of different RTC chips.

What To Do When RTC Clock Experiences Delays or Timeouts?

Figure 1 Clock Accuracy of Different RTC Chips
After selecting a high-precision RTC clock chip, it is also necessary to ensure that the matching capacitance of the 32.768 kHz crystal oscillator meets the requirements of the crystal oscillator design manual.

What To Do When RTC Clock Experiences Delays or Timeouts?

Figure 2 Matching Capacitance of Crystal Oscillator
The formula for calculating the load capacitance CL is:
What To Do When RTC Clock Experiences Delays or Timeouts?
Where:CL1, CL2:Matching capacitance of the crystal oscillator;Cstray:Stray capacitance of the circuit board

What To Do When RTC Clock Experiences Delays or Timeouts?

Figure 3 Connection Method and Device Parameters of the Crystal
Substituting values:CL = [(15*15)/(15+15)] + 5 = 12.5 pF
The above optimization through hardware circuit design improves clock accuracy, but due to production processes, chip differences, and other uncontrollable factors, the actual clock accuracy may deviate. Under stable clock frequency offset conditions, clock accuracy can be further compensated through software methods, such as setting the compensation register inside the RTC to adjust the time.
The basic principle of the compensation register is to compensate for time by adding or reducing clock correction pulses instead of changing the frequency of the crystal oscillator. As shown in Figure 4, the bit7 of the compensation register sets the compensation mode, while bit[6:0] sets the compensation value.

What To Do When RTC Clock Experiences Delays or Timeouts?

Figure 4 Description of Compensation Register

1. Compensation Value Calculation Method One
The calculation process is shown in Figure 5.

What To Do When RTC Clock Experiences Delays or Timeouts?

Figure 5 Compensation Value Calculation Method One
  1. First, use a frequency counter or high-precision oscilloscope to measure the frequency Fmeas of the PCF8563 chip pin 7 CLKOUT (the software must set pin 7 output to measure the waveform);
  2. Convert it into time tmeas;
  3. Calculate the deviation Dmeas from the ideal clock period of 32.768 kHz;
  4. Calculate the ppm offset based on the measured value;
  5. Calculate the value of the compensation register based on the set mode. For example, the ppm offset calculated from 32768.48 Hz is 14.648 ppm. If it is mode 0, the calculated compensation value is 3.375, rounded to 3.
Based on the formula for compensation calculation, if the measured actual frequency is Factual, the ppm offset Eppm can be quickly calculated using the following formula:

What To Do When RTC Clock Experiences Delays or Timeouts?

As shown in the above compensation calibration calculation framework, the value calculated from 32768.48 Hz is also 14.648.
It can be seen that if Factual ≥ 32768 Hz, then the calculated compensation value ≥ 0; if Factual < 32768 Hz, then the calculated compensation value < 0.

2. Compensation Value Calculation Method Two

What To Do When RTC Clock Experiences Delays or Timeouts?

Figure 6 Compensation Value Calculation Method Two
As shown in Figure 6, a ±20 ppm oscillator frequency deviation of 1 ppm will lead to a daily deviation of 0.0864 s.
In the absence of testing conditions for measuring frequency, one can first test the time deviation over 24 hours. If the time is fast, the compensation is positive; if the time is slow, the compensation is negative. For example, if a certain RTC measures 7 seconds faster than Beijing time over 24 hours, then the ppm offset Eppm = 7/0.0864 = 81.0185 ppm, then the compensation register value under mode 0 is 81.0185/4.34 = 18.67, rounded to 19; the compensation register value under mode 1 is 81.0185/4.069 = 19.9119, rounded to 20.
Similarly, if a certain RTC measures 7 seconds slower than Beijing time over 24 hours, then the ppm offset Eppm = 7/0.0864 = 81.0185 ppm, then the compensation register value under mode 0 is 81.0185/4.34 = 18.67, rounded to -19; the compensation register value under mode 1 is 81.0185/4.069 = 19.91, rounded to -20.

Note: The calculation method for 0.0864 s is as follows: the unit of ppm is one millionth, so a deviation of 20 ppm in one day is described as (24 hours * 60 minutes * 60 seconds * 20) / 10^6 = 1.728 s, thus the deviation time for 1 ppm in one day is 1.728 s / 20 = 0.0864 s. Other oscillator accuracies can also be estimated using this method.

If the product has high RTC accuracy requirements and using conventional RTCs with the above calibration/compensation still does not meet product requirements, one needs to consider selecting high-precision RTC chips, such as RX8025T.

What To Do When RTC Clock Experiences Delays or Timeouts?

ZLG Innovative CPM Core Board

  • RZ/G2UL, RZ/G2L Processor

  • 1.0/1.2 GHz Main Frequency

  • Cortex®-A55 + Cortex®-M33

Reference Price: Starting from 99 Yuan

Click to Buy

What To Do When RTC Clock Experiences Delays or Timeouts?
What To Do When RTC Clock Experiences Delays or Timeouts?
What To Do When RTC Clock Experiences Delays or Timeouts?
What To Do When RTC Clock Experiences Delays or Timeouts?
What To Do When RTC Clock Experiences Delays or Timeouts?
What To Do When RTC Clock Experiences Delays or Timeouts?
What To Do When RTC Clock Experiences Delays or Timeouts?
What To Do When RTC Clock Experiences Delays or Timeouts?
What To Do When RTC Clock Experiences Delays or Timeouts?

Leave a Comment