Device supporting off-line high-precision timing and implementation method thereof
By designing backup power supply and temperature sensing modules in the RTC module and calculating the clock compensation value using the controller, the problem that the RTC module is difficult to maintain high-precision timing during power failure or low power consumption is solved, and high-precision and low power consumption are achieved Take into account both.
Patent Information
- Application Number
- CN202411115242.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-14
- Publication Date
- 2024-12-27
AI Technical Summary
The prior art cannot obtain external standard clock source data when the RTC module is powered off or extremely low power consumption is run, and it is difficult to meet the high-precision time-travel requirements.
A device that supports offline high-precision timing is designed, including an RTC module, a backup power supply and a temperature sensing module. It generates an internal clock signal through built-in crystal oscillation, and uses a controller to calculate the clock compensation value based on external clock source and temperature sensing data. , save and send to the RTC module for correction, ensuring that high-precision timing can be maintained without external power supply.
The RTC module is realized with high-precision timing when external power supply is powered down or extremely low power consumption, reducing power consumption, reducing device volume, and implementing power management through simple one-way diodes to ensure timing accuracy and battery life.
Smart Images

Figure CN119200748A_ABST
Abstract
Description
Technical Field
[0001] The present invention mainly relates to the field of electric power, and in particular to a device supporting off-line high-precision timing and an implementation method thereof. Background Art
[0002] RTC (Real-Time Clock) is a common functional unit in power field equipment, used to support device data history curves, timestamp support for SOE functions, etc. RTC clock can be regarded as an independent timer, which generates an accurate clock signal through a crystal oscillator and tracks time through a counter.
[0003] In current technology, in order to maintain high RTC accuracy, in most cases, methods such as periodic time calibration through an external standard clock source are adopted to achieve this, where the external standard clock source can be a GPS clock, NTP server or other high-precision time server.
[0004] Due to various restrictions, some sites do not have an external standard clock source. Even if there is an external clock source, some sites require that the RTC module must operate normally at extremely low power consumption when the device is powered off, and maintain high timekeeping accuracy for a certain period of time (48 hours or even 7 days). As a result, it is difficult for traditional methods to meet high-precision timekeeping requirements because the external standard clock source data cannot be obtained when the power is off or the RTC module is running at extremely low power consumption. Summary of the invention
[0005] In order to overcome the problems existing in the prior art, the present invention provides a device and method supporting offline high-precision timing, so as to better realize high-precision timing when the external clock source is powered off or the RTC module cannot obtain the external clock source data when running at extremely low power consumption, and the application is simple and the operability is strong.
[0006] The present invention relies on the following measures to achieve the purpose:
[0007] According to a first aspect of the present invention, a device for supporting offline high-precision timing is provided. The device comprises:
[0008] RTC module, used to generate internal clock signal through the oscillation of built-in crystal;
[0009] A backup power supply, used to store power when an external power supply is provided, and to supply power to the RTC module when no external power supply is provided;
[0010] A temperature sensing module, used for collecting temperature sensing data;
[0011] A controller, configured to generate a clock compensation value at a set time interval based on an external clock signal of an external clock source, the internal clock signal and the temperature sensing data, and send the value to the RTC module;
[0012] Among them, when there is external power supply, the RTC module saves and updates the clock compensation value, and corrects the internal clock signal according to the clock compensation value; when there is no external power supply, the RTC module corrects the internal clock signal according to the latest saved clock compensation value.
[0013] Furthermore, the backup power supply includes a diode and a capacitor; the anode of the diode is connected to the external power supply, and the cathode of the diode is connected to the capacitor and the RTC module respectively.
[0014] Furthermore, the RTC module is an RTC module that supports IIC communication, clock compensation mechanism and second interrupt output.
[0015] Furthermore, the controller includes a flash memory for storing the clock compensation value.
[0016] Furthermore, the controller also includes a communication interface; the controller is also used to obtain and save the crystal oscillator frequency temperature coefficient of the RTC module via the communication interface.
[0017] Furthermore, the controller is an MCU; and the communication interface is a ModbusRTU communication interface.
[0018] According to a second aspect of the present invention, there is provided a method for implementing the device for supporting offline high-precision timing as described in the first aspect of the present invention. The method comprises:
[0019] (1) In a room temperature constant temperature environment, the controller calibrates the internal time signal according to the external clock signal, determines and saves a room temperature compensation value, and sends the room temperature compensation value to the RTC module;
[0020] (2) When the calibration is completed and the external power supply is supplied: the controller scrolls and reads the temperature sensing data collected by the temperature sensing module, and calculates the average temperature value within 24 hours in real time; the controller determines and saves the clock compensation value according to the saved normal temperature clock compensation value and the average temperature value at a preset time interval, and sends the clock compensation value to the RTC module; the RTC module receives and saves the clock compensation value, and corrects the internal clock signal according to the clock compensation value;
[0021] (3) When the calibration is completed and there is no external power supply: the RTC module is powered by the backup power supply and the internal clock signal is corrected according to the latest saved clock compensation value.
[0022] Furthermore, step (1) specifically includes:
[0023] In a constant temperature environment of 25°C, the RTC module and the external clock source send quasi-second pulses to the controller respectively; the controller processes the quasi-second pulses in an interrupt manner, writes the accurate time into the RTC module at the quasi-second moment of the external clock source and starts timing, and stops timing at the quasi-second moment of the external clock source closest to one minute after the start of timing, calculates the time difference between the external clock source and the RTC module, removes the fixed controller interrupt response time and the calculation time deviation from the time difference, and obtains the corrected time difference; the controller determines and saves the room temperature compensation value according to the corrected time difference and the crystal oscillator period of the RTC module through the following formula, and sends it to the RTC module:
[0024] m=A / H
[0025] Wherein, m is the room temperature compensation value, A is the corrected time difference, and H is the crystal oscillator period of the RTC module.
[0026] Furthermore, in step (2), the controller scrolls and reads the temperature sensing data collected by the temperature sensing module, and calculates the average temperature value within 24 hours, which specifically includes:
[0027] The controller is set to read the temperature sensing value collected by the temperature sensing module once every half hour and fill it into a 48-bit first-in-first-out array, and calculate the average temperature value within 24 hours based on the temperature sensing value stored in the array.
[0028] Furthermore, in step (2), the controller determines the clock compensation value according to the following formula:
[0029] n=-(X-25)2×T f ×f×60+m
[0030] Among them, n is rounded to an integer to get the clock compensation value within 1 minute, X is the average temperature value within 24 hours, T f is the crystal frequency temperature coefficient, f is the crystal frequency, and m is the room temperature compensation value.
[0031] Compared with the prior art, the present invention has the following beneficial effects:
[0032] 1. By setting a backup power supply for the RTC module, a controller is set to determine and save the clock compensation value according to the internal and external clock signals and temperature sensing data, and send it to the RTC module for storage, so that the RTC module can be powered by the backup power supply even when the external power supply is off or the power consumption is extremely low, and the internal clock signal can be compensated with high precision according to the saved clock compensation value.
[0033] 2. By setting the backup power supply to include a diode and a capacitor, and connecting the positive pole of the diode to the external power supply, and the negative pole of the diode to the capacitor and the RTC module respectively, there is no need to detect when the external power supply is powered on and when it is powered off. A simple unidirectional diode can be used to automatically charge the capacitor when the external power supply is powered on, and when the external power supply is powered off, the capacitor automatically only supplies power to the RTC module. In this way, power consumption can be greatly reduced (for example, the supply current of the RTC module can be as low as only about 500nA), and a 1 Farad button supercapacitor can keep the RTC module working for more than a week. At the same time, the volume of the backup power supply can be greatly reduced, thereby reducing the volume of the entire device.
[0034] 3. Perform room temperature calibration through the controller to determine the room temperature compensation value, store the value in the controller and send it to the RTC module for clock compensation, so that the user does not need to pay attention to the size of the clock compensation value. At the same time, there is no need to set up an additional clock compensation calculation module in the RTC module, which further reduces the power consumption of the RTC module when the external power supply is off, ensuring the normal operation of the RTC module when the power is off.
[0035] 4. By reading the temperature sensing value collected by the temperature sensing module every half hour and filling it into a 48-bit first-in-first-out array, the latest data can be automatically filled in and the oldest data can be discarded when the array is full, so as to realize the real-time update of the temperature sensing value within 24 hours, and then obtain a more accurate real-time average temperature value within 24 hours, so as to minimize the impact of the day and night temperature difference on the clock accuracy. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] Figure 1 It is a schematic diagram of the structure of the device supporting off-line high-precision timing in the present invention.
[0037] Figure 2 It is a flow chart of the method for supporting offline high-precision timing in the present invention. DETAILED DESCRIPTION
[0038] In order to make the purpose, technical scheme and advantages of the present invention clearer, the technical scheme of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. The embodiments described in this application are only part of the embodiments of the present invention, not all of them. Based on the spirit of the present invention, other embodiments obtained by ordinary technicians in this field without creative work are all within the scope of protection of the present invention.
[0039] The present invention will be described clearly and completely below. Obviously, the hardware structure and method of the device of the present invention are a complete functional unit, but it is not required to be completely independent of other functional modules in terms of function. Based on the embodiments of the present invention, all other embodiments of the functions of the device embedded in the present invention obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0040] Example 1
[0041] In this embodiment, a device supporting offline high-precision timing is provided, which can be used, for example, in a terminal device that needs to maintain high offline timing accuracy or power-off timing accuracy.
[0042] like Figure 1 , the RTC device supporting offline high-precision timing includes: an RTC module for generating an internal clock signal through oscillation of a built-in crystal;
[0043] A backup power supply, used to store power when an external power supply is provided, and to supply power to the RTC module when no external power supply is provided;
[0044] A temperature sensing module, used for temperature sensing data;
[0045] A controller, configured to generate a clock compensation value at a set time interval based on an external clock signal of an external clock source, the internal clock signal and the temperature sensing data, and send the value to the RTC module;
[0046] Among them, when there is external power supply, the RTC module saves and updates the clock compensation value, and corrects the internal clock signal according to the clock compensation value; when there is no external power supply, the RTC module corrects the internal clock signal according to the latest saved clock compensation value.
[0047] It can be seen that in this embodiment, by setting a backup power supply for the RTC module, a controller is set to determine and save the clock compensation value based on the internal and external clock signals and temperature sensing data, and send it to the RTC module for storage, so that the RTC module can obtain a real-time clock compensation value that takes into account the internal and external clock deviations and temperature factors when powered by an external power supply; even when the external power supply is powered off or the power consumption is extremely low, it can be powered by the backup power supply and perform high-precision compensation for the internal clock signal based on the saved clock compensation value.
[0048] In a more preferred embodiment, the backup power supply includes a diode and a capacitor; the positive electrode of the diode is connected to the external power supply, and the negative electrode of the diode is connected to the capacitor and the RTC module, respectively. Specifically, the capacitor can be a supercapacitor, such as a 1 Farad button supercapacitor.
[0049] The design of the backup power supply does not need to detect when the external power supply is on and when it is off. A simple unidirectional diode can be used to automatically charge the capacitor when the external power supply is on. When the external power supply is off, the capacitor automatically only supplies power to the RTC module. In this way, power consumption can be greatly reduced (for example, the supply current of the RTC module can be as low as only about 500nA). A 1 Farad button supercapacitor can keep the RTC module working for more than one week. At the same time, the size of the backup power supply can be greatly reduced, thereby reducing the size of the entire device.
[0050] In this embodiment, the RTC module is an RTC module that supports IIC communication, clock compensation mechanism, and second interrupt output. Supporting the clock compensation mechanism means that the RTC module supports writing clock compensation values, and can, for example, compensate in units of minutes, such as increasing or decreasing the set number of timing pulses at certain fixed moments within one minute, thereby realizing the correction of the internal clock signal of the RTC module.
[0051] In this embodiment, the controller may be an MCU. The MCU may include a flash memory for storing the clock compensation value. In addition, the controller has an external clock source interface to obtain an external clock signal from an external clock source. The external clock source interface may be, for example, a UART (Universal Asynchronous Receiver and Transmitter) interface.
[0052] In a more preferred embodiment, the controller further comprises a communication interface. The controller is also used to obtain and save the crystal oscillator frequency temperature coefficient of the RTC module via the communication interface. Preferably, the communication interface is a ModbusRTU communication interface.
[0053] In a more preferred embodiment, the temperature sensing module uses a temperature sensor chip that supports IIC communication.
[0054] Example 2
[0055] This embodiment provides an implementation method of the device supporting offline high-precision timing according to the present invention. Figure 2 , the method comprising:
[0056] Step 1: Under a constant temperature environment at room temperature, the controller calibrates the internal time signal according to the external clock signal, determines and saves a room temperature compensation value, and sends the room temperature compensation value to the RTC module.
[0057] As a specific example, this step includes: before formal use after leaving the factory, room temperature calibration is performed in a constant temperature environment of 25°C, that is, compensation calculation is performed in minutes, and the controller calculates the travel time deviation between the internal clock signal of the RTC module and the external clock signal provided by the external clock source within one minute, and then converts the deviation into a room temperature compensation value and writes it to the RTC module, and saves it to the flash memory inside the controller. Both the external clock source and the RTC module have quasi-second pulses sent to the controller, and the controller processes the quasi-second pulses in an interrupt manner. The controller writes the accurate time provided by the external clock source to the RTC module at the first quasi-second moment of the external clock source and starts timing. One minute later, the controller again calculates the time difference with the RTC quasi-second moment at the second quasi-second moment of the external clock source. This time difference is the basis for the room temperature compensation value sent to the RTC module. Specifically, when calculating the room temperature compensation value, the controller will remove the fixed controller interrupt response time and calculation time from the time difference to obtain the corrected time difference, and then determine and save the room temperature compensation value according to the corrected time difference and the crystal oscillator period of the RTC module through the following formula, and send it to the RTC module:
[0058] m=A / H
[0059] Wherein, m is the room temperature compensation value, A is the corrected time difference between the external clock source and the RTC module within one minute, and H is the crystal oscillator period of the RTC module.
[0060] Step 2, when the calibration is completed and the external power supply is provided: the controller scrolls and reads the temperature sensing data collected by the temperature sensing module, and calculates the average temperature value within 24 hours in real time; the controller determines and saves the clock compensation value according to the preset time interval based on the saved normal temperature clock compensation value and the average temperature value, and sends the clock compensation value to the RTC module; the RTC module receives and saves the clock compensation value, and corrects the internal clock signal according to the clock compensation value.
[0061] In this step, the temperature sensing data collected by the temperature sensing module is scrolled and read by the controller, and the average temperature value within 24 hours is calculated, which specifically includes: setting the controller to read the temperature sensing value of the temperature sensing module once every half an hour, and filling the temperature sensing value into a 48-bit first-in-first-out array, and calculating the average temperature value within 24 hours based on the temperature sensing value stored in the array. More specifically, when the first-in-first-out array is not full, the MCU calculates the average value with the existing data. For example, if the device has just been powered on and worked for 5 hours, and there are only 10 temperature samples, the MCU will calculate the average value of the 10 samples. When the first-in-first-out array is full of 48 bits, the latest data is filled in, and the oldest data will be discarded.
[0062] The purpose of calculating the average temperature value is to keep the device at a very low power consumption when the external device is powered off. When the external device is powered off, only the RTC module keeps working, and the controller no longer collects temperature information and calculates the compensation correction value. If the clock compensation value saved by the RTC module is based on the temperature value at a certain moment, the compensation correction value based on a certain moment will not achieve the expected effect due to temperature changes within a day. The compensation correction value based on the average algorithm will maintain a relatively high timekeeping accuracy when the device is powered off.
[0063] Furthermore, in this step, the controller determines the clock compensation value according to the following formula:
[0064] n=-(X-25)2×T f ×f×60+m
[0065] Among them, n is rounded to an integer to get the clock compensation value within 1 minute, X is the average temperature value within 24 hours, T f is the crystal frequency temperature coefficient, f is the crystal frequency, and m is the room temperature compensation value. Both the crystal frequency and the crystal frequency temperature coefficient can be obtained by the controller through the communication interface and written into the internal flash memory of the controller.
[0066] As a specific example, assuming that the crystal frequency is 32.768kHz, the frequency temperature coefficient is -0.01ppm / ℃2, the average temperature value of a 24-hour period is X, and the room temperature standard is 25℃, the above clock compensation value calculation formula yields n as -(X-25)2×0.01×10 -6 ×(32.768×10 3 )×60+m, where m is the room temperature compensation value. A negative value indicates a decrease in frequency and an increase in period. The clock compensation value n is rounded off to the nearest integer. The clock compensation value n also represents the number of pulses that need to be compensated within 1 minute. If n is a negative number, it means that the corresponding number of pulses is reduced within 1 minute.
[0067] After each acquisition of a new temperature sensing value and calculation of the average temperature value, the controller writes the clock compensation value into the RTC module.
[0068] Step 3: When the calibration is completed and there is no external power supply: the RTC module is powered by the backup power supply, and the internal clock signal is corrected according to the latest saved clock compensation value.
[0069] Specifically, when the device encounters an abnormal power outage, the RTC module will continue to work under the backup power supply according to the latest saved clock compensation value (for example, the clock compensation value updated in the last half hour), thereby ensuring the offline timing accuracy of the device.
[0070] When the device is powered on again, it returns to step (2), that is, the controller reads the room temperature compensation value and the crystal frequency temperature coefficient stored in the flash memory, and then calculates the clock compensation value based on the average temperature value read in real time. At the same time, the external power supply will charge the backup power supply.
[0071] It should be noted that the device supporting offline high-precision timing of the present invention is a complete functional unit itself, but in specific implementation, the functional unit can be integrated with other functional modules. For example, the controller in the device of the present invention can simultaneously realize the collection of digital quantity data and send it to other functional modules or units for processing through the ModbusRTU communication interface. Since the controller maintains accurate time inside, if the controller adds a timestamp to the transition moment of each digital quantity signal, the SOE (event sequence record) function is realized.
[0072] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention rather than to limit it. Although the present invention has been described in detail with reference to the above embodiments, ordinary technicians in the relevant field should understand that the specific implementation methods of the present invention can still be modified or replaced by equivalents, and any modifications or equivalent replacements that do not depart from the spirit and scope of the present invention should be covered within the scope of protection of the claims of the present invention.
Claims
1. A device supporting offline high-precision timing, characterized in that: include: RTC module, used to generate internal clock signal through the oscillation of built-in crystal; A backup power supply, used to store power when an external power supply is provided, and to supply power to the RTC module when no external power supply is provided; A temperature sensing module, used for temperature sensing data; A controller, configured to generate a clock compensation value at a set time interval based on an external clock signal of an external clock source, the internal clock signal and the temperature sensing data, and send the value to the RTC module; Among them, when there is external power supply, the RTC module saves and updates the clock compensation value, and corrects the internal clock signal according to the clock compensation value; when there is no external power supply, the RTC module corrects the internal clock signal according to the latest saved clock compensation value.
2. The device for supporting offline high-precision timing according to claim 1, characterized in that: The backup power supply includes a diode and a capacitor; the anode of the diode is connected to the external power supply, and the cathode of the diode is connected to the capacitor and the RTC module respectively.
3. The device for supporting offline high-precision timing according to claim 1, characterized in that: The RTC module is an RTC module that supports IIC communication, clock compensation mechanism and second interrupt output.
4. The device for supporting offline high-precision timing according to claim 1, characterized in that: The controller includes a flash memory for storing the clock compensation value.
5. The device for supporting offline high-precision timing according to claim 1, characterized in that: The controller also includes a communication interface; the controller is also used to obtain and save the crystal oscillator frequency temperature coefficient of the RTC module via the communication interface.
6. The device for supporting offline high-precision timing according to claim 5, characterized in that: The controller is an MCU; the communication interface is a ModbusRTU communication interface.
7. A method for implementing the device supporting offline high-precision timing as claimed in any one of claims 1 to 6, characterized in that: The steps include: (1) In a room temperature constant temperature environment, the controller calibrates the internal time signal according to the external clock signal, determines and saves a room temperature compensation value, and sends the room temperature compensation value to the RTC module; (2) When the calibration is completed and the external power supply is on: the controller scrolls and reads the temperature sensing data collected by the temperature sensing module, and calculates the average temperature value within 24 hours in real time; The controller determines and saves a clock compensation value based on the saved normal temperature clock compensation value and the average temperature value at a preset time interval, and sends the clock compensation value to the RTC module; The RTC module receives and stores the clock compensation value, and corrects the internal clock signal according to the clock compensation value; (3) When the calibration is completed and there is no external power supply: the RTC module is powered by the backup power supply and the internal clock signal is corrected according to the latest saved clock compensation value.
8. The method for supporting offline high-precision timing according to claim 7, characterized in that: Step (1) specifically includes: In a constant temperature environment of 25°C, the RTC module and the external clock source send quasi-second pulses to the controller respectively; the controller processes the quasi-second pulses in an interrupt manner, and writes the accurate time provided by the external clock source into the RTC module at the first quasi-second moment of the external clock source and starts timing. One minute later, the controller calculates the time difference between the external clock source and the RTC module at the second quasi-second moment of the external clock source, removes the fixed controller interrupt response time and the calculation time deviation from the time difference, and obtains the corrected time difference; the controller determines and saves the room temperature compensation value according to the corrected time difference and the crystal oscillator period of the RTC module through the following formula, and sends it to the RTC module: m=A / H Wherein, m is the room temperature compensation value, A is the corrected time difference between the external clock source and the RTC module within one minute, and H is the crystal oscillator period of the RTC module.
9. The method for supporting offline high-precision timing according to claim 7, characterized in that: In step (2), the controller scrolls and reads the temperature sensing data collected by the temperature sensing module, and calculates the average temperature value within 24 hours, which specifically includes: The controller is set to read the temperature sensing value collected by the temperature sensing module once every half hour and fill it into a 48-bit first-in-first-out array, and calculate the average temperature value within 24 hours based on the temperature sensing value stored in the array.
10. The method for supporting offline high-precision timing according to claim 7, characterized in that: In step (2), the controller determines the clock compensation value according to the following formula: n=-(X-25)2×T f ×f×60+m Among them, n is rounded to an integer to get the clock compensation value within 1 minute, X is the average temperature value within 24 hours, T f is the crystal frequency temperature coefficient, f is the crystal frequency, and m is the room temperature compensation value.