You are on page 1of 36

Course T300, Engineering an 800xA System

Chapter 7 Programs using FBD/ST

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

Course T300, Engineering an 800xA System

7-2

Engineering an 800xA System

7.1 General Information


7.1.1 Description
Program contains a declaration of variables, functions and function blocks and code
blocks in any of the languages specified in the IEC 61131-3 standard.
A program is the "top level" executable object in an application. You cannot reuse
programs as you can with, for example data types and function block types. The actual
execution code is written in one of the five programming languages. Execution speed
and priority are defined using Tasks.
You can create new programs (max 64). Each program can be connected to its own
task. The program task connection cannot be performed before the application is
connected to a controller.

7.1.2 Objectives
On completion of this chapter you will be able to:

Create a new program for an application

Create new logic with the Function Block Editor

Instantiate and use existing function block types from a library

Declare variables for a program and connect them to function block instances

Test the program

7.1.3 Reference Documentation


In the Control Builder Online Help: Index tab, keyword programs
In the Control Builder Online Help: Contents tab, System and Basic Functions
In the Control Builder Online Help: Contents tab, Programming Languages >
Function Block Diagram Editor
In the Control Builder Online Help: Contents tab, Programming Languages > ST
Structured Text

7.1.4 Limits

Max 64 programs per application

Max 256 applications per project

Max 8 applications per controller

Max 32 tasks per controller

Max 32 controller per project

7-3

Engineering an 800xA System


Chapter 7 Programs using FBD/ST

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

Engineering an 800xA System

7.2 Program Handling


7.2.1 Create Program
Create a new Program in the Control Builder:
1. Right mouse click onto Programs and left mouse click onto New Program

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.2.2 Delete Program


Delete a program in Control Builder:

7-5

Engineering an 800xA System


Chapter 7 Programs using FBD/ST

1. Right mouse click onto a program and left mouse click onto Delete

Right
click

Left
click

7.2.3 Copy and Paste Program


Copy and paste has to be done in PP in the Control Structure.
All child objects will be copied with same names. The name of the copied program
has the name extension _1.
Copy of a program in PP Control Structure:
1. Right mouse click onto a program and left mouse click onto Copy.

7-6

Engineering an 800xA System

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

Engineering an 800xA System


Chapter 7 Programs using FBD/ST

7-8

Engineering an 800xA System

7.3 The POU Editor


The IEC 61131 standard describes Programs, Function Blocks and Functions as
Program Organization Units or POUs. These units help you organize your automation
project into code blocks to minimize code writing and optimize the code structure and
code maintenance. The Function Blocks and Functions POUs are not limited to "onetime-use". You can use them repeatedly and in a recursive structure. In addition to
these two POUs, you have the Program. Although the program is the only POU that
cannot be reused in any of the other POUss it is defined as a POU. The figures below
describe the hierarchical structure of the POUs. As you can see, you can use both the
Function Block and the Control Module recursively to an unlimited depth whereas the
program or Control Module is a "top-level" POU. The Application contains the
program code that is to be compiled and downloaded for execution in the controller.

7-9

Engineering an 800xA System


Chapter 7 Programs using FBD/ST

7.3.1 Functions and Function Blocks


7.3.1.1 Functions

Always return a (single) value at the time they are executed.

Can be used in expressions.

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.

7.3.1.2 Function Blocks

Have both input and output parameters.

Can give several output values using parameters.

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.

Have to be used as instances of a type definition.

7.3.2 Opening the POU Editor


You open the POU editor by double clicking on it. The POU editors of Program,
Function Blocks and Control Modules have basically the same look and functionality.
This chapter will explain the functions and functionality of a Program, for more details
about Control Modules and Function Blocks see the chapters about Functions and
Function Blocks and Control Modules. The figure below shows the POU editor of a
Program.

7-10

Engineering an 800xA System

7.3.2.1 Toolbar Icons


The tables below describe menu commands, toolbar icons and keyboard short cuts
common to all editors. Editor-specific functions are described in the chapter of
respective editors.
Toolbar
icon

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

Check. Checks the editor contents for errors. The result is


displayed in the "Check" tab in the output pane. Double-click
on the lines with error messages to jump directly to the
place where an error occurred.

Ctrl + P

Print. Prints the current pane on a printer.

Ctrl + J

Preview. Displays a screen preview of printer output.

Ctrl + Z

Undo. Undoes the most recent action. You can undo


several steps, except in the ST code editor, which only
supports undoing the most recent action. Not available in
the SFC editor.

Ctrl + Y

Redo. Recalls the last undo action. Not available in the ST


code and the SFC editor.

Ctrl + X

Cut. Standard cut function

Ctrl + C

Copy. Standard copy function.

Ctrl + V

Paste. Standard paste function.

Ctrl + F

Find. Standard find function. Note: the function only


searches the current pane and present code block.

F3

Find Next. Finds the next occurrence of a specified text


string. Note: the function only searches the current pane and
present code block.
Find in Editor. Standard find function, but searches all panes
and all code blocks.
Message Pane. Toggles the display of the lower pane - the
message pane.

Ctrl + I

Insert Statements. Inserts statements like if-then-else, forloop, etc.

Ctrl + Space

Complete Word. Fills in the rest of the name, for example, a


variable name in the code pane.

7-11

Engineering an 800xA System


Chapter 7 Programs using FBD/ST
Ctrl + J

Insert Variable, Type, Attribute.... Inserts a variable, data


type or attribute in the declaration pane or in the code pane.

INS

Insert Function/Function Block. Inserts a function or function


block.

Ctrl + L

Insert Function. Inserts a function.

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

Edit Parameter List. Opens the connection editor for


parameter input assistance.

7.3.3 Message Pane


The message pane consists of three tabs: Description, Check and Find in editor.

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.3.3.3 Find in Editor


When you search for text strings, the result of the search is displayed in this pane.
Double-click on a line in this report to go quickly to the place the line references.

7.3.4 Code Pane


The code pane is divided into code blocks. Each tab contains a code block in one of
the different programming languages.

7-12

Engineering an 800xA System

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.3.4.1 Changing the Language


Right click on the tab of a code block and select Change Language to change
language on a code block.

7.3.4.2 Inserting Code Blocks


Right click on the tab of a code block and select Insert to insert a code block.

7.3.4.3 Arranging Code Blocks


Right click on the tab of a code block and select Arrange to arrange the code
blocks.

7.3.4.4 Deleting Code Blocks


Right click on the tab of a code block and select Delete to delete a code block.

7.3.4.5 Selecting Code Blocks


Right click on the tab of a code block and select Select to select a code block from
the pop up window.

7-13

Engineering an 800xA System


Chapter 7 Programs using FBD/ST

7.3.4.6 Renaming Code Blocks


Right click on the tab of a code block and select Rename to change name on the
code block.

7.3.5 Checking, Applying and Saving the Program


Use this button
to check and then this button
is saved and closed with this button .

to save the program, the window

7.3.6 Error Messages


If, following a check, there is an error in your program, an error message is written in
the Check tab in the message pane of the POU Editor. The error message below says
that the variable Start in the code block FBD_Code is not
declared.

7-14

Engineering an 800xA System

7.4 Function Block Diagram (FBD) language


7.4.1 General
Function Block Diagram (FBD) is a high-level graphical programming language. It
describes the POUs in terms of processing elements and displays the signal flow
between them, similarly to electronic circuit diagrams. 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. The FBD
editor consists of the following major parts:

7.4.1.1 FBD Pane


The FBD panes are the right upper and lower sub panes within the code pane if you
are working with the FBD editor. They contain the Function Block Diagram of the
POU you are programming. The FBD panes contain:

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.

7-15

Engineering an 800xA System


Chapter 7 Programs using FBD/ST

Comment of the page and footer.

*) In order to use a function block in a program, an instance of a function block type


has to be created. The type declaration is usually made in library, and acts as a general
template for all instances based on this type. A CTU (Count up) is an example of a
Function block type. Instances of this type, Counter_1, CTU_22, MyUpCounter etc.
can then be created in the POU editor.

Use the FBD panes to:

7-16

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, edit comments

Assign values to the parameters of function blocks and functions (connect them by
lines)

Check pagination and repaginate

Check texts of the footer

Engineering an 800xA System

7.4.1.2 Toolbar buttons


