Programming with EN/ENO boxes (FBD)

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

EN/ENO boxes have an enabling input EN and an enabling output ENO. The enabling input can be used to suppress processing of the box. If an error occurs while the box is being processed, this is displayed at the enabling output.

A detailed description of the functions with EN/ENO boxes can be found in the cor- responding sections. Programming of the EN/ENO boxes in the function block dia- gram is the primary focus here. Fig. 8.28 provides an overview of the functions im- plemented with EN/ENO boxes.

The parameters of the EN/ENO boxes must all be connected. The enabling input EN and the enabling output ENO are not parameters of the box function. They are used for processing boxes, and are added by the program editor to the box function.

A detailed description of EN and ENO and how the EN/ENO mechanism can be used with self-created blocks can be found in Chapter 12.4.1 “EN/ENO mechanism with LAD and FBD” on page 418.

The block calls in the function block diagram which are also shown as EN/ENO boxes are described in Chapter 8.6.5 “Block call functions in the function block diagram”

on page 282.

8.5.1 Positioning of EN/ENO boxes in the function block diagram

Fig. 8.29 uses the MOVE function to show the positioning of EN/ENO boxes in a logic operation. An EN/ENO box can be positioned on its own in a network, with or with- out connection of the EN input or the ENO output.

The ENO output can be connected to the EN input of the following box. A binary tag at the EN input of the first box can be used to switch processing of the complete box series on and off. The ENO output of the last box indicates by means of signal state

“1” that the complete sequence has been executed without errors.

The ENO output of one box can be connected to the ENO output of another box. If an EN/ENO box is positioned in a T branch, its ENO output can no longer be returned to the logic operation at which the T tap commences.

8.5.2 Transfer functions in the function block diagram

Boxes with the following transfer functions are available in the programming language FBD:

b Copy an operand or tag (MOVE)

b Read a field component with variable index (FieldRead) b Write a field component with variable index (FieldWrite) b Copy a data area (MOVE_BLK)

b Copy a data area without interruption (UMOVE_BLK) b Fill a data area (FILL_BLK)

b Fill a data area without interruption (UFILL_BLK) b Exchange the bytes within a tag (SWAP).

Fig. 8.28 Overview of boxes with enable input EN and enable output ENO MOVE

SHR

CONV

T_CONV S_CONV

EXPT

CONCAT

ADD

XOR EN

EN

EN

EN EN

EN

EN

EN

EN IN

IN N

IN

IN IN

IN1

IN1 IN2

IN2

IN1

IN1 IN2

IN2 OUT1

ENO

OUT

OUT OUT

ENO

ENO

ENO

ENO OUT2

OUT ENO

ENO

ENO ENO

OUT

OUT

OUT

OUT Transfer

functions e.g. transfer

Shift functions e.g. shift to right

Conversion functions for numerical values

Conversion functions for time values

Conversion functions for strings Arithmetic functions e.g. add

Logic functions e.g. digital logic operation XOR Mathematical

functions e.g. exponentiate

String functions e.g. concatenate

Boxes with EN input and ENO output

A detailed description of the transfer functions is provided in Chapter 11.1 “Trans- fer functions” on page 356.

Fig. 8.30 shows an example of the programming of transfer functions. If the tag

“Input 1” changes the signal state from “0” to “1”, the MOVE and FILL_BLK boxes will be executed.

The MOVE box copies the content of tag #Int1 to tag #Field1[1]. #Field1[1] is a com- ponent of the tag #Field1 with the same data type as the tag #Int1.

The MOVE box can be provided with further outputs: select the MOVE box and then the Insert output command from the shortcut menu. In the example, the content of

#Int1 is also transferred to the tag #Field1[9] and to the component #Struc- ture1.Int1.

The FILL_BLK box transfers the value 1234.567 to four successive components of the field tag #Field3, starting with #Field3[1]. The tag #Field3 consists of compo- nents with data type REAL.

Fig. 8.29 Positioning of EN/ENO boxes in the function block diagram using example of MOVE box

8.5.3 Arithmetic functions for numerical values in the function block diagram Boxes with the following arithmetic functions for numerical values are available in the programming language FBD:

b Add (ADD), subtract (SUB), multiply (MUL) and divide (DIV) two numerical values

b Divide with remainder as result (MOD)

b Form absolute value (ABS), negation (NEG, multiplication by –1), decrement (DEC, reduce numerical value by 1) and increment (INC, increase numerical value by 1).

A detailed description of these arithmetic functions is provided in Chapter 11.3

“Arithmetic functions for numerical values” on page 366.

Fig. 8.31 shows an example of the arithmetic functions with numerical values. Two tags of data type INT are added, and the intermediate result is saved in the tempo- rary tag #t_Int1. This intermediate result is multiplied by –1 and output to tag

#Int3. The absolute value of tag #Int1 is generated; this value is divided by 3 and the remainder of the division written to tag #Int4.

8.5.4 Arithmetic functions with time values in the function block diagram In the FBD programming language, durations (time spans, data type TIME) and points in time (date and time, data type DTL) can be connected together. Boxes with the following arithmetic functions are available for this:

Boxes with the following arithmetic functions are available for this:

b Add two durations, or add a duration to a point in time (T_ADD)

b Subtract two durations, or subtract one duration from a point in time (T_SUB) b Generate the difference between two points in time (T_DIFF).

A detailed description of these arithmetic functions is provided in Chapter 11.4

“Arithmetic functions for time values” on page 369.

