Binary -> gray code conversion
This FP instruction converts the binary data at input s into a gray code value if the trigger EN is TRUE. The result is stored in d.
Input
Binary data
Output
Gray code value
Decimal to binary/BCD/gray code table
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 fuction*)
dwInput_value: DWORD:=16#0000000B;
dwConversionResult: DWORD:=0;
(*result after a 0->1 leading
edge from start:
16#0000000E*)
END_VAR
When the variable bStart is set 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 := 5 ;
NETWORK_BODY
B(B_F,FP_BIN_TO_GRAY!,,12,1,21,5,,?DEN?D@'s'?AENO?Cd);
B(B_CONTACT,,bStart,7,2,9,4,);
B(B_VARIN,,dwInput_value,10,3,12,5,);
B(B_VAROUT,,dwConversionResult,21,3,23,5,);
L(1,3,7,3);
L(9,3,12,3);
L(1,0,1,5);
END_NETWORK_BODY
END_NET_WORK
END_BODY
IF bStart then
FP_BIN_TO_GRAY(s := dwInput_value, d => dwConversionResult);
END_IF;