Clock synchronization method, device and equipment of distributed system and storage medium

By constructing a local system clock copy and a reference clock in the slave device, calculating and compensating the clock synchronization deviation of the distributed system, the problem of insufficient clock synchronization accuracy and performance in the existing technology is solved, and more efficient clock synchronization is achieved.

CN118784137APending Publication Date: 2024-10-15SHENZHEN INVT ELECTRIC
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411031966.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-30
Publication Date
2024-10-15

AI Technical Summary

Technical Problem

Existing distributed system clock synchronization solutions have deficiencies in clock synchronization accuracy and performance. The accuracy of clock synchronization is not high and the synchronization performance is poor. This is mainly because the compensation deviation calculation depends on the arrival time of the data frame and the line transmission delay changes. Clock synchronization jitter is large.

Method used

Build a local system clock copy and a local system reference clock in the slave device, calculate the compensation deviation through the latch and reference clock of the current and historical clocks, and compensate within the synchronization period according to the compensation frequency and the preset compensation value to improve the clock Synchronization accuracy and performance.

Benefits of technology

By reducing the time deviation of the clock synchronization source, the accuracy of clock synchronization is improved, and the appropriate compensation frequency is used to ensure uniform and effective compensation, which improves synchronization performance and achieves more stable clock synchronization.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118784137A_ABST
    Figure CN118784137A_ABST
Patent Text Reader

Abstract

The invention discloses a clock synchronization method, device and equipment of a distributed system and a storage medium, and relates to the technical field of communication, the method is applied to slave station equipment, and the method comprises the following steps: acquiring a local system clock copy according to a local clock of the slave station equipment and system clock offset sent by master station equipment; according to the local system clock copy latches corresponding to the current system reference clock and the historical system reference clock and the local system reference clock, the compensation deviation of the current synchronization period is determined; compensating a local system clock in the current synchronization period according to a compensation frequency corresponding to the compensation deviation and a preset single compensation value; therefore, the local system clock copy and the local system reference clock which are built in the slave station equipment are utilized, the compensation deviation of each synchronization period can be accurately calculated, the clock synchronization precision is improved, compensation is performed according to the appropriate compensation frequency in each synchronization period, the compensation can be ensured to be uniform and effective, and the synchronization performance is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of communication technology, and in particular to a clock synchronization method, device, equipment and storage medium for a distributed system. Background Art

[0002] At present, in industrial control systems, multi-machine solutions not only require extremely low latency in the master-slave communication network, but also have high requirements for the synchronization performance of multiple machines. The most critical part of multi-machine synchronization is the distributed system clock synchronization; the stability of the distributed system clock directly affects the overall performance of the system. Therefore, the stability and consistency of the master and slave station time in the distributed system must be guaranteed.

[0003] In the prior art, for the clock synchronization scheme of distributed systems, most of them are that the slave device obtains the synchronization clock sent by the reference slave based on the master device, directly calculates the compensation deviation of the current synchronization cycle, and directly compensates the local clock. Although this scheme can simply and quickly complete the time synchronization of a single cycle, the compensation deviation is calculated according to the arrival time of the data frame of the synchronization clock, and the sending time of the data frame does not completely follow the change of the synchronization cycle, so that the time deviation may be particularly large, resulting in low accuracy of clock synchronization; secondly, because the line transmission delay will also change, the compensation deviation will change dramatically, the clock synchronization compensation DC (Distributed Clock) jitter is large, and the synchronization performance is poor. Therefore, how to improve the accuracy of clock synchronization and improve synchronization performance is an urgent problem to be solved today. Summary of the invention

[0004] The purpose of the present invention is to provide a clock synchronization method, device, electronic device and computer storage medium for a distributed system, so as to improve the accuracy of clock synchronization of the distributed system and enhance the synchronization performance.

[0005] In order to solve the above technical problems, the present invention provides a clock synchronization method for a distributed system, which is applied to a slave device, comprising:

[0006] Constructing a local system clock copy of the slave device according to the local clock of the slave device and the system clock offset sent by the master device;

[0007] According to the system reference clock sent by the clock synchronization source and the local system clock copy, the local system reference clock of the slave device is adjusted and updated to obtain a local system reference clock corresponding to the system reference clock;

[0008] Determine the compensation deviation of the current synchronization cycle according to the local system clock replica latch and the local system reference clock corresponding to the current system reference clock and the historical system reference clock, wherein the historical system reference clock is a system reference clock received before the current system reference clock;

[0009] The local system clock is compensated in the current synchronization period according to the compensation frequency corresponding to the compensation deviation and a preset single compensation value.

[0010] On the other hand, the local clock, the local system clock, and the system reference clock are all first number bits; adjusting and updating the local system reference clock of the slave device according to the system reference clock sent by the clock synchronization source and the local system clock copy to obtain the local system reference clock corresponding to the system reference clock includes:

[0011] According to the data of the second high number of bits of the local system clock copy and the data of the third low number of bits of the current system reference clock, the local system reference clock is adjusted and updated to obtain the local system reference clock corresponding to the current system reference clock; wherein the sum of the second number and the third number is the first number.

[0012] On the other hand, adjusting and updating the local system reference clock according to the data of the second high number of bits of the local system clock copy and the data of the third low number of bits of the current system reference clock to obtain the local system reference clock corresponding to the current system reference clock includes:

[0013] configuring the data of the second high number of bits of the local system reference clock as the data of the second high number of bits of the local system clock copy;

[0014] After receiving the current system reference clock, assign the data of the lower third number of bits of the local system reference clock to the lower third number of bits of the local system reference clock of the previous cycle, and configure the data of the lower third number of bits of the local system reference clock as the data of the lower third number of bits of the current system reference clock;

[0015] If the data of the third lower number of bits of the local system reference clock is less than the third lower number of bits of the local system reference clock of the previous cycle, the data of the second upper number of bits of the local system reference clock is increased by 1, and the processed local system reference clock is used as the local system reference clock corresponding to the current system reference clock;

[0016] If the data of the third lower number of bits of the local system reference clock is not less than the third lower number of bits of the local system reference clock of the previous cycle, the current local system reference clock is used as the local system reference clock corresponding to the current system reference clock.

[0017] On the other hand, the method of determining the compensation deviation of the current synchronization cycle according to the local system clock replica latch and the local system reference clock corresponding to the current system reference clock and the historical system reference clock respectively includes:

[0018] Obtaining a local system clock replica latch and a local system reference clock corresponding to a target historical system reference clock; wherein the target historical system reference clock is a system reference clock received at a preset interval time before the current system reference clock; the preset interval time is the product of a preset synchronization cycle time and a preset number of intervals;

[0019] Calculating a first deviation based on the local system clock replicas latched corresponding to the current system reference clock and the target historical system reference clock;

[0020] Calculating a second deviation according to local system reference clocks corresponding to the current system reference clock and the target historical system reference clock;

[0021] A compensation deviation of a current synchronization cycle is determined according to the first deviation and the second deviation.

[0022] On the other hand, determining the compensation deviation of the current synchronization cycle according to the first deviation and the second deviation includes:

[0023] If the clock synchronization count is greater than or equal to the times threshold, the difference between the second deviation and the first deviation is calculated to obtain the third deviation; if the clock synchronization count is greater than or equal to the preset compensation start value and less than the times threshold, the difference between the local system clock replica latch and the local system reference clock corresponding to the current system reference clock is calculated to obtain the third deviation; wherein the first deviation is the difference between the local system clock replica latch corresponding to the current system reference clock and the target historical system reference clock, and the second deviation is the difference between the local system reference clock corresponding to the current system reference clock and the target historical system reference clock;

[0024] Performing a mean filter with a preset width on the third deviation to obtain a filtered deviation;

[0025] The quotient of the filtered deviation and the preset interval number is calculated to obtain the compensation deviation of the current synchronization cycle.

[0026] On the other hand, the compensating the local system clock in the current synchronization period according to the compensation frequency corresponding to the compensation deviation and the preset single compensation value includes:

[0027] Determining the total amount of compensation for the current synchronization cycle according to a preset compensation threshold and the absolute value of the compensation deviation;

[0028] Calculate the quotient of the total step length and the compensation times threshold to obtain the single step length corresponding to the compensation frequency; wherein the total step length is the quotient of the preset synchronization cycle time and the counting cycle time of the time counter, and the compensation times threshold is the quotient of the total compensation amount and the preset single compensation value;

[0029] According to the clock count of the time counter, the single step length, the compensation times threshold and the preset single compensation value, the local clock is compensated at a compensation frequency corresponding to the single step length.

[0030] On the other hand, the compensating the local clock according to the compensation frequency corresponding to the single step length according to the clock count of the time counter, the single step length, the compensation number threshold and the preset single compensation value includes:

[0031] Starting the time counter and obtaining the current clock count of the time counter;

[0032] Determine whether the current clock count reaches the count threshold corresponding to the single step length;

[0033] If the counting threshold is reached, the time counter is cleared and the compensation count value is increased by 1 to obtain an updated compensation count value;

[0034] If the updated compensation count value is not greater than the compensation count threshold, then when the compensation deviation is a negative number, the preset single compensation value is added to the local clock, and the step of obtaining the current clock count of the time counter is performed; when the compensation deviation is a positive number, the preset single compensation value is subtracted from the local clock, and the step of obtaining the current clock count of the time counter is performed;

[0035] If the updated compensation count value is greater than the compensation times threshold, the compensation count value is cleared and the time counter is closed.

[0036] The present invention also provides a clock synchronization device for a distributed system, which is arranged in a slave station device and includes:

[0037] A local construction module, used to construct a local system clock copy of the slave device according to the local clock of the slave device and the system clock offset sent by the master device;

[0038] A reference adjustment module, configured to adjust and update the local system reference clock of the slave device according to the system reference clock sent by the clock synchronization source and the local system clock copy, so as to obtain a local system reference clock corresponding to the system reference clock;

[0039] A deviation determination module, used to determine the compensation deviation of the current synchronization cycle according to the local system clock replica latch and the local system reference clock corresponding to the current system reference clock and the historical system reference clock respectively; wherein the historical system reference clock is a system reference clock received before the current system reference clock;

[0040] The deviation compensation module is used to compensate the local system clock in the current synchronization period according to the compensation frequency corresponding to the compensation deviation and a preset single compensation value.

[0041] The present invention also provides an electronic device, comprising:

[0042] Memory for storing computer programs;

[0043] A processor is used to implement the steps of the clock synchronization method of the distributed system as described above when executing the computer program.

[0044] In addition, the present invention also provides a computer storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the clock synchronization method for a distributed system as described above are implemented.

[0045] A clock synchronization method for a distributed system provided by the present invention is applied to a slave device, comprising: constructing a local system clock replica of the slave device according to the local clock of the slave device and the system clock offset sent by the master device; adjusting and updating the local system reference clock of the slave device according to the system reference clock and the local system clock replica sent by the clock synchronization source to obtain a local system reference clock corresponding to the system reference clock; determining a compensation deviation of a current synchronization cycle according to the local system clock replica latch and the local system reference clock corresponding to the current system reference clock and the historical system reference clock respectively; wherein the historical system reference clock is a system reference clock received before the current system reference clock; and compensating the local system clock in the current synchronization cycle according to the compensation frequency corresponding to the compensation deviation and a preset single compensation value;

[0046] It can be seen that the present invention, by constructing a local system clock replica and a local system reference clock inside the slave station device, can use the latest local system clock replica latch and local system reference clock of the current synchronization period and the previous local system clock replica latch and local system reference clock to determine the compensation deviation of the current synchronization period, thereby reducing the time deviation of the synchronization clock source and improving the accuracy of clock synchronization; and can determine the appropriate compensation frequency according to the size of the compensation deviation, compensate the local system clock in the current synchronization period, ensure that the compensation is uniform and effective, and improve the synchronization performance. In addition, the present invention also provides a clock synchronization device, electronic device and computer storage medium for a distributed system, which also have the above-mentioned beneficial effects. BRIEF DESCRIPTION OF THE DRAWINGS

[0047] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying creative work.

[0048] Figure 1 A flowchart of a clock synchronization method for a distributed system provided by an embodiment of the present invention;

[0049] Figure 2 A schematic diagram of a configuration process of a distributed system provided by an embodiment of the present invention;

[0050] Figure 3 A schematic diagram of a construction process of a local system clock replica and a local system reference clock provided by an embodiment of the present invention;

[0051] Figure 4 A schematic diagram of a calculation flow of compensating deviation provided by an embodiment of the present invention;

[0052] Figure 5 A schematic diagram of a process of local clock compensation provided by an embodiment of the present invention;

[0053] Figure 6 A structural block diagram of a clock synchronization device for a distributed system provided by an embodiment of the present invention;

