Clock synchronization method, device and equipment for electric energy meter based on RTC hardware backup

By constructing a clock synchronization method for electricity meters based on RTC hardware backup, the problems of single-point failure risk and weak fault recovery capability of electricity meter clock systems are solved, achieving highly reliable and highly available time synchronization, and ensuring the accuracy of power grid billing and monitoring.

CN122247544APending Publication Date: 2026-06-19EAST CHINA BRANCH OF STATE GRID CORP +1

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
EAST CHINA BRANCH OF STATE GRID CORP
Filing Date
2026-03-25
Publication Date
2026-06-19

AI Technical Summary

Technical Problem

Existing electricity meter clock systems suffer from high single-point failure risk, weak fault recovery capability, and poor clock calibration accuracy.

Method used

A clock synchronization method for electricity meters based on RTC hardware backup is adopted, including clock calibration after power failure, remote clock calibration, and clock calibration during operation. By reading data from multiple clock sources for legality verification and cross-arbitration, the target reliable time is determined and time synchronization is updated.

Benefits of technology

It improves the reliability and availability of the electricity meter clock system, ensuring accurate timing even when a single clock source fails, reducing the risk of clock drift, and enhancing the accuracy of grid operation analysis and billing fairness.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122247544A_ABST
    Figure CN122247544A_ABST
Patent Text Reader

Abstract

This application discloses a method, apparatus, and device for synchronizing the clock of an energy meter based on RTC hardware backup, relating to the field of smart energy meter calibration technology. The method includes a power-on clock calibration sub-method, a remote clock calibration sub-method, and a clock calibration sub-method during operation. The power-on clock calibration sub-method includes: reading clock source data after power-on, including internal hard clock data, external hard clock data, and power-off clock data; verifying the internal hard clock data, external hard clock data, and power-off clock data to obtain verification results; arbitrating the internal hard clock data, external hard clock data, and power-off clock data based on the verification results and preset cross-arbitration rules to obtain a target reliable time; and updating the software clock, internal hard clock, and external hard clock of the energy meter based on the target reliable time. The method of this application can improve the accuracy of energy meter clock system calibration.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of electricity meter clock calibration technology, and in particular to an electricity meter clock synchronization method, apparatus and equipment based on RTC hardware backup. Background Technology

[0002] In smart grid systems, the accuracy and reliability of electricity meters, especially gateway meters used for trade settlement and grid monitoring, are crucial. Accurate timestamps are fundamental for electricity metering, rate switching, event logging, and data synchronization, directly impacting billing fairness and the accuracy of grid operation analysis. Traditional electricity meters typically rely on a temperature-compensated hardware real-time clock integrated within the microcontroller unit as the sole high-precision time source. This hardware clock provides a stable physical time reference for the system, upon which the system software maintains a software clock as the runtime base for various functions.

[0003] However, this highly integrated solution inherently carries a single point of failure risk. As a complex system-on-a-chip, the MCU's hardware RTC module may malfunction or output abnormal data due to electromagnetic interference, power fluctuations, silicon defects, or long-term aging. Once the internal hardware clock fails, the system typically relies solely on a software-maintained clock for timing. Since the software clock depends entirely on the MCU's counters and interrupts, its accuracy is susceptible to software load, interrupt latency, and even program crashes. After the hardware clock fails, it cannot guarantee timing accuracy for an extended period, potentially leading to severe clock drift and rendering the system unusable.

[0004] Therefore, how to build a highly reliable and available electricity meter clock system that can maintain accurate timing or recover quickly when a single clock source fails has become a key technical issue for improving the performance and reliability of high-end electricity meters. Summary of the Invention

[0005] In view of this, the present invention provides a method, apparatus and equipment for synchronizing the clock of an energy meter based on RTC hardware backup, the main purpose of which is to solve the problems of high risk of single point of failure, weak fault recovery capability and poor clock calibration accuracy.

[0006] To address the aforementioned problems, this application provides a method for synchronizing the clock of an energy meter based on RTC hardware backup, comprising: a power-down clock calibration sub-method, a remote clock calibration sub-method, and a clock calibration sub-method during operation, wherein the power-down clock calibration sub-method includes: Read the clock source data after power-on, including internal hard clock data, external hard clock data, and power-off clock data; The validity of the internal hard clock data, external hard clock data, and power-down clock data is verified to obtain the verification results. Based on the verification results and the preset cross-arbitration rules, the internal hard clock data, the external hard clock data, and the power-down clock data are compared and arbitrated to obtain the target reliable time. Based on the target reliable time, the software clock, internal hard clock, and external hard clock of the energy meter are updated for time synchronization.

[0007] Optionally, the step of comparing and arbitrating the internal hard clock data, the external hard clock data, and the power-down clock data based on the verification result and preset cross-arbitration rules to obtain the target reliable time specifically includes: When the verification result indicates that the internal hard clock data is valid and the difference between the internal hard clock data and the power-down clock data is less than a preset threshold, the internal hard clock data is determined as the target reliable time. When the verification result is that the internal hard clock data is invalid, the external hard clock data is valid, and the difference between the external hard clock data and the power-down clock data is less than a preset threshold, the external hard clock data is determined as the target reliable time. When the verification result is that the internal hard clock data is invalid, the external hard clock data is invalid, and the power-down clock data is valid, the power-down clock data is determined as the target reliable time. When the verification result indicates that the internal hard clock data is invalid, the external hard clock data is invalid, and the power-down clock data is invalid, a system time anomaly alarm is triggered.

