Real-time clock RTC fault detection method and system

By building interrupt service and verification variables in the main control chip of the real-time clock RTC, detecting the error signal of the RTC, the problem of only one type of fault detection in the prior art is solved, and accurate detection and automatic calibration of multiple RTC faults is achieved, reducing detection cost and complexity.

CN119739575APending Publication Date: 2025-04-01国电投新电智控(保定)科技有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411713134.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-27
Publication Date
2025-04-01

AI Technical Summary

Technical Problem

The prior art has limitations when detecting faults of real-time clock RTCs. It can only detect one type of fault, the detection results are less reliable and require additional hardware equipment, resulting in higher detection costs.

Method used

The interrupt service is constructed by the internal timer of the master chip equipped with the real-time clock RTC, the initial time of the RTC register is set, and the RTC is calibrated according to the real time. Then, by reading the numerical value of the RTC register and the constructed verification variable, the error signal is calculated to determine whether the RTC has an external power supply failure, a crystal oscillator failure or a frequency abnormality.

Benefits of technology

It realizes the accurate identification of various possible faults that may occur in the RTC without adding external hardware devices, reduces detection costs, improves the accuracy and reliability of detection results, and has automatic calibration function.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119739575A_ABST
    Figure CN119739575A_ABST
Patent Text Reader

Abstract

The present application proposes a fault detection method and system for a real-time clock RTC, the method comprising: constructing an interrupt service through the internal timer of the main control chip, setting the initial time of the RTC register when the program is first burned, and calibrating the RTC according to the real time; after the chip is powered on again, reading the first value of the RTC register, judging whether the RTC has an external power supply failure, and constructing a check variable based on the interrupt service; calculating a first error signal according to the first value and the check variable, reading the real-time second value in the RTC register after the change of the RTC detection cycle, judging whether the RTC crystal oscillator fails; calculating a second error signal according to the second value and the changed check variable, comparing the first error signal and the second error signal to judge whether the frequency of the RTC crystal oscillator is abnormal. The method does not require additional equipment, and can accurately identify multiple faults and reduce detection costs by detecting the accuracy of the RTC in real time through software algorithms.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of real-time clock detection and calibration, and in particular to a real-time clock (RTC) fault detection method and system. Background Art

[0002] At present, Real Time Clock (RTC) has been widely used in various fields such as industrial manufacturing, commercial machine maintenance, medical equipment management and agricultural facilities due to its high time accuracy. RTC function can be integrated in any electronic device that requires real-time monitoring. RTC plays a key role in embedded systems. It can accurately track time and date when the device is disconnected from the network or the main power is turned off. RTC is powered by a special battery and can continue to run even when the system power is turned off. However, in actual applications, RTC may also fail, resulting in errors in the time it provides. Therefore, it is necessary to test the accuracy of RTC to determine whether it has failed.

[0003] In the related art, an independent timer is generally used to compare with the RTC clock frequency, and the accuracy of the RTC module clock frequency is determined by monitoring the RTC clock frequency. However, the detection method in the above related art has great limitations, and can only detect one type of fault. The reliability of the detection result is poor, and additional hardware equipment is required, resulting in high detection costs. Summary of the invention

[0004] The present application aims to solve one of the technical problems in the related art at least to some extent.

[0005] To this end, the first purpose of the present application is to propose a real-time clock (RTC) fault detection method, which does not require the addition of external hardware equipment. The accuracy of the RTC is detected in real time through a software algorithm, which can accurately identify multiple faults and reduce detection costs.

[0006] The second object of the present application is to provide a fault detection system for a real-time clock RTC;

[0007] A third object of the present application is to provide a non-transitory computer-readable storage medium.

[0008] To achieve the above object, the first aspect of the present application is to provide a real-time clock (RTC) fault detection method, the method comprising the following steps:

[0009] An interrupt service is established by using an internal timer of a main control chip equipped with a real-time clock RTC, an initial time of an RTC register is set when the main control chip is first programmed, and timing is started after the RTC is calibrated according to the real time;

[0010] After the main control chip is powered on again, a first value of the RTC register is read, and according to the first value, the initial time and a preset empirical value, whether an external power supply failure occurs to the RTC, and a check variable that increases every second is constructed based on the interrupt service;

[0011] Calculate a first error signal according to the first value and the check variable, read a real-time second value in the RTC register after the check variable changes through an RTC detection cycle, and determine whether an RTC crystal oscillator failure occurs according to the first value and the second value;

[0012] A second error signal is calculated according to the second value and the changed check variable, and whether the frequency of the RTC crystal oscillator is abnormal is determined by comparing the first error signal with the second error signal.

[0013] Optionally, in one embodiment of the present application, judging whether an external power supply failure occurs in the RTC based on the first value, the initial time and a preset empirical value includes: storing the read first value in a first variable, and calculating the difference between the first value and the initial time; comparing the difference with the empirical value, and judging that an external power supply failure occurs in the RTC when the difference is greater than zero and less than the empirical value.

[0014] Optionally, in one embodiment of the present application, calculating the first error signal based on the first numerical value and the verification variable includes: when reading the numerical value of the first variable, simultaneously reading the real-time numerical value of the verification variable; subtracting the real-time numerical value of the verification variable from the numerical value of the first variable to obtain the first error signal.

[0015] Optionally, in one embodiment of the present application, judging whether an RTC crystal oscillator failure occurs based on the first value and the second value includes: storing the read second value in a second variable, and comparing the relationship between the value of the first variable and the value of the second variable, and when the value of the first variable is equal to the value of the second variable, judging that the RTC crystal oscillator has failed; calculating the second error signal based on the second value and the changed check variable includes: adding the real-time value of the check variable when reading the value of the first variable to the RTC detection period, and calculating the real-time value of the check variable after the update; subtracting the real-time value of the check variable after the update from the value of the second variable to obtain the second error signal.

[0016] Optionally, in one embodiment of the present application, determining whether the frequency of the RTC crystal oscillator is abnormal by comparing the first error signal and the second error signal includes: calculating an error value obtained by subtracting the second error signal from the first error signal; when the error value is greater than zero, determining that the frequency of the RTC crystal oscillator is slower than the normal frequency; when the error value is less than zero, determining that the frequency of the RTC crystal oscillator is faster than the normal frequency; when the error value is equal to zero, determining that the frequency of the RTC crystal oscillator is normal.

[0017] Optionally, in one embodiment of the present application, after determining whether the frequency of the RTC crystal oscillator is abnormal, it also includes: calculating the sum of the second numerical value and the error value, and using the sum as a calibration parameter; writing the calibration parameter into the timing register of the RTC through a time calibration function to automatically calibrate the RTC time.

[0018] To achieve the above object, the second aspect of the present application further proposes a fault detection system for a real-time clock RTC, comprising the following modules:

[0019] A setting module is used to construct an interrupt service through the internal timer of a main control chip equipped with a real-time clock RTC, set the initial time of the RTC register when the main control chip is first programmed, and start timing after calibrating the RTC according to the real time;

[0020] A first detection module is used to read the first value of the RTC register after the main control chip is powered on again, determine whether the RTC has an external power supply failure according to the first value, the initial time and a preset empirical value, and construct a check variable that increases every second based on the interrupt service;

[0021] A second detection module is used to calculate a first error signal according to the first value and the check variable, read a real-time second value in the RTC register after the check variable changes through an RTC detection cycle, and determine whether an RTC crystal oscillator failure occurs according to the first value and the second value;

[0022] The third detection module is used to calculate a second error signal according to the second value and the changed check variable, and determine whether the frequency of the RTC crystal oscillator is abnormal by comparing the first error signal with the second error signal.

[0023] In order to implement the above embodiments, the third aspect of the present application also proposes a non-temporary computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the fault detection method of the real-time clock RTC in the above first aspect is implemented.

[0024] The technical solution provided by the embodiment of the present application brings at least the following beneficial effects: the present application can monitor the RTC timestamp in real time through relevant software algorithms to detect the accuracy of the device chip RTC without adding other external hardware devices and without relying on external communication, and can accurately detect various types of faults that may occur in the RTC. Therefore, on the one hand, the present application reduces the cost of RTC detection, saves external communication steps, and reduces the complexity of detection. On the other hand, it can detect a variety of faults and specifically locate the type of fault currently occurring in the RTC, improve the accuracy and reliability of the detection results, and refine the detection results. In addition, the present application can also realize the RTC automatic calibration function, report the fault after identifying the RTC fault, and calibrate the abnormal RTC clock signal at any time according to the RTC detection result. The calibration method is relatively simple, which is conducive to ensuring the normal and stable operation of the RTC function.

[0025] Additional aspects and advantages of the present invention will be given in part in the following description and in part will be obvious from the following description, or will be learned through practice of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS

[0026] The above and / or additional aspects and advantages of the present application will become apparent and easily understood from the following description of the embodiments in conjunction with the accompanying drawings, in which:

