BCD data subtraction
This FP instruction subtracts the BCD data specified by s2 from s1 if the trigger EN is TRUE. The result is stored in d.
Input
Minuend, subtrahend
Output
Difference
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;
(*activates the function*)
dwMinuend: DWORD:=16#23210044;
dwSubtrahend: DWORD:=16#00210011;
(*this value will be subtracted
from the value at s1*)
dwResult: DWORD;
(*result after 0->1 leading
edge from start:
16#23000033*)
END_VAR
When the variable bStart changes from FALSE to TRUE, the function is carried out.
BODY
WORKSPACE
NETWORK_LIST_TYPE := NWTYPELD ;
ACTIVE_NETWORK := 0 ;
END_WORKSPACE
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 6 ;
NETWORK_BODY
B(B_F,FP_SUB_BCD!,,17,1,25,6,,?DEN?D@'s1'?Ds2?AENO?Cd);
B(B_CONTACT,,bStart,11,2,13,4,R);
B(B_VARIN,,dwMinuend,15,3,17,5,);
B(B_VARIN,,dwSubtrahend,15,4,17,6,);
B(B_VAROUT,,dwResult,25,3,27,5,);
L(1,3,11,3);
L(13,3,17,3);
L(1,0,1,6);
END_NETWORK_BODY
END_NET_WORK
END_BODY
IF DF(start) then
FP_SUB_BCD(s1 := dwMinuend, s2 := dwSubtrahend, d => dwResult);
END_IF;