[0008] Optionally, the step of synchronizing and updating the software clock, internal hard clock, and external hard clock of the energy meter based on the target reliable time specifically includes: Update the power-down clock data based on the target reliable time; The software clock data of the energy meter is updated based on the updated power-down clock data; The updated power-off clock data is written to both the internal hard clock and the external hard clock of the energy meter to synchronize the internal hard clock data and the external hard clock data, respectively.

[0009] Optionally, the remote clock calibration sub-method includes: In response to receiving a valid time synchronization command sent by the target communication interface, the software clock data of the energy meter is updated based on the target verification time carried in the valid time synchronization command; The updated software clock data is written to the internal hard clock and the external hard clock to obtain the writing result; When the updated software clock data is successfully written to the internal hard clock, the remote clock calibration operation is considered successful.

[0010] Optionally, the method further includes: When writing the updated software clock data to the internal hard clock is successful but writing the updated software clock data to the external hard clock fails, the remote clock calibration operation is determined to be successful and the failure to write the external clock is logged. When writing the updated software clock data to the internal hard clock fails and writing the updated software clock data to the external hard clock succeeds / fails, the remote clock calibration operation is determined to have failed, the time calibration exception flag is set, and the error is logged.

[0011] Optionally, the clock calibration sub-method during operation includes: Read the internal hard clock data of the energy meter; If the internal hard clock data is successfully read and the internal hard clock data is valid, the software clock data of the energy meter is updated based on the internal hard clock data, and the clock hardware fault flag is reset. If the read fails or the internal hard clock data is invalid, read the external hard clock data of the energy meter; If the external hard clock data is successfully read and the external hard clock data is valid, the software clock data of the energy meter is updated based on the external hard clock data and the internal clock abnormality flag is reset. If reading the external hard clock data fails or the external hard clock data is invalid, the synchronization fails, the clock hardware fault flag is reset, and the dual hard clock fault is logged.

[0012] Optionally, the method further includes: The frequency of dual hard clock read failures is calculated for the current synchronization period and the number of synchronization periods prior to the current synchronization period. When the frequency exceeds a preset threshold, the internal hard clock data and the external hard clock data are updated based on the current software clock data of the current synchronization period.

[0013] To address the aforementioned problems, this application provides a clock synchronization device for electricity meters based on RTC hardware backup, comprising: a power-off clock calibration sub-device, a remote clock calibration sub-device, and a clock calibration sub-device during operation, wherein the power-off clock calibration sub-device includes: The reading module is used to read the clock source data after power-on, which includes internal hard clock data, external hard clock data, and power-off clock data. The verification module is used to verify the legality of the internal hard clock data, external hard clock data, and power-down clock data, and obtain the verification result. The arbitration module is used to compare and arbitrate the internal hard clock data, the external hard clock data, and the power-down clock data based on the verification result and the preset cross-arbitration rules to obtain the target reliable time. The synchronization update module is used to synchronize and update the software clock, internal hard clock, and external hard clock of the energy meter based on the target reliable time.

[0014] To address the aforementioned problems, this application provides a storage medium storing a computer program that, when executed by a processor, implements the steps of the aforementioned energy meter clock synchronization method based on RTC hardware backup.

[0015] To address the aforementioned problems, this application provides an electronic device, comprising at least a memory and a processor. The memory stores a computer program, and the processor, when executing the computer program in the memory, implements the steps of the aforementioned energy meter clock synchronization method based on RTC hardware backup.

[0016] The beneficial effects of this application are as follows: By constructing a hierarchical clock architecture with one software and two hardware components, and designing multi-scenario synchronization, arbitration and fault handling logic, this application achieves significant improvements in core dimensions such as reliability, availability, robustness and cost-effectiveness compared to existing single hardware clock and software clock technologies. At the same time, it meets the core needs of smart grid gateway energy meters for trade settlement and grid monitoring, and improves the accuracy of energy meter time signals.

[0017] The above description is merely an overview of the technical solution of the present invention. In order to better understand the technical means of the present invention and to implement it in accordance with the contents of the specification, and to make the above and other objects, features and advantages of the present invention more apparent and understandable, specific embodiments of the present invention are described below. Attached Figure Description

[0018] Various other advantages and benefits will become apparent to those skilled in the art upon reading the following detailed description of preferred embodiments. The accompanying drawings are for illustrative purposes only and are not intended to limit the invention. Furthermore, the same reference numerals denote the same parts throughout the drawings. In the drawings: Figure 1 A flowchart illustrating a method for synchronizing an energy meter clock based on RTC hardware backup, provided in an embodiment of this application, is shown. Figure 2 This illustration shows a flowchart of a method for synchronizing an energy meter clock based on RTC hardware backup, according to another embodiment of this application. Figure 3 A flowchart illustrating the remote clock calibration sub-method provided in an embodiment of this application is shown; Figure 4 A flowchart illustrating a clock calibration sub-method during operation, provided in another embodiment of this application, is shown. Figure 5 A block diagram of a clock synchronization device for an energy meter based on RTC hardware backup, according to another embodiment of this application, is shown. Detailed Implementation

[0019] Various embodiments and features of this application are described herein with reference to the accompanying drawings.

[0020] It should be understood that various modifications can be made to the embodiments described herein. Therefore, the above description should not be considered as limiting, but merely as an example of embodiments. Other modifications within the scope and spirit of this application will be apparent to those skilled in the art.

[0021] The accompanying drawings, which are included in and form part of this specification, illustrate embodiments of the present application and, together with the general description of the present application given above and the detailed description of the embodiments given below, serve to explain the principles of the present application.

[0022] These and other features of this application will become apparent from the following description of preferred forms of embodiments given as non-limiting examples, with reference to the accompanying drawings.

[0023] It should also be understood that although this application has been described with reference to some specific examples, those skilled in the art can certainly implement many other equivalent forms of this application.

[0024] The above and other aspects, features and advantages of this application will become more apparent when taken in conjunction with the accompanying drawings and in view of the following detailed description.

[0025] Specific embodiments of this application are described thereafter with reference to the accompanying drawings; however, it should be understood that the claimed embodiments are merely examples of this application, which can be implemented in various ways. Well-known and / or repeated functions and structures are not described in detail to avoid unnecessary or redundant details that could obscure the application. Therefore, the specific structural and functional details claimed herein are not intended to be limiting, but merely to teach those skilled in the art to use this application in a variety of substantially any suitable detailed structures.

[0026] This specification may use the phrases “in one embodiment,” “in another embodiment,” “in yet another embodiment,” or “in other embodiments,” all of which may refer to one or more of the same or different embodiments according to this application.

[0027] This application provides a method for synchronizing the clock of an energy meter based on RTC hardware backup, such as... Figure 1 As shown, it includes: Step S101: Read the clock source data after power-on, the clock source data including internal hard clock data, external hard clock data and power-down clock data; In this implementation process, the electricity meter clock system includes: a software clock (Tnow), an internal hardware clock (Thard), and an external hardware clock (Text). The software clock (Tnow) runs in the MCU memory and is incremented by a system timer interrupt, serving as the runtime base for the unified functional logic of the electricity meter. The internal hardware clock is a temperature-compensated real-time clock module integrated within the MCU, serving as the primary physical clock source. The external hardware clock is an external real-time clock chip (such as the RX8025T) independent of the MCU chip, serving as an auxiliary physical clock source. This external clock chip is connected to the MCU via I2C or SPI buses. During system operation, the software clock (Tnow) is the sole time output. When the meter experiences an abnormal power outage and is then restored, the values ​​from three time sources are immediately read and stored in temporary variables: the internal hardware clock data of the MCU is read and stored in the first temporary variable mcuTime; the external hardware clock data is read and stored in the second temporary variable extTime; and the power-down clock data stored in the electrically erasable memory EE before the power outage is read and stored in the third temporary variable eeTime. The power-down clock data is the effective time of the last system synchronization before the power outage.

[0028] Step S102: Verify the validity of the internal hard clock data, external hard clock data, and power-down clock data, and obtain the verification result; In this step, the validity of the internal hard clock data, external hard clock data, and power-down clock data is verified using a single-source validity check. If the internal hard clock data is valid, the flag of the internal hard clock is set to mcuTimeOk=True; otherwise, it is set to False. If the external hard clock data is valid, the flag of the external hard clock is set to extTimeOk=True; otherwise, it is set to False. If the power-down clock data is valid, the flag of the power-down clock is set to eeTimeOk=True; otherwise, it is set to False.

[0029] Step S103: Based on the verification result and the preset cross-arbitration rules, compare and arbitrate the internal hard clock data, the external hard clock data, and the power-down clock data to obtain the target reliable time; In this step, when the verification result shows that the internal hard clock data is valid and the difference between the internal hard clock data and the power-down clock data is less than a preset threshold, the internal hard clock data is determined as the target reliable time. When the verification result shows that the internal hard clock data is invalid, the external hard clock data is valid, and the difference between the external hard clock data and the power-down clock data is less than a preset threshold, the external hard clock data is determined as the target reliable time. When the verification result shows that the internal hard clock data is invalid, the external hard clock data is invalid, and the power-down clock data is valid, the power-down clock data is determined as the target reliable time. When the verification result shows that the internal hard clock data is invalid, the external hard clock data is invalid, and the power-down clock data is invalid, a system time anomaly alarm is triggered.

[0030] Step S104: Based on the target reliable time, update the time synchronization of the software clock, internal hard clock and external hard clock of the energy meter.

[0031] In the specific implementation process of this step, the power-down clock data is updated based on the target reliable time; the software clock data of the energy meter is updated based on the updated power-down clock data; and the updated power-down clock data is written into the internal hard clock and the external hard clock of the energy meter respectively to synchronize the internal hard clock data and the external hard clock data.

[0032] This application constructs a hierarchical clock architecture with one hardware and two software components, and designs multi-scenario synchronization, arbitration, and fault handling logic. Compared with existing single hardware clock and software clock technologies, it achieves significant improvements in core dimensions such as reliability, availability, robustness, and cost-effectiveness. At the same time, it meets the core needs of smart grid gateway energy meters for trade settlement and grid monitoring, and improves the accuracy of energy meter time signals.

[0033] Another embodiment of this application provides a different method for synchronizing the clock of an energy meter based on RTC hardware backup, including a power-off clock calibration sub-method, a remote clock calibration sub-method, and a clock calibration sub-method during operation, such as... Figure 2 As shown, the power-on clock calibration method includes the following steps: Step S201: Read the clock source data after power-on, the clock source data including internal hard clock data, external hard clock data and power-down clock data; In the specific implementation of this step, when the meter experiences an abnormal power outage and is then powered on again, the values ​​of three time sources are immediately read and stored in temporary variables respectively: the internal hardware clock data of the MCU is read and stored in the first temporary variable mcuTime; the external hardware clock data is read and stored in the second temporary variable extTime; the power-down clock data stored in the electrically erasable memory EE before the power outage is read and stored in the third temporary variable eeTime; the power-down clock data is the valid time of the last system synchronization before the power outage.

[0034] Step S202: Verify the validity of the internal hard clock data, external hard clock data, and power-down clock data, and obtain the verification result; In this step, the validity of the internal hard clock data, external hard clock data, and power-down clock data is verified using a single-source validity check. If the internal hard clock data is valid, the flag of the internal hard clock is set to mcuTimeOk=True; otherwise, it is set to False. If the external hard clock data is valid, the flag of the external hard clock is set to extTimeOk=True; otherwise, it is set to False. If the power-down clock data is valid, the flag of the power-down clock is set to eeTimeOk=True; otherwise, it is set to False.

[0035] Step S203: When the verification result shows that the internal hard clock data is valid and the difference between the internal hard clock data and the power-down clock data is less than a preset threshold, the internal hard clock data is determined as the target reliable time. In the specific implementation process of this step, when the verification result is that the internal hard clock data is valid (mcuTimeOk=True) and the difference between the internal hard clock data and the power-down clock data is less than a preset threshold, the internal hard clock data is determined as the target reliable time. Specifically, if mcuTimeOk=True and the difference between mcuTime and eeTime is within a reasonable range, then mcuTime is determined to be reliable, useMcuTime=True is set, and the internal hard clock data is determined as the target reliable time.

[0036] Step S204: When the verification result is that the internal hard clock data is invalid, the external hard clock data is valid, and the difference between the external hard clock data and the power-down clock data is less than a preset threshold, the external hard clock data is determined as the target reliable time. In this step, when the verification result is that the internal hard clock data is invalid, the external hard clock data is valid, and the difference between the external hard clock data and the power-down clock data is less than a preset threshold, the external hard clock data is determined as the target reliable time. Specifically, if the internal hard clock data mcuTime is unreliable, and the external hard clock data extTimeOk=True is valid, and the difference between the external hard clock data extTime and the power-down clock data eeTime is within a reasonable range, the external hard clock data extTime is determined to be reliable, and the external hard clock data is determined as the target reliable time.

[0037] Step S205: When the verification result is that the internal hard clock data is invalid, the external hard clock data is invalid, and the power-down clock data is valid, the power-down clock data is determined as the target reliable time; In this step, when the verification result shows that the internal hard clock data is invalid, the external hard clock data is invalid, and the power-down clock data is valid, the power-down clock data is determined as the target reliable time. Specifically, if both hard clocks are unreliable, i.e., the internal hard clock data mcuTime is unreliable and the external hard clock data extTime is unreliable, the valid power-down clock data eeTime is used as the final target reliable time. If the power-down clock data eeTime is also invalid, a system time anomaly alarm is triggered, and manual time calibration is required.

[0038] Step S206: When the verification result is that the internal hard clock data is invalid, the external hard clock data is invalid, and the power-down clock data is invalid, a system time anomaly alarm is triggered; In the specific implementation process of this step, when the verification result is that the internal hard clock data is invalid, the external hard clock data is invalid, and the power-down clock data is invalid, a system time abnormality alarm is triggered, and manual time calibration is required.

[0039] Step S207: Update the power-down clock data based on the target reliable time; In the specific implementation process, this step involves copying and updating the most reliable target time obtained from arbitration to the power-down clock data eeTime, ensuring that the reference time stored in EE is the latest valid value.

[0040] Step S208: Update the software clock data of the energy meter based on the updated power-down clock data; In the specific implementation process, this step uses the updated power-down clock data eeTime to restore the software clock data, which serves as the time base for system operation.

[0041] Step S209: Write the updated power-down clock data into the internal hard clock and external hard clock of the energy meter respectively to synchronize the internal hard clock data and the external hard clock data.

[0042] In this step, the updated power-down clock data is written to both the internal and external hard clocks of the energy meter to synchronize the data. Forced synchronization is then performed, writing the power-down clock data eeTime to both the internal and external hard clocks to synchronize their updates and ensure time consistency across all clock sources. If only one hard clock is reliable, while synchronizing eeTime to that clock, an attempt is made to write to another faulty hard clock to complete the repair.

[0043] When the electricity meter experiences an abnormal power outage and is then restored, the system is in a state of time chaos. During this stage, by reading three time sources—internal hard clock data, external hard clock data, and power-out clock data—and performing single-clock validity verification and cross-comparison arbitration, the most reliable target time is selected. The target reliable time is then used to force synchronization to all clock sources, which can ensure time reliability in extreme scenarios.

[0044] The remote clock calibration sub-method, such as Figure 3 As shown, it includes: Step S301: In response to receiving a valid time synchronization command sent by the target communication interface, update the software clock data of the energy meter based on the target verification time carried in the valid time synchronization command; In the specific implementation of this step, the target communication interface is an infrared interface, an RS-485 interface, or a carrier communication interface. The remote master station controls the energy meter to perform clock calibration by sending a valid time synchronization command through the target communication interface. The new target verification time in the valid time synchronization command is directly updated to the software clock Tnow, ensuring that the system real-time time takes effect immediately.

[0045] Step S302: Write the updated software clock data into the internal hard clock and the external hard clock to obtain the writing result; In the specific implementation process, the calibration of the internal and external hard clocks in this step is divided into primary action and best-effort action: Primary action: Write the software clock data value corresponding to the updated software clock Tnow to the internal hard clock to update the internal hard clock data and verify the writing result; Best-effort action: Parallel or sequential action: Write the same software clock data to the external hardware clock to update the external hard clock data, and verify the writing result in the same way. The writing order can be selected as parallel or sequential according to the hardware design.

[0046] Step S303: When the updated software clock data is successfully written to the internal hard clock, the remote clock calibration operation is confirmed to be successful.

[0047] In this step, time synchronization is considered successful as long as the internal hard clock is successfully written. If writing the updated software clock data to the internal hard clock is successful but writing it to the external hard clock fails, the remote clock calibration operation is considered successful, and the external clock writing failure is logged. If writing the updated software clock data to the internal hard clock fails and writing it to the external hard clock is successful / failed, the remote clock calibration operation is considered failed, a time synchronization error flag is set, and a log entry is made. If the external hard clock writing fails, it does not affect the time synchronization success status, but an "external clock writing failure" log entry must be immediately recorded for subsequent synchronization cycle checks and repairs. If the internal hard clock writing fails but the external hard clock writing succeeds, the time synchronization is still considered failed, a "time synchronization error" flag is set, a log entry is made, and the system waits for the master station to resend the command.

[0048] The clock calibration sub-method during operation, such as Figure 4 As shown, it includes the following steps: Step S401: Read the internal hard clock data of the energy meter; In this specific implementation process, after the power-on initialization of the electricity meter clock system, hardware and software initialization are completed first. The hardware includes an external clock chip and communication bus, etc.; the software includes flags, timers, logs, etc. The initialization actions include initializing the MCU's internal hardware clock Thard and external independent hardware clock Text, such as RX8025T, configuring I2C / SPI communication bus parameters to ensure normal communication with the external clock chip; initializing the software clock Tnow, configuring a clock synchronization timer once per minute for configurable synchronization time points to avoid peak data processing times; initializing various status flags, such as "clock hardware failure", "mcuTimeOk", "extTimeOk", "useMcuTime" and other fault log modules, with the flags initially in an untriggered or invalid state; performing the first synchronization from the hard clock to the software clock, prioritizing reading Thard to initialize Tnow, if Thard fails, then reading Text, if both hard clocks fail, Tnow is temporarily driven independently by the system timer, and the "clock hardware failure" flag is set. During normal system operation, the software clock Tnow is the sole time output source, and all metering, billing, and event recordings utilize Tnow. To eliminate accumulated errors in the software clock, unidirectional synchronization between the hard clock and the software clock is performed at a fixed interval of once per minute. After system initialization and during normal operation, the system reads the internal hard clock data of the energy meter's MCU in real time and performs validity verification on the internal hard clock data, considering multiple dimensions such as data format, check bit, and communication timeout.

[0049] Step S402: If the internal hard clock data is successfully read and the internal hard clock data is valid, update the software clock data of the energy meter based on the internal hard clock data and reset the clock hardware fault flag bit. In the specific implementation process of this step, if the internal hard clock data is successfully read and valid, the value of the internal hard clock data is directly used to overwrite and update the software clock data TnowTime. Once this synchronization is completed, the "clock hardware failure" flag is reset.

[0050] Step S403: If the reading fails or the internal hard clock data is invalid, read the external hard clock data of the energy meter; In the specific implementation process of this step, if the internal hard clock data reading fails or the internal hard clock data is invalid, such as internal hard clock data being abnormal or internal hard clock communication timing out, a backup mechanism is activated to attempt to read the external hardware clock Text and perform validity verification.

[0051] Step S404: If the external hard clock data is successfully read and the external hard clock data is valid, update the software clock data of the energy meter based on the external hard clock data and reset the internal clock abnormality flag. In the specific implementation process of this step, if the external hard clock data is successfully read and valid, the software clock is updated with the value of the external hard clock. The synchronization is then completed, the "internal clock abnormal" temporary flag is set, and the log is recorded.

[0052] Step S405: If reading the external hard clock data fails or the external hard clock data is invalid, the synchronization fails. The clock hardware fault flag is reset and the dual hard clock fault is logged.

[0053] In this step, if the external hard clock data also fails to be read or is invalid, the synchronization fails, and the software clock is not updated. The software clock continues to run independently via a system timer interrupt, and the "clock hardware failure" core flag is set; a dual hard clock failure log is also recorded. The frequency of dual hard clock read failures in the current synchronization period and a preset number of synchronization periods prior to the current synchronization period is counted. When the frequency exceeds a preset threshold, the internal hard clock data and the external hard clock data are updated based on the current software clock data of the current synchronization period. The preset number of periods can be 2, and each synchronization period can be set to 1 minute. The preset number of periods and the duration of the synchronization period can be set according to actual needs. If dual hard clock read failures occur for three consecutive synchronization periods, a serious hardware clock system failure is determined, and a reverse synchronization repair is immediately performed using a remote clock calibration sub-method to repair the clock system: the currently roughly accurate software clock data is written to the internal hard clock (Thard) and the external hard clock (Text) respectively, attempting to forcibly correct the hardware clock. After repair, the regular synchronization process is re-executed.

