Real-time clock adaptive digital temperature compensation method, equipment, medium and product

By constructing an initial static compensation model and combining it with an external absolute time source for dynamic correction, the digital fine-tuning register value is adaptively adjusted, solving the problem of insufficient timing accuracy caused by crystal aging and stress changes in traditional real-time clocks, and achieving high-precision and reliable real-time clock compensation.

CN121923593APending Publication Date: 2026-04-24RAYSTAR MICROELECTRONICS TECHNOLOGY CO LTD
View PDF 5 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
RAYSTAR MICROELECTRONICS TECHNOLOGY CO LTD
Filing Date
2026-01-13
Publication Date
2026-04-24

Smart Images

  • Figure CN121923593A_ABST
    Figure CN121923593A_ABST
Patent Text Reader

Abstract

The invention discloses a real-time clock adaptive digital temperature compensation method, equipment, a medium and a product, and relates to the field of real-time clocks. The method comprises the following steps: measuring a digital fine tuning register value enabling the output frequency of a real-time clock to reach a target frequency under a plurality of reference temperature points, generating digital fine tuning register reference data covering a complete working temperature range based on the symmetry of a crystal frequency temperature curve, and constructing a static compensation model; in the running process of the real-time clock, dynamically correcting reference data in the static compensation model by acquiring reference time and local time, calculating a time error and combining a temperature distribution condition to obtain a self-adaptive updated compensation model; and obtaining a target digital fine tuning register value from the corrected model according to the current temperature, and compensating the output frequency of the real-time clock. The problem that a traditional fixed compensation model cannot cope with crystal aging and stress changes can be relieved, and the long-term timing precision and reliability of a real-time clock are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of real-time clock technology, and in particular to a real-time clock adaptive digital temperature compensation method, device, medium, and product. Background Technology

[0002] Real-Time Clock (RTC) circuits are key components in electronic systems, providing a continuous and accurate time reference. They are widely used in automotive electronics, industrial control, and IoT devices—fields requiring precise timing. The core frequency source of an RTC typically uses a quartz crystal resonator. However, the crystal's oscillation frequency drifts significantly with changes in ambient temperature, becoming a major factor limiting RTC accuracy. Therefore, temperature compensation of the RTC to counteract timing errors caused by temperature drift is essential for achieving high-precision timing.

[0003] In traditional temperature compensation schemes, a common practice is to test the frequency characteristics of the RTC at different temperatures during the production phase and generate a fixed temperature-frequency compensation model (e.g., a lookup table or compensation coefficients) based on this, which is then stored in the chip's memory. When the device is operating, the system detects the current ambient temperature and queries this fixed model to obtain the corresponding compensation value, adjusting the RTC's output frequency in real time.

[0004] However, such compensation methods based on fixed models have an inherent limitation: their compensation data cannot be updated after the chip leaves the factory. In practical applications, crystal resonators experience irreversible aging drift due to prolonged operation. Simultaneously, the mechanical stress experienced by the chip during soldering and assembly introduces individual differences in frequency characteristics. These factors, which change dynamically with time and usage conditions, cause the fixed compensation model calibrated at the factory to gradually deviate from reality. This makes it difficult to guarantee the long-term timing accuracy of the RTC, failing to meet the long-term accuracy requirements of applications with extremely high reliability requirements (such as automotive-grade electronics). Summary of the Invention

[0005] To address the aforementioned technical problems and deficiencies, the purpose of this invention is to provide a real-time clock adaptive digital temperature compensation method, device, medium, and product, which can alleviate the problem that traditional fixed compensation models cannot cope with crystal aging and stress changes, and improve the long-term timing accuracy and reliability of real-time clocks.

[0006] To achieve the above objectives, in a first aspect, the present invention provides a real-time clock adaptive digital temperature compensation method, comprising: measuring digital fine-tuning register values ​​at multiple reference temperature points to achieve a target frequency for the output frequency of the real-time clock; generating digital fine-tuning register reference data covering the entire operating temperature range based on the symmetry of the crystal frequency-temperature curve and the digital fine-tuning register values; storing the digital fine-tuning register reference data in the memory of the real-time clock to construct a static compensation model; during the operation of the real-time clock, acquiring a first absolute time reference value and a second absolute time reference value from an external absolute time source, and simultaneously acquiring a first time value and a second time value corresponding to the real-time clock; calculating the time error of the real-time clock within a corresponding time period based on the first absolute time reference value, the second absolute time reference value, the first time value, and the second time value; correcting the digital fine-tuning register reference data in the static compensation model based on the time error and the temperature distribution of the real-time clock within the corresponding time period to obtain a corrected compensation model; during the operation of the real-time clock, acquiring the corresponding target digital fine-tuning register value from the corrected compensation model based on the current temperature; and compensating the output frequency of the real-time clock based on the target digital fine-tuning register value.

[0007] This invention effectively solves the problem that traditional real-time clocks, which rely solely on factory-fixed models, cannot cope with crystal resonator aging drift and mechanical stress changes by combining an initial static compensation model with a dynamic closed-loop correction mechanism during operation. During operation, this invention uses an external absolute time source as a reference to accurately calculate the actual timekeeping error of the real-time clock and adaptively corrects the reference data in the digital fine-tuning register in memory online, taking into account the temperature distribution within the corresponding time period. This allows the system to automatically detect and compensate for device parameter drift caused by long-term operation, maintaining high-precision timing throughout its entire lifecycle without the need for expensive specialized equipment for secondary calibration. It is particularly suitable for automotive-grade electronics and industrial IoT devices with extremely high long-term reliability requirements, reducing maintenance costs and improving system timing accuracy.

[0008] In some implementations, measuring the digital fine-tuning register value that enables the output frequency of the real-time clock to reach the target frequency at multiple reference temperature points includes: determining the inflection point temperature of the crystal frequency temperature curve of the real-time clock; selecting multiple reference temperature points on one side of the temperature change of the crystal frequency temperature curve with the inflection point temperature as the center of symmetry; for each reference temperature point, adjusting the digital fine-tuning register and testing the output frequency, and recording the corresponding digital fine-tuning register value when the output frequency reaches the target frequency.

[0009] By employing the above scheme, and determining the inflection point temperature, and selecting a reference point only on one side of the crystal's frequency-temperature curve for measurement, the symmetry of the crystal's physical properties is fully utilized. This scheme ensures the acquisition of key characteristic data while significantly reducing the number of temperature points that need to be controlled and stabilized during production testing. This results in a substantial reduction in testing time per chip, effectively lowering mass production costs and improving production line calibration efficiency.

[0010] In some implementations, digital fine-tuning register reference data covering the entire operating temperature range is generated based on the symmetry of the crystal frequency-temperature curve and the digital fine-tuning register value. This includes: based on the symmetry of the crystal frequency-temperature curve, mapping the digital fine-tuning register value of the reference temperature point measured on one side of the temperature change to the corresponding other side of the crystal frequency-temperature curve to obtain a symmetrical temperature point; and generating continuously distributed digital fine-tuning register reference data within the entire operating temperature range using a numerical processing algorithm based on the digital fine-tuning register values ​​of the reference temperature point and the symmetrical temperature point.

[0011] The above scheme utilizes the principle of symmetry to map measured data from one side to the other, and generates continuously distributed benchmark data through numerical processing algorithms. This scheme can construct a high-resolution lookup table or model covering the entire operating temperature range based on a limited number of discrete measurement points, ensuring the smoothness and continuity of compensation data across the entire temperature range, avoiding frequency jumps caused by missing data, and laying a data foundation for high-precision compensation.

[0012] In some implementations, the static compensation model is corrected based on the time error and the temperature distribution of the real-time clock within the corresponding time period. This includes: calculating the time error based on the first time difference between the first time value and the second time value, and the second time difference between the first absolute time reference value and the second absolute time reference value; dividing the complete operating temperature range into multiple temperature statistical sub-intervals, and calculating the running time weight of the real-time clock within each temperature statistical sub-interval within the corresponding time period; calculating the model correction amount for one or more temperature statistical sub-intervals based on the time error and the running time weight; and updating the digital fine-tuning register reference data for the corresponding temperature interval in the static compensation model based on the model correction amount.

[0013] The above scheme introduces a runtime weighting analysis mechanism based on temperature statistical sub-intervals, which correlates the accumulated total time error with the specific temperature distribution. This scheme avoids the distortion of the compensation model caused by simply averaging the error, and can accurately attribute and correct the frequency deviation to the specific temperature range that caused the error based on the actual operating conditions, significantly improving the targeting and correction accuracy of the dynamic correction algorithm.

[0014] In some implementations, the model correction for one or more temperature statistical sub-intervals is calculated based on the time error and the running time weight, including: calculating the average frequency deviation based on the ratio of the time error to the second time difference; identifying the dominant temperature statistical sub-interval with the largest value in the running time weight; and determining all or part of the average frequency deviation as the model correction for the dominant temperature statistical sub-interval.

[0015] The above scheme optimizes the convergence speed of the correction algorithm by identifying the dominant temperature statistical sub-interval and allocating the average frequency deviation to that interval. This scheme is particularly suitable for applications where the equipment operates at a relatively stable ambient temperature for extended periods. It can quickly correct aging drift at the main operating temperature points, maximizing timing accuracy at the most frequently used temperature while ensuring computational efficiency.

[0016] In some implementations, the static compensation model includes first compensation data corresponding to a heating trend and second compensation data corresponding to a cooling trend; before obtaining the corresponding target digital fine-tuning register value from the corrected compensation model based on the current temperature, the model further includes: monitoring the current temperature change trend of the real-time clock; and selecting to query the digital fine-tuning register value from the first compensation data or the second compensation data based on the current temperature change trend.

[0017] By employing the above scheme and constructing two sets of compensation data corresponding to the heating and cooling trends respectively, the temperature hysteresis effect commonly found in crystal resonators and peripheral circuits is effectively resolved. This scheme enables the system to select a more suitable fine-tuning value based on the current temperature change direction, eliminates frequency tracking errors caused by thermal inertia, and significantly improves the dynamic compensation performance of the real-time clock during drastic or rapid fluctuations in ambient temperature.

[0018] In some implementations, the output frequency of the real-time clock is compensated based on the target digital fine-tuning register value, including: obtaining the cumulative operating time of the real-time clock; substituting the cumulative operating time into a preset aging drift prediction model to calculate the aging compensation value; superimposing the target digital fine-tuning register value and the aging compensation value to obtain the final digital fine-tuning register value; and compensating the output frequency of the real-time clock based on the final digital fine-tuning register value.

[0019] By adopting the above scheme, combining the accumulated working time with the preset aging drift prediction model, a feedforward aging compensation is introduced on the basis of feedback correction. This scheme can pre-compensate part of the expected aging drift based on the theoretical model when the external absolute time source is temporarily unavailable or the synchronization interval is long. It complements the dynamic correction based on measured errors, further ensuring the robustness of the real-time clock in long-term operation.

[0020] In a second aspect, the present invention provides an electronic device comprising: one or more processors and a memory; the memory being coupled to the one or more processors, the memory being used to store computer program code including computer instructions, the one or more processors invoking the computer instructions to cause the electronic device to perform the methods described in the first aspect and any possible implementation thereof.

[0021] Thirdly, the present invention provides a computer-readable storage medium storing computer instructions that, when executed on an electronic device, cause the electronic device to perform the methods described in the first aspect and any possible implementation thereof.

[0022] Fourthly, the present invention provides a computer program product including computer instructions that, when executed on an electronic device, cause the electronic device to perform the method described in the first aspect and any possible implementation thereof.

[0023] Understandably, the electronic device provided in the second aspect, the storage medium provided in the third aspect, and the computer program product provided in the fourth aspect are all used to execute the method provided by this invention. Therefore, the beneficial effects they can achieve can be referred to the beneficial effects in the corresponding methods, and will not be repeated here. Attached Figure Description

[0024] Figure 1 This is a flowchart illustrating a real-time clock adaptive digital temperature compensation method according to an embodiment of the present invention.

[0025] Figure 2 This is a crystal frequency-temperature characteristic curve before digital temperature compensation is implemented in an embodiment of the present invention;

[0026] Figure 3 This is a real-time clock output frequency characteristic curve after digital temperature compensation is implemented in an embodiment of the present invention;

[0027] Figure 4 This is a schematic diagram of the hardware architecture of an electronic device according to an embodiment of the present invention. Detailed Implementation

[0028] The terminology used in the following embodiments of the present invention is for the purpose of describing particular embodiments only and is not intended to be limiting of the invention. As used in the specification and appended claims of the present invention, the singular expressions “a,” “an,” “the,” “the,” “the,” and “this” are intended to include the plural expressions as well, unless the context clearly indicates otherwise. It should also be understood that the term “and / or” as used in the present invention refers to any or all possible combinations comprising one or more of the listed items.

[0029] Hereinafter, the terms "first" and "second" are used for descriptive purposes only and should not be construed as implying or suggesting relative importance or implicitly indicating the number of indicated technical features. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of that feature, and in the description of the embodiments of the present invention, unless otherwise stated, "a plurality of" means two or more.

[0030] Embodiments of the present invention provide a real-time clock adaptive digital temperature compensation method. This method is executed by a real-time clock adaptive digital temperature compensation system (hereinafter referred to as the system), which includes a real-time clock circuit, a temperature sensor, a memory, and a processing unit. This method achieves adaptive compensation for the long-term accuracy of the real-time clock by establishing an initial static compensation model and dynamically correcting it based on an external absolute time source during operation. The following describes the method in conjunction with... Figure 1 The steps of this method are explained in detail below:

[0031] S101: At multiple reference temperature points, measure the digital fine-tuning register value that makes the output frequency of the real-time clock reach the target frequency.

[0032] In this step, the system performs temperature-frequency characteristic testing during the production testing or initial calibration phase. Specifically, the system places the real-time clock chip in a controlled temperature environment, such as a temperature chamber or thermostat, and sets multiple reference temperature points for measurement. The selection of reference temperature points typically covers the operating temperature range of the real-time clock; for example, several temperature points are selected within the range of -40 degrees Celsius to 85 degrees Celsius. Typical reference temperature points may include -40 degrees Celsius, -20 degrees Celsius, 0 degrees Celsius, 25 degrees Celsius, 50 degrees Celsius, 70 degrees Celsius, and 85 degrees Celsius.

[0033] At each reference temperature point, after the system waits for the temperature to stabilize, it uses a high-precision frequency meter to measure the actual output frequency of the real-time clock. The digital trimmer register is a configurable register within the real-time clock circuit; by changing the value of the digital trimmer register, the output frequency of the real-time clock can be adjusted. The system adjusts the value of the digital trimmer register to gradually bring the output frequency of the real-time clock closer to the target frequency, which can be 32768 Hz.

[0034] The system employs a binary search or successive approximation method to determine the digital fine-tuning register value that enables the output frequency to reach the target frequency. This digital fine-tuning register value is then mapped to the corresponding reference temperature point and recorded. By repeating this measurement process at multiple reference temperature points, the system obtains multiple sets of temperature-digital fine-tuning register value correspondence data.

[0035] S102: Based on the symmetry of the crystal frequency-temperature curve and the digital fine-tuning register value, generate digital fine-tuning register reference data covering the entire operating temperature range.

[0036] In this step, the system utilizes the inherent symmetry of the crystal resonator's frequency-temperature characteristic curve to expand the coverage of the compensation data. The frequency-temperature characteristic curve of a crystal resonator typically exhibits a quadratic parabolic shape, possessing symmetry with the axis of symmetry located near the inflection point temperature—the temperature at which the crystal frequency reaches its maximum or minimum value. For tuning fork quartz crystals commonly used in real-time clocks, or other crystals with quadratic parabolic frequency-temperature characteristics, their curves are symmetrical, with the axis of symmetry located near the inflection point temperature. For commonly used tuning fork crystals, the inflection point temperature is typically around 25 degrees Celsius.

[0037] The system first determines the inflection point temperature of the crystal frequency-temperature curve based on the digital fine-tuning register values ​​at multiple reference temperature points obtained in step S101. The system can determine the inflection point temperature by performing a quadratic polynomial fitting on the digital fine-tuning register values ​​at the reference temperature points. After determining the inflection point temperature, the system utilizes the symmetry of the curve for data expansion: for any temperature point T1, if the corresponding digital fine-tuning register value is known, the digital fine-tuning register value at another temperature point T2, which is symmetrical about the inflection point temperature, can be approximately considered to be the same as T1 or only slightly different.

[0038] The system leverages this symmetry to extend the digital fine-tuning register values ​​of measured reference temperature points to temperature points that have not been directly measured, thereby generating digital fine-tuning register reference data covering the entire operating temperature range. For temperature points that have not been directly measured and cannot be obtained directly through symmetry, the system can use interpolation algorithms, such as linear interpolation or spline interpolation, to calculate the values ​​based on the digital fine-tuning register values ​​of adjacent known temperature points.

[0039] Ultimately, the system generates a complete digital fine-tuning register reference data table with a temperature resolution of 0.5 degrees Celsius or 1 degree Celsius, which can cover the full operating temperature range from -40 degrees Celsius to 85 degrees Celsius.

[0040] S103: Store the digital fine-tuning register reference data in the memory of the real-time clock to build a static compensation model.

[0041] In this step, the system writes the digital fine-tuning register reference data generated in step S102 into the non-volatile memory of the real-time clock chip. The non-volatile memory can be a one-time programmable memory, electrically erasable programmable read-only memory, or flash memory, etc.

[0042] The system organizes the digital fine-tuning register reference data in ascending or descending order of temperature, forming a lookup table structure. Each entry in the lookup table contains a temperature value and its corresponding digital fine-tuning register value. The system stores the lookup table in a designated address space of memory and records metadata such as the start address, data length, and temperature resolution of the lookup table.

[0043] After storage, the reference data of the digital fine-tuning register constitutes a static compensation model. The static compensation model refers to the fixed temperature compensation reference data relied upon during the initial use phase after the real-time clock leaves the factory. During storage, the system can compress and encode the reference data of the digital fine-tuning register to save storage space, for example, by storing only the difference values ​​of the digital fine-tuning register values ​​at adjacent temperature points instead of the absolute values.

[0044] The system can also add check codes, such as cyclic redundancy check codes, to the stored digital fine-tuning register reference data to ensure data integrity and reliability.

[0045] S104: During the operation of the real-time clock, acquire the first absolute time reference value and the second absolute time reference value from the external absolute time source, and synchronously acquire the first time value and the second time value corresponding to the real-time clock.

[0046] In this step, the system obtains reference time information by synchronizing with an external absolute time source while the real-time clock is operating normally. An external absolute time source refers to an external system or device capable of providing high-precision absolute time, such as the Global Positioning System, the BeiDou Navigation Satellite System, a Network Time Protocol server, or other high-precision clock sources.

[0047] The system communicates with an external absolute time source at time t1 to obtain a first absolute time reference value provided by the external absolute time source. This first absolute time reference value represents the accurate absolute time of time t1. Simultaneously, the system records the first time value of the real-time clock at time t1. This first time value is the time displayed by the internal timer of the real-time clock at time t1. The system ensures that the acquisition of the first absolute time reference value and the first time value are synchronized, meaning they correspond to the same physical time.

[0048] After a certain time interval, the system communicates with the external absolute time source again at the second time t2 to obtain a second absolute time reference value provided by the external absolute time source. This second absolute time reference value represents the accurate absolute time of the second time t2. Similarly, the system records the second time value of the real-time clock at the second time t2, which is the time displayed by the internal timer of the real-time clock at the second time t2. The time interval between the first time t1 and the second time t2 should be long enough to accumulate sufficient time error for subsequent analysis; the time interval can be 1 hour, 24 hours, or longer.

[0049] To improve measurement accuracy, the system needs to consider communication delay when acquiring absolute time reference values, and compensate for time deviations introduced by network transmission or signal propagation by round-trip delay measurement or timestamp technology.

[0050] S105: Calculate the time error of the real-time clock within the corresponding time period based on the first absolute time reference value, the second absolute time reference value, the first time value, and the second time value.

[0051] In this step, the system calculates the actual timekeeping error of the real-time clock based on the four time values ​​obtained in step S104.

[0052] The system first calculates the time interval between the first time t1 and the second time t2 from the external absolute time source. This time interval is equal to the second absolute time reference value minus the first absolute time reference value, and is denoted as the reference time interval. The reference time interval represents the actual amount of physical time elapsed.

[0053] Then, the time interval between the first time point t1 and the second time point t2 is calculated. This time interval is equal to the second time value minus the first time value, and is denoted as the real-time clock time interval. The real-time clock time interval represents the amount of time elapsed as measured by the real-time clock.

[0054] The system compares the real-time clock time interval with the reference time interval and calculates the time error, which is equal to the real-time clock time interval minus the reference time interval. If the time error is positive, it means the real-time clock is running fast, i.e., the output frequency of the real-time clock is higher than the target frequency; if the time error is negative, it means the real-time clock is running slow, i.e., the output frequency of the real-time clock is lower than the target frequency.

[0055] The system can also convert time error into relative frequency error, which is equal to time error divided by reference time interval. This relative frequency error represents the proportion of deviation of the real-time clock output frequency from the target frequency.

[0056] Through the above calculations, the system obtains the actual time error of the real-time clock within the corresponding time period. This time error reflects the deviation between the compensation effect of the current static compensation model and the actual requirements.

[0057] S106: Based on the time error and the temperature distribution of the real-time clock within the corresponding time period, the reference data of the digital fine-tuning register in the static compensation model is corrected to obtain the corrected compensation model.

[0058] In this step, the system adaptively corrects the static compensation model based on the time error calculated in step S105 and the temperature distribution experienced by the real-time clock from the first time t1 to the second time t2.

[0059] The system first acquires the temperature distribution of the real-time clock within the corresponding time period. Specifically, the system periodically samples and records the operating temperature of the real-time clock chip using a temperature sensor. The temperature sampling interval can be 1 minute, 10 minutes, or other suitable intervals. The system then calculates the duration or frequency of each temperature point or temperature range from the first time point t1 to the second time point t2, forming a temperature distribution histogram. The temperature distribution histogram reflects the distribution of the real-time clock's operating time at different temperatures.

[0060] The source of the time error is then analyzed. Since the time error accumulates over the entire time period, it is the result of weighted summation of the frequency deviations at each temperature point according to their duration. The system employs an error allocation algorithm to distribute the total time error across the reference data of the digital fine-tuning registers at each temperature point. The error allocation algorithm can use a uniform allocation method, distributing the time error evenly across all temperature points; or it can use a weighted allocation method, allocating the error based on the duration of each temperature point, with longer duration temperature points receiving a larger error correction.

[0061] For each temperature point, the system calculates the amount that the digital fine-tuning register value needs to be adjusted. The direction and magnitude of the adjustment are determined by the sign of the time error and the amount of error allocated to that temperature point. If the time error is positive, indicating that the system is running too fast, the digital fine-tuning register value needs to be decreased to reduce the output frequency; if the time error is negative, indicating that the system is running too slow, the digital fine-tuning register value needs to be increased to increase the output frequency.

[0062] The calculated adjustment is added to the original digital fine-tuning register reference data at the corresponding temperature point in the static compensation model to obtain the corrected digital fine-tuning register value. The system reorganizes the corrected digital fine-tuning register values ​​for all temperature points into a new lookup table, which is the corrected compensation model. The system updates and stores the corrected compensation model in memory, replacing the original static compensation model, for use in subsequent temperature compensation.

[0063] To avoid the measurement noise or outliers introduced by a single correction from having too much impact on the compensation model, the system can adopt a progressive correction strategy, that is, only correcting part of the error each time instead of all the error, or using filtering methods such as moving average to smooth the results of multiple corrections.

[0064] This correction process is essentially a closed-loop feedback control system that uses the observed system output (time error) to calibrate the system parameters (digital fine-tuning register reference data) in reverse, thereby approximating the true aging curve of the crystal.

[0065] S107: During the operation of the real-time clock, the corresponding target digital fine-tuning register value is obtained from the corrected compensation model based on the current temperature.

[0066] In this step, the system performs dynamic temperature compensation in real time based on changes in ambient temperature during the normal operation of the real-time clock. The system periodically detects the current operating temperature of the real-time clock chip using a temperature sensor. The temperature detection period can be set to 1 second, 10 seconds, 1 minute, or other suitable time intervals.

[0067] After obtaining the current temperature value, the system uses this current temperature value as an index to look up the corresponding digital fine-tuning register value in the corrected compensation model. The corrected compensation model is stored in memory in the form of a lookup table, where each entry contains a temperature value and its corresponding digital fine-tuning register value. If the current temperature value is exactly equal to the temperature value of an entry in the lookup table, the system directly reads the corresponding digital fine-tuning register value as the target digital fine-tuning register value. If the current temperature value lies between two adjacent temperature points in the lookup table, the system uses an interpolation algorithm to calculate the target digital fine-tuning register value. The interpolation algorithm can be linear interpolation, spline interpolation, or other interpolation methods. For example, if the current temperature value is 26.5 degrees Celsius, and the lookup table stores the digital fine-tuning register value for 26 degrees Celsius as 100 and the digital fine-tuning register value for 27 degrees Celsius as 102, then the system calculates the target digital fine-tuning register value for 26.5 degrees Celsius as 101 through linear interpolation.

[0068] The system temporarily stores the target digital fine-tuning register value obtained from searching or calculating in the register of the processing unit, ready for subsequent frequency compensation operations.

[0069] S108: Compensates the output frequency of the real-time clock based on the target digital fine-tuning register value.

[0070] In this step, the system writes the target digital fine-tuning register value obtained in step S107 into the digital fine-tuning register of the real-time clock circuit, thereby adjusting the output frequency of the real-time clock to compensate for frequency drift caused by temperature.

[0071] The digital trimmer register is a hardware register in the real-time clock circuit. Its value directly controls the load capacitance or bias voltage of the crystal oscillator, thereby changing the oscillation frequency. The system writes the target digital trimmer register value into the register via an internal bus or dedicated control signal. Changes to the digital trimmer register value take effect immediately, and the real-time clock circuit adjusts its output frequency accordingly. If the target digital trimmer register value increases, the real-time clock output frequency increases accordingly; if the target digital trimmer register value decreases, the real-time clock output frequency decreases accordingly.

[0072] This adjustment compensates for the real-time clock's output frequency to be close to the target frequency at the current temperature, thus offsetting the impact of temperature drift on timing accuracy. The system continuously monitors temperature changes and repeats steps S107 and S108 to achieve dynamic and continuous compensation of the real-time clock's output frequency.

[0073] In addition, the system periodically repeats steps S104 to S106 to continuously correct the compensation model by periodically synchronizing with an external absolute time source. This enables the compensation model to adaptively track frequency characteristic changes caused by long-term factors such as crystal aging and environmental changes, thereby ensuring the high-precision timing performance of the real-time clock throughout its entire lifespan.

[0074] Through the above steps S101 to S108, the real-time clock adaptive digital temperature compensation method of this embodiment not only establishes a static compensation model covering the entire operating temperature range in the initial stage, but also can adaptively correct the compensation model based on the feedback information of the external absolute time source during the operation of the real-time clock. This effectively solves the problem that the traditional fixed compensation model cannot cope with crystal aging and stress changes, and significantly improves the long-term timing accuracy and reliability of the real-time clock.

[0075] To illustrate the technical solution of the present invention in more detail, this embodiment also provides a real-time clock adaptive digital temperature compensation method, including the following steps:

[0076] S201: Determine the inflection point temperature of the crystal frequency temperature curve of the real-time clock.

[0077] In this step, the system first needs to determine the inflection point temperature of the frequency-temperature characteristic curve of the crystal resonator. The inflection point temperature is the temperature point on the frequency-temperature curve where the curvature changes. At this temperature point, the oscillation frequency of the crystal reaches its extreme value. For commonly used tuning fork quartz crystals, the inflection point temperature is usually located around 25 degrees Celsius.

[0078] In a laboratory environment, the real-time clock chip is placed in a high-precision temperature control device. Multiple densely packed temperature test points are selected near the expected inflection point temperature, for example, one test point every 1 degree Celsius within the range of 20 to 30 degrees Celsius. At each test point, after the system waits for the temperature to stabilize, the actual output frequency of the real-time clock is measured using a high-precision frequency meter, and the correlation between temperature and frequency is recorded. The system plots the measured temperature-frequency data into a curve and determines the inflection point temperature through mathematical analysis.

[0079] Specifically, the system can perform a quadratic polynomial fitting on the measured data. The fitting function has the form f(T) = a × (T - T0)² + f0, where T represents the temperature, T0 represents the inflection point temperature, f0 represents the frequency at the inflection point temperature, and a is the coefficient of the quadratic term. The system solves for the fitting parameters using the least squares method, and the obtained T0 is the inflection point temperature.

[0080] After determining the inflection point temperature, the system stores the inflection point temperature value in the system's configuration parameters for use in subsequent steps.

[0081] S202: Select multiple reference temperature points on one side of the temperature change curve of the crystal frequency-temperature curve with the inflection point temperature as the center of symmetry.

[0082] In this step, the system utilizes the symmetry of the crystal frequency-temperature curve about the inflection point temperature, selecting a reference temperature point for measurement only on one side of the temperature change, thereby reducing the workload of testing. The side of the temperature change refers to the direction in which the temperature increases or decreases relative to the inflection point temperature, such as from the inflection point temperature towards a higher temperature or towards a lower temperature.

[0083] The system determines the temperature range to be covered based on the operating temperature range of the real-time clock. For example, if the operating temperature range of the real-time clock is -40 degrees Celsius to 85 degrees Celsius and the inflection point temperature is 25 degrees Celsius, then the high-temperature side of 25 degrees Celsius to 85 degrees Celsius can be selected for the temperature change side.

[0084] The system selects multiple reference temperature points on the selected side of the temperature change according to a certain temperature interval. The interval between the reference temperature points can be uniformly distributed. For example, a reference temperature point is set every 10 degrees Celsius, resulting in reference temperature points of 25 degrees Celsius, 35 degrees Celsius, 45 degrees Celsius, 55 degrees Celsius, 65 degrees Celsius, 75 degrees Celsius, and 85 degrees Celsius.

[0085] The reference temperature points can also be non-uniformly distributed, with denser reference temperature points set in areas of rapid temperature change or large frequency drift to improve compensation accuracy. The system records the selected reference temperature points in the test configuration table as temperature setpoints for subsequent measurements.

[0086] S203: For each reference temperature point, adjust the digital fine-tuning register and test the output frequency. When the output frequency reaches the target frequency, record the corresponding digital fine-tuning register value.

[0087] In this step, the system measures and calibrates each reference temperature point selected in step S202. The system places the real-time clock chip in a temperature control device, setting the target temperature of the temperature control device to the current reference temperature point to be measured, such as 35 degrees Celsius. The system waits for the temperature control device to reach the target temperature and stabilize, typically for 15 to 30 minutes, to ensure that the temperature of the real-time clock chip is evenly distributed and reaches thermal equilibrium.

[0088] Once the temperature stabilizes, the system begins adjusting the digital trim register of the real-time clock. The digital trim register is a programmable register in the real-time clock circuit that controls the operating parameters of the crystal oscillator. By changing the value of the digital trim register, the load capacitance, bias voltage, or other parameters affecting the oscillation frequency of the crystal oscillator can be fine-tuned, thereby adjusting the output frequency.

[0089] The system employs an iterative search algorithm to determine the digital fine-tuning register value that enables the output frequency to reach the target frequency. First, the system sets the digital fine-tuning register to an initial value, such as the register's intermediate value. Then, a high-precision frequency meter is used to measure the actual output frequency of the real-time clock. The system compares the actual output frequency with the target frequency. If the actual output frequency is lower than the target frequency, the digital fine-tuning register value is increased; if the actual output frequency is higher than the target frequency, the digital fine-tuning register value is decreased. The system can use a binary search method for rapid convergence, re-measuring the output frequency after each adjustment until the deviation between the actual output frequency and the target frequency is less than a preset threshold, for example, a deviation less than 0.1 Hz or a relative error less than 3 ppm.

[0090] When the accuracy requirements are met, the system records the current digital fine-tuning register value and stores the mapping relationship between this value and the corresponding reference temperature point in the test data table. The system repeats this process for all reference temperature points, ultimately obtaining the digital fine-tuning register values ​​corresponding to all reference temperature points on the side of temperature change.

[0091] S204: Based on the symmetry of the crystal frequency-temperature curve, the digital fine-tuning register value of the reference temperature point measured on one side of the temperature change is mapped to the corresponding other side of the crystal frequency-temperature curve to obtain the symmetrical temperature point.

[0092] In this step, the system utilizes the symmetry of the crystal frequency-temperature curve to extend the measured reference temperature point data from one side of the temperature change to the other, thereby generating compensated data for the complete temperature range. A symmetrical temperature point is a temperature point on the crystal frequency-temperature curve that is symmetrical about the inflection point temperature. For any reference temperature point T1 on one side of the temperature change, the system calculates the temperature difference ΔT = T1 - T0 between this reference temperature point and the inflection point temperature T0, and then calculates the temperature value of the symmetrical temperature point T2 = T0 - ΔT. For example, if the inflection point temperature T0 is 25 degrees Celsius and the reference temperature point T1 on the temperature change side is 35 degrees Celsius, then the temperature difference ΔT is 10 degrees Celsius, and the symmetrical temperature point T2 is 25 degrees Celsius minus 10 degrees Celsius, which equals 15 degrees Celsius.

[0093] Based on the symmetry assumption of the crystal frequency-temperature curve, the system assumes that the crystal frequency characteristics at the symmetric temperature point T2 are the same as or very close to those at the reference temperature point T1. Therefore, the digital fine-tuning register value corresponding to the symmetric temperature point T2 can be directly adopted from the digital fine-tuning register value corresponding to the reference temperature point T1, or only minor correction is required.

[0094] The system performs this mapping operation on all reference temperature points on the side of the temperature change, generating corresponding symmetrical temperature points and their corresponding digital fine-tuning register values. For example, if the reference temperature points on the side of the temperature change include 35 degrees Celsius, 45 degrees Celsius, 55 degrees Celsius, 65 degrees Celsius, 75 degrees Celsius, and 85 degrees Celsius, then the corresponding symmetrical temperature points are 15 degrees Celsius, 5 degrees Celsius, -5 degrees Celsius, -15 degrees Celsius, -25 degrees Celsius, and -35 degrees Celsius, respectively.

[0095] The system adds symmetrical temperature points and their corresponding digital fine-tuning register values ​​to the compensation data table, forming a temperature-digital fine-tuning register value mapping relationship that covers the positive and negative temperature range together with the original reference temperature point data.

[0096] S205: Based on the digital fine-tuning register values ​​at the reference temperature point and the symmetrical temperature point, a numerical processing algorithm is used to generate digital fine-tuning register reference data that is continuously distributed within the full operating temperature range.

[0097] In this step, the system generates continuous distribution data covering the entire operating temperature range based on the obtained discrete data of the reference temperature point and symmetrical temperature point through numerical processing algorithms. The numerical processing algorithms include mathematical methods such as interpolation algorithms, fitting algorithms, or smoothing algorithms.

[0098] The system first sorts all reference temperature points and symmetrical temperature points in ascending order of temperature, forming an ordered sequence of temperature-digital fine-tuning register values. The system determines the complete operating temperature range, for example, from -40 degrees Celsius to 85 degrees Celsius, and determines the temperature resolution of the continuously distributed data. Temperature resolution refers to the temperature interval between two adjacent data points, which can be 0.5 degrees Celsius or 1 degree Celsius.

[0099] Within its full operating temperature range, the system generates all temperature points according to a set temperature resolution. For example, with a resolution of 1 degree Celsius, it generates temperature points from -40 degrees Celsius, -39 degrees Celsius, -38 degrees Celsius up to 85 degrees Celsius. For each generated temperature point, the system determines whether it is exactly equal to a known reference temperature point or a symmetrical temperature point. If so, it directly uses the digital fine-tuning register value corresponding to that known temperature point; otherwise, the system uses an interpolation algorithm to calculate the digital fine-tuning register value corresponding to that temperature point.

[0100] Interpolation algorithms can employ linear interpolation, Lagrange interpolation, spline interpolation, or other higher-order interpolation methods. Taking linear interpolation as an example, the system finds two known temperature points T_low and T_high adjacent to the temperature point T to be calculated, where T_low is less than T and T is less than T_high, and the corresponding digital fine-tuning register values ​​V_low and V_high. Then, the digital fine-tuning register value V corresponding to temperature point T is calculated using the linear interpolation formula: V = V_low + (V_high - V_low) × (T - T_low) / (T_high - T_low).

[0101] The system performs this calculation for all temperature points requiring interpolation, ultimately generating digital fine-tuning register values ​​covering all temperature points within the complete operating temperature range. This complete data serves as the digital fine-tuning register reference data. The system can smooth the generated digital fine-tuning register reference data to eliminate potential data jumps or noise. Smoothing methods can include moving average filtering or Gaussian filtering.

[0102] S206: Store the reference data of the digital fine-tuning register in the memory of the real-time clock to construct a static compensation model. The static compensation model includes first compensation data corresponding to the heating trend and second compensation data corresponding to the cooling trend.

[0103] In this step, the system stores the generated digital fine-tuning register reference data into the non-volatile memory of the real-time clock chip, and divides the compensation data into two groups according to the different temperature change trends. The first compensation data refers to the compensation data used by the real-time clock during the heating process, for cases where the temperature changes from low to high. The second compensation data refers to the compensation data used by the real-time clock during the cooling process, for cases where the temperature changes from high to low.

[0104] The reason for distinguishing between heating and cooling compensation data is that crystal resonators exhibit a temperature hysteresis effect, meaning that the frequency-temperature characteristics of the crystal may differ slightly during heating and cooling processes. The system can measure the temperature-frequency characteristics during heating and cooling separately during the production testing phase, generating two different sets of digital fine-tuning register reference data.

[0105] The system stores the first compensation data in the first storage area of ​​the memory and the second compensation data in the second storage area of ​​the memory. The two storage areas can be contiguous or separate address spaces. The system records metadata such as the starting address, data length, temperature range, and temperature resolution of the first and second compensation data in the memory for subsequent querying and use.

[0106] The system can also add a checksum, such as a cyclic redundancy checksum or a hash value, to each set of compensation data to verify the integrity of the data.

[0107] After storage, the first compensation data and the second compensation data together constitute the static compensation model, which is the temperature compensation basis data that the real-time clock relies on during the initial working phase.

[0108] S207: During the operation of the real-time clock, acquire the first absolute time reference value and the second absolute time reference value from an external absolute time source, and synchronously acquire the first time value and the second time value corresponding to the real-time clock.

[0109] This step can refer to the corresponding steps in the foregoing embodiments, and will not be repeated here.

[0110] S208: The time error is calculated based on the first time difference between the first time value and the second time value, and the second time difference between the first absolute time reference value and the second absolute time reference value.

[0111] In this step, the system calculates the time error by comparing the time change of the real-time clock with the time change of an external absolute time source.

[0112] The first time difference refers to the time interval measured by the real-time clock between the first and second moments. The system calculates the first time difference by subtracting the first time value from the second time value. For example, if the first time value is 12:00:00 on January 1, 2024, and the second time value is 12:00:05 on January 2, 2024, then the first time difference is 24 hours, 0 minutes, and 5 seconds, or 86,405 seconds.

[0113] The second time difference refers to the actual time interval between the first absolute time reference value and the second absolute time reference value provided by an external absolute time source. The system calculates the second time difference by subtracting the first absolute time reference value from the second absolute time reference value. For example, if the first absolute time reference value is 12:00:00:00.000 seconds on January 1, 2024, and the second absolute time reference value is 12:00:00:00.000 seconds on January 2, 2024, then the second time difference is 24 hours, 0 minutes, and 0 seconds, or 86,400 seconds.

[0114] The system calculates the time error, which is equal to the first time difference minus the second time difference. In the example above, the time error is 86405 seconds minus 86400 seconds, equaling 5 seconds. A positive value indicates that the real-time clock is 5 seconds fast. The sign and magnitude of the time error reflect the direction and degree of deviation of the real-time clock from the actual time. The system stores the calculated time error in a temporary variable for use in subsequent model correction steps.

[0115] The system can also convert time error into relative frequency error, which is equal to time error divided by the second time difference. In the example above, the relative frequency error is 5 seconds divided by 86400 seconds, which is approximately 57.9 ppm. This relative frequency error represents the proportion of deviation of the average output frequency of the real-time clock from the target frequency.

[0116] S209: Divide the complete operating temperature range into multiple temperature statistical sub-intervals, and calculate the weight of the real-time clock's running time in each temperature statistical sub-interval within the corresponding time period.

[0117] In this step, the system performs statistical analysis on the temperature distribution of the real-time clock between the first and second time points. Temperature statistical sub-intervals are several temperature intervals into which the complete operating temperature range is divided, with each sub-interval covering a specific temperature range. The system determines the number of temperature statistical sub-intervals and the width of each sub-interval based on the accuracy requirements of temperature compensation and storage space limitations. For example, if the system divides the complete operating temperature range from -40°C to 85°C into 25 temperature statistical sub-intervals, with each sub-interval having a width of 5°C, then the temperature statistical sub-intervals would be successively -40°C to -35°C, -35°C to -30°C, -30°C to -25°C, and so on, up to 80°C to 85°C.

[0118] During real-time clock operation, the system periodically samples the current temperature using a temperature sensor. The sampling period can be 1 minute, 5 minutes, or 10 minutes. The system records the timestamp and temperature value of each temperature sample and determines which temperature statistical sub-interval the value belongs to. The system maintains a counter or accumulator for each temperature statistical sub-interval to track the time the real-time clock spends within that sub-interval. When a temperature sample falls into a specific sub-interval, the system increments the accumulator corresponding to that sub-interval by one sampling period. After the entire corresponding time interval from the first moment to the second moment, the system calculates the total time the real-time clock spends in each temperature statistical sub-interval.

[0119] The system calculates the runtime weight for each temperature statistical sub-interval. The runtime weight is equal to the dwell time of that temperature statistical sub-interval divided by the total duration of the corresponding time period. For example, if the total duration of the corresponding time period is 24 hours (1440 minutes), and the real-time clock dwells for 720 minutes within the temperature statistical sub-interval of 20 to 25 degrees Celsius, then the runtime weight for that temperature statistical sub-interval is 720 divided by 1440, which equals 0.5. The sum of the runtime weights of all temperature statistical sub-intervals equals 1.

[0120] The system stores the runtime weights of each temperature statistical sub-interval in an array or list for subsequent model correction.

[0121] S210: Calculate the model correction for one or more temperature statistical sub-intervals based on time error and running time weight.

[0122] In this step, based on the time error calculated in step S208 and the runtime weights statistically obtained in step S209, the system determines which temperature statistical sub-intervals in the static compensation model need to be corrected and the magnitude of the correction. The model correction amount refers to the value that needs to be adjusted in the reference data of the digital fine-tuning register corresponding to a specific temperature statistical sub-interval. The system employs an error allocation strategy to distribute the total time error among the various temperature statistical sub-intervals. This error allocation strategy can use a weighted allocation method, that is, distributing the time error proportionally according to the runtime weight of each temperature statistical sub-interval.

[0123] For the i-th temperature statistical sub-interval, the system calculates the time error E_i assigned to that sub-interval. The calculation formula is that E_i equals the total time error E multiplied by the running time weight W_i of that temperature statistical sub-interval. For example, if the total time error is 5 seconds and the running time weight of a certain temperature statistical sub-interval is 0.5, then the time error assigned to that sub-interval is 5 seconds multiplied by 0.5, which equals 2.5 seconds.

[0124] The system converts the time error allocated to each temperature statistical sub-interval into a frequency deviation, where the frequency deviation equals the time error divided by the total duration of the corresponding time interval. The system further converts the frequency deviation into a correction amount for the digital fine-tuning register value. A certain mapping relationship exists between the digital fine-tuning register value and the output frequency, which can be obtained through pre-calibration. For example, each unit increase in the digital fine-tuning register value corresponds to a 0.1 Hz increase in the output frequency or a relative frequency change of 1 ppm. Based on this mapping relationship, the system calculates the amount of change in the digital fine-tuning register value required to compensate for the frequency deviation; this change is the model correction amount. For example, if the frequency deviation of a certain temperature statistical sub-interval is 2 ppm, and each unit increase in the digital fine-tuning register value corresponds to a 1 ppm frequency change, then the model correction amount for that temperature statistical sub-interval is 2 units.

[0125] The system calculates model corrections for all temperature statistical sub-intervals or major temperature statistical sub-intervals with significant runtime weights, and stores these corrections in a correction array. The system can also employ an adaptive adjustment strategy; for temperature statistical sub-intervals with smaller runtime weights, the system may not perform corrections or only perform partial corrections to avoid correction errors introduced by insufficient statistical samples.

[0126] In some embodiments, this step may specifically include the following steps:

[0127] S2101: The average frequency deviation is calculated based on the ratio of the time error to the second time difference.

[0128] In this step, the system converts the time error obtained in step S208 into a frequency domain deviation. The system calculates the ratio of the time error to the second time difference, which represents the relative time deviation rate of the real-time clock within the corresponding time period. The average frequency deviation is equal to the time error divided by the second time difference, and this value reflects the degree of deviation of the average output frequency of the real-time clock from the target frequency. For example, if the time error is 5 seconds and the second time difference is 86400 seconds, or 24 hours, then the average frequency deviation is approximately 0.0000579, or 57.9 ppm, equal to 5 divided by 86400. The positive or negative sign of the average frequency deviation indicates the direction of frequency deviation; a positive value indicates that the real-time clock output frequency is higher than the target frequency, i.e., it runs fast, and a negative value indicates that the real-time clock output frequency is lower than the target frequency, i.e., it runs slow.

[0129] The system stores the calculated average frequency deviation in variables as the basis for subsequent model corrections.

[0130] S2102: Identify the dominant temperature statistical sub-interval with the largest value in the runtime weight.

[0131] In this step, the system identifies the temperature statistical sub-interval with the largest weight value from the running time weights of each temperature statistical sub-interval obtained in step S209. The dominant temperature statistical sub-interval refers to the temperature interval where the real-time clock stays for the longest time in the corresponding time period, and this temperature statistical sub-interval contributes the most to the total time error.

[0132] The system iterates through the runtime weight arrays of all temperature statistical sub-intervals and finds the maximum weight value and its corresponding temperature statistical sub-interval index by comparison. For example, if the runtime weight of the temperature statistical sub-interval from 20 degrees Celsius to 25 degrees Celsius is 0.6, and the runtime weights of other temperature statistical sub-intervals are all less than 0.6, then this temperature statistical sub-interval is identified as the dominant temperature statistical sub-interval.

[0133] The system records the index number, temperature range, and runtime weight value of the dominant temperature statistical sub-interval. This information is used to subsequently determine the target region for model correction. The purpose of identifying the dominant temperature statistical sub-interval is to focus model correction on the temperature range that has the greatest impact on timing accuracy, thereby improving correction efficiency and accuracy.

[0134] S2103: Determine all or part of the average frequency deviation as the model correction amount for the dominant temperature statistical sub-interval.

[0135] In this step, the system determines the model correction amount to be applied to the dominant temperature statistical sub-interval based on the average frequency deviation calculated in S2101 and the dominant temperature statistical sub-interval identified in S2102.

[0136] This embodiment employs a dominant temperature statistical sub-interval correction strategy based on a probability maximization assumption: when the device operates at a specific stable temperature (dominant interval) for an extended period, the accumulated time error is primarily contributed by the frequency drift at that temperature. This strategy enables rapid convergence of the compensation model and is particularly suitable for applications with relatively stable ambient temperatures. Of course, in other embodiments, the error can be distributed according to the weight ratio of each interval; this embodiment prefers a dominant interval allocation to improve computational efficiency.

[0137] This embodiment can use a full correction strategy, which uses the full value of the average frequency deviation as the model correction amount for the dominant temperature statistical sub-interval. This strategy assumes that the time error mainly comes from the frequency deviation of the dominant temperature statistical sub-interval.

[0138] The system can also employ a partial correction strategy, where only a certain percentage of the average frequency deviation is used as the model correction amount. For example, 50%, 70%, or a weighted proportion based on the running time of the dominant temperature statistical sub-interval can be used as the model correction amount. This partial correction strategy can avoid over-correction and improve system stability.

[0139] The system converts the average frequency deviation into an adjustment amount for the digital fine-tuning register value. Based on the mapping relationship between the digital fine-tuning register value and the frequency, it calculates the number of digital fine-tuning register units that need to be adjusted. The system determines this adjustment amount as the model correction amount for the dominant temperature statistical sub-interval and stores this model correction amount for use in step S211.

[0140] S211: Based on the model correction amount, update the reference data of the digital fine-tuning register in the corresponding temperature range of the static compensation model to obtain the corrected compensation model.

[0141] In this step, the system applies the model correction calculated in step S210 to the static compensation model, updating the reference data of the digital fine-tuning register for the corresponding temperature range. The system reads the reference data of the digital fine-tuning register of the static compensation model from memory; this data is organized into a lookup table according to temperature order.

[0142] For each temperature statistical sub-interval, the system finds the corresponding temperature range and data item in the lookup table. For example, if the temperature statistical sub-interval is 20 degrees Celsius to 25 degrees Celsius, the system finds all data items in the lookup table corresponding to temperature values ​​of 20 degrees Celsius, 21 degrees Celsius, 22 degrees Celsius, 23 degrees Celsius, 24 degrees Celsius, and 25 degrees Celsius.

[0143] The system adds the model correction amount for this temperature statistical sub-interval to the baseline data of the digital fine-tuning register for these data items, obtaining the corrected digital fine-tuning register value. If the model correction amount is positive, it indicates that the digital fine-tuning register value needs to be increased to improve the output frequency; if the model correction amount is negative, it indicates that the digital fine-tuning register value needs to be decreased to reduce the output frequency.

[0144] The system performs this update operation on all temperature statistical sub-intervals that require correction, writing the corrected digital fine-tuning register value back to the corresponding address in memory, replacing the original digital fine-tuning register reference data. The system also needs to simultaneously update the first and second compensation data to ensure that the compensation model is corrected for both heating and cooling scenarios. The system can employ a progressive correction strategy, applying only a portion of the model correction amount each time, such as 50% or 70%, gradually converging to an accurate compensation model through multiple iterations. This avoids over-correction caused by single measurement errors or environmental interference.

[0145] After updating the data, the system performs a rationality check on the corrected data, verifying that the corrected digital fine-tuning register value is within the valid range. If it exceeds the range, amplitude limiting is applied. The system also recalculates and updates the data checksum to ensure the integrity of the corrected compensation model data. After correction, the compensation data in memory becomes the corrected compensation model. This corrected compensation model reflects the impact of long-term factors such as crystal aging and stress changes on frequency characteristics, providing a more accurate temperature compensation effect than the initial static compensation model.

[0146] S212: Monitors the current temperature change trend of the real-time clock.

[0147] In this step, the system needs to determine in real time whether the temperature of the real-time clock chip is in a heating or cooling process in order to select appropriate compensation data. The temperature change trend refers to the direction of temperature change over time, including three states: heating trend, cooling trend, and temperature stability.

[0148] The system continuously samples the temperature of the real-time clock chip using a temperature sensor and records the most recent temperature samples. The system can maintain a temperature history buffer, which stores the results of the most recent N temperature samples, where N can be 3, 5, or 10. The system determines the temperature trend by comparing the current temperature sample value with historical temperature sample values.

[0149] Specifically, the system calculates the difference between the current temperature and the previous temperature. If the difference is positive and exceeds a preset temperature change threshold, such as 0.1 or 0.2 degrees Celsius, it is determined to be an upward temperature trend. If the difference is negative and its absolute value exceeds the temperature change threshold, it is determined to be a downward temperature trend. If the absolute value of the difference is less than the temperature change threshold, it is determined to be a stable temperature. To improve the reliability of the judgment, the system can use a trend analysis method based on multiple sampling, that is, calculate the linear regression slope of multiple temperature values ​​in the temperature history buffer. If the slope is positive, it is determined to be an upward temperature trend; if the slope is negative, it is determined to be a downward temperature trend.

[0150] The system can also set the holding time of the temperature change trend. That is, when a change in the temperature change trend is detected, the temperature change trend status will only be updated after several consecutive samplings confirm the new trend, so as to avoid frequent switching due to temperature fluctuations.

[0151] The system stores the current temperature change trend it determines in a state variable. The value of this state variable can be an enumeration type, including three possible values: rising temperature, falling temperature, and stabilization.

[0152] S213: Based on the current temperature change trend, select to query the digital fine-tuning register value from the first compensation data or the second compensation data.

[0153] In this step, the system selects whether to use the first compensation data or the second compensation data to obtain the digital fine-tuning register value required for temperature compensation, based on the current temperature change trend determined in step S212. The first compensation data is optimized for the heating process, and the second compensation data is optimized for the cooling process.

[0154] The system first reads the value of the current temperature trend state variable. If the current temperature trend is upward, the system selects the first compensation data as the query source; that is, subsequent digital fine-tuning register value queries will be performed in the storage area corresponding to the first compensation data. If the current temperature trend is downward, the system selects the second compensation data as the query source; that is, subsequent digital fine-tuning register value queries will be performed in the storage area corresponding to the second compensation data. If the current temperature trend is stable, the system can either continue using the previously selected compensation data or default to using the first compensation data.

[0155] The system loads the starting address of the selected compensation data storage area, data length, and other information into the query parameters, preparing for subsequent steps to query the digital fine-tuning register value. By differentiating between heating and cooling processes and using different compensation data, the system can more accurately compensate for the temperature hysteresis effect of the crystal resonator, improving the accuracy of temperature compensation.

[0156] In some application scenarios, if the temperature hysteresis effect of the crystal is very small, the system can also be configured to not distinguish the temperature change trend and always use the same set of compensation data. In this case, the first compensation data and the second compensation data can be the same data copy.

[0157] S214: Obtain the corresponding target digital fine-tuning register value from the corrected compensation model based on the current temperature.

[0158] This step is similar to the corresponding step in the aforementioned embodiment, except that this step queries data from the modified compensation model and queries according to the type of compensation data selected in step S213.

[0159] The system acquires the current temperature value of the real-time clock chip via a temperature sensor. Then, based on the compensation data selection determined in step S213, it searches for the digital fine-tuning register value corresponding to the current temperature value in the storage area of ​​either the first or second compensation data. If the current temperature value exactly corresponds to a temperature point in the corrected compensation model lookup table, the system directly reads the digital fine-tuning register value corresponding to that temperature point as the target digital fine-tuning register value. If the current temperature value lies between two adjacent temperature points in the lookup table, the system uses an interpolation algorithm to calculate the target digital fine-tuning register value. The interpolation algorithm can be linear interpolation or other higher-order interpolation methods.

[0160] The system temporarily stores the acquired target digital fine-tuning register value in a temporary register, in preparation for subsequent aging compensation processing.

[0161] S215: Get the cumulative working time of the real-time clock.

[0162] In this step, the system needs to obtain the cumulative operating time of the real-time clock from its initial power-on to the current moment. This cumulative operating time is used to assess the aging degree of the crystal resonator. The cumulative operating time refers to the total duration for which the real-time clock circuit is actually in operation, excluding the time spent in power-off or sleep states.

[0163] The system incorporates a cumulative working time counter within its real-time clock circuit. This counter continuously increments when the real-time clock is powered on, and the incrementing time unit can be hours, days, or other suitable units. The system stores the value of the cumulative working time counter in non-volatile memory to prevent data loss after power failure.

[0164] Each time the real-time clock powers on, the system reads the previously saved cumulative working time value from the non-volatile memory and continues to accumulate it. The system periodically updates the cumulative working time value in the non-volatile memory, for example, once per hour or once per day, to ensure data accuracy.

[0165] The system reads the current cumulative operating time counter value to obtain the cumulative operating time of the real-time clock. For example, if the real-time clock has accumulated 10,000 hours of operation, the system will obtain a cumulative operating time of 10,000 hours. The cumulative operating time reflects the service life and aging condition of the crystal resonator and is an important input parameter for subsequent aging compensation calculations.

[0166] S216: Substitute the cumulative working time into the preset aging drift prediction model to calculate the aging compensation value.

[0167] In this step, the system uses a pre-established aging drift prediction model to calculate the frequency drift of the crystal resonator caused by aging based on the cumulative operating time, and converts this frequency drift into an aging compensation value. The aging drift prediction model is a mathematical model that describes the frequency change of the crystal resonator over time; this model can be linear, logarithmic, or exponential, etc.

[0168] In some embodiments, the process of constructing an aging drift prediction model may include: First, collecting experimental data on the frequency drift variation with cumulative working time by conducting long-term aging tests on a large number of crystal samples. Then, selecting an appropriate mathematical model (such as a logarithmic model, in the form of frequency drift = A × ln(1 + cumulative working time / B)) based on the crystal aging law, where A and B are undetermined parameters. Next, using the collected aging test data, determining the values ​​of model parameters A and B through curve fitting methods (such as the least squares method), thereby obtaining a specific prediction model. Finally, deploying this model in an RTC system, so that during operation, the corresponding aging compensation value can be calculated based on the real-time cumulative working time, which is then superimposed on the temperature compensation to offset the frequency drift caused by long-term crystal operation.

[0169] In this embodiment, the system substitutes the cumulative working time obtained in step S215 into the function expression of the aging drift prediction model to calculate the frequency drift. For example, if the aging drift prediction model states that the frequency drift is equal to 3ppm multiplied by ln(1 plus the cumulative working time divided by 8760 hours), and the cumulative working time is 10000 hours, then the frequency drift is approximately equal to 3ppm multiplied by ln(1 plus 10000 divided by 8760), which is approximately equal to 3ppm multiplied by 0.4463, which is approximately equal to 1.34ppm.

[0170] The system converts the calculated frequency drift into an adjustment amount for the digital fine-tuning register value, i.e., the aging compensation value. The conversion method is based on the mapping relationship between the digital fine-tuning register value and frequency, dividing the frequency drift by the frequency change corresponding to a unit digital fine-tuning register value. For example, if a 1-unit increase in the digital fine-tuning register value corresponds to a 1 ppm frequency change, then the aging compensation value is 1.34 divided by 1, approximately equal to 1 unit.

[0171] The system stores the calculated aging compensation value in a temporary variable for use in subsequent steps. The sign of the aging compensation value is usually positive or negative, depending on whether crystal aging causes the frequency to increase or decrease. For most crystals, aging causes the frequency to decrease, so the aging compensation value is usually positive and used to increase the value of the digital fine-tuning register to increase the output frequency.

[0172] S217: The target digital fine-tuning register value is superimposed with the aging compensation value to obtain the final digital fine-tuning register value.

[0173] In this step, the system superimposes the target digital fine-tuning register value obtained in step S214 with the aging compensation value calculated in step S216 to obtain the final digital fine-tuning register value that comprehensively considers temperature compensation and aging compensation. The final digital fine-tuning register value is the value actually written to the real-time clock hardware register to adjust the output frequency.

[0174] The system performs an addition operation to calculate that the final digital fine-tuning register value equals the target digital fine-tuning register value plus the aging compensation value. For example, if the target digital fine-tuning register value is 100 and the aging compensation value is 1, then the final digital fine-tuning register value is 100 plus 1, which equals 101.

[0175] The system performs boundary checks on the calculation results to ensure that the final digital fine-tuning register value is within the valid range of the hardware register. Digital fine-tuning registers typically have bit width limitations; for example, the valid value range of an 8-bit register is 0 to 255. If the calculated final digital fine-tuning register value is less than 0, the system will limit the value to 0; if the final digital fine-tuning register value is greater than 255, the system will limit the value to 255.

[0176] The system uses the final digital fine-tuning register value, after boundary checks, as a valid compensation parameter, preparing to write it into the real-time clock hardware. By superimposing the target digital fine-tuning register value and the aging compensation value, the system achieves simultaneous compensation for temperature drift and aging drift, significantly improving the long-term timing accuracy of the real-time clock.

[0177] S218: Compensate the output frequency of the real-time clock based on the final digital fine-tuning register value.

[0178] In this step, the system writes the final digital fine-tuning register value calculated in step S217 into the hardware digital fine-tuning register of the real-time clock circuit, thereby realizing real-time adjustment and compensation of the output frequency.

[0179] The system sends a write command to the address of the digital fine-tuning register via the internal control bus or dedicated register interface, and transmits the final digital fine-tuning register value as the write data to the digital fine-tuning register. Once the final digital fine-tuning register value is written, the output frequency of the real-time clock changes accordingly. If the final digital fine-tuning register value increases compared to the previous value, the output frequency increases accordingly, and the real-time clock runs faster; if the final digital fine-tuning register value decreases compared to the previous value, the output frequency decreases accordingly, and the real-time clock runs slower.

