On 12 Dec 2017 at 9:44, Isaac M. Bavaresco wrote: > > For my previously mentioned requirement of the check value not equallin= g 0xFF, I=20 > > think I can live with testing for and replacing that occurence with a d= ifferent code. >=20 > Did you see my other reply about spreading the CRC or checksum over two > bytes? That way you can ensure you will never have a 0xff. > But by using the CRC you don't have to worry about having a 0xff value > for CRC or even for the data, because CRC will catch virtually any data > corruption. > If you use BCD for your data you will use half the storage space, which > equals to half EEPROM writing time too. I could spread the CRC8 value over 2 bytes, similar to what I've done with = the digits.=20 Though I don't see any major problem with sticking to 1 byte and translatin= g a CRC=20 of 0xFF into say 0x5A. It does feel a little cheeky, but it's not like I'm = transmitting the=20 data between devices... the CRC function will be literally the same code on= the=20 same device for both reading and writing. Yes I could have packed 2 BCD digits into one byte, but have opted to sprea= d the=20 data wider to give me an extra method of corruption detection. I can test 3= ways=20 now: check the high/low nibbles to see if a symbol for a single digit is va= lid, check=20 the CRC over all 6 digits, and I can also check against the previous record= to=20 ensure it has incremented by only 1 count. > And much better than using just a "dirty" flag, adding a sequence count > to each record allows you to find the latest valid one. > You could use a record with 2-byte sequence counter, 3-byte BCD value > plus 1-byte CRC. The CRC calculated over the sequence counter and data, > so it would be easy to spot corrupted records. I'm not sure that I'll use a dirty flag... if need be I can change data so = the checks fail=20 and that way mark the record as bad/dirty/deleted. A sequence count would increase just like the hours count does, and at some= point=20 it will roll over as well. So if I have to handle a rollover eventually, th= en I may as well=20 just handle that for the hours count alone. The thought is that marking old= records=20 "dirty" on roll-over would be one way of handling it. Thanks. --=20 http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .