On 20 Sep 2012 at 20:39, Veronica Merryfield wrote: > Anyone else tried this? Good/bad?=20 >=20 > I have a project with a PIC24 that is using the self programming of > flash to store some non-volatile data including a slow count - up > time in minute increments. The counter is part of a larger structure > of NV data.=20 >=20 > I want to avoid rewriting the whole block each time the counter is > updated and came up with the following.=20 >=20 > Flash when erased reads all ones. Writing changes ones to zeros. > Overwriting can happen but only to change ones to zeros (I assume > the PIC flash behaves like other NOR flash in this regard). By > setting aside a byte or two as a counter, each count could be > represented as a zeroed bit, each bit zeroed being an increment. > When all are zeroed, a real counter is updated with the number of > bits at zero and the process can start over. As a further > enhancement, each time the block is written for an update of > something else, the counter would be updated from the bit count and > the bit counter erased to go again.=20 Your idea sounds feasible. Each consecutive bit cleared will represent 1 mi= nute=20 though so you only store 8 x 1 minute ticks in a byte, vs 256 if stored sim= ply as an 8=20 bit count. As the bits are cleared in sequence you can check for an error if a bit is = cleared out=20 of sequence, but what to do with it then... reset to zero, flag an error? D= epends on=20 your application. I have implemented an hours counter for an industrial machine before. It wa= s=20 surprisingly quite a lot of work to come up with something that worked reli= ably and=20 covered all the "requirements" of PIC EEPROM usage, ie. endurance, refreshi= ng,=20 etc. I used a 4 byte counter incrementing every 0.001 hours (3.6 seconds) of eng= ine=20 running time, but only update the values in EEPROM every 0.1 hours or whene= ver=20 power failure is iminent. Also, the EEPROM values are stored in triplicate,= using=20 best 2 out of 3 method to ignore and repair errors, plus the data is rotate= d around=20 the EEPROM to perform wear levelling and make sure it gets refreshed regula= rly. Hope this helps~! --=20 Brent Brown, Electronic Design Solutions 9 Titoki Place, Pukete, Hamilton 3200, New Zealand Ph: +64 7 849 0069 Fax: +64 7 849 0071 Cell: +64 27 433 4069 eMail: brent.brown@clear.net.nz --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .