07-31-2018 03:57 AM
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.
Solved! Go to Solution.
07-31-2018 06:42 AM - edited 07-31-2018 06:42 AM
Hi.
It's certainly not perfectly optimized, but if i understood correctly it should work (Not sure about the division)
You can use the snippet attached by directly drag it in your LabVIEW to use it.
07-31-2018 07:28 AM
Read this thread.
Thanks & Regards,
07-31-2018 07:43 AM
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
07-31-2018 09:27 AM
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.
07-31-2018 09:39 AM
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
07-31-2018 10:20 AM
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.
07-31-2018 10:48 AM
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.
08-01-2018 01:59 AM
Thanks Mathew_Kelton! it works fine.
08-01-2018 09:43 AM
@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.
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.