• Forums
• Posts
Latest Posts
Active Posts
Recently Visited
Search Results
• Page Extras
• Forum Themes

### Hot!pic 24 crc problem

Author
Neddie
Starting Member
• Total Posts : 60
• Reward points : 0
• Joined: 2010/09/06 05:53:06
• Location: 0
• Status: offline
0

# pic 24 crc problem

Hi to all.
I'm trying to get the pic24 (pic24fj256ga106) to do a checksum on a large chunk of data , and I can't get it to give
me the correct result. If I do the checksum on one  piece of data , it works fine.
If however I split the data into 2 chunks it fails.
For instance.
Array of data Data[8] = {0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08};
initial CRCWDAT = 0 , this works fine.
If I split the data into 2:
Data1[4] = {0x01,0x02,0x03,0x04};
Data2[4] = {0x05,0x06,0x07,0x08};
initial CRCWDAT = 0; Run CRC on Data1 , get result xxxx
initial CRCWDAT = xxxx , Run CRC on Data2 get incorrect result :0(

I'm using the code from AN1148 example B-2. I've just modified the function to accept an additional parameter for CRCWDAT. Initial value is 0 , then afterwards
it's the result of the previous iteration.
What am I doing wrong here.
I'm having to calculate the crc on the fly as there is not enough ram to do it in 1 go , else I'd have no problem.
cheers
Neddie

post edited by Neddie - 2013/06/14 02:39:05

RISC
Super Member
• Total Posts : 5375
• Reward points : 0
• Status: offline
Re:pic 24 crc problem 2013/06/15 09:12:31 (permalink)
0
Hi,

Look for several code examples for PIC24F CRC here : http://www.microchip.com/CodeExamples

Filter by family core to get only PIC24F (CE312, CE351, CE356)

Regards
Neddie
Starting Member
• Total Posts : 60
• Reward points : 0
• Joined: 2010/09/06 05:53:06
• Location: 0
• Status: offline
Re:pic 24 crc problem 2013/06/18 00:40:58 (permalink)
0
Thanks , I'll check them out.

Neddie
Starting Member
• Total Posts : 60
• Reward points : 0
• Joined: 2010/09/06 05:53:06
• Location: 0
• Status: offline
Re:pic 24 crc problem 2013/06/18 01:17:44 (permalink)
0
The example code (CE312)  does not work either in this case :0(
The data they supply to the CRC engine is an array of 32 int's.
If I run the code it generates a checksum of 0x4610.
If I split the array into 2 arrays of 16 int's I get a different checksum( 0x5DC1)
I run the first array through the engine and get a checksum . Then use that checksum as my prevCRC parameter and run the second array through the engine. Different result.
What am I doing wrong here!!!
Cheers
Neddie

T Yorky
Super (Thick) Member
• Total Posts : 514
• Reward points : 0
• Joined: 2012/08/28 02:07:35
• Location: UK
• Status: offline
Re:pic 24 crc problem 2013/06/18 12:46:26 (permalink)
5 (1)
Hello,
As far as I am aware, CRCs can be calculated in two main ways. These are dependant on the direction of shift (which is normally associated with the transmission method. ) eg. Uart tx bit 0->7. SPI tx bit 7->0.
Just to confirm your understanding, as long as you use the previous result, the CRC can be calculated in whatever blocks you choose, or 'on the fly' (as we do in our 'peerlink' application). The same result should occur. Obviously the data must be in the order transmitted. The issue you may experience with the MChip CRC peripheral is that it appears 'locked' into the bit 7->0 shift and is no good for the UART. Without testing your problem, I would guess that you are inadvertingly swapping around the order of the 16 integer blocks without realising it. Example your integers are INT(0)..INT(31) seperate into blocks INT(0)..INT(15) and INT(16)..INT(31). Push INT(16)..INT(31) through CRC. Take result and then push INT(0)..INT(15) through. Is this the correct result.
I hope this assists.
T Yorky.
Neddie
Starting Member
• Total Posts : 60
• Reward points : 0
• Joined: 2010/09/06 05:53:06
• Location: 0
• Status: offline
Re:pic 24 crc problem 2013/06/19 23:17:01 (permalink)
0
Hi there. I'm not using any peripherals in my application(usart , spi etc).
I'm taking an array of data , say Data[8] = {1,2,3,4,5,6,7,8};
Run it through the CRC engine (Byte 1 first) , CRCWDAT = 0 and get checksum xxxx;
Now split array into 2.
Data1[4] = {1,2,3,4}
Data2[4] = {5,6,7,8}
Run Data1 through CRC( 1 first) , get checksum yyyy;
CRCWDAT = yyyy
Run Data2 through CRC( 5 first) , get checksum qqqq , not xxxx as expected.
What gives.
It seems that if CRCWDAT is not zero at the start , the cRC engine gives the incorrect result :0(
T Yorky
Super (Thick) Member
• Total Posts : 514
• Reward points : 0
• Joined: 2012/08/28 02:07:35
• Location: UK
• Status: offline
Re:pic 24 crc problem 2013/06/20 02:00:55 (permalink)
0
Hi,
Have you tried putting Data2[4] through first and then Data1[4]. Is this the correct result?
Have a look on the Web for CRC calculations. There will be loads of info. From memory, as mentioned before, depending on the data, a left shift or a right shift is performed. This is because your block of words (or bytes) is in fact one big number or bit stream (consisting of bit 0 to bit 63 in your 2nd example). Termed the polynomial. This has to be divided by the CRC divisor (which varies). BUT.. depending on how this big number is transmitted, the most significant bit (your example bit 63) might be in the first word(byte) received or the last. This determines which way you shift when dividing, BUT also determines whether the first word in the block is the Most Significant Word or the Least Significant Word. For the MChip CRC peripheral the shift direction is fixed which (I think) makes the MSW the last element of the array so you have to 'push' the data through last element first !? Useless for the UART.
As I say all off the top of my head. Anybody spots any mistakes just put it down to old age !!!
T Yorky
jglaria
Junior Member
• Total Posts : 32
• Reward points : 0
• Status: offline
Code example which supports initialization and continuation Re:pic 24 crc problem 2013/08/14 10:29:38 (permalink)
4 (1)
Hi,

I needed an answer to this same question and I have had to implement it myself. Just in case anybody needs the same, I've shared this code example which supports initialization and continuation:

http://www.microchip.com/forums/fb.ashx?m=740115

Good luck,
Jose J.

gaubuali
Starting Member
• Total Posts : 26
• Reward points : 0
• Joined: 2008/10/18 09:34:27
• Location: 0
• Status: offline
Re:pic 24 crc problem 2018/05/16 00:58:44 (permalink)
0
Hi,
I have the same problem on dspic33EP.
Is there anybody have solutions ?
davekw7x
Entropy++
• Total Posts : 1673
• Reward points : 0
• Joined: 2012/01/16 12:01:07
• Location: Left Coast, USA
• Status: offline
Re:pic 24 crc problem 2018/05/16 07:44:22 (permalink)
5 (1)
A few suggestions:

Here's what I would try:
• Initialize the CRC module.
• Feed bytes/words to the CRC as they become available.  Do NOT save the previous CRC and try to use it to re-initialize the CRC module again.  Just leave the CRC module enabled.
• When all data have been shifted through the CRC module, retrieve the result and do whatever you need to do.

If this is not practical (for example you are using the CRC module for two different calculations with input data interleaved between the two calculations), try the trick in the link from jglaria.  (Thanks, Jose.  Great job!)  It might be a little trickier for some applications (8-bit data to a 16-bit CRC, for example), bit I think it's worth a try.

If none of this helps, then consider doing the following:
• Tell us what PIC you are using.  There are about a gazillion possibilities, and later devices have different functionality in their CRC modules than some of the older ones.  It really makes a difference to people who would like to help.
• Create a complete small project with an example sequence of data values for which you know the answer.  Tell us how you tested and what you expected to get and what you got.
• Use the "package" function in  MPLABX to create a zip file for the project.  Post it in a brand new thread (not a continuation of this one).

Regards,

Dave
post edited by davekw7x - 2018/05/16 07:46:00

Sometimes I just can't help myself...