Programming of binary logic operations (FBD)

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

The binary logic operations are carried out in the function block diagram using the AND, OR, and exclusive OR boxes. The binary tags for the logic operation can be scanned for signal state “1” or “0”. The binary results of other boxes can also be included, e.g. the evaluation of a signal edge, the validity checking of floating-point numbers, or the comparison of two digital tags (Fig. 8.3).

Fig. 8.3 Overview of binary logic operations in the function block diagram Binary tags

Binary tag Binary tag

Binary tags

AND function OR function Exclusive OR function

Scan for “loating-point value OK” Scan for “Floating-point value not OK”

Comparison function

Floating-point tag Floating-point tag

Positive edge of a binary tag Negative edge of a binary tag Scan for signal state “1” Scan for signal state “0”

Edge trigger flag Edge trigger flag

Digital tag 1 Digital tag 2 Binary logic operations

& >=1 X

Data type Function

Function Function

P

OK

N

NOT_OK

8.2.1 Scanning for signal states “1” and “0”

The binary functions scan the binary tags at the function inputs before they link the signal states together. The scan can be made for signal state “1” or “0”. When scan- ning for signal state “1”, the function input leads directly to the box. You can recog- nize the scanning for signal state “0” by means of the negation circle at the input of the function.

Scanning for signal state “1” delivers a result “1” if the scanned binary tag has the status “1”, and a result “0” if the status is “0”. Scanning for signal state “0” negates the result, i.e. the result of the scan is now “1” if the status of the scanned binary tag is “0”. The binary functions link the result of the scan, in other words the result which is present “directly” on the box. Using these two possibilities for scanning bi- nary tags, you can handle connected NO and NC contacts in the same functional manner.

Example: Fig. 8.4 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.

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 K1 controlled by output %Q4.0

Fig. 8.4 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

& & & &

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 K1 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 S1 is open, input %I1.0 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 K1 controlled by output

%Q4.0 pulls up. If sensor S1 is then activated, input %I1.0 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 K1 connected to output %Q4.0 does not pull up.

8.2.2 Taking account of the sensor type in the function block diagram 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 de- termine whether an NC or NO contact is connected to an input. It can only recognize the signal state “1” or “0”.

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.

Scanning for signal states “1” and “0” is available for this purpose. Scanning for sig- nal state “1” delivers “1” if the scanned input is also “1”. Scanning for signal state

“0” 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 connect the result of the scan further.

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

The AND function used is then fulfilled, i.e. the function output has the signal state

“1”, if the result of the scan “1” is present at all function inputs (for description, see Chapter 8.2.3 “AND function” on page 252).

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. When an NO contact is activated, the signal state at the input is “1” and is scanned for signal state “1” so that the AND operation can be fulfilled when the sensor is activated. If both NO contacts are activated, the AND logic operation is fulfilled and the contac- tor 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 scan for signal state “0”. Therefore in the second case the NO contact must be scanned for signal state “1” and the NC contact for signal state “0” in order for the contactor to pull up when both sensors are activated.

8.2.3 AND function

The AND function links two binary signal states together and delivers a result of the logic operation “1” if both states (both results of the scans) are simultaneously “1”.

If the AND function has several inputs, the results of the scans of all inputs must Fig. 8.5 Taking account of the sensor type in the function block diagram

Neither sensor is activated

Neither sensor is activated

Both sensors are activated

Both sensors are activated

The contactor pulls up

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

&

&

&

&

be “1” so that the joint result of the logic operation is “1”. In all other cases, the AND function delivers the result of the logic operation “0” at the function output.

An AND function has two inputs as standard. If you select the AND function when programming and then the Add input command in the shortcut menu using the right mouse button, the program editor extends the AND function by a further in- put. An AND function can have any number of inputs.

Fig. 8.6 shows an example of an AND function with three inputs. The binary tags

