Cyclic redundancy check
This FP instruction calculates the cyclic redundancy check (CRC) according to the calculation specified by s1_Control. The data is specified by the start address s2_Start and the number of bytes n_Bytes. The CRC value is stored in the 16-bit area specified by d.
Input
Calculation method
Starting address
Number of bytes
Output
CRC value
Specifying the control code s1_Control
0: CRC (SYS_CRC_CALCULATION_METHOD_CRC16)
1: CRC-CCITT (SYS_CRC_CALCULATION_METHOD_CRC16_CCITT)
16#0–16#F
16#0–16#F
16#0: Binary data (1 byte)
Generator polynomials
CRC-16: x16 + x15 + x2 +1
CRC-CCITT: x16 + x12 + x5 +1
if the area specified using the index modifier exceeds the limit.
if the calculation method or conversion data specified by s1_Control is out of range
if the area specified using the index modifier exceeds the limit.
if the calculation method or conversion data specified by s1_Control is out of range
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*)
wStartAddress: WORD:=16#1002;
iNumberBytes: INT:=22;
wCRC: WORD:=0;
iControlCode: INT:=16#00B0;
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 := 7 ;
NETWORK_BODY
B(B_F,FP_CRC!,,10,1,17,7,,?DEN?Ds1_Control?Ds2_Start?Dn_Bytes?AENO?Cd);
B(B_CONTACT,,bStart,4,2,6,4,);
B(B_VARIN,,iControlCode,8,3,10,5,);
B(B_VARIN,,wStartAddress,8,4,10,6,);
B(B_VARIN,,iNumberBytes,8,5,10,7,);
B(B_VAROUT,,wCRC,17,3,19,5,);
L(1,3,4,3);
L(6,3,10,3);
L(1,0,1,7);
END_NETWORK_BODY
END_NET_WORK
END_BODY
FP_CRC(s1_Control := iControlCode,
s2_Start := wStartAddress,
n_Bytes := iNumberBytes,
d => wCRC);