Programming binary logic operations with SCL

Một phần của tài liệu Hans berger automating with SIMATIC s7 1200 configuring programming (Trang 289 - 295)

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 se- quence (Table 9.2).

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

Fig. 9.3 shows a sensor connected to the programmable controller which is scanned for signal state “1” (left-hand side) and for signal state “0” (right-hand side). The result of the scan is connected directly to a contactor.

Table 9.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 combination according to AND logic operation

Scan for signal state “1” and combination according to AND logic operation

Scan for signal state “1” and combination according to OR logic operation

Scan for signal state “1” and combination according to exclusive OR logic operation

NOT – Negation of result of logic operation

When scanning for signal state “1” (left-hand side), the result of the scan is equal to the signal state of the sensor: if sensor S1 is open, input %I1.0 has the signal state

“0” and the logic operation is not fulfilled. Contactor C1 controlled by output %Q4.0 does not pull up. If sensor S1 is then activated, input %I1.0 has the signal state “1”.

The function is fulfilled, and the contactor C1 connected to output %Q4.0 pulls up.

When scanning for signal state “0” (right-hand side), the result of the scan is equal to the negated signal state of the sensor: if sensor S2 is open, input %I1.1 has the signal state “0”. The negation symbol negates this signal state, and the result of the scan is “1”. The logic operation is thus fulfilled. Contactor C2 controlled by out- put %Q4.1 pulls up. If sensor S2 is then activated, input %I1.1 has the signal state

“1”. The negation symbol negates the signal state, and the result of the scan is “0”.

The function is not fulfilled, and contactor C2 connected to output %Q4.1 does not pull up.

9.2.2 Taking account of the sensor type for SCL

If you scan a sensor in your program, you must take into consideration whether it is an NO or NC contact. Depending on the type of sensor, different signal states are present at the corresponding input when the sensor is activated: “1” with an NO contact and “0” with an NC contact. It is not possible for the control processor to determine whether an NC or NO contact is connected to an input. It can only recog- nize the signal state “1” or “0”.

Fig. 9.3 Scanning for signal states “1” and “0”

S1 S2

C1 C1 C2 C2

S1 S2

%I1. 0 %I1. 1

%Q4.0 %Q4.0 %Q4.1 %Q4.1

%I1. 0 %I1.1

“0”

“1”

“1”

“1”

“1”

“0”

“0”

“0”

Scan for signal state “1” Scan for signal state “0”

Sensor activated

Sensor activated

%Q4.1 := NOT %I1.1; %Q4.1 := NOT %I1.1;

%Q4.0 := %I1.0; %Q4.0 := %I1.0;

With SCL, a binary operand is always scanned for signal state “1”.

The signal state of the binary operands is integrated directly in the logic operation (the assignment in the example).

The scan for signal state “0” is programmed using the NOT negation. NOT negates the signal state of the binary operand before it is adopted into the logic operation (the assignment in the example).

If you write the program to obtain “1” when a sensor is activated in order to link it further, you must scan the input in different ways depending on the type of sensor.

The negation NOT is available for this purpose. Direct scanning delivers “1” if the scanned input is also “1”. Together with the NOT negation, the scan then delivers

“1” if the scanned input is “0”. In this manner you can also directly scan inputs which are to execute activities when the signal state is “0” (“zero-active”) and con- nect the result of the scan further.

The example in Fig. 9.4 shows the programming dependent on the type of sensor.

The AND function used is then fulfilled, i.e. the function result has signal state “1”

Fig. 9.4 Taking account of the sensor type for SCL Neither sensor is activated

Neither sensor is activated

Both sensor is activated

Both sensor is activated

The contactor pulls up S3

S5

S3

S5 S4

S6

S4

S6 C3

C4

C3

C4

%I1.2

%I1.4

%I1.2

%I1.4

%I1.3

%I1.5

%I1.3

%I1.5

%Q4.2

%Q4.3

%Q4.2

%Q4.3

“0”

“0” “0”

“0” “1”

“1”

“1”

“1”

“1”

“1”

“0”

“0”

Case 1: Both sensors are NO contacts

Case 2: The sensors are one NO contact and one NC contact

%Q4.3 := %I1.4 AND NOT %I1.5;

%Q4.3 := %I1.4 AND NOT %I1.5;

%Q4.3 := %I1.4 AND %I1.5; %Q4.3 := %I1.4 AND %I1.5;

When actuated, an NO contact returns signal state “1”. If both sensors are actuated, both inputs have signal state “1” and a scan result of “1” for a direct scan. The AND function is thus fulfilled and the contactor at the output picks up."

The contactor pulls up