[0180] Through this dynamic adjustment, the output frequency of the real-time clock is precisely compensated to near the target frequency (e.g., 32768 Hz) under the current temperature and current aging conditions, thereby offsetting the effects of temperature drift and aging drift on timing accuracy.

[0181] The system continuously and periodically executes steps S212 to S218 to achieve continuous dynamic compensation of the real-time clock output frequency. Simultaneously, the system periodically executes steps S207 to S211 to continuously correct the compensation model by synchronizing with an external absolute time source, enabling the compensation model to adaptively track long-term changes in crystal characteristics.

[0182] Through the above steps S201 to S218, the real-time clock adaptive digital temperature compensation method of this embodiment not only establishes an efficient initial compensation model based on crystal symmetry characteristics, but also selects appropriate compensation data according to the temperature change trend, and comprehensively considers temperature compensation and aging compensation, thereby achieving all-round accurate compensation for the real-time clock, significantly improving the timing accuracy and reliability of the real-time clock throughout its entire life cycle, and meeting the stringent requirements of high-precision application scenarios.

[0183] In some embodiments, the above method can be implemented in a microcontroller of a host computer or embedded system running C# or Python. The following provides a detailed explanation of the algorithmic logic and mathematical principles of this method.

[0184] The software implementation of this method mainly consists of two core modules: one is temperature-weighted runtime statistics, and the other is frequency deviation correction based on time error. The algorithm calculates the frequency deviation correction amount for each temperature range by comparing the external network time with the internal RTC time and combining the temperature distribution.

[0185] The core formulas of the algorithm include:

[0186]

[0187] in,

[0188] X i: The correction register value that needs to be updated for temperature range i (or the amount of correction for the dominant range), in ppm.

[0189] The average frequency deviation calculated based on the actual time error, i.e. .

[0190] : Based on the current temperature distribution weight w i And the original basic compensation value C base (T i The theoretical average compensation amount is calculated.

[0191] E: Cumulative time error, in seconds.

[0192] ΔT net : Actual time interval (network time difference), in seconds.

[0193] w i : Running time weight for temperature range i.

[0194] C base (T i ): The original basic compensation value for temperature range i, in ppm.

[0195] Step 1: Time Synchronization and Data Acquisition

[0196] During the chip's power-on operation, the system records time data at two different moments:

[0197] At the first moment t1, the system obtains the network time T. net,1 And synchronously read the internal time T of the RTC rtc,1 .

[0198] At the second time t2, the system obtains the network time T again. net,2 And synchronously read the internal time T of the RTC rtc,2 .

[0199] Step 2: Calculate the time difference and time error:

[0200] Based on the collected time data, the system calculates the time elapsed between two moments and the error:

[0201] Actual time difference (network time difference): ΔT net =T net,2 -T net,1 ;

[0202] RTC time difference (measurement time difference): ΔT rtc =T rtc,2 -T rtc,1 ;

[0203] Cumulative time error E: E=ΔT rtc -\ΔT net ;

[0204] When E>0, it indicates that the RTC is running too fast;

[0205] When E < 0, it indicates that the RTC is running too slowly.

[0206] Step 3: Temperature distribution statistics and weight calculation:

[0207] The RTC's internal temperature statistics module divides the complete operating temperature range into N temperature intervals, with the center temperature of each interval denoted as T. i In ΔT net During this period, the system statistically analyzes the RTC in each temperature range T. i The running time or number of counts.

[0208] Temperature weight w i Calculate: w i = t i / ΔT net ; where t i It is the RTC in the temperature range T i The cumulative runtime.

[0209] Weight constraints: And w i ≥0.

[0210] Step 4: Establish a mathematical model for frequency offset and compensation amount:

[0211] Assume RTC at temperature T i The actual frequency deviation is f err (T i (Unit: ppm). ΔT over the entire time period net Within, the average frequency deviation of the RTC The cumulative time error E has the following relationship:

[0212] ;

[0213] Therefore, the average frequency deviation can be expressed as: ;

[0214] At the same time, according to the principle of weighted averaging, the average frequency deviation is also a weighted sum of the frequency deviations of each temperature range: .

[0215] Step 5: Calculate the basic compensation and correction compensation amounts:

[0216] At the factory, the system has a set of basic compensation values ​​C pre-installed. base(T i ), used to offset the expected frequency deviation.

[0217] Expected average frequency offset after basic compensation: ;

[0218] Calculate the correction value X i To eliminate the residual error E, the correction register value X needs to be calculated. i Ideally, the total compensation after correction should result in a residual frequency offset of 0. Correction value X i Represents the temperature range T i Register values ​​that require additional adjustment (unit: ppm).

[0219] For the dominant temperature range (i.e., weight w) i The largest interval), or the total correction ΔC calculated by the system according to a specific allocation strategy. total for This refers to the difference between the frequency offset actually observed and the deviation after theoretical compensation, which is the part that needs to be corrected.

[0220] Finally, the correction value X for a specific temperature range i i Based on ΔC tota The allocation is updated to achieve closed-loop adaptive compensation.

[0221] Figure 2 This illustrates the original frequency characteristics of a conventional quartz crystal resonator used in a real-time clock before applying the digital temperature compensation method of this embodiment. The horizontal axis represents ambient temperature, ranging from -40°C to 105°C; the vertical axis represents frequency deviation, in ppm. Figure 2 As shown, the curve exhibits a typical quadratic parabolic shape, with its peak (the inflection point where the frequency deviation is minimal) located approximately around 25°C. The frequency deviation increases sharply as the temperature deviates to either side (towards the low-temperature side -40°C or the high-temperature side 105°C). Particularly under extreme temperature conditions, such as -40°C or 105°C, the frequency deviation can reach -150ppm or even lower (with larger absolute negative values), indicating that over a wide temperature range, relying solely on the physical properties of the crystal itself is insufficient to meet the stringent requirements for high-precision timing in fields such as automotive electronics, and a significant temperature drift problem exists.

[0222] like Figure 3 This demonstrates the output frequency performance of the real-time clock across the entire operating temperature range after applying the adaptive digital temperature compensation method of this embodiment. The horizontal axis also represents ambient temperature (-40°C to 105°C), and the vertical axis represents frequency deviation (ppm). Figure 2 compared to, Figure 3The curves exhibit remarkably flattening characteristics. Across the entire temperature range, after static model compensation and dynamic adaptive correction, the output frequency deviation of the real-time clock is successfully controlled within a very small range, with most data points falling within ±5ppm (or even better, close to 0ppm). This indicates that the compensation algorithm in this embodiment effectively offsets the original temperature drift of the crystal, eliminates the negative impact of temperature changes on timing accuracy, and achieves high-precision, high-stability output in complex temperature environments, fully meeting the application standards of automotive-grade electronic products.

[0223] In some embodiments, further research has revealed that in certain application scenarios, real-time clocks often experience complex temperature fluctuations within two absolute time synchronization intervals (e.g., 24 hours). For example, a device might operate at 25 degrees Celsius for 10 hours, at 40 degrees Celsius for 2 hours, and at 60 degrees Celsius for 12 hours. The final measured total time error is the result of the cumulative frequency deviations across these three temperature ranges.

[0224] If we continue with the approach of the previous embodiment, linearly allocating errors based on runtime weights—that is, assuming that temperature ranges with longer runtimes should bear more error corrections—this approach may overlook a crucial fact: the maturity of the compensation model varies across different temperature points. If the compensation parameters for 25°C and 60°C have undergone multiple corrections to achieve extremely high accuracy (high confidence), while 40°C is a temperature point experienced for the first time or has not yet converged (low confidence), then any significant time error occurring in this case is highly likely caused by the low-confidence 40°C range, despite its shorter runtime. Mechanically allocating errors to 25°C and 60°C according to time weights not only fails to eliminate errors but also undermines the already accurate compensation parameters, leading to model divergence or oscillation.

[0225] To address the issue of ambiguous attribution of time errors caused by multi-temperature zone mixed operation, the solution proposed in this embodiment specifically includes the following steps:

[0226] Step A1: Establish a corresponding confidence index (CI) for each temperature statistical sub-interval in the static compensation model. The confidence index is used to quantify the reliability of the current compensation parameters for that temperature interval. Initially, the confidence index for all temperature intervals is a preset low value.

[0227] Step A2: After calculating the total time error, the system statistically analyzes all active temperature sub-intervals involved in this synchronization cycle. Instead of directly allocating errors based on time weights, the system first calculates the weighted confidence level of each active temperature sub-interval.

[0228] Step A3: The system constructs an error allocation mask based on the confidence index. For temperature sub-intervals where the confidence index is higher than the preset convergence threshold, they are marked as "locked" and assigned zero correction gain or very low correction weight in this correction to prevent high-quality parameters from being modified erroneously.

[0229] Step A4: The system calculates the "residual unexplained error". The system uses the existing compensation parameters of the temperature sub-interval in the locked state to calculate the theoretically expected small error, and subtracts this expected error from the total measurement error to obtain the residual error mainly caused by the low confidence interval.

[0230] Step A5: Allocate the remaining error only to active temperature sub-intervals where the confidence index is below the convergence threshold. The allocation ratio is weighted according to the product of its running time and (1 - confidence level). This means that temperature sub-intervals with longer running times and less reliable performance will bear more error correction.

[0231] Step A6: After the correction is completed, update the confidence index of each temperature sub-interval based on the magnitude of the correction. If the correction amount of a certain temperature interval approaches zero multiple times consecutively, its confidence index is significantly increased; if the correction amount fluctuates greatly, its confidence index is decreased.

[0232] Through the above-described embodiments, the system can intelligently identify the "weak" temperature points that cause errors and precisely target them, protecting the converged temperature point parameters. This enables rapid convergence and long-term stability of the model accuracy in variable temperature environments, effectively solving the problem of "deterioration of optimal parameters" caused by blind linear allocation.

[0233] In some embodiments, further research has revealed that in practical applications, especially in automotive or outdoor scenarios, real-time clocks often face drastic temperature fluctuations (thermal shocks). The relevant static compensation model is essentially based on the assumption of steady-state temperature, that is, that the temperature measured by the temperature sensor is equal to the actual temperature of the quartz crystal.

[0234] However, in terms of physical structure, temperature sensors are typically integrated on a silicon wafer, while quartz crystals are encapsulated in a metal or ceramic housing, resulting in thermal resistance and thermal capacitance between the two. When the ambient temperature changes rapidly, the actual temperature change of the crystal lags behind the temperature measured by the sensor, creating a phenomenon known as "thermal hysteresis."

[0235] More seriously, rapid temperature changes can generate mechanical stress with thermal gradients inside the crystal resonator, directly producing additional "stress shift" through the piezoelectric effect. This shift is related to the first derivative (rate of change) of temperature, and not just to absolute temperature. This is a physical phenomenon that static lookup tables cannot cover at all.

[0236] To address the issues of crystal thermal hysteresis and stress frequency shift caused by the aforementioned thermal transients, the solution proposed in this embodiment specifically includes the following steps:

[0237] Step B1: During real-time clock operation, the system acquires the raw temperature value T_sensor from the temperature sensor at a high sampling rate (e.g., once per second) and calculates the current temperature change rate dT / dt.

[0238] Step B2: Construct a second-order thermal RC network equivalent model to estimate the actual core temperature T_core of the crystal. This model, based on pre-calibrated thermal resistance and thermal capacity coefficients, uses the T_sensor as input and calculates T_core in real-time through discretized difference equations iteratively. This step maps the sensor temperature to the true thermal equilibrium temperature inside the crystal, eliminating errors caused by thermal conduction delay.

[0239] Step B3: Introduce a stress frequency shift compensation term. Based on the current temperature change rate dT / dt, the system calculates the frequency deviation caused by transient stress using a preset stress sensitivity coefficient. This compensation term is typically proportional to dT / dt, and its direction depends on the crystal cutting type and stress polarity. For example, this stress frequency shift compensation mechanism is activated when dT / dt exceeds a preset transient threshold (e.g., a change exceeding 2 degrees Celsius per minute).

[0240] Step B4: Synthesize the final target digital fine-tuning register value. The system first uses the estimated T_core (not T_sensor) as an index to find the baseline compensation value in the static compensation model; then, it superimposes the baseline compensation value with the stress frequency shift compensation value calculated in step B3 to obtain the final dynamic compensation value.

[0241] Step B5: After the system detects that the temperature change rate dT / dt has recovered to below the steady-state threshold and has remained below it for a period of time, it automatically exits the transient compensation mode and smoothly switches back to the static compensation mode to reduce computational power consumption.

[0242] Through the above scheme, the embodiments of the present invention no longer rely solely on the static temperature-frequency correspondence, but introduce time-dimensional thermodynamic processing, which effectively compensates for the thermal hysteresis effect between the temperature sensor and the crystal, as well as the dynamic stress frequency shift caused by thermal shock. This enables the real-time clock to maintain extremely high instantaneous frequency stability under conditions of drastic fluctuations in ambient temperature (such as cold starts of automobiles or rapid heating of industrial equipment), greatly improving the dynamic robustness of the system.

[0243] The following describes an exemplary real-time clock adaptive digital temperature compensation system provided by an embodiment of the present invention. Figure 4 This is a schematic diagram of an exemplary hardware architecture of the system provided in an embodiment of the present invention.

[0244] In some embodiments, the system may be an electronic device, or the system may include an electronic device. The electronic device includes a processor, memory, and a network interface connected via a system bus. The processor of the electronic device provides computing and control capabilities. The memory of the electronic device includes a non-volatile storage medium and internal memory. The non-volatile storage medium stores an operating system, computer programs, and a database. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage medium. The database of the electronic device stores data. The network interface of the electronic device is used to communicate with other external terminals or servers via a network connection. In some embodiments, the network interface may be a wired network interface; in some embodiments, the network interface may also be a wireless network interface. When the computer program is executed by the processor, it implements the methods in the embodiments of the present invention.

[0245] Those skilled in the art will understand that Figure 4 The architecture shown is merely a block diagram of a portion of the architecture related to the present invention and does not constitute a limitation on the electronic device to which the present invention is applied. Specific electronic devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.

[0246] The above-described embodiments are only used to illustrate the technical solutions of the present invention, and are not intended to limit it. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention.

[0247] As used in the above embodiments, depending on the context, the term "when..." can be interpreted as meaning "if...", "after...", "in response to determining...", or "in response to detecting...". Similarly, depending on the context, the phrase "when determining..." or "if (the stated condition or event) is interpreted as meaning "if determining...", "in response to determining...", "when (the stated condition or event) is detected", or "in response to detecting (the stated condition or event)".

[0248] In the above embodiments, implementation can be achieved entirely or partially through software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented entirely or partially in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer instructions are loaded and executed on an electronic device, all or part of the processes or functions described in the embodiments of the present invention are generated. The electronic device may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions may be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions may be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium may be any available medium that a computer can access or a data storage device such as a server or data center that integrates one or more available media. The available medium may be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid-state drive), etc.

[0249] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. This program can be stored in a computer-readable storage medium, and when executed, it can include the processes described in the above method embodiments. The aforementioned storage medium includes various media capable of storing program code, such as ROM or random access memory (RAM), magnetic disks, or optical disks.

Claims

1. A real-time clock adaptive digital temperature compensation method, characterized in that, include: At multiple reference temperature points, the digital fine-tuning register value was measured to make the output frequency of the real-time clock reach the target frequency; Based on the symmetry of the crystal frequency-temperature curve and the digital fine-tuning register value, digital fine-tuning register reference data covering the entire operating temperature range is generated. The reference data of the digital fine-tuning register is stored in the memory of the real-time clock to construct a static compensation model; During the operation of the real-time clock, a first absolute time reference value and a second absolute time reference value from an external absolute time source are acquired, and the first time value and the second time value corresponding to the real-time clock are acquired synchronously. Based on the first absolute time reference value, the second absolute time reference value, the first time value, and the second time value, calculate the time error of the real-time clock within the corresponding time period; Based on the time error and the temperature distribution of the real-time clock in the corresponding time period, the reference data of the digital fine-tuning register in the static compensation model is corrected to obtain the corrected compensation model. During the operation of the real-time clock, the corresponding target digital fine-tuning register value is obtained from the corrected compensation model based on the current temperature; The output frequency of the real-time clock is compensated based on the target digital fine-tuning register value.

2. The method according to claim 1, characterized in that, The measurement of the digital fine-tuning register value at multiple reference temperature points, which causes the output frequency of the real-time clock to reach the target frequency, includes: Determine the inflection point temperature of the crystal frequency temperature curve of the real-time clock. With the inflection point temperature as the center of symmetry, multiple reference temperature points are selected on one side of the temperature change of the crystal frequency-temperature curve; For each reference temperature point, the digital fine-tuning register is adjusted and the output frequency is tested. When the output frequency reaches the target frequency, the corresponding digital fine-tuning register value is recorded.

3. The method according to claim 2, characterized in that, Based on the symmetry of the crystal frequency-temperature curve and the digital fine-tuning register value, reference data for the digital fine-tuning register covering the entire operating temperature range is generated, including: Based on the symmetry of the crystal frequency-temperature curve, the digital fine-tuning register value of the reference temperature point measured on one side of the temperature change is mapped to the corresponding other side of the crystal frequency-temperature curve to obtain a symmetrical temperature point. Based on the digital fine-tuning register values ​​at the reference temperature point and the symmetrical temperature point, a numerical processing algorithm is used to generate digital fine-tuning register reference data that is continuously distributed within the full operating temperature range.

4. The method according to claim 1, characterized in that, The step of correcting the static compensation model based on the time error and the temperature distribution of the real-time clock within the corresponding time period includes: The time error is calculated based on the first time difference between the first time value and the second time value, and the second time difference between the first absolute time reference value and the second absolute time reference value. The complete operating temperature range is divided into multiple temperature statistical sub-intervals, and the running time weight of the real-time clock in each temperature statistical sub-interval is calculated within the corresponding time period. Based on the time error and the running time weight, calculate the model correction for one or more of the temperature statistical sub-intervals; Based on the model correction amount, update the reference data of the digital fine-tuning register for the corresponding temperature range in the static compensation model.

5. The method according to claim 4, characterized in that, The step of calculating the model correction for one or more of the temperature statistical sub-intervals based on the time error and the running time weight includes: The average frequency deviation is calculated based on the ratio of the time error to the second time difference. Identify the dominant temperature statistical sub-interval with the largest value among the runtime weights; All or part of the average frequency deviation is determined as the model correction amount for the dominant temperature statistical sub-interval.

6. The method according to claim 1, characterized in that, The static compensation model includes first compensation data corresponding to the warming trend and second compensation data corresponding to the cooling trend; Before obtaining the corresponding target digital fine-tuning register value from the corrected compensation model based on the current temperature, the method further includes: Monitor the current temperature change trend of the real-time clock; Based on the current temperature change trend, the digital fine-tuning register value is queried from either the first compensation data or the second compensation data.

7. The method according to claim 1, characterized in that, The compensation of the real-time clock output frequency based on the target digital fine-tuning register value includes: Obtain the cumulative working time of the real-time clock; The cumulative working time is substituted into the preset aging drift prediction model to calculate the aging compensation value; The target digital fine-tuning register value is superimposed with the aging compensation value to obtain the final digital fine-tuning register value; The output frequency of the real-time clock is compensated based on the final digital fine-tuning register value.

8. An electronic device, characterized in that, Includes one or more processors and memory; The memory is coupled to the one or more processors, the memory being used to store computer program code, the computer program code including computer instructions, the one or more processors invoking the computer instructions to cause the electronic device to perform the method as described in any one of claims 1-7.

9. A computer-readable storage medium storing computer instructions, characterized in that, When the computer instructions are executed on the electronic device, the electronic device causes the electronic device to perform the method as described in any one of claims 1-7.

10. A computer program product comprising computer instructions, characterized in that, When the computer instructions are executed on the electronic device, the electronic device causes the electronic device to perform the method as described in any one of claims 1-7.

Citation Information

Patent Citations

  • Real-time clock chip calibration method, device and terminal equipment

    CN108037656A

  • System-on-chip-oriented real-time clock compensation method, apparatus and device, and medium

    CN117252138A

  • Clock retention performance improving method and device and storage medium

    CN118394178A

  • Methods, system, wireless terminals, and computer program products for calibrating electronic clock using base reference signal and non-continuous calibration reference signal having greater accuracy

    CN1441925A

  • Temperature compensation circuit and electronic apparatus

    JP2012227870A