LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

CRC5 bit calculation

Solved!
Go to solution

Dear,

 

I would like to build a VI which calculate a CRC 5 USB  bit based on the following polynomial x5+x2+1.

I would like to translate the VB code as in the attachment into Labview VI.

Any help will be welcome.

 

Thanks in advance for your reaction.

0 Kudos
Message 1 of 11
(9,239 Views)

Hi.

It's certainly not perfectly optimized, but if i understood correctly it should work (Not sure about the division)crc5.png

 

You can use the snippet attached by directly drag it in your LabVIEW to use it.

 

Message 2 of 11
(9,203 Views)

Read this thread.

Thanks & Regards,

0 Kudos
Message 3 of 11
(9,193 Views)

Arink beat me to it. But I made a few changes:

 

The INIT a constant (don't need to calculate it each run). I also removed a lot of the code from inside the for loop and autoindexed the (reversed) data array instead. There also needs to be a final Invert after the for loop. I looked up a few exemplars from the web, and this works.

 

This is a literal translation of the VBS code. I'm sure there are better ways to implement the CRC5

 

CRC5.png

Message 4 of 11
(9,186 Views)

Hi.

 

Thanks for your fast response, I have checked your example by using 0x78 as 8 bit data input and should obtain 0xE as 5 bit CRC but I am getting 0x9. I don't know where the error is.

I used VB in Excel to compare.

0 Kudos
Message 5 of 11
(9,174 Views)

Hello,

 

Thanks for your quick reaction .

I have tried to run your example but the result are different from my VB code in excell.

So data 0X78, Initial value= 0x1F  and data length is 8 bit , then the CRC should be 0XE and I am getting 00111.

I don't know what is wrong in your code

0 Kudos
Message 6 of 11
(9,172 Views)
Solution
Accepted by malkowki

Use the tool I posted several years ago. Set CRC Calculation to Other (specify).  In the CRC Parameters cluster, set CRC Order to 5, CRC Polynomila to 0x25, Initial CRC Value to 0x1F, Final CRC Value to 0, Reflect Data Preprocssing to FALSE, Reflect Data before Final XOR to FALSE.

Message 7 of 11
(9,160 Views)

There were some mistakes, now i found what i calculate if i do it by hand. But's a different result from what you said, so there's obviously something i don't understand. As it is, please use the code of Matthew_Kelton.

0 Kudos
Message 8 of 11
(9,153 Views)

Thanks Mathew_Kelton! it works fine.

0 Kudos
Message 9 of 11
(9,121 Views)

@malkowki wrote:

Thanks Mathew_Kelton! it works fine.


There are so many different variations of the CRC algorithms. Each equipment/communication standard has their own spin on how to implement it. It wasn't stated by the OP how the CRC5 USB was being used. From what I assumed and from the VB code, it appeared to be very close to the USB spec.

 

I'm not an expert, but looking at a white paper from usb.org (here) , and also here, the CRC5 is used in Token Packets for the 11 bits: addr & endp. The 5 bit CRC aligns the 11 bits to a byte boundary. Here are a few examples of a USB Token and my CRC5 calculated results.

 

another white paper.PNG

 

Matthew_Kelton's algorithm seem to work fine for the OP (8-bit data), but I couldn't get the addr&endp CRCs using that code and the settings he provided. I assume his code zero pads the bits to get an entire byte boundary?? Am I doing something wrong? Or does it need different settings?

 

I only mention this because someone may do a search on using the CRC5 USB for Token Packets per the USB standard and get sent here.

0 Kudos
Message 10 of 11
(9,060 Views)