The binary logic operations are executed in SCL with logic expressions in conjunc- tion with binary tags or expressions which deliver a binary result. The binary oper- ations can be “nested” using parentheses and thus influence the processing sequence (Table 10.2).
10.2.1 Scanning for signal states “1” and “0”
The scanning of a binary operand in SCL is always the direct scanning of the status of the binary operand. This corresponds to scanning for signal state “1”. If scanning for signal state “0” is required for the program function, one uses the NOT operator in order to negate the result of scan. NOT can also be used to negate the result of binary expressions.
The example in Fig. 10.3 shows the two “Start” and “Stop” pushbuttons. When pressed, they output the signal state “1” in the case of an input module with sinking input. This signal state is used in the logic operation.
The “/Fault” signal is not active in the normal case. Signal state “1” is then present and is negated by means of the NOT operator, and therefore it does not result in resetting of the “Fan” tag. If “/Fault” becomes active, the “Fan” tag is to be reset. The active “/Fault” signal delivers signal state “0” and results in resetting of “Fan”.
Table 10.2 Binary logic operations with SCL
Operation Operand Function
&
AND OR XOR
Binary operand or binary expression
Binary operand or binary expression
Binary operand or binary expression
Binary operand or binary expression
Scan for signal state “1” and link according to AND logic operation
Scan for signal state “1” and link according to AND logic operation
Scan for signal state “1” and link according to OR logic operation
Scan for signal state “1” and link according to exclusive OR logic operation
NOT – Negation of result of logic operation
The logic expression in the example uses NOT both for negation of the result of scan of “/Fault” and for negation of the result of the second OR function. You can also for- mulate the logic operation differently:
“Fan”:=(“Start” OR “Fan”) AND NOT “Stop” AND “/Fault”;
10.2.2 AND function
An AND function is fulfilled if all function inputs have the result of scan “1”. A description of the AND function is provided in Chapter 12.1.3 “AND function, series connection” on page 464.
SCL implements the AND logic operation using a logic expression with the opera- tors & or AND, which link binary tags or binary expressions.
Fig. 10.4 shows an example of an AND logic operation. The #Fan1.running and
#Fan2.running tags are scanned for signal state “1”, and the two results of the scans are linked according to an AND logic operation. The AND function is fulfilled (deliv- ers signal state “1”) if both fans are running.
Fig. 10.3 Scanning for signal states “1” and “0”
//AND function
#Display.twoFans := #Fan1.running AND #Fan2.running;
//OR function
#Display.Min_oneFan := #Fan1.running OR #Fan2.running;
//Exclusive OR function
#Display.oneFan := #Fan1.running XOR #Fan2.running;
Fig. 10.4 Examples of binary logic operations with SCL
"Fan"
%I1.3
%I1.2
%I1.1
%Q4.
L+
G
1
"Start" "Stop" "/Fault"
Example of scans for signal state "1" and signal state "0"
"Fan":=("Start" OR "Fan") AND NOT ("Stop" OR NOT "/Fault");
10.2.3 OR function
An OR function is fulfilled if one or more function inputs have the result of scan “1”.
A description of the OR function is provided in Chapter 12.1.4 “OR function, parallel connection” on page 465.
SCL implements the OR logic operation using a logic expression with the operator OR, which links binary tags or binary expressions.
Fig. 10.4 shows an example of an OR logic operation. The #Fan1.running and
#Fan2.running tags are scanned for signal state “1”, and the two results of the scans are linked according to an OR logic operation. The OR function is fulfilled (delivers signal state “1”) if one of the fans is running or if both fans are running.
10.2.4 Exclusive OR function
An exclusive OR function (antivalence function) is fulfilled if an odd number of function inputs has the scan result “1”. A description of the exclusive OR function is provided in Chapter 12.1.5 “Exclusive OR function, non-equivalence function” on page 465.
SCL implements the exclusive OR logic operation using a logic expression with the operator XOR, which links binary tags or binary expressions.
Fig. 10.4 shows an example of an exclusive OR logic operation. The #Fan1.running and #Fan2.running tags are scanned for signal state “1”, and the two results of the scans are linked by an exclusive OR logic operation. The exclusive OR function is fulfilled (delivers signal state “1”) if only one of the fans is running.
10.2.5 Combined binary logic operations
The AND, OR, and exclusive OR functions can be freely combined with one another.
With SCL the operators have the following priority regarding execution: AND or &
are executed before XOR, followed by OR. NOT is executed before the logic opera- tion operators.
Logic operations such as the ORing of AND functions do not require parentheses, as shown in the top example in Fig. 10.5. The first AND function is fulfilled if fan 1 is running and fan 2 is not running, the second function if fan 1 is not running and fan 2 is running. The #Display.oneFan_1 tag is set if the first AND function is fulfilled or if the second AND function is fulfilled (or if both are fulfilled, but this is not the case in this example).
//ORing of AND functions – does not require parentheses
#Display.oneFan_1 := #Fan1.running AND NOT #Fan2.running OR NOT #Fan1.running AND #Fan2.running;
//ANDing of OR functions – parentheses required
#Display.oneFan_2 := (#Fan1.running OR #Fan2.running) AND (NOT #Fan1.running OR NOT #Fan2.running);
Fig. 10.5 Examples of combined binary logic operations with SCL
This logic operation does not require parentheses since the AND function is pro- cessed “before” the OR function because of its higher priority. This also applies to ORing of exclusive OR functions or the exclusive ORing of AND functions.
The processing priority can be influenced using parentheses. The expressions in the parentheses are processed first as it were. Parentheses can be nested.
Logic operations such as the ANDing of OR functions require parentheses, as shown in the bottom example in Fig. 10.5. The first OR function is fulfilled if at least one fan is running or if both fans are running, the second if at least one fan is not run- ning or if neither fan is running. The two OR functions are present in parentheses and the results of the logic operation are linked according to an AND logic opera- tion. The #Display.oneFan_2 tag is set if only one of the fans is running.
10.2.6 Negating result of logic operation
The NOT operator negates the result of logic operation at any position in an logic operation. Using the NOT operator it is possible in a simple manner to obtain:
b a NAND function (negated AND function, is fulfilled if at least one input has the result of scan “0”),
b a NOR function (negated OR function, is fulfilled if all inputs have the result of scan “0”), and
b an inclusive OR function (equivalence function, negated exclusive OR function, is fulfilled if an even number of inputs has the result of scan “1”).
Fig. 10.6 shows the negation of binary functions. The functions are present in parentheses since they have a lower processing priority than NOT. The result of the binary function is generated first and subsequently negated.