[0027] Figure 1 A flowchart of a real-time clock RTC fault detection method proposed in an embodiment of the present application;

[0028] Figure 2 A schematic diagram of the principle of a control chip equipped with an RTC function proposed in an embodiment of the present application;

[0029] Figure 3 A structural schematic diagram of a real-time clock RTC fault detection system proposed in an embodiment of the present application. DETAILED DESCRIPTION

[0030] Embodiments of the present invention are described in detail below, examples of which are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are intended to be used to explain the present invention, and should not be construed as limiting the present invention.

[0031] It should be noted that, when performing RTC detection in the relevant embodiments, a method based on independent timer monitoring of RTC clock frequency is generally adopted, including the following steps: 1. Determine the monitoring period: monitor the RTC clock frequency once at regular intervals; 2. Obtain the RTC clock frequency: at the beginning of each monitoring period, obtain the current RTC clock frequency and record it; 3. Start the timer; 4. Monitor the change of clock frequency: at the end of the monitoring period, stop the timer and obtain the value of the timer; 5. Calculate the clock error: calculate the clock error based on the change in clock frequency; 6. Update the record as a reference for the next monitoring period.

[0032] The detection method in the above-mentioned related embodiments uses an independent timer and RTC clock frequency for comparison, obtains two clock frequencies at the start and end of a period of time, compares them, and repeats the above process to obtain the clock frequencies in different time periods. If these clock frequencies are different, it means that there is a problem with the RTC clock signal.

[0033] However, this method has certain limitations. It can only be used to monitor the RTC clock frequency and determine the accuracy of the RTC module clock frequency. That is, this method can only detect abnormal RTC crystal frequency. In actual applications, other types of faults may occur in the RTC module, and the above detection method cannot detect other types of faults.

[0034] To this end, the present application proposes a real-time clock (RTC) fault detection method and system, which can accurately identify various possible faults of the RTC without adding additional external hardware devices.

[0035] A real-time clock RTC fault detection method and system proposed in an embodiment of the present invention will be described below with reference to the accompanying drawings.

[0036] Figure 1 A flowchart of a real-time clock RTC fault detection method proposed in an embodiment of the present application is shown in FIG. Figure 1 As shown, the method comprises the following steps:

[0037] Step S101, constructing an interrupt service through the internal timer of the main control chip equipped with the real-time clock RTC, setting the initial time of the RTC register when the main control chip is first programmed, and starting timing after calibrating the RTC according to the real time.

[0038] It should be noted that RTC, as an integrated circuit, generally works on a main control chip with RTC function. For example, taking the STM32F103 series chip as an example, RTC, as a peripheral function of the chip, requires the following hardware cooperation: first, an independent external power supply as a backup power supply (usually a battery or supercapacitor); second, an external 32.768kHz crystal oscillator is required as an independent RTC crystal oscillator. After the above two conditions are met, the software configures the relevant registers inside the RTC chip to ensure that the 32-bit counter in its internal backup register accumulates and counts at a fixed frequency (1Hz). The 32-bit counter is the RTC timestamp. The timestamp starts counting from the set moment, and a real moment can be obtained after calculation. Since there is an independent crystal oscillator and power supply module outside, the RTC can still run independently when the main control chip itself is not powered.

[0039] In actual applications, when the main control chip enables the RTC function for the first time, it will first set an initial time T0, and then call the time calibration function to calibrate the RTC according to the real time T1. After the calibration is completed, the RTC internal 32-bit counter will start counting from T1.

[0040] Based on the above description, it can be seen that the following faults may have occurred when the RTC is inaccurate: The first is that the external power supply fails, the backup register will fail after the main control chip loses power, the RTC counter does not accumulate, the main control chip is powered on again, and the counter will accumulate from the internal set time T0. The second is 2. The external crystal oscillator fails, the RTC counter does not accumulate, and remains at T0. The third is 3. The external crystal oscillator frequency is abnormal, and the RTC counter can still run but is inaccurate.

[0041] However, in the detection scheme in the above-mentioned related embodiments, only the third fault mentioned above can be tested. In addition, the 32.768kHz crystal oscillator frequency used by the RTC is relatively stable. Although it may be affected by some factors, these factors are not sufficient to cause frequent changes in frequency. First, the oscillation signal generated by the 32.768kHz crystal oscillator is divided 15 times by a frequency divider to obtain a 1Hz second signal. The frequency conversion in this process is fixed, ensuring the accuracy of the clock. Secondly, although the frequency of the crystal oscillator will be affected by temperature, voltage, load capacity, aging effect and manufacturing quality, these influences usually do not cause frequent changes in frequency, so the clock detection method in the above-mentioned related embodiments has limitations.

[0042] The RTC fault detection method of the present application does not rely on external devices and external communications, and can monitor the accuracy of the device chip RTC in real time, accurately detect the above three faults, and calibrate the faulty clock.

[0043] Specifically, first set the RTC on the main control chip, and use the internal timer of the main control chip to build an interrupt service.

[0044] As an example, Figure 2 As shown, the STM32F103 series chip main control chip is used. When the RTC is set on the STM32F103 series chip, the peripherals mainly include an external clock power supply and an RTC 32.768kHz crystal oscillator. The STM32F103 chip also has an external crystal oscillator that is an 8MHz high-precision crystal oscillator. Other types of main control chips can also be used in other examples, and this application does not limit this.

[0045] In this example, the internal timer interrupt function of the chip is used for timing. The specific implementation method is as follows: first use the internal timer of the main control chip to make a 1s interrupt, and set the initial time of the RTC backup register to T0 when the program is first burned. The value of T0 can be determined according to the actual situation. For example, it can be set to 0:0:0 on January 1, 2024, and then the RTC is calibrated to the real time T1.

[0046] Step S102, after the main control chip is powered on again, read the first value of the RTC register, determine whether the RTC has an external power supply failure based on the first value, the initial time and the preset empirical value, and construct a check variable that increases every second based on the interrupt service.

[0047] Specifically, the main control chip is powered on again in accordance with the program settings after the main control chip is initially burned and calibrated. During the power-off process of the main control chip, only the power supply of the main control chip is powered off, and the backup power supply of the RTC chip continues to supply power. At a certain moment after the main control chip is powered on again, the value in the RTC register is read, which is the first value t_real0, and then a check is performed based on the read value and the known value.

[0048] In one embodiment of the present application, judging whether an external power supply failure occurs in the RTC is determined based on a first numerical value, an initial time, and a preset empirical value, including: storing the read first numerical value in a first variable, and calculating the difference between the first numerical value and the initial time; comparing the difference with the empirical value, and judging that an external power supply failure occurs in the RTC when the difference is greater than zero and less than the empirical value.

[0049] Specifically, in this embodiment, the read first value t_real0 is first stored in the first variable t_real_count0, that is, t_real_count0=t_real0. Then, the fault judgment is performed using the following formula:

[0050] 0 <t_real0-T0<600s

[0051] Among them, 600s is the empirical value set in this embodiment, and this value can be adjusted according to actual conditions. The empirical value is used to reserve a computing time after the main control chip is powered on. The smaller the value, the faster the RTC power supply failure is detected. This embodiment combines historical experience and experimental tests to determine that the empirical value is reserved for more than 30s.

[0052] Furthermore, when the above formula is satisfied, it indicates that the RTC register is counting, but the counting starts from T0. At this time, the failure of the RTC external power supply is detected, that is, the first type of fault is detected, and the detected fault is reported.

[0053] Furthermore, while the first value is read for detection, a check variable t_test_count is set, the value of which starts from 0 and increases by 1 per second with a period of 1 second. The 1 second time interval in this process is provided by the internal timer interrupt service function of the main control chip.

[0054] Step S103, calculating a first error signal according to the first value and the check variable, reading a real-time second value in the RTC register after the check variable changes through an RTC detection cycle, and determining whether an RTC crystal oscillator failure occurs according to the first value and the second value.

[0055] Specifically, the error signal is first calculated based on the read first value and the check variable, and the operation can be performed using the variable storing the value. In one embodiment of the present application, the first error signal is calculated based on the first value and the check variable, including: when reading the value of the first variable, simultaneously reading the real-time value of the check variable; subtracting the real-time value of the check variable from the value of the first variable to obtain the first error signal.

[0056] Specifically, in this embodiment, the first error signal is calculated and stored in the error recording variable t_test_err0, where t_test_err0=t_real_count0-t_test_count. The initial value of the t_test_count variable is zero. When the error calculation is performed here, its specific value is equal to the real-time value of the t_test_count variable when the value of the t_real_count0 variable is read. For example, when calculating the first error signal, the value of t_test_count can be a given value, such as 100, which means that the RTC value and the value of the test variable are read at the moment when the main control chip is powered on again for 100 seconds, and the error t_test_err0 of the two values ​​is calculated at the same time.

[0057] Further, the fault detection is continued, and after the RTC detection cycle changes, the possible fault of the RTC is detected according to the change of the value in the RTC register. In one embodiment of the present application, judging whether the RTC crystal oscillator fails according to the first value and the second value includes: storing the read second value in a second variable, and comparing the relationship between the value of the first variable and the value of the second variable, and judging that the RTC crystal oscillator fails when the value of the first variable is equal to the value of the second variable.

[0058] Specifically, in this embodiment, when the check register variable t_test_count completes a change in an RTC detection cycle, for example, when 86400 is added to the initial value (24h=86400s), the value is read again. In this embodiment, the RTC detection cycle is set to one day, and this value can be adjusted according to actual needs. The value in the RTC register is read again, that is, the second value t_real1, and the second value is stored in the second variable t_real_count1, that is, t_real_count1=t_real1.

[0059] Then, the relationship between the value of the first variable and the value of the second variable is compared. If t_real_count1=t_real_count0, it indicates that the RTC counter has not accumulated, and the RTC clock crystal oscillator is detected to be invalid. That is, the second type of fault is detected and the detected fault is reported.

[0060] Step S104, calculating a second error signal according to the second value and the changed check variable, and determining whether the frequency of the RTC crystal oscillator is abnormal by comparing the first error signal with the second error signal.

[0061] Specifically, the error signal is calculated again based on the re-read RTC value (i.e., the second value) and the check variable, and the calculation method is the same as the calculation method of the first error signal, and the variable storing the value can also be used for calculation. In one embodiment of the present application, the second error signal is calculated based on the second value and the changed check variable, including: adding the real-time value of the check variable when reading the value of the first variable to the RTC detection period to calculate the updated real-time value of the check variable; subtracting the updated real-time value of the check variable from the value of the second variable to obtain the second error signal.

[0062] Specifically, in this embodiment, the second error signal is calculated and stored in the error recording variable t_test_err1, where t_test_err1 = t_real_count1-t_test_count. The value in t_test_count in this step is related to the value of t_test_count when the first error signal is calculated in step S103, which is the value of t_test_count when the first error signal is calculated plus an RTC detection cycle. For example, if the value in t_test_count in step S103 is 100, the real-time value of the verification variable after update in this step is 86400+100, which means that the data is read again and the error is calculated after 24 hours.

[0063] Furthermore, by comparing the first error signal and the second error signal, it is determined whether the frequency of the RTC crystal oscillator is abnormal, and the specific abnormality type is determined.

[0064] In one embodiment of the present application, whether the frequency of the RTC crystal oscillator is abnormal is determined by comparing the first error signal and the second error signal, including: calculating the error value obtained by subtracting the second error signal from the first error signal; when the error value is greater than zero, determining that the frequency of the RTC crystal oscillator is slower than the normal frequency; when the error value is less than zero, determining that the frequency of the RTC crystal oscillator is faster than the normal frequency; when the error value is equal to zero, determining that the frequency of the RTC crystal oscillator is normal.

[0065] Specifically, in this embodiment, the magnitudes of t_test_err0 and t_test_err1 are compared to calculate the error value t_err, that is, t_err=t_test_err0-t_test_err1. The specific RTC crystal oscillator frequency abnormality type is then determined based on the relationship satisfied by t_err.

[0066] If t_err>0, it indicates that the RTC crystal frequency of the device is slower than the normal frequency; if t_err<0, it indicates that the RTC crystal frequency of the device is faster than the normal frequency; if t_err=0, it indicates that the RTC crystal frequency of the device is normal. Thus, the third type of fault can be detected, and the type of the detected RTC crystal frequency fault is reported as too fast or too slow.

[0067] Furthermore, the present application can also calibrate the problem clock according to the detected RTC fault type. In the above steps, when the third type of fault, i.e., the RTC crystal frequency abnormal fault detection report information, is received, the current RTC is determined to be the problem clock, and the correct RTC time in the current situation is determined in combination with the specific fault type (frequency is too fast or too slow) and RTC value and other detection data detected, and then the register value of the problem clock is calibrated according to the calculated correct RTC time.

[0068] For example, after determining whether the frequency of the RTC crystal oscillator is abnormal, it also includes: calculating the sum of the second numerical value and the error value, and using the sum as a calibration parameter; writing the calibration parameter into the timing register of the RTC through a time calibration function to automatically calibrate the RTC time.

[0069] Specifically, in this embodiment, after the RTC crystal oscillator frequency failure is detected, the time calibration function is called to write (t_real_count1+t_err) into the RTC time calibration register to automatically calibrate the time.

[0070] Therefore, based on the fault detection method in the above embodiment, in the actual application of RTC, by repeatedly executing the above steps S102 to S104, the RTC accuracy can be detected in real time, the common RTC problems detected can be determined, and the RTC can be calibrated in time when a fault is detected.

[0071] In summary, the fault detection method of the real-time clock RTC of the embodiment of the present application can monitor the RTC timestamp in real time through the relevant software algorithm to detect the accuracy of the device chip RTC without adding other external hardware devices and without relying on external communication, and can accurately detect various types of faults that may occur in the RTC. Therefore, on the one hand, the method reduces the cost of RTC detection, saves external communication steps, and reduces the complexity of detection. On the other hand, it can detect a variety of faults and specifically locate the type of fault currently occurring in the RTC, improve the accuracy and reliability of the detection results, and refine the detection results. In addition, the method can also realize the RTC automatic calibration function, report the fault after identifying the RTC fault, and calibrate the abnormal RTC clock signal at any time according to the RTC detection result. The calibration method is relatively simple, which is conducive to ensuring the normal and stable operation of the RTC function.

[0072] In order to implement the above embodiment, the present application also proposes a real-time clock RTC fault detection system. Figure 3 A structural diagram of a real-time clock RTC fault detection system proposed in an embodiment of the present application is shown in FIG. Figure 3As shown, the system includes: a setting module 100 , a first detection module 200 , a second detection module 300 and a third detection module 400 .

[0073] Among them, the setting module 100 is used to build an interrupt service through the internal timer of the main control chip equipped with a real-time clock RTC, set the initial time of the RTC register when the main control chip is first burned into the program, and start timing after calibrating the RTC according to the real time.

[0074] The first detection module 200 is used to read the first value of the RTC register after the main control chip is powered on again, determine whether the RTC has an external power supply failure based on the first value, the initial time and a preset empirical value, and construct a check variable that increases every second based on the interrupt service.

[0075] The second detection module 300 is used to calculate the first error signal based on the first value and the check variable, read the real-time second value in the RTC register after the check variable changes through an RTC detection cycle, and determine whether the RTC crystal oscillator fails based on the first value and the second value.

[0076] The third detection module 400 is used to calculate a second error signal according to the second value and the changed check variable, and determine whether the frequency of the RTC crystal oscillator is abnormal by comparing the first error signal with the second error signal.

[0077] Optionally, in one embodiment of the present application, the first detection module 200 is specifically used to: store the read first numerical value in a first variable, and calculate the difference between the first numerical value and the initial time; compare the difference with the empirical value, and when the difference is greater than zero and less than the empirical value, determine that the RTC has an external power supply failure.

[0078] Optionally, in one embodiment of the present application, the second detection module 300 is specifically used to: when reading the value of the first variable, simultaneously read the real-time value of the verification variable; subtract the real-time value of the verification variable from the value of the first variable to obtain a first error signal.

[0079] Optionally, in one embodiment of the present application, the second detection module 300 is specifically used to: store the read second value in the second variable, and compare the relationship between the value of the first variable and the value of the second variable, and determine that the RTC crystal oscillator fails when the value of the first variable is equal to the value of the second variable. The third detection module 400 is specifically used to: add the real-time value of the check variable when reading the value of the first variable to the RTC detection period, and calculate the real-time value of the check variable after the update; subtract the real-time value of the check variable after the update from the value of the second variable to obtain a second error signal.

[0080] Optionally, in one embodiment of the present application, the third detection module 400 is specifically used to: calculate the error value obtained by subtracting the second error signal from the first error signal; when the error value is greater than zero, determine that the frequency of the RTC crystal oscillator is slower than the normal frequency; when the error value is less than zero, determine that the frequency of the RTC crystal oscillator is faster than the normal frequency; when the error value is equal to zero, determine that the frequency of the RTC crystal oscillator is normal.

[0081] Optionally, in one embodiment of the present application, the third detection module 400 is also used to: calculate the sum of the second numerical value and the error value, and use the sum as a calibration parameter; write the calibration parameter into the RTC time register through a time calibration function to automatically calibrate the RTC time.

[0082] It should be noted that the above explanation of the embodiment of the fault detection method of the real-time clock RTC is also applicable to the system of this embodiment, and will not be repeated here.

