09-09-2007 10:01 PM
09-09-2007 11:34 PM
Your algorithm appears to be all wrong to me, along with the values your using for the calculation.
Firstly, have a look at the following web page on CRC calculations to get a better idea of what your trying to achieve:
http://en.wikipedia.org/wiki/Cyclic_redundancy_check#The_mathematics_of_CRCs
Then, see the attached VI which I wrote to perform a CRC using a 12th order polynomial. Your version will need to be slightly different to this as you are wanting an 8th order polynomial.
09-10-2007 12:16 AM
Hi Adam,
Using your VI and the "rotate left" from xntricity's VI, I came up with a simple CRC VI the produces 0x0A from your test-data.
I didn't understand how to use the polynomial - can you supply more info?
Cheers!
09-10-2007 07:20 PM
09-11-2007 10:33 PM
Hi,
Thanks for the vi. The program is supposed to send a string of hex commands to a OBDII port on a automobile. The CRC has to be used because that is how GM checks the commands sent a received by the ECU. I read through web page provide, and added some code to divide by the polynominal and came up with the smae value as tbd's vi. The vi worked for one of the commands, but not for the rest. I was unable to open the "Perfom CRC on 1D data array" vi becuase I am using LV 8.0. I don't understand what is wrong, the math appears to be correct. Here is the updated vi, and a list of commands including the correct CRC values.
Thanks,
Adam
09-12-2007 11:26 AM
Hi,
I found some C code on-line which calculates the CRC. Here is the code:
unsigned char
crc8(unsigned char *data,int length)
{
unsigned long crc;
int f,bit;
crc = 0xFF;
for ( f=0 ; f<length ; f++ ) {
crc ^= data[f];
for ( bit=0 ; bit<8 ; bit++ ) {
if ( (crc&0x80)!=0 ) {
crc <<= 1;
crc ^= 0x1D;
}
else
crc <<= 1;
}
}
return (~crc)&0xFF;
}
//unsigned char pkt[] = {0x68,0x6A,0xF1,0x01,0x00}; // VPW
unsigned char pkt[] = {0x61,0x6A,0xF1,0x01,0x00}; // PWM
void main()
{
printf("0x%X\n", crc8((unsigned char*)pkt,5));
}
Here is some more information about CRC calculation I found on the same site:
I am in the process of trying to port this code structure to labview.
Adam
09-12-2007 07:03 PM
HI Adam,
I've attached an image of the VI I sent previously for you to have a look at. I think all you'll need to do is to change the 0f01 value used in the program with the value for your polynomial. The algorithm I used to develop this VI is as follows:
Begin
crc = 0
for each byte (in the data) do
crc=crc XOR data_byte
for i=1 to 8 do
crc_lsb = lsb of crc (lsb = Least significant bit)
crc=crc shifted right by 1 bit with zero msb
if crc_lsb = 1
crc=crc XOR 0x0f01
end if
end for
end for
End
Regards,
Andy
09-12-2007 07:05 PM
09-12-2007 07:05 PM
09-12-2007 08:02 PM
Hi,
Thanks for the pictures, but I am not able to open the vi you sent me because I have LV 8.0, and it was saved in LV 8.2. Would it be possible to post the vi for LV 8.0? Am I right in assuming the value of my polynomial to be 0x11D, from my prevoius post?
Thanks,
Adam