When actuated, an NC contact returns signal state “0”. If both sensors are actuated, the NO contact at the input has signal state “1” and the NC contact has signal state “0”. In order to get signal state “1”

when the NC contact is actuated, the scan result must be negated. Then, if both sensors are actuated, the AND function is fulfilled and the contactor at the output picks up."

if the result of the scan “1” is present at all function inputs (for description, see Chapter 9.2.3 „AND function“).

In the first case, two NO contacts are connected to the programmable controller, in the second case one NO contact and one NC contact. In both cases, a contactor con- nected to an output is to pull up when both sensors are activated. If an NO contact is activated, the signal state at the input is “1” and is directly scanned so that the AND function can be fulfilled when the sensor is activated. If both NO contacts are acti- vated, the AND logic operation is fulfilled and the contactor pulls up.

When activating an NC contact, the signal state at the input is “0”. In order to achieve scan result “1” in this case when activating the contact, it is necessary to negate the scan result. Therefore, in the second case, the NO contact must be scanned directly and the NC contact must be scanned with the negation NOT in order for the contactor to pull up when both sensors are activated.

9.2.3 AND function

An AND function is fulfilled and provides the result “1” (TRUE) if all function inputs have the scan result “1”. A description of the AND function is provided in Chapter 10.1.5 “AND function, series connection” on page 331.

SCL implements the AND logic operation using a logic expression with the opera- tors & or AND, which link binary tags or binary expressions.

Fig. 9.5 shows an example of an AND logic operation with three inputs. The tags

Input 1” and “Input 2” are scanned directly. The scan result of the tag “Input 3” is negated. All three scan results are linked according to an AND logic operation. The AND function is fulfilled if “Input 1” and “Input 2” have signal state “1” and “Input 3”

has signal state “0”.

9.2.4 OR function

An OR function is fulfilled and provides the result “1” (TRUE) if one or more func- tion inputs have scan result “1”. A description of the OR function is provided in Chapter 10.1.6 “OR function, parallel connection” on page 332.

SCL implements the OR logic operation using a logic expression with the operator OR, which links binary tags or binary expressions.

Fig. 9.5 Examples of binary logic operations with SCL

Fig. 9.5 shows an example of an OR logic operation with three inputs. The tags

Input 1” and “Input 2” are scanned directly. The scan result of the tag “Input 3” is negated. All three scan results are linked according to an OR logic operation. The OR function is fulfilled if “Input 1” or “Input 2” has signal state “1” or “Input 3” has signal state “0”.

9.2.5 Exclusive OR function

An exclusive OR function (antivalence function) is fulfilled and provides the result

“1” (TRUE) if an odd number of function inputs have scan result “1”. A description of the exclusive OR function is provided in Chapter 10.1.7 “Exclusive OR function, non-equivalence function” on page 333.

SCL implements the exclusive OR logic operation using a logic expression with the operator XOR, which links binary tags or binary expressions.

Fig. 9.5 shows an example of an exclusive OR logic operation with two inputs. The tags “Input 1” and “Input 2” are scanned directly. The scan results are linked accord- ing to an exclusive OR logic operation. The exclusive OR function is fulfilled (it sup- plies the value TRUE) if the signal states at “Input 1” and “Input 2” are different.

9.2.6 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. 9.6. The first AND function is fulfilled if “Input 1”

and “Input 2” have signal state “1”; the second AND function is fulfilled if “Input 3”

and “Input 4” have signal state “1”. The tag “Output 4” is set if the first AND function is fulfilled, or if the second AND function is fulfilled, or if both are fulfilled.

Fig. 9.6 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. The processing pri- ority 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 following example in Fig. 9.6. The first OR function is fulfilled if “Input 1”, or

Input 2”, or both tags have signal state “1”; the second OR function is fulfilled if

Input 3”, or “Input 4”, or both tags have signal state “1”. Both OR functions are pres- ent in parentheses and their results of logic operation are linked according to an AND logic operation. The “Output 5” tag is set if both OR functions are fulfilled. The logic operation of exclusive OR functions according to an OR logic operation (last example in Fig. 9.6) also does not require parentheses. However, parentheses can be used for reasons of clarity.

9.2.7 Negating the 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. 9.7 shows the negation of binary functions. The functions are present in paren- theses since they have a lower processing priority than NOT. First the result of the binary function is generated in parentheses and then it is negated and assigned to the output tag.

Fig. 9.7 Examples of the negation of binary functions

Một phần của tài liệu Hans berger automating with SIMATIC s7 1200 configuring programming (Trang 289 - 295)

Tải bản đầy đủ (PDF)

(577 trang)