[0083] In summary, the fault detection system of the real-time clock RTC of the embodiment of the present application can monitor the RTC timestamp in real time through relevant software algorithms to detect the accuracy of the device chip RTC without adding other external hardware devices and without relying on external communication, and can accurately detect various types of faults that may occur in the RTC. Therefore, on the one hand, the system reduces the cost of RTC detection, saves external communication steps, and reduces the complexity of detection. On the other hand, it can detect a variety of faults and specifically locate the type of fault currently occurring in the RTC, improve the accuracy and reliability of the detection results, and refine the detection results. In addition, the system can also realize the RTC automatic calibration function, report the fault after identifying the RTC fault, and calibrate the abnormal RTC clock signal at any time according to the RTC detection result. The calibration method is relatively simple, which is conducive to ensuring the normal and stable operation of the RTC function.

[0084] In order to implement the above embodiments, the present application also proposes a non-temporary computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, a fault detection method for a real-time clock RTC as described in any one of the above first aspect embodiments is implemented.

[0085] In the description of this specification, the description with reference to the terms "one embodiment", "some embodiments", "example", "specific example", or "some examples" etc. means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present application. In this specification, the schematic representations of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner. In addition, those skilled in the art may combine and combine the different embodiments or examples described in this specification and the features of the different embodiments or examples, without contradiction.

[0086] In addition, the terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Therefore, the features defined as "first" and "second" may explicitly or implicitly include at least one of the features. In the description of this application, the meaning of "plurality" is at least two, such as two, three, etc., unless otherwise clearly and specifically defined.

[0087] Any process or method description in a flowchart or otherwise described herein may be understood to represent a module, fragment or portion of code comprising one or more executable instructions for implementing the steps of a custom logical function or process, and the scope of the preferred embodiments of the present application includes alternative implementations in which functions may not be performed in the order shown or discussed, including performing functions in a substantially simultaneous manner or in the reverse order depending on the functions involved, which should be understood by technicians in the technical field to which the embodiments of the present application belong.

[0088] The logic and / or steps represented in the flowchart or otherwise described herein, for example, can be considered as an ordered list of executable instructions for implementing logical functions, and can be embodied in any computer-readable medium for use by an instruction execution system, device or apparatus (such as a computer-based system, a system including a processor, or other system that can fetch instructions from an instruction execution system, device or apparatus and execute the instructions), or in combination with these instruction execution systems, devices or apparatuses. For the purpose of this specification, "computer-readable medium" can be any device that can contain, store, communicate, propagate or transmit a program for use by an instruction execution system, device or apparatus, or in combination with these instruction execution systems, devices or apparatuses. More specific examples of computer-readable media (a non-exhaustive list) include the following: an electrical connection with one or more wires (electronic device), a portable computer disk box (magnetic device), a random access memory (RAM), a read-only memory (ROM), an erasable and programmable read-only memory (EPROM or flash memory), a fiber optic device, and a portable compact disk read-only memory (CDROM). In addition, the computer-readable medium may even be paper or other suitable medium on which the program is printed, since the program may be obtained electronically, for example, by optically scanning the paper or other medium and then editing, interpreting or processing in other suitable ways if necessary, and then stored in a computer memory.

[0089] It should be understood that the various parts of the present application can be implemented by hardware, software, firmware or a combination thereof. In the above-mentioned embodiments, multiple steps or methods can be implemented by software or firmware stored in a memory and executed by a suitable instruction execution system. For example, if implemented by hardware, as in another embodiment, it can be implemented by any one of the following technologies known in the art or their combination: a discrete logic circuit having a logic gate circuit for implementing a logic function for a data signal, a dedicated integrated circuit having a suitable combination of logic gate circuits, a programmable gate array (PGA), a field programmable gate array (FPGA), etc.

[0090] A person skilled in the art may understand that all or part of the steps in the method for implementing the above-mentioned embodiment may be completed by instructing related hardware through a program, and the program may be stored in a computer-readable storage medium, which, when executed, includes one or a combination of the steps of the method embodiment.

[0091] In addition, each functional unit in each embodiment of the present application may be integrated into a processing module, or each unit may exist physically separately, or two or more units may be integrated into one module. The above-mentioned integrated module may be implemented in the form of hardware or in the form of a software functional module. If the integrated module is implemented in the form of a software functional module and sold or used as an independent product, it may also be stored in a computer-readable storage medium.

[0092] The storage medium mentioned above may be a read-only memory, a magnetic disk or an optical disk, etc. Although the embodiments of the present application have been shown and described above, it can be understood that the above embodiments are exemplary and cannot be understood as limiting the present application. A person of ordinary skill in the art may change, modify, replace and modify the above embodiments within the scope of the present application.

