You are on page 1of 57

EEC3420 Industrial Control

Department of Electrical Engineering

Lecture 3

Basic Programmable Logic Controller


(PLC) Programming

Vocational Training Council, Hong Kong. Week 1


EEE3420 Industrial Control

Learning Objectives
Know different types of programming languages used in
PLC
Understand the basic programming techniques of PLC

Vocational Training Council, Hong Kong. Week 2


EEE3420 Industrial Control

IEC 61131 standards for PLC


the use of PLC has been standardized by the IEC
developed with the input of vendors, end-users and
academics, IEC 61131 consists of five parts:
General information
Equipment and test requirements
PLC programming languages
User guidelines
Communications

Vocational Training Council, Hong Kong. Week 3


EEE3420 Industrial Control

The IEC 61131-3 programming language


the international standard for programmable controller
programming languages
specifies the syntax, semantics and display for the
following suite:
Ladder diagram (LD)
Sequential Function Charts (SFC)
Function Block Diagram (FBD)
Structured Text (ST)
Instruction List (IL)

Vocational Training Council, Hong Kong. Week 4


EEE3420 Industrial Control

Ladder diagram (LD)


widely spread graphical programming language for
PLCs
a programmatically replacement for relays and coils
which can be combined using AND and OR operations
best suited to compute Boolean expressions
IEC 61131-3 defines a complete LD set of instructions,
consisting of different types of contacts and coils

Vocational Training Council, Hong Kong. Week 5


EEE3420 Industrial Control

Ladder diagram (LD)


contacts lead (according to their type) the power
from the left to the right
coils store the incoming value
both, contacts and coils, are assigned to Boolean
variables
an LD network can be supplemented by jumps,
returns, labels and comments

Vocational Training Council, Hong Kong. Week 6


EEE3420 Industrial Control

Sequential Function Charts (SFC)


SFC is the IEC 61131 -3 method to program
sequential controls
actions may contain Boolean variables or entire
networks, networks are programmed in Ladder
Diagram, true action associations from several
steps, several concurrent SFC networks in one
diagram

Vocational Training Council, Hong Kong. Week 7


EEE3420 Industrial Control

Function Block Diagram (FBD)


FBD defined in IEC 61131-3 consists of different
functions and function blocks that are either linked or
connected to variables
in FBD networks, jumps, labels and returns can be used
similar to the creation of functional diagrams or block
diagrams, with the control logic being created by simply
connecting blocks and elements
frequently used in the process industry due to the flow-
oriented properties of function blocks

Vocational Training Council, Hong Kong. Week 8


EEE3420 Industrial Control

Structured Text language (ST)


similar to the high-level language PASCAL or BASIC
uses statements like IF...THEN or FORNEXT
concerned compiler is responsible for syntactically
correct insertion of the language constructions
text editor simplifies the programming work through
syntax highlighting
syntax and the set of instructions of ST are optimally
suited for mathematical calculations and data
manipulations

Vocational Training Council, Hong Kong. Week 9


EEE3420 Industrial Control

Instruction List (IL)


an assembler type textual programming language
large (and mostly incompatible) sets of instructions
have been created by many vendors
the IEC 61131 Instruction list reduced this set to a
minimum and favours the usage of functions and
function blocks for more complex tasks
code in IL consists of a sequence of instructions
separated by lines, which consist of one operator
("command"), one operand (variable, constant or
instance name) and one optional modifier respectively

Vocational Training Council, Hong Kong. Week 10


EEE3420 Industrial Control

Instruction List (IL)


jumps and labels can be used
concerned assembler is responsible for syntactically
correct insertion of the language constructions
text editor simplifies the programming work through
syntax highlighting (colour marking of language
elements)
mainly used if the processing speed of the PLC
program has high priority

Vocational Training Council, Hong Kong. Week 11


EEE3420 Industrial Control

Instruction List (IL)


Basic instructions used in Allen Bradley PLC

Mnemonic Function Mnemonic Function

LD Load ANDN And Not


LDN Load Not ORN Or Not
ST Store MPS Memory Push
STN Store Not MPP Memory Pop
AND And MRD Memory Read
OR Or MCR Master Control Relay
ANB And Block
ORB Or Block

Note: The instruction mnemonic may vary across different series of the Allen
Bradley PLCs.

Vocational Training Council, Hong Kong. Week 12


EEE3420 Industrial Control

Instruction List (IL)


Basic instructions used in Omron PLC

Mnemonic Function Mnemonic Function

LOAD Load NOP No Operation


LOAD NOT Load Not TR Temp. Register
OUT Out IL InterLock (eq. to MC)
AND And ILC InterLockClear(eq. to
MCR)
AND NOT And Inverted
AND LD And Block
OR Or
OR NOT Or Not
OR LD Or Block

Vocational Training Council, Hong Kong. Week 13


EEE3420 Industrial Control

