This chapter describes programming with Structured Control Language (SCL); it uses examples to show how the program functions are represented in SCL. You can find a description of the individual functions, e.g. comparison functions, in Chap- ters 12 “Basic functions” on page 461, 13 “Digital functions” on page 507, and 14
“Program flow control” on page 560.
Use of the program and symbol editor, which generally applies to all programming languages, is described in Chapter 6 “Program editor” on page 253.
SCL is used to program the contents of blocks (the user program). What blocks are, and how they are created, is described in Chapters 5.2.3 “Block types” on page 156 and 6.3 “Programming a code block” on page 257.
10.1.1 Programming with SCL in general
You use SCL to program the control function of the programmable controller – the user program (control program). The user program is organized in different types of blocks.
Fig. 10.1 shows the SCL program for a FIFO register. With a rising edge at #Write, this block writes the value present at the #Input parameter into a FIFO register. With a rising edge at #Read, the value at #Output is output again. The values are read out in the order in which they were written into the register (FIFO, first in first out). The register can be emptied using #Delete. The two displays #Full and #Empty show the status of the register (#Full and #Empty are each set following writing or reading).
The block works with a write pointer and a read pointer.
The program editor constructs an SCL program line by line. You commence with the first statement in the first line. Each SCL statement is concluded by a semicolon.
You can write several statements in one line, or one statement can occupy several lines.
You can make the SCL program clearer and easier to read by using comments and empty lines. Comments and empty lines have no influence on the function of the SCL program.
Line comments commence with two slashes and terminate at the end of the line.
Block comments commence with left parenthesis and asterisk, can extend over several lines, and terminate with asterisk and right parenthesis.
In order to program an SCL statement, use the keyboard to enter the statements in a line of the input field. Dragging the statement with the mouse from the program elements catalog is of advantage with SCL if you import functions with a parameter list into your program. To call self-created blocks, drag them from the Program blocks folder into a line.
10.1.2 SCL statements and operators
The SCL program consists of a sequence of individual STL statements. Fig. 10.2 shows which types of SCL statements exist.
Fig. 10.1 Example of a block with SCL program
Fig. 10.2 Types of SCL statements xxx
IF CASE FOR WHILE REPEAT
END_xxx END_IF END_CASE END_FOR END_WHILE END_REPEA T AND
>=
+ :=
:=
:=
:=
;
;
;
;
;
;
;
;
;
;
;
;
; //
//
//
//
:
:
:
:
General SCL instruction
Value assignment with assignment operator
Control statement
Block call SCL instruction
Value assignment
Control statement
Block call SCL statements
Most extended instructions in the program element catalog are calls of system blocks with return value.
The simplest case with a Value assignment is that the content of a tag is transferred to another tag. Control statements control the program execution, for example with program loops. Block calls are used to continue program execution in the called block.
Operators
An expression represents a value. It can comprise a single operand (a single tag) or several operands (tags) which are linked by operators.
Example: “a + b” is an expression; “a” and “b” are operands, “+” is the operator.
The sequence of logic operations is defined by the priority of the operators and can be controlled by parentheses. Mixing of expressions is permissible providing the data types generated during calculation of the expression permit this.
SCL provides the operators specified in Table 10.1. Operators of equal priority are processed from the left to the right.
Expressions
An expression is a formula for calculating a value and consists of operands (tags) and operators. In the simplest case, an expression is an operand, a tag, or a con- stant. A sign or a negation can also be included.
An expression can consist of operands which are linked together by operators.
Expressions can also be linked by operators. Expression can therefore have a very Table 10.1 Operators with SCL
Logic operation Name Operator Priority
Parentheses Left parenthesis, right parenthesis (, ) 1
Arithmetic Power ** 2
Unary plus, unary minus (sign) +, – 3
Multiplication, division *, /, DIV, MOD 4
Addition, subtraction +, – 5
Comparison Less than, less than-equal to, greater than, greater than-equal to
<, <=, >, >= 6
Equal to, not equal to =, <> 7
Binary logic operation Negation (unary) NOT 3
AND logic operation AND, & 8
Exclusive OR XOR 9
OR logic operation OR 10
Assignment Assignment := 11
“Unary” means that this operator has a fixed assignment to an operand
complex structure. Parentheses can be used to control the processing sequence in an expression.
The result of an expression can be assigned to a tag or a block parameter or used as a condition in a control statement.
Expressions are distinguished according to the type of logic operation into arithme- tic expressions, comparison expressions, and logic expressions.