Subtract
The content of the accumulator is subtracted from the operand defined in the operand field. The result is transferred to the accumulator.
Input
1st input: minuend
2nd input: subtrahend
Output
Output as input: result
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
bStart: BOOL:=FALSE;
iMinuend: INT:=0;
iSubtrahend: INT:=0;
iResult: INT:=0;
END_VAR
In this example the input variables (iMinuend, iSubtrahend and bStart) have been declared. Instead, you may enter constants directly into the function (enable input e.g. for tests).
If bStart is set, iSubtrahend (data type INT) is subracted from iMinuend. The result will be written into iResult (data type INT).
BODY
WORKSPACE
NETWORK_LIST_TYPE := NWTYPELD ;
ACTIVE_NETWORK := 0 ;
END_WORKSPACE
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 8 ;
NETWORK_BODY
B(B_VARIN,,minuend,6,3,8,5,);
B(B_VARIN,,subtrahend,6,4,8,6,);
B(B_VAROUT,,result,14,3,16,5,);
B(B_CONTACT,,enable,3,2,5,4,);
B(B_F,E_SUB!,Instance,8,1,14,6,,?DEN?D?D?AENO?C);
L(1,3,3,3);
L(5,3,8,3);
L(1,0,1,8);
END_NETWORK_BODY
END_NET_WORK
END_BODY
IF bStart then
iResult:=iMinuend-iSubtrahend;
END_IF;