- Community Home
- :
- Discussion Forums
- :
- Most Active Software Boards
- :
- LabVIEW
- :
- Re: crc 8

turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

09-13-2007 06:53 PM

Options

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

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

Regards,

Andy

Highlighted
##
##### Re: crc 8

Options

09-16-2007 02:03 PM - edited 09-16-2007 02:03 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

Hi Shivels, xntricity,

The attached VIs appear to work for several of the sequences in OBD2_Commands.txt - one uses **Shift**-Left, the other **Rotat**e-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)

09-17-2007 01:25 AM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

Related thread...

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

- Partha (CLD until Oct 2021 )

03-12-2013 12:30 PM - edited 03-12-2013 12:37 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

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:

03-12-2013 12:33 PM - edited 03-12-2013 12:34 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

... 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

03-13-2015 04:50 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

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!

03-13-2015 05:36 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

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

03-13-2015 06:02 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

03-13-2015 06:33 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

@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

03-14-2015 04:44 AM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator