High-precision synchronization method for multi-PLC controller instruction output based on soft timer
By establishing a shared variable mechanism and a periodic synchronization mechanism among multiple PLC controllers, the problem of low PLC instruction synchronization accuracy caused by soft timers is solved, and high-precision instruction synchronization is achieved, which is suitable for various control systems.
Patent Information
- Application Number
- CN202211644676.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-20
- Publication Date
- 2025-08-15
- Estimated Expiration
- 2042-12-20
AI Technical Summary
The actual execution time of PLC periodic tasks based on soft timers is uncertain, resulting in low synchronization accuracy of output of multiple sets of PLC instructions.
By establishing a shared variable mechanism among multiple PLC controllers, selecting the master and slave controllers, setting the periodic scanning task using the soft timer, and synchronizing the PLC controllers through the periodic synchronization mechanism to ensure the consistent timing of the command output.
Without changing the hardware structure of the control system, the synchronization accuracy of multiple sets of PLC instructions is improved, the cost is reduced, and it is applicable to various types of network structures to achieve high-precision instruction synchronization.
Smart Images

Figure CN116184920B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to a multi-PLC instruction output synchronization method, in particular to a multi-PLC controller instruction output high-precision synchronization method based on a soft timer. Background Art
[0002] Large-scale distributed control systems have numerous nodes and are widely distributed. To implement complex control logic, the control system is often equipped with multiple PLCs (Programmable Logic Controllers) to provide precise control instructions to various devices. The synchronization accuracy of each instruction output must meet certain requirements to ensure that various devices work together.
[0003] In order to enable multiple PLCs to output instructions simultaneously according to the established time, the operator station converts the established future time into relative time (relative to the current time) and writes it into each PLC. After each PLC receives the relative time transmitted from the operator station, it starts the local countdown and outputs the instruction when the local countdown is consistent with the received relative time.
[0004] Programmable logic controllers (PLCs) use tasks to execute instruction code. Periodic tasks are executed cyclically at a predetermined interval (e.g., 1ms). Depending on the type of PLC, periodic task implementations can be broadly categorized into two types: hardware timer implementation and software timer implementation.
[0005] For PLCs using software timers, a software timer (or soft timer for short) is a system interface provided by the PLC's internal real-time operating system. During implementation, the system tick cycle is used as the timing unit, and a callback function is called every specified time, where information is processed. The execution of a soft timer relies on context switching within the operating system and is very likely to be interrupted by other interrupts. Consequently, the actual period of a PLC's periodic task is subject to uncertainty (for example, for a 1ms periodic task, the actual execution period of the soft timer is 1 + δt, with some jitter in the δt value). Summary of the Invention
[0006] The purpose of the present invention is to provide a high-precision synchronization method for the instruction output of multiple PLC controllers based on a soft timer, so as to solve the technical problem that the actual execution time of PLC periodic tasks based on soft timers is uncertain and cannot be directly applied to time measurement, resulting in low synchronization accuracy of multiple sets of PLC instruction outputs.
[0007] To achieve the above object, the present invention provides a high-precision synchronization method for multi-PLC controller instruction output based on a soft timer, wherein a shared variable mechanism is established between the multi-PLC controllers. The method is special in that it includes the following steps:
[0008] Step 1: Determine the absolute time T0 when n sets of PLC instructions of n PLC controllers are output simultaneously, n>1, and convert each absolute time T0 into a value relative to the current time T t The relative time t0 = T0-T t ; Start all PLC controllers to operate normally and send the relative time t0 to n PLC controllers;
[0009] Step 2: Select one of the PLC controllers as the master controller, and the other PLC controllers as slave controllers;
[0010] Step 3: Set the periodic scanning task based on the soft timer of each PLC controller, and the scanning period is ΔS; at the same time, establish a periodic synchronization mechanism between each PLC controller, and the periodic synchronization mechanism is that the slave controller has a time interval ΔT and the master controller has a time interval t r Synchronize once, ΔS<ΔT;
[0011] Step 4: Execute the periodic scanning task until n sets of PLC instructions are output synchronously; the master controller cyclically executes steps 4.1 to 4.3, and the slave controller cyclically executes steps 4.4 to 4.6;
[0012] Step 4.1: After receiving the relative time t0, the main controller calls the local system time to record the local timestamp t1 of the receiving moment;
[0013] Step 4.2: The main controller obtains the local timestamp t in the i-th scanning cycle i , and calculate the local running time t corresponding to the scan cycle r =t i -t1;
[0014] Step 4.3: The main controller determines its running time t r The size of the relative time t0 received; if t r <t0, the main controller does not output PLC instructions; if t r ≥t0, the main controller immediately outputs PLC instructions;
[0015] Step 4.4: Initialize the running time of the slave controller to 0, and update it to the running time of the master controller t at every interval ΔT through the periodic synchronization mechanism. r ;
[0016] Step 4.5: Calculate the running time m corresponding to the scan cycle from the controller in the i-th scan cycle. i =m i-1 +ΔS, and m i As the local running time t of the slave controller r ; Among them, mi-1 The corresponding scanning period is m i The previous cycle of the corresponding scanning cycle;
[0017] Step 4.6: Determine t from the controller r With the size of the relative time t0, if t r <t0, the slave controller does not output PLC instructions; if t r ≥t0, the slave controller immediately outputs PLC instructions, thereby achieving synchronization of n sets of PLC instruction outputs.
[0018] Furthermore, the accuracy of the relative time t0 is equal to or higher than the synchronization time accuracy of n sets of PLC instructions.
[0019] Furthermore, the time accuracy of the scanning period ΔS is equal to or less than the synchronization time accuracy of n sets of PLC instructions.
[0020] Furthermore, the input and output update period of all PLC controllers is less than or equal to the synchronization time accuracy of n sets of PLC instructions.
[0021] Furthermore, the soft timer is a timer provided by the PLC controller.
[0022] Beneficial effects of the present invention:
[0023] 1. The present invention proposes a high-precision synchronization method for the instruction output of multiple PLC controllers based on a soft timer. By periodically synchronizing shared variables between each PLC controller, the synchronization accuracy of multiple sets of PLC instructions can be effectively improved without changing the hardware structure of the control system. It has the characteristics of low cost and strong portability.
[0024] 2. The high-precision synchronization method for multiple PLC instruction outputs based on soft timers proposed in the present invention effectively utilizes soft timers and shared variable mechanisms to achieve high-precision instruction synchronization, and is suitable for various types of PLC synchronization control with shared variable mechanisms.
[0025] 3. The method proposed in the present invention is a high-precision synchronization method for the instruction output of multiple PLC controllers based on a soft timer. It is applicable to various types of network structures. The control system does not require an additional high-precision time source unit, nor does it require network time synchronization to achieve synchronous instruction output of multiple PLCs. It has low cost, simple and efficient system.
[0026] 4. The synchronization accuracy of multiple sets of PLC instructions in the present invention is not affected by various conditions such as the number of PLCs involved in the synchronization, the complexity of the control program, the length of the program operation cycle, etc., and can be widely used in various control scenarios. This method has the characteristics of high real-time, high reliability, and high availability. BRIEF DESCRIPTION OF THE DRAWINGS
[0027] Figure 1 It is a schematic diagram of the network structure of a distributed control system;
[0028] Figure 2 is a PLC instruction synchronization flow chart of the main controller in an embodiment of the present invention;
[0029] Figure 3 1 is a PLC instruction synchronization flow chart of the slave controller in an embodiment of the present invention. In the figure, ΔS represents the operating cycle of the periodic task; ΔT represents the synchronization interval time, that is, the synchronization period of the master controller and the slave controller. DETAILED DESCRIPTION
[0030] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. All other embodiments obtained by ordinary technicians in this field based on the embodiments of the present invention without making any creative efforts shall fall within the scope of protection of the present invention.
[0031] PLC communication involves connecting PLC controllers, computers, and various field devices located in different locations via communication media. This allows for efficient data transmission, exchange, and processing using a specific communication method, in accordance with a specified communication protocol. Communication between PLC controllers typically uses Ethernet as a communication link, establishing various control networks such as 1:1, 1:N, and M:N. By configuring shared variables and synchronization cycles, one-way or two-way data transmission between PLC controllers is achieved.
[0032] The main factors that cause the output of multiple soft-timer-based PLC instructions to be out of sync are: (1) the reference time for each PLC controller to start the local countdown is different; (2) the internal clocks of each PLC controller are out of sync; and (3) the actual execution cycle of the soft timer has jitter, which makes it unsuitable for long-term time measurement.
[0033] This paper proposes a high-precision instruction synchronization method for multiple PLCs based on a soft timer. Leveraging the PLC's soft timer and the shared variable mechanism between PLCs, it enables high-precision instruction synchronization across multiple PLCs. This method can be widely applied to various types of high-precision distributed control systems based on PLCs.
[0034] The present invention is mainly aimed at PLCs that adopt a soft timer implementation mode.
[0035] like Figure 1As shown in the figure, a distributed control system generally includes an operator station, Ethernet communication, and n PLC controllers, where n > 1. Each of the n PLC controllers is connected to the operator station. Communication links exist between the PLC controllers, supporting variable sharing. The operator station is responsible for controlling the operational processes and remotely monitoring the status of each PLC controller. It also converts predetermined future times into relative times (relative to the current moment) and writes them to each PLC controller via Ethernet.
[0036] Combine Figure 2 and Figure 3 As shown, the method for synchronizing multiple PLC high-precision instructions based on a soft timer provided in this embodiment specifically includes the following steps:
[0037] Step 1: The operator station determines the absolute time T0 of the n sets of PLC instructions output simultaneously by n PLC controllers according to actual needs, and converts the absolute time T0 into the relative time T t The relative time t0 = T0-T t ; Start all PLC controllers to operate normally, and send each relative time t0 to the corresponding PLC controller; the accuracy of the relative time t0 is equal to or higher than the synchronization time accuracy of n sets of PLC instructions.
[0038] Step 2: According to the specific layout of the control system, number the n PLC controllers as 1, 2, 3, ..., n in sequence, select one of the PLC controllers as the master controller, and the other PLC controllers as slave controllers.
[0039] Step 3. All PLC controllers set periodic scanning tasks based on soft timers, with a timed scanning period of ΔS. In each periodic scanning task, the master controller cyclically executes steps 4 to 6, and the slave controller cyclically executes steps 7 to 9. The time accuracy of the scanning period ΔS is no greater than the synchronization time accuracy of n sets of PLC instructions. A synchronization mechanism is periodically established between each PLC controller, and the periodic synchronization mechanism is that the slave controller's interval time ΔT is equal to the running time t of the master controller. r Synchronize once, ΔS<ΔT; the running time t r Synchronous variables.
[0040] That is to say, all PLC controllers have soft timer functions and can obtain local system time in real time. The accuracy of the called local system time is not lower than the synchronization time accuracy requirements of n sets of PLC instructions; within the same interval time ΔT, the time error accuracy between the time calculated cumulatively according to its own scan cycle ΔS and the interval time ΔT is less than or equal to the synchronization time accuracy of n sets of PLC instructions; the input and output update cycle of all PLC controllers is less than or equal to the synchronization time accuracy of n sets of PLC instructions.
[0041] Step 4: After receiving the relative time (variable) t0 transmitted by the operator station, the main controller calls the local system time and records the local timestamp t1 of the receiving moment.
[0042] Step 5: The main controller obtains the local timestamp in the periodic scanning task. The local timestamp obtained in the i-th scanning cycle is t i , calculate the local running time t corresponding to the scan cycle r =t i -t1.
[0043] Step 6: The main controller determines the current running time t r The relative time t0 of the transmission to the operator station; if t r <t0, the periodic scan task does not output PLC instructions; if t r ≥t0, the periodic scanning task immediately outputs PLC instructions.
[0044] Step 7: Initialize the running time of the slave controller to 0, and update it to the running time of the master controller through the periodic synchronization mechanism every interval ΔT. r ;
[0045] Step 8: Calculate the running time m corresponding to the scan cycle from the controller in the i-th scan cycle. i =m i-1 +ΔS, and m i As the local running time t of the slave controller r ; Among them, m i-1 The corresponding scanning period is m i The previous cycle of the corresponding scanning cycle;
[0046] Step 9: Determine the local running time t obtained in step 8 from the controller r The relative time t0 of the transmission to the operator station, if t r <t0, the slave controller does not output PLC instructions; if t r ≥t0, the slave controller immediately outputs PLC instructions, thereby achieving synchronization of n sets of PLC instruction outputs.
[0047] The above description is merely a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any changes or substitutions within the technical scope disclosed in the present invention shall be covered by the scope of protection of the present invention. Therefore, the scope of protection of the present invention shall be subject to the scope of protection of the claims.
Claims
1. A high-precision synchronization method for multi-PLC controller instruction output based on a soft timer, wherein a shared variable mechanism is established between the multi-PLC controllers, characterized in that: The following steps are involved: Step 1: Determine the absolute time T0 when n sets of PLC instructions of n PLC controllers are output simultaneously, n>1, and convert each absolute time T0 into a value relative to the current time T t The relative time t0 = T0-T t ; Start all PLC controllers to operate normally and send the relative time t0 to n PLC controllers; Step 2: Select one of the PLC controllers as the master controller, and the other PLC controllers as slave controllers; Step 3: Set the periodic scanning task based on the soft timer of each PLC controller, and the scanning period is ΔS; at the same time, establish a periodic synchronization mechanism between each PLC controller, and the periodic synchronization mechanism is that the slave controller has a time interval ΔT and the master controller has a time interval t r Synchronize once, ΔS<ΔT; Step 4: Execute the periodic scanning task until n sets of PLC instructions are output synchronously; the master controller cyclically executes steps 4.1 to 4.3, and the slave controller cyclically executes steps 4.4 to 4.6; Step 4.1: After receiving the relative time t0, the main controller calls the local system time to record the local timestamp t1 of the receiving moment; Step 4.2: The main controller obtains the local timestamp t in the i-th scanning cycle i , and calculate the local running time t corresponding to the scan cycle r =t i -t1; Step 4.3: The main controller determines its running time t r The size of the relative time t0 received; if t r <t0, the main controller does not output PLC instructions; if t r ≥t0, the main controller immediately outputs PLC instructions; Step 4.4: Initialize the running time of the slave controller to 0, and update it to the running time of the master controller t at every interval ΔT through the periodic synchronization mechanism. r ; Step 4.5: Calculate the running time m corresponding to the scan cycle from the controller in the i-th scan cycle. i =m i-1 +ΔS, and m i As the local running time t of the slave controller r ; Among them, m i-1 The corresponding scanning period is m i The previous cycle of the corresponding scanning cycle; Step 4.6: Determine t from the controller r With the size of the relative time t0, if t r <t0, the slave controller does not output PLC instructions; if t r ≥t0, the slave controller immediately outputs PLC instructions, thereby achieving synchronization of n sets of PLC instruction outputs.
2. The method for high-precision synchronization of multiple PLC controller instruction outputs based on a soft timer according to claim 1 is characterized in that: The accuracy of the relative time t0 is equal to or higher than the synchronization time accuracy of n sets of PLC instructions.
3. The method for high-precision synchronization of multiple PLC controller instruction outputs based on a soft timer according to claim 1 or 2, characterized in that: The time accuracy of the scanning period ΔS is equal to or less than the synchronization time accuracy of n sets of PLC instructions.
4. The method for high-precision synchronization of multiple PLC controller instruction outputs based on a soft timer according to claim 3 is characterized in that: The input and output update period of all PLC controllers is less than or equal to the synchronization time accuracy of n sets of PLC instructions.
5. The method for high-precision synchronization of multiple PLC controller instruction outputs based on a soft timer according to claim 4 is characterized in that: The soft timer is a timer provided by the PLC controller.
Citation Information
Patent Citations
Method for calculating execution time of PLC scanning task
CN115202284A
Safety control method for industrial safety PLC controller
WO2022000716A1