24.01.2015 Views

PLC Programming

  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

IEC Operators and additional norm extending functions<br />

Note:<br />

If you define functions in your project with the names CheckDivByte, CheckDivWord,<br />

CheckDivDWord and CheckDivReal, you can use them to check the value of the divisor if you use<br />

the operator DIV, for example to avoid a division by 0. The functions must have the above listed<br />

names.<br />

See in the following an example for the implementation of function CheckDivReal:<br />

Example for the implementation of the function CheckDivReal:<br />

FUNCTION CheckDivReal : REAL<br />

VAR_INPUT<br />

divisor:REAL;<br />

END_VAR<br />

IF divisor = 0 THEN<br />

CheckDivReal:=1;<br />

ELSE<br />

CheckDivReal:=divisor;<br />

END_IF;<br />

Operator DIV uses the output of function CheckDivReal as divisor. In a program like shown in the<br />

following example this avoids a division by 0, the divisor (d) is set from 0 to 1. So the result of the<br />

division is 799.<br />

PROGRAM <strong>PLC</strong>_PRG<br />

VAR<br />

erg:REAL;<br />

v1:REAL:=799;<br />

d:REAL;<br />

END_VAR<br />

erg:= v1 DIV d<br />

MOD<br />

Modulo Division of one variable by another of the types: BYTE, WORD, DWORD, SINT, USINT, INT,<br />

UINT, DINT, UDINT. The result of this function will be the remainder of the division. This result will be<br />

a whole number.<br />

Example in IL:<br />

LD 9<br />

MOD 2<br />

ST Var 1 (* Result is 1 *)<br />

Example in ST:<br />

var1 := 9 MOD 2;<br />

Example in FBD:<br />

MOVE<br />

Assignment of a variable to another variable of an appropriate type. As MOVE is available as a box in<br />

the graphic editors FBD, LD, CFC, there the (unlocking) EN/EN0 functionality can also be applied on a<br />

variable assignment.<br />

Example in CFC in conjunction with the EN/EN0 function:<br />

Only if en_i is TRUE, var1 will be assigned to var2.<br />

Example in IL:<br />

CoDeSys V2.3 10-3

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!