L-force | plc designer – Lenze PLC Designer PLC Designer (R3-1) User Manual

Page 1048

Advertising
background image

L-force | PLC Designer

Programming Reference

1046

DMS 4.1 EN 03/2011 TD29

Implementation part:

// Implicitly generated code : only an suggestion for implementation
IF divisor = 0 THEN
CheckDivReal:=1;
ELSE
CheckDivReal:=divisor;
END_IF;

The operator DIV uses the output of function CheckDivReal as divisor. In the following
example a division by 0 is prohibited as the implicitly with 0 initialized value of the
divisor "d" is changed to "1" by CheckDivReal prior to the execution of the division.
Therefore the result of the division is 799.

PROGRAM PLC_PRG
VAR
erg:REAL;
v1:REAL:=799;
d:REAL;
END_VAR
erg:= v1 / d;

MOD
IEC Operator: Modulo Division of one variable by another one.
Allowed types: BYTE, WORD, DWORD, LWORD, SINT, USINT, INT, UINT, DINT, UDINT,
LINT, ULINT. The result of this function will be the remainder of the division. This result
will be a whole number.
Example in IL: (Result in Var1 is 1)

Example in ST:

var1 := 9 MOD 2;

Example in FBD:

Advertising