10

Click here to load reader

Structured Text Language

Embed Size (px)

Citation preview

Page 1: Structured Text Language

8/12/2019 Structured Text Language

http://slidepdf.com/reader/full/structured-text-language 1/10

Course T530

Chapter 9 Structured Text (ST) Language

TABLE OF CONTENTS

Chapter 9 Structured Text (ST) Language.............................................................9-1

9.1 General Information......................................................................................9-1

9.1.1 Description......................................................................................9-1

9.1.2 Objectives .......................................................................................9-1

9.1.3 Reference Documentation...............................................................9-1

9.2 Lesson 1 – ST Language...............................................................................9-2

9.2.1 Description......................................................................................9-2

9.2.2 Objectives .......................................................................................9-2

9.2.3 General............................................................................................9-2

9.2.3.1 Functions Simplifying While Editing............................9-29.2.3.2 Using Microsoft Word...................................................9-3

9.2.4 Comments and the ABB Extension ................................................9-3

9.2.5 Instructions .....................................................................................9-3

9.2.5.1 Assignment Operators ...................................................9-3

9.2.5.2 Expressions....................................................................9-4

9.2.5.2.1 Boolean Expressions and Operators .........9-4

9.2.5.2.2 Arithmetic Expressions and Operators .....9-4

9.2.5.2.3 Relational Expressions and Operators ......9-5

9.2.5.3 Statements .....................................................................9-5

9.2.5.3.1 Conditional Statements .............................9-5

9.2.5.3.2 Iteration Statements ..................................9-6

9.2.5.3.3 Return Statements.....................................9-7

9.2.5.4 Execution Order ............................................................9-7

9.2.5.5 Simulate.........................................................................9-7

9.3 Exercise 9.1 – Use the ST language..............................................................9-7

3BSE 022 850/C 9-i

Page 2: Structured Text Language

8/12/2019 Structured Text Language

http://slidepdf.com/reader/full/structured-text-language 2/10

Course T530

9-ii 3BSE 022 850/C

Page 3: Structured Text Language

8/12/2019 Structured Text Language

http://slidepdf.com/reader/full/structured-text-language 3/10

Course T530

Chapter 9 Structured Text (ST) Language

9.1 General Information

9.1.1 Description

This chapter describes the use of the programming language ST.

9.1.2 Objectives

On completion of this chapter you will be able to:

•  Use the ST Language.

9.1.3 Reference Documentation

In the Online help: Contents tab, Programming Languages > ST–Structured Text.

3BSE 022 850/C 9-1

Page 4: Structured Text Language

8/12/2019 Structured Text Language

http://slidepdf.com/reader/full/structured-text-language 4/10

Course T530Chapter 9 Structured Text (ST) Language

9.2 Lesson 1 – ST Language

9.2.1 Description

This lesson describes the use of the ST Language.

9.2.2 Objectives

On completion of this lesson you will be able to:

•  Use the ST Language.

9.2.3 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.

9.2.3.1 Functions Simpl ifying 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.

9-2 3BSE 022 850/C

Page 5: Structured Text Language

8/12/2019 Structured Text Language

http://slidepdf.com/reader/full/structured-text-language 5/10

Course T530

9.2.3.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.

9.2.4 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).

9.2.5 Instructions

The following basic instructions are available in the ST language.

9.2.5.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.

3BSE 022 850/C 9-3

Page 6: Structured Text Language

8/12/2019 Structured Text Language

http://slidepdf.com/reader/full/structured-text-language 6/10

Course T530Chapter 9 Structured Text (ST) Language

9-4 3BSE 022 850/C

9.2.5.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 asingle 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.

9.2.5.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;

9.2.5.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;

Page 7: Structured Text Language

8/12/2019 Structured Text Language

http://slidepdf.com/reader/full/structured-text-language 7/10

Course T530

9.2.5.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.

9.2.5.3 Statements

9.2.5.3.1 Conditional Statements

Operator Description

If..then..

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;

If..then..

else..

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;

If..then..

elsif..

else..

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;

case <integer> of

<integer literal> : <statements>

end_case;

 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.

case <integer> of<integer literal> : <statements><integer literal> : <statements><integer literal> : <statements>

else  <statements>

end_case;

 

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.

3BSE 022 850/C 9-5

Page 8: Structured Text Language

8/12/2019 Structured Text Language

http://slidepdf.com/reader/full/structured-text-language 8/10

Course T530Chapter 9 Structured Text (ST) Language

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

Here is an example of a conditional statement using Case:

case Seconds of1. . 4, 8. . 10 : RedLi ght : = t r ue;

Gr eenLi ght : = f al se;5. . 7 : RedLi ght : = f al se;

Gr eenLi ght : = t r ue;el se

  RedLi ght : = f al se;Gr eenLi ght : = f al se;

end_case;

where Seconds is a variable of type dint.

 

9.2.5.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 iterationstatement.

9-6 3BSE 022 850/C

Page 9: Structured Text Language

8/12/2019 Structured Text Language

http://slidepdf.com/reader/full/structured-text-language 9/10

Course T530

9.2.5.3.3 Return Statements

Operator Description

Return 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 thestatement unless you are an advanced user as it can cause problems

when executing together with other function blocks. 

9.2.5.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 Priority

(…) Parenthesized expression. HighestFunction (…) 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

9.2.5.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).

9.3 Exercise 9.1 – Use the ST language

Please do exercise 9.1

3BSE 022 850/C 9-7

Page 10: Structured Text Language

8/12/2019 Structured Text Language

http://slidepdf.com/reader/full/structured-text-language 10/10

Course T530Chapter 9 Structured Text (ST) Language

9-8 3BSE 022 850/C