A temperature compensation method for an RTC clock chip
By training a crystal oscillator frequency prediction model for the RTC clock chip and using machine learning algorithms to generate a frequency compensation model, the problem of temperature drift of the RTC clock chip in complex environments was solved, achieving high-precision timing and billing accuracy.
Patent Information
- Application Number
- CN202610551698.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-04-24
- Publication Date
- 2026-06-26
AI Technical Summary
Existing RTC clock chips are susceptible to temperature fluctuations under complex environmental conditions, which can cause clock signal frequency drift, affecting timing accuracy and billing accuracy.
By establishing a crystal oscillator frequency prediction model for RTC clock chips, using machine learning algorithms to train the crystal oscillator frequency under different environments and on-chip temperatures, setting iteration termination conditions, generating the final frequency compensation model, and correcting the crystal oscillator frequency in real time.
Significantly improves the timing accuracy of the RTC clock chip, offsets temperature drift, and ensures accurate billing.
Smart Images

Figure CN122286310A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of electronic oscillator technology, specifically to a training method for a crystal oscillator frequency prediction model of an RTC clock chip and a temperature compensation method for an RTC clock chip. Background Technology
[0002] Currently, the billing schemes in the charging pile market are generally based on multiple factors such as time, electricity consumption, power, and service fees to calculate costs.
[0003] However, market feedback collected indicates that most operating sites are outdoor sites, which are exposed to complex environmental conditions for a long time, including interference from altitude, humidity, and electromagnetic radiation. Especially in areas with significant day-night or seasonal temperature variations, the built-in crystal oscillator in the widely used RTC (real-time clock) chips is susceptible to temperature fluctuations, causing the clock signal frequency to drift. This results in a significant deviation in the long-term accuracy of timekeeping, ultimately affecting the accuracy of billing. Summary of the Invention
[0004] The purpose of this invention is to provide a temperature compensation method for an RTC clock chip. The embodiments of this invention can solve or at least partially solve the above-mentioned defects of the prior art.
[0005] To achieve the above objectives, a first aspect of the present invention provides a training method for an RTC clock chip crystal oscillator frequency prediction model, the training method comprising: S1. Based on the crystal oscillator frequency of the RTC clock chip measured at different ambient temperatures, and the following parameters corresponding to the RTC clock chip: standard crystal oscillator frequency and standard reference temperature, establish the first training data; S2. A first prediction model is obtained by training the first training data using a machine learning algorithm. The first prediction model is used to predict the crystal frequency of the RTC clock chip at a selected ambient temperature. S3. Based on the crystal oscillator frequency of the RTC clock chip measured at different on-chip temperatures, and the following parameters corresponding to the RTC clock chip: standard crystal oscillator frequency and standard reference temperature, establish second training data; S4. A second prediction model is obtained by training the second training data using a machine learning algorithm. The second prediction model is used to predict the crystal frequency of the RTC clock chip at a selected on-chip temperature. S5. When the coefficient vector of the second prediction model does not meet the preset iteration termination condition, perform the following operations iteratively on the second prediction model until the coefficient vector of the second prediction model meets the preset iteration termination condition: The model coefficient vector of the second prediction model is updated by using a machine learning algorithm to train the second training data. S6. Configure the second prediction model as the final model output for predicting the crystal oscillator frequency of the RTC clock chip; The preset iteration termination condition includes: the difference between the elements at each corresponding position of the coefficient vector of the second prediction model and the coefficient vector of the first prediction model satisfies the preset tolerance condition.
[0006] Optionally, the first prediction model is determined according to the following formula: According to ambient temperature The following parameters correspond to the RTC clock chip: standard crystal frequency. and standard reference temperature The following formula is used to determine the ambient temperature of the RTC clock chip. crystal oscillator frequency ; ; in, , and These are coefficient parameters.
[0007] Optionally, the second prediction model is determined according to the following formula: Based on on-chip temperature The following parameters correspond to the RTC clock chip: standard crystal frequency. and standard reference temperature The following formula is used to determine the on-chip temperature of the RTC clock chip. crystal oscillator frequency : in, , and These are coefficient parameters.
[0008] Optionally, the difference between the coefficient vector of the second prediction model and the coefficient vector of the first prediction model at each corresponding position satisfies a preset tolerance condition, including: The coefficient parameters of the second prediction model: , and Coefficient parameters of the first prediction model , and The following relationship must be satisfied: in, This is the preset tolerance threshold.
[0009] Optionally, the temperature sampling points corresponding to the ambient temperature include: -40℃, 0℃, and 85℃.
[0010] Optionally, the crystal oscillator frequency of the RTC clock chip is determined by a frequency counter or a digital oscilloscope.
[0011] Optionally, the preset tolerance condition includes: the absolute value of the difference between the coefficient vector of the second prediction model and the coefficient vector of the first prediction model at each corresponding position is less than the preset tolerance threshold.
[0012] A second aspect of this invention provides a temperature compensation method for an RTC clock chip, the temperature compensation method comprising: Obtain the on-chip temperature of the target RTC clock chip; Substitute the following parameters corresponding to the target RTC clock chip—on-chip temperature, standard reference temperature, and standard crystal frequency—into the prediction model to determine the actual crystal frequency corresponding to the target RTC clock chip. And when the actual crystal oscillator frequency is different from the standard crystal oscillator frequency, perform temperature compensation operation on the target RTC clock chip based on the actual crystal oscillator frequency; The prediction model is obtained through the training method of the RTC clock chip crystal oscillator frequency prediction model described above.
[0013] A third aspect of the present invention provides a machine-readable storage medium storing instructions that cause a machine to execute the above-described RTC clock chip temperature compensation method. Attached Figure Description
[0014] The accompanying drawings are provided to further illustrate embodiments of the present invention and form part of the specification. They are used together with the following detailed description to explain the embodiments of the present invention, but do not constitute a limitation thereof. In the drawings: Figure 1 A flowchart illustrating the training method for the RTC clock chip crystal oscillator frequency prediction model provided by the present invention is shown. Figure 2 A schematic flowchart of the temperature compensation method for the RTC clock chip provided by the present invention is shown. Figure 3 A schematic diagram of the structure of the RTC clock chip provided by the present invention is shown. Detailed Implementation
[0015] To better understand the above-mentioned objectives, features, and advantages of the present invention, the present invention will be further described in detail below with reference to the accompanying drawings and specific embodiments. It should be noted that, unless otherwise specified, the embodiments and features described in these embodiments can be combined with each other.
[0016] Many specific details are set forth in the following description in order to provide a full understanding of the invention. However, the invention may also be practiced in other ways different from those described herein, and therefore the scope of protection of the invention is not limited to the specific embodiments disclosed below.
[0017] Figure 1 The diagram illustrates a flowchart of the training method for the RTC clock chip crystal oscillator frequency prediction model provided by this invention. Figure 1 As shown, this invention discloses a training method for an RTC clock chip crystal oscillator frequency prediction model, which may include the following steps S101 to S106: S101. Based on the crystal oscillator frequency of the RTC clock chip measured at different ambient temperatures, and the following parameters corresponding to the RTC clock chip: standard crystal oscillator frequency and standard reference temperature, establish the first training data. Specifically, an RTC clock chip is a dedicated integrated circuit that provides independent real-time timing functionality. The RTC clock chip uses a 32.768kHz quartz crystal as its "heart," providing the fundamental frequency. An internal oscillation circuit drives the crystal, and a frequency divider chain converts it into a second signal, driving the time and date register to accumulate.
[0018] The standard crystal oscillator frequency of the RTC clock chip is 32.768kHz. ,Will After inputting a 15-level binary frequency divider (counter), the output frequency is exactly 1Hz, which is exactly the "second" signal we need.
[0019] Furthermore, the standard reference temperature of the RTC clock chip refers to the ambient temperature at which the output frequency of the RTC clock chip is most accurate and closest to its standard crystal oscillator frequency. At this temperature, the frequency deviation of the crystal oscillator is minimal. The standard reference temperature of the RTC clock chip is typically 25°C, but due to differences in crystal oscillator design and manufacturing processes, some RTC clock chips may choose 23°C or 27°C as their standard reference temperature.
[0020] In some embodiments of this example, the selected RTC clock chip is placed in an adjustable temperature high and low temperature chamber, and four temperature sampling values are selected: -40°C, 0°C, 25°C, and 85°C. -40°C represents the most severe low-temperature operating condition; 25°C represents the industrial standard room temperature, typically the standard reference temperature for crystal oscillators, at which the chip should exhibit optimal accuracy; and 85°C represents the most severe high-temperature operating condition. Further, the crystal oscillator frequency corresponding to each of the four temperature sampling values is determined in the following manner: For each of the four temperature sampling values mentioned above: set the ambient temperature of the high and low temperature chamber to that value. Once the temperature inside the chamber reaches and stabilizes at that value, measure and record the crystal oscillator frequency of the selected RTC clock chip at that temperature value every 30 minutes using a frequency counter or digital oscilloscope. After four measurements, calculate the average crystal oscillator frequency from the four measurements, and finally use the average crystal oscillator frequency as the crystal oscillator frequency corresponding to that temperature value.
[0021] In some implementations of this embodiment, the established first training data is standardized (e.g., Z-Score standardization or Min-Max normalization) and denoised (e.g., statistical filtering or median filtering). Standardization can scale data with different features to a similar numerical range (e.g., mean 0, variance 1), thereby accelerating model convergence and improving training efficiency. Denoising, on the other hand, identifies and removes errors, anomalies, or irrelevant fluctuations in the first training data to preserve the true signal, thereby improving the robustness and reliability of the model and preventing overfitting.
[0022] S102. A first prediction model is obtained by training the first training data using a machine learning algorithm. The first prediction model is used to predict the crystal frequency of the RTC clock chip at a selected ambient temperature. In some embodiments of this example, the first prediction model is a multinomial model, based on the ambient temperature. The following parameters correspond to the RTC clock chip: standard crystal frequency. and standard reference temperature The following formula is used to determine the ambient temperature of the RTC clock chip. crystal oscillator frequency ; ; (1) in, , and These are coefficient parameters.
[0023] It can be understood that the coefficient vector corresponding to formula (1) It can be represented in the following vector form: S103. Based on the crystal oscillator frequency of the RTC clock chip measured at different on-chip temperatures, and the following parameters corresponding to the RTC clock chip: standard crystal oscillator frequency and standard reference temperature, establish second training data. The on-chip temperature of the RTC clock chip refers to the temperature output by the RTC clock chip with temperature sampling, or it can be the local ambient temperature inside the RTC clock chip obtained by an external temperature sampling module.
[0024] Specifically, the selected RTC clock chip is placed in an adjustable temperature high and low temperature chamber, and multiple on-chip temperature sampling points are determined at 5°C intervals, such as -10°C, -5°C, 0°C, 5°C, 10°C, and 15°C. Further, the crystal oscillator frequency corresponding to each temperature value among the above multiple on-chip temperature sampling points is determined using the following method: The on-chip temperature of the selected RTC clock chip is acquired using a temperature detection module. The temperature of the high and low temperature chamber is adjusted to ensure the on-chip temperature of the selected RTC clock chip reaches and stabilizes at that temperature. Every 25 minutes, the crystal oscillator frequency of the selected RTC clock chip at that on-chip temperature is measured using a frequency counter or digital oscilloscope and recorded. After three measurements, the average crystal oscillator frequency of the three measurements is calculated, and this average frequency is taken as the crystal oscillator frequency corresponding to that temperature value.
[0025] S104. A second prediction model is obtained by training the second training data using a machine learning algorithm. The second prediction model is used to predict the crystal frequency of the RTC clock chip at a selected on-chip temperature. In some embodiments of this example, the second prediction model is a multinomial model, and the second prediction model is determined according to the following formula: Based on on-chip temperature The following parameters correspond to the RTC clock chip: standard crystal frequency. and standard reference temperature The following formula is used to determine the on-chip temperature of the RTC clock chip. crystal oscillator frequency : (2) in, , and These are coefficient parameters.
[0026] It can be understood that the coefficient vector corresponding to formula (2) It can be represented in the following vector form: In the specific implementation of step S104, the coefficient parameters of the second prediction model , and The solution can be obtained by fitting using the least squares method or by using the gradient descent algorithm.
[0027] S105. When the coefficient vector of the second prediction model does not meet the preset iteration termination condition, perform the following operations iteratively on the second prediction model until the coefficient vector of the second prediction model meets the preset iteration termination condition: The model coefficient vector of the second prediction model is updated by using a machine learning algorithm to train the second training data. The preset iteration termination condition in step S105 includes: the difference between the elements at each corresponding position of the coefficient vector of the second prediction model and the coefficient vector of the first prediction model satisfies the preset tolerance condition.
[0028] In some embodiments of this example, the preset tolerance condition includes: the absolute value of the difference between the coefficient vector of the second prediction model and the coefficient vector of the first prediction model at each corresponding position is less than a preset tolerance threshold. Further, combining the coefficient vector corresponding to formula (1) The coefficient vector corresponding to formula (2) For example: The coefficient parameters of the second prediction model are: , and Coefficient parameters of the first prediction model , and The coefficient vector of the second prediction model is deemed to satisfy the iteration termination condition when the following relationship is met: (3) in, This is the preset tolerance threshold.
[0029] In some implementations of this embodiment, the coefficient parameters of the second prediction model are: , and Coefficient parameters of the first prediction model , and The coefficient vector of the second prediction model is deemed to satisfy the iteration termination condition when the following relationship is met: (4) In formula (4), Indicates the magnification factor. Indicates to Round down. Indicates to Round down. Indicates to Rounding down is performed in the specific implementation process. The preferred value is 100.
[0030] In some implementations of this embodiment, the coefficient parameters of the second prediction model are: , and Coefficient parameters of the first prediction model , and The coefficient vector of the second prediction model is deemed to satisfy the iteration termination condition when the following relationship is met: (5) In formula (5), This indicates a preset relative tolerance; in the actual implementation process, The preferred value is 0.01.
[0031] S106. Configure the second prediction model as the final model output for predicting the crystal oscillator frequency of the RTC clock chip; It should be noted that the first prediction model proposed in this embodiment aims to determine the iteration termination condition of the model coefficient parameters of the second prediction model, while the second prediction model serves as the frequency compensation model deployed when it is finally applied to the RTC clock chip.
[0032] Figure 2 A schematic flowchart of the temperature compensation method for the RTC clock chip provided by the present invention is shown, as follows: Figure 2 As shown, this embodiment of the invention also provides a temperature compensation method for an RTC clock chip, the temperature compensation method comprising the following steps S201 to S203: S201. Collect the on-chip temperature of the target RTC clock chip; Specifically, on-chip temperature refers to the local ambient temperature inside the chip (especially near the crystal oscillator) as measured by the temperature sensor integrated inside the RTC clock chip.
[0033] S202. Substitute the following parameters corresponding to the target RTC clock chip: on-chip temperature, standard reference temperature and standard crystal frequency into the prediction model to determine the actual crystal frequency corresponding to the target RTC clock chip. It should be noted that the prediction model mentioned in step S202 is obtained through the training method of the RTC clock chip crystal oscillator frequency prediction model described above. Specifically, it refers to the prediction model finally output by the training method of the RTC clock chip crystal oscillator frequency prediction model described above, namely the second prediction model.
[0034] In the specific implementation process, the actual crystal oscillator frequency can be obtained from the target RTC clock chip through either method one or method two: Method 1: The prediction model is stored in the memory of the target RTC clock chip in advance. When the target RTC clock chip is working, its internal temperature sensor measures the on-chip temperature in real time. The processor queries the prediction model based on the on-chip temperature and calculates the actual crystal oscillator frequency.
[0035] Method 2: A mapping table of the actual crystal oscillator frequencies of the target RTC clock chip at different on-chip temperatures is pre-calculated based on the prediction model and stored in the memory of the target RTC clock chip. When the target RTC clock chip is working, its internal temperature sensor measures the on-chip temperature in real time, and the processor retrieves the actual crystal oscillator frequency corresponding to the on-chip temperature from the mapping table based on the on-chip temperature.
[0036] S203. When the actual crystal oscillator frequency is different from the standard crystal oscillator frequency, perform temperature compensation operation on the target RTC clock chip based on the actual crystal oscillator frequency. Specifically, when the target RTC clock chip is working, it calculates the instantaneous frequency deviation by comparing the actual crystal oscillator frequency with the standard crystal oscillator frequency, and corrects the output clock frequency in real time by adjusting the divisor of the clock divider or the load capacitance of the oscillation circuit, thereby offsetting temperature drift and achieving high-precision timing across the entire temperature range.
[0037] Figure 3 A schematic diagram of the structure of the RTC clock chip provided by the present invention is shown, as follows: Figure 3 As shown, this invention discloses an RTC clock chip, comprising: Temperature sampling module: used to acquire the analog signal corresponding to the on-chip temperature of the RTC clock chip; Memory: Used to store prediction models; It should be noted that the prediction model can be stored in storage units such as EEPROM / FLASH, or it can be stored in the internal storage units of the core processor MCU.
[0038] The prediction model is the output model obtained through the training method of the RTC clock chip crystal oscillator frequency prediction model (specifically, the second prediction model mentioned above).
[0039] The core processor MCU converts the analog signal corresponding to the on-chip temperature acquired by the temperature sampling module into a digital value through an analog-to-digital converter (ADC); and The actual crystal oscillator frequency is calculated based on the digital value corresponding to the on-chip temperature and the prediction model stored in the memory. The compensation amount is determined based on the actual crystal oscillator frequency and the standard crystal oscillator frequency and compensation is performed directly to ensure accurate timekeeping. RTC quartz crystal oscillator: used to provide a reference frequency signal.
[0040] Understandable, such as Figure 3 The structure of the RTC clock chip shown is an RTC clock chip that integrates all functions. In the specific implementation process, various modules can also be used for sampling and calibration in discrete combinations.
[0041] This invention also provides a machine-readable storage medium storing instructions that cause a machine to execute the aforementioned RTC clock chip temperature compensation method.
[0042] The training method for the RTC clock chip crystal oscillator frequency prediction model provided in this invention establishes a first prediction model by measuring the crystal oscillator frequency of the RTC clock chip at different ambient temperatures, establishes a second prediction model by measuring the crystal oscillator frequency of the RTC clock chip at different on-chip temperatures, and limits the iteration termination condition of the second prediction model according to the coefficient parameters of the first prediction model. Finally, the second prediction model that meets the iteration termination condition is used as the frequency compensation model deployed when it is finally applied to the RTC clock chip. This method can significantly improve the accuracy of the RTC clock chip and combat temperature drift.
[0043] The optional embodiments of the present invention have been described in detail above with reference to the accompanying drawings. However, the embodiments of the present invention are not limited to the specific details in the above embodiments. Within the scope of the technical concept of the embodiments of the present invention, various simple modifications can be made to the technical solutions of the embodiments of the present invention, and these simple modifications all fall within the protection scope of the embodiments of the present invention.
[0044] It should also be noted that the various specific technical features described in the above embodiments can be combined in any suitable manner without contradiction. To avoid unnecessary repetition, the embodiments of the present invention will not describe the various possible combinations separately.
[0045] Those skilled in the art will understand that all or part of the steps in the methods of the above embodiments can be implemented by a program instructing related hardware. This program is stored in a storage medium and includes several instructions to cause a microcontroller, chip, or processor to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes: a USB flash drive, a portable hard drive, and a read-only memory (ROM). Various media that can store program code, such as only memory, random access memory (RAM), magnetic disks or optical disks.
[0046] Furthermore, various different implementations of the present invention can be combined arbitrarily, as long as they do not violate the spirit of the present invention, they should also be regarded as the content disclosed in the present invention.
Claims
1. A method for training an RTC clock chip crystal frequency prediction model, characterized in that, The training method comprises: S1, establishing first training data according to the crystal oscillator frequency of the RTC clock chip measured at different environmental temperatures and the following parameters corresponding to the RTC clock chip: standard crystal oscillator frequency and standard reference temperature; S2, training the first training data by using a machine learning algorithm to obtain a first prediction model, the first prediction model being used to predict the crystal oscillator frequency of the RTC clock chip at a selected environmental temperature; S3, establishing second training data according to the crystal oscillator frequency of the RTC clock chip measured at different on-chip temperatures and the following parameters corresponding to the RTC clock chip: standard crystal oscillator frequency and standard reference temperature; S4, training the second training data by using a machine learning algorithm to obtain a second prediction model, the second prediction model being used to predict the crystal oscillator frequency of the RTC clock chip at a selected on-chip temperature; S5, when the coefficient vector of the second prediction model does not satisfy a preset iteration termination condition, iteratively performing the following operations on the second prediction model until the coefficient vector of the second prediction model satisfies the preset iteration termination condition: training the second training data by using a machine learning algorithm to update the model coefficient vector of the second prediction model; S6, configuring the second prediction model as a final model output for predicting the crystal oscillator frequency of the RTC clock chip; The preset iteration termination condition comprises that the difference between the elements at each corresponding position of the coefficient vector of the second prediction model and the coefficient vector of the first prediction model satisfies a preset tolerance condition.
2. The training method of claim 1, wherein, The first prediction model is determined according to the following formula: According to the ambient temperature , the following parameters corresponding to the RTC clock chip: standard crystal frequency and standard reference temperature and the following formula, the crystal frequency of the RTC clock chip at ambient temperature ; ; wherein , and are coefficient parameters.
3. The training method of claim 2, wherein, The second prediction model is determined according to the following formula: According to the on-chip temperature , the following parameters corresponding to the RTC clock chip: standard crystal frequency and standard reference temperature and the following formula, the crystal frequency of the RTC clock chip at the on-chip temperature : wherein , and are coefficient parameters.
4. The training method of claim 3, wherein, The difference between the elements at each corresponding position of the coefficient vector of the second prediction model and the coefficient vector of the first prediction model satisfies a preset tolerance condition, which comprises: coefficient parameters of the second prediction model: , and coefficient parameters of the first prediction model , and satisfy the following relationships: wherein is a preset tolerance threshold.
5. The training method of claim 1, wherein, The temperature sampling points corresponding to the environmental temperature include: -40℃, 0℃ and 85℃.
6. The training method of claim 1, wherein, The crystal oscillator frequency of the RTC clock chip is measured by a frequency counter or a digital oscilloscope.
7. The training method of claim 1, wherein, The preset tolerance condition comprises that the absolute value of the difference between the elements at each corresponding position of the coefficient vector of the second prediction model and the coefficient vector of the first prediction model is less than a preset tolerance threshold.
8. A temperature compensation method of an RTC clock chip, characterized in that, The temperature compensation method comprises: obtaining the on-chip temperature of a target RTC clock chip; substituting the following parameters corresponding to the target RTC clock chip: the on-chip temperature, the standard reference temperature and the standard crystal oscillator frequency into a prediction model to determine the actual crystal oscillator frequency corresponding to the target RTC clock chip; and when the actual crystal oscillator frequency is different from the standard crystal oscillator frequency, performing a temperature compensation operation on the target RTC clock chip based on the actual crystal oscillator frequency; The prediction model is obtained by the training method of the RTC clock chip crystal oscillator frequency prediction model in any one of claims 1 to 7.
9. A machine-readable storage medium, characterized in that, The machine-readable storage medium stores instructions for causing a machine to execute the RTC clock chip temperature compensation method according to claim 8.