01-06-2025 11:09 AM
Hi, I am trying to implement a CRC-6 check for a Kubler encoder using LabVIEW. I've been there are 34 bits coming back from the sensor including multiturn bits, singleturn bits, status bits and CRC bits. These are used in the CRC calculation - see below. NOTE: There is no Lifecounter for my specific device so it can be ignored.
The 6 bit CRC is also transmitted inversely, which I am assuming means that I will need to do a "Bitwise NOT" operator on them:
I've taken the LabVIEW CRC calculation algorithm from the following post on this forum and modified so it fits a 6-bit CRC with initial value of 0x00 and a poly of 0x43: Solved: Re: Implementing CRC checksum CRC-8 with 0xFF initialization - Sensirion SHT85 - NI Communit...
I get the data from the sensor as a Boolean array which I then manipulate and convert into byte arrray to then feed into the algorithm - which if done correctly should output zero. Unfortunately, I don't seem to be getting zero when I do this.
A snippet of my code is shown below:
I have also attempted a Lookup Table implementation of the algorithm which uses the pre-computed LUT mentioned in the comment within the snippet. I have luck with neither implementation.
I would be grateful if someone can help me troubleshooting the code.
The sample code which I have taken from my sensor is the boolean array as follows. Where the first (bit "0") can be ignored/disregarded for the calculation.
Thanks 🙂
Solved! Go to Solution.
01-06-2025 11:25 AM
01-07-2025 04:06 AM
Here is the actual snippet of the code attached below saved as LV 2019.
Thanks!
01-10-2025 03:56 AM
Hi, I can provide more examples of the output from the sensor (in bits) if needs be.
01-10-2025 04:19 AM
The exact specification for the BISS CRC calculation can be found in this document: https://biss-interface.com/download/biss-an-3/
01-15-2025 10:22 AM
Thanks for your response Rolf. I've had a look at that BiSS-C doucment before but still have made no progress in getting my LabVIEW CRC-6bit implementation working. The document does provide example C-code at the end however, my sensor is fully controlled via LabVIEW and I've compared the C-code to my VI which are both in essense similar. But still no luck 😞
01-16-2025 07:47 AM
This should work. It's quick and dirty. You can probably make improvements.
I found an exemplar on the web and it comes back with the correct CRC. I also did a CRC check of your "Useful Bits from Sensor" and it came back with the expected value of 0b111111 (0x3F).
I also saved it as a previous version (2019) just in case you don't have the latest installed.
version 2024 Q3
01-17-2025 04:38 AM - edited 01-17-2025 04:39 AM
Brilliant thanks maxandzoey! That seems to work now. To help my understanding of the algorithm, why is it performing an "AND" operation with the bytes using 0x3F before "XOR"-ing with the value from the Look-up Table? I thought the polynomial for the BiSS CRC-6 was 0x43 which is not present in your algorithm? Is this another method you are which is different to what I had?
Thanks 🙂
01-20-2025 11:51 PM
The polynomial 0x43 is not directly present in the algorithm. Instead, the polynomial is used to build the LUT.
The 0x3F (circled in RED) is a mask. In binary it is 0b00111111. The LUT values are only valid with indexes from 0 to 63. Since the index is an unsigned 8 bit integer and the CRC is 6 bit, the 0x3F with AND clears the 2 MSB which are not used. The way I build the index value, the mask is probably not necessary and can be removed. I just put it there for posterity.
The 0x3F and XOR outside the For Loop is there to invert the CRC. You only want to invert the 6 LSB of the CRC-6, thus the 0x3F.
01-21-2025 07:52 AM
Thanks for the reply. It makes a lot more sense now! The mask is there to ensure that only 6 bits from the unsgned 8-bit integer gets passed to the LUT. I have modified my original code with one or two of the changes from your code which has now resulted in my code also working.
I have not included the mask, but I realised one of the key things I was missing was to reverse the bool array before converting to a byte array. I have also now created a bool array with a multiple of 6 rather than 8. My code also runs the XOR before passing to the LUT index whereas in your code it carries out the XOR operation after the indexing.