14.2 PLC Ladder Logic: Contacts, Coils, Timers, Counters & Data Manipulation
Key Takeaways
- IEC 61131-3 defines the five standardized PLC programming languages, with Ladder Diagram (LD) remaining the most prevalent industrial standard; fundamental instructions include Examine If Closed (XIC), Examine If Open (XIO), Output Energize (OTE), Output Latch (OTL), and Output Unlatch (OTU).
- Fail-safe industrial safety design mandates that field Emergency Stop and Stop pushbuttons be wired physically Normally Closed (N.C.) and programmed as Examine If Closed (XIC) in ladder logic, guaranteeing that broken conductors, loose terminals, or power loss immediately de-energize the circuit.
- Industrial timers track elapsed time using three internal registers (Control bits EN/TT/DN, Preset PRE, and Accumulated ACC); On-Delay (TON) timers count when the rung is true, Off-Delay (TOF) timers count when the rung transitions from true to false, and Retentive On-Delay (RTO) timers retain accumulated time through rung loss or power cycles until cleared by an explicit Reset (RES) instruction.
- Bidirectional counting pairs Count-Up (CTU) and Count-Down (CTD) instructions referencing the same counter tag/address to manage automated inventory, queue tracking, or accumulator positioning.
- Modern Programmable Automation Controllers (PACs) utilize user-defined, tag-based alphanumeric memory structures with scope levels (Controller vs. Program) and User-Defined Data Types (UDTs), superseding legacy rack/slot/word/bit hardware-dependent addressing.
14.2 PLC Ladder Logic: Contacts, Coils, Timers, Counters & Data Manipulation
Programmable Logic Controllers execute user control logic modeled after traditional electromechanical relay schematics. The international standard IEC 61131-3 formalizes five industrial programming languages: Ladder Diagram (LD), Function Block Diagram (FBD), Structured Text (ST), Instruction List (IL), and Sequential Function Chart (SFC). Among these, Ladder Diagram remains the foundational language evaluated on the Red Seal Industrial Electrician examination.
1. IEC 61131-3 Fundamental Bit Instructions
A ladder logic program consists of two vertical power rails representing power and neutral/ground, with horizontal rungs positioned between them. Rung continuity is evaluated based on binary bit conditions in memory:
Left Power Rail Right Power Rail
│ │
Rung ├───[ XIC ]───────[ XIO ]─────────────────────────────────( OTE )──────┤
0 │ I:1/0 I:1/1 O:2/0 │
│ Start PB Stop PB Motor Starter │
│ │
├───[ XIC ]───────┘ │
│ O:2/0 │
│ Seal-In │
Bit Instruction Mechanics
| Instruction Name | Graphic Symbol | Memory Test Condition | Rung Continuity Behavior |
|---|---|---|---|
| Examine If Closed (XIC) | ---| |--- | Tests bit for 1 (True / ON) | Evaluates TRUE if referenced memory bit is 1 (energized); evaluates FALSE if bit is 0. |
| Examine If Open (XIO) | ---|/|--- | Tests bit for 0 (False / OFF) | Evaluates TRUE if referenced memory bit is 0 (de-energized); evaluates FALSE if bit is 1. |
| Output Energize (OTE) | ---( )--- | Sets bit to 1 or 0 | If rung is TRUE, writes 1 to bit; if rung is FALSE, writes 0 to bit. Non-retentive. |
| Output Latch (OTL) | ---(L)--- | Retentive Set to 1 | If rung goes TRUE, writes 1 to bit; bit remains 1 even when rung goes FALSE. |
| Output Unlatch (OTU) | ---(U)--- | Retentive Reset to 0 | If rung goes TRUE, writes 0 to bit; the only instruction that can clear an OTL bit. |
Critical Programming Warning (Duplicate Destructive Coils): An industrial electrician must never program two OTE coils referencing the exact same memory address (e.g., two
( OTE ) O:2/0instructions on different rungs). Because the PLC solves ladder rungs sequentially from top to bottom, the status written by the final rung will overwrite all preceding rungs during the output scan, resulting in erratic, unpredictable machine behavior.
2. Fail-Safe Hardwiring vs. Ladder Logic Programming
A cornerstone of Canadian electrical safety (CSA C22.1, CSA Z432, and ISO 13849-1) is the principle of fail-safe design. A control system must default to a safe, de-energized state whenever an external component fails, a wire breaks, or control power is lost.
The Field Wiring vs. Ladder Instruction Paradox
Apprentices and electricians frequently struggle with the configuration of field Stop buttons and Emergency Stop (E-Stop) circuits:
PHYSICAL FIELD WIRING (FAIL-SAFE HARDWIRED): PLC MEMORY & LADDER PROGRAM:
+24 VDC ───[/]───[ N.C. E-Stop ]───► Terminal I:1/0 │ Input Table: Bit I:1/0 = 1 (Energized)
(Closed Contact in Field) │
│ Ladder Logic: I:1/0
│ ───────[ XIC ]───────( Run Coil )
│ True (1)
Why Field Devices Must Be Normally Closed (N.C.)
- Physical Field State: The Emergency Stop and field Stop pushbuttons are wired with physical Normally Closed (N.C.) contacts in series. Under normal conditions (pushbutton released and healthy), $+24\text{ V DC}$ continuously energizes the PLC input terminal.
- PLC Input Table State: Because current is flowing through the optocoupler, the CPU writes a binary
1into the Input Image Table (I:1/0 = 1). - Ladder Instruction Selection: In the ladder logic program, the programmer uses an Examine If Closed (XIC
---\| \|---) instruction addressingI:1/0. Because the bit in memory is1, the XIC instruction evaluates TRUE, allowing rung power flow to start and run the equipment.
The Failure Mode Analysis
- Broken Conductor / Severed Wire: If a forklift severs the field conduit or a wire vibrates loose from the screw terminal, current drops to 0 mA. The input bit immediately transitions to
0. The XIC instruction evaluates FALSE, instantly opening the ladder rung and de-energizing the motor starter coil. - What If Wired Normally Open (N.O.) and Programmed XIO (
---\|/\|---)? If an electrician improperly installed a physical N.O. field contact and programmed it with an XIO instruction, a broken wire would permanently leave the input bit at0. The XIO instruction would evaluate TRUE continuously—and the operator pressing the Stop button would be completely unable to stop the machine! This constitutes a lethal, non-fail-safe failure mode.
Why must an industrial Emergency Stop (E-Stop) pushbutton be wired physically Normally Closed (N.C.) in the field and programmed with an Examine If Closed (XIC) instruction in PLC ladder logic?
3. Industrial Timers: TON, TOF, and Retentive RTO
Timers are internal software functions that measure elapsed time in increments of a programmed Time Base (typically 1.0 s, 0.01 s, or 0.001 s). In Allen-Bradley and IEC-compliant controllers, each timer structure comprises three 16-bit words:
┌─────────────────────────────────────────────────────────────────────────┐
│ INTERNAL TIMER STRUCTURE (e.g., T4:0) │
├──────────────┬──────────────┬───────────────────────────────────────────┤
│ Word 0: BITS │ EN (Bit 15) │ Enable Bit: True when rung is energized │
│ │ TT (Bit 14) │ Timer Timing Bit: True while counting │
│ │ DN (Bit 13) │ Done Bit: True when ACC >= PRE │
├──────────────┼──────────────┴───────────────────────────────────────────┤
│ Word 1: PRE │ Preset Value: Target time count to reach │
├──────────────┼──────────────────────────────────────────────────────────┤
│ Word 2: ACC │ Accumulated Value: Current elapsed time count accumulated│
└──────────────┴──────────────────────────────────────────────────────────┘
1. On-Delay Timer (TON)
- Operating Rule: Timing begins when the input rung transitions from FALSE to TRUE.
- Bit Status Dynamics:
- While rung is TRUE and $\text{ACC} < \text{PRE}$:
EN = 1,TT = 1,DN = 0. - When $\text{ACC} \ge \text{PRE}$:
EN = 1,TT = 0,DN = 1. - When rung goes FALSE at any time:
EN = 0,TT = 0,DN = 0, and $\text{ACC}$ instantly resets to 0.
- While rung is TRUE and $\text{ACC} < \text{PRE}$:
- Applications: Lubrication pre-lube cycles before motor start, conveyor sequential cascade delays, and motor star-delta transition delays.
2. Off-Delay Timer (TOF)
- Operating Rule: Timing begins when the input rung transitions from TRUE to FALSE.
- Bit Status Dynamics:
- While rung is TRUE:
EN = 1,TT = 0,DN = 1, $\text{ACC} = 0$. - When rung transitions to FALSE:
EN = 0,TT = 1,DN = 1; $\text{ACC}$ begins counting up. - When $\text{ACC} \ge \text{PRE}$:
EN = 0,TT = 0,DN = 0.
- While rung is TRUE:
- Applications: Cooling fan run-on post-shutdown, tunnel ventilation purge after machine stop, and pneumatic cylinder retraction delay.
3. Retentive On-Delay Timer (RTO) & Reset (RES)
- Operating Rule: Operates identically to a TON while the rung is TRUE. However, if the rung goes FALSE (or the entire facility loses electrical power), the accumulated value is retained in non-volatile memory!
- Accumulation Resume: When the rung transitions back to TRUE, the timer resumes counting from its retained $\text{ACC}$ value rather than starting over from zero.
- The Reset (RES) Instruction: The only way to clear an RTO's accumulated value and reset the
DNbit is to execute an explicit Reset (RES) instruction referencing the identical timer address. - Applications: Preventive maintenance tracking (e.g., lubricating bearings after 500 operating hours), industrial autoclave bake cycles, and chemical batch mixing cycles.
RTO AND RES LADDER IMPLEMENTATION:
Rung ├───[ XIC ]──────────────────────────────────────────────[ RTO ]─────┤
0 │ Motor_Running Timer: T4:1 │
│ Preset: 3600│
│ Accum: 1842│
│ │
Rung ├───[ XIC ]───────[ XIC ]─────────────────────────────────[ RES ]─────┤
1 │ Maint_Key Reset_PB Timer: T4:1 │
4. Industrial Counters: CTU, CTD & Bidirectional Counting
Counters count false-to-true transitions of their input rungs. Unlike timers, counters are inherently retentive—they maintain their accumulated value even when their input rung goes false or when the PLC is de-energized.
┌─────────────────────────────────────────────────────────────────────────┐
│ INTERNAL COUNTER STRUCTURE (e.g., C5:0) │
├──────────────┬──────────────┬───────────────────────────────────────────┤
│ Word 0: BITS │ CU (Bit 15) │ Count-Up Enable: True when CTU rung true │
│ │ CD (Bit 14) │ Count-Down Enable: True when CTD rung true│
│ │ DN (Bit 13) │ Done Bit: True when ACC >= PRE │
│ │ OV (Bit 12) │ Overflow Bit: True if ACC exceeds +32,767 │
│ │ UN (Bit 11) │ Underflow Bit: True if ACC drops < -32,768│
├──────────────┼──────────────┴───────────────────────────────────────────┤
│ Word 1: PRE │ Preset Value: Target count threshold │
├──────────────┼──────────────────────────────────────────────────────────┤
│ Word 2: ACC │ Accumulated Value: Net pulse count accumulated │
└──────────────┴──────────────────────────────────────────────────────────┘
Count-Up (CTU) & Count-Down (CTD)
- Positive Edge Triggering: A counter increments or decrements only once per false-to-true transition. If the rung remains true for 10 minutes, the counter increments exactly once. It requires the rung to go false and return to true before counting again.
- Bidirectional Accumulation: In material handling or automated multi-level parking garages, a CTU and a CTD instruction can be assigned the exact same memory address (e.g.,
C5:1):- An optical entrance sensor triggers the
CTU C5:1rung, incrementingC5:1.ACC. - An optical exit sensor triggers the
CTD C5:1rung, decrementingC5:1.ACC. - When
ACC >= PRE,C5:1.DNilluminates a "PARKING GARAGE FULL" sign and interlocks the entry gate.
- An optical entrance sensor triggers the
An industrial autoclave heating cycle uses a timer with a 1.0-second time base and a preset of 1,800 seconds (30 minutes). During the cycle, an emergency power outage de-energizes the plant for 10 minutes. Upon power restoration, the process engineer requires the timer to resume heating exactly where it left off. Which timer and supporting instruction must be selected?
5. Advanced Instructions: Math, Comparisons & Data Scaling
Industrial automation requires mathematical manipulation of process values, analog signals, and setpoints.
Comparison Instructions
Comparison instructions are placed on the input side of a ladder rung. If the mathematical condition evaluates true, rung continuity passes to downstream instructions:
EQU(Equal): True if $\text{Source A} = \text{Source B}$.NEQ(Not Equal): True if $\text{Source A} \neq \text{Source B}$.LES(Less Than) /LEQ(Less Than or Equal): True if $\text{Source A} < \text{Source B}$ (or $\le$).GRT(Greater Than) /GEQ(Greater Than or Equal): True if $\text{Source A} > \text{Source B}$ (or $\ge$).LIM(Limit Test): Evaluates whether a test value lies within low and high limits.
Data Movement Instructions
MOV(Move): Copies an entire 16-bit or 32-bit word from a Source address into a Destination address. The Source contents remain unchanged.COP(Copy File): High-speed block copy that transfers continuous arrays of data without altering internal byte boundaries.CLR(Clear): Sets all bits within the target destination register to zero.
Analog Data Scaling (The SCP Instruction)
Raw analog values from ADC cards arrive as unscaled integer counts (e.g., 6,240 to 31,208 for 4-20 mA). To display human-readable values or execute control algorithms, the PLC must scale raw counts into Engineering Units (such as PSI, °C, or GPM) using linear slope-intercept math ($y = mx + b$):
SCALE WITH PARAMETERS (SCP):
┌──────────────────────────────────────────────┐
│ SCP │
│ Scale w/ Parameters │
│ Input: N7:0 (Raw Analog Count: 18724)│
│ Input Min: 6240 │
│ Input Max: 31208 │
│ Scaled Min: 0.0 (0.0 PSI) │
│ Scaled Max: 150.0 (150.0 PSI) │
│ Output: F8:0 (Scaled Engineering Units│
└──────────────────────────────────────────────┘
6. Programmable Automation Controllers (PACs) & Tag-Based Addressing
Legacy controllers used hardware-dependent rack/slot/bit addressing (e.g., I:2/3 represented Chassis 1, Slot 2, Terminal 3). Modern Programmable Automation Controllers (PACs) (such as Rockwell ControlLogix, Siemens S7-1500, and Schneider Modicon M580) utilize tag-based memory architectures:
- Alphanumeric Tag Names: Memory locations are assigned meaningful names (e.g.,
Hydraulic_Pump_Start_PB,Header_Steam_Pressure_PV). - Tag Scopes:
- Controller Scope: Global tags accessible to all routines, tasks, and external HMIs throughout the entire processor.
- Program Scope: Local tags isolated exclusively within a single program folder, preventing data conflicts between identical machinery routines (e.g., multiple identical packaging lanes).
- User-Defined Data Types (UDTs): Programmers can create custom composite data structures bundling multiple data types into a single object. For example, a UDT named
PUMP_MOTORmight bundleStart(BOOL),Stop(BOOL),Overload_Tripped(BOOL),Speed_RPM(INT), andBearing_Temp(REAL).
Human-Machine Interface (HMI) Integration
The HMI communicates directly with the PLC tag database over industrial Ethernet (OPC-UA, CIP, Modbus TCP). Electricians configuring or troubleshooting HMIs manage three core functions:
- Dynamic Graphical Status: Color-coded animations (green = running, red = stopped, flashing yellow = alarm).
- Analog Setpoint Entry: Operator numerical inputs with built-in high/low clamp limits to prevent out-of-range commands from damaging equipment.
- Alarm Handling & Logging: Time-stamped alarm banners categorized by severity, enforcing mandatory operator acknowledgment before clearing.
A raw analog input register reads 18,724 counts from a 4-20 mA pressure transmitter mapped to an integer range of 6,240 (at 4 mA) to 31,208 (at 20 mA). The transmitter is calibrated to measure 0.0 to 150.0 PSI. What is the process pressure in engineering units?