[0054] Figure 7 The present invention is a schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0055] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0056] Please refer to Figure 1 , Figure 1 A flowchart of a clock synchronization method for a distributed system provided by an embodiment of the present invention. The method is applied to a slave device and may include:

[0057] Step 101: Construct a local system clock copy of the slave device according to the local clock of the slave device and the system clock offset sent by the master device.

[0058] Among them, the slave device in this embodiment can be a device acting as a slave in a distributed system, and the master device can be a device acting as a master in a distributed system; the master device and the slave device can communicate with each other through a network clock synchronization protocol, such as the master device and the slave device can communicate with each other through the IEEE1588 (a network clock synchronization protocol running on Ethernet) protocol, that is, the distributed system can be a distributed system based on the IEEE1588 protocol; for example, EtherCAT (Ethernet control automation technology) can be used to communicate between the master device and the slave device.

[0059] Correspondingly, in this embodiment, the local clock of the slave device (t local ) can be the local clock time of the slave device. For example, after the slave device is powered on and the local phase-locked loop is stable, the local clock counter can be used to count and accumulate according to the phase-locked loop to obtain the local clock. The system clock offset in this embodiment can be the system time offset value sent by the master device; such as the system clock offset sent by the master device in the INIT (initialization) phase of EtherCAT communication; accordingly, after receiving the system clock offset sent by the master device, the slave device can set a completion clock offset correction flag; according to the completion clock offset correction flag, a local system clock copy of the slave device is constructed; that is, by setting the completion clock offset correction flag, the construction process of the local system clock copy is triggered, so that the local system clock copy can be obtained.

[0060] It is understood that the slave device can use the local clock (t local ) and system clock offset (t SysOffset ), build a copy of the local system clock of the slave device (t Local_SysTime_Copy ), such as the local system clock copy tLocal_SysTime_Copy =t local + t SysOffset .

[0061] Correspondingly, the method provided in this embodiment may also include a configuration process of a distributed system. The specific configuration process of the distributed system is not limited in this embodiment, and may be implemented in the same or similar manner as the configuration method of a distributed system in the related art. For example, the EtherCAT communication between the master station device and the slave station device may be used. Figure 2 As shown in the figure, when the distributed system is powered on or reconfigured, it can be forced to enter the INIT stage; in the INIT stage, the master station first clears all register groups of FMMU (Fieldbus Memory Management Unit) and SM (SyncManager), reads ESC (EtherCAT slave controller) information and DL (Datalink) information, and obtains the link status topology of the slave devices in the system; then issues a time measurement instruction, reads port 0 / 1 of each slave device and obtains the time when the processing unit of each slave device receives the data frame, so as to obtain the system time offset and system time delay, and start the subsequent clock synchronization, as shown in the figure. Figure 2 During the INIT phase 3 in the process, the master device can broadcast the BWR command to write the address 0x0900 of each slave port to latch the local clock of each port of the slave device receiving the data frame. At this time, the slave device can set the configuration system flag to indicate system reconfiguration and clear the respective system time-related registers (such as the local system reference clock). During the INIT phase 4, the master device writes the system clock offset to each slave device to correct the slave clock offset. At this time, the slave device can set the clock offset correction completion flag to trigger the construction of the local system reference clock.

[0062] Accordingly, in the Pre-OP (pre-operation) stage, the master device can first set the PDO (process data object) object index of SM2 and SM3, then set the operation mode to the periodic synchronization mode, and perform SYNC (digital output signal of the distributed clock) signal output settings, such as the synchronization period (i.e., the preset synchronization period) and Sync_Start_Time (synchronization start time); accordingly, each slave device can start to send a DC signal after receiving the synchronization period and Start Time; at this point, the configuration process of the distributed system in this embodiment mainly involves the INIT stage and Pre-OP stage of EtherCAT communication, and the processing process of the Safe-OP (safe operation) and OP (operation) stages is similar to the processing process in the relevant EtherCAT communication technology, which will not be repeated here.

[0063] Step 102: According to the system reference clock sent by the clock synchronization source and the local system clock copy, the local system reference clock of the slave device is adjusted and updated to obtain a local system reference clock corresponding to the system reference clock.

[0064] The clock synchronization source in this embodiment may be a designated clock source in the distributed system, such as a master station device or a slave station device. In this step, the slave station device may construct or adjust and update the local system reference clock (i.e., the local system reference clock) of the slave station device according to the system reference clock sent by the clock synchronization source and the local system clock copy, and obtain the local system reference clock corresponding to each system reference clock.

[0065] Among them, for the system reference clock and the local system clock copy sent by the clock synchronization source in this step, the local system reference clock of the slave device is adjusted and updated to obtain the specific method of the local system reference clock corresponding to the system reference clock. The specific method can be set by the designer according to the practical scenario and user needs, such as the local clock (t Local ), local system clock (t Local_SysTime ) and the system reference clock are both the first number of bits (such as 64 bits), according to the local system clock copy (t Local_SysTime_Copy ) and the lower third number (such as 32 bits) of data of the current system reference clock are used to adjust and update the local system reference clock to obtain a local system reference clock corresponding to the current system reference clock; wherein the sum of the second number and the third number is the first number.

[0066] For example, in some embodiments, the slave station device can directly configure the data of the upper second number of bits of the local system reference clock as the data of the upper second number of bits of the local system clock copy, and configure the data of the lower third number of bits of the local system reference clock as the data of the lower third number of bits of the current system reference clock. In order to ensure the accuracy of the local system reference clock, in other embodiments, the slave station device may configure the data of the second high digit of the local system reference clock as the data of the second high digit of the local system clock copy; after receiving the current system reference clock, assign the data of the third low digit of the local system reference clock to the third low digit of the local system reference clock of the previous cycle, and configure the data of the third low digit of the local system reference clock as the data of the third low digit of the current system reference clock; if the data of the third low digit of the local system reference clock is less than the third low digit of the local system reference clock of the previous cycle, then the data of the second high digit of the local system reference clock is increased by 1, and the processed local system reference clock is used as the local system reference clock corresponding to the current system reference clock; if the data of the third low digit of the local system reference clock is not less than the third low digit of the local system reference clock of the previous cycle, then the current local system reference clock is used as the local system reference clock corresponding to the current system reference clock.

