Quote Originally Posted by Jerson View Post
Keith

This post of yours is brilliant. You explain very clearly the way the million cycles can be used up and how fast.

Jerson
I've done something slightly different, but hey, it works for me...
Got a project (temp/fan controller type thing), controls 4 relays, runs off mains power most of the time, super-low current trickle charger on a battery pack, really small solar cells backing those up...
I save the current relay status about every 10 seconds, 4 bits total. 256 bytes of eeprom. When the unit was first fired up, I cleared all of the eeprom to $ff. The first time I wrote to a byte, I clear bit 7 in byte 0, and saved the status to the lower 4 bits. The next time, I looked for the first byte in the eeprom with bit 7 set, then cleared that byte's bit 7 and saved the status to the lower 4 bits, and so on and so on and so on...
When I get to byte 255, I check the power on the mains (make sure I'm not running off battery backup), then clear all of the bytes back to $ff and start the process over again.
If main power fails, then comes back on, I look for the last byte in the eeprom with bit 7 cleared and read the state from it...then resave it of course...
This way, I use each of the bytes equally (by looking for the first byte with bit 7 set) and saving the state there. According to the table above, I should get about 40 years or so out of this controller. The building will fall down before that!
Then again, there's a thousand different ways to do 'wear levelling' with eeprom/flash and as stated earlier...a guy generally doesn't have to worry about it. I've got an article somewhere that talks all about wearing out eeprom/flash and according to this article, the key is to keep the voltage as low as possible and write as slow as possible (up to the point of doing multiple rewrites at marginal voltage) for maximum eeprom life...and temperature has a lot to do with lifespan. The article also went on to say that even after an eeprom cell has failed during normal writing procedures, rewriting the same cell a few times (within reason of course) will usually work just fine.

I wonder how many of us have actually worn out the flash in a PIC yet...if any...? I thought I did once, turned out the regulator on the MCLR pin went south for the winter (and the rest of the year for that matter)...