02-05-2009 04:23 PM - edited 02-05-2009 04:31 PM
I am trying to write the CRC-16 Generation Procedure for the SI-M Communication Card from TECO Electric and Machining Company. Here is the algorithm they provide for generating the CRC-16 word (attached is my attempt to implement it, I welcome any suggestions). This is verbatim:
A. Load a 16-bit register with FFFFH. Call this the CRC register.
B. Exclusive OR the first 8-bit byte of the message with the low order byte of the 16-bit CRC registers, putting the result in the CRC register.
C. Shift the CRC register one bit to the right (toward the LSB), zero filling the MSB. Extract and examine the LSB.
D. If LSB is 0, repeat procedure C (another shift). If LSB is 1, Exclusive OR the CRC register with the polynomial value A001H.
E. Repeat procedure C, D until eight shifts has been performed. Wile this is done, a complete byte will have been processed.
F. Repeat procedure B-E to the follwing byte of the message until all bytes of the message is processed.
G. When the CRC is placed into the message, it upper and lower bytes must be swapped.
If anyone understands this please feel free to tell me where I went wrong (see attached).
Cheers!
Solved! Go to Solution.
02-05-2009 11:07 PM
This link won't help you to fix your code, but it's a simplier algorithm that is more efficient because it's table-driven - and it will give the result you need.
Mike...
02-06-2009 08:54 AM
jmcbee,
I've attached a vi that is included with the LV Modbus library. It should get you the answer.
02-06-2009 09:12 AM
02-06-2009 09:42 AM
Mike,
The solution you linked to is very interesting. I'm a gonna hafta try it out and compare performance the bitbanger version.
02-06-2009 12:14 PM
Jmcbee,
It looks like in your attempt you did shifts until the the carry out was 1, did the XOR with A001, then repeated that 8 times. So you could have theoretically much more than 8 shifts for a given byte.
In Centerbolt's, the shift occurred 8 times total, and the XOR with A001 only occurred when the carryout of the shift was 1.
When I was looking at it last night it seemed like what you were doing matched the description. The only error I saw was that it looked like you were swapping bytes in the very beginning with the split and join functions. But after seeing Centerbolt's I see that it more accurately matches the description. The written description was just unclear enough that what you did seemed perfectly legitimate.
I'm glad it's working for you now.
02-06-2009 12:39 PM
Thanks for the reply Ravens Fan. This is my first venture into Modbus communication and I knew that inexperience was going to hurt, especially when it comes to interpretting a poorly written CRC-16 algorithm. Luckily I had access to the best minds in this type of work and figured that someone here would have the experience I lacked. As usual I was not dissapointed. I love this forum!
02-09-2009 08:32 AM
mikeporter,
Table scheme seems to work well. Just don't ask me to explain how it works. Thanks again for the link.
jmcbee,
I've attached a vi I put together to compare the two schemes to generate CRC-16 for Modbus.
11-22-2009 12:51 PM
Wayne.C
Thanks to the vi you have posted last piece of my CRC table driven puzzle has been solved!!
Cheers
Jack
12-14-2009 10:46 PM
I want table based CRC-16 generator in 7.1 if you can convert and give it will be gr8.
cheers
Madhu