Perhaps the most controversial Ladder Logic Programming Pattern is the Five Rung Logic block. The purpose of the pattern is to encapsulate all the elements required for a single machine “motion”. The idea of what constitutes a motion is a little vague, but it’s generally the following:
- The PLC does something to initiate a motion (like turn on a valve or tell a robot to move)
- There is some kind of signal to indicate the motion is complete (such as a sensor)
- We want to monitor the time it takes to complete and generate a fault if it takes too long
As you can imagine, a lot of machine control can make use of this pattern. Any time you have an air cylinder with feedback sensors (extended/retracted) then you can throw two five-rung logic blocks in there. You can also use it when you have to command a motion controller or a robot to move one or more axes to a given position.
The Five Rung pattern is called that because there are 5 coils typically used:
- Precondition (aka Trigger)
- Complete (aka “In Position”)
Some variants of this pattern would put the Safety rung before the Trigger rung, but I like to reverse that because the Trigger rung really indicates when the motion starts. In a typical program, if you’re using the Step pattern, then the trigger will be driven by a Step In Progress contact. Note that in a more complicated program this motion might be initiated by many different steps in your sequence, so you just put a bunch of Step In Progress contacts in parallel here. In a program that doesn’t use the Step pattern, then the Trigger coil could be driven directly by logic like some other cylinder extended and a part present input on. It’s important to realize that the Step pattern is more scalable and better for larger programs, but it’s not the only way to do it.
The Trigger coil only has to be on to initiate motion and only works if the machine is in Auto Mode. The Trigger coil doesn’t have to stay on the whole time. In some cases it might be common to put the motion complete sensor in this rung as a normally closed contact, so that the motion won’t initiate if the axis is already in that position. That’s redundant in our case because we take care of that later, as you’ll see.
The Safety rung is a set of conditions that have to be true during the entire motion. The prototypical example is “all E-Stops OK” but other conditions you would see here are signals from interfering axes. For example, let’s say that you have two cylinders, A and B, and only one of those can be extended at a time. It’s typical to put the Cylinder A Retracted sensor (and the Cylinder A Extend output) in the Safety rung for the Cylinder B Extend Five-Rung block, and vice-versa. This is a good double-check of your logic, so even if you make a mistake in your sequence logic, at least you’ll prevent the two cylinders from crashing into each other.
The Command rung acts as the memory in this pattern. It remembers that we’re trying to perform this motion. It can be initiated in Auto Mode by the Trigger signal or in Manual Mode by a button or other manual control. Note that the Safety conditions still have to be met even in Manual Mode, so we don’t risk allowing the operator to crash the machine inadvertently. Once the Command coil turns on, it seals itself in, typically until the motion is complete, but alternatively the circuit will be broken if the Safety rung drops out, which is basically an Abort.
Note that the example above shows an “Auto Mode” signal but you will typically see this replaced with an Auto Cycle Running signal, since most machines require you to put the machine into Auto Mode and then initiate a cycle with another button. Sometimes this is captured in the Command rung, and sometimes this is done in the Trigger rung.
The In Position rung is responsible for figuring out how you know that the motion is complete. If you have a sensor, you can use that. If you have a Motion Complete signal coming back from a motion controller or a robot, you can easily use a rising edge detection on that signal as well (in this case I would call this a Complete rung, not an In Position rung). It may also be common to put a timer in this rung to “make sure” that the motion really is complete before we do whatever is next. I prefer not to use timers unless I have some kind of nuisance problem with the machine, but I’ve seen some logic where there’s a timer in every single In Position rung. The problem with timers is that they slow down your cycle time, and nobody wants that. Note that it’s a good idea to use the In Position coil as the canonical indication that this axis is in this position. By that I mean if other parts of your program need to know that your cylinder is in the Extended position, it’s better to use this In Position coil rather than using the inputs themselves. That gives you a single place to change your logic if, for instance, you have to move the sensor to another input due to a blown input, or you want to add a timer due to “bouncing”. If you’re using the Step pattern, it’s typical to use the In Position signal in your Step Complete rung.
The next two rungs, together, make up the Fault rung and you may sometimes see them combined into a single rung depending on the programmer’s preference. The Fault rung implements a simple Timeout Fault for the motion. If you’re trying to extend a cylinder, and it takes more than a second, chances are there’s a problem. This is an example of the State Coil pattern, and requires the operator to reset the fault to continue. It’s important that this fault be reported to the operator to indicate which motion was causing the problem. Note that it also drops out the Safety rung to abort the motion. This is optional, but generally a good idea because it’s possible that the axis or cylinder is jammed and you want to stop trying to move it to prevent further damage to the machine. It isn’t always the case that you want to stop the motion, so use your judgement.
In my programs I’ll typically use a three level system of ladder logic patterns:
- Highest level: the Mission pattern
- Middle level: the Step pattern
- Lowest level: the Five Rung pattern
For example, a Mission might be “Pick Up Part”. Then there will be a routine with all the Steps necessary to perform a pick-up-part sequence, such as “Extend Arm and Turn on Vacuum”, “Extend Gripper”, “Verify Suction”, “Retract Gripper”, “Retract Arm”. Then I would have several low-level routines, such as “Arm”, “Gripper”, and “Vacuum”. The Arm and Gripper routines would each have two Five Rung logic blocks in them, one for Extend and one for Retract. The Vacuum isn’t really a motion, so it would have simpler on/off type logic, and some kind of vacuum sensor feedback logic in it.
I should warn you that when someone first sees a Five Rung logic block, they usually ask, “why do you need so much logic just to turn a valve on?” Well, that’s the difference between an experienced ladder logic programmer and an inexperienced one. Eventually the inexperienced programmer will write some really simple and straightforward logic to turn the valve on and off, and then they’ll have to add some kind of fault when the cylinder motion doesn’t complete (or the sensor stops working), and then they’ll have to differentiate between how it operates in Manual Mode instead of Automatic Mode, and before they know it they’ll have created their own custom version of a Five Rung logic block. In their next program they’ll probably just do it this way.