[0054] This application abandons the absolute reliance of existing technologies on a single internal hardware clock of the MCU, and introduces an independent external hardware clock chip to build a dual physical clock redundancy system, forming a three-layer clock architecture in conjunction with the software clock. Regardless of whether the internal hardware clock fails due to electromagnetic interference, power fluctuations, chip aging, or other reasons, it can automatically switch to the external hardware clock to maintain high-precision timing, eliminating the risk of single-point failure in the clock system from the hardware level. This ensures the stability of the time base for core functions such as electricity meter trade settlement and rate switching, completely eliminating single-point failures and significantly improving the reliability of the clock system. A dynamic switching logic for primary and backup clocks is designed. During normal operation, the internal hardware clock is used first, and if it fails, it can seamlessly switch to the external hardware clock, maintaining the accuracy of the software clock without manual intervention. Simultaneously, for the extreme scenario of power outage and power-on, a multi-source time arbitration mechanism is designed. By reading the internal and external hardware clocks and the reference time stored before the power outage, the most reliable time is automatically selected and synchronized to all clock sources, quickly restoring the system's effective time base, significantly reducing the time the clock system is in a state of "no reliable time," and even achieving seamless fault switching. This achieves automatic fault switching and rapid recovery, improving system high availability. An independent cross-validation mechanism for the master clock source has been established. By comparing the two physical clocks, latent faults in the internal hardware clock (such as slow accuracy degradation and intermittent output errors) can be detected in a timely manner, overcoming the shortcomings of existing technologies that cannot identify latent problems in the master clock. Fault escalation and reverse repair logic is designed. When both hardware clocks fail consecutively, active repair can be performed by writing back the hardware clock via the software clock. A redundant time synchronization writing strategy is also adopted, prioritizing successful writing of the master clock during remote time synchronization while making every effort to write to the backup clock. Even if a single write path fails, the time synchronization operation can still be ensured to succeed, significantly improving time synchronization fault tolerance and the overall anti-interference capability of the system. The accuracy and reliability of the clock are directly related to the fairness of electricity meter billing and the accuracy of grid operation analysis. This solution ensures that the electricity meter can output accurate timestamps throughout its entire lifecycle through full-scenario time base protection, effectively avoiding problems such as rate calculation errors, inaccurate event recording, and data synchronization disorder caused by clock drift and faults. It provides stable and reliable time support for electricity metering, grid monitoring, and remote operation and maintenance in smart grids, meeting the application requirements of high-end products such as gateway electricity meters.

[0055] Another embodiment of this application provides a clock synchronization device 500 for an energy meter based on RTC hardware backup, such as... Figure 5 As shown, it includes: a power-down clock calibration sub-device 600, a remote clock calibration sub-device 700, and a clock calibration sub-device 800 during operation. The power-down clock calibration sub-device includes: The reading module 601 is used to read the clock source data after power-on, the clock source data including internal hard clock data, external hard clock data and power-off clock data; The verification module 602 is used to verify the legality of the internal hard clock data, external hard clock data and power-down clock data, and obtain the verification result. Arbitration module 603 is used to compare and arbitrate the internal hard clock data, the external hard clock data, and the power-down clock data based on the verification result and preset cross-arbitration rules to obtain the target reliable time; The synchronization update module 604 is used to perform time synchronization updates on the software clock, internal hard clock, and external hard clock of the energy meter based on the target reliable time.

[0056] In specific implementation, the arbitration module 603 is specifically used for: determining the internal hard clock data as the target reliable time when the verification result is that the internal hard clock data is valid and the difference between the internal hard clock data and the power-down clock data is less than a preset threshold; determining the external hard clock data as the target reliable time when the verification result is that the internal hard clock data is invalid, the external hard clock data is valid and the difference between the external hard clock data and the power-down clock data is less than a preset threshold; determining the power-down clock data as the target reliable time when the verification result is that the internal hard clock data is invalid, the external hard clock data is invalid and the power-down clock data is valid; and triggering a system time anomaly alarm when the verification result is that the internal hard clock data is invalid, the external hard clock data is invalid and the power-down clock data is invalid.

[0057] In the specific implementation process, the arbitration module 603 is also used to: update the power-down clock data based on the target reliable time; update the software clock data of the energy meter based on the updated power-down clock data; and write the updated power-down clock data into the internal hard clock and the external hard clock of the energy meter respectively to synchronously update the internal hard clock data and the external hard clock data respectively.

[0058] In the specific implementation process, the remote clock calibration sub-device 700 is used to: respond to receiving a valid time calibration command sent by the target communication interface, update the software clock data of the energy meter based on the target calibration time carried in the valid time calibration command; write the updated software clock data into the internal hard clock and the external hard clock to obtain the writing result; when the updated software clock data is successfully written into the internal hard clock, the remote clock calibration operation is determined to be successful.

[0059] In specific implementation, the remote clock calibration sub-device 700 is also used to: determine that the remote clock calibration operation is successful and log the failure of writing the updated software clock data to the external hard clock when writing the updated software clock data to the internal hard clock is successful and writing the updated software clock data to the external hard clock fails; determine that the remote clock calibration operation has failed when writing the updated software clock data to the internal hard clock fails and writing the updated software clock data to the external hard clock is successful / failed, set the time calibration exception flag and log the error.

