Em 21/09/2012 10:00, Isaac Marino Bavaresco escreveu: > Em 21/09/2012 00:39, Veronica Merryfield escreveu: >> Anyone else tried this? Good/bad? >> >> I have a project with a PIC24 that is using the self programming of flas= h to store some non-volatile data including a slow count - up time in minut= e increments. The counter is part of a larger structure of NV data. >> >> I want to avoid rewriting the whole block each time the counter is updat= ed and came up with the following. >> >> Flash when erased reads all ones. Writing changes ones to zeros. Overwri= ting can happen but only to change ones to zeros (I assume the PIC flash be= haves 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 zer= oed 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 en= hancement, 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. > > It may work, but first check what the datasheet of the PIC24FJ64GA004 > family (39881D) says: > > "With RTSP, the user may write program memory data in blocks of 64 > instructions (192 bytes) at a time, and erase program memory in blocks > of 512 instructions (1536 bytes) at a time." > > > Once I read an NXP document (about an LPC ARM micro-controller) > explaining why you must not write twice the same FLASH block without > erasing: > > Each FLASH block has a hidden ECC used by the FLASH controller to detect > and correct errors, improving the processor's reliability. > When you write a block, the ECC is written at the same time. If you > program the same block again changing some bits from one to zero, the > ECC is written again also, but certainly the new value anded with the > old value will result in an invalid ECC code and the FLASH controller > will report the block as bad and will not be able to correct the "error". > > > I'm sure the same doesn't apply to PICs, but it is good to have that in > mind. > > > Perhaps the granularities of the PIC24 you are using is different. > For processors able to write one word at a time (rarer and rarer > nowadays), Microchip has an application not about emulating EEPROM in > FLASH, AN1095: > > > > Best regards, > > Isaac Veronica, Which PIC24 are you using? After replying I noticed that one program block for the PIC24FJ64GA004 has 1536, and one day has 1440 minutes. If you succeed in changing one bit at a time, you will need to erase the block only once a day. The data-sheet states that the FLASH endurance is 10000 program-erase cycles. If each programming cycle wears the FLASH as much as the erase cycle, then your PIC will last just some weeks. I'm inclined to believe that re-programming a bit with the same value it has already causes minimal wear to the memory cells, because no electrons are flowing through the dielectric. It may work. Best regards, Isaac --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .