genmed-DDS - Drive PLC Developer Studio IEC61131 3 Programming - v2 0 - EN
genmed-DDS - Drive PLC Developer Studio IEC61131 3 Programming - v2 0 - EN
L
Manual
Global Drive
PLC Developer Studio
Global Drive
Drive PLC Developer Studio
Introduction to
IEC 61131-3 programming
Show/Hide Bookmarks
Important note:
The software is supplied to the user as described in this document. Any risks resulting from its quality or use remain the responsibility
of the user. The user must provide all safety measures protecting against possible maloperation.
We do not take any liability for direct or indirect damage, e.g. profit loss, order loss or any loss regarding business.
All information given in this online documentation has been carefully selected and tested for compliance with the hardware and software
described. Nevertheless, discrepancies cannot be ruled out. We do not accept any responsibility or liability for any damage that may
occur. Required corrections will be included in updates of this documentation.
All product names mentioned in this documentation are trademarks of the corresponding owners.
Version 2.0 09/2003
Show/Hide Bookmarks
5 Programming languages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
5.1 Instruction List (IL) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
5.2 Structured Text (ST) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
5.3 Sequential Function Chart (SFC) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
5.4 Function Block Diagram (FBD) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
5.5 Ladder Diagram (LD) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
6 Appendix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
6.1 IEC keywords . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
6.2 Conventions for Lenze variable identifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
6.2.1 System block designation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
6.2.2 Indication of the variable type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
6.2.3 Indication of the data type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
6.2.4 Identifier . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
6.2.5 Indication of the signal type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
6.2.6 Examples of variable identifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
6.3 Glossary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
l DDS-IEC61131 EN 2.0 1
Show/Hide Bookmarks
The programming languages used in the Drive PLC Developer Studio meet the requirements
of the IEC 61131-3 standard.
In many cases, the Introduction also lists the international terms (in italics in brackets) in addition to
the German terms.
2 DDS-IEC61131 EN 2.0 l
Show/Hide Bookmarks
Configuration
Fig. 1 A configuration with several resources which can contain independent tasks.
2.1.1 Tasks
Tasks can be processed periodically or because of a certain event. They have a priority which
defines the assignment of CPU times within the resource.
There are several task types:
• Cyclic tasks
• Time-controlled tasks (INTERVAL tasks)
• Event-controlled tasks (EVENT tasks)
• Interrupt tasks
A task declaration consists of the task name, its priority, and a condition on which the task is to be
executed.
The condition can be a time interval, an event (rising signal at a digital input or FALSE/TRUE transition
of a global variable) or an interrupt.
Every task can be assigned to several programs which are to be activated by the task. The programs
are processed in the sequence indicated.
The following rules apply to the execution of a task:
• The task with the condition that has been met will be executed when, for instance, the interval
time indicated is over or the variable addressed changes from FALSE to TRUE.
l DDS-IEC61131 EN 2.0 3
Show/Hide Bookmarks
• If several tasks fulfill the condition, the task with the highest priority will be executed.
• It is not possible to assign the same priority to several tasks.
(Exception: Priority 0 = Task inhibited)
• If a task with a higher priority meets the condition while another task is being processed, the
task with the lower prority will be interrupted and only be processed after the other task has
been completed.
Task
Fig. 2 Structuring of program organization units (POUs) in programs, function blocks and functions
2.2.1 Programs
The run-time features of the entire program, which can run in a CPU, are determined by the
assignment of programs to a task. A program can be assiged to several tasks, i.e. several instances
of the program are generated with different run-time features. One of the programs is the main
program and is assigend to the PLC periphery, global variables and access paths.
4 DDS-IEC61131 EN 2.0 l
Show/Hide Bookmarks
l DDS-IEC61131 EN 2.0 5
Show/Hide Bookmarks
2.2.3 Functions
Unlike FBs, functions cannot buffer their internal values. Thus, they cannot use global variables,
access function blocks and declare directly addressable variables. All functions have in common
that they return the same output parameters if the input parameters are the same.
6 DDS-IEC61131 EN 2.0 l
Show/Hide Bookmarks
Cold start
With cold starts, the program is loaded again. All variables are reset to their initial value. They either
use a standard initial value (e.g. 0 or FALSE) or the initial value indicated in the variable declaration
(optionally). All tasks of the resource are started.
Warm start
With warm starts (restarts), variables are not set to their inital value but continue with the value saved
before the interruption.
l DDS-IEC61131 EN 2.0 7
Show/Hide Bookmarks
8 DDS-IEC61131 EN 2.0 l
Show/Hide Bookmarks
4.1 Identifiers
Identifiers are used to address variables, functions, programs, etc. They are elements and can
support the readability of programs.
• Identifiers are a sequence of letters, digits and underscores starting with a letter or an
underscore.
Identifiers must not
• include spaces and umlaute.
• be declared twice in the same way.
• be identical with keywords.(^Chapter 4.2)
Tip!
The conventions used for the variable identifiers of Lenze system blocks, function blocks and
functions are described in the appendix. (^ 20)
4.2 Keywords
Keywords are unambiguous character combinations which are used as individual syntax elements.
• Keywords must not be used as identifiers.
Examples of keywords to IEC 61131-3
ABS, SIN, BOOL, FALSE, TRUE, FOR, NEXT, IF, THEN, VAR, GLOBAL, DATE, TIME, FUNCTION
4.3 Comments
Comments or program parts help to understand the program and are important communication
means. Comments are allowed in all text editors at any place and must start and end with a special
character sequence (* and *). Every network can be commmented to document its functionality.
4.4 Literals
IEC 61131-3 describes literals as a sequence of characters, digits or times.
Character sequences
Character sequence literals have 0 or more characters and start and end with inverted commas (e.g.
’Character sequence’).
Digits
There are two different numerical literals: integers and reals.
l DDS-IEC61131 EN 2.0 9
Show/Hide Bookmarks
Integers can be defined with a basis, decimal numbers can also have a sign (+ or -). Reals can also
be indicated with exponents.
Identification Example
Integers
decimal 10
binary 2# 2#1010
octal 8# 8#12
hexadecimal 16# 16#A
Reals
without exponent -12.50
with exponent E 15.7E4
Times
There are two different time literals: Duration and time of day/date.
Identification Example
Duration T# or TIME# T#10ms
Time of day/date
Date D# or #DATE D#1999-08-29
Time of day TOD# or #TIME_OF_DAY TOD#15:36:30
Date and time of day DT# or #DATE_AND_TIME DT#1999-08-29-15:36:30
10 DDS-IEC61131 EN 2.0 l
Show/Hide Bookmarks
4.6 Variables
IEC 61131-3 defines five different variable classes:
• Global variables
• Local variables
• Input variables
• Output variables
• Input and output variables
Local variables do not have a connection to the outside, i.e. they can only be addressed from within
a program part; global variables can be addressed from all POUs.
Input, output and input/output variables are related to a program, function or function block. They
can be changed by reading and writing within the assigned POU; outside the POU, the change must
be defined (input, output and input/output).
The variables are declared between the keywords VAR and END_VAR in the source text. In general,
every variable is initialized after a cold restart. The default value is usually 0 or FALSE. A user-specific
initialization with another value is possible with the sign ”:=” in the declaration.
Variable attributes
The following attributes can be used additionally when declaring a variable:
• RETAIN: These variables remain the same even after a power failure. The program continues
with the values saved when being restarted.
• CONSTANT: Variable values cannot be changed.
• AT: Variables have a fixed location in the memory map (fixed address).
l DDS-IEC61131 EN 2.0 11
Show/Hide Bookmarks
5 Programming languages
IEC 61131-3 defines the following five programming languages:
• IL: Instruction List (Instruction List, IL)
• ST: Structured Text (Structured Text)
• SFC: Sequential Function Chart (Sequential Function Chart, SFC)
• FBD: Function Block Diagram (Function Block Diagram, FBD)
• LD: Ladder Diagram (Ladder Diagram, LD)
Each of these languages is used for special applications which are particularly suited to solve certain
problems.
Example:
LD 17
ST lint (* Comment*)
GE 5
JMPC next
LD idword
EQ istruct.sdword
STN test
next:
12 DDS-IEC61131 EN 2.0 l
Show/Hide Bookmarks
(Structured Text)
Structured Text consists of instructions which can be executed like in high languages with
conditions (IF..THEN..ELSE) or in loops (WHILE..DO).
Structured Text is an easily readable and understandable programming language that does not only
offer powerful loop programming and the possibility of conditioned commands but also imaging
mathematical functions.
Example:
IF value < 7 THEN
WHILE value < 8 DO
value := value + 1;
END_WHILE;
END_IF;
Instructions (overview)
l DDS-IEC61131 EN 2.0 13
Show/Hide Bookmarks
The graphical representation of transitions and steps reminds of a flow chart, is easily readable and
perfectly suitable for programming higher level status sequences.
Steps
Steps consist of flags and one or several actions or Boolean variables.
• The actions of steps are separated from the steps and can be used repeatedly in an
organization unit.
• Qualifiers activate and deactivate actions and Boolean variables (sometimes with time delay).
• Concurrences are possible because an action can still be active when the next step is already
being processed, e.g. the qualifier S (set).
Actions
Actions can contain instructions in IL or ST, networks in FBD or LD, or a sequential function (SFC).
14 DDS-IEC61131 EN 2.0 l
Show/Hide Bookmarks
Transitions
Transitions are between steps. A step that follows a transition is activated if the transition condition
is TRUE.
The following transition conditions are possible:
• Boolean variable
• Boolean address
• Boolean constant (TRUE)
• A sequence of instructions with a Boolean result in ST syntax ((i<=100) AND b)
• A sequence of instructions programmed in any language
Alternative branches
In SFC, two or more branches can be defined as alternative branches.
• Every alternative branch must start and end with a transition.
• Alternative branches can contain parallel branches and other alternative branches.
• An alternative branch starts with a horizontal line (alternative start) and ends with a horizontal
line (alternative end) or a jump.
• If the step before the alternative start line is active, the first transition of every alternative
branch is evaluated from left to right. The first transition from the left that meets the transition
condition TRUE is opened and all following steps are activated.
Parallel branches
In SFC, two or more branches can be defined as parallel branches.
• Every parallel branch must start and end with a step.
• Parallel branches can contain alternative branches or other parallel branches.
• A parallel branch starts with a double line (parallel start) and ends with a double line (parallel
end) or a jump.
• If the step before the parallel start line is active and the transition condition after this step is
TRUE, then the first steps of all parallel branches are activated. These branches are
processed in parallel.
• The steps after the parallel end line are activated if all steps before are active and the
transition condition of this step is TRUE.
Jumps
A jump is a connection with the step whose name is indicated under the jump symbol.
Jumps are necessary because it is not allowed to create upwards or crossing connections.
l DDS-IEC61131 EN 2.0 15
Show/Hide Bookmarks
16 DDS-IEC61131 EN 2.0 l
Show/Hide Bookmarks
Contacts
If a Boolean variable of a contact has the value TRUE, the status ”ON” is transmitted via the
connection line from left to right. Otherwise, the right connection is set to ”OFF”.
• Contacts can be switched in parallel. For this, one of the parallel branches must transmit the
value ”ON”.
• Contacts can also be switched in series. For this, all contacts must transmit the status ”ON”.
• Contacts can also be negated (indicated by a slash in the contact symbol). The contact
transmits the input status if its status is ”OFF” (FALSE) ist.
Coils
In LD, an unlimited number of coils is available on the right side of a network (indicated by brackets).
• A coil transmits the connection value from left to right and copies the value to the
corresponding Boolean variable.
• The start line can be set to ”ON” or ”OFF” (depending on the Boolean values TRUE or FALSE).
• Coils can only be connected in parallel.
• Coils can also be negated (indicated by a slash in the contact symbol). They then copy the
negated value to the corresponding Boolean variable.
Function blocks in LD
In addition to contacts and coils, it is also possible to enter function blocks and programs in LD.
Function blocks and programs must have an input and output with Boolean values in the network.
They can be used at the same locations as the contacts, i.e. on the left side of the LD network.
l DDS-IEC61131 EN 2.0 17
Show/Hide Bookmarks
6 Appendix
BOOL BY BYTE
GE GT
N NE NEG NOT
OF ON OR ORN
P PRIORITY PROGRAM PT PV
18 DDS-IEC61131 EN 2.0 L
Show/Hide Bookmarks
Q Q1 QU QD
XOR XORN
L DDS-IEC61131 EN 2.0 19
Show/Hide Bookmarks
Tip!
The conventions used by Lenze are based on the ”Hungarian Notation”. This ensures that the most
significant characteristics of a variable (e.g. the data type) can be instantly recognized from its
identifier.
An identifier consists of
• a system block designation (only for identifiers of system block variables)
• a variable type entry (optional)
• a data type entry
• an identifier (the ”proper” name of the variable)
• a signal type entry (optional)
20 DDS-IEC61131 EN 2.0 L
Show/Hide Bookmarks
If the variable is an array or a pointer, this will be indicated before the data type entry:
Data type entry (optional) Meaning
a Array (combined type), field
p Pointer
L DDS-IEC61131 EN 2.0 21
Show/Hide Bookmarks
6.2.4 Identifier
The identifier is the proper name of a variable and should indicate the application or function of the
variable.
• Identifiers always start with a capital letter.
• If an identifier is assembled from several ”words”, then each ”word” must start with a capital
letter.
• All other letters are written in lower case.
Examples of identifiers:
JogValue
NumberOfValues
CurrentSelectedJogValue
22 DDS-IEC61131 EN 2.0 L
Show/Hide Bookmarks
6.3 Glossary
Sequential Function Chart Sequential Function Chart SFC (Sequential Function Chart - SFC) is a programming language to describe
sequential and parallel control processes with time and event control.
Action Boolean variable or instructions which can be controlled through an action block (in SFC).
Action block Activation description of actions in SFC.
Current event Intermediate result in IL of any data type.
Instruction List Instruction List (Instruction List - IL) is a common programming language for PLC systems similar to
Assembler.
SFC Abbreviation for Sequential Function Chart
IL Abbreviation for Instruction List
Organization unit (Sub-)program unit which is part of a PLC program. Often organization units can be loaded into the PLC
independently of each other. Compare POU.
CPU Central processing unit (Central Processing Unit) of, e.g., a PLC.
Declaration Indication of variables and FB instances in a declaration block by also indicating the identifier, data type
and FB type as well as initial values, ranges and field features.
Declaration block Summary of declarations for a variable type at the beginning of a POU.
Elementary data type A standard data type predefined by IEC 61131-3.
Function extensions A function can have a variable number of inputs.
FB Abbreviation for Function Block (Function Block), often, function blocks are also called ”Function
organization units”.
FB instance See Instance
FB type Name of a function block with request interface.
FBD Function Block Diagram, see Function Block Diagram
Function A POU of type Function
Function organization unit See Function block
Function block A POU of type Function_Block
Function Block Diagram The Function Block Diagram (Function Block Diagram) consists of a list of networks which enable the
user to create graphics that show any program process by means of connection elements.
FBD See Function Block Diagram
IL Instruction List, see Instruction List
Indirect FB call Call of an FB instance whose name has been transferred to a POU as VAR_IN_OUT parameter.
Instance Structured data set of an FB by declaration of a function block plus indication of the FB type.
LD Abbreviation for Ladder Diagram
Configuration The configuration (Configuration) defines the PLC structure and represents the highest level in the
IEC 61131-3 software model.
Ladder Diagram Ladder Diagram (Ladder Diagram - LD) is a programming language to describe networks with
simultaneously operating Boolean and electromechanical elements such as contacts and coils.
LD Ladder Diagram, see Ladder Diagram
POU Abbreviation for Program Organization Unit (Program Organization Unit - POU)
POU Program Organization Unit, see Program Organization Unit
Program Organization Unit The Program Organization Unit is an organization unit in IEC 61131-3 of type function, function block or
program. It builds up user programs hierarchically.
Resource A resource (Resource) is a central unit (CPU) of a configuration.
Step Status node in an SFC program. Actions referring to a step are started here.
SFC Sequential Function Chart, see Sequential Function Chart
PLC Programmable Logic Controller (Programmable Controller).
L DDS-IEC61131 EN 2.0 23
Show/Hide Bookmarks
24 DDS-IEC61131 EN 2.0 L