Concepts

What Is Ladder Logic? (Finally Made Simple)

If you're going to work with PLCs, the one skill you can't skip is reading and writing Ladder Logic. It's the most common PLC programming language, and a lot of the logic you'll run into in the field is written in it.

In this post, I'll cover the basics you need to be comfortable reading and writing Ladder Logic code.

By the end of this post, you'll know:

  • how to read Ladder Logic,
  • how the most common instructions work, and
  • what a seal-in circuit is.

Let's get started.

What is Ladder Logic?

Ladder Logic, also known as Ladder Diagram, is the most common programming language for PLCs. It's a graphical language that's designed to be easy for electricians and technicians to read, write, and monitor.

A ladder logic routine with a power rail and three rungs

Each line of code is called a rung, because it looks like a rung on a physical ladder. You write logic by adding instructions to a rung and linking those instructions to tags.

We'll talk about tags in more detail in another post - for now, just think of them as the physical inputs and outputs of the PLC.

Instructions

There are two basic categories of instructions: input instructions and output instructions.

Input instructions read a tag, output instructions write a tag

Output Instructions

Output instructions write a value to a tag, and they always sit on the right-hand side of the rung.

Shown here is an Output Energize instruction, which is linked to the tag DO_Run_MTR. This is a digital output on the PLC that runs a motor for a conveyor.

You'll often hear Output Energize referred to by its mnemonic, OTE.

An OTE instruction linked to DO_Run_MTR with the power rail on the left

To understand how this executes, look at the vertical bar on the left of the rung. That's called the power rail.

When there's a continuous path from the power rail to an output instruction, that instruction evaluates to true. Another way to say this is that the rung-in condition for the instruction is true.

An OTE writes the value 1 to its linked tag when it evaluates to true, and writes 0 when it doesn't. When we're talking about digital inputs and outputs, the values 1 and 0 are often referred to as true and false.

With nothing between the power rail and the OTE, DO_Run_MTR is always 1

On this rung there's nothing between the power rail and the OTE, so there's always a continuous path. Every time the PLC scans this rung, it writes 1 to DO_Run_MTR, and the motor runs.

This logic isn't very useful. Let's see how we can control the output using input instructions.

Input Instructions

Input instructions read the value of a tag and evaluate to true or false based on that value.

Here I've added an Examine If Closed, or XIC, instruction to the rung and linked it to the tag DI_Start_BTN, which is the input from a start button.

DI_Start_BTN is 1, so the XIC is true and the motor runs

When DI_Start_BTN is true, the XIC evaluates to true. That creates a continuous path from the power rail to the OTE, and the motor runs.

DI_Start_BTN is 0, so the XIC is false and the motor stops

When the start button isn't pressed, the XIC evaluates to false and breaks the continuous path to the OTE, so the motor doesn't run.

If you read this rung out loud, it says: if the start button is pressed, run the motor.

AND Logic

You can build more complex logic by combining instructions on a rung.

When you put instructions in series, one after the other, you get AND logic, where every condition has to be true for the output to turn on.

Here I've added an Examine If Open instruction, or XIO, and linked it to the tag DI_Sensor, which is the input from a sensor. An XIO is the exact opposite of an XIC. It evaluates to true when its tag is false, and to false when its tag is true.

XIC and XIO in series: start pressed and sensor clear, motor running

Now the motor runs if the start button is pressed AND the sensor isn't triggered.

Sensor triggered: the XIO goes false and the motor stops

If the start button isn't pressed, or the sensor is triggered, the motor doesn't run.

OR Logic

You can also build OR logic by putting instructions in parallel, and you do that with a branch. A branch gives the rung an alternative path to the output.

Here I've added a branch around the start button, and on that branch I've put an XIC linked to DO_Run_MTR, the motor output itself.

Branch around the start button with an XIC on DO_Run_MTR, motor running

When the start button is pressed and the sensor isn't triggered, the motor runs, just like before.

Start released: the branch keeps the path closed and the motor keeps running

But now, when I release the start button, the motor keeps running. That's because the motor output is true, so the XIC on the branch is true, and that keeps a continuous path to the OTE.

Sensor triggered: the XIO breaks the path and the motor stops

The motor keeps running until the sensor is triggered and breaks the path.

Seal-In Circuits

This is a common design pattern called a seal-in circuit. It gets that name because the branch seals the output in: once it turns on, it holds itself on.

Seal-in circuit with the permissive, interlock, and seal-in branch labelled

A seal-in circuit is built from two kinds of conditions: permissives and interlocks.

Permissives are conditions that have to be true for a process to start, but don't have to stay true for it to keep running. In this example, the start button is a permissive.

Interlocks are conditions that have to be true for the process to keep running. If an interlock drops out, the process stops. Here the sensor is an interlock, because the motor stops as soon as the sensor is triggered.

Finally, the seal-in branch is a branch that goes around the permissives and refers to the seal-in circuit's output. This branch is what keeps the output on even when the permissives are false.

Seal-In Circuits are commonly used because they are non-retentive. This is because XIC and XIO instructions have special pre-scan logic that sets them to false before the rung is scanned for the first time.

Seal-ins don't survive a power cycle: power loss, pre-scan, first scan

This is a really important detail for logic that controls motors - if the PLC loses power, you don't want motors to start without warning when it is turned back on.

Wrap Up

So that's the basics of Ladder Logic. Now you know how rungs work, how the most common instructions behave, how to build AND and OR logic, and how a seal-in circuit works.

Email List

Get new content delivered straight to your inbox:

No spam. Unsubscribe anytime.

Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.

Related Posts

Ken Bourke

Industrial Automation Tutorials

© All Rights Reserved.