> Just another idea cross-parity checking. ( Not my ;) > Advantage of this method - easy to implement with PIC . > Misadvantage - to correct 48 bits of data need 16 reserved bits > (data efficient is 75%) > So question - is there another simple algorithm which also easy to PIC > programming > and have much more data efficient ? For datagrams as described (56 bits data, 8 bits check) a CRC would be better, and would be by recommended approach. > I look to CRC coding\decoding idea - I see I have to multiply\divide on > some nums, > so I think CRC is hard for my purpose . Many documents I've seen on CRC are confusing. Using straightforward code, a PIC will require 16 instructions/cycles to run each byte through the 8 bit CRC [assuming straight-line code]. Using looping code requires more cycles but fewer instructions. My recommendation is to have one CRC-byte routine which is called once for each byte in the message. In this case, the routine is 17 cycles plus call/return. The CRC byte routine itself is remarkably simple: ; DoCRC: Given a number in W, munge it into the CRC. To compute the CRC ; for a message, set CRC to the first byte of the message and then ; call this routine once every other byte of the message. Then call ; it once more with a constant value in W. The routine would have ; been a little more intuitive if I xor'ed W into CRC before doing ; the bit-munge (rather than having to do the extra call to DoCRC at ; the end) but that would have required an extra two cycles per call. ; Sorry I don't offhand know the proper values for Magic0 to ; Magic7. I'll have to write a little program to crunch them out. ; This routine should give you a pretty good idea of what's involved, ; though. DoCRC: btfsc CRC,0 xorlw Magic0 btfsc CRC,1 xorlw Magic1 btfsc CRC,2 xorlw Magic2 btfsc CRC,3 xorlw Magic3 btfsc CRC,4 xorlw Magic4 btfsc CRC,5 xorlw Magic5 btfsc CRC,6 xorlw Magic6 btfsc CRC,7 xorlw Magic7 xorwf CRC return > Finally I haven't much ROM space free inside of PIC to realize CRC > multiplication > and division, I looking for "checking" fast algorithm solution about > 70..100 program > words for PIC16Cxx . To checksum a 7+1 byte datagram with the above routine would be well within your means: movf Data0,w movwf CRC movf Data1,w call DoCRC movf Data2,w call DoCRC movf Data3,w call DoCRC movf Data4,w call DoCRC movf Data5,w call DoCRC movf Data6,w call DoCRC movlw $A5 ; Or whatever; almost anything non-zero is good call DoCRC ; At this point, CRC holds the CRC value. You could either send ; the computed value or check it against a received value which ; is stored elsewhere. The CRC method above will use 34 instruction words and take 174 cycles to execute (total time for all 7 bytes). While it may not look like much, use of the proper constants Magic0..Magic7 will give you: - Full detection of all two-bit errors - Full detection of all errors which occur within 8 consecutive bits - Full detection of all errors involving an odd number of incorrect bits - Ability (using more code) to correct all single-bit errors, with minimal risk of "correcting" something into an equally-bad packet (depending upon speed/codespace requirements, there are a number of approaches you can use for this).