Ladder logic 304: Timer application
A sample timer application written in ladder logic provides examples of various programming tips, such as ensuring the programmer knows what the customer wants. See screen captures.
A customer asked for a ladder diagram for one motor and two contactors (fast/slow) with auto control where the motor runs for 2 min. in slow. Timed out, the motor runs fast for 5 min. in manual control, when the motor can be started in either fast or slow and latches in until the timer times out. Also, the customer needed the motor to run fast in inch mode when the 2-in. buttons are pressed. Those are a lot of details, but an important part of writing code for an application is determining the specifics of what the customer wants.
One question to pose to the customer is what programmable logic controller (PLC) is being used? Most ladder logic is pretty similar from platform to platform, but addressing and instruction sets vary widely. The images in this article demonstrate the programming process. A useful side benefit of a tag-based programming platform is that the engineer can assign the needed addresses to the tagnames (see Figure 1).
Let's start by defining the outputs. This is not the only way to approach programming, but it's a pretty good one for discrete machinery. Note that all states of the motor control are pretty well defined in Figure 1, though faults and control and system modes are defined in other routines. For added safety, if the slow output is somehow turned on it will disable the fast output and vice-versa. This does not apply if outputs are forced (see Figure 2).
The timer control part of the application is discussed below, and notes follow about using delay timers for these. There is nothing here to prevent someone from taking the system out of auto or manual mode and ending the cycle early. Also, there is no indication of where the "Inch Two Hand Control Command" (Inch_2HandCtrl) bit came from. Ideally, this would be either a hardware-based, anti-tie-down relay or a software-based, anti-tie-down routine. Do NOT do what is shown in Figure 3.
In most cases programming shown in Figure 3 is not legal because of safety concerns. If the controlled devices are behind a light curtain or door, the risk might be acceptable for the application.
The point is, someone could tape down one of the pushbuttons and operate it with one hand, which defeats the purpose of a "two-hand" control.
Faults are shown to elaborate on the 203 faults. Again, note that there is nothing in Figure 4 demonstrating how the fault is acknowledged, reset, or how it is combined with other faults to create a system level fault (see Figure 4).
The programming and explanation in Figure 4 took about three hours to write. The program took about an hour to develop due to the time it takes to create the tags, set up a new processor, set up an input/output (I/O) structure, and various other things. Much of the rest of the time was spent typing and doing screen captures of the logic for import.
Unfortunately, there are not a lot of good examples of ladder logic online, even on PLC manufacturers' websites. Most programmers don't have the extra time to type all of this up and post it. There are some really helpful folks on places like www.plctalk.net and other sites, but most are paid well for their time and can only go so far without providing answers to more complex ladder logic or application questions.
- Frank Lamb is the founder of Automation Consulting Services Inc. This article originally appeared on the Automation Primer blog. Automation Primer is a CFE Media content partner. Edited by Joy Chang, Control Engineering, firstname.lastname@example.org.
- An important part of writing code for an application is determining specifics of what the customer wants.
- Most ladder logic is similar from platform to platform, but addressing tagnames and instruction sets vary widely.
- Good examples of ladder logic online are lacking, even on PLC manufacturers' websites.
What PLC is being used for a project and what do those who are involved want clarified?
- This online version includes an additional screen capture of code. See additional stories from the author below.
- Events & Awards
- Magazine Archives
- Digital Reports
- Global SI Database
- Oil & Gas Engineering
- Survey Prize Winners