There is a special toolbar in the Function Block Diagram editor, with shortcuts to
many of the commands found in the menu bar (or in the pop-up menus). You can see a
brief explanation (tool tip) of each button, if you hold the cursor over the button.
Toolbar
button

Menu Command
Insert > Function/Function
Block

Key
Ins

Tools > Edit Parameters


>Connect

Tools > Edit Parameters


>Disconnect

Tools > Edit Parameters >


Invert

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

Use this command to de-assign


a variable or constant from the
selected parameter of a
function block or function.
Use this command to invert a
Boolean input parameter of a
function block or function.

7.4.2 Insert Function/Function Block


There are several ways to insert a function/ function block; 1) use the toolbar button
, 2) choose Insert> Function/Functionblock from the POU menu, 3) Use the
Insert key or 4) right click in the code pane and choose Insert Function/Function
block.

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

Engineering an 800xA System


Chapter 7 Programs using FBD/ST

If it is a function/function block that supports configurable input parameters (number


of parameters and data type for these), these inputs can be specified in the dialog
window.
The EN checkbox makes the optional Enable parameter available (this is explained in
the next section).
To go straight to the Connection dialog window, check the box Connect Parameters.

7.4.2.1 The EN input parameter


The EN property for functions and function blocks in FBD makes it possible to write
code that corresponds to if statements in the Structured Text language. The figure
shows how the EN input can be used to produce an If-Else statement.
The EN parameter should be connected to a boolean variable just as any other boolean
parameter. If a function has an EN input, it must be connected.
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 Edit Parameter Properties section).

7.4.2.2 Functions in FBD


The following basic functions corresponding to operators of textual programming
languages are available in the FBD language:

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.

Engineering an 800xA System

7.4.2.2.2 Boolean Operators


Function

Description

NOT

Negates the Boolean value (1/0, on/off or True/False).

AND, &

Boolean AND.

XOR

Boolean XOR.

OR, >=1

Boolean OR.

7.4.2.2.3 Arithmetic Operators


Function

Description

EXPT, **

Exponential, i.e. raising to the power.

MUL, *

Multiplication.

DIV, /

Division.

ADD, +

Addition.

SUB, -

Subtraction.

MOD

Modulus.

ABS

Absolute value.

7.4.2.2.4 Relational Operators


Function
LT, <

Description
Less than.

GT, >

Greater than.

LE, <=

Less than or equal to.

GE, >=

Greater than or equal to.

EQ =

Equal to.

NE, <>

Not equal to.

7.4.2.3 Edit Parameter Properties


By clicking with the right mouse button select a Function (box) of which you want to
change the type or size. Select the Edit Parameter Properties command to change
the size or type of the function.

The checkbox activates the Enable parameter which is optional. This is shown in the
figure.

7-19

Engineering an 800xA System


Chapter 7 Programs using FBD/ST

And function with/without the Enable parameter.

7.4.2.3.1 Insert Parameters


By clicking with the right mouse button select a parameter (pin) of the function block
or function to which you want to add a new parameter (pin). Select the Insert
command to add a new, last parameter (pin). Note! This is only possible if the function
or function block is expandable.

7.4.2.3.2 Delete Parameters


By clicking with the right mouse button select a parameter (pin) of the function block
or function to which you want to add a new parameter (pin). Select the Delete
command to add a new, last parameter (pin).

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.4.3.1 Connection of Variables and Constants


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.

7.4.3.1.1 Connecting each parameter separately


To connect a variable or a constant to a specific parameter, do as follows:

7-20

Engineering an 800xA System

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.4.3.1.2 Connecting all parameters


If you want to be able to connect several of the parameters in one action, it is best to
bring up the Parameter Connections editor from the context menu. Right click and
select Edit Parameter List.

7-21

Engineering an 800xA System


Chapter 7 Programs using FBD/ST

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.3.2 Connection to Previous Selection


To connect a parameter of a function block to another parameter, select the first
parameter by clicking on it with the left mouse button. The selection of the parameter
(pin) is shown by highlight. 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. Be sure you select
one input parameter and one output parameter. Select the Connect to Previous
Selection command from the context menu to accomplish the connection.

7.4.3.3 Quick connection from one function block to another


To connect two function block 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. Be sure
that you select one input parameter and one output parameter.

7.4.4 Comments
It is possible to write comments to functions/function blocks and pages.

7.4.4.1 Edit Comments of Function Blocks and Functions


Select the function block or function to which you want to assign a comment or the
comment of which you want to change. Select the Edit Comment command from
the context menu. Edit the comment in the Comment dialog box.

7.4.4.2 Edit Page Comments


If you want to add a comment for a page in FBD, just right click and select Edit Page
Comment from the context menu.

7-22

Engineering an 800xA System

7.4.5 Structure Pane


The structure pane is the left sub pane within the code pane. It contains a list of all
function blocks and functions of the current POU.
Use the structure pane to:

Get an overview of the POU.

Select, copy and paste function blocks and functions.

Create, modify and delete function blocks and functions.

Edit instance name of function blocks, edit comments.

Change the pagination and page comments.

Check pagination and repaginate.

Check text of the footer.

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 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 Number is given at the first function block or function of every page of the
Function Block Diagram

Instance shows the name of function blocks

7.4.6 Execution Rules


The evaluation of parameter values corresponds to the execution order of the function
block and functions within the POU. The execution order of function blocks and
functions is defined at first by the order of their creation. The execution order is

7-23

Engineering an 800xA System


Chapter 7 Programs using FBD/ST

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

Engineering an 800xA System

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.

7.5.1.1 Functions Simplifying While Editing


Press < Ctrl I > to insert Statement in the code pane or use the

button.

Press < Ctrl J > to insert declared variables in the code pane.

7-25

Engineering an 800xA System


Chapter 7 Programs using FBD/ST

7.5.1.2 Using Microsoft Word


It is possible to write the code in Microsoft Word and then use the copy and paste
function to move the code to the code pane if you are using the Structured Text editor.

7.5.2 Comments and the ABB Extension


Comments can be inserted wherever it is acceptable to insert one or more spaces in the
code.
You can insert comments in the code by framing them with the characters (* and *)
according to IEC 1131-3. You can not nest comments using this syntax.
If you need to nest comments you can frame the comment with the characters (# and
#). You can nest (*...*) comments inside (#...#) comments. This is useful for

commenting out large blocks of code containing comments.


Operator

Description

(**)

Comment according to IEC 1131-3.

(##)

Comment that can be nested (ABB extension).

7.5.3 Instructions
The following basic instructions are available in the ST language.

7.5.3.1 Assignment Operators


Operator

Description

:=

Assigns a value (number, logical or string) to a variable

()

Parentheses. Commonly used to change the priority of an


expression.

A variable is assigned a certain value with an assignment statement. If we wish the


variable to take the value of Start we write:
Run := Start;

A statement is always concluded with a semicolon, ;.


As in mathematics, the parentheses are used to change the priority in which execution
is performed. Expressions within parentheses have the highest order of precedence.

7-26

Engineering an 800xA System

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.

7.5.3.2.1 Boolean Expressions and Operators


Operator

Description

NOT,

Negates the Boolean value (1/0, on/off or True/False).

AND

Boolean AND.

&

Boolean AND. See AND.

XOR

Boolean XOR.

OR

Boolean OR.

Example of a Boolean expression:


Activated := Start and not Stop;

7.5.3.2.2 Arithmetic Expressions and Operators


Operator
**

Description
Exponential, i.e. raising to the power.

Multiplication

Division.

Addition.

Subtraction.

MOD

Modulus.

Example of an Arithmetic expression:


Value:= Value +1;

7-27

Engineering an 800xA System


Chapter 7 Programs using FBD/ST

7.5.3.2.3 Relational Expressions and Operators


Operator

Description

<

Less than.

>

Greater than.

<=

Less than or equal to.

>=

Greater than or equal to.

Equal to.

<>

Not equal to.

Under the headline Conditional Statements, an example is given with Relational


Expressions.

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

A statement is executed depending on the value of


an integer variable or an integer expression. The
<integer literal> is one or several integer values or
one or several ranges of values.
If the value of the selector does not occur in any
label, the statements following the else word (if it
occurs in the case statement) shall be executed.
Otherwise, if no else exists, none of the statements
shall be executed.

Engineering an 800xA System

An example of a conditional statement using If..then..elsif..:

Here is an example of a conditional statement using Case:


case Seconds of
1..4, 8..10 : RedLight := true;
GreenLight := false;
5..7 : RedLight := false;
GreenLight := true;
else
RedLight := false;
GreenLight := false;
end_case;
where Seconds is a variable of type dint.

7.5.3.3.2 Iteration Statements


Operator

Description

For

The for statement is used to allow a statement (or statements) to be


executed repeatedly for a given number of times. The counter used in
the repetition process can be used in the statements.

While

The while statement is used in order to allow a statement (or statements)


to be executed 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 (or


statements) to be executed repeatedly until a certain condition is True.
This separates it from the for statement. It has some similarities with the
while statement.

Exit

Use the exit statement whenever you want to terminate a loop


immediately and continue execution from the first line after the iteration
statement.

7-29

Engineering an 800xA System


Chapter 7 Programs using FBD/ST

7.5.3.3.3 Return Statements


Operator
Return

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.

7.5.3.4 Execution Order


The priority of operators decides the order of evaluation of an expression. Below is a
summary of available operators, in descending priority:
Operator

Description

()

Parenthesized expression.

Function ()

Parameter list of a function, function evaluation.

Not, -

Negation, Boolean complement, i.e. value with "opposite"


value (0 becomes 1, 1 becomes 0) and arithmetical
negation (-).

**

Exponentiation, i.e. raising to a power.

*, / ,mod

Multiplication, division and modulus.

+, -

Addition and subtraction.

<, >, <=, >=

Comparison operators

=, <>

Equality and inequality.

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.5.4 Using Functions


A function call in ST is done by writing the name of the function in the editor or by
using the
button, pressing < Ctrl L> or selecting (Insert >Function). An
example with the function Add in ST:

7.5.5 Using Function Blocks


You must create an instance of the function block before it is used in the ST or SFC
editor. The instance is created as follows:

7-30

Engineering an 800xA System

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.

Write a description in the Description 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

Engineering an 800xA System


Chapter 7 Programs using FBD/ST

7.6 Program test


7.6.1 General Information
Test Mode
In Test mode Control Builder M executes the code in the same way as it is normally
executed in the controller in Online mode. (The execution time will be much faster in
Test mode since the code is executed in the PC). You can change variable values and
see the program response online for testing and fault finding purposes. You do not
need to be connected to a controller to test a project.
Simulation
An operator or engineer can completely debug the application in the controller before
commissioning the application to the real plant. In the Control Builder M the
controller is marked as simulated. The application is downloaded to the controller and
the hardware is simulated which means that the physical I/O is disconnected. The
hardware configuration can be of any product type, AC 800M or SoftController. The
simulation functionality makes it possilbe to download any product type to an AC
800M, a High Integrity Controller or a SoftController.
It is not possible to insert code breaks into the code. However, you can use If False
thenend_if for the part of the code that you do not want to execute.
Before download to the controller is done , the controller has to be reset or already
marked as simulated. When a SoftController is not used for simulation it is possible to
use it for communication purposes, for example COMLI or MODBUS.

7.6.2 Start Test Mode


Start Test Mode for a Control Builder project:
1. Left mouse click onto Tools in the menu bar and left mouse click onto Test
Mode!

7-32

Engineering an 800xA System

2. The Test Mode Analysis window is displayed.


You can restart applications in a controller in two different ways: Cold Restart and
Warm Restart. Values are retained between two versions of the application, based on
matching of instance names. In Control Builder you can generally make changes and
still retain variable values between two versions.
Depending on the attributes specified for the variables in the application, the values
are either saved or lost upon restart.

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.6.3 Stop Test Mode


Stop Test Mode for a Control Builder project:

7-33

Engineering an 800xA System


Chapter 7 Programs using FBD/ST

5. Left mouse click onto a Tools in the menu bar and left mouse click onto Stop
Test Mode

7.6.4 Online Values


To get some live values from the system double mouse click onto the program
Meas_Slow_Cont1

7-34

Engineering an 800xA System

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

Engineering an 800xA System


Chapter 7 Programs using FBD/ST

7-36

You might also like