“Input 1” and “Input 2” lead directly to the function box. The binary tag “Input 3” is scanned for signal state “0”, which can be recognized by the negation circle on the box. The AND function is fulfilled, i.e. the binary tag “Output 1” has signal state “1”, if “Input 1” and “Input 2” have signal state “1” and “Input 3” has signal state “0”. In all other cases, the AND function is not fulfilled.

If you wish to directly assign the signal state of one binary tag to another binary tag, e.g. connect an input directly to an output, it is usual to use the AND function with one input.

8.2.4 OR function

The OR function links two binary signal states together and delivers a logic opera- tion result “1” if one of the states (one of the results of the scans) is “1”. If the OR function has several inputs, it is sufficient if the result of one input scan is “1” so that the joint result of the logic operation is “1”. If the results of all input scans are

“0”, the OR function delivers the result of the logic operation “0” at the function output.

An OR function has two inputs as standard. If you select the OR function when pro- gramming and then the Add input command in the shortcut menu using the right mouse button, the program editor extends the OR function by a further input.

An OR function can have any number of inputs.

Fig. 8.6 AND function with three inputs

Fig. 8.7 OR function with three inputs

Fig. 8.7 shows an example of an OR function with three inputs. The binary tags

“Input 1” and “Input 2” lead directly to the function box. The binary tag “Input 3” is scanned for signal state “0”, which can be recognized by the negation circle on the box. The OR function is not fulfilled, i.e. the binary tag “Output 2” has signal state

“0”, if “Input 1” and “Input 2” have signal state “0” and “Input 3” has signal state “1”.

In all other cases, the OR function is fulfilled.

8.2.5 Exclusive OR function

The exclusive OR function (non-equivalence function) links two binary signal states together and delivers a logic operation result “1” if the two states (both results of the scans) differ. It delivers a result of the logic operation “0” if the two states (both results of the scans) are the same.

You can also program an exclusive OR function with more than two inputs; the ex- clusive OR function is then fulfilled if an odd number of function inputs delivers scan result “1”.

An exclusive OR function has two inputs as standard. If you select the exclusive OR function when programming and then the Add input command in the shortcut menu using the right mouse button, the program editor extends the exclusive OR function by a further input. An exclusive OR function can have any number of inputs.

Fig. 8.8 shows an example of an exclusive OR function with two inputs. The binary tags “Input 1” and “Input 2” lead directly to the function box. The exclusive OR func- tion is fulfilled, i.e. the binary tag “Output 3” has signal state “1”, if “Input 1” and

“Input 2” have different signal states. If the signal states of “Input 1” and “Input 2”

are the same, the exclusive OR function is not fulfilled.

8.2.6 Mixed binary logic operations

You can combine binary functions with each other, e.g. several AND functions lead to an OR function or two OR functions lead to an exclusive OR function. Examples are shown in Fig. 8.9.

With which signal combination in Fig. 8.9 is the binary tag “Output 4” set to signal state “1”? Firstly, “Input 5” and “Input 6” must have different signal states if the AND function at the end of the logic operation is to be fulfilled. The other condition is that either “Input 1” and “Input 2” both have signal state “1” or that “Input 3” and

“Input 4” have different signal states.

Fig. 8.8 Exclusive OR function with two inputs

8.2.7 T branch in the function block diagram

Additional possibilities for binary logic operations are provided when a “T branch”

is present in an operation. This is a parallel branch (a “parallel logic operation”) which commences in an operation and is terminated by a box.

Fig. 8.10 shows a T branch. It commences with the first AND function and is finished by the assignment to “Output 6”. In the example, “Output 5” then has signal state

“1” if “Input 0”, “Input 1”, and “Input 2” have signal state “1”, which corresponds to an AND function with three inputs. “Output 6” has signal state “1” if “Input 0” and

“Input 1” both have signal state “1” or “Input 3” has signal state “1”.

8.2.8 Negate result of logic operation in the function block diagram

A circle at the input or output of a function symbol negates the result of the logic operation. You can

b apply the negation to the scan of a binary tag; this then corresponds to scanning for signal state “0” (see Section 8.2.1 “Scanning for signal states

“1” and “0”” on page 250),

b set the negation between two binary functions (this corresponds to negation of the result of the logic operation), or

Fig. 8.9 Example of a combined binary logic operation

Fig. 8.10 T branch in the function block diagram

b position the negation at the output of a binary function (e.g. if you wish to set a binary tag and the logic operation is not fulfilled, i.e. the result of the logic operation = “0”).

Program the negation using the Invert RLO program element from the favorites of the program editor or from the program elements catalog under General. You can drag the Invert RLO element to an input or output of a box using the mouse, or select the input or output and click on Invert RLO. If you wish to cancel a negation, drag Invert RLO over again, or select the negation and click on Invert RLO.

Fig. 8.11 shows three examples of the negation of a function output. A NAND func- tion is an AND function with negated output: the output only has signal state “0” if the scan result “1” is present at all inputs. A NOR function is an OR function with negated output: the output only has signal state “1” if neither of the inputs has the scan result “1”. An exclusive OR function with a negated output is also referred to as an inclusive OR function (equivalence function): The output only has signal state

“1” if the scan results are the same for both inputs. If more than two inputs are pres- ent, an even number of inputs must have the scan result “1” so that the inclusive OR function is fulfilled.

8.2.9 Edge evaluation of binary tags in the function block diagram

The edge evaluation of a binary tag has the signal state “1” for one processing cycle if the signal state of the binary tag named above it changes from “0” to “1” (P box, rising edge) or from “1” to “0” (N box, falling edge). It responds like a “fleeting contact”. This “pulse” can be linked further.

The edge trigger flag is named underneath the edge box. This is a flag or data bit which saves the signal state of the binary tag. The signal edge is recognized by com- paring the signal states of binary tags and edge trigger flags (see also Chapter 10.3

“Edge evaluation” on page 338).

Fig. 8.11 Negating the result of the logic operation, example of a negated function output

In Fig. 8.12, the binary tag “Memory 1” is set to signal state “1” if “Input 1” changes its signal state from “0” to “1” while “Input 2” has signal state “1”. “Memory 1” is reset again by a change in signal state at “Input 3” from “1” to “0” or by signal state

“1” at “Input 4”.

8.2.10 Validity checking of floating-point numbers in the function block diagram

The OK box checks a floating-point tag for validity, i.e. whether the range limits for this data type have been observed. The NOT_OK box is the opposite, it delivers sig- nal state “1” if the floating-point tag is not valid. The OK box and the NOT_OK box are positioned at the beginning of a logic operation.

The example in Fig. 8.13 shows a validity scan of “REAL-Var 1” which, when ANDed with “Input 5”, controls the binary tag “Output 1”. “Output 2” is set if “Input 6” has signal state “1” or if “REAL-Var 2” is outside the valid range of values.

Fig. 8.12 Edge evaluation of a binary tag

Fig. 8.13 Validity checking of floating-point numbers

8.2.11 Comparison functions in the function block diagram

A comparison function is represented in the function block diagram as a box with two inputs for digital tags which are compared with each other. A correct compari- son delivers a logic operation result “1” at the function output. If the comparison is incorrect, the result of the logic operation is “0”.

Comparison functions are available for equal to, not equal to, greater than, greater than or equal to, less than, and less than or equal to. The comparison is carried out in accordance with the data type of the digital tags involved (for description, see Chapter 11.2 “Comparison functions” on page 364).

The example in Fig. 8.14 shows a comparison between two digital tags with the data type REAL. If the values of the two tags are the same, “Output 3” is set to signal state “1”, otherwise to “0”. “Output 4” has signal state “1” if either the tag “INT- Var 1” is greater than 125 or the tag “INT-Var 2” is smaller than 16 000.

In addition there are range comparisons which check whether the value of a digital tag is within or outside a numerical range.

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

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

(577 trang)