Вы находитесь на странице: 1из 25

Course T314 Chapter 11

Structured Text

Extended Automation System 800xA


ABB University - 1
Revision C
Structured Text
Overview

Objectives
After this chapter you should be able to:
Describe the Structured Text Language rules
Write simple application code in ST
Use Functions and Function Blocks in ST

Reference Documentation
3BSE043732 IndustrialIT 800xA Control and I/O
Application Programming Introduction and Design
3BSE035980 IndustrialIT 800xA Control and I/O
Basic Control Software Introduction and Configuration
3BSE035981 IndustrialIT 800xA Control and I/O
Extended Control Software Binary and Analog Handling
ABB University - 2
Revision C
Structured Text
Structured Text

Language Elements
Functions and Function Blocks
Common Mistakes and Error Messages
Change Language in Online
ABB University - 3
Revision C
Language
Elements Advantages
Structured Text (ST) is a high-level programming language

Free layout of code and comments


When in online mode the layout can be changed to Function Block or Ladder
for viewing by different personnel.
Text may be generated in any external text editor and pasted into the ST
editor.
For example you might use macros in MS Word to generate code.
Structured text reads like English and is the most efficient way of writing code.
You will have to learn Structured Text in any case because it is the only choice
in the SFC editor!
ABB University - 4
Revision C
Language
Elements Structured Text Editor
ABB University - 5
Revision C
Language
Elements Comments / Assignments

Operator Description
:= Assigns a value (number, logical or string) to a variable

() Parentheses. Commonly used to change the priority of an


expression.

Result := In1 AND In2 OR In3;


AverageFlow := (Flow1 + Flow2)/2;

Operator Description
(**) Comment according to IEC 1131-3.

(##) Comment that can be nested (ABB extension).


ABB University - 6

(* This is not (* Inner Comment *) allowed *)


(# This is (* Inner Comment *) allowed #)
Revision C
Language
Elements Boolean / Arithmetic / Relational
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.

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

* Multiplication

/ Division.
+ Addition.
- Subtraction.

MOD Modulus.

Operator Description
< Less than.

> Greater than.


ABB University - 7

<= Less than or equal to.


>= Greater than or equal to.

= Equal to.
Revision C

<> Not equal to.


Language
Elements Order of Precedence

Operator Description Priority


() Parenthesized expression. Highest

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 Lowest
ABB University - 8
Revision C
Language
Elements Conditional Statements
Operator Description
IF Boolean Expression THEN If (and only If) the Boolean Expression evaluates
Statement(s); to True, then the Statement(s) between the IF and
END_IF; END_IF is/are executed.

IF Boolean Expression THEN If the Boolean Expression evaluates to True, then


Statement(s); the Statement(s) before the ELSE is/are executed.
ELSE Else the statements after the ELSE and before the
Statement(s); END_IF are executed.
END_IF;

IF Boolean Expression 1 THEN If the Boolean Expression 1 evaluates to True,


Statement(s); then the Statement(s) before the first ELSIF is/are
ELSIF Boolean Expression 2 THEN executed. If this condition is false then the
Statement(s); subsequent Boolean Condition is tested and so on
ELSIF Boolean Expression n THEN for each ELSIF. If no expression is true then the
Statement(s); ELSE statement(s) execute.
ELSE The ELSE clause is optional. You may have as
Statement(s); many ELSIF clauses as you wish.
END_IF;

Operator Description
CASE Integer Expression OF A statement is executed depending on the value of
Integer Literal1 : Statement(s); an integer variable or an integer expression.
END_CASE; The <integer literal> is one or several integer
values or one or several ranges of values.

CASE Integer Expression OF In this example, three values are tested and the
Integer Literal1 : Statement(s); appropriate statements) executed. One variation is
Integer Literal2 : Statement(s); to permit a range of values to be tested rather than
ABB University - 9

Integer Literal3 : Statement(s); an exact single value.


ELSE If none of the test literals match the result of the
Statement(s); expression then the statement(s) in the ELSE
END_CASE; clause will be executed. If no ELSE exists, none of
Revision C

the statements will be executed.


Language
Elements Iteration Statements
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 number of
END_FOR; 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
Statement(s); (or statements) to be executed repeatedly while a certain
END_WHILE; 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


Statement(s); (or statements) to be executed repeatedly until a certain
UNTIL Boolean Expression condition is True.
END_REPEAT; Note 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.
ABB University - 10
Revision C
Structured Text
Structured Text

Language Elements
Functions and Function Blocks
Common Mistakes and Error Messages
Change Language in Online
ABB University - 11
Revision C
Functions and
Function Blocks Overview
ABB University - 12
Revision C
Functions and
Function Blocks Declare Function Block Instances
Absolute minimum = Name and function block Type
ABB University - 13
Revision C
Functions and
Function Blocks Call a Function Block Instance (1)
ABB University - 14
Revision C
Functions and
Function Blocks Call a Function Block Instance (2)
ABB University - 15
Revision C
Structured Text
Structured Text

Language Elements
Functions and Function Blocks
Common Mistakes and Error Messages
Change Language in Online
ABB University - 16
Revision C
Common
Mistakes Identifier, constant or opening parenthesis
ABB University - 17
Revision C
Common
Mistakes Variable name is not unique
ABB University - 18
Revision C
Common
Mistakes Identifier too long or invalid
ABB University - 19
Revision C
Common
Mistakes Undefined function block
ABB University - 20
Revision C
Common
Mistakes Type mismatch in assignment
ABB University - 21
Revision C
Common
Mistakes Incompatible types in expression
ABB University - 22
Revision C
Structured Text
Structured Text

Language Elements
Functions and Function Blocks
Common Mistakes and Error Messages
Change Language in Online
ABB University - 23
Revision C
Change
Language Change from ST to FBD in Online
ABB University - 24
Revision C
ABB University - 25
Revision C

Вам также может понравиться