Method and system for compensating clock drift of an electric energy meter based on model predictive control
By using model predictive control, bidirectional time data packets are collected between the electricity meter and the time server. A specific field is set to compare the router queue length, and a clock drift prediction model is constructed. This solves the problem of inaccurate clock synchronization of electricity meters under traditional methods and realizes efficient clock drift compensation for the power system.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- CHINA POWER HUARUI TECH CO LTD
- Filing Date
- 2026-03-30
- Publication Date
- 2026-06-19
AI Technical Summary
Traditional time synchronization methods struggle to maintain high-precision synchronization of electricity meter clocks under dynamic network conditions, leading to accumulated clock deviations that affect the reliability of the power system, especially in terminal equipment that requires long-term independent operation and strict timestamp accuracy.
By using model predictive control, bidirectional time data packets between the electricity meter and the time server are collected. Specific fields are set and compared with the waiting queue length of the router to determine the asymmetry coefficient of bidirectional transmission delay. A clock drift prediction model is then constructed to compensate the local clock of the electricity meter in real time.
It achieves precise compensation for clock drift in electricity meters, optimizes the timeliness and stability of compensation, adapts to the clock synchronization requirements under dynamic network conditions, and ensures the reliability of the power system.
Smart Images

Figure CN121934341B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of drift compensation technology, and more specifically, to a method and system for clock drift compensation of electricity meters based on model predictive control. Background Technology
[0002] Drift compensation is a technique used to eliminate or reduce the slow shift (i.e., drift) of the output signal of a sensor, instrument, or system caused by factors such as environmental changes, component aging, or temperature fluctuations. It restores the measured value to the true or standard state through real-time or periodic calibration, reference signal comparison, or algorithm correction, thereby ensuring the accuracy and stability of long-term measurements.
[0003] As the core equipment for electricity metering and power consumption management, the accuracy of the local clock of an electricity meter directly affects the reliability of key power system functions such as electricity billing, remote meter reading, and load control. In the time synchronization application of distributed systems, terminal devices in the network need to achieve clock alignment by exchanging messages with a high-precision time source. However, in the actual communication link of an electricity meter, data packets need to be forwarded through multiple intermediate network nodes. The processing delay, queuing status, and dynamic changes in network load of each node can lead to inconsistent transmission delays between the uplink and downlink paths. This delay asymmetry introduces synchronization errors. Traditional time synchronization methods are often based on the assumption of symmetrical delay or simple statistical estimation, which makes it difficult to maintain high-precision clock synchronization under dynamic network conditions. Especially for terminal devices that need to operate independently for a long time and have strict requirements for timestamp accuracy, the accumulated clock deviation may affect the reliability of their event recording, collaborative control, and other functions. Therefore, how to compensate for the drift of the electricity meter clock based on the bidirectional delay difference has become a problem faced by the industry. Summary of the Invention
[0004] This application provides a method and system for compensating for clock drift in electricity meters based on model predictive control, which can compensate for clock drift in electricity meters based on the bidirectional time delay difference of the electricity meter.
[0005] In a first aspect, this application provides a method for clock drift compensation of electricity meters based on model predictive control, wherein the electricity meters are connected to a time server through various routers to realize bidirectional transmission of time data between the electricity meters and the time server. The method includes the following steps:
[0006] Collect time data packets transmitted bidirectionally between the electricity meter and the time server;
[0007] A specific field is set and assigned an initial value in the time data packet. When the time data packet passes through each router, the current value of the specific field is compared with the waiting queue length of the router to obtain the valid synchronization data packet of the time data packet and the final value of the specific field.
[0008] The asymmetry coefficient of the bidirectional transmission delay between the energy meter and the time server is determined by the effective synchronization data packet, the initial value, and the final value.
[0009] A clock drift prediction model for the electricity meter is constructed. The clock drift amount of the electricity meter is predicted based on the clock drift prediction model, the effective synchronization data packet, and the asymmetry coefficient. The local clock of the electricity meter is compensated and corrected in real time based on the clock drift amount.
[0010] In some embodiments, the time data packet includes a protocol header, a unique data packet identifier ID, a timestamp of the electricity meter sending data, a timestamp of the time server receiving data, a timestamp of the time server replying to the sending data, a timestamp of the electricity meter receiving data, and an extended queue matching identifier field.
[0011] In some embodiments, when the time data packet passes through each router, comparing the current value of the specific field with the waiting queue length of the router to obtain the valid synchronization data packet of the time data packet and the final value of the specific field specifically includes:
[0012] As the time data packet passes through each router in sequence, the current value of the specific field and the waiting queue length are obtained at each router;
[0013] Compare each current value with the corresponding router's wait queue length;
[0014] If the current value is greater than or equal to the waiting queue length of the corresponding router, update the current value and time data packet and continue forwarding;
[0015] If the current value is less than the waiting queue length of the corresponding router, the time data packet is marked as an invalid data packet and discarded directly;
[0016] The current value after all router updates are completed is used as the final value of the specific field, and the time data packets that are not dropped by any router are used as the valid synchronization data packets of the time data packets.
[0017] In some embodiments, determining the asymmetry coefficient of the bidirectional transmission delay between the energy meter and the time server using the effective synchronization data packet, the initial value, and the final value specifically includes:
[0018] Extract the key timestamps from the valid synchronization data packets;
[0019] The uplink and downlink transmission delays between the energy meter and the time server are determined based on all key timestamps.
[0020] The queue length correction coefficient for bidirectional transmission between the energy meter and the time server is determined based on the initial value and the final value.
[0021] The asymmetry coefficient of the bidirectional transmission delay between the energy meter and the time server is determined by the uplink transmission delay, the downlink transmission delay, and the queue length correction coefficient.
[0022] In some embodiments, constructing the clock drift prediction model for the energy meter specifically includes:
[0023] Acquire historical clock drift data, historical transmission delay data, historical waiting queue length data, and historical asymmetry coefficient of the energy meter under different ambient temperatures and cumulative operating times, and synchronously record the aging parameters of the crystal oscillator and network link stability data of the energy meter.
[0024] Based on the historical clock drift data, historical transmission delay data, historical waiting queue length data, historical asymmetry coefficient, aging parameters, and network link stability data, calculate the influence coefficient of temperature on clock drift, the attenuation coefficient of runtime on drift rate, the correction coefficient of queue length change on delay asymmetry, and the interaction effect of temperature-runtime and link stability-delay.
[0025] The clock drift prediction model of the energy meter is constructed using the influence coefficient, attenuation coefficient, correction coefficient, and interaction effect.
[0026] In some embodiments, predicting the clock drift of the energy meter based on the clock drift prediction model, the effective synchronization data packet, and the asymmetry coefficient specifically includes:
[0027] The valid synchronization data packet and the asymmetry coefficient are input into the clock drift prediction model;
[0028] The clock drift of the electricity meter is predicted using the clock drift prediction model.
[0029] In some embodiments, real-time compensation and correction of the local clock of the energy meter based on the clock drift specifically includes:
[0030] The compensation amount of the local clock of the energy meter is determined based on the clock drift amount;
[0031] The local clock of the energy meter is compensated and corrected in real time based on the compensation amount.
[0032] Secondly, this application provides a clock drift compensation system for electricity meters based on model predictive control, wherein the electricity meters are connected to a time server through various routers to realize bidirectional transmission of time data between the electricity meters and the time server. The system includes:
[0033] The data acquisition module is used to collect time data packets transmitted bidirectionally between the electricity meter and the time server.
[0034] The processing module is used to set a specific field and assign an initial value to the time data packet. When the time data packet passes through each router, the current value of the specific field is compared with the waiting queue length of the router to obtain the valid synchronization data packet of the time data packet and the final value of the specific field.
[0035] The processing module is further configured to determine the asymmetry coefficient of the bidirectional transmission delay between the energy meter and the time server through the effective synchronization data packet, the initial value, and the final value;
[0036] The execution module is used to construct a clock drift prediction model for the electricity meter, predict the clock drift amount of the electricity meter based on the clock drift prediction model, the effective synchronization data packet and the asymmetry coefficient, and perform real-time compensation and correction on the local clock of the electricity meter based on the clock drift amount.
[0037] Thirdly, this application provides a computer device, the computer device including a memory and a processor, the memory storing code, the processor being configured to acquire the code and execute the above-described model predictive control-based clock drift compensation method for electricity meters.
[0038] Fourthly, this application provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the above-described model predictive control-based clock drift compensation method for electricity meters.
[0039] The technical solutions provided by the embodiments disclosed in this application have the following beneficial effects:
[0040] The clock drift compensation method and system for electricity meters based on model predictive control provided in this application firstly collects bidirectional transmission time data packets. Secondly, specific fields are set and initialized in the time data packets. Valid synchronization data packets are dynamically filtered by comparing them with the router's waiting queue length, effectively isolating the effects of network congestion and router delay fluctuations, and accurately extracting key transmission delay information, thereby reducing noise interference. Next, the asymmetry coefficient of bidirectional transmission delay is determined using valid synchronization data packets, the initial and final values of the specific fields, directly quantifying the delay deviation caused by network path differences, providing accurate parameter basis for compensation. Finally, a clock drift prediction model is constructed, combining the asymmetry coefficient and valid data to predict the drift amount, and the local clock is compensated and corrected in real time. This not only achieves adaptive tracking of the clock drift dynamic characteristics but also optimizes the timeliness and stability of compensation through model predictive control. Using the above scheme, clock drift of electricity meters can be compensated based on the bidirectional delay difference of the electricity meter. Attached Figure Description
[0041] Figure 1 This is an exemplary flowchart of a clock drift compensation method for an energy meter based on model predictive control, according to some embodiments of this application.
[0042] Figure 2 This is an exemplary flowchart illustrating the determination of asymmetry coefficients according to some embodiments of this application;
[0043] Figure 3 This is an exemplary flowchart illustrating the determination of clock drift amount according to some embodiments of this application;
[0044] Figure 4 This is a schematic diagram of the structure of a model predictive control-based clock drift compensation system for an energy meter, as shown in some embodiments of this application.
[0045] Figure 5 This is a schematic diagram of the structure of a computer device that implements a model predictive control-based clock drift compensation method for electricity meters, according to some embodiments of this application. Detailed Implementation
[0046] To better understand the technical solution of this application, the technical solution of this application will be described in detail below with reference to the accompanying drawings and specific embodiments.
[0047] refer to Figure 1 The figure is an exemplary flowchart of a model predictive control-based clock drift compensation method for electricity meters according to some embodiments of this application. The model predictive control-based clock drift compensation method for electricity meters mainly includes the following steps:
[0048] In some embodiments, the connection between the electricity meter and the time server via various routers can be achieved as follows: The electricity meter has a built-in Ethernet communication module or 4G IoT module that supports the UDP / IP protocol. First, it obtains a static / dynamic IP address, subnet mask, and gateway address through manual configuration. The gateway points to the first relay router, and the IP address and communication port of the time server are preset. After the electricity meter starts up, it automatically sends a network connection request to the preset gateway router. The router completes multi-hop relay based on the routing table configuration. Each router establishes a TCP / UDP bidirectional communication connection with the time server through a static routing protocol or a dynamic routing protocol. After the connection is established, the electricity meter sends a heartbeat data packet every 30 seconds to maintain the stability of the link. At the same time, the router's port mapping function and firewall rules allow time synchronization data packets to pass, ensuring that the time data between the electricity meter and the time server can be transmitted bidirectionally without blocking. If the connection is interrupted, the electricity meter will automatically retry the connection within 10 seconds until communication is restored or a fault alarm is triggered, so as to realize the bidirectional transmission of time data between the electricity meter and the time server.
[0049] In step 101, time data packets transmitted bidirectionally between the electricity meter and the time server are collected.
[0050] It should be noted that the time data packet in this application is a specific format data unit transmitted between the energy meter and the time server through a time synchronization protocol, used to achieve clock calibration. Its core function is to carry the key information required for bidirectional time synchronization, reflecting the communication link status between the energy meter and the time server, the time node information of bidirectional data transmission, and the integrity of data transmission. The time data packet includes a protocol header, a unique data packet identifier ID, an energy meter sending timestamp, a time server receiving timestamp, a time server reply sending timestamp, an energy meter receiving timestamp, and an extended queue matching identifier field.
[0051] In step 102, a specific field is set and an initial value is assigned to the time data packet. When the time data packet passes through each router, the current value of the specific field is compared with the waiting queue length of the router to obtain the valid synchronization data packet of the time data packet and the final value of the specific field.
[0052] In specific implementation, setting a specific field and assigning an initial value to the time data packet can be achieved in the following way: In the original protocol header of the time data packet, without occupying the data payload area to avoid affecting the core data transmission of time synchronization, a specific field of type 2 unsigned integer is extended and defined as the "queue matching identifier field". The field encoding format follows network byte order to ensure router-side compatibility and parsing. Considering the maximum waiting queue length range of 0-65535 for mainstream routers in industrial scenarios, and referring to the empirical threshold for link congestion judgment, the initial value of this field is set to 100, corresponding to the acceptable low-congestion queue length threshold for the router. Specifically, this is achieved by modifying the data packet encapsulation logic of the time synchronization protocol stack at the energy meter end. During the protocol layer processing stage before data packet transmission, the initial value 0x0064 (decimal 100) is written to the memory offset corresponding to this extended field through a programming interface. The address ensures that every time data packet sent from the electricity meter carries this preset initial value, and that the field information does not violate the compatibility of the original protocol and data verification rules. Among them, the specific field is a core identifier field extended in the header of the time data packet for comparing the waiting queue length of the router. Its value carries the baseline threshold of the queue length and the dynamic update result during the transmission process, reflecting the link congestion status when the time data packet passes through each relay router. The initial value corresponds to the preset low congestion queue length threshold of the router. The updated value during the transmission process reflects the minimum actual waiting queue length of the routers passed through. The final value directly reflects the minimum congestion level of the entire transmission path. At the same time, by comparing the result of this field with the queue length of each router, it indirectly reflects whether the data packet has caused excessive transmission delay due to path congestion, providing a key basis for filtering effective synchronization data packets and correcting bidirectional transmission delay calculations.
[0053] In some embodiments, when the time data packet passes through each router, comparing the current value of the specific field with the router's waiting queue length to obtain the valid synchronization data packet of the time data packet and the final value of the specific field can be achieved by the following steps:
[0054] As the time data packet passes through each router in sequence, the current value of the specific field and the waiting queue length are obtained at each router;
[0055] Compare each current value with the corresponding router's wait queue length;
[0056] If the current value is greater than or equal to the waiting queue length of the corresponding router, update the current value and time data packet and continue forwarding;
[0057] If the current value is less than the waiting queue length of the corresponding router, the time data packet is marked as an invalid data packet and discarded directly;
[0058] The current value after all router updates are completed is used as the final value of the specific field, and the time data packets that are not dropped by any router are used as the valid synchronization data packets of the time data packets.
[0059] In specific implementation, when time data packets are transmitted in the network, each time they pass through a router, the router's message processing unit first parses the time data packet, locates the extended specific field through the field extraction interface of the protocol stack, and reads the currently stored value of that feature field, i.e., the current value. At the same time, the router accesses the ifOutQLen parameter in its own management information base through the GetRequest operation of the SNMP v2c protocol. This parameter is defined by the TCP / IP protocol suite standard and is used to characterize the number of data packets waiting to be forwarded in real time at the port. The router obtains the waiting queue length of the receiving port of the time data packet. During the acquisition process, a timer is used to synchronize and ensure that the current value and the waiting queue length are the same data collected at the same time point. Other implementation methods can also be used in other embodiments, which are not limited here.
[0060] In addition, in specific implementation, if the current value is greater than or equal to the waiting queue length of the corresponding router, it means that the time data packet has not caused excessive delay due to router congestion. The program modifies the storage unit of the specific field through memory address mapping, updates it to the smaller value between the current value and the waiting queue length, and takes the minimum value after comparison to avoid the field value from exceeding the reasonable range. At the same time, the router forwarding mechanism is triggered to forward the updated time data packet to the next-hop router. Other methods can be used in other embodiments, which are not limited here.
[0061] In addition, in specific implementation, if the current value is less than the waiting queue length of the corresponding router, it means that the time data packet has caused uncontrollable delay due to congestion. The program calls the router packet filtering interface to mark the time data packet as invalid and send it to the discard queue, and no further forwarding operation is performed. At the same time, log information such as the discard time, router port and the difference between the field and the queue length is recorded. Other methods can be used in other embodiments, which are not limited here.
[0062] In addition, in specific implementation, the current value after all routers have been updated is taken as the final value of the specific field, and the time data packet that has not been discarded by any router is taken as the valid synchronization data packet of the time data packet. That is, when the time data packet has been processed by all routers in sequence, if it has not been discarded by any router, it has successfully reached the receiving end (time server or electricity meter). After the receiving end confirms that the data packet has not been tampered with through message integrity verification, it reads the value of the specific field after all routers have been updated, and takes it as the final value of the specific field in the time data packet. At the same time, the receiving end marks the time data packet that has not been discarded and has passed the verification as a valid synchronization data packet. Other methods can be used in other embodiments, which are not limited here.
[0063] It should be noted that the current value in this application represents the real-time value of a specific field of the time packet extension as it passes through each router; the waiting queue length represents the number of packets waiting to be forwarded on the router's receiving port when the time packet arrives, directly reflecting the current port congestion level and data forwarding pressure of the corresponding router; the final value represents the value that the specific field is finally retained after being compared and updated by all relay routers, reflecting the overall minimum congestion level and link smoothness of the time packet transmission path; the effective synchronization packet represents the time packet that has passed the queue comparison of all relay routers, has not been dropped, and has finally successfully arrived at the receiving end and passed the integrity check, reflecting that it has not experienced excessive delay due to router congestion during transmission, and that the data transmission is complete and the delay characteristics are traceable.
[0064] In step 103, the asymmetry coefficient of the bidirectional transmission delay between the energy meter and the time server is determined by the effective synchronization data packet, the initial value, and the final value.
[0065] In some embodiments, reference Figure 2 As shown, this figure is an exemplary flowchart for determining the asymmetry coefficient in some embodiments of this application. In this embodiment, the asymmetry coefficient of the bidirectional transmission delay between the energy meter and the time server can be determined by the following steps using the effective synchronization data packet, the initial value, and the final value:
[0066] In step 1031, each key timestamp in the valid synchronization data packet is extracted;
[0067] In step 1032, the uplink and downlink transmission delays between the energy meter and the time server are determined based on all the key timestamps.
[0068] In step 1033, a queue length correction coefficient is determined based on the initial value and the final value for bidirectional transmission between the energy meter and the time server;
[0069] In step 1034, the asymmetry coefficient of the bidirectional transmission delay between the energy meter and the time server is determined by the uplink transmission delay, the downlink transmission delay, and the queue length correction coefficient.
[0070] In specific implementation, the key timestamps in the effective synchronization data packets are extracted, namely, the sending timestamp T_send of the time data packet generated by the local real-time clock of the energy meter, the receiving timestamp T_recv1 recorded when the time server network interface receives the time data packet, the sending timestamp T_send2 generated when the time server replies to the time data packet, and the receiving timestamp T_recv2 recorded when the energy meter receives the reply time data packet. During the extraction process, the hexadecimal data stored in the field is converted into microsecond-level integers through binary-to-decimal operations to ensure that the timestamp accuracy meets the clock calibration requirements. Other methods can also be used in other embodiments, which are not limited here.
[0071] In addition, in specific implementation, determining the uplink and downlink transmission delays between the energy meter and the time server based on all key timestamps can be achieved in the following way: The uplink transmission delay T_up = T_recv1 - T_send and the downlink transmission delay T_down = T_recv2 - T_send2 between the energy meter and the time server are calculated based on all key timestamps; the queue length correction coefficient for bidirectional transmission between the energy meter and the time server is determined based on the initial and final values, i.e., by performing a division operation using the initial value V0 and the final value Vf of a specific field in the time data packet, the queue length correction coefficient K = V0 / Vf is obtained; the asymmetry coefficient of the bidirectional transmission delay between the energy meter and the time server is determined using the uplink transmission delay, the downlink transmission delay, and the queue length correction coefficient, i.e., the asymmetry coefficient of the bidirectional transmission delay is finally calculated using the formula: asymmetry coefficient = (T_up / T_down) × K. Other methods can also be used in other embodiments, which are not limited here.
[0072] It should be noted that the key timestamps in this application refer to the four core time nodes recorded in the valid synchronization data packets, reflecting the key time node information of the data packets in the bidirectional transmission between the energy meter and the time server; the uplink transmission delay refers to the time taken for the energy meter to send a data packet to the time server to receive the data packet, reflecting the uplink transmission efficiency and instantaneous congestion of the energy meter to the time server; the downlink transmission delay refers to the time taken for the time server to send a reply data packet to the energy meter to receive the data packet, reflecting the downlink transmission efficiency and instantaneous congestion of the time server to the energy meter; the queue length correction coefficient reflects the difference between the preset congestion benchmark and the actual transmission path congestion level, and is used to correct the interference of router queue length changes on the bidirectional transmission delay calculation; the asymmetry coefficient is a parameter characterizing the difference in bidirectional transmission delay, reflecting the degree of delay asymmetry of the bidirectional transmission path between the energy meter and the time server.
[0073] In step 104, a clock drift prediction model for the electricity meter is constructed. The clock drift amount of the electricity meter is predicted based on the clock drift prediction model, the effective synchronization data packet, and the asymmetry coefficient. The local clock of the electricity meter is compensated and corrected in real time based on the clock drift amount.
[0074] In some embodiments, constructing the clock drift prediction model of the energy meter can be achieved by the following steps:
[0075] Acquire historical clock drift data, historical transmission delay data, historical waiting queue length data, and historical asymmetry coefficient of the energy meter under different ambient temperatures and cumulative operating times, and synchronously record the aging parameters of the crystal oscillator and network link stability data of the energy meter.
[0076] Based on the historical clock drift data, historical transmission delay data, historical waiting queue length data, historical asymmetry coefficient, aging parameters, and network link stability data, calculate the influence coefficient of temperature on clock drift, the attenuation coefficient of runtime on drift rate, the correction coefficient of queue length change on delay asymmetry, and the interaction effect of temperature-runtime and link stability-delay.
[0077] The clock drift prediction model of the energy meter is constructed using the influence coefficient, attenuation coefficient, correction coefficient, and interaction effect.
[0078] In practice, the frequency offset is calculated as an aging parameter by comparing the factory standard frequency of the crystal oscillator in the electricity meter with the current actual output frequency. Historical network link stability data, namely packet loss rate (in %) with a resolution of 0.01% and latency jitter (in μs with an accuracy of 0.1 μs), is obtained through the router port statistics function.
[0079] In addition, in specific implementation, using historical clock drift as the dependent variable and ambient temperature as the independent variable, a linear regression equation Δt=k_T×T×t+ε is fitted using the least squares method, where Δt is the clock drift, T is the ambient temperature, t is the running time, and ε is the error term. The influence coefficient k_T of temperature on clock drift is then obtained. Similarly, using cumulative running time as the independent variable and the change in drift rate as the dependent variable, an exponential fitting equation Δt_rate=Δt_rate0×e^(-λt) is fitted, where Δt_rate0 is the initial drift rate and λ is the decay coefficient. The effect of running time on drift rate is then obtained. The attenuation coefficient λ; using the ratio of the historical waiting queue length to the corresponding asymmetry coefficient as a sample, the correction coefficient K_q for the delay asymmetry caused by the change in queue length is calculated by the arithmetic mean method; using a two-way ANOVA method, with temperature and runtime as two independent variables and clock drift as the dependent variable, the interaction strength of the two on clock drift is analyzed to obtain the temperature-runtime interaction effect coefficient k_Tt; using link stability data and transmission delay as two independent variables and clock drift residual as the dependent variable, the same two-way ANOVA is used to obtain the link stability-delay interaction effect coefficient k_Ld.
[0080] In addition, in the specific implementation, an ARM adapter for the energy meter is selected. The lightweight support vector regression model of the Cortex-M series embedded processor is used as the core framework of the clock drift prediction model. The influence coefficient k_T, runtime attenuation coefficient λ, queue length correction coefficient K_q, and interaction effect coefficients k_Tt and k_Ld are used as the model input feature vectors, and the historical clock drift is used as the output label. The training set and test set are divided in a 7:3 ratio. The radial basis function kernel function is used to construct the nonlinear mapping relationship of the model. The combination of penalty parameter C and kernel function parameter γ is traversed by grid search method. Five-fold cross-validation is used to avoid model overfitting. The root mean square error (RMSE) of the test set is used as the evaluation index. The parameters are iteratively optimized until RMSE ≤ 0.05μs. Finally, the trained and optimized model is ported to the embedded system of the energy meter through C language. The operation logic embedded in the read-only memory realizes the real-time feature extraction of input parameters, kernel function calculation and prediction result output. The time consumption of a single model operation is controlled within 50ms, which meets the timing requirements of real-time clock compensation of the energy meter. Finally, the clock drift prediction model of the energy meter is obtained. Other methods can be used to construct it in other embodiments, which are not limited here.
[0081] It should be noted that the influence coefficient in this application is a parameter characterizing the quantitative correlation between ambient temperature and the clock drift of the electricity meter, reflecting the degree of linear influence of temperature change on clock drift; the attenuation coefficient is a quantitative parameter describing the attenuation of clock drift rate with the cumulative operating time of the equipment, reflecting the changing law of the gradual decrease in clock drift rate due to the aging of the crystal oscillator; the correction coefficient is a parameter calibrating the calculation deviation of the bidirectional transmission delay asymmetry caused by the change of router queue length, reflecting the correction magnitude of the delay calculation results under different queue congestion levels, and improving the accuracy of delay correlation data; the interaction effect is a quantitative index of the superposition effect of two related influencing factors, temperature and operating time, and network link stability and transmission delay, on clock drift, reflecting the degree of joint influence that cannot be independently characterized by a single factor; the clock drift prediction model reflects the dynamic mapping relationship between multiple dimensions such as ambient temperature, equipment operating time, crystal oscillator aging, and network link status and the clock drift of the electricity meter, providing a quantitative calculation framework for accurately predicting the clock drift in the current and future periods.
[0082] In some embodiments, reference Figure 3 As shown, this figure is an exemplary flowchart for determining the clock drift amount in some embodiments of this application. In this embodiment, the prediction of the clock drift amount of the energy meter based on the clock drift prediction model, the effective synchronization data packet, and the asymmetry coefficient can be achieved by the following steps:
[0083] In step 1041, the valid synchronization data packet and the asymmetry coefficient are input into the clock drift prediction model;
[0084] In step 1042, the clock drift of the energy meter is predicted using the clock drift prediction model.
[0085] In practice, the process begins by parsing valid synchronization data packets. The timestamps of the electricity meter's transmission, the time server's reception, the time server's reply, and the electricity meter's reception are extracted using a byte offset positioning method. Real-time uplink and downlink transmission delays are calculated using a difference calculation method. Simultaneously, the previously calculated and stored asymmetry coefficient of the bidirectional transmission delay is read. Meanwhile, the current ambient temperature is collected via the electricity meter's built-in temperature sensor, the device's cumulative runtime is read from the Flash storage unit, the current router queue length is obtained via the SNMP protocol, real-time aging parameters are obtained via the crystal oscillator frequency detection circuit, and current network link stability data is obtained via the router port statistics function. Subsequently, the collected parameters are preprocessed. Anomalies exceeding ±3 standard deviations are removed using the 3σ criterion. The processed real-time uplink / downlink transmission delays, asymmetry coefficients, current temperature, cumulative runtime, queue length, aging parameters, and link stability data are then processed according to a modulus. The model pre-orders the feature dimensions and constructs a 1×7 dimensional input feature vector to ensure that the feature order is consistent with that during model training. Normalization is then applied to map each parameter to the [0,1] interval using the maximum-minimum normalization formula: x_norm=(x-x_min) / (x_max-x_min), where x_min and x_max are the minimum and maximum values of each feature during model training. Next, the lightweight support vector regression clock drift prediction model embedded in read-only memory is invoked. First, the trained and optimized penalty parameter C, radial basis function kernel parameter γ, and support vector data are read from the model parameter storage area. The support vector regression operation logic is executed by the arithmetic logic unit of the embedded processor: first, the Euclidean distance between the input feature vector and each support vector is calculated; then, the radial basis function kernel value is obtained by substituting it into the formula K(x,x_i)=exp(-γ||x-x_i||²). Finally, the Lagrange multipliers α_i and α_i' obtained during model training are combined. And the bias term b, through the formula f(x)=Σ(α_i-α_i The initial clock drift prediction value is calculated using K(x,x_i)+b. Finally, the initial prediction value is denormalized (x=x_norm×(x_max-x_min)+x_min) to correct the result to the actual physical unit. At the same time, the difference between the prediction value and the historical prediction value is checked. If the difference is ≤0.1μs, the prediction value is considered valid. Finally, the value that passes the check is output as the current clock drift prediction value of the energy meter. Other methods can be used in other embodiments, which are not limited here.
[0086] It should be noted that the clock drift in this application represents the cumulative time deviation between the local real-time clock of the electricity meter and the standard time source when the local clock is running based on the built-in crystal oscillator. Its value can be positive or negative. A positive value indicates that the local clock is faster than the standard time, and a negative value indicates that the local clock is slower than the standard time. It reflects the timing accuracy of the electricity meter's clock system, and indirectly reflects the comprehensive impact of multiple factors such as ambient temperature fluctuations, crystal oscillator aging, cumulative equipment operating time, and asymmetric network bidirectional transmission latency on clock stability. It is a core quantitative indicator for determining whether the clock needs compensation and determining the amount of compensation. Its value is directly related to the clock synchronization accuracy, the timestamp accuracy of electricity metering data, and the reliability of functions such as remote meter reading and fee control execution.
[0087] In some embodiments, real-time compensation and correction of the local clock of the energy meter based on the clock drift amount can be achieved by the following steps:
[0088] The compensation amount of the local clock of the energy meter is determined based on the clock drift amount;
[0089] The local clock of the energy meter is compensated and corrected in real time based on the compensation amount.
[0090] In practice, the real-time clock drift Δt output by the clock drift prediction model is read through the ARM Cortex-M series embedded processor of the energy meter. A positive value of Δt indicates that the local real-time clock is ahead of the PTP / NTP standard time, and a negative value indicates that the local clock is behind. The compensation amount is calculated by combining the standard timing period (30.517578125μs / pulse) of the local real-time clock's built-in 32.768kHz crystal oscillator: when Δt is positive, the compensation amount is the number of oscillation pulses to be skipped, N=ceil(Δt / 30.517578125), where ceil is rounded up to ensure that the positive drift is completely offset; when Δt is negative, the compensation amount is the additional effective timing equivalent pulses to be added, N=ceil(|Δt| / 30.517578125), which is converted into the frequency fine-tuning value of the crystal oscillator. The fine-tuning step size is 0.1ppm, and the frequency correction is achieved by adjusting the capacitance of the adjustable capacitor array built into the oscillator.
[0091] In specific implementation, the control register and frequency divider module of the local real-time clock are accessed through the I2C bus communication protocol to start the clock calibration mode: For scenarios that need to skip pulses, the frequency divider is controlled by software logic to skip N oscillation pulses in one calibration cycle, which is equivalent to reducing the corresponding timing duration; For scenarios that need frequency fine-tuning, the capacitor array capacity is adjusted by writing the fine-tuning parameters into the local real-time clock frequency control register to increase the oscillation frequency, thereby increasing the number of effective timing pulses per unit time; After the compensation is executed, the standard timestamp in the latest effective synchronization data packet is immediately extracted and compared with the time after compensation of the local real-time clock to calculate the residual error Δt_res. If |Δt_res|≤0.05μs, the compensation is deemed qualified; otherwise, the above compensation process is repeated until the accuracy requirements are met, so as to achieve real-time accurate correction of the local clock. Other methods can also be used in other embodiments, which are not limited here.
[0092] It should be noted that the compensation amount in this application is a specific quantitative value used to correct the deviation between the local real-time clock of the energy meter and the PTP / NTP standard time. The unit is usually the number of oscillation pulses or the crystal oscillator frequency fine-tuning value. Its value is directly related to the clock drift. When the clock drift is positive, the compensation amount corresponds to the number of oscillation pulses that need to be skipped; when it is negative, it corresponds to the number of effective timing equivalent pulses or frequency fine-tuning parameters that need to be added. This parameter directly reflects the intensity of the correction requirement for the local clock to deviate from the standard time, and indirectly reflects the degree of influence of factors such as ambient temperature fluctuations and crystal oscillator aging on clock stability. It is the core intermediate parameter connecting the clock drift and the actual correction operation. Its rationality directly determines the accuracy of the compensation correction, and ultimately ensures the accuracy of the energy meter's timing and the reliability of its metering, remote meter reading, and other functions.
[0093] Furthermore, in another aspect of this application, in some embodiments, this application provides a clock drift compensation system for energy meters based on model predictive control, referencing... Figure 4 The figure is a schematic diagram of a model predictive control-based clock drift compensation system for an energy meter, according to some embodiments of this application. The model predictive control-based clock drift compensation system 400 includes: a data acquisition module 401, a processing module 402, and an execution module 403, which are described below:
[0094] The data acquisition module 401 in this application is mainly used to acquire time data packets transmitted bidirectionally between the energy meter and the time server.
[0095] Processing module 402, in this application, is used to set a specific field in the time data packet and assign an initial value. When the time data packet passes through each router, the current value of the specific field is compared with the waiting queue length of the router to obtain the valid synchronization data packet of the time data packet and the final value of the specific field.
[0096] It should be noted that the processing module 402 in this application is also used to determine the asymmetry coefficient of the bidirectional transmission delay between the energy meter and the time server through the effective synchronization data packet, the initial value and the final value;
[0097] The execution module 403 in this application is mainly used to construct a clock drift prediction model for the electricity meter, predict the clock drift amount of the electricity meter based on the clock drift prediction model, the effective synchronization data packet and the asymmetry coefficient, and perform real-time compensation and correction on the local clock of the electricity meter based on the clock drift amount.
[0098] In addition, this application also provides a computer device, the computer device including a memory and a processor, the memory storing code, the processor being configured to acquire the code and execute the above-described model predictive control-based clock drift compensation method for electricity meters.
[0099] In some embodiments, reference Figure 5 The figure is a schematic diagram of the structure of a computer device implementing a model predictive control-based clock drift compensation method for electricity meters according to some embodiments of this application. The model predictive control-based clock drift compensation method for electricity meters in the above embodiments can be implemented through... Figure 5 The computer device 500 shown is used to implement this, and the computer device 500 includes at least one processor 501, a communication bus 502, a memory 503, and at least one communication interface 504.
[0100] Processor 501 can be a general-purpose central processing unit (CPU) or an application-specific integrated circuit (ASIC).
[0101] The communication bus 502 can be used to transmit information between the aforementioned components.
[0102] Memory 503 may be a read-only memory (ROM) or other type of static storage device capable of storing static information and instructions, random access memory (RAM) or other type of dynamic storage device capable of storing information and instructions, or electrically erasable programmable read-only memory (EEPROM), compact disc read-only memory (CD-ROM) or other optical disc storage, optical disc storage (including compressed optical discs, laser discs, optical discs, digital versatile optical discs, Blu-ray discs, etc.), magnetic disks or other magnetic storage devices, or any other medium capable of carrying or storing desired program code in the form of instructions or data structures and accessible by a computer, but not limited thereto. Memory 503 may exist independently and be connected to processor 501 via communication bus 502. Memory 503 may also be integrated with processor 501.
[0103] The memory 503 stores program code for executing the scheme of this application, and its execution is controlled by the processor 501. The processor 501 executes the program code stored in the memory 503. The program code may include one or more software modules. The method used in the above embodiments can be implemented by the processor 501 and one or more software modules in the program code in the memory 503.
[0104] Communication interface 504 uses any transceiver-like device to communicate with other devices or communication networks, such as Ethernet, radio access network (RAN), wireless local area networks (WLAN), etc.
[0105] In a specific implementation, as one example, a computer device may include multiple processors, each of which may be a single-core (single-CPU) processor or a multi-core (multi-CPU) processor. Here, a processor may refer to one or more devices, circuits, and / or processing cores used to process data (e.g., computer program instructions).
[0106] The aforementioned computer device can be a general-purpose computer device or a special-purpose computer device. In specific implementations, the computer device can be a desktop computer, a portable computer, a network server, a handheld digital assistant (PDA), a mobile phone, a tablet computer, a wireless terminal device, a communication device, or an embedded device. This application does not limit the type of computer device.
[0107] In addition, this application also provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the above-described model predictive control-based clock drift compensation method for electricity meters.
[0108] Although preferred embodiments of this application have been described, those skilled in the art, upon learning the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments as well as all changes and modifications falling within the scope of this application.
[0109] Obviously, those skilled in the art can make various modifications and variations to this application without departing from the spirit and scope of this application. Therefore, if such modifications and variations fall within the scope of the claims of this application and their equivalents, this application also intends to include such modifications and variations.
Claims
1. A model predictive control based method for clock drift compensation of an electric energy meter, wherein, The electricity meter connects to a time server via various routers to achieve bidirectional transmission of time data between the electricity meter and the time server. The method is characterized by the following steps: Collect time data packets transmitted bidirectionally between the electricity meter and the time server; A specific field is set and assigned an initial value in the time data packet. When the time data packet passes through each router, the current value of the specific field is compared with the waiting queue length of the router to obtain the valid synchronization data packet of the time data packet and the final value of the specific field. The asymmetry coefficient of the bidirectional transmission delay between the energy meter and the time server is determined by the effective synchronization data packet, the initial value, and the final value. A clock drift prediction model for the electricity meter is constructed. The clock drift amount of the electricity meter is predicted based on the clock drift prediction model, the effective synchronization data packet, and the asymmetry coefficient. The local clock of the electricity meter is compensated and corrected in real time based on the clock drift amount. Specifically, determining the asymmetric coefficient of the bidirectional transmission delay between the energy meter and the time server using the effective synchronization data packet, the initial value, and the final value includes: Extract the key timestamps from the valid synchronization data packets; The uplink and downlink transmission delays between the energy meter and the time server are determined based on all key timestamps. The queue length correction coefficient for bidirectional transmission between the energy meter and the time server is determined based on the initial value and the final value. The asymmetry coefficient of the bidirectional transmission delay between the energy meter and the time server is determined by the uplink transmission delay, the downlink transmission delay, and the queue length correction coefficient. Among them, the asymmetry coefficient is a parameter that characterizes the difference in bidirectional transmission delay, reflecting the degree of delay asymmetry in the bidirectional transmission path between the energy meter and the time server. Specifically, constructing the clock drift prediction model for the electricity meter includes: Acquire historical clock drift data, historical transmission delay data, historical waiting queue length data, and historical asymmetry coefficient of the energy meter under different ambient temperatures and cumulative operating times, and synchronously record the aging parameters of the crystal oscillator and network link stability data of the energy meter. Based on the historical clock drift data, historical transmission delay data, historical waiting queue length data, historical asymmetry coefficient, aging parameters, and network link stability data, calculate the influence coefficient of temperature on clock drift, the attenuation coefficient of runtime on drift rate, the correction coefficient of queue length change on delay asymmetry, and the interaction effect of temperature-runtime and link stability-delay. The clock drift prediction model of the energy meter is constructed using the influence coefficient, attenuation coefficient, correction coefficient, and interaction effect. Among them, the clock drift prediction model reflects the dynamic mapping relationship between multiple factors such as ambient temperature, equipment operating time, crystal oscillator aging, and network link status and the amount of clock drift of the electricity meter.
2. The method of claim 1, wherein, The time data packet includes a protocol header, a unique data packet identifier ID, a timestamp of the electricity meter sending data, a timestamp of the time server receiving data, a timestamp of the time server replying to the sending data, a timestamp of the electricity meter receiving data, and an extended queue matching identifier field.
3. The method of claim 1, wherein, When the time data packet passes through each router, the current value of the specific field is compared with the router's waiting queue length to obtain the valid synchronization data packet of the time data packet and the final value of the specific field. Specifically, this includes: As the time data packet passes through each router in sequence, the current value of the specific field and the waiting queue length are obtained at each router; Compare each current value with the corresponding router's wait queue length; If the current value is greater than or equal to the waiting queue length of the corresponding router, then update the current value and time data packet and continue forwarding; If the current value is less than the waiting queue length of the corresponding router, the time data packet is marked as an invalid data packet and discarded directly; The current value after all router updates are completed is used as the final value of the specific field, and the time data packets that are not dropped by any router are used as the valid synchronization data packets of the time data packets.
4. The method of claim 1, wherein, Predicting the clock drift of the energy meter based on the clock drift prediction model, the effective synchronization data packet, and the asymmetry coefficient specifically includes: The valid synchronization data packet and the asymmetry coefficient are input into the clock drift prediction model; The clock drift of the electricity meter is predicted using the clock drift prediction model.
5. The method of claim 1, wherein, The real-time compensation and correction of the local clock of the energy meter based on the clock drift specifically includes: The compensation amount of the local clock of the energy meter is determined based on the clock drift amount; The local clock of the energy meter is compensated and corrected in real time based on the compensation amount.
6. A model predictive control based clock drift compensation system for an electric energy meter, which employs the method of any one of claims 1 to 5 for compensation, wherein, The electricity meter connects to a time server via various routers to achieve bidirectional transmission of time data between the electricity meter and the time server. The system is characterized by comprising: The data acquisition module is used to collect time data packets transmitted bidirectionally between the electricity meter and the time server. The processing module is used to set a specific field and assign an initial value to the time data packet. When the time data packet passes through each router, the current value of the specific field is compared with the waiting queue length of the router to obtain the valid synchronization data packet of the time data packet and the final value of the specific field. The processing module is further configured to determine the asymmetry coefficient of the bidirectional transmission delay between the energy meter and the time server through the effective synchronization data packet, the initial value, and the final value; The execution module is used to construct a clock drift prediction model for the electricity meter, predict the clock drift amount of the electricity meter based on the clock drift prediction model, the effective synchronization data packet and the asymmetry coefficient, and perform real-time compensation and correction on the local clock of the electricity meter based on the clock drift amount.
7. A computer device, comprising: The computer device includes a memory and a processor, the memory storing code, and the processor being configured to retrieve the code and execute the energy meter clock drift compensation method based on model predictive control as described in any one of claims 1 to 5.
8. A computer-readable storage medium storing a computer program, the computer-readable storage medium comprising: The computer program, when executed by the processor, implements the method for compensating clock drift of an electric energy meter based on model predictive control according to any one of claims 1 to 5.
Citation Information
Patent Citations
Signal transmission clock synchronization compensation method for four-break series circuit breaker
CN108418235A
Multi-modal error dynamic compensation method and system of intelligent electric meter
CN119757816A