Jiangyin PLC Training: 28 PLC Programming Standards and Recommendations Not Shared by Senior Engineers

The Design Requirements for a Perfect PLC Program

A complete PLC program is not just about making the system operational; it also requires comprehensive comments, excellent architecture, good scalability, a complete alarm protection system, and a simulation system before operation.

Jiangyin PLC Training: 28 PLC Programming Standards and Recommendations Not Shared by Senior Engineers

1. Simplicity

Make the PLC program as simple as possible. Simplicity means using standardized program frameworks and simple instructions whenever possible.

To achieve simplicity, optimize the program structure on a large scale by simplifying the program with flow control instructions, and on a smaller scale, replace single-function instructions with more powerful ones, while also paying attention to the order of instructions.

2. Readability

The designed program must have good readability. This not only helps the programmer deepen their understanding of the program for debugging but also makes it easier for others to read and maintain the program. If necessary, it can also facilitate program promotion.

To enhance readability, the program should be as clear as possible. Pay attention to hierarchy, implement modular design, and use object-oriented methods. Utilize standard designs as much as possible.

In special cases where language programming is used, ladder diagram programming should be preferred for ease of reading.

Moreover, I/O allocation should be systematic for easier memorization and understanding. If necessary, add comments. The use of internal components should also follow a systematic approach; do not use them arbitrarily.

Readability should be considered from the beginning 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 components may make a previously clear program somewhat chaotic. Therefore, leave some room for adjustments during debugging, and after debugging, tidy up the program to enhance its quality.

Program comments should at least cover the following aspects:

A. System comments: Copyright company of the entire program and its purpose.

B. Program block comments: Main purpose of this program block and its author.

C. Segment comments: Purpose of this segment of code.

D. Variable comments: Importance is self-evident, including I/O comments and intermediate variable comments.

Jiangyin PLC Training: 28 PLC Programming Standards and Recommendations Not Shared by Senior Engineers

Regarding confidentiality, I believe it should be considered in the encryption algorithm of the program or blocks, rather than using reduced comments as a clever trick.

3. Correctness

The PLC program must be correct and verified through actual work to prove its proper functioning. This is the most fundamental requirement for a PLC program; if this cannot be achieved, nothing else matters.

To ensure correctness, instructions must be used accurately, and internal components must be used correctly. Accurate use of instructions is linked to a clear understanding of their meanings and usage conditions. If necessary, small programs can be written to test unclear instructions.

For the same instruction, due to different production batches or series models of PLCs, some instruction details may vary, so refer carefully to the programming manual.

Correct use of internal components is also important. For example, some PLCs have power-off protection while others do not. Ensure that power-off protection components are used where required, and vice versa.

In summary, accurate use of instructions and correct use of internal components are fundamental requirements for ensuring that the programmed PLC operates correctly.

For instance, Siemens’ rising and falling edges require the use of variables with memory functions as intermediate variables, such as M points or DB points; using the FC’s temp variable will cause issues.

4. Reliability

The program must not only be correct but also reliable. Reliability reflects the stability of the PLC program, which is also 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 not very reliable or stable, which indicates poor programming.

A good PLC program can identify abnormal working conditions and connect them back to normal conditions, making the program adaptable to various situations. A good PLC program can reject illegal operations without leaving any “traces” and only accepts legal operations.

Interlocking is a common method to reject 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 modification or redesign of the program.

Redesigning the program is necessary when changing the PLC’s process requirements, which involves not only reprogramming but also reallocating I/O. In most cases, reprogramming is not required, and minor modifications will suffice. This requires the program to be flexible and easy to modify.

Modifiability also implies elasticity, meaning that only minor changes are needed to achieve parameter changes or modifications in actions.

6. Scalability

Many programs may be written 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.

Leave enough margin in hardware, and when writing software, consider manual, automatic, and semi-automatic operations, leaving space accordingly.

Jiangyin PLC Training: 28 PLC Programming Standards and Recommendations Not Shared by Senior Engineers

7. Complete Alarm System

PLC systems are often used in industrial environments, where every accident can cause varying degrees of loss. To minimize losses during accidents or to handle them effectively, it is essential to emphasize the alarms and protections of the PLC, making it an important component of the system.

8. Program Simulation

To ensure the progress of on-site debugging or to demonstrate to clients, it is often necessary to conduct full automatic simulations of the program before arriving on-site. For this, a simulation portion must be added to the program, which will be disconnected after normal on-site operation. To enable simulation functionality, the following tasks must be completed:

(1) Convert the actual PLC I/O points into intermediate variables or data block variables;

(2) Write simulation programs for each device according to process requirements.

In the process of designing PLC programs, those that meet the above requirements can be considered good programs.

PLC Programming Standards

1.Select the appropriate PLC model and I/O point count, and choose special function modules when there are special functional requirements.

2.Familiarize yourself with the programming instructions and compilation software of the selected PLC.

3.Plan soft components, including internal relays, holding relays, data registers, timers, counters, etc.

4.Plan the program, generally in the order of fault extraction, fault handling, manual handling, automatic handling, and output handling. For larger projects or equipment, process the program in segments or blocks by functional units. For example, in an automated production line with elevators, transfer devices, and lifting rotating devices, program according to these units.

Jiangyin PLC Training: 28 PLC Programming Standards and Recommendations Not Shared by Senior Engineers

5.Before the segmented program, add a brief segment comment explaining the function of this segment, and if necessary, indicate the corresponding process flow. The order of segmented or block programs in the overall program should generally follow the process flow for better readability.

6.Before program design, abstract the equipment, extracting common factors such as stop, emergency stop, overload, over-limit, timeout, safety light curtain, collision stop, door switches, etc., and place them in the start loop or main control, as a prerequisite for the entire program structure. Based on this, divide the program into two main functional areas: automatic and manual.

7.Extract common factors in the manual functional area, such as manual control and factors that endanger equipment and personnel safety, and place them in the manual main control and interlocking loop to protect, shield, and alarm manual control.

8.Extract common factors in the automatic functional area, such as automatic, over-limit, timeout, etc., and place them in the automatic main control and interlocking loop to protect, shield, and alarm equipment under automatic control. A general principle is to strictly limit equipment entry while allowing more lenient exit, ensuring safety.

9.During program design, a total reset function should be designed to allow users to quickly restore 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 mode 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, meaning the same output statement or output coil should not appear two or more times in the program. For outputs under different mode conditions, use intermediate relays for transfer, and finally consolidate them to the output point.

12.When using touch screens, do not program other functional aspects in the control and status areas shared by the touch screen and PLC.

13.For special modules of the PLC, check whether their control and status areas occupy working words before use. If they do, do not program these working words for other purposes.

Jiangyin PLC Training: 28 PLC Programming Standards and Recommendations Not Shared by Senior Engineers

14.PLC inputs, outputs, intermediate relays, timers, counters, data registers, etc., must have Chinese comments. Inputs and outputs should also have component names and positions. For corresponding input points, it is generally assumed that peripheral switches are connected to NO contacts; those requiring NC contacts must be indicated in the comments. All comments should be clear and unambiguous, minimizing the use of vague terms.

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, and distributed to at least two people to prevent loss of the password leading to inability to open the program.

Programming Recommendations

1.When the PLC and the upper computer (or touch screen) form a monitoring system, the screen often needs control modes such as “manual” and “automatic” (generally 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; when selecting “automatic,” move 2 to the same register VB10. By checking the data in the register, you can determine the control mode of the system. This approach is easy to understand and avoids the complexity of interlocking programs.

Jiangyin PLC Training: 28 PLC Programming Standards and Recommendations Not Shared by Senior Engineers

2.If the program has analog control and the read analog value has minimal error, a time filter can be used to delay for a period. If the read data has significant errors, other filtering methods, such as averaging, should be employed. Relevant materials can be consulted.

3.During program debugging (especially when modifying equipment, and your program is added to the original program), if a condition is met but the output coil does not activate, check whether your program is between such statements as JUMP/go to, etc. Another possibility is that after an interrupt, the condition is met but the output does not activate; generally, this means 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, using a +10+10 control mode is very convenient. The idea is to preset a register, initialized to 0. When the system starts, add 10 to it, making the register 10; when the register equals 10, the first action can be performed. After completing the first action, add another 10, making the register 20, allowing the second action to be performed, and so on. This way, by checking the data in the register, you can determine which action to complete. When a jump action is needed, you can add +20/+30, etc., depending on the actual needs.

Why add 10 instead of 1? Because after adding 10, if a segment is inserted, you can choose any position within those 10 spare places.

5.When designing the program, if a process fault occurs (not controlled by the control system), it is best to maintain the fault phenomenon and have visual and audible alarms until the operator resets it, to inform them that a fault has occurred in the system. Otherwise, if the system stops, others may think there is a problem with your program. This is generally something to consider when designing a new system.

Jiangyin PLC Training: 28 PLC Programming Standards and Recommendations Not Shared by Senior Engineers

6.For frequently called subprograms, they can be made into sub-modules for frequent invocation.

7.Since the various steps of machinery in the working cycle require a certain amount of time to execute, and these times have certain limits, these times can be used as a reference. When the action of the step to be detected begins, start a timer, setting the timer’s preset value to be 20% to 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 program and starting the alarm or shutdown program, which is commonly referred to as over-timing 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, try to design outputs to activate only when needed, stopping output once in position, rather than designing them to output continuously and only stopping when required.

10.The principle of action for executing components should be to prefer not to move rather than to move erratically!

11.For single device control: each device must have soft manual/automatic switching, and during soft manual operation, it should have start/stop functionality. When switching from automatic to soft manual, the device should not stop; when switching from soft manual to automatic, the device’s start/stop depends on the automatic program.

12.Single devices (pumps, fans, and other large equipment) should run for a full 24 hours.

Need to Learn PLC Courses

You canscan the code to add the teacher

Jiangyin PLC Training: 28 PLC Programming Standards and Recommendations Not Shared by Senior Engineers

Leave a Comment