Each set of branches in a rung requires a branch-start and branch-end instruction, plus a next-branch instruction for every branch after the first. A set of branches requires three or more instructions in addition to the contacts appearing on the branches. Inverting Branched Rungsīranches in rungs affect the complexity, size, and speed of ladder logic. Obviously, if the duplicated patterns had been larger or used branches, then the savings in speed and size could have been significant, in addition to improving the readability of the program. It is also clear than the MANU_MODE and AUTO_MODE results will be useful elsewhere in the program. However, this simplification is still desirable because it makes the program easier to understand.
In this short example, the “simpler” code is actually slightly longer than the original – it uses two more instructions. We can name the two patterns MANU_MODE and AUTO_MODE and use them in these two rungs and elsewhere in the program These two patterns can be extracted out into two new rungs above the original rungs. Notice in the example above that two patterns involving the MANU_KEYSW and AUTO_KEYSW contacts are the same between the two rungs. The example avoids defining the automatic operation to focus on the extraction technique.
The example below controls a motor which can run either up or down and must respond differently in Automatic mode than in Manual mode. (As card inputs are defined prior to the start of the program, you need only worry about internal and output bits.) Following this rule will allow your program to react as quickly as possible (one scan) and avoid some rather devious program bugs. You should design your ladder program so that bits are always defined (right-side rung outputs) before they are referenced (left-side rung inputs). When you use this simplification, it is important to remember that, unlike the electric circuit that it resembles, your ladder logic program is evaluated rung-by-rung, in order, from top to bottom. This simplification is based on the associative law of boolean algebra. The pattern is then evaluated only once, and the result can be used in two or more rungs that follow without evaluating the same pattern again and again. One simplification technique you will use very often is extracting patterns which appear more than once into a rung of their own. You won’t have to remember the names of the laws – just learn to recognize their patterns and simplifications. Boolean algebra adds a few more: DeMorgan, Absorption, Tautology, and Contradiction. You may remember the names of these laws from an old math class: Associative, Distributive, Communicative, Identity.
This document explains how to apply several simple laws taken from boolean algebra to ladder logic.
If you use the simpler forms your rungs will be easier to understand and change (which helps you write software that works the way you intend) and your programs will run faster and use less memory too. Each of these patterns can be written in a shorter and simpler form that does the same thing. You can write better, simpler ladder logic by learning to recognize several common patterns within your rungs.