How To: CRC16 calculation in LadderLogic?

ergosophist

Member
Join Date
Jan 2013
Location
Boston
Posts
7
Hello,
I'm running on an AB ControlLogix and need to generate a 16-bit CRC, to ensure data integrity when transferring to another system. I have an array of 150 DINTs that I would like to CRC (similar to calculating CRC for a file). My question: How can I implement the CRC calculation for a 600-byte array in ladder (or ST)? How can I program the table generator?
Specifically, how do you use the values from the lookup table to operate on the successive bytes in the array? And, how do you generate the lookup values for that algorithm (if it is even different then just doing CRC16 on a byte with 0xFFFF pre-pended and 0x0000 appended)?

After reading Ross Williams' guide on CRCs, the theory makes sense, but I'm struggling on the ladder implementation of a table-driven approach. Of course, I would need to write the table generation code as well (or import a table that I know will work, at the least). As for the polynomial, I would use the CCITT standard 0x1021.

RSLogix doesn't come with a true CRC instruction, and I haven't found any sample code. If anybody has sample code, references , or can provide an explanation of how to calculate the array CRC, that would be greatly appreciated!!

Thank you
 
There's a CRC routine in RLL built into the Modbus_Slave and Modbus_Master examples that are (usually) installed along with Studio 5000 in the Samples section.

It's not well documented, and is a FOR/NEXT loop with the basic XOR style calculation instead of a table-driven technique, but it does work.

I've done the table-lookup style in a CompactLogix a few years ago for a not-quite-Modbus CRC calculation but I'd have to dig it up.
 
Hello,
I'm running on an AB ControlLogix and need to generate a 16-bit CRC, to ensure data integrity when transferring to another system.....
That shouldn't be done in ladder or ST. It should be part of the firmware written in C or assembly language. Writing a CRC16 will be messy. Also, different devices may use the same polynomial but start with different initial values for the CRC. I know Modican and Rockwell use different initial values but they use the same polynomial.

Calculating a Fletcher Check Sum is much easier/faster. The old TI505 used FCSs.
 
It is recommended to generate the table in the program (eg first couple of scans) - If you have an error in the preset table communications will fail at odd times due to the one table entry error!!!

Look into index addressing to step through your array
ArrayName[index] is a valid argument in control logix

For the algorithm try
http://www.efg2.com/Lab/Mathematics/CRC.htm

Method
Think about using ST in an AOI - but efficient ladder works as well
and think about timing - do you need the CRC to be calculated each scan or only once every minute or so?

If only once every minute then just calculate say 50 entries per scan would not have a huge impact on the scan time
 

Similar Topics

Hello guyzz, I have a problem that sounds something like this: I need to read from Citect a energy meter (Type Algodue UPT210) over RS-485 and...
Replies
9
Views
5,261
As it's the holidays, I'm a little bored, so looking back on something I did a while back thought I would post it just incase someone may be...
Replies
10
Views
1,835
ALL TEAM I'm working on a project using connected component workbench (CCW) from Allan Bradley PLC and I have tried to implement CRC16 but my...
Replies
0
Views
1,479
Hi all, like the title of the thread, I'm looking some sample code for realize the CRC16 routine using S7 STL or SCL language for Modubs RTU...
Replies
8
Views
7,903
Has anyone implemented a CRC16 routine in RSLogix5000? I need to do this to check a large data download. Thanks, Rich
Replies
0
Views
1,419
Back
Top Bottom