Claims

1. A method for detecting a fault of a real-time clock RTC, characterized in that: The following steps are involved: An interrupt service is established by using an internal timer of a main control chip equipped with a real-time clock RTC, an initial time of an RTC register is set when the main control chip is first programmed, and timing is started after the RTC is calibrated according to the real time; After the main control chip is powered on again, a first value of the RTC register is read, and according to the first value, the initial time and a preset empirical value, whether an external power supply failure occurs to the RTC, and a check variable that increases every second is constructed based on the interrupt service; Calculate a first error signal according to the first value and the check variable, read a real-time second value in the RTC register after the check variable changes through an RTC detection cycle, and determine whether an RTC crystal oscillator failure occurs according to the first value and the second value; A second error signal is calculated according to the second value and the changed check variable, and whether the frequency of the RTC crystal oscillator is abnormal is determined by comparing the first error signal with the second error signal.

2. The detection method according to claim 1, characterized in that: The determining, based on the first value, the initial time and a preset empirical value, whether an external power supply failure occurs in the RTC includes: storing the read first value in a first variable, and calculating the difference between the first value and the initial time; The difference is compared with the empirical value, and when the difference is greater than zero and less than the empirical value, it is determined that an external power supply failure occurs in the RTC.

3. The detection method according to claim 2, characterized in that: The calculating a first error signal according to the first value and the check variable comprises: When reading the value of the first variable, simultaneously reading the real-time value of the verification variable; The first error signal is obtained by subtracting the real-time value of the verification variable from the value of the first variable.

4. The detection method according to claim 2, characterized in that: The determining whether an RTC crystal oscillator failure occurs according to the first value and the second value includes: The read second value is stored in a second variable, and the relationship between the value of the first variable and the value of the second variable is compared, and when the value of the first variable is equal to the value of the second variable, it is determined that the RTC crystal oscillator is invalid; The calculating the second error signal according to the second value and the changed check variable comprises: adding the real-time value of the check variable when reading the value of the first variable to the RTC detection period to calculate the updated real-time value of the check variable; The second error signal is obtained by subtracting the updated real-time value of the verification variable from the value of the second variable.

5. The detection method according to claim 1, characterized in that: The determining whether the frequency of the RTC crystal oscillator is abnormal by comparing the first error signal and the second error signal includes: Calculating an error value obtained by subtracting the second error signal from the first error signal; When the error value is greater than zero, it is determined that the frequency of the RTC crystal oscillator is slower than the normal frequency; When the error value is less than zero, determining that the frequency of the RTC crystal oscillator is faster than a normal frequency; When the error value is equal to zero, it is determined that the frequency of the RTC crystal oscillator is normal.

6. The detection method according to claim 5, characterized in that: After determining whether the frequency of the RTC crystal oscillator is abnormal, the method further includes: Calculating a sum of the second numerical value and the error value, and using the sum as a calibration parameter; The calibration parameters are written into the time calibration register of the RTC through a time calibration function to automatically calibrate the RTC time.

7. A real-time clock (RTC) fault detection system, characterized in that: include: A setting module is used to construct an interrupt service through the internal timer of a main control chip equipped with a real-time clock RTC, set the initial time of the RTC register when the main control chip is first programmed, and start timing after calibrating the RTC according to the real time; A first detection module is used to read the first value of the RTC register after the main control chip is powered on again, determine whether the RTC has an external power supply failure according to the first value, the initial time and a preset empirical value, and construct a check variable that increases every second based on the interrupt service; A second detection module is used to calculate a first error signal according to the first value and the check variable, read a real-time second value in the RTC register after the check variable changes through an RTC detection cycle, and determine whether an RTC crystal oscillator failure occurs according to the first value and the second value; The third detection module is used to calculate a second error signal according to the second value and the changed check variable, and determine whether the frequency of the RTC crystal oscillator is abnormal by comparing the first error signal with the second error signal.

8. The detection system according to claim 7, characterized in that: The first detection module is specifically used for: storing the read first value in a first variable, and calculating the difference between the first value and the initial time; The difference is compared with the empirical value, and when the difference is greater than zero and less than the empirical value, it is determined that an external power supply failure occurs in the RTC.

9. The detection system according to claim 8, characterized in that: The second detection module is specifically used for: When reading the value of the first variable, simultaneously reading the real-time value of the verification variable; The first error signal is obtained by subtracting the real-time value of the verification variable from the value of the first variable.

10. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the fault detection method of the real-time clock RTC according to any one of claims 1 to 6 is implemented.