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 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. > > I want to avoid rewriting the whole block each time the counter is update= d and came up with the following. > > Flash when erased reads all ones. Writing changes ones to zeros. Overwrit= ing can happen but only to change ones to zeros (I assume the PIC flash beh= aves like other NOR flash in this regard). By setting aside a byte or two a= s a counter, each count could be represented as a zeroed bit, each bit zero= ed 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 enh= ancement, each time the block is written for an update of something else, t= he counter would be updated from the bit count and the bit counter erased t= o 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 --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .