Skip to main content
Back to module
Industrial Controls & PLCs · PLC Programming

Ladder logic programming

Reading46mLesson 2 of 3 in this module

Write PLC ladder logic for a seal-in with an interlock and simulate it scan by scan.

Why it matters

In the relay lesson you read circuits made of wires and contacts. In a PLC, the same logic is software: contacts and coils are instructions that read and write bits in memory. Writing it yourself, and predicting what happens scan by scan, is the step from reading programs to changing them safely.

The three basic instructions

  • XIC, examine if closed (-| |-): true when the referenced bit is 1. On an input, that means the input has voltage.
  • XIO, examine if open (-|/|-): true when the bit is 0.
  • OTE, output energize (-( )-): writes 1 to its bit when the rung to its left is true, and 0 when it is false.

Siemens calls these NO contact, NC contact and coil; the idea is the same. Series instructions are AND, parallel branches are OR, and an XIO is NOT.

The key mental shift: field contact vs instruction

In a relay circuit the STOP button is a normally closed contact. In a PLC, the NC stop button is wired to an input, so that input is on (1) when the button is not pressed. In the program you therefore use XIC on the stop input, not XIO.

Field device           Input bit when at rest    Instruction to use for "OK to run"
NC STOP button         1                         XIC (examine if closed)
NC overload contact    1                         XIC
NO START button        0                         XIC (true while pressed)

This trips up beginners more than anything else: the instruction is about the bit, not the button.

Seal-in in ladder logic

      STOP_PB   START_PB   OL_OK          MOTOR
 1 ---] [----+---] [----+---] [--------------( )---
             |          |
             +---] [----+
                MOTOR

As Boolean logic:

MOTOR = (START_PB OR MOTOR) AND STOP_PB AND OL_OK

The MOTOR bit in the branch is the PLC's version of the auxiliary seal-in contact. On the scan where START is pressed, MOTOR becomes 1. On the next scan, START is 0, but the MOTOR branch is true, so MOTOR stays 1. When STOP is pressed, STOP_PB becomes 0, the rung goes false and MOTOR is written 0.

Adding an interlock

For forward and reverse, each rung gets an XIO of the opposite output:

FWD = (FWD_PB OR FWD) AND STOP_PB AND OL_OK AND NOT REV
REV = (REV_PB OR REV) AND STOP_PB AND OL_OK AND NOT FWD

Because of the scan, FWD is solved first. If both buttons are pressed on the same scan from a stop, FWD becomes 1, and then the REV rung sees FWD already 1 and stays 0. Rung order decides the tie, which is one more reason to think in scans. Real reversing starters keep a hard-wired electrical and mechanical interlock as well, because software alone must not be trusted to prevent a phase-to-phase short.

Worked example: tracing scans

Start with the motor stopped. The table shows inputs and outputs at the end of each scan.

Scan  STOP_PB  FWD_PB  REV_PB  OL_OK  ->  FWD  REV
1     1        1       0       1          1    0     forward pressed
2     1        0       0       1          1    0     seal-in holds
3     1        0       1       1          1    0     interlock blocks reverse
4     0        0       0       1          0    0     stop pressed
5     1        0       1       1          0    1     reverse starts

Latch and unlatch

Many PLCs also have OTL/OTU (set/reset) instructions that latch a bit on until another rung unlatches it. Latched bits survive a power cycle on some platforms, which can make a machine restart unexpectedly. For motor control, the seal-in rung is preferred because it drops out on power loss, just like a relay circuit.

Practise in a simulator

Free tools let you practise without hardware: OpenPLC Editor includes a simulator (https://autonomylogic.com/), and many vendors offer free or trial software with simulation. The Do tab has a small in-browser simulation of the forward/reverse rungs. Checked on 2026-10-23.

Common mistakes

  • Using XIO for an NC stop button, so the motor runs only while STOP is pressed.
  • Forgetting the seal-in branch, so the motor stops when START is released.
  • Writing the same output in two rungs.
  • Relying on a software interlock alone where a hard-wired one is required.

Safety

Control panels contain voltages that can kill, stored energy in drives and capacitors, and machines that can start unexpectedly. Everything in this course is practised on paper or in simulators. Working in real panels requires employer training, supervision by a qualified person, lockout/tagout and the arc-flash practices in NFPA 70E (https://www.nfpa.org/codes-and-standards/nfpa-70e-standard-development/70e), and for electricians a registered apprenticeship and state or local licence. Checked on 2026-10-23.

Recap

  • XIC is true when the bit is 1, XIO when it is 0; OTE writes the rung result.
  • An NC stop button gives a 1 at rest, so use XIC on it.
  • Seal-in: OUTPUT = (START OR OUTPUT) AND STOP AND OL.
  • Interlock: AND NOT the opposite output; keep hard-wired interlocks too.

Try it

Open the Do tab and write the forward rung of a reversing starter.

Also in this lesson: