Technical Article

Seal-In Ladder Logic vs. Latching/Unlatching PLC Commands

2 days ago by Shawn Dietrich

An age-old debate in PLC programming: investigating the uses and caveats of latching software commands versus seal-in ladder logic for industrial control applications.

One of the most popular programming languages used with industrial automation controllers today is called ladder logic, following in the footsteps of the previous method of control which used interlocking electrical relays.

The ladder language uses graphical contacts, coils, and blocks to represent the logic instructions. As with nearly all programming languages, there are multiple ways of creating a programmed solution within the language. These multiple ways may produce a similar result, but programmers will often land on a desired method and stick to it.

A common discussion revolves around using seal-in logic vs. using latch and unlatch commands to create an output that remains on until commanded otherwise.

 

Operator with push buttons on a machine

Figure 1. Physical buttons are some of the most common input devices at the heart of the seal-in/latch debate. Image used courtesy of Adobe Stock

 

Latching Commands

In pretty much every PLC program, there are latching coils; these coils will set a variable (like an output) to become true when the rung is true, but then remain true even after the rung becomes false. An unlatch coil attached to the same variable will have the reverse logic, it will force the variable to become false as soon as the rung is true.

From a programming sense, it might be easier to think of a latching coil as assigning a value to a variable. When the latching coil is true, the variable is set equal to 1. Then, when the unlatching coil is true, the variable is set equal to 0.

For this reason, they are called latch and unlatch, but it is also very common to see ‘set’ and ‘reset’ which mean exactly the same thing.

 

Set/Reset ladder logic

Figure 2. An example of input commands being used to either latch (set) or unlatch (reset) a variable. Image used courtesy of the author

 

This style of programming allows variables to be set true in one routine and false in other routines, and can greatly reduce the amount of visual space the code takes up on the screen. It also allows for entirely different complex conditions to unlatch the variable vs the conditions required to latch the variable.

The downside to using latches is if your conditions for the latching coil do not go false before the unlatch coil is solved, the variable will be held true even if you try to unlatch it someplace else. This problem can increase troubleshooting time and can get programmers into tricky scenarios. Often programmers will use a one-shot rising / falling bit in front of a latch to ensure the conditions will only be true for one scan.

 

Seal-In Logic Structure

The ‘seal-in’ logic is often used for initializing a process, such as turning on motors with a momentary start and then later ending with a similar momentary stop push button.

The logic works by branching around the input condition(s) using the same variable as the output coil. The stop button, or stop conditions, are then placed in series before or after the branch in a normally closed state.

When the output goes true, the input conditions are said to be “sealed in” since the start command can be removed, but power will still flow to the output. When the stop conditions are met (contact becomes open), the output turns off and the seal is broken.

 

Seal-in logic for a circuit

Figure 3. Seal-in logic. Image used courtesy of the author

 

The benefit of this logic is that both the start and stop conditions are kept in one place, making it great for starting a process like a fan motor or starting a robot task.

The downside occurs if you have a lot of start or stop conditions, the series of commands and parallel branches of the rung can get unruly and difficult to read, usually expanding it to two rows on the screen.

Also, when using momentary coils, it is difficult to have multiple stop conditions or multiple start conditions for the same output. Additional handshake bits are required if you want to break the seal from other parts of the program. If not, you can end up with conflicting bit references and inconsistent machine operation.

 

“Latching Kills”

Well, perhaps that’s not really true all the time, but often I have heard this statement when referring to latching logic. The premise is that outputs may easily become stuck in the on position because there is an error in the unlatch or the latch logic. This is certainly one caveat to using latches, but it can easily be solved by cross-referencing your variables and making sure you have an unlatch for each latch.

The latching logic method produces much cleaner logic that is easy to read and follow, but can be overused to produce a web of complex latching and unlatching coils, especially when they exist across many subroutines.

 

Incorrect latch and unlatch circuit logic

Figure 4. If this is a normally open button, this latching logic will create an ‘always-on’ condition. Image used courtesy of the author

 

The logic example shown above is a simple erroneous case of an output that would only turn off (reset) when the N.O. button is pressed. As soon as the operator releases the button, the output will turn back on (set). If that output is a fan, it will never turn off.

The logic may have been intended to look like the image below. When the N.O. button is pressed, the output turns on (set). Then when released, it turns off (reset). A simple mistake of a normally closed vs open can result in output being on all the time.

 

Correct latch and unlatch conditions in a circuit

Figure 5. Proper latch/unlatch logic for a normally open button. Image used courtesy of the author

 

A Healthy Mix

Just like everything else in life, latching or seal-in logic should be used with a heap of moderation.

You won’t be able to solve every problem with latching coils and not every output needs to have seal-in conditions. The previous example of bad logic could certainly exist for either latching or seal-in logic, neither method is immune to problems.

I typically use latching logic when I want to handshake to another piece of code or another task, such as setting expected bits from a sequence. Instead of having complex code or calculations in my sequence, I’ll simply latch a bit from the sequence and then unlatch it when the calculation code is complete. The same is true with devices like cameras. I might latch a trigger bit in the sequence and then unlatch when the camera is done.

I often use seal-in logic when commanding motion devices such as servos or robots, this way I can add conditions where I might want to stop the motion before the end of the command. If I’m commanding a servo to move a linear actuator but some other tooling moves when it shouldn’t I can use a seal-in condition to issue the stop. HMI and physical push buttons often use seal-in conditions when you have a single function button like start and stop.

 

Uses for latching versus seal in logic

Figure 6. Comparing scenarios for latching (set) logic versus seal-in logic. Image used courtesy of the author

 

What is the Final Answer? Seal-in or Latching?

So here we arrive at the end of the article with no absolute conclusive recommendation. But this is typical for control automation, the situation determines the proper method. Plus, there are many scenarios in which you could use either method equally, and there is no right answer. By memorizing both methods and using careful consideration in order to apply them, you should be able to get out of most programming jams you encounter.

 


 

Can't get enough PLC content? Yeah, same here.
Check out more!

1 Comment
  • vanburicktechnology July 03, 2024

    From my point of view,  using latching software commands versus seal-in ladder logic in PLC programming is a broader, logical issue, not just specific to PLCs. This is a common challenge across various applications and industries.

    When considering latching and sealing-in, it’s important to focus on the specific requirements of the application. Latching commands set a variable to true when a condition is met and keep it true until another condition resets it. This is similar to assigning a value to a variable. For example, in alarm systems, an alarm needs to stay on until a reset button is pressed. Similarly, in sequential processes on production lines, each step needs to be confirmed before moving to the next. In these cases, latching provides a clear and maintainable way to handle state changes.

    Seal-in logic, on the other hand, involves maintaining an output state by branching around input conditions. This is particularly useful for initializing processes, such as turning on motors with a momentary start button and stopping them with a momentary stop button. For instance, motor starters use this method to turn on a motor with a start button and off with a stop button. Safety systems also benefit from seal-in logic to ensure processes stop immediately when a safety condition is violated.

    Another approach to consider is the use of masking, which involves using bits to enable or disable certain conditions in the logic. This helps manage complex conditions without altering the core logic. For example, in a safety system, masking can ensure that an emergency stop condition overrides all other commands, maintaining safety irrespective of the machine’s current state.

    Understanding the difference between states and events is crucial. States refer to the current condition of a system that persists over time, such as a motor being on or off. Events are changes in the state of the system, such as a liquid in a tank going from a level below a certain threshold to above that threshold. This distinction helps design logic that correctly responds to momentary changes in the condition of a process (events) and the continued condition (state) of the process over time.

    In conclusion, the choice between latching and seal-in logic is application-specific. Both methods have their advantages, and the key is to apply them judiciously based on the context and desired behavior of the system. This ensures robust and reliable control logic, addressing the logical challenges inherent in any control system, not just those specific to PLCs.

    Like. Reply