El PLC - Libro Programmable Logic Controllers - Festo
El PLC - Libro Programmable Logic Controllers - Festo
El PLC - Libro Programmable Logic Controllers - Festo
Programmable logic
controllers
Basic level TP301 Textbook
1A1
TP_1Y1
S1
&
TP
1B1
IN
PT
ET
1Y1
T#5s
1V1
1Y1
5
TP_1Y1
S1
1B1
T#5s
093311
1Y1
TP
IN
PT
ET
B-II
093311
SPS LB GS
D.LB-TP3011-GB
08/2002
28.08.2002, OCKER Ingenieurbro Graphics:
D. Schwarzenberger, OCKER Ingenieurbro
R. Bliesener, F.Ebel, C.Lffler, B. Plagemann,
H.Regber, E.v.Terzi, A. Winter
B-III
Preface
The programmable logic controller represents a key factor in industrial
automation. Its use permits flexible adaptation to varying processes as
well as rapid fault finding and error elimination.
This textbook explains the design of a programmable logic controller and
its interaction with peripherals.
One of the main focal points of the textbook deals with the new international standard for PLC programming, the EN 61131-3 (IEC-61131-3).
This standard takes into account expansions and developments, for
which no standardised language elements existed hitherto.
The aim of this new standard is to standardise the design, functionality
and the programming of a PLC in such a way as to enable the user to
easily operate with different systems.
In the interest of continual further improvement, all readers of this book
are invited to make contributions by way suggestions, ideas and constructive criticism.
August 2002
The authors
B-IV
B-V
Table of Contents
Chapter 1 Automating with a PLC
B-1
1.1
Introduction
B-1
1.2
B-2
1.3
B-5
1.4
B-8
Chapter 2 Fundamentals
B-11
2.1
B-11
2.2
B-11
2.3
B-13
2.4
B-13
2.5
B-14
2.6
Real numbers
B-14
2.7
B-15
B-19
3.1
B-19
3.2
B-23
3.3
B-25
3.4
B-28
3.5
Karnaugh-Veitch diagram
B-30
B-VI
B-33
4.1
Structure of a PLC
B-33
4.2
B-35
4.3
B-37
4.4
B-39
4.5
Input module
B-41
4.6
Output module
B-43
4.7
B-45
B-47
5.1
B-47
5.2
B-50
5.3
Programming languages
B-54
B-57
6.1
Resources of a PLC
B-57
6.2
B-60
6.3
Program
B-70
B-85
7.1
B-85
7.2
Evaluation of networks
B-85
7.3
Loop structures
B-87
B-89
8.1
B-89
8.2
B-92
8.3
B-93
B-VII
B-95
9.1
Instructions
B-95
9.2
Operators
B-96
9.3
B-97
B-99
10.1
Expressions
B-99
10.2
Statements
B-101
10.3
Selection statements
B-103
10.4
Iteration statements
B-106
B-111
11.1
Introduction
B-111
11.2
B-111
11.3
Transitions
B-120
11.4
Steps
B-123
11.5
Example
B-135
B-139
12.1
B-139
12.2
B-139
12.3
B-145
12.4
Edge evaluation
B-148
Chapter 13 Timers
B-153
13.1
Introduction
B-153
13.2
Pulse timer
B-154
13.3
B-156
13.4
B-158
B-VIII
Chapter 14 Counter
B-161
14.1
Counter functions
B-161
14.2
Incremental counter
B-161
14.3
Decremental counter
B-165
14.4
Incremental/decremental counter
B-167
B-169
15.1
B-169
15.2
B-169
B-175
16.1
Commissioning
B-175
16.2
B-177
Chapter 17 Communication
B-183
17.1
B-183
17.2
Data transmission
B-183
17.3
Interfaces
B-184
17.4
B-185
Bibliography of illustrations
B-187
Bibliography of literature
B-189
B-191
Glossary
B-193
Index
B-199
Appendix
B-1
Chapter 1
Simple programming
Subsequent development resulted in a system, which enabled the simple connection of binary signals. The requirements as to how these signals were to be connected were specified in the control program. With
the new systems it became possible for the first time to plot signals on a
screen and to file these in electronic memories.
Since then, three decades have passed, during which the enormous
progress made in the development of microelectronics did not stop short
of programmable logic controllers. For instance, even if program optimisation and thus a reduction of required memory capacity initially still represented an important key task for the programmer, nowadays this is
hardly of any significance.
Moreover, the range of functions has grown considerably. 15 years ago,
process visualisation, analogue processing or even the use of a PLC as
a controller, were considered as Utopian. Nowadays, the support of
these functions forms an integral part of many PLCs.
The following pages in this introductory chapter outline the basic design
of a PLC together with the currently most important tasks and applications.
B-2
Chapter 1
B-3
Chapter 1
Fig. B1.1:
Example of a
PLC application
B-4
Chapter 1
B-5
Chapter 1
Fig. B1.2:
Example of a PLC:
Festo IPC PS1 Professional
Chapter 1
PLC-program
Input module
Sensors
Output module
Actuators
The function of an input module is to convert incoming signals into signals, which can be processed by the PLC, and to pass these to the central control unit. The reverse task is performed by an output module. This
converts the PLC signal into signals suitable for the actuators.
The actual processing of the signals is effected in the central control unit
in accordance with the program stored in the memory.
The program of a PLC can be created in various ways: via assemblertype commands in statement list, in higher-level, problem-oriented languages such as structured text or in the form of a flow chart such as
represented by a sequential function chart. In Europe, the use of function block diagrams based on function charts with graphic symbols for
logic gates is widely used. In America, the ladder diagram is the preferred language by users.
Depending on how the central control unit is connected to the input and
output modules, differentiation can be made between compact PLCs
(input module, central control unit and output module in one housing) or
modular PLCs.
Chapter 1
Fig. B1.4 shows the FX0 controller by Mitsubishi and the IPC FEC Standard controller by Festo as an Example
Fig. B1.4:
Compact-PLC
(Mitsubishi FX0,
Festo IPC FEC Standard),
modular PLC
(Siemens S7-300)
Chapter 1
Chapter 1
B-10
Chapter 1
B-11
Chapter 2
Fundamentals
2.1 The decimal number system
Characteristic of the decimal number system used in general is the linear array of digits and their significant placing. The number 4344, for
instance, can be represented as follows:
4344 = 4 x 1000 + 3 x 100 + 4 x 10 + 4 x 1
Number 4 on the far left is of differing significance to that of number 4 on
the far right.
The basis of the decimal number system is the availability of 10 different
digits (decimal: originating from the Latin decem = 10 ). These 10 different digits permit counting from 0 to 9. If counting is to exceed the
number 9, this constitutes a carry over to the next place digit. The significance of this place is 10, and the next carry over takes place when 99
is reached.
The number 71.718.711 is to be used as an example:
10 7
10 6
7
105
1
10 4
7
10 3
1
102
8
10 1
7
100
1
Example
1
As can be seen from the above, the significance of the "7" on the far left
is 70.000.000 = 70 million, whereas the significance of the "7" in the third
place from the right is 700.
The digit on the far right is referred to as the least significant digit, and
the digit on the far left as the most significant digit.
Any number system can be configured on the basis of this example, the
fundamental structure can be applied to number systems of any number
of digits. Consequently, any computing operations and computing methods which use the decimal number system can be applied with other
number systems.
2.2 The binary number system
We are indebted to Leibnitz, who applied the structures of the decimal
number system to two-digit calculation. As long ago as 1679, this created the premises essential for the development of the computer, since
electrical voltage or electrical current only permits a calculation using
just two values: e.g. "current on", "current off". These two values are
represented in the form of digits: "1" and "0".
Chapter 2
2 7 = 128
26 = 64
25 = 32
24 = 16
23 = 8
22 = 4
21 = 2
20 = 1
The principle is exactly the same as that of the method used to create a
decimal number. However, only two digits are available, which is why
the significant place is not calculated to the base 10x, but to the base 2x.
Hence the lowest significant number on the far right is 0 = 1, and of the
next place 21 = 2 etc. Because of the exclusive use of two digits, this
number system is known as the binary or also the dual number system.
Up to a maximum of
2 8 1 = 256 1 = 255
can be calculated
number 1111 11112.
with
eight
places,
which
would
be
the
The individual places of the binary number system can adopt one of the
two digits 0 or 1. This smallest possible unit of the binary system is
termed 1 bit.
In the above example, a number consisting of 8 bits, i.e. one byte, has
been configured (in a computer using 8 electrical signals representing
either "voltage available" or "voltage not available" or "current on" or
"current off".) The number considered, 1011 00012, assumes the decimal value 17710.
Example
1 x 27
= 128
= 177
0 x 26
1 x 25
1 x 24
+ 32
+ 16
0 x 23
0 x 22
0 x 21
1 x 20
1
Chapter 2
0000BCD
110
0001BCD
210
0010BCD
310
0011BCD
410
0100BCD
510
0101BCD
610
0110BCD
710
0111BCD
810
1000BCD
910
1001BCD
4 digits in binary notation are therefore required for the 10 digits in the
decimal system. The discarded place (in binary notation, the numbers 0
to 15 may be represented with 4 digits) is accepted for the sake of clarity.
The decimal number 7133 is thus represented as follows in the BCD
code:
0111 0001 0011 0011BCD
16 bits are therefore required to represent a four digit decimal number in
the BCD code. BCD coded numbers are often used for seven segment
displays and coding switches.
2.4 The hexadecimal number system
The use of binary numbers is often difficult for the uninitiated and the
use of the BCD code takes up a lot of space. This is why the octal and
the hexadecimal system were developed. Three digits are always combined in the case of the octal number system. This permits counting from
0 to 7, i.e. counting in "eights".
Table B2.1:
Representation of decimal
numbers in BCD code
Chapter 2
16 3 = 4096
162 = 256
161 = 16
16 0 = 1
Integer
Range of values
unsigned
0 to 65535
signed
-32768 to +32767
Chapter 2
The number 27,3341 is thus converted into 273 341 x 10-4. Two wholesigned numbers are therefore required for a real number to be represented in a computer.
2.7 Generation of binary and digital signals
As has already become clearly apparent in the previous section, all
computers and as such all PLCs operate using binary or digital signals.
By binary signal, we understand a signal, which recognises only two
defined values.
Fig. B2.1:
Binary signal
These values are termed "0" or "1", the terms "low" and "high" are also
used. The signals can be very easily realised with contacting components. An actuated normally open contact corresponds to a logic 1signal and an unactuated one to a logic 0-signal. When working with
contactless components, this can give rise to certain tolerance bands.
For this reason, certain voltage ranges have been defined as logic 0 or
logic 1 ranges.
Fig. B2.2:
Voltage ranges
V
30
1 - range
11
5
0
-3
0 - range
t
Chapter 2
V
6
5
Analogues Signal
Digital Signal
on 0,5V basis
Digital Signal
on 1V basis
4
3
2
Digital
Signal on
3V basis
1
0
Digital signals may be formed from analogue signals. This method is for
instance used for analogue processing via PLC. Accordingly, the analogue input signal within a range of 0 to 10 V is reduced into a series of
step values. Depending on the quality of the PLC and the possible step
height set, the digital signal would thus be able to operate in steps of
value of 0.1 V, 0.01 V or 0.001 V. Naturally, the smallest range is selected in this instance in order for the analogue signal to be reproduced
as accurately as possible.
Chapter 2
One simple example of an analogue signal is pressure, which is measured and displayed by a pressure gauge. The pressure signal may assume any intermediate value between its minimum and maximum
values. Unlike the digital signal, it changes continually. In the case of the
processing of analogue values via a PLC, as described, analogue voltage signals are evaluated and converted.
On the other hand, digital signals can be formed by adding together a
certain number of binary signals. In this way, again as described in the
above paragraph, it is also possible to generate a digital signal with 256
step values.
Bit No.
Digital value
Example 1
187
Example 2
51
Example 3
This process is for instance used to implement timer and counter functions.
Example
Chapter 2
Chapter 3
Boolean operations
3.1. Basic logic functions
As described in the previous chapter, any computer and equally any
PLC operates using the number system to the base 2. This also applies
to the octal (2 3) and the hexadecimal systems (2 4). The individual variable can therefore assume only two values, "0" or "1". Special algorithms have been introduced to be able to link these variables the socalled boolean algebra. This can be clearly represented by means of
electrical contacts.
Negation (NOT function)
The push button shown represents a normally closed contact. When this
is unactuated, lamp H1 is illuminated, whereas in the actuated state,
lamp H1 goes off.
Fig. B3.1:
Circuit diagram
24V
S1
(I)
H1
(O)
0V
Push button S1 acts as signal input, the lamp forms the output. The actual status can be recorded in a truth table:
I
Fig. B3.2:
Truth table
Chapter 3
I=I
1
Conjunction (AND-function)
If two normally open contacts are switched in series, the actuated lamp
is illuminated only if both push buttons are actuated.
Fig. B3.5:
Circuit diagram
24V
S1
(I1)
S2
(I2)
H1
(O)
0V
Chapter 3
I1
I2
Fig. B3.6
Truth table
The truth table assigns the conjunction. The output assumes 1 only if
both input 1 and input 2 produce a "1"-signal. This is referred to as an
AND operation, which is represented as follows as an equation:
I1 I2 =
O
Fig. B3.7
AND function
I1
&
O
I2
0 =0
1=a
a =0
a =a
Chapter 3
Disjunction (OR-Function)
Another basic logic function is OR. If the 2 normally open contacts are
switched in parallel, then the lamp is illuminated whenever a least one
push button is pressed.
Fig. B3.8:
Circuit diagram
24V
S1
(I1)
S2
(I2)
H1
(O)
0V
Fig. B3.9
Truth table
Fig. B3.10:
OR function
I1
I2
I1
>=1
O
I2
Chapter 3
3.2
Further
operations
logic
Name
Equation
Truth table
log. symbols
pneumatic realisation
Table B3.1:
Logic connections
elektr. realisation
elektron. realisation
I
I
0
1
O
R
Negation
O
O
I
O
I1 I 2 O
I1
I2 = O
>
Conjuction
0
1
1
I1
I2
O
O
O
I1
Disjunction
I1
I2 = O
0
0
1
I2
I2
>=1
R
Chapter 3
Table B3.1:
Logic connections
(continuation)
Name
Equation
Truth table
log. symbols
pneumatic realisation
elektr. realisation
elektron. realisation
I1 I2 O
Antivalence
(exclusive
OR)
I2
I2
I1 I2 O
Equivalence
I1
I1
I1
=
I2
I1
NAND
K1
I1
I2
K1
I2
NOR
K1
O
>=1
K1
Chapter 3
1A1
B1
B4
B3
B2
Parts with the following hole patterns are for the Standard kitchen type.
These parts are to be advanced via the double-acting cylinder 1.0.
Chapter 3
Fig. B3.12:
Hole pattern parts
Assuming that a drilled hole is read as a 1-signal, the following truth table results.
Fig. B3.13
Truth table
Chapter 3
Two options are available in order to derive the logic equation from this
table, which lead to two different expressions. The same result is obtained, of course, since the same circumstances are described.
Standard form, disjunctive
In the disjunctive standard form, all conjunctions (AND-operations) of
input variables with the result 1, are carried out as a disjunctive operation (OR-operation). With signal status 0, the input variable is carried out
as a negated operation and with signal status 1 as a non-negated operation.
In the case of the example given, the logic operation is therefore as follows:
y=
(a b c d) (a b c d) (a b c
( a b c d) ( a b c d) ( a b c d)
Conjunctive standard form
In the conjunctive standard form, all disjunctions (OR-operations) of the
input variable producing the result 0, are carried out as a conjunctive
operation (AND-operation). In contrast with the disjunctive standard
form, in this instance, the input variable is negated with signal status "1"
and a non-negated operation carried out with signal status "0".
y=
( a b c d) ( a b c d) ( a b c d )
( a b c d) ( a b c d) ( a b c d )
( a b c d) ( a b c d)
( a b c d) ( a b c d)
Chapter 3
(a b c d) (a b c d) (a b c
(a b c d ) (a b c d ) (a b c d )
This expression may be simplified with the help of a boolean algorithm.
The most important rules in boolean algebra are shown below:
a 0=a
a 0 =0
a1=1
a 1=a
aa =a
a a =a
aa =1
a a =0
Commutative law
a b =ba
a b =b a
Associative law
a b c = a (b c ) = (a b )
c a b c = a (b c ) = (a
b) c
Chapter 3
Distributive law
a (b c ) = (a b ) (a
a (b c ) = (a b ) (a c )
c)
De Morgans rule
a b =a b
a b =a b
Reduction rule
a a b =a b
= acd ad b b
= ac a d
= ca d
= cd ad
For reasons of clarity, the AND-operation symbol has been omitted in
the individual expressions.
The basic principle of simplification is in the factoring out of variables
and reducing to defined expressions. However, this method does require
a sound knowledge of boolean algorithms plus a certain amount of practice. Another option for simplification will be introduced in the following
section.
Chapter 3
No.
10
11
12
13
14
15
16
cd
cd
cd
cd
ab
ab
ab
10
11
12
ab
13
14
15
16
Fig. B3.15:
Value table
Chapter 3
The results of the value table are transferred to the KV diagram according to the diagram shown below. In principle, representation is again
possible in conjunctive or disjunctive standard form. The following, however, will be limited to the disjunctive standard form.
cd
cd
cd
cd
ab
ab
ab
ab
Fig. B3.16:
Value table
The next step consists of combining the statuses, for which "1" has been
entered in the value table. This is done in blocks whilst observing the
following rules:
cd
cd
cd
cd
ab
ab
ab
ab
Y1
Y2
Fig. B3.17:
Value table
Chapter 3
The variable values are selected for the established block and these in
turn combined disjunctively.
y1 = cd
y2 = acd
y = cd acd
( )
= (c a ) d
= c ac d
= cd ad
Naturally, the KV diagram is not limited to 16 squares. 5 variables, for
instance, would result in 32 squares (2 5), and 6 variables 64 fields (2 6).
Chapter 4
Data bus
Microprocessor
(CPU)
ROM
RAM
Operatingsystem
Program
and data
Address bus
Control bus
Inputmodule
Outputmodule
Chapter 4
Chapter 4
Data bus
ALU
Control bus
Accumulator
Command register
Control bus
Program counter
Arithmetic unit
Control unit
Address bus
Chapter 4
Fig. B4.4:
Command sequence
Data bus
Microprocessor
Memory
Command Command
register
Control signals
Command
Programcounter
+1
Address bus
Chapter 4
The contents of the program counter are transferred to the address bus.
The control unit then causes the command at a specified address in the
program memory, to be relayed to the data bus. From there, the command is read to the instruction register. Once the command has been
decoded, the control unit generates a sequence of control signals for
execution.
During the execution of a program, the commands are fetched in sequence. A mechanism, which permits this sequence, is therefore required. This task is performed by a simple incrementer, i.e. a step
enabling facility in the program counter.
4.3 Function mode of a PLC
Programs for conventional data processing are processed once only
from top to bottom and then terminated. In contrast with this, the program of a PLC is continually processed cyclically.
Fig. B4.5:
Cyclical processing of
a PLC program
Image table
Inputs
Inputs
PLC program
Image table
Outputs
Outputs
Chapter 4
Prior to first program line being processed, i.e. at the beginning of the
cycle, the status of the inputs is stored in the image table. The process image is a separate memory area accessed during a cycle. The
status of an input thus remains constant during a cycle even if it has
physically changed
The processing of a program line via the central control unit of a PLC
takes time which, depending on PLC and operation can vary between a
few microseconds and a few milliseconds.
The time required by the PLC for a single execution of a program including the actualisation and output of the process image, is termed the cycle time. The longer the program is and the longer the respective PLC
requires to process an individual program line, the longer the cycle. Realistic time periods for this are between approximately 1 and 100 milliseconds.
The consequences of cyclical processing of a PLC program using a
process image are as follows:
Input signals shorter than the cycle time may possibly not be recognised.
In some cases, there may be a delay of two cycle times between the
occurrence of an input signal and the desired reaction of an output to
this signal.
Since the commands are processed sequentially, the specific behaviour sequence of a PLC program may be crucial.
With some applications it is essential for inputs or outputs to be accessed directly during a cycle. This type of program processing, bypassing of the process image, is therefore also supported by some PLC
systems.
Chapter 4
RAM
EPROM
EEPROM
RAM
The RAM (random access memory) is a fast and highly cost effective
memory. Since the main memory of computers (i.e. PLCs) consist of
RAMs, they are produced in such high quantities that they are readily
available at low cost without competition.
RAMs are read/write memories and can be easily programmed and
modified.
The disadvantage of a RAM is that it is volatile, i.e. the program stored in
the RAM is lost in the event of power failure. This is why RAMs are
backed up by battery or accumulator. Since the service life and capacity
of modern batteries are rated for several years, RAM back-up is relatively simple. Despite the fact that these are high performance batteries
it is nevertheless essential to replace the batteries in good time.
Chapter 4
EPROM
The EPROM (erasable programmable read-only memory) is also a fast
and low cost memory, which, in comparison with RAM, has the added
advantage of being non-volatile, i.e. remanent. The memory contents
therefore remain intact even in the event of power failure.
Fig. B4.6:
Example of an EPROM
Chapter 4
Screening of signals
Inputsignal
Error
voltage
detection
Signal
delay
Optocoupler
Signal to
the
control unit
The main component of todays input modules which meets these requirements is the optocoupler.
The optocoupler transmits the sensor information with the help of light,
thereby creating an electrical isolation between the control and logic
circuits, thereby protecting the sensitive electronics from spurious external voltages. Nowadays, advanced optocouplers guarantee protection
for up to approximately 5 KV, which is adequate for industrial applications.
The adjustment of control and logic voltage, in the straightforward
case of a 24 V control voltage, can be effected with the help of a breakdown diode/resistor circuit. In the case of 220 V AC, a rectifier is connected in series.
Depending on PLC manufacturer reliable signal detection is ensured
either by means of an additional downstream threshold detector or a
corresponding range of breakdown diodes and optocouplers. Precise
data regarding the signals to be detected is specified in DIN 19 240.
Fig. B4.7:
Block diagram of an
input module
Chapter 4
Chapter 4
In a number of countries, the use of negative switching sensors is commonplace, i.e. the PLC inputs operate as a power source. In these
cases, a different protective measure must be used to prevent a 1-signal
from being applied to the input of the PLC in the event of a shortcircuit
on the signal line. Possible methods are the earthing of the positive control voltage or insulation monitoring, i.e. protective grounding as a protective measure.
4.6 Output module
Output modules conduct the signals of the central control unit to final
control elements, which are actuated according to the task. In the main,
the function of an output as seen from the application of the PLC
therefore includes the following:
Signal from
the
control unit
Optocoupler
Amplifier
Short-circuit
monitoring
Output
signal
The optocoupler once again forms the basis for power electronics and
ensures the protection of the electronics and possibly also the voltage
adjustment.
A protective circuit consisting of diodes must protect the integral power
transistor from voltage surges.
Fig. B4.8:
Block diagram of an
output module
Chapter 4
Chapter 4
Programming
Testing
Commissioning
Fault finding
Program documentation
Program storage
These programming and diagnostic tools are either vendor specific programming devices or personal computers with corresponding software.
Nowadays, the latter is almost exclusively the preferred variant, since
the enormous capacity of modern PCs, combined with their comparatively low initial cost and high flexibility, represent crucial advantages.
Also available and being developed are so-called hand-held programmers for mini control systems and for maintenance purposes. With the
increasing use of laptop personal computers, i.e. portable, battery operated PCs, the importance of hand-held programmers is steadily decreasing.
Essential software system functions forming part of the programming and diagnostic tool
Any programming software conforming to EN 61131-1 (IEC 61131-1)
should provide the user with a series of functions. Hence the programming software comprises software modules for:
Program input
Creating and modifying programs in one of the programming languages via a PLC.
Syntax test
Checking the input program and the input data for syntax accuracy,
thus minimizing the input of faulty programs.
Translator
Translating the input program into a program, which can be read and
processed by the PC, i.e. the generation of the machine code of the
corresponding PC.
Chapter 4
Test functions
Supporting the user during writing and fault elimination and checking
the user program via
a status check of inputs and outputs, timers, counters etc.
testing of program sequences by means of single-step operations,
STOP commands etc.
simulation by means of manual setting of inputs/outputs, setting
constants etc.
Documentation
Drawing up a description of the PLC system and the user program.
This consists of
Description of the hardware configuration
Printout of the user program with corresponding data and identifiers for signals and comments
Cross-reference list for all processed data such as inputs, outputs,
timers etc.
Description of modifications
Chapter 5
Programming of a PLC
5.1 Systematic solution finding
Control programs represent an important component of an automation
system.
Control programs must be systematically designed, well structured and
fully documented in order to be as
error-free
low-maintenance
cost effective
as possible.
Phase model of PLC software generation
The procedure for the development of a software program illustrated in
fig. B5.1 has been tried and tested. The division into defined sections
leads to targeted, systematic operation and provides clearly set out results, which can be checked against the task.
The phase model consisting of the following sections
Chapter 5
Fig. B5.1:
Phase model for the
generation of PLC software
1.
Specification
2.
Design
3.
Realisation
4. Commissioning
Design of system
Testing of subprograms
Testing of overall program
The phase model can be applied to control programs of varying complexity; for complex control tasks the use of such a model is absolutely
essential.
The individual phases of the model are described below.
Phase 1: Specification (Problem formulation)
In this phase, a precise and detailed description of the control task is
formulated. The specific description of the control system function, formalised as much as possible, reveals any conflicting requirements,
mis- leading or incomplete specifications.
The following are available at the end of this phase:
Structure/layout
Chapter 5
Chapter 5
In so far as PLC programming systems support this, the control programs or parts of a program created should be simulated prior to commissioning. This permits the detection and elimination of errors right at
the initial stage.
Phase 4:
Commissioning (Construction and testing of the
task)
control
This phase tests the interaction of the automation system and the connected plant. In the case of complex tasks, it is advisable to commission
the system systematically, step by step. Faults, both in the system and
in the control program, can be easily found and eliminated using this
method.
Documentation
One important and crucial component of a system is documentation,
which is an essential requirement for the maintenance and expansion of
a system. Documentation, including the control programs, should be
available both on paper and on a data storage medium.
The documentation consists of the document of the individual phases,
printouts of the control programs and of any possible additional descriptions concerning the control program. Individually these are:
Problem description
Circuit diagram
Terminal diagram
Allocation list of inputs and outputs (this also forms part of the control
program printouts)
Additional documentation
Chapter 5
CONFIGURATION
RESOURCE
TASK
VAR_GLOBAL
ACCESS_PATH
Sequential function
chart
PROGRAM
FUNCTION_BLOCK
FUNCTION
DATATYPES
Configuration
automation system
Sequence
representation
Refinement
Modularisation
Structuring
of
configuration
level
Structuring
of
program level
Fig. B5.2:
EN 61131-3 (IEC
61131-3)
structuring method
Chapter 5
Configuration
Valve_production
Resource
Valve_assembly
Task_1
Resource
Conveyor_control
Resource
Quality_control
Task_
cyclical
Task_2
Program
Assembly
Program
Conveyor
Program
Initial_position_run
Program
Conveyor_idle_run
Task_
unique
Program
Packaging
Program
Statistics
Program
Data_save
Chapter 5
Chapter 5
Part_TypeA
Part_ TypeB
Part_present
Drill_ok
Sleeve_in
Chapter 5
OR
AND
Sleeve_in
Part_TypeB
Part_present
Drill_ok
Part_TypeA OR
Part_TypeB
AND Part_present
AND Drill_ok
ST Sleeve_in
Fig. B5.6:
Example of instruction
list language
Chapter 5
Structured text enables the formulation of numerous applications, beyond pure function technology, such as algorithmic problems (high order
control algorithms etc.) and data handling (data analysis, processing of
complex data structures etc.).
Sequential function chart (SFC)
The sequential function chart is a language resource for the structuring
of sequence-oriented control programs.
The elements of the sequential function chart are steps, transitions, alternative and parallel branching.
Each step represents a processing status of a control program, which is
active or inactive. A step consists of actions which, identical to the transitions, are formulated in the EN 61131-3 (IEC 61131-3) languages. Actions themselves can again contain sequence structures. This feature
permits the hierarchical structure of a control program. The sequential
function chart is therefore an excellent tool for the design and structuring
of control programs.
Chapter 6
Inputs
Outputs
Memory
Fig. B6.1:
Designations for
inputs, outputs
and memory
Chapter 6
BOOL
BYTE
WORD
1-Bit sizes, such as defined by the data type BOOL (boolean), may only
assume the values 0 or 1. Consequently, the range of values for BOOL
type data consists of the two values 0 and 1.
In contrast with this, one should observe that in the case of bit sequence
data types consisting of more than one bit, there is no immediate connected range of values. All bit sequence data types such as for instance
BYTE and WORD are merely a combination of several bits. Each of
these bits has the value 0 or 1, but their combination does not have its
own value.
The mandatory designation methods for inputs, outputs and flags of different bit length are represented in fig. B6.3.
Fig. B6.3
Designations for inputs,
outputs and memory
I, Q, M or
IX, QX, MX
1 Bit
IB, QB, MB
8 Bit
IW, QW, MW
16 Bit
An individual bit of an input, output or flag may also be addressed without the additional abbreviation X for the data type.
Chapter 6
I1
Input 1
IX9
Input 9
I15
Input 15
QW3
Output word3
MB5
Memory byte 5
MX2
Memory 2
EN 61131-3 (1EC 61131-3) does not specify the number range, which is
permissible for this numbering and whether it should start with 0 or 1.
This is specified by the controller manufacturer.
A hierarchical number of inputs, outputs and flags may also be used, if
the controller in use has been suitably configured.
A point is used to separate the individual levels of the hierarchy. The
number of hierarchy levels has not been defined.
1n the case of hierarchical numbering, the highest position in the number
on the left must be coded, the numbers further to the right represent
consecutive lower positions.
13.8.5
Example
Input
in insert No. 3
on plug-in card No. 8
as input No. 5
3.
8.
Chapter 6
EN 61131-3 (1EC 61131-3) does not make any comment regarding the
assignment of individual bits in a BYTE or WORD. Controller manufacturers frequently choose hierarchical designation methods to assign individual bits as parts of words. As such, F6.2 could for instance
represent the bit number 2 of flag word number 6. However, this does
not necessarily have to be so, since flag bit F6.2 and flag word FW6
need not be in any way connected. Moreover, no definition has been
made as to whether the numbering of individual bits in one word is to
start on the left or the right (bit number 0 on the far right has been the
most frequently used so far).
Directly addressed variables
1f resources in a control program are to be addressed directly, the resource designation must be prefixed with the sign %.
Examples of directly addressable variables:
%IX12 or %I12
Input bit 12
%IW5
Input word 5
%QB8
Output byte 8
%MW27
Memory word 27
The use of directly addressed variables is permissible solely in programs, configurations and resources.
The program organisation units Function and Function block must operate exclusively with symbolic variables in order to keep these as controller- independent as possible and as such more widely usable.
6.2 Variables and data types
The use of exclusively directly represented variables (resources, inputs,
outputs and memory) is not enough to create control programs. Frequently, data is required, which contains specific information, also of a
more complex nature. This data can be specified direct, e.g. time data or
counter values or accessible via variables only i.e. via a symbolic designation. The most important definitions for dealing with data or variables
is shown below.
Chapter 6
Symbolic addressing
A symbolic identifier always consists of capital or lower case letters, digits and an underline. An identifier must always begin with a letter or an
underline. The underline can also be used to render an identifier more
readable. 1t is however a significant character. The two identifiers Motor_on and Motoron are therefore different. Several underlines are impermissible. 1f the controller supports capital and lower case letters, then
the use of these letters must not be of any significance. The two identifiers MOTORON and Motoron are interpreted identically and designate
the same object.
The following identifiers are impermissible:
123
Button_?
Counter values
Time values
Strings
Chapter 6
Table B6.1:
Representation of
numerical data
Description
Examples
Integers
Numbers to base2
(Binary numbers)
2#1111_1111
2#1101_0011
(255 decimal)
(211 decimal
Numbers to base8
(Octal numbers)
8#377
8#323
(255 decimal)
(211 decimal
Numbers to base16
(Hexadecimal numbers)
16#FF or 16#ff
16#D3 or 16#d3
(255 decimal)
(211 decimal
0, 1
* The use of individual underlines between the digits is permissible to improve readability. However, the underline is not significant.
Table B6.2:
Representation of time data
Date
Description
Examples
Time duration
Date
D#1994-07-21
DATE#1994-07-21
Time of day
TOD#13:18:42.55
TIME_OF_DAY#13:18:42.55
DT#1994-07-21-13:18:42.55
DATE_AND_TIME#1994-07-21-13:18:42.55
Chapter 6
Day
Hour
Minute
Second
ms
Millisecond
Capitals may also be used instead of lower case letters and individual
underlines inserted for the purpose of better readability.
A fixed format has also been specified by EN 61131-3 (1EC 61131-3) for
the specification of a date, time of day or a combination of both. Each
specification starts with a key word; the actual information is represented
as shown in table B6.2.
Another important method of representation of data is the use of a sequence of characters also known as strings, which may be required for
the exchange of information, e.g. between different controllers, with
other components of an automation system or also for the programming
of texts for display on control and display units.
A string consists of zero or several characters, introduced and ended by
a simple inverted comma.
Example
Description
Warning
void string
Table B6.3:
Representation of strings
Chapter 6
Data types
EN 61131-3 (1EC 61131-3) defines a large number of data types for different tasks. One such data type, BOOL, has already been mentioned. A
BOOL type variable either assumes the value 0 or 1.
Table B6.4
A number of elementary
data types
Keyword
Data type
Range of values
BOOL
Boolean number
0, 1
SINT
Short integer
0 to 255
INT
Integer
DINT
Double integer
UINT
Unsigned integer
0 to 65 535
REAL
+/-2.9E-39 to +/-3.4E+38
TIME
Time duration
implementation-dependent
STRING
Variable-long string
implementation-dependent
BYTE
Bit sequence 8
WORD
Bit sequence 16
Two other important data types, named 1NT and U1NT define integer
numbers. Variables of data type 1NT (integer) permit numeric values of 32 768 to +32 767. The range of values of data type 1NT therefore covers both negative and positive numbers. Type U1NT variables (unsigned
integer) permit positive values only. The range of values for U1NT extends from 0 to 65 535. S1NT (short integer) and D1NT (double integer)
are additional data types defining integer numbers. However, these have
an even smaller or greater range of values than data type 1NT. The data
type REAL contains floating point numbers. These are numbers, which
can contain places after the point, such as for instance 3.24 or -1.5.
Data type T1ME is used to specify time, and may contain a time duration
such as for instance 2 minutes and 30 seconds.
Apart from these elementary predefined data types, the user has the
possibility of defining own data types. This is useful in cases where the
problem definition goes beyond the realms of pure control technology.
Derived data types are declared within a TYPE...END_TYPE construct.
The complete declaration is listed below for enumeration type Colour in
table B6.5.:
TYPE
Colour: (RED, BLUE, YELLOW, BLACK);
END_TYPE
Chapter 6
Declaration
TYPE END_TYPE
Enumeration type
Subrange type
Reference_range: INT(80..110);
Fields (array)
Structures
Coordinates:
STRUCT
X:REAL;
Y:REAL;
END_STRUCT;
A data element of the type Colour may only assume one of the values
RED, BLUE, YELLOW or BLACK.
Not every controller needs to recognise all these data types. Each controller manufacturer puts together a set of data types, which may be
used in the controller.
Variable declaration
With the use of data, the right of access to this data must be clearly defined. To this end, EN 61131-3 (1EC 61131-3) uses a variable declaration.
1n order to understand the function of a variable declaration, it is first of
all necessary to establish that the controller program is constructed into
individual organisation units.
Table B6.5:
Derived data types
Chapter 6
Configuration
Resource
Programs
Function blocks
Functions
All variables have a specific position. In the case of programming languages in text form (IL and ST), variable declarations are roughly the
same as those used in the programming language Pascal. For graphic
forms of representation, a tabular form with equivalent contents would
be feasible. These are however not specified in EN 61131-3 (IEC 611313).
All variable declarations (fig. B6.5) always start with a keyword, which
designates the position of the variable in the organisation unit of the controller, and end with the keyword END_VAR.
Fig. B6.5:
Variable declaration
VAR
Temp
: INT;
Hand
: BOOL;
Full, Open : BOOL;
END_VAR
(*Temperature
(*Flag for manual operation
(*Flag for full and open
*)
*)
*)
The variables and their assignment to a data type are entered between
these keywords in that the symbolic identifier or identifiers of the variables are specified, the data type named after a colon and the declaration closed with a semicolon. If several variables are declared, they are
repeated correspondingly. Normally, each declaration is written in a
separate line in this case.
EN 61131-3 (IEC 61131-3) differentiates between six different types of
access to variables. Each type has a keyword, which introduces the
variable declaration.
Table B6.6:
Keywords for the
declaration of variables
Input variables
VAR_INPUT
Output variables
VAR_OUTPUT
In-/Output variables
VAR_IN_OUT
Local variables
VAR
Global variables
VAR_GLOBAL
External Variables
VAR_EXTERN
Chapter 6
: INT;
(*Input value
*)
Fig. B6.6:
Declaration of an
Input variable
: INT;
(*Feedback value
*)
Fig. B6.7:
Declaration of a
Output variable
The data, which computes an organisation unit and feeds this back externally is declared as above.
All organisation unit results are to be transferred beyond the organisation units via variables declared in this way. Within the organisation
units, these can be read and written. Externally, read access only is
permitted.
1n cases where variables containing input and output values are permitted, these must be created with the keywords VAR_1N_OUT and
END_VAR.
VAR_IN_OUT
Value
END_VAR
: INT;
This form represents a third option and permits the declaration of variables, which may be read and used within the organisation unit.
1n the case of a variable declared as VAR_1N_OUT, it is assumed that
values will be supplied both to and from the organisation unit.
Often, variables are required for intermediate results, which are to remain unknown externally. Locally named variables such as these are
initiated with VAR and closed with END_VAR.
Fig. B6.8:
Declaration of a
In-/Output variable
Chapter 6
Fig. B6.9:
Declaration of a
local variable
VAR
Z
END_VAR
: INT;
(*Intermediate result
*)
The variables specified here are local to an organisation unit and can
only be used within this. They are unknown in all other organisation units
and therefore inaccessible.
One typical application are memory locations for intermediate results,
which are not of any interest in other areas of the program. 1n the case
of these variables, it should be noted that they may also exist several
times in different organisation units. 1n this way, it is for instance possible for several function blocks to declare the local variable Z. These local variables are totally unrelated and differ from one another.
A variable may also be globally declared, in which case it may be accessed universally. The necessary declaration is carried out in a similar
way, whereby the keywords VAR_GLOBAL and VAR_EXTERNAL are
used.
Fig. B6.10:
Declaration of a
global variable
VAR_GLOBAL
lobal value: INT;
END_VAR
This is how all global data for a control program is declared. Global data
is universally accessible. This declaration can only be found in the organisation units configuration and resource.
Fig. B6.11:
Declaration of access
of a global variable
VAR_EXTERNAL
Global value:
END_VAR
INT;
Chapter 6
VAR
Stop_button AT %12.3
Temperature AT %IW3
END_VAR
:
:
BOOL;
BOOL;
Fig. B6.12:
Declaration of variables
with assignment to
inputs of a controller
Declarations in this form are the best means for defining the significance
of all inputs and outputs of the controller. 1f a change occurs in the system and its connection to the controller, only these declarations need be
changed. Any usage of the Stop_button, or the Temperature within an
existing program, remain unaffected by this.
According to EN 61131-3 (1EC 61131-3) it is however nevertheless possible to use directly addressed variables without being assigned to a
symbolic identifier. The declaration in that case is as follows:
VAR
AT %14.2
AT %12.3
END_VAR
: BOOL;
: WORD;
Initialisation
Very often it is essential for a variable to be given an initial value. This
value may change several times during the processing of a program,
even though it is defined at the start.
1nitial statuses such as these are also important for other data. Such
initial values are specified jointly with the declaration of the variables. A
global variable of this type named Dozen is to be declared which, at the
start of the program, assumes the value 12.
VAR_GLOBAL
Dutzend
END_VAR
: INT :=12;
As shown by this example, the initialisation value is always inserted between the data type in this instance 1NT and the closing semicolon.
The specification of the initialisation value always requires the prefixed
symbol :=.
Fig. B6.13:
Declaration of a global variable with initial value
Chapter 6
1n this way, each variable can be assigned a special initial value. Fundamentally, variables always have a defined initial value at the start of a
program. This is facilitated by the characteristic defined in EN 61131-3
(1EC 61131-3), whereby data types already have a preset value. Each
variable is preallocated the initial value of the corresponding data type
unless otherwise specified in the program. A list of initial values of a selection of elementary data types can be seen in table B6.7.
Table B6.7:
Preset initial values
Data type
Initial value
UINT
BYTE, WORD
REAL
0.0
TIME
T#0s
STRING
(void string)
6.3 Program
The program for a controller is divided into individual organisation units,
which are as follows at the programming level:
Programs
Function blocks
Functions
Chapter 6
Functions
Functions are software modules which, when invoked provide exactly
one result (data element). This is why in a text language the invocation
of a function may be used as an operand in one expression.
Functions cannot contain status information. This means that the invocation of a function with the same arguments (input parameters) must provide the same result.
The addition of 1NT values or logic OR functions are examples for functions.
Functions and their invocation may be represented graphically or in text
form.
Fig. B6.14:
Graphic representation
of a function
F Name
X
Y
Z
Inputs
Output
Chapter 6
Fig. B6.15:
Use of formal parameters
with functions
VAR
AT
AT
AT
AT
%QW4
%IW9
%IW7
%MW1
:
:
:
:
INT;
INT;
INT;
INT;
END_VAR
%QW4
%IW9
%IW7
%IW2
4
ADD
%MW1
SHL
IN
N
%MW5
AND
%Q4.1
%M1.1
1f a function is invoked, its inputs and the function output must be connected.
Chapter 6
The ADD function illustrated in fig. 6.15a processes 1NT values, for
which the deployed directly addressed variables such as %QW4 etc. are
declared as variables of data type 1NT. Equally, the ADD function could
be applied to type S1NT or REAL counter values.
Functions such as these, which operate to input parameters of a different data type are termed as overloaded, type-independent functions in
EN 61131-3 (1EC 61131-3). Fig. B6.17 illustrates the characteristics of
an overloaded function using the example of an ADD function.
Fig. B6.17:
Overloaded, typeindependent function
ADD
example
VAR
INT
INT
ADD
AT %IW1
AT %IW2
AT %MW3
INT
: INT;
: INT;
: INT;
END_VAR
%IW1
%IW2
ADD
%MW3
example
VAR
SINT
SINT
ADD
SINT
AT %IB4
AT %IB5
AT %MB6
: SINT;
: SINT;
: SINT;
END_VAR
%IB4
%IB5
ADD
%MB6
Chapter 6
Fig. B6.18:
A typed function
general
example
VAR
INT
ADD_INT
INT
INT
AT %IW1
AT %IW2
AT %MW3
: INT;
: INT;
: INT;
END_VAR
%IW1
ADD_INT
%MW3
%IW2
Standard functions
The most important standard functions for the realisation of basic control
technology tasks are listed below.
Since a wide variety of standard function are able to operate using input
parameters of different data types, the data types have been combined
into groups. Each group is given a generic data type. The most important generic data types are shown in table B6.8.
Table B6.8:
Generic data types
ANY_NUM
all data types for floating point numbers such as REAL and for
integer numbers such as INT, UINT etc., are contained in
ANY_REAL and ANY_INT
ANY_INT
ANY_REAL
ANY_BIT
all bit sequence data types such as BOOL, BYTE, WORD etc.
Chapter 6
ANY_BIT
***
ANY_BIT
ANY_BIT
...
Table B6.9:
Bit-by-bit
boolean functions
...
ANY_BIT
* * * = name or symbol
Name
Symbol
AND
&
OR
XOR
Description
AND operation of all inputs
>=1
=2k+1
NOT
***
ANY_BIT
IN
ANY_INT
ANY_BIT
* * * = name
Name
Description
SHL
SHR
ROR
ROL
Chapter 6
Table B6.11:
ANY_BIT or ANY_NUM
...
***
ANY_BIT or ANY_NUM
...
* * * = name or symbol
Name
Table B6.12:
Functions for
type conversion
Symbol
Description
GT
>
GE
>=
EQ
Equal
LE
<=
LT
<
NE
<>
a) Graphic representation
ANY_BIT
BCD_TO_INT
INT
Description:
Converts variables of type BYTE, WORD etc. into
variables of type INT.
The bit sequence-variable contains data in BCD format.
(binary coded decimal number)
Example:
2#0011_0110_1001
BCD_TO_INT
369
b) Graphic representation
INT
INT_TO_BCD
ANY_BIT
Description:
Converts variables of type INT into variables of type BYTE,
WORD etc.
The bit sequence-variable contains data in BCD format.
Example:
25
INT_TO_BCD
2#0010_0101
Chapter 6
ANY_NUM
***
ANY_NUM
ANY_NUM
...
...
ANY_NUM
* * * = name or symbol
Name
Symbol
Description
ADD
MUL
SUB
DIV
MOVE
:=
Function blocks
Function blocks are software modules, which supply one or several result parameters.
One important characteristic is the possibility of instantiation of function
blocks. If a function block in a control program is to be used, a copy or
instance must be created. This is effected via the assignment of an instance name. Linked to this identifier is a data structure, which stores
the statuses of this function block copy (values of the input parameters,
output parameters and internal variables). The status information of the
function block copy remains intact from one processing to the next.
This can be demonstrated using the example of the standard function
block for counting operations. The current counter value remains from
one counting operation to the next and can thus be interrogated at any
chosen time. This type of behaviour cannot be realised via the language
resource, as described above.
Table B6.13:
Arithmetic functions
Chapter 6
Fig. B6.19:
Graphic representation of a
function block copy
Identifier
FB-Type
Data type
Data type
Inputs
Data type
Outputs
CTU
BOOL
CU
BOOL
INT
PV
Q
CV
BOOL
INT
Count_Pack
CTU
%I1.3
CU
R
10
PV
CV
%Q2.5
Chapter 6
the identifier
increases the
10 has been
assumes a 1-
It is also possible for several copies to be created of one and the same
function block within a control program, as illustrated fig. B6.21.
TP
BOOL
IN
BOOL
TIME
PT
ET
TIME
Function block
type TP (pulse timer)
T_Color
OR
T_Pressure
TP
TP
%I 1.7
T#7s
IN
PT
ET
Display_1
T#3s15ms
IN
PT
ET
Fig. B6.21:
Use of several copies of a
function block
Chapter 6
SR
RS
CTU
Incremental counter
CTD
Decremental counter
TP
Pulse
TON
TOF
R_TRIG
F_TRIG
User-defined functions
Apart from the functions specified, EN 61131-3 (IEC 61131-3) permits
the definition of own functions.
The following rules apply for graphic declaration:
Chapter 6
FUNCTION
Fig. B6.22:
Example function
SPEZ_MUL
SPEZ_MUL
INT
M1
INT
M2
INT
(* Functionbody:
*)
(* Programmed in FBD language *)
M1
M2
SPEZ_MUL
15
END_FUNCTION
VAR
AT
AT
AT
AT
AT
%MW1
%MW2
%MW3
%IW4
%QW5
:
:
:
:
:
Fig. B6.23:
Use of SPEZ_MUL function
INT;
INT;
INT;
INT;
INT;
END_VAR
SPEZ_MUL
%MW1
M1
%MW2
M2
%IW4
%QW5
%MW3
Chapter 6
FUNCTION_BLOCK...
Extended access of data, such as global variables are not taken into
account here.
Fig. B6.24:
Declaration of a
function block
FUNCTION_BLOCK
Debouncing
BOOL
S_ON
TIME
E_TIME
S_OFF
BOOL
S_ON
EP_ON
EP_S
TON
SR
IN
S1
PT
ET
EP_OFF
TOF
E_TIME
IN
PT
ET
END_FUNCTION_BLOCK
Q1
S_OFF
Chapter 6
The function block illustrated in fig. B6.24 represents a function block for
the debouncing of signals, consisting of two input parameters, i.e. one
boolean input for the signal and one time input for the adjustment of debounce time. The output parameter S_OFF supplies the debounced output signal.
Programs
A program consists of any language elements and constructs necessary
to achieve the desired machine or process behaviour via the PLC.
Programs are therefore constructed in the main for functions, function
blocks and the elements of the sequential function chart.
Program features are thus largely identical to those of function blocks.
The only thing of interest at this stage are the differences:
declarations are
PRO-
PROGRAM
staircase_light
VAR
Switch_
F
Switch_A
Lamp
Duratio
n
AT %IX0.0 :
AT %IX0.1 :
AT %QX0.0 :
:
*)
BOOL; (* Light switch at front door
BOOL; (* Light switch at appartment door *)
*)
BOOL; (* Stairwell light
TP;
(* Time illuminated
END_VAR
Switch_F
OR
Duration
TP
Switch_A
T#3m
END_PROGRAM
IN
PT
ET
Lamp
*)
Chapter 6
Chapter 7
>=1
Gate_closed
>
Temp
60
IN
T#7s
PT
ET
%Q2.4
Chapter 7
&
Variant_1
%M2.5
Variant_1:
%M2.1
%I 2.5
>=1
%Q1.0
Chapter 7
&
>=1
%I 2
&
%M2.0
>=1
%I 2
By means of the utilisation of a feedback path, the third input of the ORfunction assumes a defined value during its processing.
Chapter 7
Chapter 8
Ladder diagram
8.1 Elements of the ladder diagram
The ladder diagram language, like the function block diagram, represents a graphic programming language. The elements available in a
ladder diagram are contacts and coils in different forms. These are laid
out in rungs within the confines of power rails on the left and on the right.
%M1.5
%Q3.5
Fig. B8.1 illustrates the basic structure of a current rung. In this example,
the status of the flag %M1.5 is directly assigned to %Q3.5. Table B8.1
contains a list of the most important elements of a ladder diagram.
Fig. B8.1:
Basic structure of a rung
Chapter 8
Table B8.1:
Elements of the ladder
diagram
Contacts
Normally open contact
/
N
Coils
Coil
/
Negating coil
Setting coil
Resetting coil
Chapter 8
Fig. B8.2
Basic logic connections
in ladder diagram
a) AND function
%I 1.3
%M3.2
%Q2.1
b) OR function
%I 1.5
%Q2.3
% M3.4
Chapter 8
a) Incorporation of functions
Add_akt
Add_ok
+
EN ENO
Quantity_1
Quantity_2
Filling_level
TON
T#7s
IN
PT
ET
%Q2.4
The addition shown in fig. B8.3a is only undertaken, if a 1-signal is applied at the input EN. If this is the case, the variables Quantity_1 and
Quantity_2 are added and the result of these variables assigned to the
variable Filling_Level. At the same time, the value of output ENO indicates, whether the addition has been executed, activated and correct
(ENO=1). If the block has not been processed correctly, the output ENO
assumes the value 0.
Chapter 8
Function modules such as for instance the signal delay shown in fig.
B8.3b can be incorporated in the ladder diagram without additional EN
input and ENO output. The function block is connected with the elements of the current rung in the usual manner via the boolean input IN
and the boolean output Q. If input %I1.3 in fig. B8.3b assumes the value
1, the function block copy T_Startup is processed with the preset time
duration of 7 seconds. The value of output Q of T_Startup is assigned to
output %Q2.4.
8.3 Evaluation of current rungs
Similar to the graphic programming language FBD, the power flow, and
as such processing within a program organisation unit, is from left to
right and from top to bottom. Equally, the processing sequence may also
be changed in LD by using elements for execution control.
%I 1.1
Fig. B8.4:
Conditional jump in LD
%M2.5
Variant_1
Variant_1:
%M2.1
%Q1.0
%I 2.5
If the jump condition, in this case the AND operation of input %I1.1 and
flag %M2.5, is met, a jump is executed to the current rung with the identifier Variant_1. Processing is then continued from this current rung onwards.
Chapter 8
Chapter 9
Instruction list
9.1 Instructions
Instruction list is a textual, assembler-type programming language. Its
instructions most closely reassemble the commands processed in a
PLC.
A control program formulated in the Instruction List language consists of
a series of instructions, whereby each instruction must begin with a new
line.
A fixed format is specified for the formulation of an instruction. An instruction (fig. B9.1) starts with an operator with optional modifier and, if
necessary for the particular operation, one or several Operands, separated by commas. Instructions may be preceded by a label followed by a
colon. The label acts as a jump address. Labels are identified in the
same way as symbols. If a comment is used, this must represent the last
element of the line. A comment is introduced via the string (*, and ended
by the string *).
Fig. B9.1:
Structure of an instruction
Instruction
Label
Start:
Operator and
modifier
LD
AND
ST
Operand
%I1.2
%M3.7
%Q2.4
Comment
(*
(*
(*
(*
Part present
Drill ok
Stamp
advance
*)
*)
*)
*)
The value of input %I1.2 is loaded to the accumulator and ANDed with
value of flag %M3.7. The resultant actual result is assigned to output
%Q2.4.
Chapter 9
9.2 Operators
Table B9.1:
Instruction list operators
Operator
Modifier
Operand
Description/Significance
LD
ST
BOOL
BOOL
AND
N, (
BOOL
Boolean AND
&
N, (
BOOL
Boolean AND
OR
N, (
BOOL
Boolean OR
XOR
N, (
BOOL
Boolean exclusive OR
ADD
Addition
SUB
Subtraction
MUL
Multiplication
DIV
Division
GT
Comparison: >
GE
Comparison: >=
EQ
Comparison: =
NE
LE
Comparison: <=
LT
Comparison: <
JMP
C, N
Marke
Jump to label
CAL
C, N
Name
RET
C, N
Chapter 9
EN 61131-3 (IEC 61131-3) defines the operators for the instruction list
listed in table B9.1.
Operators are not linked with any priorities. Accordingly, operations are
processed in the sequence, in which they are entered in the instruction
list. If a different sequence is desired, this can be achieved through the
use of brackets so-called modifiers. Fig. B9.2 explains the use of some
modifiers.
LDN
%I1.1
AND(
%I1.2
OR
%I1.3
(*
(*
(*
(*
(*
(*
(*
(*
(*
(*
(*
(*
JMPC
Start
*)
*)
*)
*)
*)
*)
*)
*)
*)
*)
*)
*)
Fig. B9.2:
Use and significance
Temp
60
Manual_off
Gate_off
(*
(*
(*
(*
Fig. B9.3:
Invocation of functions
Measured temperature
Greater than 60
OR button Manual_off actuated
Close gate
*)
*)
*)
*)
*)
*)
*)
Chapter 9
More complex functions such as bit shift functions are invoked by the
function name being placed in the operator field. The current result (in
the Accumulator) must be used as the first argument of the function. If
further arguments are required, these must be specified in the operand
field separated by commas. The value returned by the function, represents the new current result.
Function blocks may be invoked according to different mechanisms (fig.
B9.4).
Fig. B9.4:
Invocation of function blocks
*)
*)
*)
*)
*)
*)
*)
*)
Prerequisite is for the variable T_startup to be declared as a signal delay. The invocation of a function block may be clearly set out through the
use of the operator CAL with a list of associated input parameters.
The variable T_startup from fig. B9.4a, declared elsewhere as a signal
delay, therefore represents a signal delay type block. Being a current
argument, this is assigned the value of input %I1.3 for the activation input IN and the time duration T#7s for the input PT. As a result, function
block T_startup is invoked following the actualisation of parameters.
The transfer of parameters to a function block may also be effected
separately from the actual function block invocation.
As shown in fig. B9.4b, the actual parameter values are loaded via elementary IL operations and assigned to the inputs of the function block.
Only after this is function block T_startup invoked and processed via a
CAL instruction. The advantage of this method lies in the fact that the
timing of the actualisation of arguments and the actual invocation of the
function module may be separate.
Chapter 10
Structured text
10.1 Expressions
The Structured Text language is a Pascal-type high-level language,
which incorporates the fundamental concepts of a modern high-level
language, in particular the most important principles for the structuring of
data and instructions. The structuring of data represents a common constituent of all five programming languages; the structuring of instructions,
however, is an important feature of ST only.
An expression is an elementary constituent for the formulation of instructions. An expression consists of operators and operands. Frequently
occurring operands are data, variables or function invocations. However,
an operand may also be an expression itself. The evaluation of an expression supplies a value corresponding to one of the standard data
types or to a user data type. For instance, if X is a number of the type
REAL, then the expression SIN(X) also supplies a REAL type number.
Table B10.1 contains an overview of operators.
Operation
Symbol
Priority
Parenthesis
(expression)
highest
Function processing
Function name
(Transfer parameter list)
Example: LOG(X), SIN (Y)
Exponentiation
**
Sign
Complement
NOT
Multiplication
Division
Modulo
*
/
MOD
Addition
Subtraction
Comparison
Equality
Inequality
=
<>
Boolean AND
&, AND
Boolean exclusive OR
XOR
Boolean OR
OR
lowest
Table B10.1:
Operators of structured
text language
B-100
Chapter 10
A, B and C are variables of data type INT; A assumes the value 1, B the
value 2 and C the value 3. The evaluation of expression A+B*C supplies
the value 7. If a sequence other than that specified by the precedence is
desired, this is possible by using brackets. Using the above numeric
values, the expression (A+B)*C supplies the value 9.
If an operator has two operands, the leftmost operand is to be evaluated
first. The expression SIN(X)*COS(Y) is therefore evaluated in the sequence: Calculation of the expression SIN(X), calculation of the expression COS(Y), followed by the calculation of the product of SIN(X) and
COS(Y).
As demonstrated in the previous paragraph, a function may only be invoked within an expression. The invocation is formulated by specifying
the function name and the parenthesised list of arguments.
Chapter 10
10.2 Statements
Table B10.2 contains a list of statements possible in the Structured Text
language. A statement may extend beyond one line, whereby the line
break will be treated in the same way as a blank space.
Statement
Example
Assignment :=
A := B;
CV := CV + 1;
Y := COS(X);
Invocation of function
blocks
RETURN;
RETURN
Selection statements
IF
CASE
CASE Voltage OF
101 ... 200: Display := too_large;
20 ... 100: Display := large;
2 ... 29: Display := normal;
ELSE
Display := too_small;
END_CASE;
Table B10.2:
Statements of
structured text language
Chapter 10
Table B10.2:
Statements of
structured text language
(continuation)
Statement
Example
Iteration statements
FOR
Total := 0;
FOR I := 1 TO 5 DO
Total := Total + I;
END_FOR;
REPEAT
Total := 0;
I := 0;
REPEAT
I := I + 1;
Total := Total + I;
UNTIL I = 5
END_REPEAT;
WHILE
Total := 0;
I := 0;
WHILE I < 5 DO
I := I + 1;
Total := Total + I;
END_WHILE;
Termination of loops
EXIT
EXIT;
Void instruction
;;
Assignments
An assignment is the simplest form of an instruction. This replaces the
actual value of the variable to the left of := with the value of the expression to the right of :=. Each assignment ends with a semicolon. One
possible assignment (table B10.2) is A := B; whereby the value of the
variable B is assigned to the variable A. As a result of the assignment
CV := CV + 1, the variable CV is increased by 1 as a result of the expression CV+1.
Function blocks and functions
A defined mechanism is set out in EN 61131-3 (IEC 61131-3) for the
invocation and also the early exit from a function or a function block.
As described, a function is invoked only as part of expression evaluation.
The invocation itself consists of the specification of the function name,
followed by the parenthesised list of input parameters.
Chapter 10
Chapter 10
IF-Statement
The general form of an IF statement is:
IF boolean expression1 THEN statement(s)1;
[ ELSIF boolean expression2 THEN statement(s)2; ]
[ ELSE statement(s); ]
END_IF;
The parts in square brackets are optional, i.e. these may occur in an IF
statement, but need not do so.
The simplest IF statement consists of an IF-THEN construct (simple
branch).
This is demonstrated by the following example
IF X < 0 THEN X := X;
END_IF;
Y := SQRT(X);
The statements following the keyword THEN are executed, if the condition following the keyword IF is met; if the condition is not met, the
statements formulated after the keyword ELSE are executed.
Chapter 10
The example given deals with production parts. If the part is good
(Part_ok = 1), the THEN part is executed, in this case the number of
correctly produced parts is increased by 1; otherwise a bit is set for error
detection.
If a branch is to be programmed for more than 2 branches, an IF-THENELSIF construct may be employed. Table B10.2 illustrates this by way of
an example, whereby the solutions of the quadratic equation AX2 + BX +
C = 0 are established. If the discriminant in this case variable D is
less than 0, the subsequent THEN part is executed: there is no solution,
i.e. Number_Sln := 0.
If the first condition is not met, i.e. D is greater or equal to 0, the condition following ELSIF will be evaluated: If it is met, i.e. D equals 0, the
statements following the keyword THEN will be executed: The only existing solution is specified as X1.
Otherwise (D being greater than 0), the lines following the keyword
ELSE will be executed: The two possible solutions X1 and X2 are specified.
CASE-Statement
If a selection of several possible statement groups is to be made, the
CASE statement may be used.
The standard form for the multiple selection with CASE is:
CASE Selector OF
Value1: statement(s)1;
Value2: statement(s)2;
...
Valuen: statement(s)n;
[ ELSE
statement(s); ]
END_CASE;
Chapter 10
With the evaluation of the CASE statement, the value of the selector is
determined first, followed by the execution of the first group of statements, for which the computed value of the selector applies. If the value
of the selector is not contained in any of the statement groups, the
statements following the keyword ELSE are executed. If ELSE does not
occur, no statements are executed.
In the example given in table B10.2, the text for a statement is selected
in relation to the available measured value. The values for the selection
of the statement are of the INT type.
10.4 Iteration statements
It is often necessary to execute statements repeatedly (program loops).
The FOR loop is used, if the number of repetitions has been defined in
advance, otherwise the REPEAT or the WHILE loop is used.
FOR loop
The standard representation of the FOR loop is:
FOR Variable := expression TO expression [ BY expression ] DO
statement(s);
END_FOR;
Chapter 10
The test for the termination condition is made at the beginning of each
iteration, so that the statements are not executed if the initial value exceeds the final value. A further characteristic of FOR loops is that these
may be nested at any time.
An example of the application of a FOR loop is given in table B10.2. In
this example, an addition of numbers 1 to 5 is realised via the loop.
When the loop is executed for the first time, I has the initial value 1, the
value of the variable Total is also 1. For the second loop execution, I has
the value 2, the variable Total reaches the value 1+2=3 etc. After the
fifth and last loop execution, the value for Total is 15, the counter variable has reached the final value 5, and processing of the loop is thus
completed.
REPEAT loop
Unlike the FOR loop, with the REPEAT loop the number of iterations is
not defined in advance via a specified final value. Instead, a condition
the so-called termination condition is used.
The form of a REPEAT loop is as follows
REPEAT
statement(s);
UNTIL boolean expression
END_REPEAT;
The termination of the REPEAT loop is tested after the execution of the
loop statements. The loop is therefore executed at least once. The termination condition must be changed in the loop, since the loop will otherwise be executed indefinitely. It is therefore important to ensure that
the loop has actually been completed. The following is to be checked:
Chapter 10
In the first loop execution, I has the value 1, the value of Total is also 1.
A check of the termination condition shows, that this is not met, whereby
the loop is executed again. The loop is executed repeatedly until the
termination condition is true. This will be the case after the fifth loop execution and the loop is ended. Here too, the result for the variable Total is
15L.
WHILE loop
The WHILE loop represents a second option for the formulation of iterations by specifying a termination condition. The standard representation
of a WHILE loop is:
WHILE boolean expression DO
statement(s);
END_WHILE;
Chapter 10
If the EXIT statement is within a nested loop, exit shall be from the innermost loop in which the EXIT is located. The next statement to be
executed is the statement immediately after the loop end (END_FOR,
END_WHILE, END_REPEAT). In the example is the statement "S := S
+I;".
The following applies in the case of the above example: If the value of
the boolean variable Error is equal to 0, the algorithm for the variable S
provides the value 15. If the variable Error has the value 1, the value
computed for S is 3.
Chapter 10
Chapter 11
Chapter 11
Table B11.1:
Elements of the sequential
function chart
(graphic representation)
a)
b)
c)
b
d
d)
Step_3
e)
f)
Alternative branch
Step_4
Step_5
Step_6
Step_7
Step_8
Chapter 11
g)
Table B11.1:
Elements of the sequential
function chart
(graphic representation)
Step_3
B
h)
Step_4
Step_5
Step_6
Step_7
M
Step_8
The step
A step contains a number of execution parts of the control program. Inputs and outputs may only be set or reset in a step. This also means that
all correcting variables issued to the connected plant by a control program, can only be programmed in such steps.
The execution part assigned to a step, the so-called actions, are formulated within action blocks.
A step is either active, with the associated action being executed at the
time, or inactive. In this way, the status of the connected system is defined at any given moment by the set of active steps in the control program.
As shown in table B11.1a, a step is represented graphically by a block.
Each step has a symbolic name, which can be freely selected by the
user. The same set of rules applies for the step name as those already
mentioned for symbolic identifiers: a symbolic name may consist only of
capital and lower case letters, digits and the underline and always starts
with a letter or the underline.
Fig. B11.1:
Steps with step names
Motor_3_on
Vacuum_off
Chapter 11
All steps in a program or function block formulated in a sequential function chart must have different names. Even if two steps have the same
execution parts, these are to be designated twice.
The reason for this is as follows:
Information is stored in the controller for each step. The unique assignment of this information to a step as well as the access to this data is
effected via the step name.
The user can thus obtain information regarding
the time, for which a step has been active since initiation
a) Motor_3_on.X
b) Motor_3_on.T
The evaluation of the above data can be useful with regard to monitoring
the connected system. Applications may also arise, which require the
use of variables in the control program itself.
A special case within the step element is the so-called initial step (table
B11.1b). This is drawn graphically by a double line.
Each network in a sequential function chart has precisely one initial step,
which is executed as the first step within a network.
As already mentioned, the importance of a sequential function chart lies
in its clearly structured graphic representation of a control program. It
may however also be useful to represent sequence structures textually.
The EN 61131-3 (IEC 61131-3) standard provides an equivalent textual
representation of SFC elements for this, which is as follows for the step
element:
Chapter 11
STEP Motor_3_on
(* Contents of step*)
END_STEP
STEP Vacuum_off
(*Contents of step*)
END_STEP
Fig. B11.2:
Textual representation
of steps
Chapter 11
Table B11.3:
Special transitions
Always true
transition condition
Transition condition
never true
Step_5
D
Step_6
E
Step_7
F
Here, the transitions and steps must continually alternate. The logic path
via this representation is always from top to bottom. The following behaviour can be seen in the example shown in fig. B11.3:
Assuming that step Step_5 is active, Step_5 remains active until transition D is true. Clearing of the transition results in the deactivation of the
preceding step Step_5 and the activation of the successive step Step_6.
As soon as step Step_6 is active, transition E of the controller is examined. If transition E is true, step Step_6 is ended and step Step_7 is
processed, etc.
Chapter 11
Chapter 11
Fig. B11.4:
Alternative branch:
Processing of transitions
from left to the right
Step_3
Step_4
Step_5
F
Step_6
I
Step_7
However, the EN 61131-3 (IEC 61131-3) standard also offers the facility
for the user to define the priority during the execution of the transitions.
The definition of the functionality of alternative branches in IEC 60848,
which requires a user programmed mutual exclusion of transition conditions, is also supported by EN 61131-3 (IEC 61131-3) as a third method.
In contrast with the previous examples the numbers in the path in fig.
B11.5 indicate a user-defined priority of the transition evaluation. The
path with the lowest number has the highest priority.
Fig. B11.5:
Alternative branch with
user-defined priority
Step_7
2
Step_8
Step_9
As such, a transition is evolved from step Step_7 to step Step_9, if transition E is true, or a transition is evolved from step Step_7 to step
Step_8, if transition D is true and transition E is false.
A loop structure may be regarded as a special case of alternative
branching, whereby one or several paths return to a preceding step.
Chapter 11
Fig. B11.6:
Representation of a loop
Step_3
C
Step_4
D
Step_5
Step_6
In fig. B11.6 the program flow evolves from step Step_5 to step Step_4,
if transition F is true and E is false. The evolution of step sequence
Step_4, to Step_5 may be repeated in this way.
Parallel branch
A completely different functional element of the sequential function chart
is parallel branching.
This is represented by a double line and a transition above this line (table B11.1g). As soon as transition B is fulfilled, an evolution from step
Step_3 to step Step_4 and Step_5. These two steps are executed simultaneously.
A parallel branch determines that all connected paths are to be activated
simultaneously and evolved independently of one another. In the case of
the matching counterpart, and the joining of parallel paths, the transition
is always represented underneath the horizontal double line.
Chapter 11
Step_4
Step_5
Step_6
G
Step_7
When step enabling condition F has been fulfilled, the three paths with
steps Step_4, Step_5 and Step_6 and Step_7 must be evolved simultaneously.
Depending on the contents of transition G between the two stepsStep_6
and Step_7, the control program may have to wait until transition G is
fulfilled. The lower transition H is therefore only examined if the right
path has been evolved completely. This can only be the case, if transition G in this path is true.
11.3 Transitions
Each transition is assigned a transition condition (step enabling condition). This provides the result of a boolean value.
In the simplest case, a step enabling condition can be specified by the
interrogation of an input of the controller or another boolean variable. It
is however also possible to program considerably more complex step
enabling conditions.
Chapter 11
Ladder diagram
Instruction list
Structured text
The contents of the transition condition are either specified directly at the
transition (see fig. B11.8) or linked with the transition via a transition
name (see fig. B11.9)
Fig. B11.8:
a) Transition condition
in LD - language
%IX3
%MX1
Step_3
Step_4
b) Transition condition
in FBD - language
Step_3
%IX3
&
%MX1
Step_4
c) Transition condition
in ST - language
Step_3
%IX3 & %MX1
Step_4
transition condition
Chapter 11
Here, two results are connected via a logic AND function, whereby the
transition condition will not be met until both input %IX3 and flag %MX1
assume the value 1.
The power or signal passes from left to right in the graphic languages LD
and FBD, the LD or FBD network part is defined on the left, next to the
transition symbol (horizontal line).
The boolean expression in ST languages is defined to the right of the
transition symbol.
Fig. B11.9:
Assignment of a
transition condition to the
transition by specifying
a transition name
Step_3
Tran_3_4
Transition name
Step_4
a) Transition condition
in LD - language
TRANSITION Tran_3_4:
%IX3
%MX1 Tran_3_4
END_TRANSITION
b) Transition condition
in FBD - language
TRANSITION Tran_3_4:
%IX3
%MX1
&
Tran_3_4
END_TRANSITION
c) Transition condition
in IL - language
TRANSITION Tran_3_4:
LD
%IX3
AND %MX1
END_TRANSITION
d) Transition condition
in ST - language
TRANSITION Tran_3_4:
:= %IX3 & %MX1;
END_TRANSITION
Chapter 11
11.4 Steps
A step represents the execution part of a sequential function chart. Only
within steps can a program or a function block within a controller influence the connected system via its outputs, by setting or resetting the
outputs.
Fig. B11.10:
Textual representation
of transitions
Chapter 11
a b
c
d
Field a:
Action qualifier:
N = non stored
S = set, stored
R = reset
P = pulse (unique)
L = time limited
Field b:
Name of action
Field c:
Feedback variable
Field d:
Action content
D
DS
SD
SL
= time delayed
= time delayed and stored
= stored and time delayed
= stored and time limited
Chapter 11
L
T#10s
Action_1
Action_2
Action_3
Var_1
The contents of an action, i.e. the action itself, may be defined by means
of several methods:
Ladder diagram
Fig. B11.13:
Textual representation of a
step with actions
Chapter 11
Fig. B11.14:
Formulation of actions:
graphic declaration in FBD
Action_2
>=1
%IX0.5
%MX1
%QX1.2
&
%MX3
Fig. B11.15:
Formulation of actions:
graphic declaration in
LD language
Action_2
%IX0.5
%MX1
Fig. B11.16:
Formulation of actions::
textual declaration
IL language
ACTION Action_2:
LD %IX0.5
OR( %MX1
AND %MX3
)
ST %QX1.2
END_ACTION
%QX1.2
%MX3
ST langugae
ACTION Action_2:
%QX1.2 := %IX0.5 OR (%MX1 AND %MX3);
END_ACTION
Chapter 11
Instead of an individual network of a statement sequence, several networks are also permissible within an action in textual languages. In this
way, it is possible to incorporate a very wide range of actions in a step,
and again a step itself may contain sequence structures (fig. B11.17).
Fig. B11.17: Formulation
of actions: Inclusion of
SFC elements in an action
Action_4
Start
Part_present
Color
C_ok
L
T#1s
Color_determine
If individual fields of an action block are not required, such as for instance if a boolean variable is used as action content, a further simplification in the representation of an action block is permissible.
%QX12
A feedback variable (c field) may be entered in each action block. Feedback variables are programmed within actions by the user and indicate
their completion, timeout or error conditions. Fig. B11.19 indicates a frequently recurring application. Here the sequence of steps and transitions
is structured in such a way that the action of a step sets the subsequent
step enabling condition.
Fig. B11.18:
Short representation
of an action block
Chapter 11
Fig. B11.19:
Use of
feedback variables
Step_2
Cylinder_1
Pos_1
S
S
Cylinder_2
Vacuum_on
Vac_on
Cylinder_1
Pos_2
Pos_1
Step_3
Vac_on
Step_4
Pos_2
Non-stored
Set (stored)
Overriding reset
Pulse (unique)
Time limited
Time delayed
Each action is the equivalent of exactly one of these qualifiers. In addition, the qualifiers L, D, DS, SD, SL have an associated duration of type
Time, since these define a time behaviour of the action.
Chapter 11
%QX12
1
0
1
0
In the above example, the output %QX12 is set for as long as the step
containing this action is active. On completion of the step, i.e. as soon
as the subsequent enabling condition is met, the output is automatically
reset.
S Set (stored)
%QX12
1
0
1
0
In this example, the output %QX12 is set for as long as the step containing this action is active. The output also remains set, when the subsequent step enabling condition is met and the step being considered is no
longer active. The output can only be reset in another step, in another
action, defined with qualifier R.
Chapter 11
R Reset
a previously set action (in another step) executed with the qualifier S,
DS, SD, L or SL is cancelled.
Fig. B11.22:
Reset action
R
Step
active
%QX12
%QX12
1
0
1
0
Output %QX12 has been set in another step in an action with one of the
qualifiers S, DS, SD, L or SL and reset again via this action.
P Pulse (unique)
Fig. B11.23:
Unique action
P
Step
active
%QX12
During the
processing
again. The
and a fresh
%QX12
1
0
1
0
Chapter 11
L Time limited
Step
active
%QX12
%QX12
1
0
1
0
10s
10s
Output %QX12 is set for 10 seconds and subsequently reset again. This
requires the step containing this action to be active for a period of at
least 10 seconds. If the subsequent step enabling conditions are met
prior to this time, the action time of the output is reduced also, since it is
reset at the end of the step in any case.
D Time delayed
the execution of the action is delayed until the end of the step.
Fig. B11.25:
Time delayed action
D
T#10s
Step
active
%QX12
%QX12
1
0
1
0
10s
10s
Here, output %QX12 is not set until 10 seconds have expired and remains set until the step becomes inactive. If the duration during which
the step is activated is less than 10 seconds, the output will not be set
during the processing of this step.
Chapter 11
Fig. B11.26:
Time delayed and
stored Action
DS
T#10s
Step
active
1
0
10s
%QX12
%QX12
10s
1
0
1
R
active
0
(in another step)
In this example too, output %QX12 is set after 10 seconds have expired.
However, it remains set after completion of the step. It must be reset
explicitly via another action with the qualifier R (in another step). If the
duration of the step is not sufficiently long, in this case less than 10 seconds long, the output will never be set.
Chapter 11
%QX12
Step
active
0
10s
10s
%QX12
1
R
0
active
(in another step)
Here too, output %QX12 is set after the expiry of 10 seconds. It remains
set following the end of the step and can only be explicitly reset via another action with the qualifier R in another step. Unlike the mode of action of the DS qualifier, it is not necessary for the step to remain active
beyond the duration of the delay for the output to be set.
SL Stored and time-limited
1
0
10s
%QX12
%QX12
1
0
10s
Chapter 11
The output is set for 10 seconds and then reset again. In contrast with
the mode of action of the L qualifier, it is not necessary for the step to be
active for a minimum of 10 seconds.
If the subsequent step enabling condition is met prior to this time expiring, i.e. if the step is active for less than 10 seconds, the active period of
the output remains unaffected by this. The output can be reset at any
time via another action with the qualifier R.
The mode of action of the individual qualifiers has been illustrated in the
example of a boolean variable as an action. If more complex, i.e. non
boolean actions are required, the type of execution is marginally different
to the previously examined boolean variables. The networks are continually processed for as long as the step is active. As soon as the subsequent step enabling condition is met, however, the last, unique,
execution of the networks is carried out once more.
This definition enables the targeted resetting of variables at the end of
the processing of an action, when the N qualifier is used for more complex actions.
Fig. B11.29:
Complex action
Step_5
Action_1
&
%IX1.0
%QX1.0
%MX12
Step_5.X
SR_1
SR
%IX1.5
S1
Q1
%QX1.5
Chapter 11
11.5 Example
Problem description
Components are transported together on a conveyor belt to a dual processing station. The drilling and countersinking units then move downwards as soon as a component is present. Two cylinders 1A1 and 2A1
are used to move the two machine tools. The conveying device is indexed by one working position via a third cylinder 3A1.
Two sensors B4 and B5 are provided to detect whether a workpiece is
located underneath the drill or the countersink. The required drilling and
countersink depths are sensed via two end position sensors 1B2 and
2B2. The initial positions of the transport cylinder, drill and countersink
can be detected via the values of sensors 1B1, 2B1 and 3B1. Sensor
3B2 indicates an extended transport cylinder.
The system cannot always guarantee that a workpiece will be deposited
underneath both the drill unit and the countersink after each transport
movement. Processing should then be interrupted in the case of a missing workpiece. If both workpieces are missing at the same time, neither
of the two tools should be lowered.
1A1
Fig. B11.30:
Positional sketch
2A1
1B1
2B1
1B2
2B2
B4
B5
3A1
3B1
3B2
Chapter 11
Allocation list
Table B11.4:
Allocation list
Equipment
designation
PLC input/
PLC output
Task
B4
%IX0.1
B5
%IX0.2
1B1
%IX0.3
2B1
%IX0.4
3B1
%IX0.5
1B2
%IX0.6
2B2
%IX0.7
3B2
%IX0.8
1Y1
%QX0.1
2Y1
%QX0.2
Lower countersink
3Y1
%QX0.3
Transport feed
Problem
A control program is to be designed for this task. The solution is to
achieve a configuration by means of a sequential function chart. The
conditions and actions are then to be applied to the steps and transitions. The program is to be executed cyclically.
To simplify matters, you may assume that there is no need to use timers
to compensate for positioning tolerances.
Chapter 11
Solution
Fig. B11.31:
Program in
sequence language
Start
1B1
2B1
3B1
B4
R 1Y1
R 2Y1
R 3Y1
B4
B5
B5
/
Drill
S 1Y1
1B2
Countersink
S 2Y1
2B2
D_up
R 1Y1
1B1
C_up
2B1
1
Transport
3B2
S 3Y1
R 2Y1
Chapter 11
All cylinders are brought into their initial position in one initial step. At the
end of the program, this step is also used to retract the cylinder extended during the last step for the transport device.
When all the cylinders are in their initial position, a parallel branch with
two sequences is started for drilling and countersinking. Both sequences
in this example contain the same tasks, but use different tools. The lefthand sequence lowers the drill unit and lifts it again, and the righthand
sequence evolves identically for the countersinking. The sequences
merely differ in their use of sensors and actuators. A void step is incorporated at the top and bottom of both sequences to maintain the necessary sequence steps and transitions.
The program for the drilling unit evolves as follows. It detects whether a
workpiece is available via the value of sensor B4. If this value is equal to
1, the workpiece is in the required position and the drilling process
starts. Otherwise the entire drilling process is bypassed in an alternative
path. Drilling of the hole starts with the lowering of the drill by setting
1Y1. When the lower end position is reached, i.e. drilling of the hole has
been completed, sensor 1B2 signals the end of drilling. In the next step,
the drill is returned to its normal position at the top. This part of alternative branching ends when the drill has reached the top. The program
follows the same procedure for countersinking.
When both parallel sequences have been completed, a transition takes
place in the program to the transport step. The necessary synchronisation i.e. drilling and countersinking ready is ensured by the sequential function chart and therefore does not require special treatment. A
true step enabling condition is always inserted at this point in order for
the steps and transitions to alternate.
In the last step Transport, the cylinder of the transport device is extended and the awaited completed action in the next transition condition.
Thereafter, the whole process starts anew.
Chapter 12
Protective circuits: a device may only load, if all protective devices are
switched on
Safety interlocking
Chapter 12
as
The solutions are represented in the languages LD, FBD, IL and ST. The
solution sections are preceded by a declaration of the necessary PLC
inputs and outputs. In addition, the description options of a function table
and boolean equation are also listed.
Negation
The output signal assumes the value 1, if the input signal has the value
0 and vice versa.
Example
Lamp H1 is illuminated as long as switch S1 is not actuated; it is extinguished, if the switch is closed. The purpose of S1 is therefore to switch
off the lamp.
Fig. B12.1:
Description methods
Fig. B12.2:
Declaration of variables
Function table
Boolean equation
S1 H1
H1 = S1
VAR
S1 AT %I2.5: BOOL;
H1 AT %Q1.4: BOOL;
END_VAR
Chapter 12
a) LD
b) FBD
S1
H1
S1
c) IL
LDN
ST
Fig. B12.3:
Negation
NOT
H1
d) ST
S1
H1
H1
:=
NOT S1;
AND-operation
The output signal only assumes the value 1, if all input signals have the
value 1.
Lamp H1 is to be switched on only if the two switches S1 ad S2 are actuated.
Function table
VAR
S1 AT %I2.5: BOOL;
S2 AT %I2.6: BOOL;
H1 AT %Q1.4: BOOL;
END_VAR
H1 = S1
Fig. B12.4:
Description methods
S2
<
S1 S2 H1
Boolean equation
Example
Fig. B12.5:
Declaration of variables
Chapter 12
Fig. B12.6:
AND operation
a) LD
b) FBD
S1
S2
H1
&
S1
H1
S2
c) IL
d) ST
LD
AND
ST
S1
S2
H1
H1
:=
S1 AND S2;
OR-operation
The output signal assumes the value 1, if at least one input signal has
the value 1.
Lamp H1 is to be switched on, if at least one switch, S1 or S2 is actuated.
Fig. B12.7:
Description methods
Function table
S1 S2 H1
Fig. B12.8:
Declaration of variables
VAR
S1 AT %I2.5: BOOL;
S2 AT %I2.6: BOOL;
H1 AT %Q1.4: BOOL;
END_VAR
Boolean equation
H1 = S1
<
Example
S2
Chapter 12
a) LD
Fig. B12.9:
OR operation
b) FBD
S1
H1
>=1
S1
H1
S2
S2
c) IL
d) ST
LD
OR
ST
S1
S2
H1
H1
:=
S1 OR S2;
Example
Function table
Boolean equation
S1 S2 S3 H1
H1 = (S1 S2 S3)
(S1 S2 S3)
(S1 S2 S3)
Fig. B12.10:
Description methods
Chapter 12
Fig. B12.11:
Declaration of variables
Fig. B12.12:
Combination of
VAR
S1
S2
S3
H1
END_VAR
AT
AT
AT
AT
%I2.5: BOOL;
%I2.6: BOOL;
%I2.7: BOOL;
%Q1.4: BOOL;
a) LD
b) FBD
S1
S2
S3
S2
S3
H1
S1
S2
S3
/
S1
/
S1
S2
LD (
AND
ANDN
)
OR (
ANDN
AND
)
OR (
AND
ANDN
)
ST
>=1
S2
H1
S3
S1
S2
S3
c) IL
&
&
d) ST
S3
S2
S1
S1
S2
S3
S1
S2
S3
H1
H1
Chapter 12
SR
BOOL
S1
BOOL
Q1
BOOL
Chapter 12
Function block RS
Fig. B12.14:
Function block RS,
primarily resetting
RS
BOOL
BOOL
R1
Q1
BOOL
Fig. B12.15:
Declaration of variables
:
:
:
:
BOOL;
BOOL;
BOOL;
RS;
(*
(*
(*
(*
(*
*)
*)
*)
*)
*)
END_VAR
In the languages FBD and ST, memory operations are realised by invoking a copy of the RS function block. The copy in this example has the
name RS_H1. The invocation in FBD is effected by means of graphically
linking the current transfer parameters with the inputs of the function
block copy. Since the value of the function block copy is relevant, the
output of the function block copy is connected correspondingly.
Chapter 12
a) LD
Fig. B12.16:
Use of function blocks RS
b) FBD
B1
S1
H1
RS_H1
RS
H1
S1
R1
c) IL
LD
S
LD
R
d) ST
B1
H1
S1
H1
or
CAL
LD
ST
In the textual language ST, the invocation is effected by means of specifying the function block copy. The current parameters are also listed
simultaneously. The value of the output of the function block copy
RS_H1 can be accessed via the variable RS_H1.Q1; the name of the
output variable is therefore defined via the names of the function block
copy and the names of the desired output.
The languages LD and IL have their own operations for stored setting or
resetting of variables, whereby the use of an RS function block can be
omitted. It should be noted that the sequence of set and reset commands is crucial for the behaviour of the PLC. The command, which is to
be dominant in this instance the reset command must only occur
after the set command in the program, so that it is the last command to
be executed and thereby determines the behaviour in this case the
output.
Chapter 12
To elucidate this, imagine the switches (push buttons) of a lighting system, where the edge evaluation is mechanically implemented. By actuating the push button, the light comes on (irrespective of how long this
push button is pressed). If the push button has been released in the
meantime, the light may be switched of by pressing the push button
again.
In exactly the same way, the moment in which the input signal changes
from 0 to 1 must be registered in a PLC, since only ever one single reaction per push button actuation may be triggered (196 irrespective of how
long the 1-signal applies. This prevents a process from being put in motion repeatedly by the controller, should a push button be actuated for
too long. The edges of the input signal are evaluated for each program.
In this context it is referred to as edge detection. Each binary signal has
a rising and a falling edge:
Fig. B12.17:
Rising and falling edge
rising
edge
rising
edge
1
0
falling
edge
falling
edge
Rising edges
mark the instants, in which a signal level changes from 0 to 1.
Falling edges
mark the exact instants, when a signal level changes from 1 to 0.
Chapter 12
Whether rising or falling edges are evaluated within a program or function block depends on how the respective sensor is wired (normally
closed/normally open contact) and how it is used.
A push button (normally open contact), for instance, creates a rising
edge the moment it is pressed and a falling edge the moment it is released.
EN 61131-3 (IEC 61131-3) provides two standard function blocks for the
evaluation of edges
Function block R_TRIG, rising edge
The standard function block R_TRIG (rising) is used for the detection of
rising or positive edges. Its output Q has the value 1 from one execution
of the function block to the next, if its input CLK (Clock for pulse)
changes from 0 to 1.
Fig. B12.18:
Function block R_TRIG,
rising edge
R_TRIG
BOOL
CLK
BOOL
F_TRIG
BOOL
CLK
BOOL
Chapter 12
Example
Fig. B12.20:
Declaration of variables
(*
(*
(*
: RS;
(*
(*
: R_TRIG; (*
(*
(*
RS_1Y1
R_TRIG_S1
END_VAR
Fig. B12.21:
a) LD
R_TRIG
S1
1Y1
1Y1
S1
1Y1
1Y1
b) FBD
RS_1Y1
R_TRIG_S1
1Y1
&
R_TRIG
S1
CLK
RS
S
R1
&
1Y1
c) IL
CAL
LD
ANDN
S
LD
AND
R
d) ST
R_TRIG_S1 (CLK := S1);
RS_1Y1 (S := R_TRIG_S1.Q & NOT 1Y1,
R1 := R_TRIG_S1.Q & 1Y1);
1Y1 := RS_1Y1.Q1;
Q1
1Y1
*)
*)
*)
*)
*)
*)
*)
Chapter 12
Chapter 12
Chapter 13
Timers
13.1 Introduction
Many control tasks require the programming of time. For example, cylinder 2A1 is to extend, if cylinder 1A1 is retracted but only after a delay
of 5 seconds. This is known as a switch-on signal delay. Switch-on signal delays during the switching on of power sections is often also required for reasons of safety.
The timers of a PLC are realised in the form of software modules and
are based on the generation of digital timing. The counted clock pulses
are derived from the quartz generator of the microprocessor. The desired time duration is set in the control program.
EN 61131-3 (IEC 61131-3) defines three types of timer function blocks:
TP Pulse timing
Day
Hour
Minute
Second
ms
Millisecond
T#2h15m
T#20s
T#10M25S
t#3h_40m_20s
Chapter 13
Fig. B13.2:
Timing diagram of
pulse timer TP
TP
BOOL
IN
BOOL
TIME
PT
ET
TIME
IN
PT
ET
0
Pressing of the start button S2 is to cause the piston of a cylinder to advance. This mechanism is to be used to clamp workpieces. When the
piston has advanced fully, it is to remain in this position for 20 seconds.
The cylinder then returns to its initial position
Chapter 13
VAR
S2 AT %IX1
1B1 AT %IX2
1B2 AT %IX3
1Y1 AT %QX1
SR_1Y1
:
:
:
:
:
BOOL;
BOOL;
BOOL;
BOOL;
SR;
TP_1Y1
: TP;
(*
(*
(*
(*
(*
(*
(*
(*
Start button
Cylinder retracted
Cylinder advanced
Cylinder advance
Flipflop named SR_1Y1
for status of 1Y1
TP function block
named TP_1Y1
*)
*)
*)
*)
*)
*)
*)
*)
Fig. B13.3:
Declaration of variables
END_VAR
Fig. B13.4:
Use of pulse timer in FBD
S2
&
SR_1Y1
1B1
SR
S1
TP_1Y1
Q1
1Y1
TP
1B2
IN
T#20s
PT
ET
&
1B2
The control task has been programmed in the language FBD as an example. A timer function block may of course be used in any of the other
languages. An example using a switch-off delay is given in chapter 13.4
to demonstrate this for the languages FBD, LD, IL and ST.
The valve 1Y1 for the actuation of the cylinder is switched via an SR flipflop SR_1Y1. The set condition for SR_1Y1 is met, if the start button for
the retracted cylinder is actuated. As soon as the cylinder has advanced,
the pulse timer TP_1Y1 with the time of 20 seconds is started by the
rising edge of sensor 1B2. Output Q of TP_1Y1 now assumes a 1signal. When the pulse timer has expired the 20 seconds have passed
0 applies at output Q of TP_1Y1. The reset condition for SR_1Y1 is
fulfilled: the cylinder retracts again.
Formulations such as "pulse timer" with the name TP_1Y1" mean:
TP_1Y1 is a copy of function block type TP, in this case a copy of the
pulse timer.
Chapter 13
Fig. B13.6:
Timing diagram of
Switch-on signal delay TON
TON
BOOL
IN
BOOL
TIME
PT
ET
TIME
IN
PT
ET
0
Example
Cylinder 1A1 extends, if start button S1 is actuated. Once this has been
extended for 2 seconds, a second cylinder 2A1 moves to its forward end
position. Sensors 1B1 and 1B2 indicate the retracted and the forward
end positions of cylinder 1A1.
Chapter 13
VAR
S1 AT %IX1
1B1 AT %IX2
1B2 AT %IX3
1Y1 AT %QX1
2Y1 AT %QX2
RS_1Y1
TON_2Y1
:
:
:
:
:
:
:
BOOL;
BOOL;
BOOL;
BOOL;
BOOL;
RS;
TON;
(*
(*
(*
(*
(*
(*
(*
(*
Start button
Cylinder 1A1 retracted
Cylinder 1A1 advanced
Cylinder 1A1 advance
Cylinder 2A1 advance
Flip-flop named RS_1Y1 for 1Y1
Switch-on signal delay named
TON_2Y1 for 2Y1
*)
*)
*)
*)
*)
*)
*)
*)
Fig. B13.7:
Declaration of variables
END_VAR
Fig. B13.8:
Use of Switch-on
signal delay in FBD
RS_1Y1
RS
&
S1
1B1
Q1
1Y1
R1
TON_2Y1
TON
1B2
IN
T#2s
PT
ET
2Y1
Cylinder 1A1 is controlled via valve 1Y1. As soon as cylinder 1A1 has
extended and sensor 1B2 has a 1-signal, the switch-on signal delay
TON_2Y1 is started. On expiry of 2 seconds, a 1-signal is applied at
output Q of TON_2Y1, and cylinder 2A1 extends. Cylinder 2A1 remains
extended so long as the 1-signal is applied at input IN of TON_2Y1, i. e.
so long as cylinder 1A1 remains extended.
As illustrated by this example, not all inputs and outputs of a function
block need be connected or supplied.
If an input of a function block is not connected in this case the R1 input
of RS_1Y1 the value of the input from the previous invocation is used.
In this case, the initialisation value of the variable R1, which represents a
boolean variable, is therefore preallocated with the value 0, i.e. function
block RS_1Y1 operates with the value 0 for parameter R1 during its invocation.
Chapter 13
Fig. B13.10:
Timing diagram of
Switch-off signal delay TOF
TOF
IN
PT
ET
0
BOOL
IN
BOOL
TIME
PT
ET
TIME
Chapter 13
Switch
Cylinder advance
Switch-off signal delay named
TOF_1Y1 for 1Y1
a) LD
TOF_1Y1
TOF
IN
PT
ET
TOF_1Y1
1Y1
TOF
S1
IN
T#30s
PT
ET
1Y1
c) IL
CAL
LD
ST
Fig. B13.11:
Declaration of variables
Fig. B13.12:
Use of switch-off signal
delay in FBD
b) FBD
S1
T#30s
*)
*)
*)
*)
Example
d) ST
TOF_1Y1 (IN :=S1, PT := T#30s);
1Y1 := TOF_1Y1.Q;
In all the languages, a copy of the TOF function block TOF_1Y1 is invoked to realise the switch-off signal delay of the stamping cylinder.
Chapter 13
Chapter 14
Counter
14.1 Counter functions
Counters are used to detect piece numbers and events. Controllers frequently need to operate with counters in practice. A counter is for instance required, if exactly 10 identical parts are to be conveyed to an
conveyor belt via a sorting device.
EN 61131-3 (IEC 61131-3) differentiates between three different counter
modules:
These standard function modules are used to detect standard, non timecritical counting.
With many control tasks it is however necessary to use so-called highspeed counters. "High-speed" in this case generally refers to a counter
frequency in excess of 50 Hz, i. e. more than 50 events are counted per
second. Tasks of this type cannot be solved with the standard counter
function modules of a PLC.
The limitations of counter frequency in counter function blocks are due to
the output signal delays. Each input signal i.e. also the counter signal
is delayed by a certain time, before it is released for processing in the
PLC. This prevents interference. A further limitation is the cycle time of
the PLC.
This is why additional counter modules are generally available for PLCs
for high-speed counting. High-speed counters are for instance used for
the positioning of workpieces.
14.2 Incremental counter
The Incremental counter is known as a CTU (count up). The counter is
set at the initial value 0 by a signal at reset input R.
Chapter 14
Fig. B14.1:
Function block CTU,
Incremental counter
CTU
BOOL
CU
BOOL
INT
PV
Q
CV
BOOL
INT
Fig. B14.2:
Declaration of variables
: BOOL; (*
: BOOL; (*
(*
1B1 AT %IX3 : BOOL; (*
1B2 AT %IX4 : BOOL; (*
1Y1 AT %QX1 : BOOL; (*
1Y1_advance
AT %MX1
: BOOL; (*
CTU_1Y1_M
AT %MX2
: BOOL; (*
RS_1Y1
: RS;
(*
CTU_1Y1
: CTU; (*
(*
END_VAR
*)
*)
*)
*)
*)
*)
*)
*)
*)
*)
*)
Chapter 14
S1
a) LD
1B1 CTU_1Y1.Q
Fig. B14.3:
Use of
incremental counter
1Y1
1B2
1Y1
R
CTU_1Y1
1B2
CTU_1Y1_M
CTU
CU
S2
R
15
PV
CV
RS_1Y1
b) FBD
S1
&
RS
1B1
CTU_1Y1.Q
1B2
Q1
1Y1
R1
CTU_1Y1
CTU
1B2
CU
S2
15
PV
Q
CV
c) IL
LD
AND
ANDN
ST
CAL
LD
ST
CAL
d) ST
S1
1B1
CTU_1Y1.Q
1Y1_advance
RS_1Y1 (S := 1Y1_advance, R1 :=
1B2) RS_1Y1.Q1
1Y1
CTU_1Y1 (CU := 1B2, R := S2, PV := 15)
Chapter 14
Chapter 14
CTD
BOOL
CD
BOOL
LD
INT
PV
Q
CV
BOOL
INT
*)
*)
*)
*)
*)
*)
*)
*)
*)
*)
Example
Fig. B14.5:
Declaration of variables
Chapter 14
Fig. B14.6:
Use of decremental
counter in FBD language
RS_1Y1
S1
&
RS
1B1
CTD_1Y1.Q
Q1
1Y1
R1
1B2
CTD_1Y1
CTD
1B2
CD
S2
LD
10
PV
H1
CV
The valve 1Y1 is switched via an RS function block named RS_1Y1. The
set condition is met, when the cylinder is retracted, the counter has not
yet expired and push button S1 is actuated. When the cylinder has extended completely, 0 applies again at output Q1 of RS_1Y1.
The cylinder strokes are detected via a decremental counter named
CTD_1Y1. If the cylinder is in the initial position and none of the push
buttons are actuated, the following values are applied at the inputs and
outputs at the start of the decremental counter processing: the CD and
the LD input have a 0-signal, the value 10 applies at input PV; the current counter value CV is 0, condition CV <= 0 is thus met and a 1-signal
applies at output Q. The value 1 at output Q designates the decremental
counter as expired. Lamp H1 is illuminated at the same time.
The preselect value 10 is not loaded as a current counter value until
push button S2 is pressed. CV is now greater than 0, output Q is also O
and the lamp is off. Cylinder movements may now be triggered by actuating push button S1. Each movement results in a counting pulse
through the rising edge of 1B2, which reduces the current counter status
by 1 each time. After 10 completed cylinder strokes the current counter
reading is 0; the counter has expired. This is signalled by the value 1 at
output Q.
Once the counter has been loaded with the start value 10, the counter
operations may be repeated.
Chapter 14
CTUD
BOOL
CU
QU
BOOL
BOOL
CD
QD
BOOL
BOOL
BOOL
LD
INT
PV
CV
INT
Fig. B14.7:
Function block CTUD,
Incremental/
decremental counter
Chapter 14
Chapter 15
the program is divided into steps and therefore more clearly arranged
and easier to maintain and expand
error detection in a process-related, graphically represented sequence control is more convenient and conclusive than that possible
with logic control systems.
Chapter 15
A function chart is therefore divided into two parts (fig. B15.1). The sequence part represents the time-related execution of the process.
The sequence part does not describe the actions to be executed individually. These are contained in the action part of the function chart
which, for the example in question, consists of blocks on the righthand
side of the steps.
Fig. B15.1:
Function chart for a
test process
Initial position
Timer expired
2
Lifting cylinder up
3
Defining thickness t = 1s
Timer expired
4
Chapter 15
Initial step
Fig. B15.2:
Elements of function chart
1
directed connections
Transition
Step
Action
Transitions
A transition is a link from one step to the next. The logic transition condition associated with the transition is represented next to the horizontal
line across the transition. If the condition is met, the transition to the next
step takes place and this is then processed by the controller.
Chapter 15
Sequence structures
Three basic forms of sequence structure may be created by means of
combining the step and transition elements:
Linear sequence
2
d
5
e
4
f
6
i
Chapter 15
Fig. B15.4:
Parallel branch
2
d
3
5
e
6
g
7
Table B15.1 contains the symbols defined in IEC 60848 used to describe the order of execution of the actions.
Fig. B15.5:
Action
Chapter 15
Table B15.1:
Mode of actions
stored
non-stored
delayed
enabling
limited
pulse
conditional
DCSF
conditionally stored action after delay, subject to an additional enabling
condition after storage.
Step refinement
As shown in fig. B15.6, each step may itself contain sequence structures. This facility is supported by the step-by-step refinement of a solution in the sense of a top-down design.
Fig. B15.6:
Step refinement
2.1
Filling magazine
Start
2
2.2
Part ejected
Release part
2.3
S
S
Grip part
Gripper to position 2
2.4
S
S
Part released
Ejecting cylinder in
Part released
2.5
Gripper in position 1
Chapter 16
Optimisation of software
Chapter 16
Following this, the program is transferred to the central control unit of the
PLC. A small number of PLCs now offer a facility for simulation: The
entire program is executed without the inputs and outputs being connected. Similarly, only the connection of the outputs may be omitted.
Processing of the PLC outputs thus only takes place in the image table,
in that the image table is not switched through to the physically available
outputs. This therefore eliminates the risk of damaging machines or system parts, which is of particular importance in the case of dangerous or
critical processes.
After this, the individual program parts and system functions are tested:
Manual operation, setting, individual monitoring programs etc., and finally the interaction of the program parts with the help of the overall program.
The system is therefore commissioned step-by-step. Important aspects
of commissioning and error detection are test functions of the programming system such as single-step mode or the setting of stop points. Single-step mode in particular is of importance, whereby the program in the
PLC memory is executed line-by-line or step-by-step. In this way, any
errors which may occur in the program can be immediately localised.
Optimisation of software
Larger programs can almost always be improved after the first test run. It
is important that any corrections or modifications are made not just in the
PLC program, but are also taken into account in the documentation.
Apart from the documentation, the status of the software has to be
saved.
Commissioning of the system
This already occurs in part during the testing and optimisation phase.
Once the final status of PLC program and the documentation is established, all the controller functions (in accordance with the task) need to
be executed step for step again. The system is then ready to be accepted by the customer or the relevant department.
Chapter 16
Chapter 16
Interference suppression
All PLCs are extremely sensitive to voltage supply interference. Differentiation should be made between to different versions:
Interferences reaching the logic voltage from the voltage supply via
the power supply unit;
Interferences, affecting the lines to and from the sensors and actuators.
Chapter 16
Output modules also contain an optocoupler for protection against overvoltages. Moreover, the outputs are short-circuit protected, though normally not against sustained short-circuit.
Mutual induction voltage
When inductive actuators (e.g. safety coils, solenoid coils) are switched,
it creates a mutual induction voltage at the coil.
This mutual induction voltage must be eliminated to protect the output
module. A suppressor diode is used for this. The output modules of a
number of PLCs are already equipped with suppressor diodes of this
type. The residual voltage in this case, however, remains an interference
factor on the interconnecting cables. This is why the protective measures should be taken direct at the point of origin, i.e. on the coil: by
means of a suppressor diode (for DC voltage only) or a varistor (voltage-dependent resistor). Two reverse polarity and Zener diodes
switched parallel to the coil may also be used. With a voltage in excess
of 150 V, however, several breakdown diodes must be switched in series.
EMERGENCY-STOP
If the EMERGENCY-STOP device is actuated, it is essential for a condition to be achieved, which is harmless both for people and system. Final
control elements and drives, which may produce dangerous situations,
must be switched off immediately (e.g. spindle drives). Conversely, final
control elements and drives, which may prove dangerous to people or
the system when switched off, must continue operating even in an
emergency (e.g. clamping devices). The facility to operate an
EMERGENCY-STOP must be available at any given time in a system.
This is why a standard electronic controller may not assume the
EMERGENCY- STOP function. The EMERGENCY-STOP circuit must
be established independently of the PLC by means of contactor technology. EN 418 and EN 954 also specify this, since it would be impossible
to switch an EMERGENCY-STOP with a malfunctioning controller.
Once the EMERGENCY-STOP device has been unlatched, it should be
no longer possible for machinery to operate automatically.
Chapter 16
Example
Chapter 16
Example
Chapter 16
Chapter 17
Communication
17.1 The need for communication
By communication, we understand the transfer of information, i.e. data
between the programmable logic controller and other data processing
devices, whereby these devices are used as an auxiliary means for specific control tasks, e.g. input of data takes place via a computer, output
of data via a printer controlling still remains the task of the PLC.
Automation increases the need for communication. Data needs to be
continually passed on from production to other operational areas. This
provides an overview of the production status and the individual tasks
(production data acquisition).
Automated systems nowadays are equipped with complex error and
fault detection systems. Fault indications and warnings must be generated, centralised and communicated automatically to the operator. To
this end, a printer for logging or an electronic display is connected to
the controller.
In some cases, data is to be transferred to the PLC by a computer in an
active process, or several control devices are combined into one system
network.
17.2 Data transmission
How can the PLC communicate with other data processing devices? The
individual bits, which are combined into one data word, must be transmitted from one piece of data terminal equipment to another.
Basic differentiation is made here between two methods: parallel or serial data transmission.
Parallel data transmission means that a separate line must be available
for each individual binary signal. When signal generators for example,
are connected to a programmable logic controller, a separate wire is
installed for each push button, limit switch, limiting value encoder and
sensor to a terminal strip and from there to the input of the PLC. All information (push button actuated, cylinder advanced) can in this way
be transmitted simultaneously (parallel) to the PLC. Since in the case of
parallel transmission of input and output signals, a line is required for
each signal generator, literally miles of cable bundles are installed overall for correspondingly complex machines.
For the parallel transmission of a data word, sufficient lines must therefore be available to transmit all bits of this data word simultaneously.
Chapter 17
Current interface
Designation
V.24
Centronics
20 mA
Transmission
mode
serial
asynchronus
parallel
serial
asynchronus
Mode of operation
full duplex
simplex
full duplex
Standard
V.24
RS-232-C
Centronics
TTL
TTY
Transmission distance,
transmission speed
up to 30 m
20 000 Bit/s
up to 2 m
10 6 Bit/s
up to 1000 m
20 000 Bit/s
Logic level
Data line
15 V 0 3 V
-3 V 1 -15 V
1 2,4 V
0 -0,8 V
1 = current off
0 = current on
Chapter 17
The most frequently used interface for serial data transmission is the
V.24 interface.
The Centronics and V.24 interface are both voltage interfaces. Bits are
represented for 0 or 1 via a specified voltage level. In order to create
this signal level, a joint ground line must be incorporated for the V.24
interface. In the case of a Centronics interface, each data line has its
own ground line.
In the case of both interfaces, additional lines have been defined for
data flow control apart from the data and ground lines.
Considerably more simple than via a V.24 interface is a connection configured via a serial 20 mA interface. All this current-loop interface needs
is a transmitter and receiver loop for the transmission of data. A constant
current of 20 mA signals the 0level (logic0), "current off" signals the
1level (logic1) on the data line. This interface is widely used in control
technology due to its interference immunity.
17.4 Communication in the field area
A multitude of information has to be transported within automated systems and machines. Simple binary sensor signals, analogue signals of
measuring sensors or proportional valves, and also recorded data and
parameters for the control of processes need to be exchanged reliably
between the control technology components of an automated system.
The data exchange for this must take place within specified reaction
times, since system parts could otherwise continue to operate uncontrolled.
A fieldbus is a serial, digital transmission system for these signals and
data. All stations on a fieldbus must be in a position to receive the communication from other bus stations and to exchange data in accordance
with the agreed protocol. A bus station, taking the initiative for the data
exchange is known as a master. Bus stations receiving or supplying data
purely on the instruction of the master are termed slaves.
Two-wire cables consisting of either twisted pairs or coaxial cables are
used for the transmission of data in bus systems. The extent of wiring for
bus coupled systems is therefore minimal.
Chapter 17
vendor-specific,
Open systems, for instance, are Profibus, Interbus-S, CAN, SINEC L2,
ASI.
The advantages of networking with open bus systems are as follows:
Appendix A
Appendix
Bibliography of illustrations
Fig. B1.2:
Fig. B1.4:
Appendix A
Appendix B
Bibliography of literature
Berger, Hans
Berger, Hans
Berger, Hans
John, Karl-Heinz
Tiegelkamp, Michael
Lewis, Robert
Appendix B
Appendix C
EN 50170
EN 60204
(IEC 60204)
EN 60617
(IEC 60617)
EN 61131
(IEC 61131)
Programmable controllers;
Part 1: general information
Part 2: equipment requirements and tests
Part 3: programming languages
IEC 60848
ISO 1219
Appendix C
Appendix D
Glossary
Access right
EN 61131-3 (IEC 61131-3) specifies for all variables, from which point
and to which extent read or write or changing variable access may occur.
Action
Elements of a step. The action contains the execution parts of a program
in the sequential function chart.
Action block
Collection of action qualifier, action name, feedback variables and action
content.
Action qualifier
Each action has a qualifier, which describes its behaviour in greater detail.
Address bus
Cable bundle of a system, which exclusively transmits address information, e. g. addresses of PLC input or outputs, flags or peripheral devices.
Allocation list, declaration list
The allocation list designates and explains the equipment connected to
a PLC (push buttons, valves, contactors etc.). In the EN 61131-3 (IEC
61131-3), these lists are replaced by the structured declaration of variables. This does not mean that a program system would not be able to
create lists of this type for the documentation of a control program.
Alternative branch
Branch in the execution of a program in sequential function chart into
one of several possible paths. The path taken depends on the transition
conditions of the program runtime.
Bit
Derived from binary digit: bivalent (binary) character, smallest unit of
information.
Appendix D
Bus system
Bus system for the transmission of data between for example, individual
PLC modules.
Byte
A unit of data consisting of 8 bits.
Command, instruction
Instruction to the MPU of a PLC for the execution of a precisely defined
operation. The command consists of an operation part, which contains
the information of what is to be done, and the operand or address part.
This defines, where something is to be done and where information is to
be stored or read.
Control bus
Bus circuit of a bus system, which exclusively transmits control instructions.
Control program
The program of a PLC representing the total of all instructions for signal
processing, as a result of which the equipment to be controlled is influenced. It consists of a sequence of instructions.
Cycle
In a cycle, the status of the inputs is read to the image table at the beginning, the program completely processed once, followed by the mage
table written to the outputs.
Cycle time
The cycle time of the PLC is the time required by the central control unit
to process a program once from beginning to end. This also takes into
account the time required to read and for output of the image table. The
time specification is generally in ms/K code.
Data bus
Bus of a PLC, with which information (signals, data) are transmitted.
Data type
The variables of EN 61131-3 (IEC 61131-3) may be of different types.
Corresponding declarations permit the definition of data types.
Appendix D
Declaration of data
To be able to access data with symbolic names, these must first be
linked in declarations with data types.
EEPROM
Further development of EPROMs. An electrical impulse is used to erase
the contents of a memory, instead of UV light. Subsequently, new information may be written to the memory.
EPROM
Read-only memory, whose content is erased with UV light, and which
can then be written to with new information.
Feedback variable
The feedback variable is programmed by the user and indicates the end
or also an error condition of the action. The feedback variable is frequently used in the subsequent transition condition.
Functions
A function is a program part, which supplies a unique value for the
transmitted input variables. Information cannot be stored intermediately
in a function.
Function blocks
Function blocks are program parts which can be used repeatedly to,
process the input data into output data. They can also be used to store
intermediate results and have one name for each application.
Function block diagram (FBD)
An EN 61131-3 (IEC 61131-3) programming language, which graphically
interconnects the functions and function blocks in order to solve a control task.
Image table
PLC programs as a rule do not operate directly on the inputs and outputs of the PLC, but on an image (copy of the signal values in the internal memory). Inputs are read at the beginning of a cycle and at the end
of the cycle the image of the outputs is physically output to the outputs.
Appendix D
Appendix D
Parallel interface
Interface for bit parallel data transmission. Advantage: High transmission
rates are achieved as a result of the simultaneous transmission of 8 data
bits. Disadvantage: limited line length.
Programming languages
EN 61131-3 (IEC 61131-3) permits the use of different programming
languages, partly even in mixed form, for the programming of a control
program. Function block diagram, the languages ladder diagram, instruction list and structured text are standardised programming languages of this type.
Program organisation units
EN 61131-3 (IEC 61131-3) differentiates between different parts of a
control program and requires structuring into organisation units. These
are programs, function blocks and functions. A higher-level organisation
unit is the configuration.
Read-only memory
Read-only-memory (ROM): Memory, whose content may only be read.
Sequence control system
A control system, which is subdivided into consecutively processed
steps. Only after a step has been executed, is the next one executed.
The step enabling from one step to the next depends on certain conditions, the step enabling conditions.
Sequential function chart
A graphic programming language of EN 61131-3 (IEC 61131-3). Its aim
is to structure the tasks of the control program into steps and transitions.
Serial data transmission
Form of data transmission, whereby data is transmitted consecutively bit
by bit. At least one data line is required for this.
Serial interface
Interface for serial data transmission. Advantage: A serial interface permits data to be transmitted and received simultaneously. Disadvantage:
Low transmission rates.
Appendix D
Step
Steps are the execution parts and at the same time organisation resources of the sequential function chart.
Structured text (ST)
A textual high-level language of EN 61131-3 (IEC 61131-3) for the programming of control programs.
Transition
The element of a sequential function chart, which initiates the evaluation
of a boolean variable or a boolean expression. The result is used to organise the program flow..
Appendix E
Index
A
Accumulator
B-35
Action blocks
B-124
Actions
B-124
Address line
B-34
Addressing
Symbolic
B-61
Alternative branch
Application program memory
EEPROM
EPROM
RAM
Assignments
B
B-117
B-39
B-40
B-40
B-39
B-102
B-19
B-20
B-23
B-19
B-22
B-19
BCD-Code
B-13
Boolean algebra
rules
B-19
B-19
Boolean equation
B-19
Branch
alternative
parallel
B-117
B-119
Bus systems
B-185
Appendix E
CASE statement
B-105
B-43
Command
B-35
Commissioning
B-175
Communication
in the field area
B-183
B-185
Connection
fail-safe
B-180
Control line
B-34
Control unit
B-36
Control voltage
B-177
Counters
decremental
incremental
incremental/decremental
B-165
B-161
B-167
Counter functions
B-161
Data line
B-184
Data transmission
parallel
seriel
B-183
B-183
B-184
Data types
B-60, B-64
Decremental counter
B-165
Delay
switch-off signal
switch-on signal
B-158
B-156
Diagnostic tool
B-45
Documentation
B-50
Appendix E
Edge
B-148
Edge evaluation
B-148
EEPROM
EMERGENGY-STOP
EPROM
EXIT statement
Expression
F
Fail-safe connection
FBD
B-179
B-40
B-109
B-99
B-180
see function block diagram
Fieldbus
B-185
Firmware
B-33
FOR loop
B-106
B-40
Hardware
B-85
B-85
B-149
B-149
B-146
B-145
B-77
B-80
B-82
B-169
B-28
B-33
Appendix E
IF statement
IL
B-104
see Instruction list
Incremental counter
B-161
Incremental/decremental counter
B-167
Initialisation
B-69
Input module
B-41
B-42
Instruction list
B-95
Instruction register
B-35
Instructions
B-95
Interfaces
B-184
Interference suppression
B-178
Iteration statements
FOR loop
REPEAT loop
WHILE loop
B-106
B-106
B-107
B-108
Karnaugh-Veitch diagram
B-30
Label
B-95
Ladder diagram
Elements of
B-89
B-89
LD
B-147
Logic voltage
B-177
Microcomputer
Multitasking
Mutual induction voltage
B-34
B-4
B-179
Appendix E
Network
B-86
von-Neumann principle
B-36
Number systems
binary
decimal
hexadecimal
B-11
B-11
B-13
Operand
B-99
B-175
Operator
B-99
Optocoupler
B-41
Output module
permissible power
B-43
B-44
Overlead protection
B-44
Parallel Branch
B-119
B-183
Personal computer
Phase model
B-45
see PLC software generation
PLC
Areas of application of
Basic design
B-2
B-5
PLC program
cycle time
cyclical processing
B-38
B-38
B-47
Power amplification
B-44
Precedence
Priority
B-100
B-99, B-118
Process image
B-38
Program counter
B-36
B-70
Programming device
B-45
Programming languages
B-54
Programs
B-83
Appendix E
Pulse timer
Timing diagram
R
RAM
B-39
Real numbers
B-14
Relays
B-44
REPEAT loop
B-154
B-154
B-107
Representation of data
numerical data
strings
time data
B-61
B-62
B-63
B-62
Resources of a PLC
Designation
B-60
Rung
B-93
Screening
of input signals
B-42
Selection statements
CASE
IF
B-103
B-105
B-104
B-169
B-111
B-184
SFC
Short-circuit protection
B-44
Signals
binary
digital
generation of binary and digital
voltage range
B-15
B-16
B-15
B-15
Signal detection
B-41
Software
B-33
ST
Standard form
conjunctive
disjunctive
Appendix E
Standards
IEC 61131
B-8
Statement list
B-49
Steps
Structured text
B-99
Structuring resources
at configuration level
at program level
B-50
B-52
B-51
B-158
B-158
B-156
B-156
Switching functions
simplification of
B-25
Symbolic addressing
B-61
Timer
Transition
Transition condition
B-153
B-115, B-120
B-121
Truth table
B-19, B-26
Value table
Variable declaration
B-65
Variables
directly addressed
B-60
B-60
Voltage adjustment
B-113, B-116
B-41, B-43
Voltage supply
B-177
WHILE loop
B-108
Appendix E