FP_CRC

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.

Parameters

Input

s1_Control (WORD, INT, UINT)

Calculation method

s2_Start (WORD, INT, UINT)

Starting address

n_Bytes (WORD, INT, UINT)

Number of bytes

Output

d (WORD, INT, UINT)

CRC value

Remarks

Specifying the control code s1_Control

  1.  (1) Calculation method

    0: CRC (SYS_CRC_CALCULATION_METHOD_CRC16)

    1: CRC-CCITT (SYS_CRC_CALCULATION_METHOD_CRC16_CCITT)

  2.  (2) Calculation starting position (bytes from s2_Start)

    16#0–16#F

  3.  (3) Storage starting position (bytes from d)

    16#0–16#F

  4.  (4) Data to be converted

    16#0: Binary data (1 byte)

Generator polynomials

CRC-16: x16 + x15 + x2 +1

CRC-CCITT: x16 + x12 + x5 +1

Error flags

sys_bIsOperationErrorHold (turns to TRUE and remains TRUE)
  • 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

sys_bIsOperationErrorNonHold (turns to TRUE for one scan)
  • 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

Example

POU header

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

POU body

When the variable bStart is set to TRUE, the function is carried out.

LD body

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

ST body

FP_CRC(s1_Control := iControlCode, 
       s2_Start := wStartAddress, 
       n_Bytes := iNumberBytes, 
       d => wCRC);

Modified on: 2021-10-22Feedback on this pagePanasonic hotline