[0067] Correspondingly, this embodiment does not limit the specific values ​​of the first number, the second number, and the third number. For example, the values ​​of the second number and the third number can be the same, such as the first number is 64, and the second number and the third number are both 32. For example, Figure 3 As shown, the 64-bit local system reference clock (t Local_SysRefTime ) can be divided into the high 32-bit local system reference clock (t Local_SysRefTime_H ) and the lower 32-bit local system reference clock (t Local_SysRefTime_L ) store the high 32 bits and low 32 bits of the local system reference clock respectively; when the clock offset correction completion flag is detected (such as the clock offset correction completion flag is set), it can represent the 64-bit local system clock copy (t Local_SysTime_Copy ) is valid, the high 32-bit data of the local system clock copy can be assigned to the high 32-bit local system reference clock; when the slave device receives the data frame carrying the system reference clock sent by the clock synchronization source, it saves the system reference clock in the frame data and sets the reference clock valid flag; when the reference clock valid flag is detected (such as the reference clock valid flag is set), the low 32-bit local system reference clock can be assigned to the low 32-bit local system reference clock of the previous cycle (t Local_SysRefTime_LastBuf), and then assign the lower 32 bits of the 64-bit system reference clock to the lower 32-bit local system reference clock; compare the current lower 32-bit local system reference clock with the lower 32-bit local system reference clock of the previous cycle (that is, the lower 32-bit local system reference clock of the previous cycle). If t Local_SysRefTime_L > t Local_SysRefTime_LastBuf , it means that the lower 32 bits of the original 64-bit local system clock need to overflow and carry, and t Local_SysRefTime_H Perform addition processing.

[0068] Accordingly, when the slave device detects the configuration system flag (i.e., the configuration system flag is valid), it can determine that the system has been reconfigured or powered on, and can reset the registers used to store the second high number of bits of the local system reference clock, the third low number of bits of the local system reference clock, and the third low number of bits of the local system reference clock of the previous cycle, respectively. Figure 3 The dashed box in the middle Local_SysRefTime_H ,t Local_SysRefTime_L and t Local_SysRefTime_LastBuf These registers are reset to complete the construction of the first number of bits of the local system reference clock.

[0069] Step 103: Determine the compensation deviation of the current synchronization cycle according to the local system clock replica latch and the local system reference clock corresponding to the current system reference clock and the historical system reference clock, wherein the historical system reference clock is the system reference clock received before the current system reference clock.

[0070] It can be understood that the current system reference clock in this embodiment can be the currently received system reference clock, and the current synchronization cycle can be the synchronization cycle corresponding to the current system reference clock, that is, the preset synchronization cycle time after receiving the current system reference clock; that is, the interval time of the system reference clock sent by the clock synchronization source can be the preset synchronization cycle time, so as to trigger the time synchronization of each slave device by sending the system reference clock.

[0071] Correspondingly, the specific method for the slave device to determine the compensation deviation of the current synchronization cycle according to the local system clock replica latch and the local system reference clock corresponding to the current system reference clock and the historical system reference clock in this step can be set by the designer. For example, the slave device can determine the compensation deviation of the current synchronization cycle according to the local system clock replica latch and the local system reference clock corresponding to the current system reference clock and a historical system reference clock (such as the target historical system reference clock); wherein the target historical system reference clock can be a system reference clock received at a preset interval time before the current system reference clock, and the preset interval time is the product of the preset synchronization cycle time and the preset number of intervals. The slave device can determine the compensation deviation of the current synchronization cycle according to the local system clock replica latch and the local system reference clock corresponding to the current system reference clock and multiple historical system reference clocks. This embodiment does not impose any restrictions on this.

[0072] For example, the slave device can obtain the local system clock replica latch and the local system reference clock corresponding to the target historical system reference clock; calculate the first deviation based on the local system clock replica latch corresponding to the current system reference clock and the target historical system reference clock; calculate the second deviation based on the local system reference clock corresponding to the current system reference clock and the target historical system reference clock; determine the compensation deviation of the current synchronization cycle based on the first deviation and the second deviation.

[0073] Correspondingly, in order to facilitate the latching of the local system clock copy corresponding to the target historical system reference clock and the acquisition of the local system reference clock, in this embodiment, two depths can be set to preset interval times (such as Figure 4 2 of 2 N ), and the width of each FIFO (first-in-first-out queue) is a first number (such as 64) bits. That is to say, the above process of obtaining the local system clock replica latch and the local system reference clock corresponding to the target historical system reference clock may include: storing the local system clock replica latch corresponding to the current system reference clock into the first FIFO, and obtaining the local system clock replica latch corresponding to the target historical system reference clock output by the first FIFO; storing the local system reference clock corresponding to the current system reference clock into the second FIFO, and obtaining the local system reference clock corresponding to the target historical system reference clock output by the second FIFO; wherein the depth of the first FIFO and the second FIFO are both preset interval times, and the width is the first number of bits.

[0074] like Figure 4As shown in the figure, when the slave device receives a data frame carrying the system reference clock sent by the clock synchronization source, it saves the system reference clock in the frame data and sets the reference clock valid flag; at the SOF (start of frame) moment when the data frame arrives, it can latch the local system clock copy (t Local_SysTime_Copy ), only when the reference clock valid flag is detected, SOF is determined to be valid, and the latched local system clock replica amplitude can be changed to latched local system clock replica (t local_sysTime_Copy_Lock After the reference clock valid flag is valid through the beat, the slave device can local_sysTime_Copy_Lock and the local system reference clock (t Local_SysRefTime ) are stored in their respective corresponding FIFOs (i.e. the first FIFO and the second FIFO), and the two FIFOs will output 2 N The local system clock copy corresponding to the target historical system reference clock stored before (i.e., the preset interval number) is latched and stored in the corresponding register with the local system reference clock, such as t local_sysTime_Copy_Lock_Buf and t Local_SysRefTime_Buf .

[0075] Accordingly, this embodiment does not limit the calculation method of the first deviation and the second deviation. For example, the first deviation (t Bias_LocalSysTime_Copy ) can be the difference between the local system clock replica latches corresponding to the current system reference clock and the target historical system reference clock, that is, t Bias_LocalSysTime_Copy = t local_sysTime_Copy_Lock -t local_sysTime_Copy_Lock_Buf ; Second deviation (t Bias_LocalSysRefTime ) is the difference between the local system reference clock corresponding to the current system reference clock and the target historical system reference clock, that is, t Bias_LocalSysRefTime = t Local_SysRefTime -t Local_SysRefTime_Buf Alternatively, the first deviation may be the difference between the local system clock replicas corresponding to the target historical system reference clock and the current system reference clock; the second deviation may be the difference between the local system reference clocks corresponding to the target historical system reference clock and the current system reference clock.

[0076] Among them, the specific method for determining the compensation deviation of the current synchronization cycle based on the first deviation and the second deviation can be set by the designer. For example, the slave device can directly calculate the difference between the local system clock copy latch and the local system reference clock corresponding to the current system reference clock to obtain the third deviation; calculate the quotient of the third deviation and the preset interval number to obtain the compensation deviation of the current synchronization cycle.

[0077] Furthermore, in order to improve the accuracy of determining the compensation deviation, the slave device may N+1), calculate the difference between the second deviation and the first deviation to obtain the third deviation; when the clock synchronization times count is greater than or equal to the preset compensation start value and less than the times threshold, calculate the difference between the local system clock replica latch corresponding to the current system reference clock and the local system reference clock to obtain the third deviation; wherein the first deviation is the difference between the local system clock replica latch corresponding to the current system reference clock and the target historical system reference clock, and the second deviation is the difference between the local system reference clock corresponding to the current system reference clock and the target historical system reference clock; perform a mean filter with a preset width on the third deviation to obtain a filtered deviation; calculate the quotient of the filtered deviation and the preset interval times to obtain the compensation deviation of the current synchronization period.

