Module 05 · Ladder logic basics

Contacts, coils & Boolean logic

Ladder logic is drawn like an electrical circuit: power flows from the left rail through contacts to a coil on the right. Learn to read and write rungs with normally open and normally closed contacts, series AND, parallel OR and NOT.

≈ 40 min7 lessons1 hands-on labQuiz · pass 80 %Free

By the end of this module you can

  • Explain rails, rungs, contacts and coils, and the order in which rungs are solved
  • Use normally open (XIC) and normally closed (XIO) contacts correctly with NO and NC field devices
  • Build AND, OR, NOT and exclusive-OR logic and write its truth table
  • Avoid the double-coil mistake
  • Write the same rung in Siemens, Rockwell, Mitsubishi and IEC notation

A ladder program is a list of rungs between two vertical rails. The left rail is "power". Each rung asks a question with its contacts and stores the answer with its coil:

  • A normally open contact -| |- passes power when its bit is 1. Rockwell and Logivyx call it XIC, "examine if closed".
  • A normally closed contact -|/|- passes power when its bit is 0. XIO, "examine if open".
  • A coil -( )- writes 1 to its bit if power reaches it, 0 if not. OTE, "output energize".

The PLC solves rungs left to right, top to bottom, once per scan. Nothing actually "flows": each rung is a Boolean equation, and the drawing is a convenient way to show it.

Module 02 showed that a stop button is wired NC, so its input is 1 when not pressed. In the program you want "run allowed while the stop button is not pressed", which means "while the input is 1": a normally open contact on an NC field device.

Field deviceInput when idleYou want the rung to pass when…Program contact
NO start button0pressed (input 1)XIC -| |-
NC stop button1not pressed (input 1)XIC -| |-
NC stop button1pressed (input 0), e.g. to light a "stop pressed" lampXIO -|/|-
NO door switch, closed = 1–door open (input 0)XIO -|/|-
Ask"Which value of the bit should let power through?" If 1, use XIC. If 0, use XIO. Forget about how the switch is drawn on the electrical schematic.

Contacts in series make an AND: every one must pass. Contacts in parallel (a branch) make an OR: any one may pass. An XIO contact is a NOT. Combine them and you can express any on/off condition. Try all four combinations of SW1 and SW2 and fill in the truth table in your head before you look at the lamps.

SW1SW2ANDORNANDXOR
000010
010111
100111
111100

The XOR rung is the classic two-way staircase light: either switch changes the lamp.

The rung "Lamp = (SW1 OR SW2) AND NOT Fault", written four ways:

   SW1        Fault        Lamp
--+-| |-+-----|/|---------( )--
  |  SW2|
  +-| |-+

Lamp := (SW1 OR SW2) AND NOT Fault;     // ST

Logivyx Ladder Designer: Contact — Normally Open (XIC), Contact — Normally Closed (XIO), Parallel Branch (right-click → Add Branch Leg Above/Below), Coil — Output Energize (OTE).

   "SW1"      "Fault"      "Lamp"
--+-| |-+-----|/|---------( )--
  |"SW2"|
  +-| |-+

TIA Portal LAD: Normally open contact, Normally closed contact, Assignment coil; branches via Open branch / Close branch. Tags are shown in quotes with their address, e.g. "SW1" %I0.0. In SCL: "Lamp" := ("SW1" OR "SW2") AND NOT "Fault";

BST XIC SW1 NXB XIC SW2 BND XIO Fault OTE Lamp

Studio 5000 shows the same graphic rung; the line above is its text (neutral) form, which you can type or paste into a rung. BST/NXB/BND are branch start, next branch and branch end.

LD   X0        ; SW1
OR   X1        ; SW2
ANI  X2        ; NOT Fault
OUT  Y0        ; Lamp

GX Works3 draws the ladder; the instruction list is how you'll often see it in manuals. LD starts a rung with a NO contact, LDI with an NC contact, AND/ANI add series contacts, OR/ORI parallel ones, OUT is the coil.

Because rungs are solved top to bottom, writing the same coil in two rungs means the last rung wins. The first rung's result is overwritten before the outputs are written. This "double coil" bug is common and confusing: the lamp seems to ignore SW1.

The fix: combine the conditions in one rung with a parallel branch. Most programming tools warn about duplicate coils (Logivyx: right-click a tag → Cross Reference shows every place it is written).

A press may only run when the guard is closed (Guard_Closed = 1), both hands are on the two-hand buttons (Hand_L, Hand_R) and there is no fault (Fault = 0). Whoever drew this rung used the wrong contact somewhere. Click contacts to change them between XIC and XIO, then complete the challenge.

To hold two buttons at once on a computer, click and hold one, then press Tab to the other and hold Space, or use a touch screen. (Real two-hand controls also need a safety relay and a 0.5 s simultaneity check; this is only the logic idea.)

Use the PLC_Trainer project from module 04.

Lab

L05_Logic

  1. Tools → Ladder Designer… → + Add Ladder Routine L05_Logic.
  2. Rung 1: XIC SW1, XIC SW2 in series → OTE Q1 (AND).
  3. Rung 2: a Parallel Branch with XIC SW1 on one leg and XIC SW2 on the other → OTE Q2 (OR).
  4. Rung 3: the exclusive-OR from this module → OTE Q3. Add a rung comment to each rung.
  5. Rung 4: XIC SW3 AND XIO SW4 → OTE Q4. Before running, write down when Q4 will be on.
  6. Click View Generated ST… and check that each rung became one assignment.
  7. In the Logic Editor, open Main, replace CALL L04_Test; with CALL L05_Logic;, Validate, Save & Close. Save the project.
  8. F5. Test every combination of the switches and compare the lamps with the truth table. Use 🧮 Logic Diag → View Ladder… to see which contacts pass.