Fig. 8.30 Example of the transfer functions in the function block diagram

Fig. 8.32 shows an example of arithmetic functions with time values. The difference between the tags #Date1 and #Date2 is generated. The result is a duration in TIME format. Eight hours are added to this duration, and the result output to tag #Dura- tion2.

8.5.5 Math functions in the function block diagram

Boxes with the following math functions are available in the programming language FBD:

b Trigonometric functions: sine (SIN), cosine (COS), tangent (TAN) b Arc functions: arcsine (ASIN), arccosine (ACOS), arctangent (ATAN) b Form square (SQR) and square root (SQRT)

b Exponential function to base e (EXP) b Exponential function to any base (EXPT)

Fig. 8.31 Example of arithmetic functions for numerical values in the function block diagram

Fig. 8.32 Example of arithmetic functions with time values in the function block diagram

b Natural logarithm (LN) b Extract decimal places (FRAC)

A detailed description of these math functions is provided in Chapter 11.5 “Mathe- matical functions” on page 372.

Fig. 8.33 shows an example of the math functions.

The tag #c is calculated according to the equation. The square of #a is formed first. When inputting tag names – which can also be keywords (in the input, “a” can also stand for “output”) or which can have the same name both locally and globally – the tag must be labeled accordingly: for a local tag with a preceding number sign (#), for a global tag with the name in quotation marks, and for an oper- and (absolute address) with a preceding percent sign (%).

In the example, the squares of #a and #b are stored temporarily and added. #t_Real1 is used again for the buffer. The result of the square root extraction is saved in the tag #c.

8.5.6 Conversion functions in the function block diagram

Boxes with the following conversion functions are available in the programming language FBD:

b CONV (conversion of BYTE, WORD, DWORD, SINT, INT, DINT, USINT, UINT, UDINT, REAL, LREAL, BCD16, BCD32)

b ROUND, FLOOR, CEIL, TRUNC (conversion of REAL, LREAL into SINT, INT, DINT, USINT, UINT, UDINT, REAL, LREAL)

b SCALE_X, NORM_X (scaling and standardization) b T_CONV (conversion of TIME into DINT and vice versa)

b S_CONV, STRG_VAL, VAL_STRG (conversion of SINT, INT, DINT, USINT, UINT, UDINT, REAL into STRING and vice versa)

Fig. 8.33 Example of math functions in the function block diagram

c = a2+b2

A detailed description of the conversion functions is provided in Chapter 11.6 “Con- version functions (Conversion of data type)” on page 376.

Fig. 8.34 shows an example of the conversion functions.

The conversion function CONV is used to convert a 7-digit BCD number into a DINT format number and subsequently into REAL format (tag #Real2). The value of

#Real2 is divided by 107 and converted into a fixed-point number between the limits of –150 and +250.

8.5.7 Shift functions in the function block diagram

Boxes with the following shift functions are available in the programming language FBD:

b Shift to right (SHR) and left (SHL) b Rotate to right (ROR) and left (ROL)

A detailed description of the shift functions is provided in Chapter 11.7 “Shift func- tions” on page 389.

Fig. 8.34 Example of conversion functions in the function block diagram

Fig. 8.35 Example of shift functions in the function block diagram

Fig. 8.35 shows an example of the shift functions. The content of tag #Int2 is shifted three places to the right and output to tag #Int3. Shifting of fixed-point numbers one place to the right is equivalent to a division by two. In the example, tag #Int2 is divided by eight (23) and the rounded-off result output to tag #Int3.

8.5.8 Logic functions in the function block diagram

Boxes with the following logic functions are available in the programming language FBD:

b Digital logic operations AND, OR and XOR b Invert (INV)

b Code bit (DECO) and set bit number (ENCO)

b Selection functions (SEL, MUX), minimum and maximum selection (MIN, MAX), limiter (LIMIT)

A detailed description of the logic functions is provided in Chapter 11.7 “Shift func- tions” on page 389.

Fig. 8.36 shows an example of the logic functions.

The MUX function is used to select the components whose number is present in the tag #Selection from the first four components of field tag #Field4. If, for example, the tag #Selection has a value of 3, the tag #Field4[3] will be selected.

If the value of #Selection is not between 1 and 4, the value of the tag #Real4 is used as a substitute. The result of the selection is limited to the range between –375 and +1200 and output to #Real1.

The MUX box has been extended in the example by two inputs: select the box when programming and then the Insert input command from the shortcut menu.

Fig. 8.36 Example of logic functions in the function block diagram

8.5.9 Functions for strings in the function block diagram

Boxes with the following functions for strings are available in the programming language FBD:

b LEN Outputs the length of a string b CONCAT Combines two strings together b LEFT Outputs the left part of a string b RIGHT Outputs the right part of a string b MID Outputs the middle part of a string b DELETE Deletes part of a string

b INSERT Inserts characters into a string b REPLACE Replaces characters in a string

b FIND Outputs the position of a searched character

A detailed description of these functions is provided in Chapter 11.9 “Processing of strings (Data type STRING)” on page 398.

Fig. 8.37 shows an example of string functions. The tag #String1 has the STRING format and is 24 characters long. By means of the LEFT box, 16 characters are re- moved left-justified from the tag and saved in the intermediate memory #t_String.

REPLACE replaces characters in a string. In the example, the characters '0123' are re- placed in the tag #t_String starting at the 10th position, and the complete string is written in tag #String2.

Fig. 8.37 Example of functions for strings in the function block diagram

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

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

(577 trang)