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

Page 1047

Advertising
background image

L-force | PLC Designer

Programming Reference

DMS 4.1 EN 03/2011 TD29

1045

DIV
IEC Operator: Division of one variable by another one.
Allowed types: BYTE, WORD, DWORD, LWORD, SINT, USINT, INT, UINT, DINT, UDINT,
LINT, ULINT, REAL and LREAL.
Example in IL: (Result in Var1 is 4)

Example in ST:

var1 := 8/2;

Example in FBD:

Note: Please notice, that different target systems may behave differently concerning
a division by zero.


Check functions
In order to check the value of the divisor, for example in order to avoid a division by 0
you may make use of the provided check functions CheckDivInt, CheckDivLint,
CheckDivReal and CheckDivLReal. After they have been included in the application
each division occurring in the related code will provoke a preceding call to these
functions. To include them in the application use the Add Object dialog. Therein
choose the object "POUs for implicit checks", mark the checkbox of a corresponding
check function, select an implementation language and confirm your choice with
Open. The selected function will be opened in the editor corresponding to the choice of
the implementation function. Independently of this choice the declaration part of the
functions is preset and must not be changed except for adding local variables. A
default implementation of the functions that might be modified is available in ST.
See the following example for an implementation of the function CheckDivReal:
Default implementation of the function CheckDivReal:
Declaration part:

// Implicitly generated code : DO NOT EDIT
FUNCTION CheckDivReal : REAL
VAR_INPUT
divisor:REAL;
END_VAR

Advertising