Download as pdf or txt
Download as pdf or txt
You are on page 1of 32

Automation

Robotics and
System
CONTROL Università degli Studi
di Modena e Reggio Emilia

Programming languages for PLC:


International Standard IEC61131-3
(part one)
Cesare Fantuzzi (cesare.fantuzzi@unimore.it)

Ingegneria Meccatronica
AA 2012/2013
IEC Standards
The International Electrotechnical Commission(IEC)
is a not-for-profit, non-governmental international
standards organization that prepares and publishes
International Standards for all electrical, electronic and
related technologies.
The IEC held its inaugural meeting on 26 June 1906,
following discussions between the British IEE, the
American Institute of Electrical and Electronics
Engineers (IEEE) (then called AIEE), and others.
It currently counts more than 130 countries.
Originally located in London, the commission moved to
its current headquarters in Geneva in 1948.

C. Fantuzzi International Standard IEC61131-3 2


IEC 61131 Standard
IEC 61131 is an IEC standard for Programmable logic controllers
(PLCs). It was known as IEC 1131 before the change in numbering
system by IEC.
- 1 General overview, definitions
- 2 Hardware
- 3 Programming Languages
- 4 User Guidelines
- 5 Messaging Service Specification
- 7 Fuzzy Logic
- 8 Implementation guidelines
C. Fantuzzi International Standard IEC61131-3 3
Key quality features of IEC
61131-3
• Structured software - through use of Configuration,
Resource and Program Organization Units (POUs), that
implements software modularization.
• Data Typing – languages restrict operations to only apply to
appropriate types of data
• Execution control - use of tasks
• Discrete event system handling - Sequential
Function Charts
• Software encapsulation - through use of POUs,
structures and complex data types.

C. Fantuzzi International Standard IEC61131-3 4


History of IEC 61131
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
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


it took 20 years to make that standard…
International Standard
C. Fantuzzi 5
IEC61131-3
Importance of the IEC61131

IEC 61131-3 is the most important automation language


in industry.
80% of all PLCs support it, all new developments base
on it.
Depending on the PLC vendor (and often Country
because cultural reasons), some languages are most
used.

C. Fantuzzi International Standard 6


IEC61131-3
Application Configuration
(Hardware)
configuration

resource resource
Application configuration
(Software)
configuration
resource resource

program program program program

FB FB FB FB
Application Software
(Run Time)
configuration
resource resource
task task task task

program program program program

FB FB FB FB

A Task is a run time


(scan) instance of a
program.
IEC 61131 – Software Model
(Variable exchange)
configuration
resource resource
task task task task

program program program program

FB FB FB FB

global and directly represented variables

access paths

communication function legend: execution control path


or variable access paths
FB function block
variable

C. Fantuzzi International Standard IEC61131-3 10


Communication model (a)

C. Fantuzzi 3. I Linguaggi di Programmazione 11


Communication model (b)

C. Fantuzzi 3. I Linguaggi di Programmazione 12


IEC Programming Model
Data types
Variables
Program organization units (POU)

}
– Functions
Programming
– Function blocks
languages
– Programs
(Programming
Sequential Function Chart (SFC) elements } language)
Configuration elements
– Global variables
– Resources
– Access paths
– Tasks
C. Fantuzzi 3. I Linguaggi
C. Fantuzzi International Standard IEC61131-3
di Programmazione 13 13
The five IEC 61131-3
Programming languages
graphical languages
Function Block Diagram (FBD) Sequential Flow Chart (SFC)
AUTO CALC1
START STEP
DI CALC PUMP

V IN1 OUT >=1 DO T1


MAN_ON V N ACTION D1 D1_READY
STEP A
ACT IN2
D ACTION D2 D2_READY
T2
N ACTION D3 D3_READY
STEP B
Ladder Diagram (LD) D ACTION D4 D4_READY
CALC1 T3

AUTO CALC PUMP


IN1 OUT textual languages
ACT Structured Text (ST)
IN2
MAN_ON
VAR CONSTANT X : REAL := 53.8 ;
Z : REAL; END_VAR
VAR aFB, bFB : FB_type; END_VAR

Instruction List (IL) bFB(A:=1, B:=‘OK’);


Z := X - INT_TO_REAL (bFB.OUT1);
A: LD %IX1 (* PUSH BUTTON *) IF Z>57.0 THEN aFB(A:=0, B:=“ERR”);
ANDN %MX5 (* NOT INHIBITED *) ELSE aFB(A:=1, B:=“Z is OK”);
ST %QX2 (* FAN ON *) END_IF
Structured Text (ST)
ST is a textual language similar to “C”, or (for who might
remember it) PASCAL.
ST can be successfully used to develop complex
algorithm, data structure handling, etc.
ST has the syntactical structure of the procedural
programming languages:
– Assignment
– Choices
– Iteration

