Ilek Technologies

PLC Programming Basic Instructions

Industrial Automation Mar 03, 2026 83 views
PLC Programming Basic Instructions

Introduction

At the heart of every PLC program lies a set of fundamental instructions - the building blocks that every automation engineer must master before writing complex programs. These basic instructions fall into well-defined categories: bit logic operations, timer and counter instructions, comparison operations, mathematical operations, move and data handling instructions, and program control flow instructions.

This guide provides a complete, practical reference for all essential PLC instructions, explained in plain language with real-world examples in both Ladder Diagram (LAD) and Structured Control Language (SCL / Structured Text). Whether you are a student beginning your automation journey or an experienced engineer refreshing your knowledge, this guide will serve as your go-to reference.

PLC Programming Languages Overview

Before diving into individual instructions, it is important to understand that PLC supports multiple IEC 61131-3 programming languages. Each language represents the same logic differently, but all compile to the same machine code:

LanguageFull NameStyleBest For
LADLadder DiagramGraphical - resembles electrical relay circuit diagramsBit logic, relay replacement, beginners
FBDFunction Block DiagramGraphical - logic gates and function blocks connected by linesBoolean logic, signal flow visualization
STLStatement ListText - low-level assembly-like instructionsLegacy programs, compact code
SCLStructured Control LanguageText - high-levelComplex math, loops, data manipulation
GRAPHSequential Function ChartGraphical - step-by-step sequential controlProcess sequences, batch control

Bit Logic Instructions

Bit logic instructions are the foundation of PLC programming. They operate on single-bit Boolean (BOOL) variables - digital inputs, digital outputs, memory flags, and timer/counter status bits. Every PLC program, no matter how complex, is built on these fundamental operations.

Normally Open Contact (NO)

-| |-

Normally Open Contact

Passes power (TRUE) when the associated bit is 1 (TRUE). In electrical terms, this represents a normally open switch or contact that closes when the coil is energized. This is the most frequently used instruction in Ladder Diagram programming.

Normally Closed Contact (NC)

-|/|-

Normally Closed Contact

Passes power (TRUE) when the associated bit is 0 (FALSE). This is the logical inverse of the Normally Open contact. In electrical terms, it represents a normally-closed switch that opens when the coil is energized - cutting power when the condition is active.

Output Coil 

-( )-

Output Coil

Sets the associated bit to the value of the rung's power rail (TRUE or FALSE). When power flows through all contacts on the rung to the coil, the bit is set to 1. When power does not flow, the bit is reset to 0. This is the standard output assignment instruction.

Set Coil (S) and Reset Coil (R)

-( S )-

Set (Latch) Coil

Sets the associated bit to 1 (TRUE) and holds it there even after the enabling condition becomes FALSE. The bit remains set until a Reset (R) instruction explicitly clears it. Also known as a Latch coil.

-( R )-

Reset (Unlatch) Coil

Resets the associated bit to 0 (FALSE) and holds it at 0 until a Set (S) instruction sets it again. Set and Reset coils are always used in pairs to create latched (maintained) outputs.

Positive Edge Detect (P) and Negative Edge Detect (N)

-|P|-

Rising Edge (Positive Transition)

Produces a ONE-SCAN pulse (TRUE for exactly one PLC scan cycle) when the associated bit transitions from 0→1 (OFF to ON). Used to trigger one-shot actions on the rising edge of a signal.

-|N|-

Falling Edge (Negative Transition)

Produces a ONE-SCAN pulse when the associated bit transitions from 1→0 (ON to OFF). Used to trigger actions on the falling edge of a signal.

Timer Instructions

Timer instructions are among the most important in PLC programming. They are used everywhere: conveyor delays, pump run-on timers, alarm delays, dwell times in sequences, and safety monitoring timeouts.

TON - Timer On-Delay

TON

Timer On-Delay

Starts timing when the IN (enable) input goes TRUE. After the preset time PT elapses, the output Q goes TRUE. Q remains TRUE as long as IN stays TRUE. The elapsed time is available on the ET output. When IN goes FALSE, the timer resets immediately.
PinDirectionData TypeDescription
INInputBOOLEnable input - timer runs while IN = TRUE
PTInputTIMEPreset Time - how long to wait (e.g., T#5s)
QOutputBOOLOutput - goes TRUE when ET >= PT
ETOutputTIMEElapsed Time - current count value

TOF - Timer Off-Delay

TOF

Timer Off-Delay

The output Q goes TRUE immediately when IN goes TRUE. When IN goes FALSE, the timer starts counting. Q remains TRUE until the preset time PT elapses after IN goes FALSE. Used for run-on timers - keeping something running for a period after the trigger is removed.

TP - Timer Pulse

TP

Timer Pulse

Generates a fixed-duration output pulse. When IN transitions from FALSE to TRUE, Q goes TRUE for exactly the preset time PT, regardless of what IN does during that period. After PT elapses, Q goes FALSE. The timer cannot be re-triggered during the pulse.

Timer Comparison Table

Timer TypeOutput Goes ON When...Output Goes OFF When...Typical Use Case
TON (On-Delay)IN has been TRUE for >= PT durationIN goes FALSE (immediate reset)Startup delays, confirmation timers, debounce
TOF (Off-Delay)IN goes TRUE (immediately)IN goes FALSE AND PT duration elapsesRun-on timers, cooling fans, lubrication after stop
TP (Pulse)IN transitions FALSE→TRUE (rising edge)PT duration elapses after triggerFixed-time actuators, solenoid pulses, one-shots
TONR (Retentive)IN has been cumulatively TRUE for >= PTReset input R goes TRUEMaintenance hour counters, cumulative run time

Counter Instructions

Counter instructions count events - rising edges of a bit signal. They are used to count parts produced, cycles completed, bottles filled, faults occurred, or any discrete event that needs to be totalized.

CTU - Count Up Counter

CTU

Count Up Counter

Counts upward each time the CU (Count Up) input transitions from FALSE to TRUE (rising edge). When the accumulated count CV reaches or exceeds the preset value PV, the output Q goes TRUE. The counter holds its value until Reset input R goes TRUE.
PinDirectionData TypeDescription
CUInputBOOLCount Up - increments count on each rising edge
RInputBOOLReset - sets CV back to 0 when TRUE
PVInputINTPreset Value - count target
QOutputBOOLOutput - TRUE when CV >= PV
CVOutputINTCurrent Value - accumulated count

CTD - Count Down Counter

CTD

Count Down Counter

Counts downward each time the CD (Count Down) input has a rising edge. Starts from the preset value PV when Load input LD goes TRUE. Output Q goes TRUE when CV reaches 0 or below. Used for dispensing, depletion tracking, and countdown operations.

CTUD - Count Up/Down Counter

CTUD

Count Up/Down Counter

Combines both count-up and count-down capabilities in a single counter. CU input counts up, CD input counts down. QU output goes TRUE when CV >= PV (up limit reached); QD output goes TRUE when CV <= 0 (down limit reached). Useful for tracking quantity in a buffer or bin.

Comparison Instructions

Comparison instructions compare two values and produce a Boolean (BOOL) result. They are essential for threshold checks, range validation, setpoint comparisons, and conditional logic that involves numeric values. All comparison instructions work with numeric data types: INT, DINT, REAL, TIME, etc.

The Six Comparison Operators

InstructionLAD SymbolSCL OperatorCondition for TRUE Output
CMP ==-[ == ]-=IN1 is equal to IN2
CMP <>-[ <> ]-<>IN1 is NOT equal to IN2
CMP >-[ > ]->IN1 is greater than IN2
CMP >=-[ >= ]->=IN1 is greater than or equal to IN2
CMP <-[ < ]-<IN1 is less than IN2
CMP <=-[ <= ]-<=IN1 is less than or equal to IN2

Mathematical Instructions

Mathematical instructions perform arithmetic operations on numeric variables. Math operations can be performed on INT, DINT, REAL, and LREAL data types. REAL arithmetic is used for most process calculations since it supports decimal values.

Basic Arithmetic: ADD, SUB, MUL, DIV

InstructionLAD NameSCL OperatorDescription
ADDADD+Adds two values: OUT = IN1 + IN2
SUBSUB-Subtracts: OUT = IN1 - IN2
MULMUL*Multiplies: OUT = IN1 × IN2
DIVDIV/Divides: OUT = IN1 ÷ IN2 (integer division truncates)
MODMODMODModulo - remainder of integer division: OUT = IN1 MOD IN2

Move and Data Handling Instructions

Move and data handling instructions transfer values between variables, convert between data types, and manipulate data in memory. These are essential for recipe management, data logging, communication with other systems, and organizing process data.

MOVE - Simple Value Assignment

MOVE

Move / Assign Value

Transfers the value from the input (IN) to the output (OUT). It allows conditional data transfer - the move only occurs when the enable input (EN) is TRUE.

Conclusion & Learning Path

The instructions covered in this guide form the complete foundation of PLC programming. Every complex automation program - no matter how sophisticated - is ultimately built from these fundamental building blocks. A conveyor system's interlocking logic uses Bit Logic instructions. A batch process uses Timers and Counters to track time and quantity. A temperature control loop uses Comparison and Math instructions to calculate PID outputs.