Single Pushbutton On-Off Control Including a Ladder Logic Demo in the Modicon PLC

Return to the Industrial Control and Automation Index

Single momentary pushbutton On-Off control is a convenient way to start and stop a machine especially when implemented using a lighted pushbutton. The result is a clean simplified control panel with a clear on-off indicator. Perhaps the best aspect of this lighted pushbutton is that the software is in control of the machine. Should a fault occur, the machine halts and the associated indicator lamp is extinguished.

We will implement the control pattern in a Schneider Electric Modicon TM221CE24T PLC using ladder logic. The presentation is academic in nature and the proposed solution may not be the simplest implementation. Instead, it attempts to build on information you already know and points out PLC specific programming features. For example, we will use a state variable and a jump command. Neither are strictly required, but both features are essential knowledge for advanced PLC programming.

Tech Tip: The “software in control” of your machine is an important safety aspect. To better understand the meaning, please consider the alternative. Suppose your machine is controlled via a toggle or selector switch. Under normal operating conditions, the machine is on and running when the switch is placed in the on position. That’s fine until that machine encounters a fault and shuts down. We now have a discrepancy between the machine’s apparent front panel settings and the internal state. It’s far better to have a lighted momentary pushbutton where the running state of the machine is presented as a lit indicator lamp. A fault extinguishes the lamp. Consequently, the machine’s front panel is always a true representation of the machine’s state.

Safety: Do not place 100% trust in electronic controls. Perform a risk assessment and place safety critical actions into independent control systems. For example, controls such as an emergency stop, light-curtain, tank overflow, or machine overrun should always be independent of the PLC. We should send a copy of these critical sensor inputs to the PLC, but we should never depend on the PLC to take care of the situation.

Figure 1: Picture of the Modicon TM221 PLC and pushbutton on a PLC trainer.

Ladder Logic implementation of the single pushbutton control

The ladder logic for the single pushbutton control is presented in Figure 2. Let’s begin by identifying some of the programming features:

  • Use of symbols: The Modicon PLC has fixed memory locations. For example, outputs begin with %Q, inputs with %I, and bit memory location with %M. Rather than use these hard-to-remember names, we use descriptive symbols. The objective is to make the code self-documenting.

  • Rising edge contact: Rungs 1 and 2 feature rising edge contacts. These appear as normally open contacts with a “P” in the middle. In this code, the L_PB1_Switch (lighted pushbutton #1 switch element) will evaluate as true for one program cycle corresponding to the rising edge of the button press.

  • Rung 0 features a jump to label command. This is seen as the double arrow with the %L0 label. If Rung 0 evaluates as true, we jump over Rung 1. This feature must be used with extreme care as the technique is prone to programming errors. To date, I have been unable to find a way to alias the name. Instead, we are required to use the %L identifier. In my opinion, this has the potential to introduce a very hard to troubleshoot bug. Perhaps it’s best to avoid the feature, we will look at an alternative later in this article.

  • Use of input and output maps: Three Program Organization units (POU) are included in this project including prgInMap, prgCtrl, and prgOutMap (not shown). The input and output maps are used to prevent the screw terminal I/O (%I and %Q) from being called from within the primary control POU. While not strictly necessary, this program style can make it easier to troubleshoot. It also ensures that each I/O point appears once and only once in the project. This makes it very easy to change physical I/O in the future; with confidence that you will not miss an %I or %Q.

Tech Tip: Contact bounce can be a problem for PLC programmers especially the triggered system shown in Figure 2. Thankfully most PLCs feature a filter that will eliminate the need to consider this annoyance. The Modicon digital inputs are preset with a 3 ms filter. This should mitigate contact bounce for most inputs. In the Modicon TM221, we turn the filter off or extend it to 12 ms.

Figure 2: Ladder logic for the single button start stop control.

The basic idea of the ladder logic program is to look for the rising edge of the button press. Upon detection, the state variable toggles.

  • In English, the primary thought associated with Rung 0 reads, “if the state variable is set and we have a rising edge of the pushbutton, then clear the state variable.

  • Rung 1 reads, “if the state variable is clear and we have a button press, then set the state variable.

  • Rung 2 is not particularly important to this conversation. It is one of potentially many rungs that do something with the state variable. For example, we could turn on a motor as well as the lighted pushbutton’s lamp if the state variable is set.

These two statements would seem to be enough to take care of the situation, but there is a problem.

Without further attention, the Rung 1 will always undo Rung 0.

Consider the program scan in which the button press occurs. The button press event will evaluate as true in both Rungs 0 and 1. Assuming the state variable is set, rung 0 will dutifully place a 0 into state variable memory location via the reset coil.

Here is where we get into trouble.

For the program scan associated with the button press rising edge, Rung 1 will see the state variable as clear and then place a 1 into the state memory location via the set coil. This undoes any action from Rung 0. Together, the two rungs do nothing, and the state variable remains forever in the set condition.

One way out of this situation is to include a jump. If Rung 0 evaluates as true, we jump over Rung 1. Consequently, Rung 1 never has a chance to undo Rung 0. As previously mentioned, the jump-to-label operation works, but can lead to difficult to troubleshoot code if we inadvertently use the wrong label.

In this article’s opening I mentioned the concept of software in control of the machine. That important consideration is included in Rung 0. Observe that the GLOBAL_FAULT variable is used to force the state variable into a reset condition. Given the resulting jump over Rung 1, the operator will be unable to restart the machine while the fault exists. Under no conditions will the state variable be reasserted while there is a fault. This prevents unexpected startups even when the start pushbutton is physically jammed.

Tech Tip: Use of rising edge detection for pushbuttons can be a safety feature. In this example code, it prevents impatient operators and technicians from physically jamming the start switch. To start the machine, the pushbutton must make a complete off to on cycle. This is much preferred to a level sensitive user interface which invites bypassing such as when a toothpick is jammed into the start button.

The final and perhaps the single most important contact in this example is the SB_FIRSTRUN. This system variable will be true on the first, and only the first program scan. This action forces the state variable into a clear condition. Consequently, any time the PLC is restarted or activates after a power failure, the system will start in the reset (off) state. This prevents unexpected equipment starts thereby protecting the machine operators, technicians servicing the machine, and the machine itself.

Remember the safety tip, do not depend on this mechanism. Be sure to add redundant and independent systems to prevent unexpected equipment starts.

Video 1 demonstrates the operation of the system. Observe that the lighted green panel lamp is activated and then deactivated by keypress. Also observe that the red pushbutton will stop the system. In this example, it simulates the GLOBAL_FAULT condition. The large 3-phase motor starter and interposing relay may be heard in the background.

Video 1: Demonstration of the single pushbutton control with the green lighted pushbutton.

Modification of the code to operate without a jump instruction

We can modify the code to eliminate the jump over Rung 1. One option is to add the L_PB1_LOCKOUT variable shown in Figure 3. This performs the same function as the jump by disabling Rung 1 any time Rung 0 evaluates as true. Of the two options, the Figure 3 listing may be safer as it eliminates the jump. It is also slightly easier to read. In English we would say, “If the rung is not in lockout, and the state variable is clear, and a rising edge of the lighted pushbutton occurs, then change the state to active.

Figure 3: Code listing with a lighted-pushbutton-1-lockout variable to prevent activation of Rung 1.

Parting thoughts

At this point we should consider wrapping this code into a User Defined Function Block (UDFB). It appears to be a useful addition to our code library.

What do you think? Is this a good way to handle the single pushbutton on / off control? Did we miss anything? Please leave your comments and suggestions in the space below.

Best Wishes,

APDahlen

P.S. This assembly was built on the PLC trainer described in an earlier article. Click on the link to find the parts list.

Return to the Industrial Control and Automation Index