[Introduction] When learning PLC ladder diagram programming, beginners should follow certain rules and develop good habits. Below, using Mitsubishi PLC as an example, we will briefly introduce the rules that need to be followed when programming PLC ladder diagrams. These rules can also be followed when programming other PLCs. We hope this will be helpful to everyone. It should be noted that although this article uses Mitsubishi PLC as an example, these rules can also be followed when programming other PLCs.
1. Trapezoidal steps always begin on the left busbar and end on the right busbar (usually this can be omitted, and only the left busbar needs to be drawn). The left side of each row represents the contact combination, indicating the conditions driving the logic coil, while the logic coil representing the result can only be connected to the right busbar. Contacts cannot appear to the right of a coil. As shown in Figure (a), it should be changed to (b):
2. Connections should be drawn on horizontal lines, not vertical lines. For example, in Figure (a), the relationship between connection X005 and other connections cannot be identified. For this type of bridge circuit, all paths should be drawn individually according to the unidirectional principle of left to right and top to bottom, as shown in Figure (b).
3. When connecting parallel blocks in series, the path with more connection points should be placed on the left side of the ladder diagram (left-heavy, right-light principle); when connecting series blocks in parallel, the parallel path with more connection points should be placed at the top of the ladder diagram (top-heavy, bottom-light principle). This simplifies the program and reduces instruction scan time, which is especially important for large programs. See the diagram below:
4. Dual-coil output is not recommended. If the same component's coil is used twice or more in the same ladder diagram, it is called dual-coil output or coil reuse. Dual-coil output is a common mistake made by beginners in ladder diagram design. In dual-coil output, only the last coil is effective, while the preceding coils are ineffective. This is determined by the scanning characteristics of the PLC.
The PLC CPU operates using a cyclic scanning mode. It generally includes five stages (as shown in the figure): internal diagnostics and processing, communication with peripherals, input sampling, user program execution, and output refresh. When the mode switch is in the STOP position, only the first two stages are executed: internal diagnostics and processing, and communication with peripherals.
1. Input sampling stage
The PLC sequentially reads the status of each input terminal and stores it in an internal unit called the input image register. During program execution, if the input terminal status changes, the corresponding unit information in the input image register does not change. The information only changes during the input sampling phase of the next scan cycle. Therefore, the PLC ignores pulse changes in the switching signals of input terminals that are less than a scan cycle in time.
2. Program execution phase
The PLC starts from program step 0 and scans the user program and performs logical operations in a top-to-bottom and left-to-right order. The PLC performs logical operations based on the contents of the input image area and writes the results to the output image area instead of directly outputting them to the terminals.
3. Output refresh phase
The PLC changes the state of the output terminals based on the contents of the output image area. This is the actual output of the PLC.
The above briefly explains the working principle of a PLC. Below, we will use an example to illustrate why it's not advisable to reuse coils when writing ladder diagram programs. As shown in the diagram, during input sampling, X001=ON, X002=OFF, Y003=ON, and Y004=ON in the input image area are actually written to the output image area. However, as execution continues, because X002=OFF, Y003=OFF, and this result of the subsequent input is written to the output image area, changing the original state of Y003. Therefore, during the output refresh phase, the actual external output is Y003=OFF and Y004=ON. Many beginners have encountered this problem: why is X001 closed, but Y003 has no output? The logic is incorrect. This is actually caused by the use of double coils.
Note: We are saying that it is not advisable (preferably not) to use dual coils. The use of dual coils is not absolutely prohibited; they can be used in some special cases, but this requires considerable programming experience and skills. We will discuss this further below. However, beginners should not take this risk. In fact, as can be seen from the examples above, the reason why reusing coils causes output confusion in Y003 is due to the program executing sequentially from top to bottom. However, if we can change the program execution order to ensure that only one driving logic occurs for each coil at any given time, dual coils can be used. The most common method is to use jump instructions, as shown in the following diagram:
Program Analysis: When M0 is closed, the program jumps to P0 (without executing statement X001). M0's normally closed loop opens, CJP1 does not occur, and the next statement is executed. At this time, Y003 drives the state of X002. When M0 is open, the program executes sequentially and drives T003 according to the state of X001. When M0's normally closed loop closes, the program jumps to P1 and drives Y004 according to the state of X003, thus skipping the statement that drives Y003 through X002. Therefore, only one Y003 drive can occur at any given time. In this case, the use of a double coil is possible.
However, when programming ladder diagrams, we should still try to avoid using double coils, and introducing an auxiliary relay is a common method. See the diagram below:
In Figure (b), contacts X001 and X002 control auxiliary relay M000, contacts X003~X005 control auxiliary relay M001, and the parallel combination of the contacts of the two relays M000 and M001 controls coil Y000. This maintains the logical relationship but transforms a dual-coil system into a single-coil system.