CEI331 PLC Programming
CEI331 PLC Programming
A PLC is a rugged, real-time control system that monitors inputs (sensors, switches) and
processes them to control outputs (motors, valves, actuators) based on pre-programmed logic.
The key characteristics of a PLC are:
A typical PLC consists of several key components that work together to perform control tasks:
PLCs can communicate with other PLCs or supervisory systems (e.g., SCADA,
o
DCS) using communication protocols like Modbus, Profibus, or Ethernet/IP.
6. Human-Machine Interface (HMI) (Optional but often used):
o Allows operators to interact with the PLC, monitor real-time status, and make
adjustments.
o Often used for displaying control processes, alarms, or diagnostics.
Working of PLC
The operation of a PLC can be understood through its scan cycle, which is the repeated sequence
of steps the PLC performs to monitor and control the system:
1. Input Scan: The PLC reads the status of all connected input devices (e.g., sensors,
switches).
2. Program Execution: The PLC runs the control program, performing logical and
arithmetic operations based on input conditions.
3. Output Scan: The PLC updates the status of all output devices (e.g., turning motors on
or off, opening or closing valves).
4. Housekeeping: The PLC performs any necessary internal functions, like communication
or diagnostics.
This scan cycle is repeated continuously, and the PLC responds in real-time to any changes in
input conditions.
PLCs can be programmed using various languages, with the most common being:
Each language has its strengths, and the choice depends on the specific application and the user's
familiarity.
Downloaded by Gowtham Raj (gowthamtb2004@[Link])
lOMoARcPSD|65740826
1. Flexibility: PLC programs can be easily modified or updated to change control sequences
without rewiring or changing hardware.
2. Reliability: PLCs are designed to operate in harsh industrial environments and provide
real-time responses.
3. Ease of Troubleshooting: With diagnostic tools and software, PLCs provide easier ways
to troubleshoot and detect problems in the control system.
4. Cost-effective: While PLCs have an initial cost, they often reduce long-term maintenance
costs compared to traditional hardwired systems.
5. Scalability: PLCs can be expanded by adding modules for more inputs, outputs, or
specialized functions.
6. Integration with other systems: PLCs can be integrated with SCADA systems, DCS
(Distributed Control Systems), and other automation tools.
Applications of PLCs
Conclusion
PLC programming plays a crucial role in industrial automation, offering a flexible, reliable, and
efficient solution to control complex processes. Understanding PLCs, their architecture,
programming languages, and applications is essential for anyone involved in industrial control,
automation, or process engineering.
A PLC consists of several key components, each performing a specific function to ensure the
control and automation process runs smoothly. Below is a simplified block diagram of a typical
PLC system:
+-------------------+
|
V
+-------------------+
| CPU (Central |
| Processing Unit)|
+-------------------+
|
+-----------------+-----------------+
| |
V V
+------------------+ +------------------+
| Input Modules | | Output Modules |
| (Digital/Analog)| | (Digital/Analog) |
+------------------+ +------------------+
| |
+-------------------------------------+
|
V
+-------------------+
| Communication |
| Interface |
+-------------------+
|
V
+-------------------+
| Programming |
| Device/Panel |
+-------------------+
1. Power Supply:
o Provides the necessary electrical power for the entire PLC system to operate.
o Typical PLCs operate on a 24V DC or AC supply.
2. CPU (Central Processing Unit):
o This is the brain of the PLC, responsible for processing the input data, executing
the program, and generating the appropriate outputs.
o It controls the entire operation of the PLC.
o It also contains the memory for storing the control program and data.
3. Input Modules:
o The input modules receive signals from external devices such as sensors,
switches, or other input devices.
o These can be either digital inputs (ON/OFF signals) or analog inputs
(continuous signals like temperature, pressure, etc.).
o The signals are then converted into a format that the PLC can process.
4. Output Modules:
o These modules send control signals to external devices like motors, actuators,
solenoids, or lamps based on the processed logic.
o Similar to input modules, outputs can be digital outputs (ON/OFF) or analog
outputs (varying control signals).
o The output modules activate the devices based on the PLC's program logic.
5. Communication Interface:
o This block allows the PLC to communicate with other devices, such as other
PLCs, supervisory systems
Downloaded likeRaj
by Gowtham SCADA, or remote I/O devices.
(gowthamtb2004@[Link])
lOMoARcPSD|65740826
Flow of Operation
1. Input Reading: The input modules receive signals from external devices (e.g., sensors)
and send them to the CPU.
2. Processing: The CPU processes the input signals using the control program and executes
the logic based on the conditions defined in the program (e.g., turning on a motor when a
sensor is activated).
3. Output Control: Based on the processed data, the CPU sends commands to the output
modules, activating or deactivating the corresponding devices (e.g., turning on a motor).
4. Communication: The PLC can also communicate with external devices and systems for
additional control, monitoring, or data collection.
PLC programming uses different languages to create control programs based on industrial needs.
These languages are standardized under the IEC 61131-3 standard, which defines five
programming languages for PLCs. The choice of language typically depends on the complexity
of the task, the user's background, and the hardware being used.
Description:
Ladder Logic is the most commonly used PLC programming language. It resembles
electrical relay diagrams and is particularly intuitive for those with an electrical
engineering or control background.
Structure:
It uses rungs (horizontal lines) that represent logic operations like relays and switches.
The left side of the rung represents input conditions (like a contact), and the right side
represents output actions (like a relay or motor).
Key Features:
o Easy to visualize and understand.
o Resembles traditional relay logic used in control panels.
o Great for discrete (ON/OFF) control systems, timers, counters, and basic logic.
Downloaded by Gowtham Raj (gowthamtb2004@[Link])
lOMoARcPSD|65740826
Example:
A simple ladder logic for turning a motor on when a start button is pressed:
|--[ Start Button ]--( Motor )--|
Here, when the Start Button is pressed, the Motor turns on.
Description:
FBD represents control logic as blocks connected by lines. Each block performs a
specific function (e.g., logic, arithmetic, comparison), and the blocks are connected to
define the control process.
Structure:
The diagram consists of blocks (function blocks), each representing a function such as
timers, counters, or mathematical operations. The blocks are connected with lines that
represent data flow.
Key Features:
o Good for designing complex control processes.
o Modular and easy to reuse function blocks.
o Typically used for continuous control processes (e.g., PID control).
Example:
A typical FBD might look like a block that performs an AND operation, where two
inputs need to be TRUE to activate an output.
Description:
Structured Text is a high-level, text-based programming language similar to traditional
programming languages like C, Pascal, or Python.
Structure:
It uses statements, functions, and control structures like IF, FOR, WHILE, CASE, etc.,
to create complex control logic in a textual form.
Key Features:
o Good for complex algorithms, loops, and arithmetic operations.
o High-level language, easy for those with programming experience to learn.
o Can handle more advanced control processes, including bit-level operations.
Example:
A simple structured text example to turn on a motor when a button is pressed:
IF Start_Button THEN
Motor := TRUE;
END_IF;
Description:
Instruction List is a low-level, assembly-like language used in PLC programming. It's
less popular now, but it was part of the original PLC programming standard.
Structure:
The language is composed of simple instructions (like MOV, ADD, AND) that the PLC
executes in sequence. Each instruction corresponds to a specific hardware operation.
Key Features:
o Low-level programming, similar to machine code or assembly language.
o Allows for precise control of hardware, but more difficult to read and maintain.
Example:
A simple example in Instruction List to turn on a motor when a start button is pressed:
LD Start_Button ; Load Start Button state
AND Motor_Off ; AND with Motor_Off state
OUT Motor ; Output to Motor
Note: Instruction List is being phased out in favor of the more user-friendly languages
like Ladder Logic and Structured Text.
Description:
SFC is used for describing processes that must be carried out in a specific sequence. It's
ideal for applications where operations must occur step-by-step, such as batch processes
or state machines.
Structure:
It uses steps and transitions. A step represents a state or operation in the process, and a
transition defines the condition under which the process moves from one step to another.
Key Features:
o Ideal for complex, sequential, or cyclical operations.
o Visual representation of the process, making it easy to understand and modify.
o Suitable for operations that involve multiple phases or stages.
Example:
In a basic SFC, a motor might go through multiple stages:
Step 1: Start Motor
Transition: Motor is ON
Step 2: Run Motor for 10 seconds
Transition: 10 seconds elapsed
Step 3: Stop Motor
Ladder Logic (LD) is ideal for simple control systems, especially when transitioning
from relay logic.
Function Block Diagram (FBD) is better for complex process control and when
modularity and reuse of functions are important.
Structured Text (ST) is suitable for tasks requiring sophisticated calculations, loops, and
conditions.
Instruction List (IL) is rarely used today but can be useful for low-level hardware
control in legacy systems.
Sequential Function Chart (SFC) is used when processes need to be executed in a
specific sequence.
Conclusion
The choice of PLC programming language depends on the application, complexity of the control
system, and the experience of the user. Most modern PLC systems support a combination of
these languages, allowing users to select the most appropriate one for each part of the program.
In PLC programming, instructions are the basic building blocks of the control program. These
instructions are executed in sequence to control the behavior of the system, like turning devices
on or off, performing calculations, or timing operations. Most PLCs support a variety of
instructions, categorized by their functionality.
Here’s an overview of basic instruction sets commonly found in PLCs, especially in Ladder
Logic (LD) and Structured Text (ST):
These are the basic instructions in ladder logic, used to represent electrical relay logic.
2. Timer Instructions
Timers are used to introduce delays or time-based control into PLC programs.
3. Counter Instructions
Counters are used to count events or pulses and perform actions based on the count.
o Description: Increments the counter each time the input becomes true.
o Usage: The counter counts the number of input transitions (e.g., pressing a
button).
o Example:
o --[ Count_Button ]--( CTU C1, 10 )--( Output )--
CTD (Count Down)
o Description: Decrements the counter each time the input becomes true.
o Usage: The counter counts down from a preset value.
o Example:
o --[ Reset_Button ]--( CTD C1, 0 )--( Output )--
RES (Reset Counter)
o Description: Resets the counter value to zero.
o Usage: Used to reset the count of a counter.
o Example:
o --[ Reset_Button ]--( RES C1 )--
4. Comparison Instructions
Equal (EQU)
o Description: Compares two values and returns true if they are equal.
o Example:
o --[ Value = 5 ]--( Output )--
Not Equal (NEQ)
o Description: Compares two values and returns true if they are not equal.
o Example:
o --[ Value != 5 ]--( Output )--
Greater Than (GT)
o Description: Returns true if the first value is greater than the second.
o Example:
o --[ Value > 5 ]--( Output )--
Less Than (LT)
o Description: Returns true if the first value is less than the second.
o Example:
o --[ Value < 5 ]--( Output )--
Greater Than or Equal (GEQ)
o Description: Returns true if the first value is greater than or equal to the second.
o Example:
o --[ Value >= 5 ]--( Output )--
Less Than or Equal (LEQ)
o Description: Returns true if the first value is less than or equal to the second.
o Example:
o --[ Value <= 5 ]--( Output )--
5. Mathematical Instructions
These instructions perform arithmetic operations like addition, subtraction, multiplication, and
division.
Downloaded by Gowtham Raj (gowthamtb2004@[Link])
lOMoARcPSD|65740826
ADD (Addition)
o Description: Adds two values together.
o Example:
o ADD( Value1, Value2 ) -> Result
SUB (Subtraction)
o Description: Subtracts one value from another.
o Example:
o SUB( Value1, Value2 ) -> Result
MUL (Multiplication)
o Description: Multiplies two values together.
o Example:
o MUL( Value1, Value2 ) -> Result
DIV (Division)
o Description: Divides one value by another.
o Example:
o DIV( Value1, Value2 ) -> Result
MOD (Modulo)
o Description: Returns the remainder when one value is divided by another.
o Example:
o MOD( Value1, Value2 ) -> Result
MOV (Move)
o Description: Moves data from one location to another.
o Example:
o MOV( Source_Value, Destination_Value )
COP (Copy)
o Description: Copies a block of data from one location to another.
o Example:
o COP( Source, Destination, Length )
FAL (Fill Array with a Value)
o Description: Fills an array with a specific value.
o Example:
o FAL( Array, Value, Length )
Conclusion
PLC instruction sets are the foundation for creating control programs that automate industrial
processes. By using these basic instructions—such as relay contacts, timers, counters,
comparison instructions, and arithmetic operations—you can create a variety of control systems.
These instructions work together to process inputs, perform operations, and control outputs.
In industrial automation, alarms and interlocks are critical for safety, equipment protection,
and reliable operation. A good design ensures that abnormal conditions are detected early and
unsafe operations are prevented automatically.
1. Alarms
What is an Alarm?
An alarm is a warning signal generated by the PLC to alert operators about an abnormal or
unsafe condition that requires attention.
Purpose of Alarms
Types of Alarms
1. Process Alarms
o High / Low temperature
o High / Low pressure
o Level alarms (Tank full / empty)
2. Equipment Alarms
o Motor overload
o Pump failure
o Sensor failure
3. Safety Alarms
o Emergency stop activated
o Fire or gas detection
Downloaded by Gowtham Raj (gowthamtb2004@[Link])
lOMoARcPSD|65740826
4. System Alarms
o PLC fault
o Power failure
o Communication failure
3. Alarm Indication
o Visual: Lamp, HMI message
o Audible: Buzzer or horn
4. Alarm Acknowledgement
o Operator confirms alarm (ACK button)
o Alarm remains logged until acknowledged
5. Alarm Reset
o Alarm clears automatically when condition returns to normal
o Or manual reset (depending on design)
2. Interlocks
What is an Interlock?
An interlock is a logical condition that prevents a machine or process from operating unless
certain safety conditions are met.
Purpose of Interlocks
Types of Interlocks
1. Safety Interlocks
o Emergency stop
o Door / guard closed
o Safety relay feedback
2. Process Interlocks
o Pump starts only if valve is open
o Motor runs only if lubrication is ON
3. Electrical Interlocks
o Prevent two motors from running together
o Forward and reverse motor interlock
4. Software Interlocks
o Implemented using PLC logic (no physical wiring)
This prevents forward and reverse contactors from turning ON at the same time.
4. Best Practices
Conclusion
PLC networking refers to the interconnection of PLCs with other PLCs, computers, HMIs,
SCADA systems, sensors, and actuators to enable data exchange, monitoring, and
coordinated control in an industrial automation system.
1. PLC–PLC Networking
2. PLC–HMI Networking
3. PLC–SCADA Networking
1. Serial Communication
RS-232
RS-485
Used for short distances and simple networks
2. Fieldbus Communication
Downloaded by Gowtham Raj (gowthamtb2004@[Link])
lOMoARcPSD|65740826
3. Ethernet-Based Communication
1. Modbus
2. Profibus
3. Profinet
Ethernet-based
High-speed real-time communication
Used in industrial automation
4. Ethernet/IP
5. CAN / CANopen
6. DeviceNet
1. Bus Topology
Downloaded by Gowtham Raj (gowthamtb2004@[Link])
lOMoARcPSD|65740826
2. Star Topology
PLC1
|
PLC2 -- Switch -- PLC3
|
PLC4
Easy troubleshooting
Widely used with Ethernet
3. Ring Topology
PLC1 ---- PLC2
| |
PLC4 ---- PLC3
High reliability
Used in redundant systems
Manufacturing plants
Power stations
Water treatment plants
Oil & gas industries
Building automation
Conclusion
PLC networking enables distributed, flexible, and efficient industrial automation systems.
By using suitable communication protocols and network structures, multiple PLCs and control
devices can work together reliably in real-time environments.
Safety in PLC-based automation is about protecting human life, equipment, and the
environment. Modern industries use Safety PLCs and well-designed safety logic to ensure
machines move to a safe state whenever a fault or abnormal condition occurs.
A normal PLC controls the process, whereas a Safety PLC is specifically designed to perform
safety-related functions.
2. Safety Interlocks
4. Redundancy
1. Fail-Safe Operation
o On power failure or fault → system goes to safe state
2. Redundancy
o Multiple safety channels for critical signals
3. Diagnostics & Monitoring
o Continuous fault detection
o Detection of short circuits, wire breaks
4. Separation of Safety & Control Logic
o Safety functions handled independently
6. Case Studies
Problem:
Operators work near a high-speed conveyor. Accidental entanglement risk exists.
Safety Solution:
If E_Stop = TRUE
→ All motors OFF
→ Alarm ON
→ Restart only after manual reset
Result:
Problem:
Machine should not run when safety door is open.
Safety Solution:
Logic:
Result:
Problem:
Boiler explosion risk due to high pressure or low water level.
Safety Measures:
Safety Action:
Result:
Problem:
Risk of hand injury during pressing operation.
Safety Solution:
Safety Logic:
Result:
8. Conclusion
Process safety automation is the systematic use of control systems—especially PLCs and
Safety PLCs—to prevent accidents such as fires, explosions, toxic releases, and equipment
damage in industrial processes. Safety is achieved in layers, so that if one layer fails, another
layer protects the process.
Process safety is implemented in multiple levels, ranging from basic control to emergency
response. PLCs play a major role in Levels 1 to 3.
Role of PLC
Functions
PID control
Start/stop sequencing
Normal interlocks
Downloaded by Gowtham Raj (gowthamtb2004@[Link])
lOMoARcPSD|65740826
Example
Safety Contribution
Role of PLC
Functions
Example
Safety Contribution
Functions
Standards
IEC 61508
IEC 61511
Example
If Pressure > High-High
→ Close fuel valve
→ Stop pump
→ Trip system
Safety Contribution
Example
Safety Contribution
Emergency evacuation
Fire brigade response
Disaster management plans
Example
Scenario
Level 1 (BPCS)
PLC controls temperature using PID loop.
Level 2 (Alarm)
High temperature alarm alerts operator.
Level 3 (SIS)
Safety PLC trips heater and opens vent valve at High-High temperature.
Level 4 (Physical)
Pressure relief valve opens if pressure continues to rise.
Level 5 (Emergency)
Plant evacuation if toxic release occurs.
10. Conclusion
The IEC 61131-3 is the international standard for programmable controllers, especially for
PLC programming languages and software structure. It is the most important standard for
automation engineers because it defines:
✅ Programming languages
✅ Program organization
✅ Data types and structures
✅ Software architecture
📌 Programming languages
📌 Software organization
📌 Data types
📌 Functions and function blocks
📌 Execution model
BOOL True/False
BYTE 8-bit
WORD 16-bit
DWORD 32-bit
STRING Text
IEC 61131-3 defines Program Organization Units which are building blocks of PLC software:
1. Program
2. Function Block
3. Function
Program
Function Block
Function
Reusable code
No internal memory (stateless)
Configuration
└── Resource (CPU)
└── Task
└── Program
E. Execution Model
5. Summary
5 programming languages
Data types
Program structure
Execution model
Modular programming
✔ Safety of personnel
✔ Protection of equipment
✔ Environment protection
✔ Compliance with legal requirements
✔ Consistency across industries
SIL Levels
SIL 1 10 – 100
2. Determination of SIL / PL
Example:
Example:
Example logic:
IF (Pressure_HH) THEN
Shutdown_Valve := ON;
END_IF;
Standards require:
This includes:
Testing
Simulation
Proof testing
Documentation
Periodic testing
Calibration
Firmware updates
Safety audits
Safety Function
If Pressure > High-High (HH)
→ Shutdown valve closes
→ Vent valve opens
→ Alarm triggers
SIL Requirement
Conclusion
✔ Reliable
✔ Consistent
✔ Testable
✔ Maintained throughout lifecycle
✔ Compliant with legal requirements
Unit – II IEC61131-3
2.1 Rails
In IEC 61131-3, the term “rails” is not a standard technical term. However, in the context of
PLC programming (Ladder Diagram), “rails” refer to the vertical power lines on the left
and right sides of a ladder diagram.
Rails are the vertical lines on both sides of a ladder diagram representing:
They form the boundary of the ladder diagram, and the rungs (horizontal lines) connect between
these rails.
Meaning of Rails
Left Rail
Acts as the logical Downloaded
power source (like the live wire in electrical diagrams).
by Gowtham Raj (gowthamtb2004@[Link])
lOMoARcPSD|65740826
Right Rail
Acts as the return path (like neutral wire).
All logic conditions are evaluated from left to right, just like current flowing from left rail to
right rail.
Here:
This means:
Summary
Term Meaning in IEC 61131-3 Ladder Diagram
In IEC 61131-3, Ladder Diagram (LD) is one of the standard PLC programming languages. A
rung is a horizontal line in a ladder diagram that represents a single logic statement or control
operation.
What is a Rung?
Structure of a Rung
Left Rail ───[ Contacts ]──( Output )── Right Rail
Meaning
Meaning
Motor ON when:
o Start button is pressed
o Stop button is NOT pressed
Symbol Meaning
2. Coils (Outputs)
Symbol Meaning
3. Function Blocks
Meaning:
Meaning:
A rung can have parallel branches (OR logic) or series branches (AND logic).
Series (AND)
|--[ A ]--[ B ]--( Output )--|
Parallel (OR)
|--[ A ]----------------( Output )--|
|--[ B ]----------------( Output )--|
Summary
Term Meaning
Relay Logic is the basic logic used in Ladder Diagram (LD) programming. It is modeled after
electrical relay circuits, where contacts and coils are used to control machines.
In IEC 61131-3, Ladder Diagram is one of the standard languages and relay logic is the
foundation of ladder programming.
1. Contacts
2. Coils
3. Relay
Meaning
Meaning
Meaning
Key Points
In IEC 61131-3, a latch switch is implemented using latching logic, which is commonly done
using SET (OTL) and RESET (OTU) coils in Ladder Diagram (LD).
This is used to hold an output ON even after the input is removed (like a memory).
Motor starters
Pumps
Conveyor belts
Automatic systems that need to stay ON
Ladder Diagram
|--[ Start ]------( OTL Motor )--|
|--[ Motor ]------( OTL Motor )--|
|--[ Stop ]------( OTU Motor )--|
Explanation
How It Works
Condition Result
Applications of Latching
Important Points
In IEC 61131-3, timers are standard function blocks used in PLC programming. They help you
create time-based control actions, such as delays, pulse generation, and time measurement.
Symbol
TON
Operation
Example
Action: Delays turning OFF an output after the input becomes FALSE.
Symbol
TOF
Operation
Example
3 TP (Pulse Timer)
Symbol
TP
Operation
When input turns TRUE → output turns TRUE for preset time
After time expires → output becomes FALSE
If input stays TRUE, the pulse still remains fixed
Example
ET Elapsed Time
Ladder Diagram
|--[ Start ]--( TON T1, PT=5s )--|
|--[ T1.Q ]--( Motor )--|
Explanation
Ladder Diagram
|--[ Motor ]--( TOF T2, PT=3s )--|
|--[ T2.Q ]--( Lamp )--|
Downloaded by Gowtham Raj (gowthamtb2004@[Link])
lOMoARcPSD|65740826
Explanation
Ladder Diagram
|--[ Start ]--( TP T3, PT=2s )--|
|--[ T3.Q ]--( Buzzer )--|
Explanation
Practical Applications
Important Notes
In IEC 61131-3, counters are standard function blocks used in PLC programming to count
events like pulses, items, or operations. Counters are widely used in industrial automation for
counting objects on conveyors, batching, production totals, etc.
Counts upward each time the input signal changes from FALSE to TRUE (rising edge).
Use
Input Meaning
CU Count Up input
R Reset
PV Preset Value
CV Current Value
Counts downward each time the input signal changes from FALSE to TRUE.
Use
Input Meaning
R Reset
PV Preset Value
CV Current Value
Use
Input Meaning
CU Count Up
CD Count Down
R Reset
PV Preset Value
CV Current Value
QU Output when CV ≥ PV
QD Output when CV ≤ 0
Goal
Count number of items passing a sensor. When count reaches 10 → turn ON output.
Ladder Logic
|--[ Sensor ]--( CTU C1, PV=10 )--|
|--[ C1.Q ]--( Output )--|
Meaning
Goal
Start with 20 items and count down with each item removed. When count reaches 0 → stop
process.
Ladder Logic
|--[ ItemRemoved ]--( CTD C2, PV=20 )--|
|--[ C2.Q ]--( Stop )--|
Goal
Up button increments
Down button decrements
Ladder Logic
|--[ UpButton ]--( CTUD C3 )--|
|--[ DownButton ]--( CTUD C3 )--|
🔹 Counter Reset
Key Points
Applications of Counters
Batching systems
Product counting
Part sorting
Production monitoring
Downloaded by Gowtham Raj (gowthamtb2004@[Link])
lOMoARcPSD|65740826
Filling operations
Boolean logic is the foundation of PLC programming. In IEC 61131-3, Boolean logic is used to
control the flow of logic in Ladder Diagram (LD), Function Block Diagram (FBD), and
Structured Text (ST).
Value Meaning
TRUE 1
FALSE 0
A B A AND B
0 00
0 10
1 00
1 11
Structured Text
Output := A AND B;
2 OR (Logical Disjunction)
A B A OR B
0 00
0 11
1 01
1 11
Structured Text
Output := A OR B;
A NOT A
0 1
1 0
Structured Text
Output := NOT A;
A B A NAND B
0 01
0 11
A B A NAND B
1 10
Structured Text
Output := NOT (A AND B);
A B A NOR B
0 01
0 10
1 00
1 10
Structured Text
Output := NOT (A OR B);
A B A XOR B
0 00
0 11
1 01
1 10
Structured Text
Output := A XOR B;
Parallel Contacts = OR
|--[ A ]---------------( Output )--|
|--[ B ]---------------( Output )--|
Example
IF (Start AND NOT Stop) OR Reset THEN
Motor := TRUE;
ELSE
Motor := FALSE;
END_IF;
Summary Table
Boolean Operator Ladder Symbol Structured Text
OR Parallel contacts A OR B
In IEC 61131-3, math instructions and data manipulation instructions are part of standard
function blocks used for processing numeric data and managing variables in PLC programs.
These instructions are commonly used in Structured Text (ST) and Function Block Diagram
(FBD), and are also available in Ladder Diagram (LD) in most PLC software.
These are basic arithmetic operations used on numeric data types (INT, DINT, REAL, etc.)
A. Addition (+)
C := A + B;
Example:
If A = 10, B = 20 → C = 30
B. Subtraction (-)
C := A - B;
Example:
If A = 30, B = 10 → C = 20
C. Multiplication (*)
C := A * B;
Example:
If A = 5, B = 6 → C = 30
D. Division (/)
C := A / B;
Example:
If A = 20, B = 4 → C = 5
E. Modulus (MOD)
C := A MOD B;
Example:
If A = 20, B = 6 → C = 2 (remainder)
F. Exponentiation (Power)
C := A ** B;
Example:
If A = 2, B = 3 → C = 8
2. Comparison Instructions
Instruction Meaning
= Equal
Example
IF Temperature >= SetPoint THEN
Heater := FALSE;
END_IF;
A. Move (MOV)
MOV(Source, Destination);
Example
MOV(TempValue, DisplayValue);
C. Copy (CPY)
D. Set / Reset
SET(Output);
RESET(Output);
E. Shift Instructions
Instruction Meaning
F. Bitwise Operations
Instruction Meaning
OR Bitwise OR
G. Type Conversion
Function Meaning
C := A + B; // Math operation
D := INT_TO_REAL(C); // Type conversion
IF C >= 15 THEN
Output := TRUE;
END_IF;
Applications
Summary Table
Category Instructions
Math +, -, *, /, MOD, **
Data Manipulation MOV, CPY, SET, RESET, SHL, SHR, ROL, ROR
IEC 61131-3 standardizes PLC programming, but it also recognizes the need for
communication between PLCs and other automation devices. Although IEC 61131-3 does not
define network protocols, it provides guidelines and structures that support communication
and distributed control systems.
IEC 61131-3 defines standard software architecture and program organization, which makes
it easier to build distributed automation systems using communication networks.
Modern industrial systems often have multiple PLCs distributed across a plant.
Communication is required for:
Tasks
Programs
Resources
Configurations
For distributed systems, tasks in different PLCs must synchronize using network
communication.
Downloaded by Gowtham Raj (gowthamtb2004@[Link])
lOMoARcPSD|65740826
Sensors
Drives
HMIs
SCADA
MES / ERP
IEC 61131-3 supports standard data types and structures, making data exchange easier.
✔ Online monitoring
✔ Online editing
✔ Diagnostics
IEC 61131-3 defines data types and structures which are essential for communication:
These types allow consistent data exchange across devices and systems.
Configuration
└─ Resource (CPU)
└─ Task
└─ Program
Downloaded by Gowtham Raj (gowthamtb2004@[Link])
lOMoARcPSD|65740826
Periodic execution
Event-based execution
In a networked system, tasks may depend on data received from other PLCs.
Programs
Function Blocks
Functions
Ethernet/IP, Profinet, Modbus, OPC UA (not defined by IEC 61131-3 but supported by
PLC vendors)
Important Note
IEC 61131-3 does not define specific network protocols (like Modbus, Profinet, etc.).
Instead, it provides:
✔ Program organization
✔ Execution model
Summary Table
Requirement IEC 61131-3 Support
IEC 61131-3 does not define network protocols, but it supports communication through:
So, PLC-to-PC communication is implemented using standard PLC programs defined in IEC
61131-3, but the network protocol is chosen by the PLC vendor (e.g., Modbus TCP, OPC UA,
Ethernet/IP).
Program
Function Block
Function
A) Shared Variables
Typical Architecture
PLC (IEC 61131-3 Program)
|
Ethernet / Serial
|
PC (SCADA / HMI / Data Logger)
Even though IEC 61131-3 does not define protocols, these are commonly used:
Protocol Use
PLC Side
PC Side
PLC Side
PC Side
Summary
IEC 61131-3 provides the programming framework, while communication protocols are
implemented using vendor-specific libraries and function blocks.
Function Block Diagram (FBD) and Ladder Logic (LD) are both graphical programming
languages in IEC 61131-3.
Although they look different, many ladder logic circuits can be represented in FBD using logic
blocks and contacts.
Ladder Logic
|--[ A ]--[ B ]--( Q )--|
FBD Equivalent
A ----| AND |---- Q
B ----|
Ladder Logic
|--[ A ]--------------( Q )--|
|--[ B ]--------------( Q )--|
FBD Equivalent
A ----| OR |---- Q
B ----| Downloaded by Gowtham Raj (gowthamtb2004@[Link])
lOMoARcPSD|65740826
Ladder Logic
|--[ /A ]--( Q )--|
FBD Equivalent
A ----| NOT |---- Q
4) AND + OR Combination
Ladder Logic
|--[ A ]--[ B ]--------------( Q )--|
|--[ C ]---------------------------|
FBD Equivalent
(A AND B) ----|
| OR |---- Q
C ------------|
Ladder Logic
|--[ Start ]--( M )--|
|--[ M ]-------------|
|--[ Stop ]--( /M )--|
FBD Equivalent
6)Timer (TON)
Ladder Logic
|--[ Start ]--( TON T1 )--|
|--[ T1.Q ]--( Motor )--|
FBD Equivalent
Start ----| TON |---- T1.Q ---- Motor
7) Counter (CTU)
Ladder Logic
|--[ Pulse ]--( CTU C1 )--|
|--[ C1.Q ]--( Output )--|
FBD Equivalent
Pulse ----| CTU |---- C1.Q ---- Output
Ladder
|--[ A ]--[ B ]--( X )--|
|--[ C ]----------------|
FBD
A ----| AND |----|
B ----| | |
| OR |---- X
C --------------|
Function Block Diagram (FBD) is one of the five programming languages defined by IEC
61131-3 for PLC programming. FBD is a graphical language that represents control systems
Downloaded by Gowtham Raj (gowthamtb2004@[Link])
lOMoARcPSD|65740826
using function blocks, connected with data flow paths. It is commonly used in process control
systems, automation, and industrial applications.
FBD Basics
Function Blocks (FBs) are the building blocks of FBD programming. Each block
represents a specific function or operation.
Connections (lines) represent the flow of data between blocks.
Inputs and Outputs are the variables used to transfer data into and out of blocks.
Key Components:
1. Function Block (FB): Encapsulates a specific functionality (e.g., AND, OR, Timer,
Counter).
2. Variables (Inputs/Outputs): Inputs and outputs are the data associated with each
function block.
3. Connections: Lines that represent data flow, linking blocks together.
8. Variables
o Inputs: Data coming into the function block.
o Outputs: Results produced by the function block.
9. Data Flow
o Arrows or lines are used to show how data flows between function blocks.
The AND block has multiple inputs and produces an output that is true when all inputs
are true.
FBD Representation:
A ----|
| AND |---- Q
B ----| Downloaded by Gowtham Raj (gowthamtb2004@[Link])
lOMoARcPSD|65740826
2) OR Function Block
The OR block has multiple inputs and produces an output that is true if any one input is
true.
FBD Representation:
A ----|
| OR |---- Q
B ----|
Q is TRUE if A OR B is TRUE.
FBD Representation:
A ----| NOT |---- Q
Q is the opposite of A.
The TON (Timer ON Delay) function block starts counting when the input is TRUE.
After the preset time has passed, the output is set to TRUE.
FBD Representation:
Start ----| TON |---- Q
|
| T1
The CTU (Counter Up) function block increments a counter each time the input signal
goes from FALSE to TRUE.
FBD Representation:
Downloaded by Gowtham Raj (gowthamtb2004@[Link])
lOMoARcPSD|65740826
In this example, we’ll use FBD to create a simple motor control system that starts and stops a
motor based on inputs:
FBD Representation:
StartButton ----|
| AND |---- Motor
StopButton ----|
| NOT |
|
Timer (TON)
In IEC 61131-3, function blocks are used for many operations. Some common function blocks
include:
1) Mathematical Operations
2) Logical Operations
3) Timers
4) Counters
Problem
FBD Diagram
StartButton ----|
| AND |---- Motor
StopButton ----|
| NOT |
|
Timer (TON)
AND
AND block Logic is true when all inputs are true.
Operation
NOT
NOT block Inverts the input signal.
Operation
TON (Timer ON
Timer (TON) Delays the output when the input is true.
Delay)
Instruction List (IL) is one of the five programming languages defined in IEC 61131-3 for
PLC programming.
It is a low-level textual language, similar to assembly language, designed for simple and fast
PLC programs.
Note:
IL is deprecated in later versions of IEC 61131-3 and many modern PLCs do not support it.
However, it is still important for understanding older PLC programs and exam purposes.
Key Features of IL
✅ Text-based (assembly-like)
✅ Compact and fast execution
✅ Suitable for simple logic
✅ Often used in older PLCs
Instructions
Operands (variables)
Labels
Comments
Common IL Instructions
Instruction Meaning
LD Load a value
Downloaded by Gowtham Raj (gowthamtb2004@[Link])
lOMoARcPSD|65740826
Instruction Meaning
OR Logical OR
ST Store result
NOT Invert
ADD Addition
SUB Subtraction
MUL Multiply
DIV Divide
CTU Counter Up
Problem
Motor starts when Start button is pressed and stops when Stop button is pressed.
IL Code
LD Start
ANDN Stop
ST Motor
Explanation
IL Instructions (Detailed)
1) Load Instructions
Instruction Meaning
2) Logical Instructions
Instruction Meaning
OR OR operation
3) Store Instructions
Instruction Meaning
4) Set / Reset
Instruction Meaning
Instruction Meaning
Problem
Motor should latch ON after Start pressed and turn OFF on Stop.
IL Code
LD Start
SET Motor
LD Stop
RST Motor
Advantages of IL
Disadvantages of IL
IL vs Ladder Diagram
Ladder Diagram Instruction List
Graphical Textual
Sequential Function Chart (SFC) is one of the five programming languages defined in IEC
61131-3.
It is a graphical language used for sequential control systems, where processes occur in steps
and transitions.
✔ Batch processes
✔ Start-up and shutdown sequences
✔ Step-by-step operations
✔ Process control with multiple states
1 Steps
2 Transitions
Connect steps.
Each transition has a condition.
When the condition is TRUE, the active step transfers control to the next step.
3 Actions
SFC Structure
Step 1 --[Transition 1]--> Step
Downloaded 2 --[Transition
by Gowtham 2]--> Step 3
Raj (gowthamtb2004@[Link])
lOMoARcPSD|65740826
Types of Actions
Action Type Description
Objective
SFC Diagram
[Step 1: Start Conveyor]
|
[T1: StartButton]
|
[Step 2: Conveyor Running]
|
[T2: Timer Done]
|
[Step 3: Stop Conveyor]
Transition2:
IF Timer.Q THEN
Step2 := FALSE;
Step3 := TRUE;
END_IF;
Advantages of SFC
Applications of SFC
State-based Logic-based
✅ Summary Table
Component Meaning
Structured Text (ST) is one of the five programming languages defined by IEC 61131-3.
It is a high-level textual language, similar to Pascal or C, used for complex algorithms, math
operations, data handling, and structured programming.
✔ Process control
✔ Motion control
✔ Data manipulation
✔ Complex logic
✔ PID control
✅ High-level language
✅ Easy for complex calculations
✅ Supports loops, conditions, arrays, structures
✅ Best for algorithm-based programming
✅ Very readable for programmers
Basic Syntax of ST
Variable Declaration
VAR
A : INT;
B : REAL;
Motor : BOOL;
END_VAR
Basic Operations in ST
1) Assignment
A := 10;
B := 3.14;
Motor := TRUE;
2) IF-ELSE Statement
IF Start AND NOT Stop THEN
Motor := TRUE;
ELSE
Motor := FALSE;
END_IF;
3) CASE Statement
CASE Mode OF
0: Motor := FALSE;
1: Motor := TRUE;
2: Motor := NOT Motor;
ELSE
Motor := FALSE;
END_CASE;
4) FOR Loop
FOR i := 1 TO 10 DO
Sum := Sum + i;
END_FOR;
5) WHILE Loop
WHILE A < 10 DO
A := A + 1;
END_WHILE;
Downloaded by Gowtham Raj (gowthamtb2004@[Link])
lOMoARcPSD|65740826
Function
Function Block
FUNCTION_BLOCK FB_Latch
VAR_INPUT
Set : BOOL;
Reset : BOOL;
END_VAR
VAR_OUTPUT
Q : BOOL;
END_VAR
IF Set THEN
Q := TRUE;
ELSIF Reset THEN
Q := FALSE;
END_IF;
END_FUNCTION_BLOCK
TON Timer
TON(Timer := Start, PT := T#5s);
IF Timer.Q THEN
Motor := TRUE;
END_IF;
Counter
IF Pulse THEN
Count := Count + 1;
END_IF;
Motor := TRUE;
ELSE
Motor := FALSE;
END_IF;
Advantages of ST
Applications
PID control
Complex math operations
Data processing
Batch control
Motion control
Summary
Feature Description
Similar to Pascal / C