With data containing a lot of the same value, it is important that the checksum algorithm takes into
account the address of the data as well as the content, so a simple arithmetic sum is not suitable.
A simple enhancement could be to XOR the data bytes with the address (or byte count) LSB before
adding. A simple CRC is not at all complicated to do if speed is not critical - a handful of
instructions. If you're using a serial eeprom with bit-bashed access, it gets even easier as you add the CRC in
the read/write code in half a dozen instructions or less.
You don't need to understand the maths. If you're using the PIC 18 series, the multiply instruction
offers some useful possibilities as well.
On Wed, 26 Mar 2003 10:00:58 -0000, you wrote:
{Quote hidden}>Being of the mathematically challenged variety, I was pondering this
>question the other day, after having some problems with devising a checksum.
>
>What is a good way of doing a checksum? The particular data I have contains
>lots of 0x00 bytes, with a few interspersed non-zero bytes. I was wanting to
>store these in an eeprom with a header of 8 bytes, and a checksum that my
>initialisation routine could use to verify data integrity on power up, and
>if necessary report an error message.
>
>The header is to contain two 16 bit pointers, one to beginning of data,
>other to end of data (actually checksum byte). If both are equal then there
>is no actual data, and the checksum should be just the header checksum. The
>beginning of data pointer should always point to location 8, once the eeprom
>has been initially set-up, but it turned out the algorithm I was using still
>reported a good checksum with the ex-factory contents of all zeros. :)) I
>was using an add and shift algorithm I had come across on a serial line
>protocol, but other details of that protocol meant it did not get lots of
>zeros in the data because of compression within the protocol. On this basis
>it looks like I chose an unsuitable checksum system for this purpose,
>although now it is all installed and running it seems to serve the purpose
>OK.
>
>Does anyone have any pointers to suitable algorithms that those of us who
>are challenged in these sort of mental mathematics can look at please? About
>the only other method I could think of was to use a CRC type method, but I
>was not looking to do anything quite that complex.
--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email .....listservKILLspam
@spam@mitvma.mit.edu with SET PICList DIGEST in the body