
Diamond 10kW Manual
Dynatronix, Inc.
198-1603-03 Rev 01
Page 115 of 150
B.1.7 CRC Calculation
The CRC is used for error detection. The following is C code for the CRC calculation.
/////////////////////////////////////////////////////////////////////////////
// FUNCTION: CRC_Calc()
// DESCRIPTION: Calculate the CRC value for a string.
// PARAMETERS: Pointer to the string to perform the CRC calculation on.
// RETURNS: CRC word, 00000 to 65535.
// NOTES: The CRC calculation used by all Dynatronix units.
/////////////////////////////////////////////////////////////////////////////
uint16_t CRC_Calc (char * szData)
{
uint16_t uiCRC = 0xFFFF;
int16_t iCount = (int16_t)strlen(szData);
int16_t iIndex;
char cShiftCnt;
for(iIndex = 0; iIndex < iCount; +)
{
cShiftCnt = 8;
uiCRC = (uint16_t)(uiCRC ^ (szData[iIndex] & 0xFF));
while (cShiftCnt != 0)
{
if ((uiCRC & 0x0001) == 0x0001)
{
uiCRC = (uint16_t)((uiCRC >> 1) ^ (uint16_t)0xA001);
}
else
{
uiCRC = (uint16_t)(uiCRC >> 1);
}
cShiftCnt--;
}
}
return uiCRC;
} //CRC_Calc