Divide
DIV divides the value of the first input variable by the value of the second.
Input
1st input: dividend
2nd input: divisor
Output
Output as input: result
Input and output variables must be of one of the noted data types. All operands must be of the same data type.
All input and output variables used for programming this function have been declared in the POU header. The same POU header is used for all programming languages.
VAR
enable: BOOL:=FALSE;
dividend: INT:=0;
divisor: INT:=0;
result: INT:=0;
END_VAR
In this example the input variables dividend, divisor and enable have been declared. Instead, you may enter constants directly into the function (enable input e.g. for tests).
If enable is set (TRUE), dividend is divided by divisor. The result is written into result.
BODY
WORKSPACE
NETWORK_LIST_TYPE := NWTYPELD ;
ACTIVE_NETWORK := 0 ;
END_WORKSPACE
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 5 ;
NETWORK_BODY
B(B_VARIN,,dividend,8,2,10,4,);
B(B_CONTACT,,enable,4,1,6,3,);
B(B_F,E_DIV!,,10,0,16,5,,?DEN?D?D?AENO?C);
B(B_VARIN,,divisor,8,3,10,5,);
B(B_VAROUT,,result,16,2,18,4,);
L(6,2,10,2);
L(1,2,4,2);
L(1,0,1,5);
END_NETWORK_BODY
END_NET_WORK
END_BODY
LD |
enable |
E_DIV |
dividend, divisor, result |