Anda di halaman 1dari 112

2.3.

1 PLCs: Definition and Market

2.1 Instrumentation
2.2 Control
2.3 Programmable Logic Controllers
2.3.1 PLCs: Definition and Market
2.3.3 PLCs: Functions and construction
2.3.5 PLC Programming Languages
2.3.5.1 IEC 61131 Languages
2.3.5.2 Function blocks
2.3.5.3 Program Execution
2.3.5.4 Input / Output
2.3.5.5 Structured Text
2.3.5.6 Sequential Function Charts
2.3.5.7 Ladder Diagrams
2.3.5.8 Instruction Lists
2.3.5.9 Programming environment

Industrial Automation
2013

Programmable Logic Controllers 2.3 - 1

PLC = Programmable Logic Controller: Definition


AP = Automates Programmables industriels
SPS=SpeicherprogrammierbareSteuerungen
Definition:

small computers, dedicated to automation tasks in an industrial environment"

Formerly:

cabled relay control (hence 'logic'), analog (pneumatic, hydraulic) governors

Today:

real-time (embedded) computer with extensive input/output

Function:

Measure, Control, Protect

Distinguish

Instrumentation
flow meter, temperature, position,. but also actors (pump, )
Control
programmable logic controllers with digital peripherals & field bus
Visualization
Human Machine Interface (HMI) in PLCs (when it exists) is limited
to service help and control of operator displays

Industrial Automation
2013

Programmable Logic Controllers 2.3 - 2

Simple PLC
network

digital inputs

analog inputs / outputs


digital outputs

Industrial Automation
2013

Programmable Logic Controllers 2.3 - 3

PLC in a cabinet
CPU1

redundant field
bus connection

Industrial Automation
2013

CPU2

serial connections
inputs/outputs

Programmable Logic Controllers 2.3 - 4

example: turbine control (in the test lab)

Industrial Automation
2013

Programmable Logic Controllers 2.3 - 5

PLC: functions

(Messen, Schtzen, Regeln = MSR)


PLC = PMC: Protection, Measurement and Control

Measure
Control (Command and Regulation)
Protection
Event Logging
Communication
Human interface

Industrial Automation
2013

Programmable Logic Controllers 2.3 - 6

PLC: Characteristics

large number of peripherals: 20..100 I/O per CPU, high density of wiring, easy assembly.
digital and analog Input/Output with standard levels
operate under harsh conditions, require robust construction, protection against dirt,
water and mechanical threats, electro-magnetic noise, vibration, extreme temperature
range (-30C..85C), sometimes directly located in the field.
programming: either very primitive with hand-help terminals on the target machine
itself, or with a laptop
network connection for programming on workstations and connection to SCADA
field bus connection for remote I/Os
primitive Human-Machine-Interface for maintenance, either through LCD-display or
connection of a laptop over serial lines (RS232) or wireless.
economical - 1000.- .. 15'000.- for a full crate.
the value is in the application software (licenses 20'000 ..50'000)

Industrial Automation
2013

Programmable Logic Controllers 2.3 - 7

PLC: Location in the control architecture

Enterprise Network

Engineer
station

Operator
station

Supervisor
Station

gateway

direct I/O

Industrial Automation
2013

Field Stations

COM 2

CPU
I/O

gateway

COM

COM
CPU

I/O

I/O

COM
I/O

COM
CPU

I/O

I/O

I/O

I/O

CPU

PLC

Field Bus

FB
gateway

small PLC
data concentrators,
not programmable,
but configurable

COM1

I/O

Control Station
with Field Bus

Field Bus
COM

directly connected
I/O

I/O

I/O

I/O

PLC

COM 2

CPU
COM1

I/O

I/O

I/O

I/O

I/O

COM1

large
PLCs

CPU

Control Bus
(e.g. Ethernet)

Field Devices

Sensor Bus (e.g. ASI)

Programmable Logic Controllers 2.3 - 8

Why 24V / 48 V supply ?

Aftertheplantlost
electricpower,operators
couldreadinstrumentsonly
bypluggingintemporary
batteries
[IEEESpectrumNov2011
aboutFukushima]

Photo TEPCO

Industrial Automation
2013

Programmable Logic Controllers 2.3 - 9

Global players

Total sales in 2004: 7000 Mio


Source: ARC Research, 2005-10
Industrial Automation
2013

Programmable Logic Controllers 2.3 - 10

Kinds of PLC

(1)

Compact
Monolithic construction
Monoprocessor
Fieldbus connection

(2)

Modular PLC
Modular construction (backplane)
One- or multiprocessor system
Fieldbus and LAN connection
Small Micro Memory Card (MMC) function possible

(3)

Soft-PLC
Linux or Windows NT or CE-based automation products
Direct use of CPU or co-processors

Industrial Automation
2013

Programmable Logic Controllers 2.3 - 11

Compact PLC

courtesy ABB

courtesy ABB

courtesy ABB

Monolithic (one-piece) construction


Fixed casing
Fixed number of I/O (most of them binary)
No process computer capabilities (no MMC)
Can be extended and networked by an extension (field) bus
Sometimes LAN connection (Ethernet, Arcnet)
Monoprocessor
Typical product: Mitsubishi MELSEC F, ABB AC31, SIMATIC S7
costs: 2000
Industrial Automation
2013

Programmable Logic Controllers 2.3 - 12

Specific Controller (example: Turbine)


tailored for a specific application, produced in large series
Programming port

Relays and fuses

Thermocouple
inputs

binary I/Os,
CAN field bus
RS232 to HMI

courtesy Turbec

cost: 1000.-

Industrial Automation
2013

Programmable Logic Controllers 2.3 - 13

Modular PLC
can be tailored to needs of application

development
environment

RS232

housed in a 19" (42 cm) rack


(height 6U ( = 233 mm) or 3U (=100mm)
high processing power (several CPUs)

LAN

large choice of I/O boards

backplane
parallel bus

concentration of a large number of I/O

courtesy ABB

interface boards to field busses

fieldbus

requires marshalling of signals

Power Supply

primitive or no HMI
cost effective if the rack can be filled

CPU CPU

Analog I/O

Binary I/O
fieldbus

supply 115-230V~ , 24V= or 48V= (redundant)


cost ~ 10000 for a filled crate
Typical products: SIMATIC S5-115, Hitachi H-Serie, ABB AC110
Industrial Automation
2013

Programmable Logic Controllers 2.3 - 14

Small modular PLC

courtesy ABB

courtesy Backmann

mounted on DIN-rail, 24V supply


cheaper (5000)
not water-proof,
no ventilator
extensible by a parallel bus (flat cable or rail)

Industrial Automation
2013

Programmable Logic Controllers 2.3 - 15

Compact or modular ?

field bus
extension

compact PLC
(fixed number of I/Os)

modular PLC (variable number of I/Os

Limit of local I/O

# I/O modules
Industrial Automation
2013

Programmable Logic Controllers 2.3 - 16

Industry- PC

courtesy INOVA

courtesy MPI

Wintel architecture
(but also: Motorola, PowerPC),
HMI (LCD..)
Limited modularity through mezzanine boards
(PC104, PC-Cards, IndustryPack)
Backplane-mounted versions with PCI or Compact-PCI
Industrial Automation
2013

Competes with modular PLC


no local I/O,
fieldbus connection instead,
costs: 2000.-

Programmable Logic Controllers 2.3 - 17

Soft-PLC (PC as PLC)

23
4
3
3

12
2

PC as engineering workstation
PC as human interface (Visual Basic, Intellution, Wonderware)
PC as real-time processor
PC assisted by a Co-Processor (ISA- or PC104 board)
PC as field bus gateway to a distributed I/O system

I/O modules

Industrial Automation
2013

Programmable Logic Controllers 2.3 - 18

Protection devices
substation

measurement
transformers

communication to operator

Ir
Is
It
Ur
Us
UT

Human interface
for status
and
settings

Programming
interface

trip relay

Protection devices are highly specialized PLCs that measure the current and voltages in an electrical
substation, along with other statuses (position of the switches,) to detect situations that could
endanger the equipment (over-current, short circuit, overheat) and trigger the circuit breaker (trip) to
protect the substation.
In addition, they record disturbances and send the reports to the substations SCADA.
Sampling: 4.8 kHz, reaction time: < 5 ms.

costs: 5000

Industrial Automation
2013

Programmable Logic Controllers 2.3 - 19

Comparison Criteria what matters


Brand

Siemens

Hitachi

Number of Points
Memory

1024
10 KB

640
16 KB

Programming Language

Ladder Diagrams
Instruction List
Logic symbols
Hand-terminal

Ladder Diagrams
Instruction List
Logic symbols
Basic
Hand-terminal

Programming Tools
Download

Graphical (on PC)


no

Graphical (on PC)


yes

Real estate per 250 I/O

2678 cm2

1000 cm2

Label surface
per line/point

5.3 mm2
7 characters

6 mm2
6 characters

Network

10 Mbit/s

19.2 kbit/s

Mounting

DIN rail

cabinet

Industrial Automation
2013

Programmable Logic Controllers 2.3 - 20

2.3.3 PLCs: Function and construction

2.1 Instrumentation
2.2 Control
2.3 Programmable Logic Controllers
2.3.1 PLCs: Definition and Market
2.3.3 PLCs: Functions and construction
2.3.5 PLC Programming Languages
2.3.5.1 IEC 61131 Languages
2.3.5.2 Function blocks
2.3.5.3 Program Execution
2.3.5.4 Structured Text
2.3.5.5 Sequential Function Charts
2.3.5.6 Ladder Diagrams
2.3.5.7 Instruction Lists
2.3.5.8 Programming environment

Industrial Automation
2013

Programmable Logic Controllers 2.3 - 21

Implementation

PLC operates periodically


Samples signals from sensors and converts them to digital form
with A/D converter
Computes control signal and converts it to analog form for the
actuators.
1. Wait for clock interrupt
2. Read input from sensor
3. Compute control signal
4. Send output to the actuator
5. Update controller variables
7. Communication
6. Repeat

Waiwera Organic Winery, Distillation Plant

Industrial Automation
2013

Programmable Logic Controllers 2.3 - 22

The signal chain within a PLC


y(i)

time

analog
variable
(e.g. 4..20mA)

time

filtering
&
scaling

sampling

analogdigital
converter
1

binary
variable

y(i)

filtering

011011001111

processing

sampling

(e.g. 0..24V)

0001111

counter

time

digitalanalog
converter

amplifier

analog
variable
e.g. -10V..10V

transistor
or
relay

binary
variable

non-volatile
memory

time
Industrial Automation
2013

Programmable Logic Controllers 2.3 - 23

General PLC architecture


RS 232

CPU

Real-Time
Clock

ROM

flash
EPROM

serial port
controller

Ethernet

ethernet
controller
extension
bus

parallel bus

fieldbus
controller

buffers

analogdigital
converters

digitalanalog
converters

Digital Output

Digital
Input

signal
conditioning

power
amplifiers

relays

signal
conditioning

external
I/Os

direct Inputs and Outputs

field bus

Industrial Automation
2013

Programmable Logic Controllers 2.3 - 24

Example Architecture: Internals of a protection device


Can you find all the components from the previous slide?
In addition this device uses a DSP module for complex computations.

Industrial Automation
2013

Programmable Logic Controllers 2.3 - 25

2.3.5 Programming languages

2.1 Instrumentation
2.2 Control
2.3 Programmable Logic Controllers
2.3.1 PLCs: Definition and Market
2.3.3 PLCs: Functions and construction
2.3.5 Programming languages
2.3.5.1 IEC 61131 Languages
2.3.5.2 Function blocks
2.3.5.3 Program Execution
2.3.5.4 Input / Output
2.3.5.5 Structured Text
2.3.5.6 Sequential Function Charts
2.3.5.7 Ladder Diagrams
2.3.5.8 Instruction Lists
2.3.5.9 Programming environment

Industrial Automation
2013

Programmable Logic Controllers 2.3 - 26

The long march to IEC 61131

PLC industry needs aggreement on


Data types (operations may only be executed on appropriate types)
Programming languages
Software structure (program organization units for modularity, encapsulation)
Discrete event system handling
Execution
NEMA Programmable Controllers Committee formed (USA)
GRAFCET (France)
DIN 40719, Function Charts (Germany)
NEMA ICS-3-304, Programmable Controllers (USA)
IEC SC65A/WG6 formed
DIN 19 239, Programmable Controller (Germany)
IEC 65A(Sec)38, Programmable Controllers
MIL-STD-1815 Ada (USA)
IEC SC65A(Sec)49, PC Languages
IEC SC65A(Sec)67
IEC 848, Function Charts
IEC 64A(Sec)90
IEC 1131-3

it took 20 years to make that standard

Type 3 report
recommendation

IEC 61131-3
name change
70

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

Source: Dr. J. Christensen


Industrial Automation
2013

Programmable Logic Controllers 2.3 - 27

Matching the analog and binary world


Binary World

Analog World
Pneumatic and electromechanical
controllers

Relay control, pneumatic


sequencer

I1
A
B
C

combinatorial

P1

P2

Regulation, controllers
continuous processes

sequential

discrete processes
Described by variables of nonoverlapping values. The transition from
one state to another is abrupt, it is
caused by an external event.

The time constant of the control


system must be at least one order
of magnitude smaller than the
smallest time constant of the plant.

PLC
Industrial Automation
2013

Programmable Logic Controllers 2.3 - 28

"Real-Time" languages

Extend procedural languages to


express time

Languages developed for cyclic


execution and real-time
("application-oriented languages")

(introduce programming constructs to


influence scheduling and control flow)
ADA

Ladder Diagrams

Real-Time Java

function block language

MARS (TU Wien)

instruction lists

Forth

GRAFCET

C with real-time features

SDL

etc
could not impose themselves

Industrial Automation
2013

etc...
wide-spread in the control industry.
Now standardized as IEC 61131

Programmable Logic Controllers 2.3 - 29

The five IEC 61131-3 Programming languages


graphical languages

Function Block Diagram (FBD)


CALC1

PUMP

CALC
AUTO

>=1

IN1 OUT

DO

Sequential Flow Chart (SFC)

START STEP
T1

MAN_ON

STEP A

IN2

ACT

T2
STEP B

Ladder Diagram (LD)

ACT

CALC
IN1 OUT
OUT

ACTION D1

D1_READY

ACTION D2

D2_READY

ACTION D3

D3_READY

ACTION D4

D4_READY

PUMP

IN2
MAN_ON

Instruction List (IL)


A: LD
%IX1 (* PUSH BUTTON *)
ANDN %MX5 (* NOT INHIBITED *)
ST
%QX2 (* FAN ON *)
Industrial Automation
2013

T3

CALC1
AUTO

http://www.isagraf.com

textual languages

Structured Text (ST)

VAR CONSTANT X : REAL := 53.8 ;


Z : REAL; END_VAR
VAR aFB, bFB : FB_type; END_VAR
bFB(A:=1, B:=OK);
Z := X - INT_TO_REAL (bFB.OUT1);
IF Z>57.0 THEN aFB(A:=0, B:=ERR);
ELSE aFB(A:=1, B:=Z is OK);
END_IF

Programmable Logic Controllers 2.3 - 30

61131 Elementary Data Types


No.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

Keyword
BOOL
SINT
INT
DINT
LINT
USINT
UINT
UDINT
ULINT
REAL
LREAL
TIME
DATE
TIME_OF_DAY or TOD
DATE_AND_TIME or DT
STRING
BYTE
WORD
DWORD
LWORD

Industrial Automation
2013

Data Type

Bits

Boolean
Short integer
Integer
Double integer
Long integer
Unsigned short integer
Unsigned integer
Unsigned double integer
Unsigned long integer
Real numbers
Long reals
Duration
Date (only)
Time of day (only)
Date and time of day
Character string
Bit string of length 8
Bit string of length 16
Bit string of length 32
Bit string of length 64

1
8
16
32
64
8
16
32
64
32
64
variable
variable
variable
variable
variable
8
16
32
64

Programmable Logic Controllers 2.3 - 31

Importance of IEC 61131

IEC 61131-3 is the most important automation language in industry.


80% of all PLCs support it, all new developments are based on it.
Depending on the country, some languages are more popular than others.

More information:
http://www.plcopen.org/pages/tc1_standards/downloads/plcopen_iec61131-3_feb2014
.pptx
http://www.plcopen.org/pages/pc2_training/downloads/index.htm

Industrial Automation
2013

Programmable Logic Controllers 2.3 - 32

2.3.5.2 Input and Output

2.1 Instrumentation
2.2 Control
2.3 Programmable Logic Controllers
2.3.1 PLCs: Definition and Market
2.3.3 PLCs: Functions and construction
2.3.5 PLC Programming Languages
2.3.5.1 IEC 61131 Languages
2.3.5.2 Input & Output
2.3.5.3 Function blocks
2.3.5.4 Program Execution
2.3.5.5 Structured Text
2.3.5.6 Sequential Function Charts
2.3.5.7 Ladder Diagrams
2.3.5.8 Instruction Lists
2.3.5.9 Programming environment

Industrial Automation
2013

Programmable Logic Controllers 2.3 - 33

Connecting to Input/Output, Method 1: dedicated I/O blocks

The Inputs and Outputs of the PLC must be connected to (typed) variables

IN_1

OUT_1

The I/O blocks are configured to be attached to the


corresponding I/O groups.

Industrial Automation
2013

Programmable Logic Controllers 2.3 - 34

Connecting to Input / Output, Method 2: Variables configuration


All program variables must be declared with name and type, initial value and volatility.
A variable may be connected to an input or an output, giving it an I/O address.
Several properties can be set: default value, fall-back value, store at power fail,
These variables may not be connected as input, resp. output to a function block.

predefined addresses
Industrial Automation
2013

Programmable Logic Controllers 2.3 - 35

2.4.2.3 Function Blocks Language

2.1 Instrumentation
2.2 Control
2.3 Programmable Logic Controllers
2.3.1 PLCs: Definition and Market
2.3.3 PLCs: Functions and construction
2.3.5 PLC Programming Languages
2.3.5.1
IEC 61131 Languages
2.3.5.2
Input / Output
2.3.5.3
Function blocks language
2.3.5.4
Program Execution
2.3.5.5
Structured Text
2.3.5.6
Sequential Function Charts
2.3.5.7
Ladder Diagrams
2.3.5.8
Instruction Lists
2.3.5.9
Programming environment

Industrial Automation
2013

Programmable Logic Controllers 2.3 - 36

Function Block Languages

(Funktionsblocksprache, langage de blocs de fonctions)


(Also called "Function Chart" or "Function Plan" - FuPla)

The function block languages express "combinatorial"


programs in a way similar to electronic circuits.
They draw on a large variety of predefined and custom functions
This language is similar to the Matlab / Simulink language
used for simulations

Industrial Automation
2013

Programmable Logic Controllers 2.3 - 37

Function Block Examples


Example 1:
A
B
Example 2:

&

external outputs

external inputs
Trigger
Running
Reset

Tempo

&

S Q

Spin

Graphical programming language, similar to electrical and block


diagrams. Mostly expresses combinatorial logic, but blocks may have
memory (e.g. RS-flip-flops)

Industrial Automation
2013

Programmable Logic Controllers 2.3 - 38

Function Block Elements


Function block

input signals

Example

set point
measurement

parameters
PID

output signals
command
overflow

"continuously"
executing block,
independent,
no side effects

The block is defined by its:


Data flow interface (number and type of input/output signals)
Black-Box-Behavior (functional semantic, e.g. in textual form).
Signals

Typed connections that carry a pseudo-continuous data flow.


Connects the function blocks.
set point

Example

Industrial Automation
2013

(set point)
(set point)

Programmable Logic Controllers 2.3 - 39

Function Block Example

Industrial Automation
2013

Programmable Logic Controllers 2.3 - 40

Function Block Rules


There exist exactly two rules for connecting function blocks by signals
(this is the actual programming):
Each signal is connected to exactly one source.
This source can be the output of a function block or a plant signal.
The type of the output pin, the type of the input pin and the signal type
must be identical.
The function plan should be drawn so the signals flow from left
to right and from top to bottom. Some editors impose additional rules.

Retroactions are an exception to this rule. In this case, the signal direction is
identified by an arrow (forbidden in some editors use global variables instead).
a
b

x
z

Industrial Automation
2013

Programmable Logic Controllers 2.3 - 41

Types of Programming Organisation Units (POUs)

1) Functions
- are part of the base library.
- have no memory.
Examples: and gate, adder, multiplier, selector,....
2) Elementary Function Blocks (EFB)
- are part of the base library
- have a memory ("static" data).
- may access global variables (side-effects !)
Examples: counter, filter, integrator,.....
3) Programs (Compound blocks)
- user-defined or application-specific blocks
- may have a memory
- may be configurable (control flow not visible in the FBD
Examples: PID controller, Overcurrent protection, Motor sequence
(a library of compound blocks may be found in IEC 61804-1)

Industrial Automation
2013

Programmable Logic Controllers 2.3 - 42

Function Block library

The programmer chooses the blocks in a block library, similarly to the


hardware engineer who chooses integrated circuits in a catalogue.
The library describes the pinning of each block, its semantics and the
execution time.
The programmer may extend the library by defining function block macros
composed of library elements.
If some blocks are used often, they will be programmed in an external
language (e.g. C, micro-code) following strict rules.

Industrial Automation
2013

Programmable Logic Controllers 2.3 - 43

Library functions for discrete and continuous plants


Basic blocks
logical operations(AND, OR, )
Flip-flop
Selector m-out-of-n
Multiplexer m-to-n
Timer
Counter
Memory
Sequencing
Compound blocks
Display
Manual input, touch-screen
Safety blocks (interlocking)
Alarm signaling
Logging

Industrial Automation
2013

Basic blocks
Summator / Subtractor
Multiplier / Divider
Integrator / Differentiator
Filter
Minimal value, Maximum value
Radix
Function generator
Regulation Functions
P, PI, PID, PDT2 controller
Fixed set-point
Ratio and multi-component regulation
Parameter variation / setting
2-point regulation
3-point regulation
Output value limitation
Ramp generator
Adaptive regulation
Drive Control
Programmable Logic Controllers 2.3 - 44

Function Block library for specialized applications

MoveAbsolute
AXIS_REF
BOOL
REAL
REAL
REAL
REAL
REAL
MC_Direction

Axis
Execute
Position
Velocity
Acceleration
Deceleration
Jerk
Direction

Axis
Done
CommandAborted
Error
ErrorID

AXIS_REF
BOOL
BOOL
BOOL
WORD

standardized blocks are defined in libraries, e.g. Motion Control or Robotics

Industrial Automation
2013

Programmable Logic Controllers 2.3 - 45

Specifying the behaviour of Function Block


Time Diagram:
0
x

y
T

Truth Table:

Mathematical Formula:

Textual Description:

Industrial Automation
2013

x1
x2

x1

x2

previous state

dx
Kpx Kd
Ki xd
dt
0

Calculates the root mean square of the input with a filtering constant
defined in parameter FilterDelay
Programmable Logic Controllers 2.3 - 46

Function Block specification in Structured Text

Industrial Automation
2013

Programmable Logic Controllers 2.3 - 47

IEC 61131-3 library (extract)


Boolean Functions

Selector

Arithmetic Functions
Binary
selection

Select one of N
inputs depending
on input K

Flip-flop
Up counter
dominant set
Q:=S1|(Q&!R)

Trigger

dominant
reset
Q:=!R1&(Q|S)

rising edge
detector

CU input (rising
edges count up)
R reset counter
(CV:=0)
PV preset value
Q 1 if CV >= PV
CV current value

ADD

adder

SUB

subtractor

MUL

multiplier

DIV

divider

INT
Reset
PV
In

Integrator
(if reset)
Out := PV,
else
Out:= t *In +
Out

More details http://calc1.kss.ia.polsl.pl/content/dydaktyka/PC/PLC_IEC61131-3.pdf


Industrial Automation
2013

Programmable Logic Controllers 2.3 - 48

Exercise: What do the following blocks do ? (t = 1)


1.

2.
In

ADD

(10)

In1

(1024)

Out
(initially 2)

DIV

In2
(2)

Remember:
INT
If (Reset) :
Out := PV,
Else:
Out := t *In + Out

Out
(initially 0)

What are the values of Out?


What happens if out is initially 1024?

What are the values


of Out?
3.

INT
Reset = 0
PV
In

t1

CTU
CU
RESET Q
CV
PV

t2

t3 t4 t5 t6

t7

t8

CU
Reset = 0, PV = 3, CV = #up Q = (CV >= PV) ?
Flipflop: dominant set or reset?

4.
S

S1
R

S
R1

SR
Q
RS
Q

dominant set
Q:=S1|(Q&!R)
dominant
reset
Q:=!R1&(Q|S)

http://tinyurl.com/IAFunctionBlock
https://docs.google.com/forms/d/1ynmoXf3JTcRn2yv2_4bKhcK0HJNDYpiTnQQm13lDSso/viewform
Industrial Automation
2013

Programmable Logic Controllers 2.3 - 49

Exercise: What do the following blocks do ?


1.

2.
2, 12, 22, 32, 42

If out is initially 0:
0, 0, 0, 0, 0
If out is initially 1024: 1024, 1024, 1024,

3.
CV = 1, 1, 2, 2, 3, 3, 4, 4
Q = 0, 0, 0, 0, 1, 1, 1, 1

4.

S1
R

SR
Q

dominant set
Q:=S1|(Q&!R)

Q
https://
docs.google.com/forms/d/1ynmoXf3JTcRn2yv2_4b
KhcK0HJNDYpiTnQQm13lDSso/viewform

Industrial Automation
2013

ftp://advantechdownloads.com/Traini
ng/KW%20training/

Programmable Logic Controllers 2.3 - 50

Exercise: Asymmetric Sawtooth Wave

Build an asymmetric sawtooth wave generator with


IEC 61131 function blocks
5s

12s

75

0
-25

Industrial Automation
2013

Programmable Logic Controllers 2.3 - 51

Exercise: Asymmetric Sawtooth Wave

Build an asymmetric sawtooth wave generator with


IEC 61131 function blocks
5s

12s

75

0
-25

Hints:
- Compute the slopes
- Use integrators, comparators, flip-flops and selectors
Industrial Automation
2013

Programmable Logic Controllers 2.3 - 52

Exercise: Saw-tooth FBD

Out
75.0

-25.0

+ 8.3
-20.0

Other solutions exists.


Industrial Automation
2013

Programmable Logic Controllers 2.3 - 53

Function Block decomposition


A function block describes a data flow interface.
Its body can be implemented differently:
Elementary block
The body is implemented in an external language
(micro-code, assembler, IEC 61131 ST):

=
Compound block

procedure xy (a,b:BOOLEAN; VAR b,c: BOOLEAN);


begin
......
....
end xy;

The body is realized as a function block program


.
Each input (output) pin of the interface is implemented as
exactly one input (output) of the function block.
All signals must appear at the interface to guarantee
freedom from side effects.

=
Industrial Automation
2013

Programmable Logic Controllers 2.3 - 54

Function Block segmentation


An application program (task) is decomposed into segments ("Programs")
for easier reading, each segment being represented on one (A4) printed page.
Within a segment, the connections are represented graphically
.
Between the segments, the connections are expressed by signal names
.
Segment A
X1
M2

M1
Y1

Segment B
X2

Y2

M1
X3

Industrial Automation
2013

M2

Programmable Logic Controllers 2.3 - 55

2.3.5.3 Program execution

2.1 Instrumentation
2.2 Control
2.3 Programmable Logic Controllers
2.3.1 PLCs: Definition and Market
2.3.3 PLCs: Functions and construction
2.3.5 PLC Programming Languages
2.3.5.1 IEC 61131 Languages
2.3.5.2 Function blocks
2.3.5.3 Program Execution
2.3.5.4 Input / Output
2.3.5.5 Structured Text
2.3.5.6 Sequential Function Charts
2.3.5.7 Ladder Diagrams
2.3.5.8 Instruction Lists
2.3.5.9 Programming environment

Industrial Automation
2013

Programmable Logic Controllers 2.3 - 56

Execution of Function Blocks


Segment or POU
(program organization unit)

A
B
C

F1
F3

Machine Code:
The function blocks are
translated to machine language
(intermediate code, IL),
that is either interpreted or
compiled to assembly language
Blocks are executed in sequence,
normally from upper left to lower right
The sequence is repeated every t ms.
Industrial Automation
2013

X01

F2

X02

function
input1
input2
output

F4
Y

F1
A
B
X01
F2
X01
X
F3
B
C
X02
F4
X
X02
Y
Programmable Logic Controllers 2.3 - 57

Input-Output of Function Blocks


Run-time:
read
inputs
I

write
outputs
X

execute

individual period

O
time

The function blocks are executed cyclically.


all inputs are read from memory or from the plant (possibly cached)
the segment is executed
the results are written into memory or to the plant (possibly to a cache)
The order of execution of the blocks generally does not matter.
To speed up algorithms and avoid cascading, it is helpful to impose an
execution order to the blocks.
The different segments may be assigned a different individual period.

Industrial Automation
2013

Programmable Logic Controllers 2.3 - 58

Program configuration

The programmer divides the program into tasks (sometimes called


pages or segments), which may be executed each with a different
period.
The programmer assigns each task (each page) an execution
period. Since the execution time of each block in a task is fixed, the
execution time is fixed.
Event-driven operations are encapsulated into blocks, e.g. for
transmitting messages.
If the execution time of these operations take more than one period,
they are executed in background.
The periodic execution always has the highest priority.
Industrial Automation
2013

Programmable Logic Controllers 2.3 - 59

IEC 61131 - Execution engine


configuration
resource

resource

task

task

program

program
FB

task

task

program

program

FB

FB

global and directly

FB

represented variables

access paths
communication function
Legend:
FB

execution control path


variable access paths
function block
variable

Industrial Automation
2013

Programmable Logic Controllers 2.3 - 60

Parallel execution
Function blocks are particularly well suited for true multiprocessing (parallel processors).
The performance limit is given by the needed exchange of signals by shared memory.
Semaphores are not used since they could block an execution and make the concerned
processes non-deterministic.

processor
1

processor
2

processor
3

input/
output

shared
memory

shared
memory

shared
memory

shared
memory

Industrial Automation
2013

Programmable Logic Controllers 2.3 - 61

2.3.5.5 Structured Text

2.1 Instrumentation
2.2 Control
2.3 Programmable Logic Controllers
2.3.1 PLCs: Definition and Market
2.3.3 PLCs: Functions and construction
2.3.5 PLC Programming Languages
2.3.5.1 IEC 61131 Languages
2.3.5.2 Function blocks
2.3.5.3 Program Execution
2.3.5.4 Input / Output
2.3.5.5 Structured Text
2.3.5.6 Sequential Function Charts
2.3.5.7 Ladder Diagrams
2.3.5.8 Programming environment

Industrial Automation
2013

Programmable Logic Controllers 2.3 - 62

Structured Text
(StrukturierteTextsprache,langagelittralstructur)

Structured Text is an imperative language similar to Pascal (If, While, etc..)


The variables defined in ST can be used in other languages
ST is used to do complex data manipulation and write blocks
Caution: writing programs in structured text can breach the real-time rules !

Industrial Automation
2013

Programmable Logic Controllers 2.3 - 63

Data Types
Function Blocks are typed: the types of connection, input and output must match.
Elementary Types are defined either in Structured Text or in the FB configuration.

analog types:

binary types:
BOOL
BYTE
WORD
DWORD

1
8
16
32

REAL
LREAL

(Real32)
(Real64)

Derived Types are user-defined and must be declared in Structured Text


subrange,
enumerated,
arrays,
structured types
(e.g. AntivalentBoolean2)
Variables can receive initial values and be declared as non-volatile (RETAIN), so
after restart they contain the last value before power-down or reset.
Industrial Automation
2013

Programmable Logic Controllers 2.3 - 64

Example of Derived Types

TYPE
ANALOG_CHANNEL_CONFIGURATION
STRUCT
RANGE: ANALOG_SIGNAL_RANGE;
MIN_SCALE : ANALOG_DATA ;
MAX_SCALE : ANALOG_DATA ;
END_STRUCT;
ANALOG_16_INPUT_CONFIGURATION :
STRUCT
SIGNAL_TYPE : ANALOG_SIGNAL_TYPE;
FILTER_CHARACTERISTIC : SINT (0.99)
CHANNEL: ARRAY [1..16] OF ANALOG_CHANNEL_CONFIGURATION;
END_STRUCT ;
END_TYPE

Industrial Automation
2013

Programmable Logic Controllers 2.3 - 65

Structured Text Examples


IFtank.temp>200THEN
pump.fast:=1;
pump.slow:=0;
pump.off:=0;
ELSIFtank.temp>100THEN
pump.fast:=0;
pump.slow:=1;
pump.off:=0;
ELSE
pump.fast:=0;
pump.slow:=0;
pump.off:=1;
END_IF;

IF(Switch_0ANDSwitch_1)THEN
Start_Motor:=1;
Start_Count:=Start_Count+1;
END_IF;
pos:=0;
WHILE((pos<100)
&s_arr[pos].value<>target))DO
pos:=pos+2;
String_tag.DATA[pos]:=
SINT_array[pos];
END_WHILE;

Predefined functions, e.g.:


SIZE(SINT_array,0,SINT_array_size);
Count the number of elements in SINT_array (array that contains inputs) and store
result in SINT_array_size (DINT tag).
[http://literature.rockwellautomation.com/idc/groups/literature/documents/pm/1756-pm007_-en-p.pdf ]

Industrial Automation
2013

Programmable Logic Controllers 2.3 - 66

Structured Text Example


Move ASCII characters from a SINT array into a string tag. (In a SINT array, each element holds one
character.) Stop when you reach the carriage return.

element_num:=0;
SIZE(SINT_array,0,SINT_array_size);
WHILESINT_array[element_num]<>13DO
String_tag.DATA[element_num]:=SINT_array[element_num];
element_num:=element_num+1;
String_tag.LEN:=element_num;
IFelement_num=SINT_array_sizethen
exit;
END_IF;
END_WHILE;
Explanations:
1.Initialize element_num to 0.
2.Count the number of elements in SINT_array (array that contains the ASCII characters) and store the result in
SINT_array_size (DINT tag).
3.If the character at SINT_array[element_num] = 13 (carriage return), then stop.
4.Set String_tag[element_num] = the character at SINT_array[element_num].
5.Add 1 to element_num. This lets the controller check the next character in SINT_array.
6.Set the Length member of String_tag = element_num. (This records the number of characters in String_tag so
far.)
7.If element_num = SINT_array_size, then stop. (You are at the end of the array and it does not contain a
carriage return.)
8.Go to 3.
[http://literature.rockwellautomation.com/idc/groups/literature/documents/pm/1756-pm007_-en-p.pdf ]
Industrial Automation
2013

Programmable Logic Controllers 2.3 - 67

Structured Text Exercise


A user-defined data type (structure) stores information about an item in an Inventory array:
Inventory[i].ID: Barcode ID of the item (string data type)
Inventory[i].Qty: Quantity in stock of the item (DINT data type)
An array of the above structure contains an element for each different item in your inventory. You
want to search the array for a specific product (by its barcode) and determine the quantity in stock.
Pseudocode:
1.Get size (number of items) of Inventory array and store result in Inventory_Items (DINT tag).
2.Loop over positions in array.
3.If Barcode matches the ID of an item in the array, then:
a. Set the Quantity tag = Inventory[position].Qty
b. Stop.

[http://literature.rockwellautomation.com/idc/groups/literature/documents/pm/1756-pm007_-en-p.pdf ]

Industrial Automation
2013

Programmable Logic Controllers 2.3 - 68

Structured Text Exercise Solution


A user-defined data type (structure) stores information about an item in an Inventory array:
Inventory[i].ID: Barcode ID of the item (string data type)
Inventory[i].Qty: Quantity in stock of the item (DINT data type)
An array of the above structure contains an element for each different item in your inventory. You
want to search the array for a specific product (by its barcode) and determine the quantity in stock.
Pseudocode:
1.Get size (number of items) of Inventory array and store result in Inventory_Items (DINT tag).
2.Loop over positions in array.
3.If Barcode matches the ID of an item in the array, then:
a. Set the Quantity tag = Inventory[position].Qty
b. Stop.

Solution:
SIZE(Inventory,0,Inventory_Items);
FORposition:=0toInventory_Items1DO
IFBarcode=Inventory[position].IDTHEN
Quantity:=Inventory[position].Qty;
EXIT;
END_IF;
END_FOR;
[http://literature.rockwellautomation.com/idc/groups/literature/documents/pm/1756-pm007_-en-p.pdf ]

Industrial Automation
2013

Programmable Logic Controllers 2.3 - 69

2.3.5.6 Sequential Function Charts

2.1 Instrumentation
2.2 Control
2.3 Programmable Logic Controllers
2.3.1 PLCs: Definition and Market
2.3.3 PLCs: Functions and construction
2.3.5 PLC Programming Languages
2.3.5.1 IEC 61131 Languages
2.3.5.2 Function blocks
2.3.5.3 Program Execution
2.3.5.4 Input / Output
2.3.5.5 Structured Text
2.3.5.6 Sequential Function Charts
2.3.5.7 Ladder Diagrams
2.3.5.8 Programming environment

Industrial Automation
2013

Programmable Logic Controllers 2.3 - 70

SFC (Sequential Flow Chart)


(Ablaufdiagramme,diagrammesdefluxensquence)

START STEP
T1
STEP A

STEP B

ACTION D1

D1_READY

ACTION D2

D2_READY

T2

Describes sequences of operations and interactions between parallel processes.


Derived from Grafcet and SDL (Specification and Description Language, used for
communication protocols), mathematical foundation lies in Petri Nets.

Industrial Automation
2013

Programmable Logic Controllers 2.3 - 71

SFC: Elements
S0
event condition
("1" = always true)

"1"

transitions
Sa

states
token

Ea

example transition condition


Ec = ((varX & varY) | varZ)

Sb
Eb
Sc

The sequential program consists of states connected by transitions.


A state is activated by the presence of a token (the corresponding variable becomes TRUE).
The token leaves the state when the transition condition (event) on the state output is true.
Only one transition takes place at a time, the execution period is a configuration parameter
(task to which this program is attached)

Rule: there is always a transition between two states,


there is always a state between two transitions
Industrial Automation
2013

Programmable Logic Controllers 2.3 - 72

SFC: Initial state

State which come into existence with a token are called initial states.

All initial states receive exactly one token, the other states receive none.

Initialization takes place explicitly at start-up.


In some systems, initialization may be triggered in a user program
(initialization pin in a function block).

Industrial Automation
2013

Programmable Logic Controllers 2.3 - 73

SFC: Switch and parallel execution


E0

"1"
token switch : the token crosses the first active

Sa

transition (at random if both Ea and Eb are true)


Note: transitions are after the alternance

Ea

Eb

Sc
Ec

Sb

Sd
Ed
Se

token forking : when the transition Ee is true, the token


is replicated to all connected states

Ee

Note: transition is before the fork

token join : when all connected states have tokens


and transition Eg is true, one single token is forwarded.
Note: transition is after the join

Industrial Automation
2013

Ef

Sg

Sf
Eg

Programmable Logic Controllers 2.3 - 74

SFC: P1, N and P0 actions

State1

P1 State1_P1: do at enter
N

State1_N: do while

P0 State1_P0: do at leaving

P1 (pulse raise) action is executed once when the state is entered


P0 (pulse fall) action is executed once when the state is left
N (non-stored) action is executed continuously while the token is in the state
P1 and P0 actions could be replaced by additional states.
The actions are described by a code block written e.g. in Structured Text.

Industrial Automation
2013

Programmable Logic Controllers 2.3 - 75

Special action: the timer

rather than define a P0 action reset timer., there is an implicit variable defined as
<state name>.t that express the time spent in that state.

S
S.t > t#5s
Sf

Industrial Automation
2013

Programmable Logic Controllers 2.3 - 76

SFC: graphic rules


The input and output flow of a state are always in the same vertical line (simplifies structure)
Alternative paths are drawn such that no path is placed in the vertical flow
(otherwise would mean this is a preferential path)

intentional displacement to
avoid optical preference of a
path.

Priority:

The alternative path most to the left has the


highest priority, priority decreases towards the right.
Loop: exit has a higher priority than loopback.

Industrial Automation
2013

Programmable Logic Controllers 2.3 - 77

SFC: Exercise
Variables
Input:
I0, I1, I2, I3 (boolean);
Output:
Trap = {0: closed; 1: open}
Speed = {+20: +1 m/s; +1: +5 cm/s; 0: 0m/s}
Register = {0: closed; 1: open}
negative values: opposite direction
trap

I0

Register = {0: closed; 1: open}

+speed

I1

I2

I3

Inputs generate 1 as long


as the tag of the vehicle
(1cm) is over the sensor.

Speed = 5 cm/s from I1 to I0 and from I2 to I3, faster otherwise.


Initially: move vehicle at reduced speed until it touches I0 and open the trap for 5s
(empty the vehicle).
1 - Let the vehicle move from I0 to I3
2 - Stop the vehicle when it reaches I3.
3 - Open the tank during 5s.
Industrial Automation
2013

4 - Go back to I0
5 - Open the trap and wait 5s.
repeat above steps indefinitely
Programmable Logic Controllers 2.3 - 78

Exercise SFC Example Solution

Industrial Automation
2013

Programmable Logic Controllers 2.3 - 79

SFC: Structuring
Every flow chart without a token generator may be redrawn as a
structured flow chart (by possibly duplicating program parts)
Not structured

structured
A
a

b
d

B'

A'

Industrial Automation
2013

Programmable Logic Controllers 2.3 - 81

SFC: Complex structures


These general rules serve to build networks, termed by DIN and IEC as flow charts

Problems with general networks:


Deadlocks, uncontrolled
token multiplication
Industrial Automation
2013

Solution:
assistance through the flow chart editor.

Programmable Logic Controllers 2.3 - 82

Function Blocks And Flow Chart

Function Blocks:
Continuous (time) control

Sequential Flow Charts:


Discrete (time) Control

Many PLC applications mix continuous and discrete control.


A PLC may execute alternatively function blocks and flow charts.
Communication between these program parts must be possible.

Principle:
A flow chart taken as a whole can be considered a function
block with binary inputs (transitions) and binary outputs (states).

Industrial Automation
2013

Programmable Logic Controllers 2.3 - 83

Executing Flow Charts As blocks


A function block may be implemented in different ways:

procedure
xy(...);
begin
...
endxy;

extern (ST/IL)

function blocks

flow chart

Function blocks and flow chart communicate over binary signals.

Industrial Automation
2013

Programmable Logic Controllers 2.3 - 84

Flow Charts or Function Blocks ?

A task can sometimes be written indifferently as function blocs or as flow chart.


The application may decide which representation is more appropriate:
Flow Chart

Function Block

a
"1"

S
R

c
NOT

b
d

Industrial Automation
2013

Programmable Logic Controllers 2.3 - 85

Flow Charts Or Blocks ? (2)

Flow Chart
init

"1"
a
b

Function Blocks

S
R

&

B
C

S
R

B
&

b
S
R

C
&

In this example, a flow chart seems to be more appropriate:

Industrial Automation
2013

Programmable Logic Controllers 2.3 - 86

Exercise: write the SFC for this task

V1
L1

V3

V2
upper
lower
MS

H1
heater
(actor)

open V1 until tanks L1 indicates upper level


open V2 during 25 seconds
open V3 until the tanks L1 indicates it reached the lower level
while stirring.
heat mixture during 50 minutes while stirring
empty the reactor while the drying bed is moving
repeat

temperature
(sensor)

V4
MD
Industrial Automation
2013

Programmable Logic Controllers 2.3 - 87

2.3.5.7 Ladder Diagrams

2.1 Instrumentation
2.2 Control
2.3 Programmable Logic Controllers
2.3.1 PLCs: Definition and Market
2.3.2 PLCs: Kinds
2.3.3 PLCs: Functions and construction
2.3.5 PLC Programming Languages
2.3.5.1 IEC 61131 Languages
2.3.5.2 Function blocks
2.3.5.3 Program Execution
2.3.5.4 Input / Output
2.3.5.5 Structured Text
2.3.5.6 Sequential Function Charts
2.3.5.7 Ladder Diagrams
2.3.5.8 Programming environment

Industrial Automation
2013

Programmable Logic Controllers 2.3 - 88

Ladder Diagrams (1)


(Kontaktplansprache,langagecontacts)

Ladder Diagrams is the oldest programming language for PLC


- based on relay intuition of electricians.
- widely in use outside Europe.
- not recommended for large new projects.
Input instructions (conditions)

Output (actions)

Rung 0
Rung 1
Rung 2

Industrial Automation
2013

Programmable Logic Controllers 2.3 - 89

Ladder Diagrams (2)

The contact plan or "ladder diagram" language allows an easy transition from the
traditional relay logic diagrams to the programming of binary functions.
It is well suited to express combinational logic
It is not suited for process control programming (there are no analog elements).
The main Ladder Diagrams symbols represent the elements:

make contact

contact travail Arbeitskontakt

break contact

contact repos Ruhekontakt

relay coil
Industrial Automation
2013

bobine

Spule

Programmable Logic Controllers 2.3 - 90

Ladder Diagrams Example (3)

origin:
electrical
circuit

make contact
(contact travail)

01

02

relay coil
(bobine)

03

50
break contact
(contact repos)

02

01
corresponding
ladder diagram

50

03
50

05
44

Industrial Automation
2013

rung

"coil" 50 is used to move


other contact(s)
Programmable Logic Controllers 2.3 - 91

Ladder Diagrams (4)


Binary combinations are expressed by series and parallel relay contact:
Ladder Diagrams representation
Series

01

logic" equivalent
01

02
50

02

50

Coil 50 is active (current flows) when 01 is active and 02 is not.


Parallel

01
40
02

01
02

40

Coil 40 is active (current flows) when 01 is active or 02 is not.

Industrial Automation
2013

Programmable Logic Controllers 2.3 - 92

Ladder Diagrams (5)


The Ladder Diagrams is more intuitive for complex binary expressions than literal languages
1

textual expression
! 1 & 2 & ( 3 & ! 4 | ! 5 & 6 ) = 50

50

Or
N1 & 2 STR 3 & N4 STR N5 & 6
/ STR & STR = 50

0
2

1
3
10

4
6
11

Industrial Automation
2013

5
7

12

50

N0 & 1 STR 2 & 3 / STR STR 4


& 5 STR N 6 & 7
/ STR & STR STR 10
& 11 / STR & 12 = 50

Programmable Logic Controllers 2.3 - 93

Ladder Diagrams (6)


Ladder Diagrams stems from the time of the relay technology.
As PLCs replaced relays, their new possibilities could not be expressed any more
in relay terms.
The contact plan language was extended to express functions:

00

01
FUN 02

200

literal expression:
!00 & 01 FUN 02 = 200

The intuition of contacts and coil gets lost.


The introduction of functions that influence the control flow itself, is problematic.
The contact plan is - mathematically - a functional representation.
The introduction of a more or less hidden control of the flow destroys the
freedom of side effects and makes programs difficult to read.

Industrial Automation
2013

Programmable Logic Controllers 2.3 - 94

Ladder Diagrams Example


Ladder Diagrams diagram for a batch process: lling a container with a liquid,
mixing the liquid, and draining the container. The sequence of events is as follows:
1. ll valve opens and lets the liquid into the container until it is full.
2. liquid in the container is mixed for 3 minutes.
3. a drain valve opens and drains the tank.

O = output
I = input

Source: http://teacher.buet.ac.bd/zahurul/ME6401/ME6401_PLC.pdf
Industrial Automation
2013

Address of variable
(module number, port
number)

Programmable Logic Controllers 2.3 - 95

Ladder Diagrams Exercise


Consider a PLC with one input module and one output module. Two external switches (SW-0
& SW-1) are connected via terminal IN-0 and In-1 of input module. Two terminals of the output
module (OUT-0 & OUT-1) drive two indicator lamps (Lamp-0 & Lamp-1).

Which lamps are lit with the current switch positions?


What happens if you change the position of Switch SW-1?
Source: http://teacher.buet.ac.bd/zahurul/ME6401/ME6401_PLC.pdf
Industrial Automation
2013

Programmable Logic Controllers 2.3 - 96

Ladder Diagrams Exercise Solution


The top rung will light Lamp-0 if both SW-0 and SW-1 are closed. The bottom rung will light
Lamp-1 if either SW-0 or OUT-0 are closed.

In the current position LAMP-1 is lit.


If we change the position of Switch SW-1 then LAMP 0 will be lit too.
Source: http://teacher.buet.ac.bd/zahurul/ME6401/ME6401_PLC.pdf
Industrial Automation
2013

Programmable Logic Controllers 2.3 - 97

Ladder Diagrams (7)

Ladder Diagrams provides neither:


sub-programs (blocks), nor
data encapsulation nor
structured data types.
It is not suited to make reusable modules.
IEC 61131 does not prescribe the minimum requirements for a compiler / interpreter
such as number of rungs per page nor does it specifies the minimum subset to be
implemented.
Therefore, it should not be used for large programs made by groups of people
It is very limited when considering analog values (it has only counters)
used mostly in manufacturing, not in process control

Industrial Automation
2013

Programmable Logic Controllers 2.3 - 98

2.3.6 Instruction Lists

2.1 Instrumentation
2.2 Control
2.3 Programmable Logic Controllers
2.3.1 PLCs: Definition and Market
2.3.2 PLCs: Kinds
2.3.3 PLCs: Functions and construction
2.3.5 PLC Programming Languages
2.3.5.1 IEC 61131 Languages
2.3.5.2 Function blocks
2.3.5.3 Program Execution
2.3.5.4 Input / Output
2.3.5.5 Structured Text
2.3.5.6 Sequential Function Charts
2.3.5.7 Ladder Diagrams
2.3.5.8 Instructions Lists
2.3.5.9 Programming environment
Industrial Automation
2013

Programmable Logic Controllers 2.3 - 99

Instruction Lists (1)


(Instruktionsliste,listed'instructions)
Instruction lists is the machine
language of PLC programming
It has 21 instructions (see table)
Three modifiers are defined:
"N" negates the result
"C" makes it conditional and
"(" delays it.
All operations relate to one result
register (RR) or accumulator.

Industrial Automation
2013

Programmable Logic Controllers 2.3 - 100

Instruction Lists (2)


(Instruktionsliste,listed'instructions)
Accumulator-based pogramming:
First, values are loaded into the accumulator (LD instruction)
Then, operations are executed with first parameter taken out of accumulator
and second parameter of operand.
Result put in the accumulator, from where it can be stored (ST instruction)
Conditional executions or loops are supported by comparing operators like
EQ, GT, LT, GE, LE, NE and jumps (JMP, JMPC, JMPCN, for the last two the
accumulators value is checked on TRUE or FALSE)
Syntax:
-each instruction begins on a new line and contains an operator and,
depending on the type of operation, one or more operands separated by commas
-before an instruction there can be a label, followed by a colon (:), as target for jumps
-use brackets to define order of execution
-comments must be placed last
-empty lines are allowed.

Industrial Automation
2013

Programmable Logic Controllers 2.3 - 101

Instruction Lists Example (3)

End:ST

speed3(*result*)

Instructions Lists is the most efficient way to write code, but only for specialists.
Otherwise, IL should not be used, because this language:
provides no code structuring
has weak semantics
is machine-dependent
Industrial Automation
2013

Programmable Logic Controllers 2.3 - 102

Instruction Lists Examples (4)


Labels
LD TRUE
ANDN BOOL1
JMPC mark

(*load TRUE into the accumulator*)


(*execute AND with the negated value of the BOOL1 variable*)
(*if the result was TRUE, then jump to the label "mark"*)

LDN BOOL2
ST RES
JMP continue

(*load the negated value of BOOL2 into the accumulator*)


(*store the content of the accumulator in RES*)
(*jump to label continue"*)

mark:
LD BOOL2
ST RES

(*save the value of *)


(*BOOL2 in RES*)

continue:

Brackets (without)
LD 2
MUL 2
ADD 3
ST RES

(*7 is stored in RES*)


Industrial Automation
2013

(with)
LD 2
MUL(2
ADD 3
)
ST RES (* 10 is stored in RES*)

Programmable Logic Controllers 2.3 - 103

Instruction Lists Exercise(3)

End:ST

speed3(*result*)

What is the resulting speed3 for the following input?


a)

Temp1 = 10
Temp2 = 15
Speed1 = 50
Speed2 = 100

Industrial Automation
2013

b)

Temp1 = 10
Temp2 = 5
Speed1 = 50
Speed2 = 100

Programmable Logic Controllers 2.3 - 104

Exercise IEC 61131 Languages

Ladder Diagram
A B

Function Block Diagram


C
A

-| |--|/|----------------( )

Instruction List
?

Structured Text

C:= ?

http://tinyurl.com/IA61131
https://docs.google.com/forms/d/1lGkFXQrlwlnoKc8gUg-_ESAdtVy-RgIOLnFbkIOGNa8/viewform
Industrial Automation
2013

Programmable Logic Controllers 2.3 - 105

Exercise IEC 61131 Languages

Ladder Diagram
A B

Function Block Diagram


C
A

-| |--|/|----------------( )

AND

Instruction List
LD

ANDN

ST

Structured Text

C:= A AND NOT B

http://tinyurl.com/IA61131
https://docs.google.com/forms/d/1lGkFXQrlwlnoKc8gUg-_ESAdtVy-RgIOLnFbkIOGNa8/viewform
Industrial Automation
2013

Programmable Logic Controllers 2.3 - 106

2.3.5.9 Programming environment

2.1 Instrumentation
2.2 Control
2.3 Programmable Logic Controllers
2.3.1 PLCs: Definition and Market
2.3.2 PLCs: Kinds
2.3.3 PLCs: Functions and construction
2.3.5 PLC Programming Languages
2.3.5.1 IEC 61131 Languages
2.3.5.2 Function blocks
2.3.5.3 Program Execution
2.3.5.4 Input / Output
2.3.5.5 Structured Text
2.3.5.6 Sequential Function Charts
2.3.5.7 Ladder Diagrams
2.3.5.8 Instructions Lists
2.3.5.9 Programming environment
Industrial Automation
2013

Programmable Logic Controllers 2.3 - 107

Programming environment capabilities


A PLC programming environment (e.g. ABB ControlBuilder,
Siemens Step 7, CoDeSys,...) allows the programmer to
- program in one of the IEC 61131 languages
- define the variables (name and type)
- bind the variables to the input/output (binary, analog)
- run simulations
- download programs and firmware to the PLC
- upload from the PLC (if provided, rare)
- monitor the PLC
- document and print

Industrial Automation
2013

Programmable Logic Controllers 2.3 - 108

61131 Programming environment


configuration, editor,
compiler, library

symbols

workstation
code

firmware
download

variable
monitoring
and
forcing
for debugging

network
PLC

Industrial Automation
2013

Programmable Logic Controllers 2.3 - 109

Program maintenance

The source of the PLC program is generally on the laptop of the technician.
This copy is frequently modified, it is difficult to track the original in a process
database, especially if several people work on the same machine.
Therefore, it would be convenient to be able to reconstruct the source programs
out of the PLC's memory (called back-tracking, Rckdokumentation, reconstitution).
This supposes that the instruction lists in the PLC can be mapped directly to graphic
representations -> set of rules how to display the information.
Names of variables, blocks and comments must be kept in clear text, otherwise the
code, although correct, would not be readable.
For cost reasons, this is rarely implemented.

Industrial Automation
2013

Programmable Logic Controllers 2.3 - 110

Is IEC 61131 FB an object-oriented language ?

Not really: it does not support inheritance.


Blocks are not recursive.
But it supports interface definition (typed signals), instantiation,
encapsulation, some form of polymorphism.
Some programming environments offer control modules for better
object-orientation

Industrial Automation
2013

Programmable Logic Controllers 2.3 - 111

Limitations of IEC 61131

- No support to distribute execution of programs over several devices


- No support for event-driven. Blocks may be triggered by a Boolean
variable (intentionally, for good reasons).
- If structured text increases in importance, better constructs are
required (object-orientation)

Industrial Automation
2013

Programmable Logic Controllers 2.3 - 112

Assessment

Which are programming languages defined in IEC 61131 and for what are they used ?
In a function block language, which are the two elements of programming ?
How is a PLC program executed and why is it that way ?
Draw a ladder diagram and the corresponding function block chart.
Draw a sequential chart implementing a 2-bit counter
Program a saw tooth waveform generator with function blocks
How are inputs and outputs to the process treated in a function block language ?
Write a program for a simple chewing-gum coin machine
Program a ramp generator for a ventilator speed control (soft start and stop in 5s)

Industrial Automation
2013

Programmable Logic Controllers 2.3 - 113

Anda mungkin juga menyukai