A method for calibrating an RTC clock based on a low-speed internal clock source
Through the combination of timer and electronic counter, automatic intelligent calibration of RTC clock based on low-speed internal clock source is achieved, solving the problem of low LSI calibration accuracy and improving the accuracy of RTC clock.
Patent Information
- Application Number
- CN202410907113.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-08
- Publication Date
- 2024-12-20
- Estimated Expiration
- 2044-07-08
AI Technical Summary
The calibration accuracy of the low-speed internal clock source (LSI) is poor and is greatly affected by temperature, resulting in inaccurate RTC clocks.
The recorded RTC interrupt data and LSI frequency division flag are updated through timer counting and electronic counter, and the RTC clock frequency division ratio is estimated and corrected. Combined with the analysis of the current temperature and historical temperature difference, the LSI frequency division flag is adjusted to improve calibration accuracy.
It improves the accuracy of the full temperature range of LSI calibration, improves the accuracy of the RTC clock, ensures that the clock can be calibrated in time when the temperature changes, and reduces the impact of temperature changes on LSI.
Smart Images

Figure CN118707834B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of calibration technology, and in particular to a calibration method for an RTC clock based on a low-speed internal clock source. Background Art
[0002] With the rapid development of information technology, more and more digital and networked equipment are being used in the intelligent control of power plants. The continuous improvement of the measurement accuracy of various automatic monitoring devices provides a better platform for data sharing, analysis and advanced applications between systems, while also placing higher requirements on the accuracy of various data time tags. In the field related to electronic systems, the clock system is of vital importance and is the pulse of the electronic system. In order to realize the automated management of the electronic system, a clock source is usually used to realize management through a real-time clock (RTC) based on a clock signal, wherein the clock source includes: a high-speed internal clock source (HSI), a high-speed external clock source (HSE), a low-speed internal clock source (LSI) and a low-speed external clock source (LSE). The high-speed internal clock source (HSI) and the low-speed internal clock source (LSI) exist inside the control unit, and their temperature often directly affects the life of the control unit. At present, the calibration accuracy of the HSI over the full temperature range is relatively high, but the calibration accuracy of the LSI is relatively poor, and it is greatly affected by the temperature, which often leads to inaccurate RTC clocks. Therefore, the present invention proposes a calibration method for an RTC clock based on a low-speed internal clock source, wherein the RTC low-speed clock source is calibrated by timer counting, the calibration accuracy of the LSI over the full temperature range is improved, and thus the accuracy of the RTC clock is improved. Summary of the invention
[0003] The object of the present invention is to provide a method for calibrating an RTC clock based on a low-speed internal clock source to solve the problems raised in the above background technology.
[0004] To achieve the above object, the present invention provides the following technical solution: a method for calibrating an RTC clock based on a low-speed internal clock source, comprising:
[0005] Determine the calibration position of the RTC clock and obtain the current temperature at the calibration position;
[0006] Initialize the timer and start the electronic timer to count;
[0007] Performing a difference analysis on the current temperature and the historical temperature to determine whether the temperature difference is greater than a first threshold value, thereby obtaining a first analysis and determination result;
[0008] According to the first analysis and judgment result, the time is set for the initialized timer, and the RTC interrupt data and the LSI frequency division mark are updated and recorded in combination with the timer and the electronic counter;
[0009] When the RTC interrupt record data is greater than the second threshold, the RTC clock division is obtained, and then the division ratio is estimated based on the RTC clock division. The original RTC clock division is corrected according to the RTC clock estimated division ratio combined with the LSI division flag, and the RTC clock error analysis is performed based on the electronic timer and timer.
[0010] Furthermore, the initialization setting of the timer includes: determining the current setting state of the timer, analyzing whether the current setting state of the timer is the initial state of the timer, obtaining the timer setting state analysis and judgment result, and then restoring the current setting of the timer to the initial state according to the timer setting state analysis and judgment result.
[0011] Furthermore, when setting the time for the initialized timer according to the first analysis and judgment result, the LSI frequency division flag is obtained according to the first analysis and judgment result. When the first analysis and judgment result is that the temperature difference is greater than the first threshold value, the current data of the LSI frequency division flag is obtained, and then the current data of the LSI frequency division flag is analyzed and judged whether it is equal to 1, and the second analysis and judgment result is obtained. When the second analysis and judgment result is that the current data of the LSI frequency division flag is equal to 1, the timing time of the timer and the alarm wake-up time are set, and then the metering data information of the timer and the electronic counter is obtained, so as to update the record of the RTC interrupt data and the LSI frequency division flag according to the metering information of the timer and the electronic counter.
[0012] Further, when the RTC interrupt data and the LSI frequency division flag are updated and recorded according to the metering information of the timer and the electronic counter, it is analyzed that the timer occurs a Systick interrupt according to the timing time. When the timer occurs a Systick interrupt according to the timing time, the overflow signal of the electronic counter is obtained, and the LSI frequency division flag is updated according to the overflow signal to obtain the LSI frequency division flag update data, and the Systick interrupt count is performed according to the LSI frequency division flag update data. At the same time, it is analyzed and determined whether the LSI frequency division flag update data is equal to the third threshold value to obtain a third analysis and judgment result. When the third analysis and judgment result is that the LSI frequency division flag update data is equal to the third threshold value, the RTC is interrupted and the RTC interrupt data record data is updated. Then, it is analyzed and determined whether the updated RTC interrupt data record data is equal to the third threshold value to obtain a fourth analysis and judgment result, and the RTC clock frequency division is obtained according to the fourth analysis and judgment result.
[0013] Furthermore, when the RTC is interrupted, it is also determined whether the LSI frequency division flag update data is equal to 0 to obtain the fifth analysis and judgment result. According to the fifth analysis and judgment result, when the LSI frequency division flag update data is not equal to 0, data analysis is performed on the RTC interrupt mSecCount self-increment count, and the size of the LSI frequency division flag update data is adjusted to the third threshold.
[0014] Furthermore, the frequency division ratio is estimated according to the RTC clock frequency division, including:
[0015] Determine the actual output signal frequency of the RTC clock according to the RTC clock division to obtain RTC_PreReal;
[0016] Obtain the accumulated data of the self-increment count in the case of RTC interruption, and perform mean calculation in combination with the second threshold to determine the count average value in the case of RTC interruption, and obtain mSecCountAvg;
[0017] Use RTC_PreReal combined with mSecCountAvg to perform estimated division ratio analysis and calculation to obtain the estimated division ratio of the RTC clock.
[0018] Furthermore, the original frequency division of the RTC clock is corrected according to the estimated frequency division ratio of the RTC clock and the LSI frequency division flag, including:
[0019] Determine the target frequency division of the RTC clock according to the estimated frequency division ratio of the RTC clock;
[0020] The current RTC clock frequency division is obtained for the RTC clock to obtain the original RTC clock frequency division;
[0021] Analyze the relative relationship between the original RTC clock frequency division and the target RTC clock frequency division in combination with the RTC clock target frequency division to determine the correction direction;
[0022] Perform difference analysis on the original frequency division of the RTC clock and the target frequency division of the RTC clock to obtain the target frequency division correction adjustment difference;
[0023] Perform frequency division ratio analysis based on the target correction adjustment difference to determine the target frequency division ratio correction value;
[0024] Match the correction control instruction according to the correction direction, and fill the target frequency division ratio correction value in the matching result at the target position to obtain the target correction instruction;
[0025] The target correction instruction is used to adjust the current RTC clock division, and after the adjustment is completed, the temperature is obtained and the current temperature is updated according to the calibration position of the RTC clock.
[0026] Furthermore, when performing RTC clock error analysis based on the electronic timer and the timer, error analysis is performed for multiple corrections, and data information of time counting based on the set alarm wake-up time during each correction process is obtained to obtain the timer timing time, and the timer timing time is combined with the set alarm wake-up time for error analysis to obtain correction error data, and then the data information of the electronic timer in each correction process is obtained to obtain the electronic timer data measurement information, and then the clock source frequency division is determined based on the electronic timer data measurement information, and the clock source frequency division is combined with the correction error data for overall analysis to determine the optimal correction result.
[0027] Furthermore, when the current temperature is acquired at the calibration position, multi-point temperature acquisition is performed at the calibration position to obtain multiple monitoring temperature data, and then a preliminary analysis is performed on the multiple monitoring temperature data to determine whether the monitoring temperature data are consistent. When the monitoring temperature data are consistent, the monitoring temperature data is the current temperature of the RTC clock calibration position. When the monitoring temperature data are inconsistent, an extreme value analysis is performed on the monitoring temperature, and the extreme values are used as the current temperature and the historical temperature for difference analysis.
[0028] Further, when determining whether the temperature difference is greater than a first threshold, the temperature difference is compared with the first threshold in numerical value, wherein the first threshold is preset, and when setting the first threshold, the target setting data is immediately converted, including:
[0029] Acquire target setting data and determine unit information of the target setting data;
[0030] Analyze whether the unit information of the target setting data is the same as the unit information of the current temperature, and obtain the temperature unit analysis and judgment result;
[0031] When the unit information of the target setting data is different from the unit information of the current temperature according to the temperature unit analysis result, a unit conversion rule between the unit information of the target setting data and the unit information of the current temperature is determined;
[0032] The unit conversion is performed on the target setting data according to the unit conversion rule between the unit information of the target setting data and the unit information of the current temperature.
[0033] The present invention combines timer counting to calibrate the RTC low-speed clock source, realizes the automatic intelligent calibration of the RTC clock based on the low-speed internal clock source, thereby improving the calibration accuracy of the LSI over the full temperature range, and further improving the accuracy of the RTC clock. By initializing and setting the timer, it is not only convenient to set the timer on demand, but also can avoid the interference of the timer's historical setting data, ensure the accuracy of the timer, and form a comparison between the electronic counter and the timer to digitize the RTC clock error, so that the error can be more intuitively clarified, providing convenience for calibration optimization, and by obtaining the current temperature, the correction position can be calibrated in time when the temperature changes, and the LSI frequency division mark is adjusted by updating the LSI frequency division mark, so that the LSI can output stably, reduce the impact of temperature changes on the LSI, and improve the calibration accuracy of the LSI over the full temperature range, and further improve the accuracy of the RTC clock.
[0034] Other features and advantages of the present invention will be described in the following description, and partly become apparent from the description, or understood by practicing the present invention. The purpose and other advantages of the present invention can be realized and obtained by the structures particularly pointed out in the written description, claims, and drawings.
[0035] The technical solution of the present invention is further described in detail below through the accompanying drawings and embodiments. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] The accompanying drawings are used to provide a further understanding of the present invention and constitute a part of the specification. Together with the embodiments of the present invention, they are used to explain the present invention and do not constitute a limitation of the present invention. In the accompanying drawings:
[0037] Figure 1 A schematic diagram of the steps of a method for calibrating an RTC clock based on a low-speed internal clock source according to the present invention;
[0038] Figure 2 It is a flowchart diagram of step 4 of a method for calibrating an RTC clock based on a low-speed internal clock source according to the present invention;
[0039] Figure 3 It is a partial step schematic diagram of step 5 of a method for calibrating an RTC clock based on a low-speed internal clock source according to the present invention;
[0040] Figure 4 This is an example data diagram of RTC clock error analysis in step 5 of a method for calibrating an RTC clock based on a low-speed internal clock source according to the present invention;
[0041] Figure 5The present invention is a schematic diagram of the steps for setting the first threshold in step three of the RTC clock calibration method based on a low-speed internal clock source. DETAILED DESCRIPTION
[0042] The preferred embodiments of the present invention are described below in conjunction with the accompanying drawings. It should be understood that the preferred embodiments described herein are only used to illustrate and explain the present invention, and are not used to limit the present invention.
[0043] like Figure 1 As shown, an embodiment of the present invention provides a method for calibrating an RTC clock based on a low-speed internal clock source, comprising:
[0044] Step 1: Determine the calibration position of the RTC clock and obtain the current temperature at the calibration position;
[0045] Step 2: Initialize the timer and start the electronic timer to count;
[0046] Step 3: Perform a difference analysis on the current temperature and the historical temperature to determine whether the temperature difference is greater than a first threshold value, thereby obtaining a first analysis and determination result;
[0047] Step 4: according to the first analysis and judgment result, set the time for the initialized timer, and update and record the RTC interrupt data and LSI frequency division mark in combination with the timer and the electronic counter;
[0048] Step 5. When the RTC interrupt record data is greater than the second threshold, obtain the RTC clock division, then estimate the division ratio based on the RTC clock division, and correct the original RTC clock division according to the RTC clock estimated division ratio combined with the LSI division mark, and perform RTC clock error analysis based on the electronic timer and timer.
[0049] In the above technical solution, the historical temperature refers to the current temperature at the last moment obtained at the calibration position.
[0050] In the above technical solution, the first threshold is a boundary value set for the temperature difference, which can be adjusted according to the actual application scenario. When adjusting and setting the first threshold, the power consumption in standby mode and the RTC clock accuracy are considered. Here, the first threshold is usually 5, so that when determining the first analysis and judgment result, the temperature difference is compared with 5 to obtain the first analysis and judgment result. This can not only make the deviation impact of the RTC clock on the internal LSI within an acceptable range and reduce frequent calibration operations, but also make the system power consumption during frequent wake-up and calibration in the storage state within an acceptable range, so as to meet and balance the dual factors of power consumption in standby mode and RTC clock accuracy.
[0051] In the above technical solution, the second threshold is a boundary value set for the RTC interrupt record data. The larger the value, the longer the calibration time and the higher the accuracy of the RTC clock. For example, if the second threshold is 3, when the RTC interrupt record data is greater than 3, the RTC clock frequency division is obtained, and then the frequency division ratio is estimated according to the RTC clock frequency division, and the original RTC clock frequency division is corrected according to the RTC clock estimated frequency division ratio combined with the LSI frequency division mark, and the RTC clock error is analyzed at the same time.
[0052] In the above technical solution, when performing RTC clock error analysis based on the electronic timer and the timer, the error analysis is performed based on the recorded data of the electronic counter and the timing setting data of the timer.
[0053] The above technical solution combines the timer count to calibrate the RTC low-speed clock source, and realizes the automatic intelligent calibration of the RTC clock based on the low-speed internal clock source, thereby improving the calibration accuracy of the LSI over the full temperature range, and further improving the accuracy of the RTC clock. By initializing the timer, it is not only convenient to set the timer on demand, but also can avoid the interference of the timer's historical setting data, and ensure the accuracy of the timer. By comparing the electronic counter with the timer, the RTC clock error is digitized, so that the error can be more intuitively clarified, providing convenience for calibration optimization, and by obtaining the current temperature, the correction position can be calibrated in time when the temperature changes, and the LSI frequency division flag is adjusted by updating the LSI frequency division flag, so that the LSI can output stably, reduce the impact of temperature changes on the LSI, and improve the calibration accuracy of the LSI over the full temperature range, and further improve the accuracy of the RTC clock.
[0054] In one embodiment provided by the present invention, the initialization setting of the timer includes: determining the current setting state of the timer, analyzing whether the current setting state of the timer is the initial state of the timer, obtaining the timer setting state analysis and judgment result, and then restoring the current setting of the timer to the initial state according to the timer setting state analysis and judgment result.
[0055] In the above technical solution, when the result of the timer setting state analysis is that the current setting state of the timer is the initial state of the timer, there is no need to restore the initial state again and the Systick timing setting and the alarm wake-up time setting can be directly performed. When the result of the timer setting state analysis is that the current setting state of the timer is not the initial state of the timer, the current setting of the timer is restored to the initial state, and then the Systick timing setting and the alarm wake-up time setting can be performed again based on the initial state of the timer.
[0056] The above technical solution can adjust the Systick timing setting and the alarm wake-up time setting based on the initialization state of the timer by initializing the timer, which can not only avoid the influence of the current setting state of the timer on the Systick timing setting and the alarm wake-up time setting, but also provide convenience for the Systick timing setting and the alarm wake-up time setting, and determine by analyzing the timer setting state, so that when the timer setting state analysis and judgment result is that the current setting state of the timer is the initial state of the timer, the Systick timing setting and the alarm wake-up time setting are directly performed, thereby reducing unnecessary time waste and improving the efficiency of initializing the timer.
[0057] In one embodiment provided by the present invention, when setting the time for the initialized timer according to the first analysis and judgment result, the LSI frequency division flag is obtained according to the first analysis and judgment result. When the first analysis and judgment result is that the temperature difference is greater than the first threshold value, the current data of the LSI frequency division flag is obtained, and then the current data of the LSI frequency division flag is analyzed and judged whether it is equal to 1, and the second analysis and judgment result is obtained. When the second analysis and judgment result is that the current data of the LSI frequency division flag is equal to 1, the timing time of the timer and the alarm wake-up time are set, and then the metering data information of the timer and the electronic counter is obtained, so as to update the record of the RTC interrupt data and the LSI frequency division flag according to the metering information of the timer and the electronic counter.
[0058] In the above technical solution, when the first analysis and judgment result is that the temperature difference is not greater than the first threshold, the new current temperature continues to be acquired, and the difference analysis is performed between the current temperature and the historical temperature.
[0059] In the above technical solution, when the second analysis and judgment result is that the current data of the LSI frequency division flag is not equal to 1, the LSI frequency division flag is continuously monitored and acquired.
[0060] In the above technical solution, when setting the timer's timing and alarm wake-up time, the time unit of Systick timing setting is ms. For example, Systick timing is set to 1ms for the convenience of time calculation. Systick timing can also be set to other time data. The time unit of alarm wake-up time setting is s. For example, WakeT (alarm wake-up time) is set to 10S.
[0061] In the above technical solution, when obtaining metering data information for the timer and the electronic counter, the timer and the electronic counter are monitored in real time to obtain the overall status information of the timer and the electronic counter, wherein the overall status information includes: whether an interruption occurs, metering data, etc.
[0062] The above technical solution performs calibration in time according to the first analysis and judgment result when the first analysis and judgment result is that the temperature difference is greater than the first threshold value, and combines the RTC interrupt data and the LSI division flag, so that the output signal can be adjusted in time when the temperature at the calibration position of the RTC clock changes significantly, thereby reducing the impact of temperature on the LSI and ensuring the stable output of the RTC clock of the low-speed internal clock source.
[0063] like Figure 2 As shown, in one embodiment provided by the present invention, when updating and recording RTC interrupt data and LSI frequency division flag according to the metering information of the timer and the electronic counter, the timer is analyzed to generate a Systick interrupt according to the timing time. When the timer generates a Systick interrupt according to the timing time, the overflow signal of the electronic counter is obtained, the LSI frequency division flag is updated according to the overflow signal, the LSI frequency division flag update data is obtained, and the Systick interrupt count is performed according to the LSI frequency division flag update data. At the same time, it is analyzed and determined whether the LSI frequency division flag update data is equal to a third threshold value to obtain a third analysis and judgment result. When the third analysis and judgment result is that the LSI frequency division flag update data is equal to the third threshold value, the RTC is interrupted, and the RTC interrupt data record data is updated. Then, it is analyzed and determined whether the updated RTC interrupt data record data is equal to the third threshold value to obtain a fourth analysis and judgment result, and the RTC clock frequency division is obtained according to the fourth analysis and judgment result.
[0064] In the above technical solution, when the third analysis result is that the LSI frequency division flag update data is not equal to the third threshold, the LSI frequency division flag update data is continuously monitored and the obtained LSI frequency division flag update data is compared with the third threshold.
[0065] In the above technical solution, the third threshold is the data boundary value of the LSI frequency division flag, which can be adjusted according to actual application requirements. For example, when the third threshold is 3, the obtained LSI frequency division flag update data is compared with 3. When the LSI frequency division flag update data is equal to 3, the RTC is interrupted.
[0066] In the above technical solution, when Systick interrupt counting is performed according to the LSI frequency division flag update data, if the LSI frequency division flag update data is equal to 2, the Systick interrupt mSecCount is automatically incremented.
[0067] In the above technical solution, when the LSI frequency division flag is updated according to the overflow signal, when the frequency of the overflow signal increases, the frequency divider needs to be divided into more segments, so the LSI frequency division flag will change; when the frequency of the overflow signal decreases, the frequency divider needs to be divided into fewer segments, and the LSI frequency division flag will also change accordingly.
[0068] In the above technical solution, when the RTC interrupt data record data is updated, the RTC interrupt mSecCount is automatically incremented.
[0069] In the above technical solution, when the RTC clock frequency division is obtained according to the fourth analysis and judgment result, if the fourth analysis and judgment result is that the updated RTC interrupt data record data is equal to the third threshold, the RTC clock frequency division is obtained, otherwise the LSI frequency division flag is continued to be analyzed and judged.
[0070] The above technical solution realizes the measurement of time and number through a timer and an electronic counter, so that in the calibration method of the RTC clock based on the low-speed internal clock source, the measurement of time and process can be realized automatically, without the need for manual monitoring, thus saving manpower, and with a small error, thereby realizing a more accurate calibration of the RTC clock based on the low-speed internal clock source.
[0071] In one embodiment provided by the present invention, when the RTC is interrupted, it is also determined whether the LSI frequency division flag update data is equal to 0 to obtain a fifth analysis and judgment result. According to the fifth analysis and judgment result, when the LSI frequency division flag update data is not equal to 0, data analysis is performed on the RTC interrupt mSecCount self-increment count, and the size of the LSI frequency division flag update data is adjusted to the third threshold.
[0072] In the above technical solution, when analyzing the data of the RTC interrupt mSecCount self-increment count, RTC_SecCountAcc=RTC_SecCount+(RTC_SecCountAcc) is used. ′ The accumulated value of the self-increment count at the last RTC interruption and the self-increment count data in the current RTC interruption are accumulated. RTC_SecCountAcc represents the accumulated value of the self-increment count in the RTC interruption, and RTC_SecCount represents the self-increment count data in the current RTC interruption. For example, when the alarm wake-up time is 10s, RTC_SecCount is the self-increment count data in the current 10-second RTC interruption. (RTC_SecCountAcc) ′ Indicates the accumulated value of the self-increment count when the RTC was last interrupted.
[0073] The above technical solution realizes interrupt monitoring of the RTC clock, so that the interruption of the RTC clock can be discovered in time, and the impact of the RTC clock interruption can be reduced. Moreover, when the RTC clock is interrupted, it is determined whether the LSI frequency division flag is equal to 0 to determine whether it is caused by the LSI frequency division flag being equal to 0. Then, it is possible to determine in time whether the RTC clock interruption is caused by an abnormal phenomenon, thereby avoiding the LSI frequency division flag being equal to 0 for a long time and affecting the LSI output.
[0074] In one embodiment provided by the present invention, estimating the frequency division ratio according to the RTC clock frequency division includes:
[0075] Determine the actual output signal frequency of the RTC clock according to the RTC clock division to obtain RTC_PreReal;
[0076] Obtain the accumulated data of the self-increment count in the case of RTC interruption, and perform mean calculation in combination with the second threshold to determine the count average value in the case of RTC interruption, and obtain mSecCountAvg;
[0077] Use RTC_PreReal combined with mSecCountAvg to perform estimated division ratio analysis and calculation to obtain the estimated division ratio of the RTC clock.
[0078] In the above technical solution, the accumulated data of the self-increment count in the case of RTC interruption is obtained, and the average value is calculated in combination with the second threshold to determine the average value of the count in the case of RTC interruption. For example, if the second threshold is 3, then mSecCountAvg = RTC_SecCountAcc / 3, and mSecCountAvg is the average value of the self-increment count based on the alarm wake-up time in the case of RTC interruption.
[0079] In the above technical solution, when RTC_PreReal is combined with mSecCountAvg to perform the estimated division ratio analysis and calculation, the estimated division ratio of the RTC clock is calculated by the following formula:
[0080] RTC_PreNew=10000*RTC_PreReal / mSecCountAvg
[0081] Among them, RTC_PreNew represents the estimated division ratio of the RTC clock, RTC_PreReal represents the actual output signal frequency of the RTC clock, and mSecCountAvg represents the average value of the self-increment count based on the alarm wake-up time in the case of RTC interruption. For example, when the alarm wake-up time is 10s, mSecCountAvg is the average value of the count every 10 seconds in the case of RTC interruption.
[0082] The above technical solution calculates the estimated data by using RTC_PreReal in combination with mSecCountAvg, so that the estimated data can be consistent with the actual situation, reduce the error of the estimated data, and ensure the credibility of the estimated data.
[0083] like Figure 3 As shown, in one embodiment provided by the present invention, the original frequency division of the RTC clock is corrected according to the estimated frequency division ratio of the RTC clock combined with the LSI frequency division mark, including:
[0084] A1. Determine the target frequency division of the RTC clock according to the estimated frequency division ratio of the RTC clock;
[0085] A2. Obtain the current RTC clock frequency division for the RTC clock to obtain the original RTC clock frequency division;
[0086] A3. Analyze the relative relationship between the original RTC clock frequency division and the target RTC clock frequency division in combination with the RTC clock target frequency division to determine the correction direction;
[0087] A4. Perform difference analysis on the original frequency division of the RTC clock and the target frequency division of the RTC clock to obtain the target frequency division correction adjustment difference;
[0088] A5. Perform frequency division ratio analysis based on the target correction adjustment difference to determine the target frequency division ratio correction value;
[0089] A6. Match the correction control instruction according to the correction direction, and fill the target frequency division ratio correction value in the matching result at the target position to obtain the target correction instruction;
[0090] A7. Use the target correction instruction to adjust the current RTC clock division frequency, and after the adjustment is completed, obtain the temperature and update the current temperature according to the calibration position of the RTC clock.
[0091] In the above technical solution, when the frequency division ratio analysis is performed based on the target correction adjustment difference, the frequency division ratio analysis is performed on the target correction adjustment difference based on the mapping relationship between the frequency division and the frequency division ratio, so as to determine the target frequency division ratio correction value.
[0092] In the above technical solution, the correction control instruction is a correction control instruction template formed in advance for the correction direction, and only the vacant positions in the correction control instruction template need to be filled to obtain a complete and correct target correction instruction.
[0093] In the above technical solution, after the adjustment is completed, the temperature of the calibration position of the RTC clock is acquired and the current temperature is updated, the temperature of the calibration position of the RTC clock is reacquired, and then the current temperature is updated, and the temperature acquired at this time is used as the current temperature and the current temperature before the update is analyzed for difference.
[0094] The above technical solution determines the target frequency division of the RTC clock according to the estimated frequency division ratio of the RTC clock, so that correction analysis is performed based on the frequency division, thereby avoiding correction errors caused by small differences in the numerical values of the frequency division ratio, ensuring the accuracy of the calibration method of the RTC clock based on the low-speed internal clock source, and matching the correction control instructions according to the correction direction so that the target correction instructions are determined based on the existing correction control instruction template, not only will there be no correction errors, but the determination efficiency of the target correction instructions is also high. In addition, after the adjustment is completed, temperature acquisition and current temperature update for the calibration position of the RTC clock can realize continuous analysis of the temperature of the calibration position of the RTC clock, and realize continuous calibration based on the calibration position of the RTC clock.
[0095] In one embodiment provided by the present invention, when performing RTC clock error analysis based on an electronic timer and a timer, an error analysis is performed for multiple corrections, and data information of time counting based on the set alarm wake-up time during each correction process is obtained to obtain the timer timing time, and the timer timing time is combined with the set alarm wake-up time to perform error analysis to obtain correction error data, and then the data information of the electronic timer in each correction process is obtained to obtain the electronic timer data measurement information, and then the clock source frequency division is determined based on the electronic timer data measurement information, and the clock source frequency division is combined with the correction error data for overall analysis to determine the optimal correction result.
[0096] In the above technical solution, multiple calibrations can be distinguished by serial numbers in the form of serial numbers.
[0097] In the above technical solution, the clock source frequency division combined with the correction error data for overall analysis can organize the data information in the form of charts, such as Figure 4 As shown, it provides more intuitive data support for correcting the optimal result.
[0098] The above technical solution clarifies the optimal situation among multiple corrections by performing error analysis, so that the calibration situation of the RTC clock based on the low-speed internal clock source can be better understood, and multiple corrections are distinguished by serial numbers in the form of serial numbers, which facilitates the distinction between multiple corrections, so that multiple corrections can have simple identification and are easy to correspond.
[0099] In one embodiment provided by the present invention, when the current temperature is acquired at the calibration position, multi-point temperature acquisition is performed at the calibration position to obtain multiple monitoring temperature data, and then a preliminary analysis is performed on the multiple monitoring temperature data to determine whether the monitoring temperature data are consistent. When the monitoring temperature data are consistent, the monitoring temperature data is the current temperature of the RTC clock calibration position. When the monitoring temperature data are inconsistent, an extreme value analysis is performed on the monitoring temperature data, and the extreme values are used as the current temperature and the historical temperature for difference analysis.
[0100] In the above technical solution, the extreme value includes a maximum value and a minimum value. When the extreme value is used as the current temperature and the historical temperature for difference analysis, a first temperature difference and a second temperature difference are obtained according to the maximum value and the minimum value respectively. When either the first temperature difference or the second temperature difference is greater than the first threshold value, the first analysis judgment result is that the temperature difference is greater than the first threshold value.
[0101] In the above technical scheme, when performing extreme value analysis on the monitored temperature data, a fluctuation analysis is performed on the monitored temperature data to obtain the variance of the monitored temperature data, and then it is determined whether the variance of the monitored temperature data is greater than the preset variance limit. When the variance of the monitored temperature data is greater than the preset variance limit, the monitored temperature data is directly compared to determine the maximum and minimum values of the monitored temperature. Otherwise, the monitored temperature data is amplified to obtain monitored temperature processed data, and then the monitored temperature processed data are compared to determine the maximum and minimum values of the compared monitored temperature processed data, thereby obtaining the maximum and minimum values of the monitored temperature based on the comparison of the maximum and minimum values of the compared monitored temperature processed data.
[0102] The above technical solution obtains the temperature of the calibration position more comprehensively by acquiring multiple temperature points at the calibration position, thereby avoiding the inaccurate first analysis and judgment result caused by uneven temperature distribution at the calibration position, thereby ensuring the accuracy of the RTC clock calibration method based on the low-speed internal clock source.
[0103] like Figure 5 As shown, in one embodiment provided by the present invention, when determining whether the temperature difference is greater than a first threshold, the temperature difference is compared with the first threshold in numerical value, wherein the first threshold is preset, and when setting the first threshold, the target setting data is immediately converted, including:
[0104] B1. Obtain target setting data and determine unit information of the target setting data;
[0105] B2. Analyze whether the unit information of the target setting data is the same as the unit information of the current temperature, and obtain the temperature unit analysis and judgment result;
[0106] B3. when the unit information of the target setting data is different from the unit information of the current temperature according to the temperature unit analysis result, determine the unit conversion rule between the unit information of the target setting data and the unit information of the current temperature;
[0107] B4. Perform unit conversion on the target setting data according to the unit conversion rule between the unit information of the target setting data and the unit information of the current temperature.
[0108] In the above technical solution, the unit information of the target setting data may be Celsius, Fahrenheit, or Kelvin.
[0109] In the above technical solution, when the unit information of the target setting data is the same as the unit information of the current temperature according to the temperature unit analysis result, there is no need to perform unit conversion on the target setting data.
[0110] The above technical solution performs a difference analysis between the current temperature and the historical temperature to make the difference between the current temperature and the historical temperature clear, without considering whether it is a positive difference or a negative difference, thereby simplifying the process of determining the first analysis and judgment result, and is not prone to analysis and judgment errors. When setting the first threshold, the target setting data is converted instantly, so that the target setting data of any unit can be judged. This not only reduces the setting requirements of the target setting data, but also allows the data of any unit to be set, providing convenience for relevant personnel to set the first threshold. At the same time, the target setting data is converted instantly so that the temperature difference can be directly compared and judged with the first threshold, thereby facilitating the determination of the first analysis and judgment result.
[0111] Those skilled in the art should understand that the first and second in the present invention merely refer to different application stages.
[0112] Other embodiments of the present disclosure will be readily apparent to those skilled in the art after considering the specification and practicing the disclosure disclosed herein. This application is intended to cover any variations, uses, or adaptations of the present disclosure that follow the general principles of the present disclosure and include common knowledge or customary techniques in the art that are not disclosed in the present disclosure. The specification and examples are to be considered as exemplary only, and the true scope and spirit of the present disclosure are indicated by the following claims.
[0113] It should be understood that the present disclosure is not limited to the exact structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.
Claims
1. A method for calibrating an RTC clock based on a low-speed internal clock source, characterized in that: include: Determine the calibration position of the RTC clock and obtain the current temperature at the calibration position; Initialize the timer and start the electronic timer to count; Performing a difference analysis on the current temperature and the historical temperature to determine whether the temperature difference is greater than a first threshold value, thereby obtaining a first analysis and determination result; According to the first analysis and judgment result, the time is set for the initialized timer, and the RTC interrupt data and the LSI frequency division mark are updated and recorded in combination with the timer and the electronic counter; When the RTC interrupt record data is greater than the second threshold, the RTC clock division is obtained, and then the division ratio is estimated based on the RTC clock division. The original RTC clock division is corrected according to the RTC clock estimated division ratio combined with the LSI division flag, and the RTC clock error analysis is performed based on the electronic timer and timer.
2. The method according to claim 1, characterized in that: The initialization setting of the timer includes: determining the current setting state of the timer, analyzing whether the current setting state of the timer is the initial state of the timer, obtaining the timer setting state analysis and judgment result, and then restoring the current setting of the timer to the initial state according to the timer setting state analysis and judgment result.
3. The method according to claim 1, characterized in that When setting the time for the initialized timer according to the first analysis and judgment result, the LSI frequency division flag is obtained according to the first analysis and judgment result. When the first analysis and judgment result is that the temperature difference is greater than the first threshold value, the current data of the LSI frequency division flag is obtained, and then the current data of the LSI frequency division flag is analyzed and judged whether it is equal to 1, and the second analysis and judgment result is obtained. When the second analysis and judgment result is that the current data of the LSI frequency division flag is equal to 1, the timing time of the timer and the alarm wake-up time are set, and then the metering data information of the timer and the electronic counter is obtained, so as to update the record of the RTC interrupt data and the LSI frequency division flag according to the metering information of the timer and the electronic counter.
4. The method according to claim 3, characterized in that When the RTC interrupt data and the LSI frequency division flag are updated and recorded according to the metering information of the timer and the electronic counter, the Systick interrupt occurs at the timing time according to the analysis of the timer. When the Systick interrupt occurs at the timing time, the overflow signal of the electronic counter is obtained, the LSI frequency division flag is updated according to the overflow signal, the LSI frequency division flag update data is obtained, and the Systick interrupt count is performed according to the LSI frequency division flag update data. At the same time, it is analyzed and determined whether the LSI frequency division flag update data is equal to the third threshold value to obtain a third analysis and judgment result. When the third analysis and judgment result is that the LSI frequency division flag update data is equal to the third threshold value, the RTC is interrupted and the RTC interrupt data record data is updated. Then, it is analyzed and determined whether the updated RTC interrupt data record data is equal to the third threshold value to obtain a fourth analysis and judgment result, and the RTC clock frequency division is obtained according to the fourth analysis and judgment result.
5. The method according to claim 4, characterized in that When the RTC is interrupted, it is also determined whether the LSI frequency division flag update data is equal to 0, and the fifth analysis and judgment result is obtained. According to the fifth analysis and judgment result, when the LSI frequency division flag update data is not equal to 0, data analysis is performed on the RTC interrupt mSecCount self-increment count, and the size of the LSI frequency division flag update data is adjusted to the third threshold.
6. The method according to claim 5, characterized in that Estimation of the division ratio based on the RTC clock division includes: Determine the actual output signal frequency of the RTC clock according to the RTC clock division to obtain RTC_PreReal; Obtain the accumulated data of the self-increment count in the case of RTC interruption, and perform mean calculation in combination with the second threshold to determine the count average value in the case of RTC interruption, and obtain mSecCountAvg; Use RTC_PreReal combined with mSecCountAvg to perform estimated division ratio analysis and calculation to obtain the estimated division ratio of the RTC clock.
7. The method according to claim 1, characterized in that According to the estimated division ratio of the RTC clock and the LSI division mark, the original division ratio of the RTC clock is corrected, including: Determine the target frequency division of the RTC clock according to the estimated frequency division ratio of the RTC clock; The current RTC clock frequency division is obtained for the RTC clock to obtain the original RTC clock frequency division; Analyze the relative relationship between the original RTC clock frequency division and the target RTC clock frequency division in combination with the RTC clock target frequency division to determine the correction direction; Perform difference analysis on the original frequency division of the RTC clock and the target frequency division of the RTC clock to obtain the target frequency division correction adjustment difference; Perform frequency division ratio analysis based on the target correction adjustment difference to determine the target frequency division ratio correction value; Match the correction control instruction according to the correction direction, and fill the target frequency division ratio correction value in the matching result at the target position to obtain the target correction instruction; The target correction instruction is used to adjust the current RTC clock division, and after the adjustment is completed, the temperature is obtained and the current temperature is updated according to the calibration position of the RTC clock.
8. The method according to claim 1, characterized in that When performing RTC clock error analysis based on electronic timers and timers, error analysis is performed for multiple corrections, and data information of time counting based on the set alarm wake-up time during each correction process is obtained to obtain the timer timing time, and the timer timing time is combined with the set alarm wake-up time for error analysis to obtain correction error data, and then the data information of the electronic timer in each correction process is obtained to obtain the electronic timer data measurement information, and then the clock source frequency division is determined based on the electronic timer data measurement information, and the clock source frequency division is combined with the correction error data for overall analysis to determine the optimal correction result.
9. The method according to claim 1, characterized in that: When acquiring the current temperature at the calibration position, multi-point temperature acquisition is performed at the calibration position to obtain multiple monitored temperature data, and then a preliminary analysis is performed on the multiple monitored temperature data to determine whether the monitored temperature data are consistent. When the monitored temperature data are consistent, the monitored temperature data is the current temperature of the RTC clock calibration position. When the monitored temperature data are inconsistent, an extreme value analysis is performed on the monitored temperature, and the extreme values are used as the current temperature and the historical temperature for difference analysis.
10. The method according to claim 1, characterized in that When determining whether the temperature difference is greater than a first threshold, the temperature difference is compared with the first threshold in numerical value, wherein the first threshold is preset, and when setting the first threshold, the target setting data is immediately converted, including: Acquire target setting data and determine unit information of the target setting data; Analyze whether the unit information of the target setting data is the same as the unit information of the current temperature, and obtain the temperature unit analysis and judgment result; When the unit information of the target setting data is different from the unit information of the current temperature according to the temperature unit analysis result, a unit conversion rule between the unit information of the target setting data and the unit information of the current temperature is determined; The unit conversion is performed on the target setting data according to the unit conversion rule between the unit information of the target setting data and the unit information of the current temperature.
