Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Contents
1 Data Types ................................................................................................................................................. 3
1.1 Variable data types ............................................................................................................................ 3
1.1.1 Simple Data Types ..................................................................................................................... 3
1.1.2 Structured Data Types ............................................................................................................... 3
1.1.3 System defined I/O Data Types ................................................................................................. 4
1.2 Global variables ................................................................................................................................. 5
1.3 Local variables ................................................................................................................................... 5
2 Function Block Diagram ............................................................................................................................. 6
2.1 FBD Editor .......................................................................................................................................... 6
2.1.1 Execution Rules ......................................................................................................................... 6
2.1.2 Functions in FBD ........................................................................................................................ 7
2.1.3 FBD Pane ................................................................................................................................... 7
2.1.4 Toolbar Buttons ......................................................................................................................... 8
2.1.5 Inserting a Function / Function Block ........................................................................................ 9
2.1.6 EN Input Parameter ................................................................................................................... 9
2.1.7 Editing Parameter Properties .................................................................................................. 10
2.1.8 Making Connections ................................................................................................................ 10
2.1.9 Inverting Connections ............................................................................................................. 12
2.1.10 Adding Comments ................................................................................................................... 12
2.1.11 Structure Pane ......................................................................................................................... 12
3 Structured Text (ST) ................................................................................................................................. 13
3.1 Structured Text Editor ..................................................................................................................... 13
3.2 Basic Language Elements ................................................................................................................ 13
3.2.1 Assignment Statements ........................................................................................................... 14
3.2.2 Comment Statements ............................................................................................................. 15
3.2.3 Operators ................................................................................................................................ 15
3.2.4 Precedence .............................................................................................................................. 15
1
3.2.5 Conditional Structures ............................................................................................................. 16
3.2.6 Iteration Structures ................................................................................................................. 17
3.2.7 RETURN Statement .................................................................................................................. 17
3.3 Functions and Function Blocks ........................................................................................................ 17
3.3.1 Functions ................................................................................................................................. 17
3.3.2 Function Blocks ........................................................................................................................ 18
3.3.3 How to Declare Function Block Instances ............................................................................... 18
3.3.4 How to Call a Function Block Instance ..................................................................................... 19
3.4 Common Mistakes and their Error Messages ................................................................................. 20
3.4.1 Identifier, constant or opening parenthesis expected ............................................................ 20
3.4.2 Variable name is not unique .................................................................................................... 21
3.4.3 Identifier too long or invalid .................................................................................................... 21
3.4.4 Undefined function block ........................................................................................................ 22
3.4.5 Type mismatch in assignment ................................................................................................. 22
3.4.6 Incompatible types in expression ............................................................................................ 22
4 Sequential Function Charts (SFC) ............................................................................................................ 23
4.1 SFC Editor ........................................................................................................................................ 23
4.2 Steps and Transitions ...................................................................................................................... 23
4.2.1 Steps ........................................................................................................................................ 24
4.2.2 Transition ................................................................................................................................. 24
4.3 Sequence Constructs ....................................................................................................................... 24
4.3.1 Simultaneous Sequences ......................................................................................................... 24
4.3.2 Sequence Selection ................................................................................................................. 25
4.4 Jumps and Destinations ................................................................................................................... 25
5 Control Modules ...................................................................................................................................... 25
5.1 Control Modules as Code Containers .............................................................................................. 26
5.1.1 Code ........................................................................................................................................ 26
5.1.2 Graphics ................................................................................................................................... 26
5.2 Representation of Control Modules ................................................................................................ 26
5.2.1 When to use what? ................................................................................................................. 27
5.3 Control Module Diagram (CMD) Editor ........................................................................................... 27
5.3.1 How to Create a Control Module Instance .............................................................................. 28
5.3.2 Graphical Connections ............................................................................................................. 28
2
1 Data Types
Variables are used to store data inside the controller memory. During execution of the control code the
data may change following changes in the process states or else due to calculations made.
When the application code is written, the programmer must create variables to store the data which is
manipulated by the application code. Variables are the containers for values within the application, its
programs, its function blocks and its control modules.
Modern controllers are capable of handling many different sorts of data. The simplest type is boolean, but
other types are possible such as integer (whole numbers), real (floating point numbers) and string
(character strings such as text messages). Additionally, in System 800xA, many other more complex data
types are possible.
Variables are declared in an application by opening the application editor from the Project Explorer tree:
3
For example, suppose you have a vessel which has the following data associated with it:
• Tank is Full
• The volume of fluid (measured in cubic meters).
• The temperature of the fluid (measured in Kelvin).
• The minimum permitted temperature of the fluid.
• The maximum permitted temperature of the fluid (both measured in Kelvin).
This data could be packed into a data type called say, TankType.
Once the “TankType” data type has been defined, variables of that type may be declared in any application.
Suppose a variable is now declared called Tank1. The individual componets of this variable may be accessed
using “dot notation”: Tank1.Full, Tank1.Volume, Tank1.Temperature, Tank1.MinTemp, Tank1.MaxTemp
DintIO is used to connect to integer channels on, for example, a pulse counter module. DwordIO may be
used to access all 16 channels on a DI or DO module as a word rather than as individual IO points.
1.1.3.1 BoolIO
Use a BoolIO type when you connect to either a digital input or digital output channel. The datatype is
defined by the system and has the following components:
1.1.3.2 RealIO
Use a RealIO type when you connect to an analog input or analog output channel. The Value, IOValue,
Forced and Status components are given by the system to the application. The Inverted, Max, Min, Unit and
Fraction components are given by the user of the application to the system in the “Scaling” tab. The data
type has the following components.
4
Name Data Type Description
Value Bool Value used by the application code
IOValue Bool Value of the I/O channel. IOValue and Value are equal if the channel is not
forced
Forced Bool Indicates whether or not the channel is forced.
Status DInt Status as a integer
Parameters SignalPar Measuring Range
Note that the last component ‘Parameters’ is itself a structured variable of type SignalPar. The data type
SignalPar has the following components:
• Name: every variable must have a unique name. The identifier for a variable, a function block etc.
• Data Type: The data type this variable is. There are several datatypes available
o Basic data types: bool, int, real dword etc
o I/O data types: boolIO, RealIO, DwordIO
o Data types defined by other software libraries. Typically consists of a collection of several other
data types.
• Attributes: The attribute of the variable is defined.
• Initial value: for basic data types an initial value can be given… (Eg: Boolean: ture/false) Defines the
initial value of the data type. If no value is given, the default value is used.
• I/O address Defines the I/O address to the I/O unit.
• Access variables System variables that are to be accessed from a remote system with a loose
connection must be declared in the Access Variable Editor.
• Description: In the description fields a short description can be written when declaring variables,
parameters, function blocks, and data type components.
5
2 Function Block Diagram
It represents the function block and functions by graphical symbols (boxes), their input and output
parameters by pins of the boxes and the assignment of parameters by lines between the pins. A
comprehensive basic range of function blocks and functions are available.
You can change the execution order later by moving the selected function blocks and functions "up" or
"down" within the structure pane. Just drag-and-drop the function block within the structure pane.
6
2.1.2 Functions in FBD
The following basic functions corresponding to operators of textual programming languages are available in
the FBD language:
You can drag the separation line just underneath the variable declaration pane to access the upper sub
pane. The FBD panes contain:
7
• Graphic symbols of function and function block (boxes)
• Instance names of the function blocks
• Comments attached to the function blocks and functions
• Assignment of parameters in form of connection lines between the graphic symbols
• Comment of the page and footer
• Inspect the function block diagram of the POU you are programming
• Select, copy and paste functions and function blocks
• Create, modify and delete function blocks and functions
• Edit instance name of function blocks and edit comments
• Assign values to the parameters of function blocks and functions
8
2.1.5 Inserting a Function / Function Block
There are several ways to insert a function/ function block;
In the dialog window a list of available functions and function block types is presented in the drop-down
list.
NOTE! Just type the first letters of the function name to jump to that entry.
It is also possible to use the Browse button to get an explorer-like overview of all libraries and
applications and their functions / function blocks. If you want to choose from a list of previously used
function block types, use the “Local FB Declarations” button.
Connect Parameters
If it is a function/function block that supports configurable input parameters, these inputs can be specified
in the dialog window. To go straight to the Connection dialog window, check “Connect Parameters”.
The “EN” checkbox makes the optional Enable parameter available (this is explained in the next section).
The EN parameter should be connected to a bool variable just as any other bool parameter.
When the EN input is true, the function or function block will be executed, otherwise not. When the EN
input becomes false, all outputs will keep their values from the previous cycle of execution.
The EN parameter can be turned on/off when inserting a new function or function block (see Insert
Function/Function Block dialog section), or when editing the parameter properties (see below).
Right click on a parameter (pin) of the function block or function. Select “Insert Parameter” to add a new,
last parameter (pin). Select “Delete Parameter” to delete the parameter (pin).
NOTE! An output parameter can be assigned to any number of input parameters but never to another
output parameter.
There are basically two ways of connecting the parameters (pins) of a function or function block: Either you
connect the parameters one-by-one or you connect them all at once.
Right click on the parameter (pin) of the function block or function (box) to which you want to assign a
variable or a constant and select “Connect…”from the context menu.
10
Fill in the “To” field with a constant value or a variable name. To
display a list of all available variables, press Ctrl+J.
<main_identifier>.<component>
To connect two parameters to each other, select one parameter (pin) by clicking on it with the left mouse
button. Press the Ctrl key while clicking with the left mouse button on the other parameter (pin) that you
want to connect to.
NOTE! Be sure that you select one input parameter and one output parameter.
11
Connect to a Previous Selection
To connect a parameter to another parameter, select the first parameter by clicking on it with the left
mouse button. Click on another parameter (pin) that you want to connect to with the right mouse button.
By this, you select the second parameter, though the selection of the first one remains, and you open the
context menu. Select “Connect to Previous Selection” from the context menu to accomplish the
connection.
If you want to add a comment for a page in FBD, just right click and select
“Edit Page Comment…” from the context menu.
12
• Change the pagination and page comments.
• Navigate within the program.
• Change the order of execution in the FBD code pane.
The structure pane consists of the following sizable and movable columns:
• Item shows the type name of the function block or function with their properties in parentheses
• Comment shows the comment attached to the function block or function
• Page Comment shows the comment on the top of the corresponding Function Block Diagram page
• Page No is given at the first function block or function of every page of the Function Block Diagram
• Instance shows the name of function blocks
The code is simple to write and easy to read, because of its logical and structured layout. The compactness
of the language gives an excellent overview of the code and less scrolling in the editor.
The code pane may be divided into several ‘tabs’. Each tab is also referred to as Code Blocks. When the
code is compiled the execution order of the code is firstly in tab order (left to right) and then from top to
bottom inside the tabs.
Instances of variables and function blocks are declared in the declaration pane.
13
The left hand side, before the assignment operator (:=) is called the assigned variable. The right hand side is
an expression which is evaluated to give a value to the assigned variable.
In the above example the expression results in a Boolean – true/false value. (It is a Boolean expression).
The AND and the OR are referred to as operators (In this case Boolean operators).
NOTE! The := symbol is used for the assignment of operators and a statement must be ended with a semi-
colon.
The variable AverageFlow is assigned the value given by the result of the calculation on the right. Flow1 is
firstly added to Flow2 and then the total is divided by 2.
The expression on the right is a Real expression because it results in a Real value (floating point value). The
symbols + and / are called arithmetic operators because they perform arithmetic operations on the variable
values which follow them.
14
3.2.2 Comment Statements
(*…*) Comment according to IEC 1131-3.
This is useful for commenting out large blocks of code containing comments.
3.2.3 Operators
3.2.4 Precedence
The priority of operators decides the order of evaluation of an expression. Below is a summary of available
operators, in descending priority:
15
If you are unsure of the evaluation order then use parenthesis to force evaluation of sub-expressions.
16
3.2.6 Iteration Structures
Several iteration constructs exist: They should be used with extreme caution. During the iteration of the
loop, the CPU remains in the loop. If a loop has a large number of iterations then the normal scan time may
be easily exceeded.
NOTE! Only use these constructs when you know exactly how many iterations are going to be done.
Operator Description
FOR i := 0 to 15 DO The FOR statement is used to allow a statement (or
Statement(s); statements) to be executed repeatedly for a given
END_FOR; number of times. The counter used in the repetition
process can be used in the statements. In the
example, the statements between the FOR and
END_FOR will be executed 16 times.
WHILE Level > 80.0 DO The WHILE statement is used in order to allow a
Statement(s); statement (or statements) to be executed
END_WHILE; repeatedly while a certain condition is True. This
separates it from the FOR statement. It has some
similarities with the REPEAT statement.
REPEAT The REPEAT statement is used in order to allow a
Statement(s); statement (or statements) to be executed
UNTIL Boolean Expression repeatedly until a certain condition is True. Note
END_REPEAT; that the test to exit the loop is placed at the end, so
a minimum of one execution of the statement(s)
will occur even if the expression is true at the time
the loop is entered.
EXIT; Use the EXIT statement whenever you want to
terminate a loop immediately and continue
execution from the first line after the iteration
statement.
Var := FunctionName(Parameter(s))
In the example below the square root of a flow signal is calculated by using the Sqrt() function.
17
3.3.2 Function Blocks
Function block calls do not appear in assignment statements. The call is itself a valid statement. Note that
in ST, function block input parameters are listed with the := symbol and output parameters are listed with
the => symbol. The example below shows the code for calling a delay off timer:
The above timer function block is the same as the following in FBD form:
1. Mark the “Function Blocks” tab in the declarations pane of the POU.
2. Type in an instance name for the function block in the “Name” column.
3. Type in the required function block type in the “Function Block Type” column. Place the cursor in
the field and press ‘Ctrl + J’ to see a list of all available function block types.
18
If the library that contains the function block type that you want has not been connected to the application
then it will not appear in the list.
1. Call the function block instance by typing its instance name in the code pane followed by an
opening parenthesis ‘(‘
The system will then offer a dialogue for you to make connections.
19
2. Fill in the parameters that are to be connected to the function block instance in the parameter
column by any of the following methods:
Type the name of the variable to be connected directly into the “Parameter” field. (After a few
characters the system will try to help you finish by supplying first matching variable name).
3. Use the “Insert from List” method by clicking on the Insert Variable … icon in the menu bar or use
the “Insert Path from Tree” Icon to browse the application for the variable:
4. Click on the “Exit and Close” icon in the dialogue.
5. The result (for this example) looks like:
20
Note also that some other items are classed as ‘variables’ by the system:
This means that within any POU all of the above must have unique names.
1. Variable naming rules have been disobeyed - the name begins with a number.
2. A key word has been used - both words “On” and “Off” are reserved.
21
3.4.4 Undefined function block
The programmer has declared the function block with the name MixTimer but has referenced MuxTimer in
the code.
In this case the programmer has attempted to add a “real” and a “dint” to get a “dint” result. (You can’t
multiply apples with pears!)
22
4 Sequential Function Charts (SFC)
The Sequential Function Chart (SFC) programming language allows the user to describe the sequential
behavior of the control program graphically. This is quoted as the
fifth IEC 61131-3 language but it’s not really a new language just
a specialized editor for coding sequences.
It is not possible to have a sequence without any steps or transitions. The sequence must consist of at least
one step and one transition.
23
4.2.1 Steps
A step is a basic element, which is activated by its preceding transition. The step becomes active until its
succeeding transition is true, and then next step is activated.
Each step has a name, that can be changed, and each step can have up to three associated set of actions. It
is not possible to change the action names.
The step is used to hold instructions which perform actions on the process devices.
NOTE! The instructions must be programmed in the Structured Text language.
• Instructions written in the Entry block (P1 = Pulse rising edge) are executed once and once only on
entry into the step. (During transition from the previous step)
• Instructions written in the Active block (N = Non-stored) are executed on each scan whilst the step
is active.
• Instructions written in the Exit block (P0 = Pulse falling edge) are executed once and once only on
exit from the step. (During transition to the next step).
4.2.2 Transition
The transition from one step to the next holds a Boolean expression. (Note that it is NOT a code block as
such and requires a slightly different syntax).
A Boolean expression is any sequence of terms and operators that results in a single Boolean result – True
or False. The sequence will transit from one step to the next when the transition following the currently
active step goes true.
When the transition Tr7 becomes true, Step S7 is left and each of the
three steps S8, S9 and S10 become active. When a parallel branch is left all preceding steps must be active
AND the following transition must become true. In the above steps S12, S9 and S13 must be active together
with Tr9 being true before the exit from the branch takes place.
24
4.3.2 Sequence Selection
A series of transition conditions are monitored when the prior step is active.
The next step to become active is determined by which transition becomes
true. That branch is selected and the execution continues in that branch.
The execution can only continue in one of the branches. The branch with
the highest priority (graphically, the left to right branch order corresponds
to the priority order) and a true transition condition will be chosen.
5 Control Modules
Control module types and their instances represent an extension to those code containers (POU) described
by IEC 61131-3. You can think of control modules as super function blocks that have the ability to hold code
and also graphics.
The coding techniques and editors are the same as for function block types and programs, with very little
difference, so all the knowledge of programming with traditional programs can be carried forward into the
world of control modules.
However because of the addition of graphics as part of the module, the beginner must learn about a new
graphics editor called the Control Module Diagram Editor (CMD Editor). Just as an FBD editor is used to
build programs with function blocks, so the CMD editor is used to build applications with control modules.
25
5.1 Control Modules as Code Containers
5.1.1 Code
Code is written in a code editor which is
exactly the same as that for programs. This
means that the code inside control modules
may be written in Structured Text, Function
Block, Ladder, Instruction list or Sequential
Flow Chart. Code may be separated into
code blocks (tabs). In this respect there is
nothing new to learn.
5.1.2 Graphics
The graphical part of a control module is written in its own editor called the Control Module Diagram Editor
(CMD Editor)
The graphical part is drawn within the green boundary, using the
tools in the toolbox to the left. The tools available are:
26
Note that types are shown with green icons, whereas instances are shown with blue icons.
Instances of previously defined control module types are placed graphically in the application using the
CMD editor. Open the CMD editor for an application by marking the respective application, and then
clicking right for the context menu.
27
These modules are prepared with nodes and may be connected graphically.
1. Click right in the view and select “Create > Graphical Connection”
2. The cursor will appear.
3. Click once on the node where the connection is to start
4. Move the cursor to the destination node and double click to finish.
28