Anyone with CRC experience?
Paul Baker
Posts: 6,351
I am writng a CRC object (first in spin then in assembly) and have the CRC16 CCITT working correctly but the CRC8 and CRC32 routines are not working. With the help of online calculators I figured out I need to reverse the data and reverse the result, but I am a little unlcear where in the code this occurs,·I found some code described as inverted/reversed/reflected but it too didnt produce the value expected. Here's the two routines,
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
PUB crc8bitwise(pBuf, buflen, poly, initial): crc | i,j crc := initial repeat i from 0 to buflen - 1 crc ^= BYTE[noparse][[/noparse]pBuf][noparse][[/noparse]i] repeat j from 0 to 7 if crc & $80 crc := (crc << 1) ^ poly else crc <<= 1 crc &= $ff PUB crc8bitreverse(pBuf, buflen, poly, initial) : crc | i, j crc := initial repeat i from 0 to buflen - 1 crc ^= BYTE[noparse][[/noparse]pBuf][noparse][[/noparse]i] repeat j from 0 to 7 if crc & $01 crc := (crc >> 1) ^ poly else crc >>= 1
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
Comments
I am not a CRC expert.· For a recent product design I had to implement a CRC for a wireless communication.· I programmed the base station which had·a Propeller and my design firm programmed the recevier.· We agreed to use a CRC-8.· I Googgled and read several resources but I admit I don't fully understand that math.· Based on a couple examples I found and an on-line calculator I created the below code.· This works to create a CRC-8 based on the polynomial described in the comments.
This routine looks very much like the routine you posted except for a few changes in the naming of variables and that my routine is 'written out' a little more than your.· If I remember correctly I built this routine around psuedo code found in a datasheet or appnote for a one-wire chip - I think (my memory is vague).· Note that the polynomial is 9 bits instead of 8 bits, I remember this holding me up.· What polynomial are you using?· What are you using for initial?
Coding first in Spin in then into ASM is so easy with the Prop - I love this aspect of the language.· I like prototyping in Spin and then when I have confidence I optimize it to ASM.·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Timothy D. Swieter
tdswieter.com
One little spark of imagination is all it takes for an idea to explode
http://www.8052.com/codelib/crc16.zip
http://www.8052.com/codelib/CRC_16.asm
http://www.8052.com/codelib/CRC_16.A51
http://www.atmel.com/dyn/resources/prod_documents/doc1143.pdf
What's in red are the changes made, just needed to spin a few bytes around. Thanks for your input guys.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
Boy, almost every time I review someone elses code I learn something new. Your posts in this thread in particular Paul. There are several things I realize I could code more effeciently and then there is the "><" operator which I didn't realize existed. Thank you!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Timothy D. Swieter
tdswieter.com
One little spark of imagination is all it takes for an idea to explode
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
Maybe you can get your hands on the book "Practical Algorithms for Programmers" A. Binstock, J. Rex; Addison Wesley; 1995.
Great book anyhow.
Nick
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Never use force, just go for a bigger hammer!
The DIY Digital-Readout for mills, lathes etc.:
YADRO
Post Edited (Nick Mueller) : 12/20/2007 11:55:20 AM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
This one is also in the book I named.
Nick
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Never use force, just go for a bigger hammer!
The DIY Digital-Readout for mills, lathes etc.:
YADRO