Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
159
Добавлен:
11.10.2020
Размер:
2.81 Mб
Скачать

Appendix A: - IEC Operators and additional norm extending functions

ST erg_byte

ROR

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.

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:

PROGRAM ror_st

VAR

in_byte : BYTE:=16#45;

in_word : WORD:=16#45; erg_byte : BYTE; erg_word : WORD;

n: BYTE :=2;

END_VAR

erg_byte:=ROR(in_byte,n); (* Result is 16#51 *) erg_word:=ROR(in_word;n); (* Result is16#4011 *)

Example in FBD:

Example in IL:

LD 16#45

ROR 2

ST erg_byte

10.4Selection 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.

SEL

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

(* IN0 = 3, IN1 =4 *)

ST

Var1

(* Result is 4

*)

LD

FALSE

 

 

SEL

3,4

 

 

ST

Var1

(* Result is 3

*)

Example in ST:

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

10-8

CoDeSys V2.3

Appendix A: - IEC Operators and additional norm extending functions

Example in FBD:

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

MAX

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

MAY 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:

MIN

Minimum function. Returns the lesser of the two values.

OUT := MIN(IN0, IN1)

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

Example in IL:

LD 90

MIN 30

MIN 40

MIN 77

ST Var1 (* Result is 30 *)

Example in ST:

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

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

Example in FBD:

CoDeSys V2.3

10-9

Appendix A: - IEC Operators and additional norm extending functions

LIMIT

Limiting

OUT := LIMIT(Min, IN, Max) means:

OUT := MIN (MAX (IN, Min), Max)

Max is the upper and Min the lower limit for the result. Should the value IN exceed the upper limit Max, LIMIT will return Max. Should IN fall below Min, the result will be Min.

IN and OUT can be any type of variable.

Example in IL:

LD 90

LIMIT 30,80

ST Var1 (* Result is 80 *)

Example in ST:

Var1:=LIMIT(30,90,80); (* Result is 80 *);

MUX

Multiplexer

OUT := MUX(K, IN0,...,INn) means:

OUT := INK.

IN0, ...,INn and OUT can be any type of variable. K must be BYTE, WORD, DWORD, SINT, USINT, INT, UINT, DINT or UDINT. MUX selects the Kth value from among a group of values.

Example in IL:

LD 0

MUX 30,40,50,60,70,80

ST Var1 (* Result is 30 *)

Example in ST:

Var1:=MUX(0,30,40,50,60,70,80); (* Result is 30 *);

Please note: An expression occurring ahead of an input other than INK will not be processed to save run time ! Only in simulation mode all expressions will be executed.

10.5Comparison Operators...

GT

Greater than

A Boolean operator which returns the value TRUE when the value of the first operand is greater than that of the second. The operands can be BOOL, BYTE, WORD, DWORD, SINT, USINT, INT, UINT, DINT, UDINT, REAL, LREAL, TIME, DATE, TIME_OF_DAY, DATE_AND_TIME and STRING.

Example in IL:

LD 20

GT 30

ST Var1 (* Result is FALSE *)

Example in ST:

VAR1 := 20 > 30 > 40 > 50 > 60 > 70;

10-10

CoDeSys V2.3

Appendix A: - IEC Operators and additional norm extending functions

Example in FBD:

LT

Less than

A Boolean operator that returns the value TRUE when the value of the first operand is less than that of the second. The operands can be BOOL, BYTE, WORD, DWORD, SINT, USINT, INT, UINT, DINT, UDINT, REAL, LREAL, TIME, DATE, TIME_OF_DAY, DATE_AND_TIME and STRING.

Example in IL:

LD 20

LT 30

ST Var1 (* Result is TRUE *)

Example in ST:

VAR1 := 20 < 30;

Example in FBD:

LE

Less than or equal to

A Boolean operator that returns the value TRUE when the value of the first operand is less than or equal to that of the second. The operands can be BOOL, BYTE, WORD, DWORD, SINT, USINT, INT, UINT, DINT, UDINT, REAL, LREAL, TIME, DATE, TIME_OF_DAY, DATE_AND_TIME and STRING.

Example in IL:

LD 20

LE 30

ST Var1 (* Result is TRUE *)

Example in ST:

VAR1 := 20 <= 30;

Example in FBD:

GE

Greater than or equal to

A Boolean operator that returns the value TRUE when the value of the first operand is greater than or equal to that of the second. The operands can be BOOL, BYTE, WORD, DWORD, SINT, USINT, INT, UINT, DINT, UDINT, REAL, LREAL, TIME, DATE, TIME_OF_DAY, DATE_AND_TIME and STRING.

Example in IL:

LD 60

GE 40

ST Var1 (* Result is TRUE *)

CoDeSys V2.3

10-11

Appendix A: - IEC Operators and additional norm extending functions

Example in ST:

VAR1 := 60 >= 40;

Example in FBD:

EQ

Equal to

A Boolean operator that returns the value TRUE when the operands are equal. The operands can be BOOL, BYTE, WORD, DWORD, SINT, USINT, INT, UINT, DINT, UDINT, REAL, LREAL, TIME, DATE, TIME_OF_DAY, DATE_AND_TIME and STRING.

Example in IL:

LD 40

EQ 40

ST Var1 (* Result is TRUE *)

Example in ST:

VAR1 := 40 = 40;

Example in FBD:

NE

Not equal to

A Boolean operator that returns that value TRUE when the operands are not equal. The operands can be BOOL, BYTE, WORD, DWORD, SINT, USINT, INT, UINT, DINT, UDINT, REAL, LREAL, TIME, DATE, TIME_OF_DAY, DATE_AND_TIME and STRING.

Example in IL:

LD 40

NE 40

ST Var1 (* Result is FALSE *)

Example in ST:

VAR1 := 40 <> 40;

Example in FBD:

10-12

CoDeSys V2.3

Соседние файлы в папке 759-333