LGF_CalcCRC8Advanced (FC / V3.1.0)

Overview

Author: Siemens Industry Support

Short description

The CRC calculation is used for error detection at data transmission. The result of a calculation returns a CRC value via the data sent. The receiver detects a faulty transmission due to the unequal CRC value. The function LGF_CalcCRC8Advanced uses 8 bits as the generator polynomial (mask) and the parameters finalXorValue, reflectInput, and reflectResult.

Block Interface

LGF_CalcCRC8Advanced (FC)
Byte  initValue Ret_Val  Byte
    
Byte  mask error  Bool
    
Byte  finalXorValue status  Word
    
Bool  reflectInput   
    
Bool  reflectResult   
    
UInt  noOfElements   
    
Array[*] of Byte  array  Array[*] of Byte
       
   

Input parameter

IdentifierData type Description
initValueByte Start value with which the calculation is executed.
If there is no need for start value - assign 16#00
maskByte Generator polynomial with which the calculation is executed.
(Mask / CRC polynomial)
finalXorValueByte Value with which another XOR operation is performed at the end
reflectInputBool TRUE: the sequence of the bits within the input byte is mirrored. The sequence 0...7 becomes 7...0.
reflectResultBool TRUE: the order of the bits within the result is mirrored. The sequence 0...7 becomes 7...0.
noOfElementsUInt Number of elements to be used in CRC calculation
0 = all elements / the whole array

Output parameter

IdentifierData type Description
Ret_ValByte Calculated CRC value (return value of the function).
errorBool TRUE: An error occurred during the execution of the FB
statusWord 16#0000 - 16#7FFF: Status of the FB, 16#8000 - 16#FFFF: Error identification

In/Out parameter

IdentifierData type Description
arrayArray[*] of Byte Data stream for which the CRC value will be calculated.

Status & Error codes

Code / ValueIdentifier / Description
16#0000STATUS_NO_ERROR
No error occurred in function call
16#8400ERR_NO_OF_ELEMENTS
Error: `noOfElements` exceeds the maximum number of array elements

Functional description

The function calculates the CRC value from a data stream of any size. The data stream is composed of the individual elements of the array at the input/output parameter array. The start value initValue and the generator polynomial mask can be freely selected.

Via the Boolean input parameters reflectInput and reflectResult, you may optionally mirror the bits of the input data or the CRC value. An XOR operation is also performed with the CRC value at the end and the value finalXorValue.

The input noOfELements can be used to specify the desired number of elements for calculation, it applies:

NumberOfElements <= (ArrayUpperLimit - ArrayLowerUnderLimit + 1)


Note
Various online tools are available for calculating the CRC values. The function of the block was tested with the following online tool, since it supports the input parameters mask (Polynomial) and initValue (Initial Value):
http://www.sunshine2k.de/coding/javascript/crc/crc_js.html

Change log

Version & DateChange description
01.00.00Simatic Systems Support
16.12.2019first release, copied from "LGF_CalcCRC32Advanced"
03.00.00Simatic Systems Support
23.04.2020Set version to V3.0.0, harmonize the version of the whole library
03.00.01Simatic Systems Support
12.11.2020Insert documentation
Assign default start values to optional inputs - `initValue`, `mask`, `finalXorValue`, `reflectInput`, `reflectResult`
03.01.00Simatic Systems Support
14.04.2023Add input `noOfElements` to assign length to be converted different from array size
Add outputs `error` and `status` display a wrong assignment to `noOfElements`