Instruction List (IL)


Basic instructions used in Mitsubishi PLC FX series

Mnemonic Function Mnemonic Function

LD Load NOP No Operation


LDI Load Inverted MPS Memory Push
OUT Out MPP Memory Pop
AND And MRD Memory Read
ANI And Inverted MC Master Control
ANB And Block MCR Master Control Reset
OR Or
ORI Or Inverted
ORB Or Block

Vocational Training Council, Hong Kong. Week 14


EEE3420 Industrial Control

IL, LD and its associated logic equation

operation labeled
with circle 1 is
performed first as it
is the deepest
nested term, and
operations proceed
with circle 2,circle 3
and circle 4
consecutively
(Mitsubishi PLC
codes)

Vocational Training Council, Hong Kong. Week 15


EEE3420 Industrial Control

Instruction List (IL)


A list of commonly used IL operators defined in IEC 61131-3

Vocational Training Council, Hong Kong. Week 16


EEE3420 Industrial Control

Instruction List (IL)


example of IL using the syntax defined in IEC 61131-3

Vocational Training Council, Hong Kong. Week 17


EEE3420 Industrial Control

Instruction List (IL)

example of IL using
the syntax defined
in IEC 61131-3

Vocational Training Council, Hong Kong. Week 18


EEE3420 Industrial Control

Instruction List (IL)

example of IL program using


the instructions MPS, MPP &
MRD to implement multiple
outputs using the syntax
defined in IEC 61131-3

Vocational Training Council, Hong Kong. Week 19


EEE3420 Industrial Control

Instruction List (IL)

example demonstrating
the use of TR instruction
(similar to MPS, MPP &
MRD instructions defined
in IEC 6113-3) in Omron
PLC

Vocational Training Council, Hong Kong. Week 20


EEE3420 Industrial Control

Instruction List (IL)

example
demonstrating
the use of MCR
instruction in
Allen Bradley
PLC

Vocational Training Council, Hong Kong. Week 21


EEE3420 Industrial Control

Instruction List (IL)

example
demonstrating the
use of MC & MCR
instructions in
Mitsubishi PLC
(N0 is the nested
number, maximum
7,i.e. a total of 8
nested levels; SP
means space)

Vocational Training Council, Hong Kong. Week 22


EEE3420 Industrial Control

Instruction List (IL)

example
demonstrating
the use of IL &
ILC instructions
in Omron PLC

Vocational Training Council, Hong Kong. Week 23


EEE3420 Industrial Control

Conversion of more complex logic gates

Vocational Training Council, Hong Kong. Week 24


EEE3420 Industrial Control

Multiplexer

Vocational Training Council, Hong Kong. Week 25


EEE3420 Industrial Control

Time Related Instruction the Latch

a latch in ladder logic uses one


instruction to latch, and a
second instruction to unlatch
the output with an L inside will
turn the output D on when the
input A becomes true
D will stay on even if A turns off
D will turn off if input B
becomes true

Vocational Training Council, Hong Kong. Week 26


EEE3420 Industrial Control

Time Related Instruction the Latch

Vocational Training Council, Hong Kong. Week 27


EEE3420 Industrial Control

Time Related Instruction the Latch

a typical timing diagram, ignoring the brief pulse

Vocational Training Council, Hong Kong. Week 28


EEE3420 Industrial Control

The SR (Set-Reset) Flip Flop


Latches are not used universally by all PLC vendors,
others such as Siemens use flip-flops

Vocational Training Council, Hong Kong. Week 29


EEE3420 Industrial Control

The SR (Set-Reset) Flip Flop


the SR Flip Flop may be implemented by using AND-OR
functions

Vocational Training Council, Hong Kong. Week 30


EEE3420 Industrial Control

The SR (Set-Reset) Flip Flop


the SR Flip Flop may also be implemented by using SET-
RESET functions

Vocational Training Council, Hong Kong. Week 31


EEE3420 Industrial Control

The SR (Set-Reset) Flip Flop


implement the SR Flip Flop in Omron PLC

Vocational Training Council, Hong Kong. Week 32


EEE3420 Industrial Control

The Timers
four fundamental types
on-delay timer will wait for a set time after a line of
ladder logic has been true before turning on, but it
will turn off immediately
off-delay timer will turn on immediately when a line
of ladder logic is true, but it will delay before turning
off
retentive timer will sum all of the on or off time for a
timer, even if the timer never finished
non-retentive timer will start timing the delay from
zero each time

Vocational Training Council, Hong Kong. Week 33


EEE3420 Industrial Control

Operation of a TON (non-retentive) Timer

Vocational Training Council, Hong Kong. Week 34


EEE3420 Industrial Control

Operation of a RTO (retentive time on) timer

Vocational Training Council, Hong Kong. Week 35


EEE3420 Industrial Control

Operation of a TOF (non-retentive t-off) timer

Vocational Training Council, Hong Kong. Week 36


EEE3420 Industrial Control

Timers in Mitsubishi PLCs


in FX1N and FX2N series, there are four types of
timers
T0 ~ T199 are non-retentive time on timer with
timing interval of 100 ms
T200 ~ T245 are non-retentive time on timer with
timing interval of 10 ms
T246 ~ T249 are retentive time on timer with timing
interval of 1 ms
T250 ~ T255 are retentive time on timer with timing
interval of 100 m

Vocational Training Council, Hong Kong. Week 37


EEE3420 Industrial Control

Using non-retentive time on timer in


Mitsubishi FX series PLC

Vocational Training Council, Hong Kong. Week 38


EEE3420 Industrial Control

Timers in Omron PLC


in CP series, there are 48 timers/counters with
timing range running
from 0.1s to 999.9s if it is set as common timer
or 0.01s to 99.99s if it is set as high speed timer

Vocational Training Council, Hong Kong. Week 39


EEE3420 Industrial Control

Timers in Omron PLC

Vocational Training Council, Hong Kong. Week 40


EEE3420 Industrial Control

The Counters
two basic counter types:
count-up and count-down.
when the input to a count-up counter goes true the accumulator
value will increase by 1, if the accumulator value reaches the
preset value the counter DN bit will be set
a count-down counter will decrease the accumulator value until the
preset value is reached

Vocational Training Council, Hong Kong. Week 41


EEE3420 Industrial Control

An up-down counter in Allen Bradley PLC

Vocational Training Council, Hong Kong. Week 42


EEE3420 Industrial Control

Counter operation in Mitsubishi PLC

Vocational Training Council, Hong Kong. Week 43


EEE3420 Industrial Control

Counter operation in Omron PLC

Vocational Training Council, Hong Kong. Week 44


EEE3420 Industrial Control

The Edge Triggering Instructions


in Mitsubishi FX series PLC, there are two edge
triggering instructions, namely, PLS (PuLSe) and PLF
(PuLse Falling)

Vocational Training Council, Hong Kong. Week 45


EEE3420 Industrial Control

The Edge Triggering Instructions


in Mitsubishi FX series PLC, there are two edge
triggering instructions, namely, PLS (PuLSe) and PLF
(PuLse Falling)

Vocational Training Council, Hong Kong. Week 46


EEE3420 Industrial Control

The Edge Triggering Instructions


in Omron PLC, there are similar edge triggering
instructions, namely, the DIFU (DIFferentiate Up) and the
DIFD (DIFferentiate Down)

Vocational Training Council, Hong Kong. Week 47


EEE3420 Industrial Control

The Edge Triggering Instructions


in Omron PLC, there are similar edge triggering
instructions, namely, the DIFU (DIFferentiate Up) and the
DIFD (DIFferentiate Down)

Vocational Training Council, Hong Kong. Week 48


EEE3420 Industrial Control

Applications of Time Related Instructions

The timers and the counters find their


applications in many industrial process controls

Vocational Training Council, Hong Kong. Week 49


EEE3420 Industrial Control

Applications of Time Related Instructions

Pulse generator circuit

Vocational Training Council, Hong Kong. Week 50


EEE3420 Industrial Control

Applications of Time Related Instructions

Fixed width pulse generator circuit

Vocational Training Council, Hong Kong. Week 51


EEE3420 Industrial Control

Applications of Time Related Instructions


Delay off timer - Many PLCs such as Mitsubishi do not
provide delay off timer, but this function can easily be
built by the delay on timer

Vocational Training Council, Hong Kong. Week 52


EEE3420 Industrial Control

Applications of Time Related Instructions


Light flasher

Vocational Training Council, Hong Kong. Week 53


EEE3420 Industrial Control

Applications of Time Related Instructions


Variable delay on/variable delay off circuit with Mitsubishi
PLC

Vocational Training Council, Hong Kong. Week 54


EEE3420 Industrial Control

Applications of Time Related Instructions


Variable delay on/variable delay off circuit with Omron
PLC

Vocational Training Council, Hong Kong. Week 55


EEE3420 Industrial Control

Summary of Basic PLC Programming


The Instruction List programming language uses stack
operation to perform the operations specified.
Logic can be represented with basic Boolean operations
AND, OR, NOT.
Boolean equations can be converted to and from ladder
logic or instruction list.
The MPS, MPP and MRD enable intermediate results to
be pushed, pop and read to facilitate multiple outputs.
Use of the MC/MCR instructions simplifies the
organization of the ladder logic.
The time related instructions realize the sequential
functions.
Vocational Training Council, Hong Kong. Week 56
EEE3420 Industrial Control

Basic PLC Programming

End of Lecture 3

Revision
Mitsubishi PLC FX series hardware handbook.
Allen Bradley PLC handbook
Omron PLC manual

Vocational Training Council, Hong Kong. Week 57