General Introduction to Basic SCL Terms
7.7 Data Types
A declaration of a variable must always specify what data type that variable is. The data type determines the permissible range of values for the variable and the operations that it can be used to perform.
The data type determines
S the type and interpretation of a data element, S the permissible range of values for a data element,
S the permissible number of operations that can be performed by an address of a variable, and
S the format of the data of that data type.
The following types of data type are distinguished:
Table 7-2 Elementary Data Types
Data Type Explanation
Elementary Standard type provided by SCL
Complex Can be created by combining elementary data types
User-defined Defined by the user for specific applications and assigned a user-defined name
Parameter types Can only be used for declaring parameters
Elementary data types define the structure of data elements which can not be subdivided into smaller units. They conform to the definition given in the standard DIN EN 1131-3.
SCL has twelve predefined elementary data types as follows:
BOOL CHAR INT TIME
BYTE DINT DATE
WORD REAL TIME_OF_DAY
DWORD S5TIME
Summary
Types of Data Type
Elementary Data Types
Complex data types define the structure of data elements which are made up of a combination of other data elements. SCL allows the following complex data types:
DATE_AND_TIME STRING
ARRAY STRUCT
These are global data types (UDTs) which can be created in SCL for user-specific applications. This data type can be used with its UDT identifier UDTx (x represents a number) or an assigned symbolic name in the
declaration section of a block or data block.
In addition to elementary, complex and user-defined data types, you can also use parameter types for defining parameters. SCL provides the following parameter types for that purpose:
TIMER BLOCK_FB POINTER ANY
COUNTER BLOCK_FC
BLOCK_DB BLOCK_SDB Complex Data
Types
User-Defined Data Types
Parameter Types
General Introduction to Basic SCL Terms
7.8 Variables
An identifier whose assigned value can change during the process of execution of a program is called a variable. Each variable must be
individually declared (that is, defined) before it can be used in a logic block or data block. The declaration of a variable specifies that an identifier is a variable (rather than a constant, etc.) and defines the variable type by assigning it to a data type.
The following types of variable are distinguished on the basis of their applicability:
S Local data S Global user data
S Permissible predefined variables (CPU memory areas)
Local data are declared in a logic block (FC, FB, OB) and apply only within that logic block. Specifically these are the following:
Table 7-3 Local Data of a Block
Variable Type Explanation
Static Variables A static variable is a local variable whose value is retained throughout all block cycles (block memory). It is used for storing values for a function block.
Temporary Variables Temporary variables belong to a local logic block and do not occupy any static memory. Their values are retained for a single block cycle only. Temporary variables can not be accessed from outside the block in which they are declared.
Block Parameters Block parameters are formal parameters of a function block.
or a function. They are local variables that are used to pass over the current parameters specified when a block is called.
Declaration of Variables
Local Data
These are data or data areas that can be accessed from any point in a program. To use global user-defined variables, you must create data blocks (DBs).
When you create a DB, you define its structure in a structure declaration.
Instead of a structure declaration, you can use a user-defined data type (UDT). The order in which you specify the structural components determines the sequence of the data in the DB.
You can access the memory areas of a CPU directly from any point in the program via the address identifiers (see Section 7.5) without having to declare those variables first.
Apart from that, you can always address those memory areas symbolically.
Assignment of symbols is performed globally in this case by means of the symbol table in STEP 7. For more details, refer to /231/.
Global
User-Defined Data
CPU Memory Areas
General Introduction to Basic SCL Terms
7.9 Expressions
An expression stands for a value that is calculated either when the program is compiled or when it is running. It consists of one or more addresses linked by operators. The order in which the operators are applied is determined by their priority and can also be controlled by bracketing.
S Mathematical expressions S Logical expressions S Comparative expressions
A typical example of a mathematical expression is (b*b–4*a*c)/(2*a)
The identifiers a and b and the numbers 4 and 2 are the addresses, the symbols *, – and / are the corresponding operators (multiply, subtract and divide). The complete expression represents a numerical value.
A comparative expression is a logical expression that can be either true or false. The following is an example of a comparative expression:
Setpoint < 100.0
In this expression, SETPOINT is a real variable, 100.0 a real number and the symbol < a comparator. The expression has the value True if the value of Setpoint is less than 100.0. If it is not, the value of the expression is False.
The following is a typical example of a logical expression:
a AND NOT b
The identifiers a and b are the addresses, the keywords AND and NOT are logical operators. The complete expression represents a bit pattern.
Summary
Mathematical Expressions
Comparative Expressions
Logical Expression
7.10 Statements
An SCL statement is an executable action in the code section of a logic block. There are three basic types of statements in SCL:
S Value assignments (assignment of an expression to a variable) S Control statements (repetition or branching statements)
S Subroutine calls (statements calling or branching to other logic blocks)
The following is an example of a typical value assignment:
SETPOINT := 0.99*PREV_SETPOINT
This example assumes that SETPOINT and PREV_SETPOINT are real variables. The assignment instruction multiplies the value of
PREV_SETPOINT by 0.99 and assigns the product to the variable SETPOINT. Note that the symbol for assignment is := .
The following is an example of a typical control statement:
FOR Count :=1 TO 20 DO
LIST[Counter] := VALUE+Counter;
END_FOR;
In the above example, the statement is performed 20 times over. Each time, the recalculated value in the array LIST is entered in the next highest position on the list.
By specifying a block identifier for a function (FC) or a function block (FB) you can call the block declared for that identifier. 1 If the declaration of the logic block includes formal parameters, then current addresses can be assigned to the formal parameters when the formal parameters are called.
All parameters listed in the declaration sections VAR_INPUT, VAR_OUTPUT and VAR_IN_OUT
of a logic block are referred to as formal parameters - in contrast, the corresponding parameters included in the subroutine calls within the code section are termed actual parameters.
Assignment of the actual parameters to the formal parameters is part of the subroutine call.
Summary
Value
Assignments
Control Statements
Subroutine Call
General Introduction to Basic SCL Terms