[0060] In the specific implementation process, the clock calibration sub-device 800 is used to read the internal hard clock data of the energy meter during operation; if the reading of the internal hard clock data is successful and the internal hard clock data is valid, the software clock data of the energy meter is updated based on the internal hard clock data, and the clock hardware fault flag is reset; if the reading fails or the internal hard clock data is invalid, the external hard clock data of the energy meter is read; if the reading of the external hard clock data is successful and the external hard clock data is valid, the software clock data of the energy meter is updated based on the external hard clock data, and the internal clock abnormality flag is reset; if the reading of the external hard clock data fails or the external hard clock data is invalid, the synchronization fails, the clock hardware fault flag is reset, and the dual hard clock fault is logged.

[0061] In the specific implementation process, the clock calibration sub-device 800 is also used to count the frequency of dual hard clock read failures in the current synchronization period and the number of synchronization periods before the current synchronization period; when the frequency exceeds the preset number threshold, the internal hard clock data and the external hard clock data are updated based on the current software clock data of the current synchronization period.

[0062] This application constructs a hierarchical clock architecture with one hardware and two software components, and designs multi-scenario synchronization, arbitration, and fault handling logic. Compared with existing single hardware clock and software clock technologies, it achieves significant improvements in core dimensions such as reliability, availability, robustness, and cost-effectiveness. At the same time, it meets the core needs of smart grid gateway energy meters for trade settlement and grid monitoring, and improves the accuracy of energy meter time signals.

[0063] Another embodiment of this application provides a storage medium storing a computer program, which, when executed by a processor, implements the following method steps: Step 1: Read the clock source data after power-on. The clock source data includes internal hard clock data, external hard clock data, and power-down clock data. Step 2: Verify the validity of the internal hard clock data, external hard clock data, and power-down clock data, and obtain the verification results; Step 3: Based on the verification results and the preset cross-arbitration rules, compare and arbitrate the internal hard clock data, the external hard clock data, and the power-down clock data to obtain the target reliable time; Step 4: Based on the target reliable time, update the time synchronization of the electricity meter's software clock, internal hard clock, and external hard clock.

[0064] Those skilled in the art will understand that all or part of the processes in the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium. When executed, the computer program can include the processes of the embodiments of the above methods. Any references to memory, storage, databases, or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in a variety of forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), dual data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), RAMbus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.

[0065] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the above-described division of functional units and modules is used as an example. In practical applications, the above functions can be assigned to different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above.

[0066] The specific implementation process of the above method steps can be found in any of the above embodiments of the electricity meter clock synchronization method based on RTC hardware backup, and will not be repeated here.

[0067] This application constructs a hierarchical clock architecture with one hardware and two software components, and designs multi-scenario synchronization, arbitration, and fault handling logic. Compared with existing single hardware clock and software clock technologies, it achieves significant improvements in core dimensions such as reliability, availability, robustness, and cost-effectiveness. At the same time, it meets the core needs of smart grid gateway energy meters for trade settlement and grid monitoring, and improves the accuracy of energy meter time signals.

[0068] Another embodiment of this application provides an electronic device, which can be a server. The electronic device includes a processor, a memory, a network interface, and a database connected via a system bus. The processor provides computing and control capabilities. The memory includes non-volatile and / or volatile storage media and internal memory. The non-volatile storage media stores an operating system, computer programs, and a database. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage media. The network interface is used to communicate with external clients via a network connection. When the program is executed by the processor, it implements the functions or steps of a server-side method for synchronizing an energy meter clock based on RTC hardware backup.

[0069] In one embodiment, an electronic device is provided, which can be a client. The electronic device includes a processor, memory, a network interface, a display screen, and an input device connected via a system bus. The processor provides computing and control capabilities. The memory includes a non-volatile storage medium and internal memory. The non-volatile storage medium stores an operating system and computer programs. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage medium. The network interface is used to communicate with an external server via a network connection. When the program is executed by the processor, it implements the functions or steps of a client-side method for synchronizing an energy meter clock based on RTC hardware backup.

[0070] Another embodiment of this application provides an electronic device, including at least a memory and a processor. The memory stores a computer program, and the processor, when executing the computer program in the memory, performs the following method steps: Step 1: Read the clock source data after power-on. The clock source data includes internal hard clock data, external hard clock data, and power-down clock data. Step 2: Verify the validity of the internal hard clock data, external hard clock data, and power-down clock data, and obtain the verification results; Step 3: Based on the verification results and the preset cross-arbitration rules, compare and arbitrate the internal hard clock data, the external hard clock data, and the power-down clock data to obtain the target reliable time; Step 4: Based on the target reliable time, update the time synchronization of the electricity meter's software clock, internal hard clock, and external hard clock.

[0071] The specific implementation process of the above method steps can be found in any of the above embodiments of the electricity meter clock synchronization method based on RTC hardware backup, and will not be repeated here.

[0072] This application constructs a hierarchical clock architecture with one hardware and two software components, and designs multi-scenario synchronization, arbitration, and fault handling logic. Compared with existing single hardware clock and software clock technologies, it achieves significant improvements in core dimensions such as reliability, availability, robustness, and cost-effectiveness. At the same time, it meets the core needs of smart grid gateway energy meters for trade settlement and grid monitoring, and improves the accuracy of energy meter time signals.

