Professional Documents
Culture Documents
TABLE OF CONTENTS
Chapter 7 Programs using FBD/ST ............................................................................................................................................... 7-1
7.1 General Information ............................................................................................................................................................. 7-3
7.1.1 Description .................................................................................................................................................................... 7-3
7.1.2 Objectives...................................................................................................................................................................... 7-3
7.1.3 Reference Documentation............................................................................................................................................. 7-3
7.1.4 Limits............................................................................................................................................................................. 7-3
7.1.5 Steps to go ..................................................................................................................................................................... 7-4
7.2 Program Handling ................................................................................................................................................................ 7-5
7.2.1 Create Program ............................................................................................................................................................. 7-5
7.2.2 Delete Program ............................................................................................................................................................. 7-5
7.2.3 Copy and Paste Program............................................................................................................................................... 7-6
7.3 The POU Editor.................................................................................................................................................................... 7-9
7.3.1 Functions and Function Blocks .................................................................................................................................. 7-10
7.3.2 Opening the POU Editor............................................................................................................................................. 7-10
7.3.3 Message Pane .............................................................................................................................................................. 7-12
7.3.4 Code Pane.................................................................................................................................................................... 7-12
7.3.5 Checking, Applying and Saving the Program ............................................................................................................ 7-14
7.3.6 Error Messages............................................................................................................................................................ 7-14
7.4 Function Block Diagram (FBD) language ........................................................................................................................ 7-15
7.4.1 General ........................................................................................................................................................................ 7-15
7.4.2 Insert Function/Function Block .................................................................................................................................. 7-17
7.4.3 Connections................................................................................................................................................................. 7-20
7.4.4 Comments.................................................................................................................................................................... 7-22
7.4.5 Structure Pane ............................................................................................................................................................. 7-23
7.4.6 Execution Rules .......................................................................................................................................................... 7-23
7.5 ST Language ...................................................................................................................................................................... 7-25
7.5.1 General ........................................................................................................................................................................ 7-25
7.5.2 Comments and the ABB Extension ............................................................................................................................ 7-26
7.5.3 Instructions.................................................................................................................................................................. 7-26
7.5.4 Using Functions .......................................................................................................................................................... 7-30
7.5.5 Using Function Blocks................................................................................................................................................ 7-30
7.6 Program test........................................................................................................................................................................ 7-32
7.6.1 General Information.................................................................................................................................................... 7-32
7.6.2 Start Test Mode ........................................................................................................................................................... 7-32
7.6.3 Stop Test Mode ........................................................................................................................................................... 7-33
7.6.4 Online Values.............................................................................................................................................................. 7-34
7-1
7-2
7.1.2 Objectives
On completion of this chapter you will be able to:
Declare variables for a program and connect them to function block instances
7.1.4 Limits
7-3
7.1.5 Steps to go
1. Create a new program
2. Open the POU (Program Organization Unit) editor for the program
3. Change the language of the POU editor
4. Create the logic (Functions and Function Blocks)
5. Check the logic
6. Save the logic
7. Test the logic
7-4
Right
click
2. The New Program dialog box is displayed. Type in a new program name and
click OK.
The new program is created in the Programs folder and is also visible in the
Control Structure in PP.
7-5
1. Right mouse click onto a program and left mouse click onto Delete
Right
click
Left
click
7-6
Right
click
Left
click
2. Right mouse click onto Programs folder and left mouse click onto Paste.
The Program Meas_Slow_Cont1_1 is created in the Programs folder with all child
objects.
7-7
7-8
7-9
Do not retain their old values from one scan to the next.
Always give the same value when the input parameters have the same value.
Retain their values, from the last call, when called the second time. Can give
different output values even if the input values are the same.
7-10
Keyboard
hot key
Description
Ctrl + U
Save and Close. Saves the changes and closes the editor.
Ctrl + W
Save. Save the changes but does not close the editor.
Ctrl + B
Ctrl + P
Ctrl + J
Ctrl + Z
Ctrl + Y
Ctrl + X
Ctrl + C
Ctrl + V
Ctrl + F
F3
Ctrl + I
Ctrl + Space
7-11
INS
Ctrl + L
Ctrl + E
Edit Type. Edits a type. The type can be write protected, for
example if it is a system-protected type or an user-protected
type.
Ctrl + M
7.3.3.1 Description
In the description tab, you can write notes in plain ASCII text. The notes are common
to all code blocks and grids. It does not change depending on which tab is activated.
The description is displayed in the lower pane of the tree view control by marking the
edited object (for which a description has been written), e.g. a program in the tree
view control and after that selecting the Description tab.
7.3.3.2 Check
When you are validating code error messages are displayed in this pane. Double-click
an error message to go quickly to the place where the error occurred.
7-12
The order of execution is determined by the order of the tabs for Function Blocks and
Programs. The execution order for Control Modules is set up by the system for the
most effective order as possible. In the figure above the CodeBlock1, CodeBlock2
and CodeBlock3 code blocks are executed in that sequence. The sequence can be
changed using Edit > CodeBlock or right clicking on a code block tab.
7-13
7-14
7-15
7-16
Inspect the Function Block Diagram of the POU you are programming
Assign values to the parameters of function blocks and functions (connect them by
lines)
Menu Command
Insert > Function/Function
Block
Key
Ins
Description
Insert new function or function
block
Use this command to assign
variables and constants to the
selected parameter of a
function block or function.
Ctrl + D
In the dialog window a list of available functions and function block types is presented
in the drop-down list. 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 and function blocks.
If you want to choose from a list of previously used function block types, use the
Local FB Declarations button.
7-17
7.4.2.2.1 Assignments
Function
Move, :=
7-18
Description
Assigns the value (number, logical or string) of the input parameter to the
output parameter.
Description
NOT
AND, &
Boolean AND.
XOR
Boolean XOR.
OR, >=1
Boolean OR.
Description
EXPT, **
MUL, *
Multiplication.
DIV, /
Division.
ADD, +
Addition.
SUB, -
Subtraction.
MOD
Modulus.
ABS
Absolute value.
Description
Less than.
GT, >
Greater than.
LE, <=
GE, >=
EQ =
Equal to.
NE, <>
The checkbox activates the Enable parameter which is optional. This is shown in the
figure.
7-19
7.4.2.3.3 Invert
By clicking with the right mouse button select the parameter (pin). Select the Invert
command to invert the assignment to this parameter (pin). The parameter can also be
inverted in the Connect dialog window. This is shown in the section Connect each
parameter separately.
7.4.3 Connections
In the Function Block Diagram editor, parameters of functions and function blocks are
shown as pins of the (boxes). The assignment of values (variables and constants) to
parameters is indicated by lines connecting to the pins.
If a parameter is to be connected to another parameter, one of them must be an output
parameter and the other one an input parameter. (An output parameter can be assigned
to any number of input parameters but never to another output parameter.)
7-20
1. 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 the Connect command from
the context menu.
2. Fill in the To field with a constant value or a variable name. To display a list of all
available variables, press Ctrl+J. If you want to connect an OUT parameter to
several variables, separate the names with , (comma). For example:
Start1,Start2
Note! Literal values cannot be assigned to parameters of data type Time or String.
After the variable name has been entered, press OK to close the dialog window or
Apply/Next to apply the connection and go the next parameter. The Direction setting
together with the value in the Next: drop-down list determine what will happen when
the Next button is pressed. In the example in the figure pressing Apply/next will move
the selection forward to the next unconnected parameter.
If the user enters a name that is not recognized by the system (i.e. not declared in the
editors declaration pane) and presses OK or Apply/Next, the system will ask the user
if the unknown name should be declared by the system, as shown in the figure.
7-21
Fill in the name of the variable in the Actual Parameter field. Use the button
get a tree-like overview of the POU and its variables.
to
7.4.4 Comments
It is possible to write comments to functions/function blocks and pages.
7-22
The structure pane consists of the following sizable and movable columns:
Item shows the name of the function block or function with their properties in
parentheses
Page Comment shows the comment on the top of the corresponding Function
Block Diagram page
Page Number is given at the first function block or function of every page of the
Function Block Diagram
7-23
represented by the order of the graphic symbols (boxes) in FBD "from the left to the
right" and "from the top to the bottom". 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 .
7-24
7.5 ST Language
7.5.1 General
Structured Text (ST) is a high-level programming language. It is compact, highly
structured and contains a comprehensive range of constructs for assignments,
function/function block calls, expressions, conditional statements, iterations and more.
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. Tabs and spaces are used to structure the code for easy
reading. Below is an example of code written in Structured.
button.
Press < Ctrl J > to insert declared variables in the code pane.
7-25
Description
(**)
(##)
7.5.3 Instructions
The following basic instructions are available in the ST language.
Description
:=
()
7-26
7.5.3.2 Expressions
There are different kinds of expressions. They are expression containing: boolean
operators (and, or, not, xor), arithmetic operators (+, -, *, **, mod), and expression
containing relational operators (=, >=, >, <=, <, <>). An expression always results in a
single value. An expression contains operators, functions and operands. Operators may
be +, -, /. Functions may be for instance sin(x) or cos(x). The operand can be a value, a
variable, a function or another expression.
Description
NOT,
AND
Boolean AND.
&
XOR
Boolean XOR.
OR
Boolean OR.
Description
Exponential, i.e. raising to the power.
Multiplication
Division.
Addition.
Subtraction.
MOD
Modulus.
7-27
Description
<
Less than.
>
Greater than.
<=
>=
Equal to.
<>
7.5.3.3 Statements
7.5.3.3.1 Conditional Statements
Operator
If..then..
end_if;
If..then..
else..
end_if;
If..then..
elsif..
else..
Description
These statements conditionally execute a group of
statements, depending on the value of one or several
Boolean expressions. A conditional statement is
always concluded with end_if;
These statements conditionally execute a group of
statements, depending on the value of one or several
Boolean expressions. A conditional statement is
always concluded with end_if;
These statements conditionally execute a group of
statements, depending on the value of one or several
Boolean expressions. A conditional statement is
always concluded with end_if;
end_if;
case <integer> of
<integer literal> : <statements>
end_case;
case <integer> of
<integer literal> : <statements>
<integer literal> : <statements>
<integer literal> : <statements>
else
<statements>
end_case;
7-28
Description
For
While
Repeat
Exit
7-29
Description
Exit and terminate the execution of the current code. The instruction is
usually found in function blocks and functions. It is not advisable to use the
statement unless you are an advanced user as it can cause problems
when executing together with other function blocks.
Description
()
Parenthesized expression.
Function ()
Not, -
**
*, / ,mod
+, -
Comparison operators
=, <>
and, &
Boolean AND.
xor
Boolean exclusive OR
or
Boolean OR
Priority
Highest
Lowest
7.5.3.5 Simulate
When you simulate code written in the language Structured Text, is it possible to view
the code in Ladder or Function Block Diagram (This works only for code written in
Structured Text). Select (Tools> Setup) in the menu of the code block where the code
is written (You must be in online mode when you do this).
7-30
Click on the Function blocks tab of the Program, Control Module Type or
Function block type.
Write the name of the function block you intend to use in the Function Block
Type field or press < Ctrl J >.
Give the function block instance a suitable name in the Name field.
Call the function block by writing like this in the code block were you intend to
use it: TimerCloseDoor(
A new window like the one below will be visible. Write suitable variables in the
Actual Parameter field.
7-31
7-32
3. If you want to start Test Mode as Cold Restart left mouse click onto the Cold
Restart All button
4. Left mouse click onto the Continue button
7-33
5. Left mouse click onto a Tools in the menu bar and left mouse click onto Stop
Test Mode
7-34
The program is visible on screen and the Function Block GenGenerator_1 offers some
live values
6. For changing the value of the Reset parameter right mouse click onto the false
value of the Reset parameter of the Function Block GenGenerator_1.
7. Select ON from the list.
7-35
7-36