CRC-16 Component

Post and discuss new components that you have created.
mnfisher
Valued Contributor
Posts: 953
http://meble-kuchenne.info.pl
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 104 times
Been thanked: 507 times

Flowcode v10 CRC-16 Component

Post 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 178 times
crc_test.fcfx
(8.21 KiB) Downloaded 181 times
Martin

Landlweg
Posts: 7
Joined: Fri Jun 11, 2021 6:44 pm

Re: CRC-16 Component

Post 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

Landlweg
Posts: 7
Joined: Fri Jun 11, 2021 6:44 pm

Re: CRC-16 Component

Post by Landlweg »

Sorry i will work with a PIC16F18877,

regards
Hermann

mnfisher
Valued Contributor
Posts: 953
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 104 times
Been thanked: 507 times

Re: CRC-16 Component

Post by mnfisher »

It should work okay. Add the component and set the polynomial on the properties.

Let is know how it goes.

Martin

Landlweg
Posts: 7
Joined: Fri Jun 11, 2021 6:44 pm

Re: CRC-16 Component

Post 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

kersing
Valued Contributor
Posts: 157
Joined: Wed Dec 02, 2020 7:28 pm
Has thanked: 64 times
Been thanked: 58 times

Re: CRC-16 Component

Post by kersing »

It’s a macro which you can import.

medelec35
Matrix Staff
Posts: 1451
Joined: Wed Dec 02, 2020 11:07 pm
Has thanked: 512 times
Been thanked: 472 times

Re: CRC-16 Component

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

mnfisher
Valued Contributor
Posts: 953
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 104 times
Been thanked: 507 times

Re: CRC-16 Component

Post 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

Landlweg
Posts: 7
Joined: Fri Jun 11, 2021 6:44 pm

Re: CRC-16 Component

Post by Landlweg »

Hi Martin,

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

regards
Hermann

mnfisher
Valued Contributor
Posts: 953
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 104 times
Been thanked: 507 times

Re: CRC-16 Component

Post 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

Post Reply