Ladder logic programming

Ladder diagram instructions, Boolean equivalence, start–stop seal-in, timers and counters, and scan-order effects with worked examples.

Drafted with Aria, reviewed by the AiCanCode.org team. Spotted an error? Use Give Feedback at the bottom of the page.

Why it matters

Ladder diagram (LD) is still the most widely used PLC language in Indian plants because electricians and technicians can read it like a relay drawing. Motor starters, interlocks, sequences, alarms and pump alternation are written in ladder every day. Interviewers routinely ask you to draw a start–stop circuit or predict an output from a few rungs.

Key ideas

Structure. Two vertical power rails with horizontal rungs between them. Each rung has conditions (contacts) on the left and an action (coil or function box) on the right. If there is a continuous logical path of true contacts from the left rail, the rung is true and its output is energised; otherwise the output is de-energised (for a normal coil). The PLC solves rungs top to bottom, each rung left to right, once per scan, using the input image table read at the start of the scan.

Basic instructions (IEC 61131-3 names, with common vendor names).

  • Normally open contact (–| |–, XIC "examine if closed"): true when the referenced bit is 1.
  • Normally closed contact (–|/|–, XIO "examine if open"): true when the bit is 0.
  • Output coil (–( )–, OTE): writes the rung result to a bit every scan.
  • Set/Reset (latch/unlatch) coils (–(S)– / –(R)–, OTL/OTU): set the bit to 1 or 0 and leave it there until the opposite instruction acts — retentive.
  • Edge contacts / one-shots (P and N contacts, ONS): true for exactly one scan on a rising or falling edge.

Boolean equivalence. Contacts in series = AND; contacts in parallel (branches) = OR; a normally closed contact = NOT. Any combinational logic can be drawn as ladder, for example Y = A·B̄ + C is a branch of (A in series with NC B) in parallel with C.

Start–stop with seal-in (latching). Motor = (Start + Motor) · Stop_healthy · Overload_healthy. A normally open contact of the motor output in parallel with the Start contact keeps the rung true after Start is released. For safety the field Stop push button is wired normally closed, so the input bit is 1 when healthy and drops to 0 if the button is pressed or the wire breaks; in the program it is therefore examined with a normally open contact. The same principle applies to overload and emergency-stop contacts.

Timers.

  • TON (on-delay): output turns on after the input has been continuously true for the preset time PT; resets when the input goes false.
  • TOF (off-delay): output turns on immediately with the input and stays on for PT after the input goes false.
  • TP (pulse): gives a fixed-width pulse.
  • RTO (retentive on-delay): accumulates time over several on-periods; needs an explicit reset. Older PLCs set the preset as a count of a time base (0.01 s, 0.1 s, 1 s): preset count = time/time base. Timer accuracy is limited to about one scan, because the done bit is only acted upon when its rung is solved.

Counters. CTU counts up on each false-to-true transition of its input; CTD counts down; CTUD does both. When the accumulated value reaches the preset, the done bit (Q) turns on. A reset input clears it. The input pulses must be longer than a scan (plus input filter), otherwise use a high-speed counter.

Other instructions. Compare (EQ, GT, LT), move, arithmetic, scaling, and function blocks such as PID. Sequences are often built with step bits or written in sequential function chart (SFC).

Good practice. Use each output coil only once (duplicate coils — the last rung wins). Put interlocks in the same rung as the output they protect. Keep hard-wired emergency stops independent of the PLC. Comment every rung.

Formulas

series contacts: Y = A·B; parallel contacts: Y = A + B; NC contact: Y = Ā

Motor = (Start + Motor)·Stop·OL

  • Start: NO push-button bit; Stop, OL: bits from NC-wired stop button and overload relay (1 when healthy); Motor: output bit used as its own seal-in contact.

preset count = T_delay / time base

  • T_delay: required delay (s); time base: timer increment (s).

T_actual ≈ T_preset to T_preset + t_scan

  • Timer done-bit action is resolved to within one scan time t_scan.

t_pulse,min > t_scan + t_filter

  • Shortest input pulse a normal counter is guaranteed to count.

Worked examples

Example 1 (standard) — evaluating rungs. A program has two rungs: Rung 1: Y1 = (A·B̄) + C. Rung 2: Y2 = Y1·D̄. Inputs are A = 1, B = 0, C = 0, D = 1. Find Y1 and Y2. Then find the outputs if B changes to 1.

  1. Rung 1: A·B̄ = 1·1 = 1; Y1 = 1 + 0 = 1.
  2. Rung 2: D̄ = 0, so Y2 = 1·0 = 0.
  3. With B = 1: A·B̄ = 1·0 = 0; Y1 = 0 + 0 = 0, and Y2 = 0·0 = 0.
  4. Because Rung 1 is solved before Rung 2 in the same scan, Y2 uses the Y1 value just computed — rung order matters.

Example 2 (GATE level) — timer and counter. A conveyor M1 starts when the operator presses Start. Conveyor M2 must start 12 s after M1, using a TON with a 0.1 s time base. A CTU counts cartons from a photo-eye; after 48 cartons both conveyors stop. The scan time is 25 ms and the input filter is 5 ms. (a) Find the timer preset count. (b) Find the window in which M2 actually starts. (c) What is the shortest photo-eye pulse that is guaranteed to be counted? (d) Write the Boolean equation for M1.

  1. (a) Preset count = 12 s/0.1 s = 120.
  2. (b) The done bit becomes true 12 s after M1, and the M2 rung sees it within one scan: M2 starts between 12.000 s and about 12.025 s after M1 (plus output delay).
  3. (c) t_pulse > 25 + 5 = 30 ms. If cartons pass faster than that, use a high-speed counter input.
  4. (d) M1 = (Start + M1)·Stop·OL·C̄_done, where C_done is the counter done bit: M1 drops out when 48 cartons are counted. The counter is reset by Start (or a separate reset) for the next batch.

Common mistakes

  • Programming the Stop button as a normally closed contact when it is already wired NC in the field — the motor then can never start (or runs when Stop is pressed).
  • Forgetting the seal-in branch, so the motor runs only while Start is held.
  • Using the same output coil in two rungs; only the last rung's result reaches the output.
  • Using a latch (set) coil without any reset path, so the output stays on after a power cycle.
  • Expecting timers to be exact to the millisecond; they resolve to about one scan.
  • Counting pulses shorter than the scan time with an ordinary counter.

For GATE IN

Typical tasks: convert a ladder rung into a Boolean expression and back; predict the output of a set of rungs for given inputs (including rung order effects); draw the start–stop seal-in and interlock logic; and compute timer presets and timing diagrams for TON and TOF. Practise reading timing diagrams carefully — an on-delay resets whenever its input drops.

Quick check

  1. Two contacts in parallel feeding a coil implement which logic function?
  2. A TON has preset 3 s. Its input is true for 2 s, false for 1 s, then true for 2 s. Does its output ever turn on?
  3. Write the Boolean equation of a start–stop seal-in rung for output M.
  4. How many counts must you preset on a 0.01 s time-base timer for a 4 s delay?

Answers: 1. OR. 2. No — the on-delay resets when its input goes false, and neither true period reaches 3 s. 3. M = (Start + M)·Stop (with Stop = 1 when healthy). 4. 400.

Try answering each one aloud before you open it.

  1. 1.What is ladder logic programming and where is it commonly used?Concept

    Ladder logic programming is a graphical programming language used to develop software for programmable logic controllers (PLCs). It resembles electrical relay logic diagrams and is commonly used in industrial automation for controlling machinery and processes.

  2. 2.Explain the basic components of a ladder logic diagram.Concept

    A ladder logic diagram consists of rungs, which are horizontal lines that represent control logic. Each rung contains input instructions (like switches or sensors) on the left and output instructions (like motors or lights) on the right. The vertical lines on either side represent the power supply.

  3. 3.How does a PLC execute a ladder logic program?Concept

    A PLC executes a ladder logic program by scanning each rung from top to bottom, left to right. It evaluates the input conditions and updates the outputs accordingly. This process is repeated continuously in a loop, allowing the PLC to respond to changes in inputs in real-time.

  4. 4.Why is ladder logic preferred in industrial automation?Application

    Ladder logic is preferred in industrial automation because it is easy to understand and resembles traditional electrical schematics. This makes it accessible to engineers and technicians familiar with electrical control systems. Additionally, it allows for quick troubleshooting and modifications.

  5. 5.What happens to an output coil when the logic on its rung is false?Application

    For a normal output coil (OTE) the PLC writes the rung result every scan, so when there is no true path from the left rail the output bit is set to 0 and the field device de-energises. Set/latch coils behave differently: they leave the bit unchanged until a reset/unlatch instruction acts. Programming software will not accept a rung that is structurally incomplete, so in practice the question is about a rung whose conditions are false.

  6. 6.Explain the use of timers in ladder logic programming.Concept

    Timers in ladder logic programming are used to introduce delays or to measure time intervals. They can be used to delay the activation of an output or to ensure that an input condition is met for a specific duration before triggering an output. Common types include on-delay and off-delay timers.

  7. 7.How can you implement a simple start-stop motor control circuit using ladder logic?Application

    Use one rung: a normally open Start contact in parallel with a normally open contact of the motor output (the seal-in), in series with the Stop and overload contacts, driving the motor coil — Motor = (Start + Motor)·Stop·OL. The field Stop button is wired normally closed so that a pressed button or a broken wire both stop the motor; because its input bit is 1 when healthy, it is examined with a normally open contact in the program. Pressing Start energises the coil, the seal-in holds it after Start is released, and opening Stop or OL breaks the rung.

  8. 8.What is the role of counters in ladder logic programming?Concept

    Counters in ladder logic programming are used to count events or occurrences. They can be used to track the number of items produced, the number of cycles completed, or any other countable event. Counters can be set to count up or down and can trigger outputs when a preset count is reached.

  9. 9.A timer in a ladder program is set to 5 s and the PLC scan time is 100 ms. What delay does it actually produce?Numerical

    The timer accumulates real time from the PLC clock, so its preset delay of 5 s does not depend on the scan time. However, the done bit is only acted upon when the rungs that use it are solved, so the output reacts somewhere between 5.0 s and about 5.1 s (one scan later), plus input-filter and output delays. If better timing is needed you use a faster periodic task or a hardware timer.

Finished this topic? Mark it so your progress, study plan and readiness keep up.

Stuck on something here?