Материал: m912201e

Внимание! Если размещение файла нарушает Ваши авторские права, то обязательно сообщите нам

294 The IEC Operators

Bit-Shift Operators

Example in FBD:

Example in IL:

LD 16#45

SHL 2

ST erg_byte

12.4.2SHR

Bitwise right-shift of an operand: erg:= SHR (in, n)

erg, in and n should be of the type BYTE, WORD or DWORD. in will be shifted to the right by n bits and filled with zeros on the left.

See the following example in hexadecimal notation to notice the results of the arithmetic operation depending on the type of the input variable (BYTE or WORD).

Example in ST:

WAGO-I/O-SYSTEM 759 WAGO-I/O-PRO 32

The IEC Operators

295

Bit-Shift Operators

 

 

 

Example in FBD:

Example in IL:

LD 16#45

SHL 2

ST erg_byte

12.4.3ROL

Bitwise rotation of an operand to the left: erg:= ROL (in, n)

erg, in and n should be of the type BYTE, WORD or DWORD. in will be shifted one bit position to the left n times while the bit that is furthest to the left will be reinserted from the right.

Note:

Please note, that the amount of bits, which is regarded for the arithmetic operation, is pretended by the data type of the input variable !. If the input variable is a constant the smallest possible data type is regarded. The data type of the output variable has no effect at all on the arithmetic operation.

See in the following example in hexadecimal notation that you get different results for erg_byte and erg_word depending on the data type of the input variable (BYTE or WORD), although the values of the input variables in_byte and in_word are the same.

Example in ST:

WAGO-I/O-SYSTEM 759 WAGO-I/O-PRO 32

296 The IEC Operators

Bit-Shift Operators

Example in FBD:

Example in IL:

LD 16#45

SHL 2

ST erg_byte

12.4.4ROR

Bitwise rotation of an operand to the right: erg = ROR (in, n)

erg, in and n should be of the type BYTE, WORD or DWORD. in will be shifted one bit position to the right n times while the bit that is furthest to the left will be reinserted from the left.

Note:

Please note, that the amount of bits, which is regarded for the arithmetic operation, is pretended by the data type of the input variable !. If the input variable is a constant the smallest possible data type is regarded. The data type of the output variable has no effect at all on the arithmetic operation.

See in the following example in hexadecimal notation that you get different results for erg_byte and erg_word depending on the data type of the input variable (BYTE or WORD), although the values of the input variables in_byte and in_word are the same.

Example in ST:

WAGO-I/O-SYSTEM 759 WAGO-I/O-PRO 32

The IEC Operators 297

Selection Operators

Example in FBD:

Example in IL:

LD 16#45

SHL 2

ST erg_byte

12.5 Selection Operators

All selection operations can also be performed with variables. For purposes of clarity we will limit our examples to the following which use constants as operators.

12.5.1SEL

Binary Selection.

OUT := SEL(G, IN0, IN1) means:

OUT := IN0 if G=FALSE;

OUT := IN1 if G=TRUE.

IN0, IN1 and OUT can be any type of variable, G must be BOOL. The result of the selection is IN0 if G is FALSE, IN1 if G is TRUE.

Example in IL:

LD TRUE

SEL 3,4

WAGO-I/O-SYSTEM 759 WAGO-I/O-PRO 32

298 The IEC Operators

Selection Operators

ST

Var1

(* Result ist

4

*)

LD

FALSE

 

 

 

SEL

3,4

 

 

 

ST

Var1

(* Result ist

3

*)

Example in ST:

Var1:=SEL(TRUE,3,4); (* Result is 4 *)

Example in FBD:

Note:

Note that an expression occurring ahead of IN1 or IN2 will not be processed if IN0 is TRUE.

12.5.2MAX

Maximum function. Returns the greater of the two values.

OUT := MAX(IN0, IN1)

IN0, IN1 and OUT can be any type of variable.

Example in IL:

LD

90

MAX

30

MAX

40

MAX

77

ST

Var1 (* Result is 90 *)

Example in ST:

Var1:=MAX(30,40); (* Result is 40 *)

Var1:=MAX(40,MAX(90,30)); (* Result is 90 *)

Example in FBD:

WAGO-I/O-SYSTEM 759 WAGO-I/O-PRO 32