

A complete PLC program is not just about getting the system to run; it also requires complete comments, excellent architecture, good scalability, a comprehensive alarm protection system, and a simulation system before operation.
1. Simplicity
Keep the PLC program as simple as possible. Simplicity means using standardized program frameworks and simple instructions whenever possible.
To simplify the program, focus on optimizing the program structure with control flow instructions, using powerful instructions to replace single-function instructions, and paying attention to the order of instructions.
2. Readability
The designed program should have good readability. This not only helps the designer deepen their understanding of the program for debugging but also allows others to understand your program and facilitates maintenance. If necessary, it can also promote the program.
To enhance readability, the program should be as clear as possible, with attention to hierarchy and modular design, potentially using object-oriented methods. Standard designs should be utilized frequently.
In special cases where language programming is used, ladder diagram programming should be preferred for ease of reading.
I/O allocation should be systematic for easy memory and understanding. If necessary, annotations should be made. The use of internal devices should also follow a pattern; do not use them arbitrarily.
Readability should be considered from the start of program design. This is not easy to achieve completely, as during debugging, the addition or removal of instructions and changes in the use of internal devices may make a previously clear program somewhat chaotic. Therefore, allow for some flexibility in debugging, and after debugging, organize the program to ensure higher quality.
Program comments should at least cover the following aspects:
A. System Comments: Copyright company and purpose of the program
B. Program Block Comments: Main purpose of this program block and author
C. Segment Comments: Purpose of this segment of code
D. Variable Comments: Importance speaks for itself, including I/O comments and comments on intermediate variables
As for confidentiality, I believe it should be considered in the encryption algorithm or block encryption, rather than through reducing comments as a clever trick.
3. Correctness
PLC programs must be correct and verified through actual work to prove they operate correctly. This is the fundamental requirement for PLC programs; if this cannot be achieved, nothing else matters.
To ensure correctness, instructions must be used accurately, and internal devices must be used correctly. Accurate use of instructions is tied to a clear understanding of their meaning and usage conditions. If necessary, small programs can be written to test unclear instructions.
The same instruction may have different details due to different production batches or model series of PLCs; consult the programming manual carefully.
Correct use of internal devices is also crucial. Some PLCs have power-off protection while others do not. Ensure that power-off protection devices are used where required, and vice versa.
In summary, accurate use of instructions and correct use of internal devices are the fundamental requirements for ensuring the correctness of PLC programs.
For example, Siemens’ rising and falling edges require using variables with memory functions as intermediate variables, such as M points or DB points; using the FC’s temp variable would cause issues.
4. Reliability
The program must not only be correct but also reliable. Reliability reflects the stability of the PLC program, which is a basic requirement.
Some PLC programs may work correctly under normal working conditions or legal operations, but fail under abnormal conditions (such as temporary power outages followed by quick reconnection) or illegal operations (such as pressing buttons out of order or pressing several buttons simultaneously). Such programs are unreliable or unstable, indicating poor quality.
Good PLC programs can recognize abnormal working conditions and connect them with normal conditions, adapting the program to various situations. They can refuse illegal operations without leaving any “traces” and only accept legal operations.
Interlocking is a common method to refuse illegal operations, often used in relay circuits, and PLCs can inherit this method.
5. Modifiability
The program should be easy to modify.
One of the characteristics of PLCs is convenience, allowing flexible adaptation to various situations. This is achieved through modifications or redesigning the program.
Redesigning the program is required when changing the PLC’s process requirements; this involves not only recompiling the program but also reallocating I/O. In most cases, recompiling is unnecessary, and minor modifications will suffice. This requires the program to be easily modifiable.
Modifiability also implies flexibility, meaning that only minor changes are needed to alter parameters or modify actions.
6. Expandability
Many programs may be compiled before arriving on-site, but additional programs may need to be added on-site. To avoid disrupting the overall system structure, it is necessary to reserve some space in each functional area as a backup.
Sufficient hardware margins should be left, and software should consider manual, automatic, and semi-automatic operations, leaving appropriate positions available.
7. Comprehensive Alarm System
PLC systems are often used in industrial environments, where every incident can cause varying degrees of loss. To minimize losses during incidents or for pre-incident processing, it is crucial to emphasize PLC alarms and protection, highlighting them as an important component of the system.
8. Program Simulation
To ensure on-site debugging progress or to demonstrate to clients, it is often necessary to conduct full automatic simulations of the program before arriving on-site. This requires adding a simulation program section, which should be disconnected after normal site operation. To enable simulation functionality, the following tasks must be completed:
(1) Convert the actual PLC’s I/O points to intermediate variables or data block variables;
(2) Write simulation programs for each device based on process requirements.
A PLC program that meets the above requirements can be considered a good program.
1.Select the appropriate PLC model and I/O points; choose special function modules when special functionalities are required.
2.Familiarize yourself with the selected PLC programming instructions and compilation software.
3.Conduct soft component planning, including internal relays, holding relays, data registers, timers, counters, etc.
4.Plan the program, generally in the order of fault extraction, fault handling, manual processing, automatic processing, and output processing. For larger projects or equipment, process them in segments or blocks by functional units, such as an automated production line with elevators, transfers, and lifting rotation devices, which should be programmed in segments by the above units.
5.Before writing the segmented programs, add brief segment comments explaining the functionality of this segment, and if necessary, indicate the corresponding process flow. The sequence of segmented or block programs in the overall program should generally follow the order of the process flow to enhance program readability.
6.Before program design, abstract the equipment, extracting common factors such as stop, emergency stop, overload, over-limit, timeout, safety light curtains, collision stops, door switches, etc., placing them in the startup loop or primary control and interlocking loops as a major premise for the entire program structure. Based on this, divide the program into automatic and manual functional areas.
7.Extract common factors from the manual functional area of the program structure, such as manual operations and factors affecting equipment and personnel safety, placing them in the manual primary control and interlocking loops to protect, shield, and alarm manual control.
8.Extract common factors from the automatic functional area of the program structure, such as automatic operations, over-limit, timeout, etc., placing them in the automatic primary control and interlocking loops to protect, shield, and alarm equipment under automatic control. A general principle is to strictly limit equipment entry under safe conditions while allowing more lenient exit restrictions.
9.During program design, a general reset function should be designed to facilitate users in quickly restoring normal operation in case of equipment failure. The total reset should fully consider the safety of equipment and personnel during the reset process.
10.When switching from automatic to manual mode, the program should clear the outputs and intermediate states from the automatic mode. Especially when using the SET instruction in automatic mode, it must be cleared with the RESET instruction in manual mode.
11.It is strictly forbidden to use double outputs in program compilation, i.e., the same output statement or output coil appearing two or more times in the program. For outputs of the same point under different mode conditions, use intermediate relays to transfer, and finally consolidate them to the output point.
12.When using touch screens, the control and status areas shared by the touch screen and PLC must not be programmed for other functionalities.
13.For special PLC modules, check before use whether their control and status areas occupy working words; if they do, these working words must not be programmed for other functionalities.
14.PLC inputs, outputs, intermediate relays, timers, counters, data registers, etc., must have Chinese comments. Inputs and outputs must also have component names and positions. Generally, the default assumption is that peripheral switches are connected with NO contacts; those requiring NC contacts must be indicated in the comments. All comments should be clear and unambiguous, avoiding vague references.
15.After engineering debugging is completed, the final software program must be retained, and the saved file name should include project number/author/date information/version number, etc.
16.Regarding program encryption: The password for encrypted programs must be saved in a dedicated file, indicating the corresponding username + password + permissions, distributed to at least two people to prevent the loss of the password leading to an inability to open the program.
1.When PLC and upper-level computers (or touch screens) form a monitoring system, control modes such as “manual” and “automatic” often need to be present on the screen (usually only one can be active at a time). In the program, the “MOV” instruction can be used. For example, when selecting “manual,” move constant 1 to register VB10, and when selecting “automatic,” move 2 to the same register VB10. By checking the data in the register, the control mode of the system can be determined. This approach is easy to understand and avoids complex interlocking programs.
2.When controlling analog quantities in the program, if the read analog quantity has minimal error, a time filter can be applied, introducing a delay. If the read data has significant errors, other filtering methods, such as averaging, should be adopted. Relevant materials can be consulted.
3.During program debugging (especially when modifying devices, where your program is added to the original device’s program), if conditions are met in the program statement but the output coil does not activate, check whether your program lies between such statements as JUMP/go to, etc. Another possibility is that after interrupting the program, conditions are met but the output is not activated, which usually indicates that this segment of the program is not being scanned.
4.In sequential control programs, where one action is completed before moving to the next, a +10+10 control mode can be very convenient. The idea is to preset a register, initialized to 0. When the system starts, add 10 to it, making the register 10, which allows the first action to be performed. After completing the first action, add another 10, making the register 20 for the second action, and so on. By checking the data in the register, the current action can be determined. When a jump action is needed, you can add +20/+30, etc., depending on the actual needs.
Why add 10 instead of 1? Because adding 10 allows for inserting an action in any of the 10 vacant slots.
5.When designing the program, if a process fault occurs (not controlled by the control system), it is best to retain the fault phenomenon and have visual and auditory alarms until the operator resets it, so they are aware of the fault. Otherwise, if the system shuts down, others may think the issue lies with your program. This should be considered especially when designing a new system.
6.For frequently called sub-programs, they can be made into sub-modules for frequent invocation.
7.Since the operation of production machinery requires a certain amount of time for each step in the working cycle, and these times have certain limits, these times can be used as a reference. When a step action is about to be detected, start a timer, setting the timer’s preset value to 20%–30% longer than the normal duration of that action. The timer’s output signal can be used for alarms or automatic shutdown devices. If the action time of a certain step exceeds the specified time and does not transition to the next step, the timer will issue a fault signal, stopping the normal working cycle and initiating the alarm or shutdown procedure, which is commonly referred to as over-cycle protection.
8.Some safety detection switches (such as emergency stop buttons, safety light curtains, limit switches, etc.) should use normally closed (NC) inputs.
9.For safety and energy-saving considerations, outputs should be designed to activate only when needed, stopping once in position, rather than being designed to continuously output and only disconnect when stopping is required.
10.The action principle of executing elements should be to avoid unnecessary movements!
11.For single device control: each device must have a soft manual/automatic switch, and during soft manual operation, it should be able to start/stop the device; switching from automatic to manual should not cause the device to stop; switching from manual to automatic should depend on the automatic program.
12.Single devices (pumps, fans, and other large equipment) should run continuously for 24 hours.
Complete Question Bank for 2021 Electrician Beginner Exam (includes answers)
Having trouble troubleshooting inverter faults? Just one click away!
Want to sweep through all electrical exam questions with one click? Have you got this magic tool yet?
Which of the five major electrical drawing software (CAD, Eplan, CADe_simu…) do you pick?
Latest electrical version CAD drawing software, with a super detailed installation tutorial!
Latest electrical drawing software EPLAN, with a super detailed installation tutorial!
Common issues faced by beginners using S7-200 SMART programming software (with download links)
Comprehensive electrical calculation EXCEL sheets, generated automatically! No need to ask for electrical calculations!
Bluetooth headsets, electrician/PLC introductory books available? Come and claim your electrical gifts!
Basic Skills in PLC Programming: Ladder Diagrams and Control Circuits (with 1164 practical cases for Mitsubishi PLC)
Still can’t understand electrical diagrams? Grab the basics of electrician diagram recognition and simulation software, theory and practice quickly!
12 free electrician video courses, 10GB of software/e-books, and 30 days of free electrician live classes are available!
