Page 1 of 2

CRC-16 Component

Posted: Sun Aug 20, 2023 12:33 pm
by mnfisher
The current project I'm currently working on needs a CRC-16 calculating for a block of data.

Given the polynomial (0x8005 in my case) - who knew that there was such a wide range of possible CRC calculations possible. For the given polynomial there were several possible CRC 'functions' possible - and my first attempt gave the wrong result.

So - I wrote a small component - this allows the user to set the polynomial, initial CRC, whether it is 'reversed' (refIn and refOut = true - note this only supports refin == refout) and a final value to XOR the result with. I've tested a range of values against https://crccalc.com/ - and seems to work correctly (more testing please ~:-) )

The initialise macro generates the lookup table for the given polynomial.

It would be possible to extend to CRC-32 if anyone needs this?

There is also a very simple test program - run in simulation - that generates the CRC for a small (5 byte) block of data.

It only supports data blocks up to 255 bytes - this could be extended if needed?
CRC16.fcpx
(2.19 KiB) Downloaded 210 times
crc_test.fcfx
(8.21 KiB) Downloaded 205 times
Martin

Re: CRC-16 Component

Posted: Tue Sep 12, 2023 10:32 am
by Landlweg
Dear Martin,

i think i need this programm
i have to transmit 9 byte data with CRC16 plynom 0x8408
can you help ?

regards
Hermann

Re: CRC-16 Component

Posted: Tue Sep 12, 2023 12:55 pm
by Landlweg
Sorry i will work with a PIC16F18877,

regards
Hermann

Re: CRC-16 Component

Posted: Tue Sep 12, 2023 2:23 pm
by mnfisher
It should work okay. Add the component and set the polynomial on the properties.

Let is know how it goes.

Martin

Re: CRC-16 Component

Posted: Wed Sep 13, 2023 6:44 pm
by Landlweg
Hi Martin,
thank you for help
but in what way i can include it in Flowcode V10
the extension is normal for Flowcode *.fcfx
but this have *fcpx ?

regards
Hermann

Re: CRC-16 Component

Posted: Wed Sep 13, 2023 8:26 pm
by kersing
It’s a macro which you can import.

Re: CRC-16 Component

Posted: Wed Sep 13, 2023 9:34 pm
by medelec35
Hello.
Place the fcpx within a folder of your choice.
Within Flowcode select File > Global settings (bottom left) > Locations tab
Within look for components in... window, add the path of the folder where you placed the fcpx file.
Note if you are going to have subfolders then place a semicolon at the end.
Select OK, save and reload your project.
Any components placed within the folder you just added should now be accessible.

Re: CRC-16 Component

Posted: Wed Sep 13, 2023 9:50 pm
by mnfisher
Thanks Martin,

Yes - it is a component. Set the polynomial value in the component properties (and reverse / final XOR value if needed)
Call Initialise (once) - this calculates the lookup table for the CRC calculations

You can then pass an array of bytes to it (any length up to 255) and it's size to CRC16. As mentioned above - I used crccalc.com to check the results.

Martin

Re: CRC-16 Component

Posted: Thu Sep 14, 2023 7:05 pm
by Landlweg
Hi Martin,

Sorry - what i make wrong
to import a makro it must have extensione *fcm ?

regards
Hermann

Re: CRC-16 Component

Posted: Thu Sep 14, 2023 8:08 pm
by mnfisher
Hi Hermann,

Follow Martin's (medelec's) post above to install the component - then add the component to your code ('components' - search for CRC16) - then you can use the macros from CRC16 (in the components tab of the project explorer)

What are you trying to do - I'll try and create a demo and some more instructions if needed.

Martin