cancel
Showing results for 
Search instead for 
Did you mean: 
Reply

crc 8

Re: crc 8

Here's the VI version for labview 8.0 you've been asking for.

 

Regards,

Andy

 

0 Kudos
Message 11 of 21
(4,084 Views)
Highlighted

Re: crc 8

Hi Shivels, xntricity,

     The attached VIs appear to work for several of the sequences in OBD2_Commands.txt - one uses Shift-Left, the other Rotate-Left.  While Rotate-Left is slightly "cleaner" its use requires a deviation from the data-types found in the CRC-8-SAE C example-code. 

I've had no experience with these polynomial CRCs, but noted that xntricity's solution doesn't initialize CRC to 0xFF; uses a rotate-Right instead of rotate Left, and it doesn't perform a final NOT (or mask Low-byte) - all these steps seem to be required by the CRC_8_SAE algorithm(?)

Cheers!

Message Edited by tbd on 09-16-2007 02:03 PM

"Inside every large program is a small program struggling to get out." (attributed to Tony Hoare)
Message 12 of 21
(4,046 Views)

Re: crc 8

Related thread...

http://forums.ni.com/ni/board/message?board.id=170&message.id=271455

- Partha (CLD until Oct 2021 Smiley Happy)
0 Kudos
Message 13 of 21
(4,028 Views)

Re: crc 8

Calculate "Exclusive OR" checksum and calculate checksum by sum of array without carry IS TOTALLY not recommended. The algorithm is very simple but it fails because it is very easy having two different arrays with the same checksum changing two bits.

 

Test results:

==============================================
Test Nº1, Exclusive OR:
Lanzados 200000 tests aleatorios, resultando erroneos 748: 1 cada 267.38
Lanzados 40 tests 1 bit, resultando erroneos 0: 1 cada 1.#INF
Lanzados 32 tests 2 bits 1 posicion, resultando erroneos 8: 1 cada 4
Lanzados 200000 tests 2 bits aleatorios, resultando erroneos 20006: 1 cada 9.997
Lanzados 200000 tests 3 bits aleatorios, resultando erroneos 0: 1 cada 1.#INF
==============================================
Test Nº2, SUMA sin carry:
Lanzados 200000 tests aleatorios, resultando erroneos 781: 1 cada 256.082
Lanzados 40 tests 1 bit, resultando erroneos 0: 1 cada 1.#INF
Lanzados 44 tests 2 bits 1 posicion, resultando erroneos 6: 1 cada 7.33333
Lanzados 200000 tests 2 bits aleatorios, resultando erroneos 8558: 1 cada 23.3699
Lanzados 200000 tests 3 bits aleatorios, resultando erroneos 1491: 1 cada 134.138
==============================================
Test Nº3, Uso de indices: (inventado o reinventado por mí)
Lanzados 200000 tests aleatorios, resultando erroneos 781: 1 cada 256.082
Lanzados 40 tests 1 bit, resultando erroneos 0: 1 cada 1.#INF
Lanzados 74 tests 2 bits 1 posicion, resultando erroneos 1: 1 cada 74
Lanzados 200000 tests 2 bits aleatorios, resultando erroneos 767: 1 cada 260.756
Lanzados 200000 tests 3 bits aleatorios, resultando erroneos 775: 1 cada 258.065
==============================================
Test Nº4, Rutina CRC8 de Heli:
Lanzados 200000 tests aleatorios, resultando erroneos 841: 1 cada 237.812
Lanzados 40 tests 1 bit, resultando erroneos 0: 1 cada 1.#INF
Lanzados 80 tests 2 bits 1 posicion, resultando erroneos 0: 1 cada 1.#INF
Lanzados 200000 tests 2 bits aleatorios, resultando erroneos 0: 1 cada 1.#INF
Lanzados 200000 tests 3 bits aleatorios, resultando erroneos 0: 1 cada 1.#INF

 

 

I would prefer the CRC8 with polynomial 0x8C, I tested it again the C++ routine. The attached vi does not ask for any other .vis and does not produce errors and do not need CAN modules:

0 Kudos
Message 14 of 21
(2,229 Views)

Re: crc 8

... and here is the C routine. LON1 is the length of the input array without CRC:

#define CRC8_POLY 0x8C

byte ActualizaCRC8 (byte Dato, byte CRC8) { byte Cont; for (Cont = 0; Cont < 8; Cont++) { if ((CRC8 ^ Dato) & 0x01) CRC8 = (CRC8 >> 1 ) ^ CRC8_POLY; else CRC8 >>= 1; Dato >>= 1; } return CRC8; } byte hallaCRC(byte *u) { byte CRC=0; int i; for (i=0;i<LON1;i++) { //CRC^=u[i]; //CRC+=u[i]; CRC=ActualizaCRC8 (u[i], CRC);//EL MEJOR } return CRC; } void poneCRC(byte *u) { u[LON1]=hallaCRC(u); }

 

Sorry because using Spanish routine names

0 Kudos
Message 15 of 21
(2,228 Views)

Re: crc 8

Hi all,

 

We are facing a problem calculating the CRC code of a byte array. We have a test application, which indicates wheter we send the correct or incorrect CRC8 code. The generator polynom is given as: 0xD5. We just cannot seem to find out how to calculate properly:

00000001

00000000

...

00000000

 

results in CRC=197 being the proper CRC code

00000000

00000001

00000000

...

00000000

 

and now the CRC=4. We do not know the correct algorithm to calculate these vaules with the given polynom. We have already tried some online calculators, and bit sequencial dividing (XOR), but these did not work.

 

Do you guys have any idea, what could we possibly be missing, what is the correct way to calculate the CRC in this case?
Thank you in advance!

0 Kudos
Message 16 of 21
(1,723 Views)

Re: crc 8

Of course the CRC result changes.  You added data which will change the CRC.  Do you have exact data input and what the CRC should be?


There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
0 Kudos
Message 17 of 21
(1,716 Views)

Re: crc 8

The only change was that I put the 1 in a different byte. So lets say my array is A. If i put a 1 in A[73] it will require me to calculate CRC=197, A[74]  CRC=4, A[75] CRC=193, A[76] CRC=197, A[77] CRC=4 and so on. Only one byte has a value of 1 in all cases, yet the CRC changes, but only to these 3 values, and it repeats. I guess there must be a method which i am unfamiliar with. How is the CRC being calculated, when i have an array of bytes? Does the algorithm XOR every byte with the polynom and then sums it?

0 Kudos
Message 18 of 21
(1,709 Views)

Re: crc 8


@Balazs22 wrote:

How is the CRC being calculated, when i have an array of bytes? Does the algorithm XOR every byte with the polynom and then sums it?


No.  There are a lot of interesting bit shifting and conditional XORing with values.

Cyclic Redundancy Check on Wikipedia

 

So what exactly is your problem?  Are you coming up with the wrong CRC for an instrument?  Do you have any code to help us understand what your issue is?


There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
0 Kudos
Message 19 of 21
(1,701 Views)

Re: crc 8

The problem is that, the code that is correct cannot be calculated. We have a application, to check if we send the proper CRC code, WE were experimenting which code would be correct, we just do not know how the calculate it. I am aware that there are a lot of calculating forms for CRC, i wrote here because i thought we were missing something obvious, i guess we need more information from the project organizer to calculete the CRC. No actual code yet, we downloaded az llb file which contains multiple CRC calculating algorithms from this forum. It did not work. Anyway, thank you for your attention, i really appreciate it!

0 Kudos
Message 20 of 21
(1,683 Views)