mt8000 ST Programming Manual
mt8000 ST Programming Manual
altus
General Conditions
No part of this document may be copied or reproduced in any form without the prior written consent
of Altus Sistemas de Informática S.A. who reserves the right to carry out alterations without prior
advice.
According to current legislation in Brazil, the Consumer Defense Code, we are giving the following
information to clients who use our products, regarding personal safety and premises.
The industrial automation equipment, manufactured by Altus, is strong and reliable due to the
stringent quality control it is subjected to. However, any electronic industrial control equipment
(programmable controllers, numerical commands, etc.) can damage machines or processes controlled
by them when there are defective components and/or when a programming or installation error
occurs. This can even put human lives at risk.
The user should consider the possible consequences of the defects and should provide additional
external installations for safety reasons. This concern is higher when in initial commissioning and
testing.
The equipment manufactured by Altus does not directly expose the environment to hazards, since
they do not issue any kind of pollutant during their use. However, concerning the disposal of
equipment, it is important to point out that built-in electronics may contain materials which are
harmful to nature when improperly discarded. Therefore, it is recommended that whenever
discarding this type of product, it should be forwarded to recycling plants, which guarantee proper
waste management.
It is essential to read and understand the product documentation, such as manuals and technical
characteristics before its installation or use.
The examples and figures presented in this document are solely for illustrative purposes. Due to
possible upgrades and improvements that the products may present, Altus assumes no responsibility
for the use of these examples and figures in real applications. They should only be used to assist user
trainings and improve experience with the products and their features.
Altus warrants its equipment as described in General Conditions of Supply, attached to the
commercial proposals.
Altus guarantees that their equipment works in accordance with the clear instructions contained in
their manuals and/or technical characteristics, not guaranteeing the success of any particular type of
application of the equipment.
Altus does not acknowledge any other guarantee, directly or implied, mainly when end customers are
dealing with third-party suppliers.
The requests for additional information about the supply, equipment features and/or any other Altus
services must be made in writing form. Altus is not responsible for supplying information about its
equipment without formal request.
COPYRIGHTS
Ponto Series, MasterTool, PX Series, Quark, ALNET and WebPLC are the registered trademarks of
Altus Sistemas de Informática S.A.
Windows, Windows NT and Windows Vista are registered trademarks of Microsoft Corporation.
i
Sumary
Summary
1. INTRODUCTION ............................................................................................................................................. 1
3. PROCEDURES ................................................................................................................................................. 7
4. PROGRAMMING........................................................................................................................................... 12
Functions .......................................................................................................................................................... 22
Program............................................................................................................................................................ 23
Parameters Passing .................................................................................................................................... 24
Parameters Passing to F Module ............................................................................................................... 26
Signs of Module Input and Output ............................................................................................................ 26
Internal Variable of Control ...................................................................................................................... 27
Scope and Life Time Rules ............................................................................................................................. 27
Commands ....................................................................................................................................................... 28
Expressions ............................................................................................................................................... 28
Integer Constants ....................................................................................................................................... 30
Attribution Command ............................................................................................................................... 31
Command of Program control ................................................................................................................... 31
Commands of selection ............................................................................................................................. 31
Commands de Repetition or Iteration ....................................................................................................... 32
5. DEBUG ............................................................................................................................................................. 35
7. APPENDIX ...................................................................................................................................................... 43
Keywords.......................................................................................................................................................... 43
8. GLOSSARY ..................................................................................................................................................... 44
iii
1. Introduction
1. Introduction
ST Language (Structured Text) is a structured text language, high level, with resources similar to C
and Pascal languages. It can be used for writing programs with commands IF, THEN, ELSE, loops
FOR and WHILE, local variables and vectors can be created, creation and calling of sub-routines,
etc. It is an alternative to the use of Ladder graphic language, as it can access operands.
Programming in ST language is facility of MasterTool XE Advanced. It is available to use with CPU
AL-2004, as well as Ponto Series PLCs. Through this language it is possible to create procedure
modules (P module) and function modules (F modules), as defined by the norm IEC-1131-3.
After creation, the ST modules have the same characteristics as the other F of P modules already
existent. The parameters number of input and output can be configured. The calling of new ST
module must be done on the application program Ladder with CHF or CHP instruction, as it is done
to other modules F and P.
The module created in ST language can be read again from the microcomputer PLC. In this case, the
source program ST is normally restored, even with its comments. There are passwords to protect
against not allowed reading and/or modifying, protecting the designer technology. MasterTool XE
implements a subgroup of ST Language, and it includes most of the structures and data commands
defined by IEC-61131-3.
The execution performance of the PLC of a ST module is better than an equivalent module in Ladder,
as the ST module is verified as a whole, while in Ladder it is divided in many instruction calls.
The main benefits of the use of ST Language are:
Another option on programming language, according to international norm
Possibility of creating programming, according to international norm
Text language instead of graphic: copy/paste/substitute or traditional editors text macros
Shorter time to developing, resulting in less engineering costs
Better execution performance
Lite: programming software specific for small applications. This version does not support ST.
Professional: programming software with tools for all lines of Altus CLPs.
Advanced: programming software with tools for bigger applications
Each version has its characteristics, ends and functions specified for each purpose. Further details
about these differences can be seen on Master Tool XE Using Manual.
Visual Inspection
Before proceeding the installation, it is recommendable to make a careful visual inspection of the
material, verifying if it does not have damages caused by the transport. Check if all the products
received are in perfect state. In case of defects, inform the transport company and the nearer Altus
representative.
It is important to register the serial number of each equipment received, as well as the revisions of
software, in case it exists. This information will be necessary in case of need to contact the Altus
technical support.
Technical Support
To contact Altus technical support in São Leopoldo, RS, Call +55-51-35899500. To know Altus
technical support centers in others localities, check our site (www.altus.com.br ) or send an email to
[email protected].
If the equipment is already installed, please have the following information upon requesting the
assistance:
The model of the equipments used and the configuration of the installed system.
The PLC serial number.
Equipments review and executive software version, in the label on the side of the product.
Information about the operating mode of the PLC, obtained through Master Tool programmer.
The content of the application program (modules), obtained through MasterTool programmer.
The version of the programmer used.
2
1. Introduction
DANGER: indicates a risk to life, production, serious harm to people, or that substantial
material or environmental damage may happen it the necessary precautions are not taken.
WARNING:
Indicates configuration, application and installation details that must be followed to avoid
situations that can cause system errors and related consequences.
ATTENTION:
Indicates important configuration, application or installation details to obtain the maximum
performance of the system.
3
2. Technical Description
2. Technical Description
This section presents the technical characteristics of ST Editor.
Software Characteristics
Types of Data
The available types of data are shown in the following table:
Description Bits Related PLC Operand
BOOL Boolean 1 Bit of %A, %E, %S or %M
BYTE 8 bits sequence 8 Operand %A, %E or %S
WORD 16 bits sequence 16 Operand %M or %TM
DWORD 32 bits sequence 32 Operand %I or %TI
USINT Short int not signed 8 Operand %A, %E or %S
INT Integer 16 Operand %M or %TM
DINT Long Integer 32 Operand %I or %TI
REAL Real 32 Operand %F or %TF
Software Limits
Description
Call nested functions 16 function call
Size of módule P or F Up to 32KB
Data area for variables Up to 3KB1
Function quantity It is size limit of module.
1
To variables declared between VAR..END_VAR and are not mapped to PLC operand, and to variables alloced
automatically for MasterTool XE and used in temporary operations.
4
2. Technical Description
PLC Operands
A module developed through ST language can access CLP operands. The following table shows the
PLC operands, as well as its compatibility with ST Language:
Operand Type Can be used by ST ?
%A, %E and %S Yes
%M and %TM Yes
%I and %TI Yes
%F and %TF Yes
%D and %TD No
Operators
The operators of arithmetic expressions and logic in ST are similar to other languages, as shown in
the following table:
Type Operators
Mathematics + Sum
- Subtraction
* Multiplication
/ Division
MOD Rest
Commands
The following table shows the commands of ST language:
Typo Commands
Repetition WHILE
REPEAT
FOR
Selection IF
CASE
6
3. Procedures
3. Procedures
In this section is presented an example of how to generate a procedure module or a function module
with ST Editor. In both examples, a digital filter program that must be applied on three input
operands will be used.
7
3. Procedures
VAR_INPUT
INPUT: INT; (*Input data to be filtered*)
LAST_OUTPUT: REAL; (*Last filter result*)
END_VAR
VAR
FILTER_FACTOR: REAL; (*Local variable to the filter factor*)
END_VAR
(*Store the division of the sample time and the filter time constant*)
(*in a local variable*)
FILTER_FACTOR := SAMPLE_TIME/FILTER_TIMEO;
END_FUNCTION
8
3. Procedures
END_PROGRAM
VAR_IN_OUT
OP_INPUT_OUTPUT_0: REAL;
OP_INPUT_OUTPUT_1: REAL;
OP_INPUT_OUTPUT_2: REAL;
END_VAR
END_PROGRAM
Diagnostic Operands
The diagnostic operands are used to report for user any error in execution time. The operands can be
configured through menu Module / Operands / Diagnostic. If the operands were not configured an
error is reported in verification time. The errors code can be seen in section Errors in Execution
Time.
9
3. Procedures
Temporary Operands
The temporary operands are used to solve some operations that use variables of type DINT and
REAL. It is an optional configuration, but if the compiler needs it will be reported on verification
time. The operands can be configured through menu Module / Operands / Temporary. The maximum
quantity of the operands, if required, is 4.
10
3. Procedures
WARNING:
MasterTool XE only allows sending modules without errors to the PLC. However, the previous
versions of MasterTool XE do not execute it, so in this case a module with error can be sent to the
PLC. But due to the verification error, the module will not execute it and an error in execution time
will happen.
Using a Module in ST
The ST module is used as modules in Ladder. It must be called through another ladder module using
the CHP instructions (to P modules) or the instructions CHF (to F modules).
11
4. Programming
4. Programming
This chapter describes the rules to write a program in ST language, presenting its syntax, semantic
rules and the structure of the source code.
BEGIN TEXT
It is obligatory to have a
program declaration. This
is the code that will be
executed when the PROGRAM...END_PROGRAM
module is called by
ladder.
END TEXT
Elements of ST Language
The elements of ST Language are all the symbols, numbers, operators and other punctuation used by
the language and that cannot be textually divided. The ST language elements are:
Identifiers
Numerical constants
12
4. Programming
Boolean constants
Empty space
Comment
Operators and other punctuation signs
Identifiers
An identifier is used to name different elements in the language, being an unique element in its
scope. It is formed by letters, numbers and by the character subscribed (“_”). It must start by letter or
by the subscribed character, but it cannot have two consecutive subscribed characters and cannot end
with this character.
Only the first 32 characters of the sequence. The others will not have meaning and will be ignored.
The use of capital or small letters does not have meaning on the identifier, it means, Level_Vase1,
level_vase1 or Level_vase1 are distinct identifiers
The following table has some example of valid and non-valid identifiers:
Valid Identifiers PumpStatus
ALM_PressureHigh
B1_ACTIVE
_1001_1
pressureTest
Invalid Identifiers __Test
Pump__B3214
Valve-125201
154_TurnOn
Pressure_
WARNING:
An identifier can have up to 32 characters. The characters up this limit are not considered. The
identifier name is not case sensitive.
Empty Space
The space characters, tab and break line are considered empty spaces, it means, they can be used
freely among the other elements of ST language.
Comments
Comments on the source code must be done between “(*” and “*)”.
Many lines can be commented with the same block. However it is not allowed the use of comments
nested as: "(* ... (* ... *) ... *)".
13
4. Programming
Numerical Constants:
There are two types of constants: integer and real. In both cases, a number can have several
characters of subscribed inside it. This character does not have meaning, it serves only to make a
number more legible. However the subscribed character cannot start or finish a number, as well as it
is not allowed the use of two subscribed characters together.
An integer number can also be expressed in binary, octal or hexadecimal bases. For this, one of the
prefixes 2#, 8# and 16# must be used before the number, as can see below.
2#0000_1001 (* Binary constant equal to 9 *)
2#1111_1111 (* Binary constant equal to 255 *)
8#457 (* Octal constant equal to 303 *)
16#00AA (* Hexa constant equal to 170 *)
16#8000 (* Hexa constant equal to 32768 *)
The following table brings some examples of numerical literal valid and non-valid:
Example Value in decimal
Valid numerical literal 12547 12547
10_531 10531
-1_532 -1532
6978 6978
2#0000_1001 9
2#01001100 76
2#001 1
8#457 303
8#6254 3244
16#4576_ab4f 1165405007
16#980ABE4D 2550840909
16#FFFF_ffff 4294967295
Invalid numeric literal _1546
4578_
-_5447
10__135
#0010001
2#4577_0158#00159
16#_1789
16#4587_
14
4. Programming
Boolean constants
For boolean constants the words TRUE or FALSE can be used; or its numerical equivalents 1 or 0.
Types of Data
The type of data defines the manner in which the data can be stored on the PLC memory. This
section defines the possible types of data as well as the conversion functions applicable from a type
to another.
Note 1: Numerical band is not applicable to the types BYTE, WORD and DWORD.
Note 2: the floating point with simple precision is defined by the norm IEC 559 (IEEE 754).
Classifying Data
The several types of data are classified in groups according to a hierarchy. Afterwards, it will be seen
that the use of operators usually is limited to determined types of a same group.
15
4. Programming
Types Conversion
The variable can be converted to another format through the converting type functions. The
converting of a type to another can occur on an implicit manner, when the verifier inserts a
conversion function automatically; or in an explicit manner, when the user must insert the conversion
function.
The conversion functions use the format:
<source type>_TO_<target type>( <value to convert> )
The implicit conversions among types are possible since there is no risk of losing information, and
that there is compatibility among types. The following figure presents all the possible implicit
conversions between two types:
16
4. Programming
17
4. Programming
WARNING:
The conversion of variables type REAL to any variable type ANY_INT using the functions of
conversion type, will always be passed the integer part of the REAL variable. Those functions do not
carry out rounding.
18
4. Programming
Variables
A variable is a memory area that stores a type of language data. The data are defined as Basic Types
of Data. All the variables must be declared before being used.
Declaring de Variables
Any variable declaration must be done between the words VAR and END_VAR. Each declaration
can have many variables, separated by comma. In this case, all will be of a same type.
VAR
<Var1>, <Var2>, ... , <VarM> : <tipo1>;
<VarN>, <VarO>, ... , <VarZ> : <tipoN>;
END_VAR
The variables are always initiated automatically with the standard value, according to the following
table. Only the variable placed in PLC operands are not initiated automatically.
Data Type Default start value
BOOL FALSE or 0
USINT, INT, DINT 0
BYTE, WORD, DWORD 0
REAL 0.0
Only-Reading Variables
A variable declared as only reading only accepts value attribution in its declaration. Any other
attribution during the code will cause error in verifying time.
The declaration of only-reading variables, also known as constant variables, is done through the
clause CONSTANT, according to what is shown bellow:
VAR CONSTANT
<Var1>, <Var2>, ... , <VarM> : <type1>;
<VarN>, <VarP>, ... , <VarZ> : <typeN>;
END_VAR
The application of those variables occurs when it is necessary to map a variable of the PLC inside the
ST module and that cannot have writing operations on them. Other application occurs when it is
desired to substitute symbols for numerical constants and group in an only place the values
associated to them.
The following example shows a simple application of variables type CONSTANT:
VAR CONSTANT
INI : INT := 1;
END : INT := 100;
END_VAR
VAR
VECTOR : ARRAY[1..100] OF INT;
LEVEL AT %F0030 : REAL;
I : INT;
END_VAR
19
4. Programming
Declaring Vectors
Vectors are declared using the clause ARRAY. The inferior and superior limits can be specified
freely. That is, it is possible to define a vector of 10 elements, being the first element accessed by the
index 14 and the last one by 23, for example. Those vectors can be indexed through any expression
of type USINT, INT or DINT, since it is positive. The maximum number of elements is limited only
by the size of the data area (3kbytes).
VAR
<vetor1> : ARRAY [ <inferior_limit> .. <superior_limit > ] OF <type>;
<vetor2> : ARRAY [ <inferior_limit> .. <superior_limit> ] OF <type>;
END_VAR
A declaration of vectors where the superior limit is less than the inferior limit or where the inferior
limit is less than zero will cause a verification error.
A vector can also be started on the declaration. In this case, the values are written in sequence and
must be separated by comma.
VAR
Vector : ARRAY [1..10] OF INT := [ 11, 12, 13, 0, 0, 0, 0, 18, 19, 20 ];
END_VAR
It is equivalent to:
Vector[ 1 ] := 11;
Vector[ 2 ] := 12;
Vector[ 3 ] := 13;
Vector[ 4 ] := 0;
Vector[ 5 ] := 0;
Vector[ 6 ] := 0;
Vector[ 7 ] := 0;
Vector[ 8 ] := 18;
Vector[ 9 ] := 19;
Vector[ 10 ] := 20;
20
4. Programming
The types allowed on the declaration must be compatible with the operands. The following table
shows the possible associations among operands and types:
Operand Allowed Types
%M.x, %A.x, %E.x and BOOL
%S.x
%A, %E and %S USINT or BYTE
%M or %TM INT, or WORD
%I or %TI DINT, or DWORD
%F or %TF REAL
All the operands MAPEAMENTOS are verified during the module execution so that it is possible to
be sure that this operand was declared on C module. In case it not exists, an error in execution time
occurs, according the description of the Table 5-2.
VAR
(*Declaring a vector of 150 positions on the operands block of operands M1000 to
M1149*)
ALARMS AT %M1000 : ARRAY[ 1..150 ] OF WORD;
21
4. Programming
In operands mapping, every block must be declared on module C of the CP. A mapped vector in table
operand must be totally in the table operand mapped. In case any of these conditions is false, an error
in execution time occurs.
Functions
A function is a routine that must be executed several times. The main use of the functions is allow a
better modularity to a program. A function is declared in the following manner:
START TEXT
It is obligatory at least
one comand on the
function code. Comands
END_FUNCTION
END TEXT
END_VAR
FUNCTION1 := A * 2;
END_FUNCTION
The input parameters must be specified between the words VAR_INPUT and END_VAR. The order
in which the parameters are specified determines the order in which they must pass to this function.
The input parameters cannot be mapped in PLC operands, or be defined as vectors.
A function can call other functions defined by the user. However, the call of the same function is not
allowed and an error in verification time occurs. The limit of calls nested function is 16 calls, that is,
from the main program, can only be called 16 functions according to the following picture:
Program
Program is the code routine where the execution of module starts. A program can access all the
global variable and functions defined on the module. It is declared as in the following figure:
23
4. Programming
START TEXT
PROGRAM <Nome>
The program can contain
on or more input prameters
declared on the block
VAR_INPUT...END_VAR.
VAR_INPUT...END_VAR
VAR...END_VAR
The program can have
many declarations of
internal variables , or none.
END_PROGRAM
END TEXT
Parameters Passing
Whenever a module F is being programmed, the passing of input and output parameters is possible.
They are passed through the ladder instruction and are limited to the amount of parameters allowed
by the instruction, being a total of 10 input parameters to input and/or output and 10 more output
parameters.
24
4. Programming
Figure 4-7. Relations between inputs and outputs of CHF with ST module operands
All the parameters are passed by value. They can be table operands, blocks of simple operands. The
consistence rules to the passing of parameters are shown bellow, and any violation will cause an error
in execution time:
The parameters must be passed to equivalent types according to the table 4-8;
Constant operands, %KM, %KI and %KF, can only be related to VAR_INPUT and only to simple
variable, they cannot be vector
Can not be passed part of the operand, like bit, nible, byte or word.
Table operands can be related only to vector;
A VECTOR must be related to a table operand or to a block of simple operands, where the first
VECTOR position is the operand passed on the CHF;
All the operands passed by parameters must be declared;
All the operands related to vector must be declared, and it includes the complete vector size.
Table 4-9 represents the input and output operands declaration to the following declaration of
variables in a ST module.
PROGRAM TEST
VAR_INPUT
OP_INPUT0: ARRAY[ 1..100 ] OF INT;
OP_INPUT1: INT;
OP_INPUT2: INT;
END_VAR
VAR_IN_OUT
OP_IN_OUT0: REAL;
OP_IN_OUT1: REAL;
OP_IN_OUT2: REAL;
END_VAR
VAR_OUTPUT
OP_OUTPUT0: ARRAY[ 1..10 ] OF INT;
OP_OUTPUT1: INT;
OP_OUTPUT2: INT;
OP_OUTPUT3: REAL;
OP_OUTPUT4: REAL;
OP_OUTPUT5: REAL;
END_VAR
;
END_PROGRAM
25
4. Programming
VAR_IN_OUT
VAR_IN_OUT_0: REAL;
VAR_IN_OUT_1: REAL;
END_VAR
VAR_OUTPUT
VAR_OUT_0: INT;
VAR_OUT_1: INT;
END_VAR
<program body>
END_PROGRAM
At the end of the execution of the ST module the operands type VAR_IN_OUT are copied to their
respective source operands.
ATTENTION:
Only parameters type VAR_INPUT can be associated to constant operands (%KM, %KI, %KF)
through the input parameters of the CHF.
ATTENTION:
For the execution of the program it is necessary that the first input of the CHF and CHP instruction
is enabled.
26
4. Programming
The variable OUTPU1, OUTPUT2 and OUTPUT3 are only writing. The variable OUPUT1 is started
with TRUE while the others are started with FALSE. In case there is an error in execution time, the
variable OUTPUT1 is placed in FALSE, independently of what the user have already written on it.
PROGRAM SUM
VAR_INPUT
I ,J : INT;
END_VAR
VAR
SUM : INT;
END_VAR
(* Input 2 of the function defines if the sum must be times 2 or times 4*)
IF INPUT2 THEN
SUM := (I + J) * 2;
ELSE
SUM := (I + J) * 4;
END_IF;
END_PROGRAM
VAR_INPUT
I ,J, K : INT;
END_VAR
VAR
TEMP : INT;
END_VAR
TEMP := I + J;
IF INTERNAL_OVERFLOW THEN
OUTPUT1 := FALSE;
RETURN;
END_IF;
TEMP := TEMP + K;
IF INTERNAL_OVERFLOW THEN
OUTPUT1 := FALSE;
END_IF;
END_PROGRAM
When an overflow or underflow happen, the result of operation will be limited on type used in
operation. For example, add two variables of type INT, whose values are 15_000 and 25_000, the
result will be 32_767.
The local scope is the scope inside the functions and the program. The declared variables inside this
scope are visible only to the functions in which they were declared.
It is not allowed to declare the same name twice inside the same scope. However, when a local
variable name coincides with a global variable name, the name declared in the global scope will
always be used.
The lifetime of variables will depend on the local where they were declared. To variables inside the
functions, the value of those variables is destroyed at the end of the function call. The variable values
declared on the global scope are destroyed at the end of the module call, when the program returns to
ladder. The variables mapped in operands, which keep its value between the modules call, are
exceptions.
Commands
A program written in ST is composed by a sequence of “commands”. The types of commands are:
Commands of attribution
Commands of function call
Commands of program control
Commands of selection
Commands of repetition
Besides the commands, the verifier or the ST Language is able to evaluate mathematics expressions
to value calculus.
Expressions
Expressions are used to calculate or evaluate values. An expression is composed by several operands
and operators. They can be variable, literal or function call.
Operators can use one or two operands. When they use only one operator they are called “unary”. In
this case, they will always be located before the operand. When they use two operands, they are
called binary. In this case, the operator must be between the operands.
Both operators used in binary operations, in most of the operations, must be the of the same type.
When operators of different types are used, a conversion function must be used, according to the
description of the section Types Conversion .
Mathematics Operators
Those operators carry through mathematics operations between two operands. The operands can be
any ANY_NUM, but they cannot be different among them. The mathematics operator always returns
the same type of used operands.
Operator Description Application Change
INTERNAL_OVERFLOW
+ Addition ANY_NUM + ANY_NUM Yes
- Subtraction ANY_NUM – ANY_NUM Yes
- Denied - REAL Yes
- DINT
- INT
* Multiplication ANY_NUM * ANY_NUM Yes
/ Division ANY_NUM / ANY_NUM No
MOD Modulo of division ANY_INT MOD ANY_INT No
28
4. Programming
The operation Var1 MOD 0 will return 0 (zero). This operation will not create error of division by zero.
Relation Operators
Relation operands execute a comparison between two numerical types according to the description
on the Table 4-11. The operands must be of the same type and the operation returns always in a type
BOOL.
Operator Description Application
< Less than ANY_NUM < ANY_NUM
> Grater than ANY_NUM > ANY_NUM
<= Lesser or equal ANY_NUM <= ANY_NUM
>= Greater or equal ANY_NUM >= ANY_NUM
= Equality ANY = ANY
<> Inequality ANY <> ANY
29
4. Programming
- Negation
1
NOT Complement
* Multiplication
2 / Division
MOD Rest
+ Addition
3
- Subtraction
4 < , > , <= , >= Comparing
= Equality
5
<> Inequality
6 AND, & Operation “AND” boolean
7 XOR Operation “OR” exclusive boolean
8 (less) OR Operation “OR” boolean
In an expression that has more than one function, it is not possible to determine what function will be executed first.
EXPT Function
The EXPT function return the result of the operation (base exponent), where the base can be ANY_INT
or REAL and the exponent can be USINT. The type of result will be the same type of the base. This
function change the value of INTERNAL_OVERFLOW.
VAR
base, result : INT;
exponent : USINT;
END_VAR
base := 4;
exponent := 2;
result := EXPT( base, exponent );
(* result is equal to 16 *)
Integer Constants
Integer constants can be used in operation with ANY_INT since the literal value does not pass the
limit of the type of the other operand.
30
4. Programming
Attribution Command
Attribution is used to write a given value in a variable.
<variable> := <expression>;
Commands of selection
A command of selection executes one among several affirmation blocks. The chosen of the block is
defined by an evaluation function expressed by non-terminal <boolean_expression>.There are two
kinds of affirmation of selection: the command IF and the command CASE.
Command IF
IF command executes the affirmations after THEN if the test <boolean_expression> is true.
Optionally, it is possible insert other test conditions with the ELSIF clause, being only the
affirmation group where the first test is true executed.
Optionally, it is possible to specify an affirmation block to be executed, in case all the tests fail,
through the clause ELSE.
IF <boolean_expression> THEN <commands>
[ ELSE <commands> ]
END_IF;
Example:
IF A = B THEN
TEST := 10;
ELSEIF A = C THEN
TEST := 11;
ELSEIF A = D THEN
TEST := 12;
31
4. Programming
ELSEIF A = E THEN
TEST := 13;
ELSE
TEST := 0;
END_IF;
Command CASE
Command CASE also executes only one affirmation block. The block selection is done by comparing
the integer value of <integer_expression> with the values written on <cases>.
Optionally it is possible to specify an affirmation block to be executed if all the tests fail through the
clause ELSE.
CASE <integer_expression> OF
<cases> : <commands>
{ <cases> : <commands> }
[ ELSE <commands> ]
END_CASE;
0 : Bomb1 := 10;
END_CASE;
<commands>
END_WHILE;
Example:
WHILE I <= END_TABLE DO
END_WHILE;
32
4. Programming
Command REPEAT
The command REPEAT executes the commands block until the evaluation function
<boolean_expression> is true. Differently of the command WHILE, the command REPEAT
executes first the affirmation block and after tests the evaluation function. So, the affirmation block is
executed at least once.
REPEAT
<comands>
Example:
REPEAT
Command FOR
The command FOR allows executing an statement block repeatedly. The number of repetitions is
controled by a <control_variable>. This variable must be type USINT or INT and cannot be an
operand of the CPU of the programmable controller (%M, for example).
First, <control_variable> is initialized with the value of <start_exp>. In the beginning of each
repetition, it is verified if the value of <control_variable> exceeds the value defined by <end_exp>.
If it did not exceed, the statement block is executed. If not, the FOR command is stopped. In the end
of the block execution, <control_variable> is incremented in 1, or by the value defined by
<inc_exp><inc_exp>. The <control_variable> and the expressions <start_exp>, <expr_inicial>
and <end_exp> must be data of the same type (USINT or INT).
FOR <control_variable> := <start_exp> TO <end_exp> [ BY
<inc_exp><inc_exp><inc_exp><inc_exp> ] DO
<commands>
END_FOR;
or
FOR <control_variable> := <expr_start> TO <expr_end> DO
<commands>
END_FOR;
<control_variable>, inside the scope of the loop FOR, can be read but cannot be written.
During the iterations, the value <end_exp>evaluated in the beginning of FOR. That is, this expression is not evaluated again
during the command.
Example:
FOR I := START_TABLE TO END_TABLE DO
33
4. Programming
END_FOR;
34
5. Debug
5. Debug
Debug methods
This chapter describes as the debug of a module created in language ST, according to the orientations
on Chapter 4 – Programming. Besides forcing and monitoring variables, there are other resources
very useful when it is desired to debug an application, in ladder or ST language.
Afterwards, two methods are described. The first one uses execution in cycled mode of the
programmable controller, and the second one uses status machines to implement the debug.
Cycled Mode
When in cycled mode, the programmable controller does not execute periodically the module E001,
and remains waiting for commands of MasterTool programmer. To further details about mode cycled
check the Programming Manual of MasterTool XE.
Using the depuration in cycled mode, a verification of the variable values used can be done between
a cycle and other, verifying the variable values used and even force values to verify the behavior of
the application that is being debugged.
Status Machines
This debug method consists in creating a defined sequence of actions related to an index or status.
This manner, the code can be executed step by step, and each step can be a simple code line or a part
of any code.
A simples implementation of this status machine can be obtained through the IF command, according
to what is shown in the following example:
IF STATUS = 1 THEN
< commands block 1>
STATUS := 0;
END_IF;
IF STATUS = 2 THEN
< commands block 2>
STATUS := 0;
END_IF;
.
.
.
IF STATUS = n THEN
< commands block n>
STATUS := 0;
END_IF;
Each command block of the code presented is executed once, as the status index is zeroed at the end
of the block execution. Incrementing the variable of the status, different parts of the code can be
executed in a controlled manner. Between a status and another, different values can be forced to the
verification of the code behavior and the values obtained in the involved variables, for example.
35
5. Debug
associations and inappropriate use of instructions, easing the process of development of the ST
module.
The language ST verification can generate the following errors in a module:
Description Probably cause
Invalid Char The verifier did not recognize the typed text or char.
Invalid Symbol Indicates that the lexical notation used is incorrect. The possible notations
are listed below:
Identifier:
- Ended with "_"
- Have two consecutive "_".
Numeric Literal:
- Ended with "_"
- Have two consecutive "_".
- Floating point with exponent without value.
Commentary not closed with *) End of file was found before the end of comment.
Was expected <token 1> instead of Syntax Error. Probably was typed a wrong text, or a text is missing.
<text 2>
It was not expected <text 1> after <text Syntax Error. Probably was typed a wrong text, or a text is missing.
2>
It was not expected <text 1> Syntax Error. Probably was typed a wrong text, or a text is missing.
The Identifier <name> was already The Identifier was already declared. Use another name.
declared on this scope.
Identifier Identifier
Variable <name> was not declared. The variable was not declared. Declare the variable before use it.
Vector<name> was not declared. The vector was not declared. Declare the vector before use it.
Function <name> was not declared. The function was not declared. Declare the function before use it.
Was expected an integer expression. The commands CASE expect integer expressions to test. The expression
used is not integer.
Impossible to convert <type 1> to <type The conversion between the types is not allowed. Try using an explicit
2> function conversion.
Is not possible execute the operation The operation is not valid to the types. Use de conversion function to
<operation> between the types <left convert to correct type.
type> and the <right type>.
Is not possible execute the operation The operation is not valid to the type. Use de conversion function to
<operation> with <right type>. convert to correct type.
Command EXIT can not be executed The command EXIT can not be executed out of a loop WHILE, FOR or
out of a loop WHILE, FOR or REPEAT. REPEAT.
This code will never be executed. The code was written after a command of RETURN or EXIT and will
never be executed.
Recursive calling of the function A function can not be called recursively.
<name>
One part of the function <name> does Exist a part of the code that do not return a value through the command:
not return a value. Function := value;
Function <name> was called with more
parameters than declared.
Function <name> was called with less
parameters than declared.
Symbol <name> is not a function Was expected that the symbol was a function.
Symbol <name> is not a vector Was expected that the symbol was a vector.
Symbol <name> is not a variable Was expected that the symbol was a variable.
Symbol <name> is not a constant Was expected that the symbol was a constant.
36
5. Debug
37
5. Debug
Operand Description
38
5. Debug
39
6. Examples of Use
6. Examples of Use
This chapter presents examples of programs written in ST.
Buffer of events
The module F-EVT.030 inserts an event in the event buffer implemented in the operand %TM0010.
Each event operand occupies 3 positions in the buffer. The first position stores the minute value in
the high byte and the second value in the low byte. The second position stores the time. The third
position stores the event code.
(*
Store the events in a TM. Each event is stored in 3 positions.
High byte low byte
pos 0 minute second
pos 1 hour
pos 2 event
(* Constants *)
VAR CONSTANT
BUFFER_INF : INT := 1; (* First array index *)
BUFFER_SUP : INT := 120; (* Last array index *)
BUFFER_LIMIT : INT := 40; (* Maximal number of elements on buffer *)
END_VAR
(* Functions-------------------------------------------------------------------------- *)
(*
Function: InsertValue
(* Control overflow *)
IF BUFFER_NUM_EVENTS = BUFFER_LIMIT THEN
INSERT_VALOR := TRUE;
ELSE
BUFFER_NUM_EVENTS := BUFFER_NUM_EVENTS + 1;
INSERT_VALUE := FALSE;
END_IF;
40
6. Examples of Use
END_FUNCTION
(* Program -------------------------------------------------------------------------- *)
PROGRAM F_EVT_030
(*CHF input parameters*)
VAR_INPUT
EVENT : INT; (* Parameter 1 of CHF*)
HOUR : INT; (* Parameter 2 of CHF*)
MINUTE : INT; (* Parameter 3 of CHF*)
SECOND : INT; (* Parameter 4 of CHF*)
END_VAR
(* Insert event *)
INSERT_VALUE( MINUTE*256 + SECOND );
INSERT_VALUE( HOUR );
INSERT_VALUE( EVENT );
END_PROGRAM
Conversion of Values
The module P-CONV.040 converts the table degree values Fahrenheit to Celsius, storing the values
in another table.
(*
Convert the temperatures from ºF to ºC
*)
(* Functions-------------------------------------------------------------------------- *)
(*
Function: Convert
Execute the conversion from one unit to another. Retorns the converted value.
Makes the operation using the REAL type to obtain precision.
*)
END_FUNCTION
(* Program -------------------------------------------------------------------------- *)
PROGRAM P_CONV_040
(* Variables *)
VAR
TEMPERATURES_CELSIUS AT %TM0010[ 0 ]: ARRAY[ 1..100 ] OF INT;
TEMPERATURES_FAHRENHEIT AT %TM0011[ 0 ]: ARRAY[ 1..100 ] OF INT;
I : INT;
END_VAR
(* Constants *)
VAR CONSTANT
START : INT := 1;
END : INT := 100;
END_VAR
41
6. Examples of Use
32, 232 );
END_FOR;
END_PROGRAM
42
7. Appendix
7. Appendix
Keywords
Here are presented a relation of keyworks pertaining to ST language. Not all of them are currently
used by ST Language, but they were saved to future implementations.
AT RETAIN
ARRAY OF STRUCT END_STRUCT
CASE OF ELSE END_CASE TASK
INPUT1 INPUT2 INPUT3 TYPE END_TYPE
OUTPUT1 OUTPUT2 OUTPUT3 VAR_IN_OUT END_VAR
INTERNAL_* VAR_OUTPUT END_VAR
EXIT VAR_EXTERNAL END_VAR
FALSE TRUE VAR_ACESS END_VAR
FOR TO BY DO END_FOR WITH
FUNCTION END_FUNCTION BYTE WORD DWORD LWORD
IF THEN ELSIF ELSE END_IF DINT LINT UDINT U LINT
REPEAT UNTIL END_REPEAT LREAL TRUNC
RETURN TIME DATE TIME_OF_DAY TOD
DATE_AND_TIME DT
CONSTANT
ANY ANY_NUM ANY_REAL
VAR END_VAR
ANY_INT ANY_BIT STRING
VAR_INPUT END_VAR
ANY_DATE
WHILE DO END_WHILE
ABS SQRT LN LOG EXP SIN COS
BOOL
TAN ASIN ACOS ATAN
SINT USINT INT UINT
SEL MAX MIM LIMIT MUX
REAL
LEFT RIGHT MID CONCAT INSERT
AND OR XOR NOT MOD DELETE REPLACE LEN FIND
*_TO__** (conversion types) JMP CAL RET
EN ENO ADD MUL DIV EXPT MOVE
F_EDGE SHL SHR ROR ROL
FUNCTION_BLOCK GT GE EQ LE LT NE
END_FUNCTION_BLOCK N R S L D P SD DS SL LD ST
PROGRAM WITH ACTION END_ACTION
PROGRAM END_PROGRAM INITIAL_STEP END_STEP
R_EDGE STEP END_STEP
READ_ONLY READ_WRITE TRANSITION FROM TO
RESOURCE ON END_REPEAT END_TRANSITION
43
8. Glossary
8. Glossary
Active CPU In a redundant system is the CPU that is controlling the system – reading the inputs, executing the
application program and activating the outputs.
Jumpers Small connector to shortcut pins located on a circuit board. Used to set addresses or configuration.
Algorithm Finite and well defined sequence of instructions with the goal to solve problems
Altus Relay and Blocks Set of rules, conventions and syntaxes used when building a application program to run in an Altus PLC.
Language
Application Program Program downloaded into the PLC and has the instructions that define how the machinery or process will
work.
Arrestor Lightning protection device using inert gases.
Assembly Language Microprocessor programming language, it is also known as machine language
Backup CPU In a redundant system, it is the CPU supervising the active CPU. It is not controlling the system, but is
ready to take control if the main CPU fails.
Bit Basic information unit, it may be at 1 or 0 logic level.
BT Battery test.
Bus Set of electrical signals that are part of a logic group with the function of transferring data and control
between different elements of a subsystem
Byte Information unit composed by eight bits.
C-Module See Configuration Module.
Commercial Code Product code formed by the letters PO and followed by four digits.
Commissioning Final verification of a control system, when the application programs of all CPUs and remote stations are
executed together, after been developed and verified individually.
Configuration Module Also referred to as C-Module. Unique module in a remote application program that carries several needed
parameters for its operation, such as the operands quantity and disposition of I/O modules in the bus
CPU Central Processing Unit. It controls the data flow, interprets and executes the program instructions as well
as monitors the system devices.
Diagnostic Procedures to detect and isolate failures. It also relates to the data set used for such tasks, and serves for
analysis and correction or problems.
E2PROM Electrically Erasable Programmable Read-Only Memory. Non-volatile memory that may be electrically
erased by the electronic circuit.
E-Module See Execution Module
Encoder Normally refers to position measurement transducer.
EPROM Erasable Programmable Read Only Memory. Memory for read only that may be erased and programmed
out of the circuit. The memory doesn‟t loose its contents when powered off.
ER Acronym used on LEDs to indicate error
ESD Electrostatic Discharge.
Execution Module Application program modules. May be one of three types: E000, E001 and E018. The E000 module is
executed just once upon system powering or when setting programming into execution mode. The E001
module has the main program that is executed cyclically, while the E018 module is activated by the time
interruption.
Firmware The operating system of a PLC. It controls the PLC basic functions and executes the application programs.
FLASH EPROM Non volatile memory that may be electrically erased and programmed..
F-Module See Function Module.
FMS Fieldbus Message System.
Function Module Application software module called from the main module (E-module) or from another function module or
procedure module. It passes parameters and return values. Works as a subroutine.
Hardkey Connector normally attached to the parallel port of a microcomputer to avoid the use of illegal software
copies
Hardware Physical equipment used to process data where normally programs (software) are executed
I/O See Input/Output.
I/O Module Hardware module that is part of the Input/Output (I/O) subsystem.
I/O Subsystem Set of digital or analog I/O modules and interfaces of a PLC
IEC 61131 Generic international standard for operation and use of programmable controllers.
IEC Pub. 144 (1963) International standard for protection of accidental access and sealing the equipment from water, dust and
other foreign objects.
IEC-536-1976 International standard for electrical shock protection.
44
8. Glossary
IEC-801-4 International standard for tests of immunity against interference by pulses burst
IEEE C37.90.1 (SWC) SWC stands for Surge Withstand Capability. This is the international standard for oscillatory wave noises
protection.
Input/Output Also known as I/O. Data input or output devices in a system. In PLCs these are typically the digital or
analog modules that monitor or actuate the devices controlled by the system.
Interface Normally used to refer to a device that adapts electrically or logically the transferring of signals between
two equipments.
Interruption Priority event that temporarily halts the normal execution of a program. The interruptions are divided into
two generic types: hardware and software. The former is caused by a signal coming from a peripheral,
while the later is caused within a program
ISOL. Acronym used to indicate isolation or isolated.
kbytes Memory size unit. Represents 1024 bytes.
LED Light Emitting Diode. Type of semiconductor diode that emits light when energized. It‟s used for visual
feedback.
Logic A graphic matrix in Altus Relay and Blocks Language where are inserted the relay diagram language
instructions that are part of an application program are inserted. A set of sequentially organized logics
makes up a program module.
MasterTool The Altus WINDOWS® based programming software that allows application software development for
PLCs from the Ponto, Grano, Piccolo, AL-2000, AL-3000 and Quarks series. Throughout this manual, this
software is referred by its code or as MasterTool Programming.
Menu Set of available options for a program, they may be selected by the user in order to activate or execute a
specific task
Module (hardware) Basic element of a system with very specific functionality. It‟s normally connected to the system by
connectors and may be easily replaced.
Module (software) Part of a program capable of performing a specific task. It may be executed independently or in conjunction
with other modules through information sharing by parameters.
Module address: Address used by the CPU in order to access a specific I/O module.
Nibble Information unit composed of four bits.
Not-operant CPU In a redundant system this is the CPU that is neither active nor backup. May not take control of the system.
Operands Elements on which software instructions work. They may represent constants, variables or set of variables.
PA See Jumpers.
PLC See Programmable Controller.
P-Module See Procedure Module.
Procedure Module PLC application software module called from the main module (E-module) or from another procedure
module or function module that does not have parameters.
PROFIBUS PA Means PROFIBUS Process Automation.
Programmable Also know as PLC. Equipment controlling a system under the command of an application program. It is
Controller composed of a CPU, a power supply and I/O modules.
Programming Language Set of rules, conventions and syntaxes utilized when writing a program.
RAM Random Access Memory. Memory where all the addresses may be accessed directly and in random order
at the same speed. It is volatile, in other words, its content is erased when powered off, unless there is a
battery to keep its contents.
Redundant CPU The other CPU in a redundant system. For instance, the redundant CPU of CPU2 is CPU1 and vice versa.
Redundant system System with a backup or double elements to execute specific tasks. Such system may suffer certain
failures without stopping the execution of its tasks.
Ripple Oscillation present in continuous voltages.
RX Acronym used to indicate serial reception.
Scan Cycle A complete execution of the PLC application program.
Sockets Part to plug in integrated circuits or other components, thus facilitating their substitution and maintenance.
Software Computer programs, procedures and rules related to the operation of a data processing system
Supervisory Station Equipment connected to a PLC network with the goal of monitoring and controlling the process variables
Tag Name associated to an operand or to a logic that identifies its content.
Toggle Element with two stable states that are switched at each activation.
Hot swap Procedure of replacing modules in a system without powering it off. It is a normal procedure for I/O
modules.
TX Acronym used to indicate serial transmission.
Upload Reading a program or configuration from the PLC.
Varistor Protection device against voltage spikes.
Watchdog timer Electronic circuit that checks the equipment operation integrity.
WD Acronym for watchdog. See Watchdog timer
Word Information unit composed by 16 bits.
45