LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

I need to be able to generate a CRC using a specified 8bit Polynomial.

I need to commnicate with custom hardware devices that use CRC error detection. The Polynomials are usally 8 bits and they are sometimes different.
I would like to get a good handle on this and create a VI to handle the CRC generation as well as a VI to do CRC error checking.
0 Kudos
Message 1 of 7
(3,623 Views)
There is a lot of good information on the net about how to implement a CRC. The best implementations make use of lookup tables to streamline the calculations. In addition, you can change the polynomial by using a different lookup table.

I have one 8-bit CRC implementation but am not sure of the polynomial as I developed it sometime ago for a specific piece of equipment. What version of LV are you using?

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 2 of 7
(3,623 Views)
Mike;
Thanks for the responce.
I'm Currently using LV 6.02.
The Polymonial Currently in question is 10101011.

The Firmware developer I have to "match" is using a simple shift register type of CRC generation, Ican imbed this into a LV CIN, but I'm trying to figure out how to perform the smae function from withing labview it self. This way I can keep it more flexible, and easier to modify as I work with different Firmware developers. Unfourtunatley "C" is not my strong point my "C"-code experiance is very limited.

Keith
0 Kudos
Message 3 of 7
(3,623 Views)
Post the c code and let me see what I can come up with...

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 4 of 7
(3,623 Views)
cp=(U8*)inbuff;
n=0;
locbuff[n++]=0xFF;
locbuff[n++]=0xFF;
locbuff[n++]=STX;
i=inlength+2; /* address + CRC */
crc=0;
while (i) {
if (n==3) {
c=destaddress;
} else {
if (i==1) c=0; else c=*(cp++);
}
for (bit=0x80; bit; bit>>=1) {
crc <<= 1;
if(c & bit) crc |= 0x0001;
if(crc & 0x0100) crc^=0x01AB;
}
if (i==1) c=(U8)crc;
if ((c==STX)||(c==ETX)||(c==DLE)) {locbuff[n++]=DLE; locbuff[n++]=c+0xE0;}
else locbuff[n++]=c;
if (n>=(sizeof(locbuff)-2)) return(FALSE);
i--;
}
locbuff[n++]=ETX;
As you can see there are very few comments with his code.
What he is doing I think is reading in the Data packet at inbuff he is also building the transmitt packet in "locbuff", I don't care abo
ut that part.
I just want to get the final value of "crc".
Hope this doesn't leave you as confused as it did me.

I have tried building a CIN but even that seems to come out wrong,
with a 3 byte packet of "0x01 0x20 0x05" I should get a CRC of 0x71. but I get 0x10??
0 Kudos
Message 5 of 7
(3,623 Views)
I'll look into this if I have a chance this evening, but one thing to look at is that there's some logic that if the intermediate crc comes out to be an STX, ETX or DLE character you do two more steps. Talk to the guy who wrote this and see if he can clairify the logic for you at this point. The code in question is the bit:

if ((c==STX)||(c==ETX)||(c==DLE)) {locbuff[n++]=DLE; locbuff[n++]=c+0xE0;}
else locbuff[n++]=c;

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 6 of 7
(3,622 Views)
Hi Mike Sorry it has taken so long to pick up on this. I've been working on another project, but now I'm back to this one.

The Variables STX, ETX, DLE, are CONST that are part of the packet, These are defined else where and are not part of the CRC calculation.
hope this clarifies thing a bit, It's clear as mud to me!!

I ned to see this same thing done in LV so I can get a clear understanding of what is going on.

P.S.
I am still using LV 6.02 trying to upgrade but sofar the bean counters say no.
0 Kudos
Message 7 of 7
(3,621 Views)