C. Fantuzzi International Standard IEC61131-3 15


Assignment
The variable on the left side should be of the same type
of the result of the expression of the right side.
on contrary, the ST compiler will introduce a variable
casting to set all the variables to the same type.

<variable> := <expression>;

C. Fantuzzi International Standard IEC61131-3 16


Choices
IF <Boolean_Expr_1> THEN
<code>;
ELSIF <Boolean_Expr_2> THEN
<code>;
ELSE
<code>;
END_IF

CASE <integer_expression> OF
<integer_value_1> : <code>;
<integer_value_2> : <code>;
...
ELSE
<code>;
END_CASE

C. Fantuzzi International Standard IEC61131-3 17


Iteration
REPEAT
<code>;
UNTIL <Boolean_Expr>
END_REPEAT;

WHILE <Boolean_Expr> DO
<code>
END_WHILE;

FOR <integer_Variable>:= <initial_value> TO


<final_value> BY <step> DO
<code>
END_FOR;

C. Fantuzzi International Standard IEC61131-3 18


Warning
The iteration structure may violate the real time concerns
of the program.
An iteration can’t be done to wait for a external variable
changes.

C. Fantuzzi International Standard 19


IEC61131-3
ST Operators (a)

C. Fantuzzi International Standard IEC61131-3 20


ST Operators (b)

C. Fantuzzi International Standard IEC61131-3 21


Functional Block Language

Funktionsblocksprache, Langage de blocs de


fonction.
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

C. Fantuzzi International Standard IEC61131-3 22


Function Block Examples
Example 1:
A
B & C

Example 2: external inputs external outputs

Trigger T &
S Spin
Running

Reset R

Function blocks is a graphical programming language, which is akin to the


electrical and block diagrams of the analog and digital technique.

It mostly expresses combinatorial logic, but its blocks may have a memory
(e.g. flip-flops).

C. Fantuzzi International Standard IEC61131-3 23


Function Block Elements
Function block parameters

Example "continuously"
set point PID executing block,
independent,
measurement motor 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 Connections that carry a pseudo-continuous data flow.
Connects the function blocks.

Example set point (set point)


(set point)

C. Fantuzzi International Standard IEC61131-3 24


Function Block Example

C. Fantuzzi International Standard IEC61131-3 25


Rule of evaluation
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.
The signals flow from left to right and from top to bottom.
Feedback is an exception: the signal direction is from right to
the left, and it is identified by an arrow
a
b x

c y

C. Fantuzzi 26
Ladder Diagram

(Kontaktplansprache, langage à contacts)


The ladder logic is the oldest programming language for
PLC
it bases directly on the relay intuition of the electricians.
it is widely in use outside Europe.
It is described here but not recommended for new
projects.

C. Fantuzzi 3. I Linguaggi di Programmazione 27


Ladder Logic (1)

make contact
origin: 02
electrical 01 relay coil
circuit (bobine)

03 50
break contact
(contact repos)

01 02
corresponding 50 rung
03
ladder diagram

50 05 "coil" 50 is used to move


44 other contact(s)
C. Fantuzzi International Standard IEC61131-3 28
Ladder logic (2)
The contact plan or "ladder logic" 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 logic symbols represent the elements:

make contact contact travail Arbeitskontakt

break contact contact repos Ruhekontakt

relay coil bobine Spule

C. Fantuzzi International Standard IEC61131-3 29


Ladder logic (3)
Binary combinations are expressed by series and parallel relay contact:
ladder logic representation "CMOS" equivalent
Series
+ 01 02 01

50 50
02

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

Parallel + 01
40 01

02 40
02

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

C. Fantuzzi International Standard 30


IEC61131-3
Ladder logic (4)
The ladder logic is more intuitive for complex binary expressions than
literal languages textual expressions

1 2 3 4
%50 !N 1 & 2 STR 3 & N 4 STR N 5
5 6 & 6 / STR & STR = %50

0 1 4 5 12
%50 !0 & 1 STR 2 & 3 / STR STR 4
2 3 6 7 & 5 STR N 6 & 7

/ STR & STR STR 10


10 11 & 11 / STR & 12 = %50

C. Fantuzzi International Standard IEC61131-3 31


Ladder logic (5)
Ladder logic 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
literal expression:
FUN 02 200
!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.

C. Fantuzzi International Standard IEC61131-3 32

You might also like