Time synchronization method, master device node, slave device node and device

By detecting the rising edge of the clock signal in the master device node and the slave device node to calculate the conversion time, millisecond-level time alignment is achieved based on the reference time and synchronization code, which solves the problem of time error in the existing technology and improves the system time accuracy and robustness.

CN118764124APending Publication Date: 2024-10-11SUPCON TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410913947.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-09
Publication Date
2024-10-11

AI Technical Summary

Technical Problem

Existing time synchronization methods analyze time information in units of seconds, causing the system to rely on its own crystal oscillator for time calculation within 1 second, resulting in time errors that affect time accuracy and system robustness.

Method used

By receiving the clock signal sent by the clock signal source in real time, detecting the rising edge to calculate the millisecond-level conversion time, if it is within the preset time range, calculate the system time based on the base time and conversion time, and send the base time and synchronization code to the slave device Node to achieve millisecond-level time alignment.

Benefits of technology

It improves the accuracy of time alignment and the robustness of the system, reduces the time error, and enhances the accuracy of the system's chain actions.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118764124A_ABST
    Figure CN118764124A_ABST
Patent Text Reader

Abstract

The invention provides a time synchronization method, a master device node, a slave device node and a device, and the method comprises the steps: the master device node receives a clock signal transmitted by a clock signal source based on a specific protocol in real time, and analyzes the clock signal to obtain reference time; when the rising edge of the clock signal is detected, the main equipment node calculates first conversion time, and the first conversion time is millisecond-level time; if the first conversion time is out of the preset time range, calculating system time based on the reference time and the first conversion time; and sending the reference time and the synchronous code corresponding to the clock signal to the slave equipment node, so that the slave equipment node obtains the system time based on the reference time and the synchronous code, thereby realizing millisecond-level time alignment and improving the time synchronization effect.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of industrial automation and instrumentation technology, and in particular to a time synchronization method, a master device node, a slave device node and a device. Background Art

[0002] For medium and large programmable logic controller (PLC) systems and distributed control systems (DCS), time accuracy is particularly important in order to improve the robustness of system operation and the accuracy of system chain actions.

[0003] The current synchronization method usually parses time information in seconds, that is, parses a synchronization data frame once per second and performs system time synchronization. However, for the time interval between two system time synchronizations, the system needs to rely on its own crystal oscillator to calculate the time within 1 second, which will result in a certain time error and poor synchronization effect. Summary of the invention

[0004] In view of this, an embodiment of the present invention provides a time synchronization method, a master device node, a slave device node and an apparatus to solve the problem of poor time synchronization effect existing in the method of parsing time information in seconds.

[0005] To achieve the above objectives, the embodiments of the present invention provide the following technical solutions:

[0006] A first aspect of an embodiment of the present invention discloses a time synchronization method, which is applicable to a master device node and includes:

[0007] Receiving a clock signal sent by a clock signal source based on a specific protocol in real time, and analyzing the clock signal to obtain a reference time;

[0008] When a rising edge of the clock signal is detected, a first conversion time is calculated, where the first conversion time is a time in millisecond level;

[0009] If the first conversion time is outside a preset time range, calculating the system time based on the reference time and the first conversion time, the preset time range being determined based on the time interval between any two adjacent rising edges of the clock signal;

[0010] The reference time and a synchronization code corresponding to the clock signal are sent to a slave device node, so that the slave device node obtains the system time based on the reference time and the synchronization code.

[0011] Preferably, when the rising edge of the clock signal is detected, calculating the first conversion time comprises:

[0012] When a rising edge of the clock signal is detected, reading a first clock count value of a timer of the master device node;

[0013] A first conversion time is calculated using the first clock count value.

[0014] Preferably, after calculating the first conversion time, the method further includes:

[0015] If the first conversion time is within a preset time range, taking the rising edge of the clock signal as a reference and combining the first clock count value to calculate the second conversion time, and clearing the first clock count value;

[0016] Calculate the system time based on the reference time, the second conversion time, and a synchronization code corresponding to the clock signal;

[0017] The reference time and a synchronization code corresponding to the clock signal are sent to a slave device node, so that the slave device node obtains the system time based on the reference time and the synchronization code.

[0018] Preferably, the specific protocol is the IRIG-B protocol of the Target Range Instrument Group.

[0019] A second aspect of an embodiment of the present invention discloses a time synchronization method, which is applicable to a slave device node, and includes:

[0020] Receiving a clock signal sent by a clock signal source based on a specific protocol in real time, and receiving a reference time sent by a master device node and a synchronization code corresponding to the clock signal, wherein the reference time is obtained by the master device node parsing the clock signal;

[0021] When a rising edge of the clock signal is detected, a third conversion time is calculated, where the third conversion time is a time in millisecond level;

[0022] If the third conversion time is outside a preset time range, the system time is calculated based on the reference time and the synchronization code, and the preset time range is determined based on the time interval between any two adjacent rising edges of the clock signal.

[0023] Preferably, when the rising edge of the clock signal is detected, calculating the third conversion time comprises:

[0024] When a rising edge of the clock signal is detected, reading a second clock count value of the timer of the slave device node;

[0025] The third conversion time is calculated using the second clock count value.

[0026] Preferably, after calculating the third conversion time, the method further includes:

[0027] If the third conversion time is within the preset time range, a fourth conversion time is calculated based on the rising edge of the clock signal and the second clock count value, and the second clock count value is cleared;

[0028] The system time is calculated based on the reference time, the fourth conversion time and the synchronization code.

[0029] A third aspect of an embodiment of the present invention discloses a master device node, the master device node comprising:

[0030] A receiving unit, configured to receive in real time a clock signal sent by a clock signal source based on a specific protocol, and parse the clock signal to obtain a reference time;