[0078] That is to say, after the reference clock valid flag is valid through the beat, the slave device can count the clock synchronization times (counter) +1, and calculate the third deviation (t Bias ); if the number threshold is 2 N +1, the preset compensation start value is 2, t Bias_LocalSysTime_Copy = t local_sysTime_Copy_Lock -t local_sysTime_Copy_Lock_Buf , t Bias_LocalSysRefTime = t Local_SysRefTime -t Local_SysRefTime_Buf In the case of 2<= counter <2 N + 1, t Bias = t local_sysTime_Copy_Lock -t Local_SysRefTime ; When counter >=2 N + 1, t Bias = t Bias_LocalSysRefTime -t Bias_LocalSysTime ; The third deviation (t Bias ) can represent the deviation between two different times within the time period t, and the sign can represent the direction of compensation; accordingly, when counter <2, the present process can be terminated or the next reference clock can be waited for, so as to avoid erroneous compensation caused by inaccurate calculation of the third deviation when the clock synchronization times count does not reach the preset compensation start value by setting a preset compensation start value greater than 1 (such as 2).

[0079] Accordingly, after obtaining the third deviation of the current synchronization period, a mean filter with a preset width can be performed to eliminate the t Bias Jitter, get the deviation after filtering t Bias_average , in order to improve the accuracy of clock synchronization; because, after filtering, the deviation t Bias_average is the deviation in the time period t, so it is also necessary to pass t bias_final =tBias_average >>> N, get the compensation deviation t of the current synchronization cycle bias_final , that is, t bias_final = t Bias_average / 2 N .

[0080] Step 104: Compensate the local system clock in the current synchronization period according to the compensation frequency corresponding to the compensation deviation and the preset single compensation value.

[0081] Among them, the compensation frequency in this step can be the frequency of compensating the local system clock in the current synchronization cycle, and the preset single compensation value can be the preset compensation amount for each compensation in the current synchronization cycle, such as the preset single compensation value can be a positive integer greater than or equal to 1.

[0082] It should be noted that the specific method of compensating the local system clock in the current synchronization cycle according to the compensation frequency corresponding to the compensation deviation and the preset single compensation value in this step can be set by the designer. For example, in order to ensure the balance of multiple clock synchronizations, the compensation deviation can be limited in this embodiment; for example, in this step, the slave station device can determine the total compensation amount of the current synchronization cycle according to the preset compensation threshold and the absolute value of the compensation deviation; calculate the quotient of the total step length and the compensation number threshold to obtain the single step length corresponding to the compensation frequency; wherein the total step length is the quotient of the preset synchronization cycle time and the counting cycle time of the time counter, and the compensation number threshold is the quotient of the total compensation amount and the preset single compensation value; according to the clock count of the time counter, the single step length, the compensation number threshold and the preset single compensation value, the local clock is compensated according to the compensation frequency corresponding to the single step length, so that the total compensation value of the compensation is the total compensation amount.

[0083] For example, if Figure 5 As shown, when the compensation deviation (t bias_final ) is less than the preset compensation threshold (t max ) The absolute value of the compensation deviation can be used as the total compensation amount (t fianl ); When the absolute value of the compensation deviation is greater than or equal to the preset compensation threshold, the preset compensation threshold can be used as the total compensation amount. According to the preset synchronization cycle time (T) and the counting cycle time of the time counter (t pll ), the total step length can be calculated, that is, M = T / t pll ; Based on the total step length and the total amount of compensation, the single step length (K) can be calculated, that is, K = M / t fianl .

[0084] Correspondingly, this embodiment does not limit the specific numerical value of the preset single compensation value, that is, it does not limit the compensation amount corresponding to each single step. For example, the preset single compensation value can be 1, that is, the above-mentioned compensation number threshold can be the total compensation amount; the preset single compensation value can also be a positive integer greater than 1. For example, when the preset single compensation value is 2, the above-mentioned compensation number threshold can be half of the total compensation amount.

[0085] Accordingly, this embodiment does not limit the compensation method for compensating the local system clock, such as directly compensating the local system clock; or compensating the local system clock by compensating the local clock of the slave device. For example, the process of compensating the local clock according to the compensation frequency corresponding to the single step length according to the clock count, single step length, compensation times threshold and preset single compensation value of the time counter may include: starting the time counter and obtaining the current clock count of the time counter; judging whether the current clock count reaches the counting threshold corresponding to the single step length (such as single step length or single step length-1); if the counting threshold is reached, the time counter is cleared, and the compensation count value is increased by 1 to obtain the updated compensation count value; if the updated compensation count value is not greater than the compensation times threshold, when the compensation deviation is a negative number, the local clock is added with the preset single compensation value, and the above step of obtaining the current clock count of the time counter is executed; when the compensation deviation is a positive number, the local clock is subtracted from the preset single compensation value, and the above step of obtaining the current clock count of the time counter is executed; if the updated compensation count value is greater than the compensation times threshold, the compensation count value is cleared and the time counter is closed.

[0086] like Figure 5 As shown, the preset single compensation value can be 1. When the counting threshold is single step length -1, the slave device can use the clock count (Z) of the time counter and the single step length (K) for continuous comparison; when Z < K-1, the time counter continues to count the clock; when Z=K-1, the clock count of the time counter is reset to zero, restarts, and outputs a valid signal, adding 1 to the compensation count (P); when the compensation count P < t fianl (total compensation amount, i.e. compensation times threshold), outputs a compensation flag, making the local clock t local The value is increased by 1 or -1, such as in the compensation deviation t bias_final (or the third deviation t Bias ) is a negative number, let the local clock t local The value of is increased by 1; when compensating for the deviation t bias_final (or the third deviation t Bias ) is a positive number, let the local clock t local The value of is reduced by 1; when P = t fianl When t is reached, the compensation of the current synchronization cycle is completed, the last compensation flag is output, and then the next synchronization cycle t is waited. fianlThe value is updated and compensation is started again. After multiple synchronization cycles of continuous compensation, the local system clock compensation of the slave device can be completed.

[0087] That is to say, when the preset single compensation value can be 1 and the counting threshold is the single step length -1, the above process of compensating the local clock according to the compensation frequency corresponding to the single step length according to the clock count, single step length, compensation times threshold and preset single compensation value of the time counter can include: starting the time counter and obtaining the current clock count of the time counter; judging whether the current clock count reaches the difference between the single step length and 1 (i.e., the counting threshold); if it reaches the difference between the single step length and 1, clearing the time counter and adding 1 to the compensation count value to obtain an updated compensation count value; if the updated compensation count value is not greater than the total compensation amount (i.e., the compensation times threshold), when the compensation deviation is a negative number, the local clock is increased by 1 and the step of obtaining the current clock count of the time counter is executed; when the compensation deviation is a positive number, the local clock is decreased by 1 and the step of obtaining the current clock count of the time counter is executed; if the updated compensation count value is greater than the total compensation amount (i.e., the compensation times threshold), the compensation count value is cleared and the time counter is closed.

[0088] Among them, this embodiment is demonstrated by taking the clock synchronization of a slave device in a distributed system as an example, that is, each slave device in the distributed system can use the method provided by this embodiment to supplement and adjust its own local system clock, so that all slave devices in the entire distributed system can operate according to the same system clock. Through experimental measurement, the method provided by this embodiment can ensure that the DC jitter of all slave devices in the distributed system is at the ns (nanosecond) level, thereby ensuring the synchronization performance of the system.

[0089] In this embodiment, the embodiment of the present invention constructs a local system clock replica and a local system reference clock inside the slave station device, and can use the latest local system clock replica latch and local system reference clock of the current synchronization cycle and the previous local system clock replica latch and local system reference clock to determine the compensation deviation of the current synchronization cycle, thereby reducing the time deviation of the synchronization clock source and improving the accuracy of clock synchronization; and can determine the appropriate compensation frequency according to the size of the compensation deviation, compensate the local system clock in the current synchronization cycle, ensure that the compensation is uniform and effective, and improve the synchronization performance.

[0090] Corresponding to the above method embodiment, an embodiment of the present invention further provides a clock synchronization device for a distributed system. The clock synchronization device for a distributed system described below and the clock synchronization method for a distributed system described above can refer to each other.

[0091] Please refer to Figure 6 , Figure 6This is a structural block diagram of a clock synchronization device for a distributed system provided by an embodiment of the present invention. The device is arranged in a slave station device and may include:

[0092] A local construction module 10, configured to construct a local system clock copy of the slave device according to the local clock of the slave device and the system clock offset sent by the master device;

[0093] A reference adjustment module 20, configured to adjust and update the local system reference clock of the slave device according to the system reference clock sent by the clock synchronization source and the local system clock copy, to obtain a local system reference clock corresponding to the system reference clock;

[0094] The deviation determination module 30 is used to determine the compensation deviation of the current synchronization cycle according to the local system clock replica latch and the local system reference clock corresponding to the current system reference clock and the historical system reference clock, wherein the historical system reference clock is a system reference clock received before the current system reference clock;

[0095] The deviation compensation module 40 is used to compensate the local system clock in the current synchronization period according to the compensation frequency corresponding to the compensation deviation and the preset single compensation value.

[0096] On the other hand, the local clock, the local system clock and the system reference clock are all first quantity bits, and the reference adjustment module 20 can be specifically used to adjust and update the local system reference clock according to the data of the high second quantity bits of the local system clock copy and the data of the low third quantity bits of the current system reference clock to obtain the local system reference clock corresponding to the current system reference clock; wherein the sum of the second quantity and the third quantity is the first quantity.

[0097] In some embodiments, the reference adjustment module 20 may include:

[0098] A high bit setting submodule, used for configuring the data of the second high number of bits of the local system reference clock as the data of the second high number of bits of the local system clock replica;

[0099] A low bit setting submodule is used to assign the data of the lower third number of bits of the local system reference clock to the lower third number of bits of the local system reference clock of the previous cycle after receiving the current system reference clock, and configure the data of the lower third number of bits of the local system reference clock to the data of the lower third number of bits of the current system reference clock;

[0100] The adjustment setting submodule is used to increase the data of the second high digit of the local system reference clock by 1 if the data of the third low digit of the local system reference clock is less than the third low digit of the local system reference clock in the previous cycle, and use the processed local system reference clock as the local system reference clock corresponding to the current system reference clock; if the data of the third low digit of the local system reference clock is not less than the third low digit of the local system reference clock in the previous cycle, then use the current local system reference clock as the local system reference clock corresponding to the current system reference clock.

[0101] In some embodiments, the first number is 64, and the second number and the third number are both 32.

[0102] In some embodiments, the deviation determination module 30 may include:

[0103] A target acquisition submodule is used to acquire a local system clock replica latch and a local system reference clock corresponding to a target historical system reference clock; wherein the target historical system reference clock is a system reference clock received at a preset interval time before the current system reference clock; the preset interval time is the product of a preset synchronization cycle time and a preset number of intervals;

[0104] A first calculation submodule, configured to calculate a first deviation according to the local system clock replica latches corresponding to the current system reference clock and the target historical system reference clock;

[0105] A second calculation submodule, configured to calculate a second deviation according to local system reference clocks corresponding to the current system reference clock and the target historical system reference clock;

[0106] The deviation determination submodule is used to determine the compensation deviation of the current synchronization period according to the first deviation and the second deviation.

[0107] In some embodiments, the deviation determination submodule may include:

[0108] A classification calculation unit, configured to calculate the difference between the second deviation and the first deviation to obtain a third deviation if the clock synchronization count is greater than or equal to a times threshold; and to calculate the difference between the local system clock replica latch corresponding to the current system reference clock and the local system reference clock to obtain a third deviation if the clock synchronization count is greater than or equal to a preset compensation start value and less than the times threshold; wherein the first deviation is the difference between the local system clock replica latch corresponding to the current system reference clock and the target historical system reference clock, and the second deviation is the difference between the local system reference clock corresponding to the current system reference clock and the target historical system reference clock;

[0109] A mean filtering unit, used for performing a mean filtering of a preset width on the third deviation to obtain a filtered deviation;

[0110] The deviation calculation unit is used to calculate the quotient of the filtered deviation and the preset interval number to obtain the compensation deviation of the current synchronization cycle.

[0111] In some embodiments, the target acquisition submodule may include:

[0112] A first storage unit is used to latch and store a local system clock replica corresponding to a current system reference clock into a first FIFO, and obtain a local system clock replica latch corresponding to a target historical system reference clock output by the first FIFO;

[0113] The second storage unit is used to store the local system reference clock corresponding to the current system reference clock into the second FIFO, and obtain the local system reference clock corresponding to the target historical system reference clock output by the second FIFO; wherein the depth of the first FIFO and the second FIFO are both 2 N , the width is the first number of digits, and the preset interval number is 2 N .

[0114] In some embodiments, the local building block 10 may include:

[0115] The offset receiving submodule is used to receive the system clock offset sent by the master device during the initialization phase of EtherCAT communication and set a clock offset correction completion flag;

[0116] The building submodule is used to build a local system clock copy of the slave device according to the completion flag of clock offset correction.

[0117] In some embodiments, the deviation compensation module 40 may include:

[0118] A limit submodule, used to determine the total amount of compensation in the current synchronization cycle according to a preset compensation threshold and an absolute value of a compensation deviation;

[0119] The step length calculation submodule is used to calculate the quotient of the total step length and the compensation number threshold to obtain the single step length corresponding to the compensation frequency; wherein the total step length is the quotient of the preset synchronization cycle time and the counting cycle time of the time counter, and the compensation number threshold is the quotient of the total compensation amount and the preset single compensation value;

[0120] The compensation submodule is used to compensate the local clock according to the compensation frequency corresponding to the single step length according to the clock count of the time counter, the single step length, the compensation number threshold and the preset single compensation value, so that the total compensation value is the total compensation amount.

[0121] In some embodiments, the compensation submodule may include:

[0122] A clock counting unit, used for starting a time counter and obtaining a current clock count of the time counter;

[0123] A step length judgment unit, used to judge whether the current clock count reaches a counting threshold corresponding to a single step length;

[0124] An updating unit, configured to clear the time counter and add 1 to the compensation count value to obtain an updated compensation count value if the count threshold is reached;

[0125] A compensation unit, for, if the updated compensation count value is not greater than the compensation count threshold, then when the compensation deviation is a negative number, adding a preset single compensation value to the local clock and executing the step of obtaining the current clock count of the time counter; when the compensation deviation is a positive number, subtracting the preset single compensation value from the local clock and sending a start signal to the clock counting unit;

[0126] The closing unit is used to clear the compensation count value to zero and close the time counter if the updated compensation count value is greater than the compensation times threshold.

[0127] In this embodiment, the embodiment of the present invention constructs a local system clock replica and a local system reference clock inside the slave station device, and can use the latest local system clock replica latch and local system reference clock of the current synchronization cycle and the previous local system clock replica latch and local system reference clock to determine the compensation deviation of the current synchronization cycle, thereby reducing the time deviation of the synchronization clock source and improving the accuracy of clock synchronization; and can determine the appropriate compensation frequency according to the size of the compensation deviation, compensate the local system clock in the current synchronization cycle, ensure that the compensation is uniform and effective, and improve the synchronization performance.

[0128] Corresponding to the above method embodiment, an embodiment of the present invention further provides an electronic device. The electronic device described below and the clock synchronization method of a distributed system described above can refer to each other.

[0129] Please refer to Figure 7 , Figure 7 This is a schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. The electronic device may include:

[0130] A memory D1, for storing computer programs;

[0131] The processor D2 is used to implement the steps of the clock synchronization method for a distributed system provided by the above method embodiment when executing a computer program.

[0132] The electronic device in this embodiment may specifically be a slave device in a distributed system, such as a slave device in an EtherCAT communication network, that is, EtherCAT communication may be adopted between the slave device and the master device.

[0133] The steps in the clock synchronization method for a distributed system described above can be implemented by the structure of an electronic device.

[0134] Corresponding to the above method embodiment, the embodiment of the present invention further provides a computer program product. The computer program product described below and the clock synchronization method of a distributed system described above can refer to each other.

[0135] A computer program product includes a computer program / instruction, which, when executed by a processor, implements the steps of the clock synchronization method for a distributed system provided by the above method embodiment.

[0136] Corresponding to the above method embodiment, an embodiment of the present invention further provides a computer storage medium. The computer storage medium described below and the clock synchronization method of a distributed system described above can refer to each other.

[0137] A computer storage medium stores a computer program, which, when executed by a processor, implements the steps of the clock synchronization method for a distributed system in the above method embodiment.

[0138] The computer storage medium may specifically be a U disk, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, or other storage medium that can store program codes.

[0139] The various embodiments in the specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referred to each other. For the devices, computer program products, and computer storage media disclosed in the embodiments, since they correspond to the methods disclosed in the embodiments, the description is relatively simple, and the relevant parts can be referred to the method part description.

[0140] The clock synchronization method, device, electronic device and computer storage medium of a distributed system provided by the present invention are introduced in detail above. Specific examples are used herein to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea. It should be pointed out that for ordinary technicians in this technical field, without departing from the principles of the present invention, several improvements and modifications can be made to the present invention, and these improvements and modifications also fall within the scope of protection of the present invention.

Claims

1. A clock synchronization method for a distributed system, characterized in that: Applicable to slave devices, including: Constructing a local system clock copy of the slave device according to the local clock of the slave device and the system clock offset sent by the master device; According to the system reference clock sent by the clock synchronization source and the local system clock copy, the local system reference clock of the slave device is adjusted and updated to obtain a local system reference clock corresponding to the system reference clock; Determine the compensation deviation of the current synchronization cycle according to the local system clock replica latch and the local system reference clock corresponding to the current system reference clock and the historical system reference clock, wherein the historical system reference clock is a system reference clock received before the current system reference clock; The local system clock is compensated in the current synchronization period according to the compensation frequency corresponding to the compensation deviation and a preset single compensation value.

2. The clock synchronization method of a distributed system according to claim 1, characterized in that: The local clock, the local system clock and the system reference clock are all first number bits; the local system reference clock of the slave device is adjusted and updated according to the system reference clock sent by the clock synchronization source and the local system clock copy to obtain the local system reference clock corresponding to the system reference clock, including: According to the data of the second high number of bits of the local system clock copy and the data of the third low number of bits of the current system reference clock, the local system reference clock is adjusted and updated to obtain the local system reference clock corresponding to the current system reference clock; wherein the sum of the second number and the third number is the first number.

3. The clock synchronization method of a distributed system according to claim 2, characterized in that: The adjusting and updating the local system reference clock according to the data of the second high number of bits of the local system clock copy and the data of the third low number of bits of the current system reference clock to obtain the local system reference clock corresponding to the current system reference clock includes: configuring the data of the second high number of bits of the local system reference clock as the data of the second high number of bits of the local system clock copy; After receiving the current system reference clock, assign the data of the lower third number of bits of the local system reference clock to the lower third number of bits of the local system reference clock of the previous cycle, and configure the data of the lower third number of bits of the local system reference clock as the data of the lower third number of bits of the current system reference clock; If the data of the third lower number of bits of the local system reference clock is less than the third lower number of bits of the local system reference clock of the previous cycle, the data of the second upper number of bits of the local system reference clock is increased by 1, and the processed local system reference clock is used as the local system reference clock corresponding to the current system reference clock; If the data of the third lower number of bits of the local system reference clock is not less than the third lower number of bits of the local system reference clock of the previous cycle, the current local system reference clock is used as the local system reference clock corresponding to the current system reference clock.

4. The clock synchronization method of a distributed system according to claim 1, characterized in that: The step of determining the compensation deviation of the current synchronization cycle according to the local system clock replica latch and the local system reference clock corresponding to the current system reference clock and the historical system reference clock respectively includes: Obtaining a local system clock replica latch and a local system reference clock corresponding to a target historical system reference clock; wherein the target historical system reference clock is a system reference clock received at a preset interval time before the current system reference clock; the preset interval time is the product of a preset synchronization cycle time and a preset number of intervals; Calculating a first deviation based on the local system clock replicas latched corresponding to the current system reference clock and the target historical system reference clock; Calculating a second deviation according to local system reference clocks corresponding to the current system reference clock and the target historical system reference clock; A compensation deviation of a current synchronization cycle is determined according to the first deviation and the second deviation.

5. The clock synchronization method of a distributed system according to claim 4, characterized in that: The determining, according to the first deviation and the second deviation, a compensation deviation of a current synchronization cycle includes: If the clock synchronization count is greater than or equal to the times threshold, the difference between the second deviation and the first deviation is calculated to obtain the third deviation; if the clock synchronization count is greater than or equal to the preset compensation start value and less than the times threshold, the difference between the local system clock replica latch and the local system reference clock corresponding to the current system reference clock is calculated to obtain the third deviation; wherein the first deviation is the difference between the local system clock replica latch corresponding to the current system reference clock and the target historical system reference clock, and the second deviation is the difference between the local system reference clock corresponding to the current system reference clock and the target historical system reference clock; Performing a mean filter with a preset width on the third deviation to obtain a filtered deviation; The quotient of the filtered deviation and the preset interval number is calculated to obtain the compensation deviation of the current synchronization cycle.

6. The clock synchronization method for a distributed system according to any one of claims 1 to 5, characterized in that: The compensating the local system clock in the current synchronization period according to the compensation frequency corresponding to the compensation deviation and the preset single compensation value includes: Determining the total amount of compensation for the current synchronization cycle according to a preset compensation threshold and the absolute value of the compensation deviation; Calculate the quotient of the total step length and the compensation times threshold to obtain the single step length corresponding to the compensation frequency; wherein the total step length is the quotient of the preset synchronization cycle time and the counting cycle time of the time counter, and the compensation times threshold is the quotient of the total compensation amount and the preset single compensation value; According to the clock count of the time counter, the single step length, the compensation times threshold and the preset single compensation value, the local clock is compensated at a compensation frequency corresponding to the single step length.

7. The clock synchronization method of a distributed system according to claim 6, characterized in that: The compensating the local clock according to the compensation frequency corresponding to the single step length according to the clock count of the time counter, the single step length, the compensation times threshold and the preset single compensation value includes: Starting the time counter and obtaining the current clock count of the time counter; Determine whether the current clock count reaches the count threshold corresponding to the single step length; If the counting threshold is reached, the time counter is cleared and the compensation count value is increased by 1 to obtain an updated compensation count value; If the updated compensation count value is not greater than the compensation count threshold, then when the compensation deviation is a negative number, the preset single compensation value is added to the local clock, and the step of obtaining the current clock count of the time counter is performed; when the compensation deviation is a positive number, the preset single compensation value is subtracted from the local clock, and the step of obtaining the current clock count of the time counter is performed; If the updated compensation count value is greater than the compensation times threshold, the compensation count value is cleared and the time counter is closed.

8. A clock synchronization device for a distributed system, characterized in that: Set on the slave device, including: A local construction module, used to construct a local system clock copy of the slave device according to the local clock of the slave device and the system clock offset sent by the master device; A reference adjustment module, configured to adjust and update the local system reference clock of the slave device according to the system reference clock sent by the clock synchronization source and the local system clock copy, so as to obtain a local system reference clock corresponding to the system reference clock; A deviation determination module, used to determine the compensation deviation of the current synchronization cycle according to the local system clock replica latch and the local system reference clock corresponding to the current system reference clock and the historical system reference clock respectively; wherein the historical system reference clock is a system reference clock received before the current system reference clock; The deviation compensation module is used to compensate the local system clock in the current synchronization period according to the compensation frequency corresponding to the compensation deviation and a preset single compensation value.

9. An electronic device, characterized in that: include: Memory for storing computer programs; A processor, configured to implement the steps of the clock synchronization method for a distributed system as described in any one of claims 1 to 7 when executing the computer program.

10. A computer storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the clock synchronization method for a distributed system as described in any one of claims 1 to 7 are implemented.

Citation Information

Cited By

  • Clock synchronization method, chip and multi-chip interconnection system

    CN120804013A