[0073] The above embodiments are merely exemplary embodiments of this application and are not intended to limit this application. Those skilled in the art can make various modifications or equivalent substitutions to this application within the scope and nature of this application, and such modifications or equivalent substitutions should also be considered to fall within the scope of protection of this application.

Claims

1. A method for synchronizing the clock of an energy meter based on RTC hardware backup, characterized in that, include: The method includes a power-down clock calibration sub-method, a remote clock calibration sub-method, and a clock calibration sub-method during operation. The power-down clock calibration sub-method further includes: Read the clock source data after power-on, including internal hard clock data, external hard clock data, and power-off clock data; The validity of the internal hard clock data, external hard clock data, and power-down clock data is verified to obtain the verification results. Based on the verification results and the preset cross-arbitration rules, the internal hard clock data, the external hard clock data, and the power-down clock data are compared and arbitrated to obtain the target reliable time. Based on the target reliable time, the software clock, internal hard clock, and external hard clock of the energy meter are updated for time synchronization.

2. The method as described in claim 1, characterized in that, The step of comparing and arbitrating the internal hard clock data, the external hard clock data, and the power-down clock data based on the verification result and preset cross-arbitration rules to obtain the target reliable time specifically includes: When the verification result indicates that the internal hard clock data is valid and the difference between the internal hard clock data and the power-down clock data is less than a preset threshold, the internal hard clock data is determined as the target reliable time. When the verification result is that the internal hard clock data is invalid, the external hard clock data is valid, and the difference between the external hard clock data and the power-down clock data is less than a preset threshold, the external hard clock data is determined as the target reliable time. When the verification result is that the internal hard clock data is invalid, the external hard clock data is invalid, and the power-down clock data is valid, the power-down clock data is determined as the target reliable time. When the verification result indicates that the internal hard clock data is invalid, the external hard clock data is invalid, and the power-down clock data is invalid, a system time anomaly alarm is triggered.

3. The method as described in claim 1, characterized in that, The time synchronization update of the software clock, internal hard clock, and external hard clock of the energy meter based on the target reliable time specifically includes: Update the power-down clock data based on the target reliable time; The software clock data of the energy meter is updated based on the updated power-down clock data; The updated power-off clock data is written to both the internal hard clock and the external hard clock of the energy meter to synchronize the internal hard clock data and the external hard clock data, respectively.

4. The method as described in claim 1, characterized in that, The remote clock calibration sub-method includes: In response to receiving a valid time synchronization command sent by the target communication interface, the software clock data of the energy meter is updated based on the target verification time carried in the valid time synchronization command; The updated software clock data is written to the internal hard clock and the external hard clock to obtain the writing result; When the updated software clock data is successfully written to the internal hard clock, the remote clock calibration operation is considered successful.

5. The method as described in claim 4, characterized in that, The method further includes: When writing the updated software clock data to the internal hard clock is successful but writing the updated software clock data to the external hard clock fails, the remote clock calibration operation is determined to be successful and the failure to write the external clock is logged. When writing the updated software clock data to the internal hard clock fails and writing the updated software clock data to the external hard clock succeeds / fails, the remote clock calibration operation is determined to have failed, the time calibration exception flag is set, and the error is logged.

6. The method as described in claim 1, characterized in that, The clock calibration sub-method during operation includes: Read the internal hard clock data of the energy meter; If the internal hard clock data is successfully read and the internal hard clock data is valid, the software clock data of the energy meter is updated based on the internal hard clock data, and the clock hardware fault flag is reset. If the read fails or the internal hard clock data is invalid, read the external hard clock data of the energy meter; If the external hard clock data is successfully read and the external hard clock data is valid, the software clock data of the energy meter is updated based on the external hard clock data and the internal clock abnormality flag is reset. If reading the external hard clock data fails or the external hard clock data is invalid, the synchronization fails, the clock hardware fault flag is reset, and the dual hard clock fault is logged.

7. The method as described in claim 6, characterized in that, The method further includes: The frequency of dual hard clock read failures is calculated for the current synchronization period and the number of synchronization periods prior to the current synchronization period. When the frequency exceeds a preset threshold, the internal hard clock data and the external hard clock data are updated based on the current software clock data of the current synchronization period.

8. A clock synchronization device for an energy meter based on RTC hardware backup, characterized in that, include: The system includes a power-off clock calibration sub-device, a remote clock calibration sub-device, and a clock calibration sub-device during operation. The power-off clock calibration sub-device comprises: The reading module is used to read the clock source data after power-on, which includes internal hard clock data, external hard clock data, and power-off clock data. The verification module is used to verify the legality of the internal hard clock data, external hard clock data, and power-down clock data, and obtain the verification result. The arbitration module is used to compare and arbitrate the internal hard clock data, the external hard clock data, and the power-down clock data based on the verification result and the preset cross-arbitration rules to obtain the target reliable time. The synchronization update module is used to synchronize and update the software clock, internal hard clock, and external hard clock of the energy meter based on the target reliable time.

9. A storage medium, characterized in that, The storage medium stores a computer program, which, when executed by a processor, implements the steps of the energy meter clock synchronization method based on RTC hardware backup as described in any one of claims 1-7.

10. An electronic device, characterized in that, It includes at least a memory and a processor, wherein the memory stores a computer program, and the processor, when executing the computer program in the memory, implements the steps of the energy meter clock synchronization method based on RTC hardware backup as described in any one of claims 1-7.