[0031] A first calculation unit, configured to calculate a first conversion time when a rising edge of the clock signal is detected, wherein the first conversion time is a time in millisecond level;

[0032] a second calculation unit, configured to calculate a system time based on the reference time and the first conversion time if the first conversion time is outside a preset time range, wherein the preset time range is determined based on a time interval between any two adjacent rising edges of the clock signal;

[0033] The sending unit is used to send the reference time and a synchronization code corresponding to the clock signal to a slave device node, so that the slave device node obtains the system time based on the reference time and the synchronization code.

[0034] A fourth aspect of an embodiment of the present invention discloses a slave device node, the slave device node comprising:

[0035] A receiving unit, configured to receive in real time a clock signal sent by a clock signal source based on a specific protocol, and to receive a reference time sent by a master device node and a synchronization code corresponding to the clock signal, wherein the reference time is obtained by parsing the clock signal by the master device node;

[0036] A first calculation unit, configured to calculate a third conversion time when a rising edge of the clock signal is detected, wherein the third conversion time is a time in millisecond level;

[0037] The second calculation unit is used to calculate the system time based on the reference time and the synchronization code if the third conversion time is outside a preset time range, and the preset time range is determined based on the time interval between any two adjacent rising edges of the clock signal.

[0038] A fifth aspect of an embodiment of the present invention discloses a time synchronization device, which includes: a clock signal source, a master device node disclosed in the third aspect of an embodiment of the present invention, and a slave device node disclosed in the fourth aspect of an embodiment of the present invention.

[0039] Based on the above-mentioned embodiment of the present invention, a time synchronization method, a master device node, a slave device node and an apparatus are provided. The method is as follows: the master device node receives the clock signal sent by the clock signal source based on a specific protocol in real time, and parses the clock signal to obtain the reference time; when the rising edge of the clock signal is detected, the master device node calculates the first conversion time, which is a time at the millisecond level; if the first conversion time is outside the preset time range, the system time is calculated based on the reference time and the first conversion time; the reference time and the synchronization code corresponding to the clock signal are sent to the slave device node, so that the slave device node obtains the system time based on the reference time and the synchronization code. In this scheme, in the process of receiving the clock signal, when the rising edge of the clock signal is detected, the master device node calculates the first conversion time at the millisecond level. If the first conversion time is outside the preset time range, the master device node calculates the system time based on the reference time and the first conversion time, and sends the reference time and the synchronization code to the slave device node so that the slave device node obtains the system time, achieving millisecond-level time alignment, thereby improving the time synchronization effect. BRIEF DESCRIPTION OF THE DRAWINGS

[0040] 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.

[0041] Figure 1 A schematic diagram of the connection between a clock signal source, a master device node and a slave device node provided in an embodiment of the present invention;

[0042] Figure 2 A flowchart of a time synchronization method provided by an embodiment of the present invention;

[0043] Figure 3 A waveform diagram of a B code signal provided by an embodiment of the present invention;

[0044] Figure 4 A flowchart of a time synchronization method provided by an embodiment of the present invention;

[0045] Figure 5 A schematic diagram of the interaction between a clock signal source, a master device node and a slave device node provided in an embodiment of the present invention;

[0046] Figure 6A structural block diagram of a master device node provided by an embodiment of the present invention;

[0047] Figure 7 A structural block diagram of a slave device node provided by an embodiment of the present invention;

[0048] Figure 8 A structural block diagram of a time synchronization device provided in an embodiment of the present invention. DETAILED DESCRIPTION

[0049] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only 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.

[0050] In this application, the terms "comprises", "comprising" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "comprising a ..." does not exclude the presence of other identical elements in the process, method, article or device comprising the element.

[0051] As can be seen from the background technology, for medium and large programmable logic controller (PLC) systems and distributed control systems (DCS), in order to improve the robustness of system (PLC system and DCS system, etc.) operation, the accuracy of system chain actions, etc., time accuracy is particularly important.

[0052] The current synchronization method usually parses time information in seconds, that is, parses a synchronization data frame once per second and performs system time synchronization. However, for the time interval between two system time synchronizations, the system needs to rely on its own crystal oscillator to calculate the time within 1 second, which will result in a certain time error and poor synchronization effect.

[0053] In addition, for a running system, a new device newly added to the system can have the correct system time only after the system and the new device have completed the second-level time alignment.

[0054] In order to solve the above problems, this solution proposes a time synchronization method, a master device node, a slave device node and an apparatus. In the process of receiving a clock signal, when the rising edge of the clock signal is detected, the master device node calculates the first conversion time at the millisecond level. If the first conversion time is outside the preset time range, the master device node calculates the system time based on the reference time and the first conversion time, and sends the reference time and the synchronization code to the slave device node so that the slave device node obtains the system time, achieving millisecond-level time alignment, thereby improving the time synchronization effect.

[0055] It is worth noting that in the subsequent explanation of this solution, objects such as clock signal source, master device node and slave device node will be involved. In order to better understand the subsequent explanation of this solution, Figure 1 The connection diagram of the clock signal source, the master device node and the slave device node shown is used as an example.

[0056] exist Figure 1 In the embodiment, the clock signal source is the InterRange Instrumentation Group (IRIG-B) signal source, the master device node is the control device master node in the system (PLC system or DCS system), and the slave node device is the I / O device (i.e., input / output device) in the system.

[0057] like Figure 1 It can be seen that the system contains multiple racks ( Figure 1 Only two racks are used as an example), each rack includes: a control device master node and multiple I / O devices; an IRIG-B signal source is connected via an RS485 differential line ( Figure 1 The solid line in the figure transmits the clock signal (also called B code signal or B code level signal) to the control device master node and I / O device, that is, Figure 1 The solid line in is equivalent to the transmission path of the RS485 differential line transmission clock signal;

[0058] After receiving the clock signal, the control device master node transmits the clock signal to the control device master node through the ECI bus ( Figure 1 The dashed line in the figure sends a synchronization code (also called a synchronization signal code or a time sequence number) to the I / O devices in the same rack.

[0059] above Figure 1 The content in is an explanation of the relationship between the clock signal source, the master device node and the slave device node. The following is a detailed description of this solution through various embodiments.

[0060] See also Figure 2 , which shows a flow chart of a time synchronization method provided by an embodiment of the present invention, Figure 2 The time synchronization method shown is applicable to the master device node. Figure 2 The following steps are involved:

[0061] Step S201: The master device node receives a clock signal sent by a clock signal source based on a specific protocol in real time, and parses the clock signal to obtain a reference time.

[0062] It should be noted that the clock signal source sends clock signals to the master device node and the slave device node in real time based on a specific protocol. The specific protocol is the IRIG-B protocol. The clock signal can be derived from a satellite signal.

[0063] For example: the clock signal source converts the satellite signal into a B-code signal (clock signal) through a time conversion board, and then sends the B-code signal to the master device node and the slave device node through the RS485 bus, thereby enhancing the anti-interference ability of the transmitted B-code signal.

[0064] In the specific implementation of step S201, the master device node receives a clock signal sent by a clock signal source in real time, and the clock signal carries time information at the second level.

[0065] For example, the master device node receives a clock signal (B code signal) sent by a clock signal source based on the IRIG-B protocol in real time. The time information carried by the clock signal includes: year, month, day, hour, minute, and second.

[0066] The master device node parses the received clock signal through its own single-chip microcomputer to obtain the reference time, which is a time longer than seconds (time in whole second format), that is, the reference time is at the second level.

[0067] Step S202: When the master device node detects the rising edge of the clock signal, it calculates a first conversion time, where the first conversion time is in milliseconds.

[0068] It should be noted that the clock signal source divides 1 second (1s) of time into multiple fixed-length code elements on an even basis based on the clock signal sent by the specific protocol;

[0069] For example, assuming that the clock signal is a B-code signal, when the clock signal source is sending the B-code signal, the waveform of the B-code signal is as follows: Figure 3 As shown, the B code signal divides 1 second into 100 code elements of 10 milliseconds (10ms) in length; on this basis, the inventors have found through research that the time interval between two adjacent rising edges of the B code signal is a fixed 10ms, and each rising edge of the B code signal will trigger a rising edge interrupt, so this feature can be used to achieve millisecond-level timing.

[0070] In the specific implementation of step S202, the master device node detects the rising edge of the clock signal when receiving the clock signal; when the master device node detects the rising edge of the clock signal, the master device node calculates a first conversion time, which is a time in milliseconds.

[0071] Specifically, the master device node calculates the first conversion time in the following manner: when the rising edge of the clock signal is detected, the master device node reads the first clock count value (tick) of the timer (CPU timer) of the master device node, and the clock reference of the first clock count value is the physical oscillation of the crystal oscillator circuit of the microcontroller of the master device node.

[0072] The master device node calculates the first conversion time using the first clock count value; specifically, the master device node calculates the first conversion time using the main frequency of the single-chip microcomputer of the master device node and the first clock count value.

[0073] For example: assuming that the main frequency of the single-chip microcomputer of the master device node is 180Mhz (that is, the count value of the timer per microsecond is 180), and the clock signal is a B code signal; when the master device node detects the rising edge of the B code signal, the first clock count value of the timer of the master device node is 18800000; then, the calculated first conversion time = 18800000 / 180 / 1000≈104ms.

[0074] In summary, when the master device node is in the process of receiving the clock signal and the clock signal enters a rising edge interrupt, the master device node calculates the first conversion time in the above manner.

[0075] Step S203: The master device node determines whether the first conversion time is outside the preset time range; if the first conversion time is outside the preset time range, execute steps S204 to S205; if the first conversion time is within the preset time range, execute steps S206 to S208.

[0076] It should be noted that the preset time range is determined based on the time interval between any two adjacent rising edges of the clock signal.

[0077] For example: Assume that the clock signal is a B-code signal, such as Figure 3 As shown, the time interval between any two adjacent rising edges of the B code signal is fixed at 10ms; then, the preset time range may be 10ms±0.5ms, that is, the preset time range is [9.5ms, 10.5ms].

[0078] In the specific implementation of step S203, the master device node determines whether the first conversion time is outside the preset time range; if the first conversion time is outside the preset time range, it indicates that the currently received clock signal is abnormal (equivalent to the received clock signal being an interference signal or an error signal), and steps S204 to S205 are executed at this time;

[0079] If the first conversion time is within the preset time range, it indicates that the currently received clock signal is normal (equivalent to the clock signal being credible), and step S206 to step S208 are executed.

[0080] For example: assuming that the preset time range is 10ms±0.5ms; when entering the 10ms rising edge interrupt, if the calculated first conversion time is outside the range of "10ms±0.5ms", it indicates that the currently received clock signal is abnormal, and execute steps S204 to S205; conversely, if the first conversion time is within the range of "10ms±0.5ms", it indicates that the currently received clock signal is normal, and execute steps S206 to S208.

[0081] Step S204: the master device node calculates the system time based on the reference time and the first conversion time.

[0082] In the process of implementing step S204, if the first conversion time is outside the preset time range, indicating that the currently received clock signal is abnormal, the master device node directly calculates the system time of the system (PLC system or DCS system) in which the master device node is located based on the reference time obtained by analyzing the clock signal and the first conversion time calculated by the first clock count value. The system time is: the time granularity is the time with the accuracy of "the time interval between any two adjacent rising edges of the clock signal".

[0083] That is to say, if the first conversion time is outside the preset time range, the abnormal clock signal is discarded, and the master device node directly uses the time calculated by the reference time and the first conversion time to replace the original system time. That is, the master device node uses the time calculated by the reference time and the first conversion time as the currently used system time until the clock signal returns to normal (until the first conversion time is within the preset time range).

[0084] For example: Assume that the clock signal is a B-code signal, such as Figure 3 As shown, the time interval between two adjacent rising edges of the B code signal is fixed at 10ms; if the first conversion time is outside the preset time range, the system time calculated by the master device node based on the reference time and the first conversion time is: the time with a time granularity of 10ms accuracy.

[0085] Step S205: The master device node sends the reference time and the synchronization code corresponding to the clock signal to the slave device node, so that the slave device node obtains the system time based on the reference time and the synchronization code.

[0086] It should be noted that, from the content of the above step S202, it can be seen that the clock signal source sends a clock signal based on a specific protocol that divides 1 second (1s) into multiple code elements of fixed length on average, and the master device node encodes these code elements into multiple time positions, which are synchronization codes (also called synchronization signal codes or time sequence numbers).

[0087] For example: Assuming that the clock signal is a B-code signal, the clock signal source combines Figure 3 It can be seen that the B code signal divides 1 second of time into 100 code elements of 10ms in length; the master device node encodes the 100 code elements within 1 second into time positions 1-100, and these 100 time positions are represented by seq1-seq100, and seqN (the Nth code element) is the synchronization code (also called synchronization signal code or time sequence number).

[0088] In the specific implementation of step S205, the master device node sends the reference time (time longer than seconds) and the synchronization code to each slave device node in the same rack as the master device node, so that each slave device node obtains the system time based on the reference time and the synchronization code.

[0089] It should be noted that when the master device node broadcasts the reference time and the synchronization code, the period of broadcasting the reference time and the period of broadcasting the synchronization code are different.

[0090] Specifically, the "time interval between any two adjacent rising edges of the clock signal" is referred to as the "time interval"; the master device node will broadcast a synchronization code (the Nth code element) to each slave device node on the same rack as itself within each "time interval" cycle; the synchronization code is used to determine which "time interval" it is currently in; in addition, the master device node will broadcast the reference time within each specific time period.

[0091] For example: Assume that the clock signal is a B-code signal, such as Figure 3 As shown in the figure, the time interval between two adjacent rising edges of the B code signal is fixed at 10ms; then, the master device node will broadcast a synchronization code (seqN) to each slave device node in the same rack as itself in each 10ms cycle, and the synchronization code is used to determine that it is currently in the Nth 10ms cycle; the master device node will broadcast the reference time to each slave device node in the same rack as itself in each 1s cycle (specific time period). In other words, the master device node broadcasts the reference time once in 1s and broadcasts the synchronization code once every 10ms.

[0092] It is worth noting that in the process of executing step S204 to step S205, since the first conversion time is outside the preset time range, the currently received clock signal is unreliable (that is, the synchronization code corresponding to the currently received clock signal cannot be used). At this time, when the master device node sends the synchronization code, the master device node needs to update the synchronization code according to the first clock count value (tick) (equivalent to the master node device regenerating a new synchronization code according to its own crystal oscillator), and then send the updated synchronization code to the slave device node;

[0093] In other words, when the first conversion time is outside the preset time range, the "synchronization code corresponding to the clock signal" sent by the master device node to the slave device node is: the synchronization code updated by the master device node according to the first clock count value.

[0094] Step S206: the master device node calculates the second conversion time based on the rising edge of the clock signal and the first clock count value, and clears the first clock count value.

[0095] In the process of implementing step S206, if the first conversion time is within the preset time range, it indicates that the currently received clock signal is credible. At this time, the master device node uses the rising edge of the clock signal as a reference, combined with the first clock count value of the timer to calculate the second conversion time, and clears the first clock count value of the timer to facilitate the counting of the next cycle.

[0096] For example: assuming that the preset time range is 10ms±0.5ms; when entering the 10ms rising edge interrupt, if the calculated first conversion time is within the range of "10ms±0.5ms", it indicates that the currently received clock signal is credible. The master device node uses the rising edge of the clock signal as a reference, combined with the first clock count value, to calculate the second conversion time, and clears the first clock count value of the timer to allow for the next 10ms cycle count.

[0097] Step S207: The master device node calculates the system time based on the reference time, the second conversion time, and the synchronization code corresponding to the clock signal.

[0098] Since the first conversion time is within the preset time range, the currently received clock signal is credible, and the clock signal can be directly used to calculate the system time;

[0099] In the process of implementing step S207, the master device node calculates the system time of the system (PLC system or DCS system) in which the master device node is located based on the reference time, the second conversion time, and the synchronization code corresponding to the clock signal. The system time calculated at this time is: the time granularity is within the accuracy of "the time interval between any two adjacent rising edges of the clock signal".

[0100] For example: Assume that the clock signal is a B-code signal, such as Figure 3 As shown, the time interval between two adjacent rising edges of the B code signal is fixed at 10ms; if the first conversion time is within the preset time range, the system time calculated by the master device node based on the reference time, the second conversion time and the synchronization code is: the time with a time granularity within 10ms accuracy (such as a time granularity of 1ms, 2ms and 120us).

[0101] Step S208: The master device node sends the reference time and the synchronization code corresponding to the clock signal to the slave device node, so that the slave device node obtains the system time based on the reference time and the synchronization code.

[0102] It should be noted that, in the specific implementation of step S208, the master device node sends the reference time and the synchronization code corresponding to the clock signal to the slave device node. For details, please refer to the content of the above step S205, which will not be repeated here.

[0103] It is worth noting that, in the process of executing step S206 to step S207, since the first conversion time is within the preset time range, the currently received clock signal is credible, and the synchronization code corresponding to the currently received clock signal can be used. At this time, when the master device node calculates the system time, the synchronization code used is the synchronization code corresponding to the currently received clock signal; and when the master device node sends the synchronization code, the master device node sends the synchronization code corresponding to the currently received clock signal to the slave device node;

[0104] In other words, when the first conversion time is within the preset time range, the synchronization code used by the master device node to calculate the system time is: the synchronization code corresponding to the currently received clock signal; the synchronization code sent by the master device node to the slave device node is: the synchronization code corresponding to the currently received clock signal.

[0105] In the embodiment of the present invention, when the rising edge of the clock signal is detected, the master device node calculates the first conversion time at the millisecond level. If the first conversion time is outside the preset time range, the master device node calculates the system time based on the reference time and the first conversion time, and sends the reference time and the synchronization code to the slave device node so that the slave device node obtains the system time, achieving millisecond-level time alignment, thereby improving the time synchronization effect.

[0106] The above embodiments of the present invention Figure 2 The content in is the explanation of the time alignment of the master device node; accordingly, the following Figure 4 Let's explain the process of time alignment from device nodes.

[0107] See also Figure 4 , which shows a flow chart of a time synchronization method provided by an embodiment of the present invention, Figure 4 The time synchronization method shown is applicable to slave device nodes. Figure 4 The following steps are involved:

[0108] Step S401: The slave device node receives in real time a clock signal sent by a clock signal source based on a specific protocol, and receives a reference time sent by a master device node and a synchronization code corresponding to the clock signal.

[0109] In the specific implementation process of step S401, the slave device node receives a clock signal sent by a clock signal source based on a specific protocol, and receives a reference time and a synchronization code sent by a master device node. The slave device node can determine the time information above seconds using the reference time.

[0110] It should be noted that after the slave device node receives the synchronization code sent by the master device node, the slave device node can determine that it is in the Nth "time interval" according to the synchronization code (seqN); for the relevant explanation of the synchronization code, please refer to the above-mentioned embodiment of the present invention. Figure 2 The contents of step S205 are not repeated here.

[0111] For example: Assume that the clock signal is a B-code signal, such as Figure 3 As shown, the time interval between two adjacent rising edges of the B code signal is fixed at 10ms; after the slave device node receives the synchronization code sent by the master device node, the slave device node can determine that it is within the Nth 10ms according to the synchronization code (seqN).

[0112] For the explanation of the reference time and the clock signal of the specific protocol, please refer to the above embodiment of the present invention. Figure 2 The contents of step S201 are not repeated here.

[0113] Step S402: When the slave device node detects the rising edge of the clock signal, it calculates the third conversion time.

[0114] In the specific implementation process of step S402, when receiving the clock signal, the slave device node detects the rising edge of the clock signal; when detecting the rising edge of the clock signal, the slave device node calculates a third conversion time, which is a time in milliseconds.

[0115] Specifically, the specific method for calculating the third conversion time from the device node is: when the rising edge of the clock signal is detected, the slave device node reads the second clock count value (tick) of the timer (CPU timer) of the slave device node, and the clock reference of the second clock count value is: the physical oscillation of the crystal oscillator circuit of the microcontroller of the slave device node.

[0116] The slave device node calculates the third conversion time using the second clock count value; specifically, the slave device node calculates the third conversion time using the main frequency of the single-chip microcomputer of the slave device node and the second clock count value.

[0117] In summary, when the slave device node is in the process of receiving the clock signal and the clock signal enters a rising edge interrupt, the master device node calculates the third conversion time in the above manner.

[0118] Step S403: Determine from the device node whether the third conversion time is outside the preset time range; if the third conversion time is outside the preset time range, execute step S404; if the third conversion time is within the preset time range, execute steps S405 to S406.

[0119] It should be noted that the preset time range is determined based on the time interval between any two adjacent rising edges of the clock signal. For the relevant explanation of the preset time range, please refer to the above-mentioned embodiment of the present invention. Figure 2 The content in step S203 is not repeated here.

[0120] In the specific implementation of step S403, the slave device node determines whether the third conversion time is outside the preset time range; if the third conversion time is outside the preset time range, it indicates that the currently received clock signal is abnormal (equivalent to the received clock signal being an interference signal or an error signal), and step S404 is executed at this time;

[0121] If the third conversion time is within the preset time range, it indicates that the currently received clock signal is normal (equivalent to the clock signal being credible), and step S405 to step S406 are executed.

[0122] Step S404: The slave device node calculates the system time based on the reference time and the synchronization code.

[0123] In the process of implementing step S404, if the third conversion time is outside the preset time range, indicating that the currently received clock signal is abnormal, the slave device node directly calculates the system time based on the reference time and synchronization code sent by the master device node (no longer considering the currently received clock signal). The system time is: the time granularity is the time with the accuracy of "the time interval between any two adjacent rising edges of the clock signal".

[0124] That is to say, if the third conversion time is outside the preset time range, the abnormal clock signal is discarded, and the slave device node directly uses the time calculated by the reference time and the synchronization code to replace the original system time, that is, the slave device node uses the time calculated by the reference time and the synchronization code as the currently used system time until the clock signal returns to normal (until the third conversion time is within the preset time range).

[0125] For example: Assume that the clock signal is a B-code signal, such as Figure 3 As shown, the time interval between two adjacent rising edges of the B code signal is fixed at 10ms; if the third conversion time is outside the preset time range, the system time calculated by the slave device node based on the reference time and the synchronization code is: the time with a time granularity of 10ms accuracy.

[0126] Step S405: The slave device node calculates the fourth conversion time based on the rising edge of the clock signal and the second clock count value, and clears the second clock count value.

[0127] In the process of implementing step S405, if the third conversion time is within the preset time range, it indicates that the currently received clock signal is credible. At this time, the slave device node uses the rising edge of the clock signal as a reference, combined with the second clock count value to calculate the fourth conversion time, and clears the second clock count value to facilitate counting of the next cycle.

[0128] For example: assuming that the preset time range is 10ms±0.5ms; when entering the 10ms rising edge interrupt, if the calculated third conversion time is within the range of "10ms±0.5ms", it indicates that the currently received clock signal is credible, and the slave device node uses the rising edge of the clock signal as a reference, combines the second clock count value to calculate the fourth conversion time, and clears the second clock count value to count the next 10ms cycle.

[0129] Step S406: The slave device node calculates the system time based on the reference time, the fourth conversion time and the synchronization code.

[0130] In the process of implementing step S406, the slave device node calculates the system time of the system (PLC system or DCS system) in which the slave device node is located based on the reference time, the fourth conversion time and the synchronization code. The system time calculated at this time is: the time granularity is within the accuracy of "the time interval between any two adjacent rising edges of the clock signal".

[0131] For example: Assume that the clock signal is a B-code signal, such as Figure 3As shown, the time interval between two adjacent rising edges of the B code signal is fixed at 10ms; if the third conversion time is within the preset time range, the system time calculated from the device node based on the reference time, the fourth conversion time and the synchronization code is: the time with a time granularity within 10ms accuracy (such as a time granularity of 1ms).

[0132] In the embodiment of the present invention, when the rising edge of the clock signal is detected, the slave device node calculates the third conversion time in milliseconds. If the third conversion time is outside the preset time range, the slave device node calculates the system time based on the reference time and the synchronization code sent by the master device node, achieving millisecond-level time alignment, thereby improving the time synchronization effect.

[0133] The above embodiments of the present invention Figure 4 The content in is the explanation about time alignment of slave device nodes.

[0134] To further explain how the master device node and the slave device node are time-aligned, from a practical application perspective, the following Figure 5 The interaction diagram of the clock signal source, the master device node and the slave device node is shown for illustration.

[0135] Figure 5 In the example, the clock signal source converts the satellite signal into a B-code signal (clock signal) through a GPS satellite signal conversion card, the master device node is the PLC master controller, and the slave device node is the I / O card;

[0136] The central processor of the PLC main controller is composed of a field programmable gate array (FPGA) time analysis unit, a 10ms interruption part, and a time calculation and filtering part.

[0137] The I / O card consists of a 10ms interrupt part and a microcontroller logic processing part.

[0138] Combination Figure 5 As shown in the content, the time synchronization process of the PLC controller and the I / O card is as follows: the clock signal source converts the satellite signal into a B code signal through the GPS satellite signal conversion card, and sends the B code signal to the PLC main controller and the I / O card through the IRIG-B protocol.

[0139] The FPGA time parsing unit of the PLC main controller parses the B-code signal to obtain the reference time (year, month, day, hour, minute, second) in the whole second format;

[0140] The 10ms interrupt part of the PLC main controller is used to detect the rising edge interrupt of the B code signal 10ms, and calculate the time within 10ms in combination with the clock crystal oscillator (crystal oscillator circuit);

[0141] When the time calculation and filtering part of the PLC main controller detects the rising edge interrupt of the B code signal 10ms, it performs corresponding processing according to the clock crystal oscillator of the central processor of the PLC main controller and sends the reference time and synchronization code to the I / O card; the specific content of the aforementioned "corresponding processing" can be referred to the above embodiment of the present invention. Figure 2 The contents in will not be repeated here.

[0142] The 10ms interrupt part of the I / O card is used to detect the rising edge interrupt of the B code signal 10ms;

[0143] When the single-chip logic processing part of the I / O card detects the rising edge interrupt of the B code signal 10ms, it performs corresponding processing according to the reference time and synchronization code broadcast by the PLC main controller to complete the time alignment. The specific content of the "corresponding processing" can be referred to the above embodiment of the present invention. Figure 4 The contents in will not be repeated here.

[0144] Overall, when the B code signal is normal, the interaction process between the PLC main controller and the I / O card is as follows:

[0145] When the PLC main controller receives a B-code signal, the PLC main controller parses out the reference time in the whole second format (time longer than seconds), determines the synchronization code (used to transmit time with an accuracy of 10ms) according to the received B-code signal, and broadcasts the reference time and synchronization code to the I / O cards in the same rack; in addition, the PLC main controller uses the rising edge of the received B-code signal as a reference and cooperates with its own first clock count value (the tick of the PLC main controller) to calculate the time within 10ms; the system time finally calculated by the PLC main controller is accurate to within 10ms.

[0146] The I / O card calculates the time longer than 10ms based on the reference time and synchronization code sent by the PLC main controller. The I / O card then calculates the time within 10ms based on the rising edge of the received B code signal and its own second clock count value (I / O card tick). The system time finally calculated by the I / O card is accurate to within 10ms.

[0147] In summary, when the B code signal is normal, the system time finally calculated by the PLC main controller and I / O card is accurate to within 10ms.

[0148] When the B code signal is abnormal, the interaction process between the PLC main controller and the I / O card is as follows:

[0149] When the PLC main controller receives the B code signal, the PLC main controller parses the reference time in the whole second format (time longer than seconds), updates the synchronization code according to its own first clock count value (the tick of the PLC main controller), and sends the reference time and the updated synchronization code to the I / O card; in addition, since the currently received B code signal is unreliable, the system time finally calculated by the PLC main controller at this time is accurate to more than 10ms.

[0150] Since the currently received B code signal is unreliable, the I / O card only uses the reference time and synchronization code sent by the PLC main controller. The I / O card finally calculates the system time with an accuracy of more than 10ms, that is, the system time is accurate to more than 10ms.

[0151] In summary, when the B code signal is abnormal, the system time finally calculated by the PLC main controller and I / O card is more than 10ms.

[0152] The above embodiments of the present invention Figure 5 This is an example of this solution. In actual applications, one of the application scenarios of this solution is: when a new slave device node is just connected to the system, because the period of the master device node broadcasting the reference time is different from the period of broadcasting the synchronization code, the slave device node may miss the reference time sent by the master device node (that is, the slave device node cannot get more than a second temporarily), and the slave device node only receives the synchronization code sent by the master device node (temporarily called the old synchronization code). The master device node continues to broadcast the reference time and synchronization code in the manner of this solution. When the slave device node receives the reference time and the new synchronization code, the slave device node can reverse the time based on the reference time, the new synchronization code, and the old synchronization code, thereby calculating the accurate system time and completing the system synchronization.

[0153] Combining the contents of the above embodiments, it can be seen that the time synchronization method proposed in this solution has the following beneficial effects:

[0154] 1. This solution uses the rising edge interrupt of the clock signal to determine whether the clock signal is credible, and transforms the system (PLC system or DCS system) into millisecond-level time alignment, thereby improving the overall time accuracy;

[0155] 2. Use the clock count values ​​of the master device node and the slave device node to reversely monitor the clock signal sent by the clock signal source to ensure the robustness of the received clock signal;

[0156] 3. While improving the time synchronization accuracy, there is no need to change the hardware, thereby improving the compatibility of time synchronization.

[0157] Corresponding to a time synchronization method provided in the above embodiment of the present invention, see Figure 6 , the embodiment of the present invention also provides a structural block diagram of a master device node, the master device node includes: a receiving unit 601, a first computing unit 602, a second computing unit 603 and a sending unit 604;

[0158] The receiving unit 601 is used to receive a clock signal sent by a clock signal source based on a specific protocol in real time, and parse the clock signal to obtain a reference time.

[0159] In some embodiments, the specific protocol is the IRIG-B protocol.

[0160] The first calculation unit 602 is used to calculate a first conversion time when a rising edge of a clock signal is detected, where the first conversion time is a time in millisecond level.

[0161] In a specific implementation, the first calculation unit 602 is specifically used to: read a first clock count value of a timer of the master device node when a rising edge of a clock signal is detected; and calculate a first conversion time using the first clock count value.

[0162] The second calculation unit 603 is used to calculate the system time based on the reference time and the first conversion time if the first conversion time is outside a preset time range, and the preset time range is determined based on the time interval between any two adjacent rising edges of the clock signal.

[0163] The sending unit 604 is used to send the reference time and the synchronization code corresponding to the clock signal to the slave device node, so that the slave device node obtains the system time based on the reference time and the synchronization code.

[0164] Preferably, combined Figure 6 The content shown, the main device node also includes:

[0165] The processing unit is used to calculate the second conversion time based on the rising edge of the clock signal and the first clock count value if the first conversion time is within a preset time range, and clear the first clock count value.

[0166] The third calculation unit is used to calculate the system time based on the reference time, the second conversion time, and the synchronization code corresponding to the clock signal.

[0167] Accordingly, the sending unit 604 is executed to send the reference time and the synchronization code corresponding to the clock signal to the slave device node, so that the slave device node obtains the system time based on the reference time and the synchronization code.

[0168] In the embodiment of the present invention, when the rising edge of the clock signal is detected, the master device node calculates the first conversion time at the millisecond level. If the first conversion time is outside the preset time range, the master device node calculates the system time based on the reference time and the first conversion time, and sends the reference time and the synchronization code to the slave device node so that the slave device node obtains the system time, achieving millisecond-level time alignment, thereby improving the time synchronization effect.

[0169] Corresponding to a time synchronization method provided in the above embodiment of the present invention, see Figure 7 , the embodiment of the present invention also provides a structural block diagram of a slave device node, the slave device node includes: a receiving unit 701, a first computing unit 702 and a second computing unit 703;

[0170] The receiving unit 701 is used to receive in real time a clock signal sent by a clock signal source based on a specific protocol, and to receive a reference time sent by a master device node and a synchronization code corresponding to the clock signal, wherein the reference time is obtained by parsing the clock signal by the master device node.

[0171] The first calculation unit 702 is used to calculate a third conversion time when a rising edge of the clock signal is detected, where the third conversion time is a time in millisecond level.

[0172] In a specific implementation, the first calculation unit 702 is specifically used for: when a rising edge of a clock signal is detected, reading a second clock count value of a timer from the device node; and calculating a third conversion time using the second clock count value.

[0173] The second calculation unit 703 is used to calculate the system time based on the reference time and the synchronization code if the third conversion time is outside the preset time range, and the preset time range is determined based on the time interval between any two adjacent rising edges of the clock signal.

[0174] Preferably, combined Figure 7 The content shown, the slave device node also includes:

[0175] The processing unit is used to calculate the fourth conversion time based on the rising edge of the clock signal and the second clock count value if the third conversion time is within the preset time range, and clear the second clock count value.

[0176] The third calculation unit is used to calculate the system time based on the reference time, the fourth conversion time and the synchronization code.

[0177] In the embodiment of the present invention, when the rising edge of the clock signal is detected, the slave device node calculates the third conversion time in milliseconds. If the third conversion time is outside the preset time range, the slave device node calculates the system time based on the reference time and the synchronization code sent by the master device node, achieving millisecond-level time alignment, thereby improving the time synchronization effect.

[0178] Corresponding to a time synchronization method provided in the above embodiment of the present invention, see Figure 8 , the embodiment of the present invention further provides a time synchronization device, the time synchronization device comprises: a clock signal source 801, a master device node 802 and a slave device node 803;

[0179] The clock signal source 801 is used to send clock signals to the master device node 802 and the slave device node 803 based on a specific protocol; the execution principle of the master device node 802 can refer to the above-mentioned embodiment of the present invention. Figure 6 For the relevant contents in the above, the execution principle of the slave device node 803 can be found in the above embodiment of the present invention. Figure 7 Related content in .

[0180] In summary, the embodiment of the present invention provides a time synchronization method, a master device node, a slave device node and an apparatus. In the process of receiving a clock signal, when the rising edge of the clock signal is detected, the master device node calculates the first conversion time at the millisecond level. If the first conversion time is outside the preset time range, the master device node calculates the system time based on the reference time and the first conversion time, and sends the reference time and the synchronization code to the slave device node so that the slave device node obtains the system time, achieving millisecond-level time alignment, thereby improving the time synchronization effect.

[0181] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can refer to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the system or system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can refer to the partial description of the method embodiment. The system and system embodiments described above are merely schematic, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without creative work.

[0182] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.

[0183] The above description of the disclosed embodiments enables those skilled in the art to implement or use the present invention. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but rather to the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A time synchronization method, characterized in that: The method is applicable to a master device node, and the method comprises: Receiving a clock signal sent by a clock signal source based on a specific protocol in real time, and parsing the clock signal to obtain a reference time; When a rising edge of the clock signal is detected, a first conversion time is calculated, where the first conversion time is a time in millisecond level; If the first conversion time is outside a preset time range, calculating the system time based on the reference time and the first conversion time, the preset time range being determined based on the time interval between any two adjacent rising edges of the clock signal; The reference time and a synchronization code corresponding to the clock signal are sent to a slave device node, so that the slave device node obtains the system time based on the reference time and the synchronization code.

2. The method according to claim 1, characterized in that When a rising edge of the clock signal is detected, calculating a first conversion time comprises: When a rising edge of the clock signal is detected, reading a first clock count value of a timer of the master device node; A first conversion time is calculated using the first clock count value.

3. The method according to claim 2, characterized in that After calculating the first conversion time, it also includes: If the first conversion time is within a preset time range, taking the rising edge of the clock signal as a reference and combining the first clock count value to calculate the second conversion time, and clearing the first clock count value; Calculate the system time based on the reference time, the second conversion time, and a synchronization code corresponding to the clock signal; The reference time and a synchronization code corresponding to the clock signal are sent to a slave device node, so that the slave device node obtains the system time based on the reference time and the synchronization code.

4. The method according to any one of claims 1 to 3, characterized in that: The specific protocol is the IRIG-B protocol.

5. A time synchronization method, characterized in that: The method is applicable to a slave device node, and the method comprises: Receiving a clock signal sent by a clock signal source based on a specific protocol in real time, and receiving a reference time sent by a master device node and a synchronization code corresponding to the clock signal, wherein the reference time is obtained by the master device node parsing the clock signal; When a rising edge of the clock signal is detected, a third conversion time is calculated, where the third conversion time is a time in millisecond level; If the third conversion time is outside a preset time range, the system time is calculated based on the reference time and the synchronization code, and the preset time range is determined based on the time interval between any two adjacent rising edges of the clock signal.

6. The method according to claim 5, characterized in that When a rising edge of the clock signal is detected, calculating a third conversion time comprises: When a rising edge of the clock signal is detected, reading a second clock count value of the timer of the slave device node; The third conversion time is calculated using the second clock count value.

7. The method according to claim 6, characterized in that After calculating the third conversion time, it also includes: If the third conversion time is within the preset time range, a fourth conversion time is calculated based on the rising edge of the clock signal and the second clock count value, and the second clock count value is cleared; The system time is calculated based on the reference time, the fourth conversion time and the synchronization code.

8. A master device node, characterized in that: The master device node comprises: A receiving unit, configured to receive in real time a clock signal sent by a clock signal source based on a specific protocol, and parse the clock signal to obtain a reference time; A first calculation unit, configured to calculate a first conversion time when a rising edge of the clock signal is detected, wherein the first conversion time is a time in millisecond level; a second calculation unit, configured to calculate a system time based on the reference time and the first conversion time if the first conversion time is outside a preset time range, wherein the preset time range is determined based on a time interval between any two adjacent rising edges of the clock signal; The sending unit is used to send the reference time and a synchronization code corresponding to the clock signal to a slave device node, so that the slave device node obtains the system time based on the reference time and the synchronization code.

9. A slave device node, characterized in that: The slave device node comprises: A receiving unit, configured to receive in real time a clock signal sent by a clock signal source based on a specific protocol, and to receive a reference time sent by a master device node and a synchronization code corresponding to the clock signal, wherein the reference time is obtained by parsing the clock signal by the master device node; A first calculation unit, configured to calculate a third conversion time when a rising edge of the clock signal is detected, wherein the third conversion time is a time in millisecond level; The second calculation unit is used to calculate the system time based on the reference time and the synchronization code if the third conversion time is outside a preset time range, and the preset time range is determined based on the time interval between any two adjacent rising edges of the clock signal.

10. A time synchronization device, characterized in that: The device comprises: a clock signal source, the master device node described in claim 8, and the slave device node described in claim 9.