Re: ATmega88PA EEPROM Memory Life
2012-12-13 by bayramdavies
--- In AVR-Chat@yahoogroups.com, "Benny Smith" <benny@...> wrote: > I have a digital light dimmer whose > intensity level is ... an 8-bit > variable. When power is removed ... > when the light is turned ON again, > the dimmer level is restored to its > previous value ... cannot sense > removal of power ... forced to save > the dimmer value ... when it changes. OK, well, the solution to your problem has nothing to do with sensing power loss and saving state at that time, then. All you need is a scheme for saving a single byte of data in EEPROM when the data changes only as a result of user interaction. You need to decide on an upper limit for how often the data will change, on average, and figure out whether an EEPROM cell is really going to wear out in the product's lifetime. Consider not saving every sample of the user's input, but only saving the value when it has been left alone for some time, such as five seconds or one second. The result of this will probably be acceptable to the user. If you still think that you will need more changes than a single EEPROM byte can tolerate, I would personally go with rotating the value thorough a circular buffer rather than counting uses of a single byte and then moving on. This would be just more robust and avoids relying on that 100,000 number. You need to come up with a way of finding the "real" value in the buffer after a power cycle. The easiest way is to define 0xFF as invalid data. Then you just scan the buffer for the last value that isn't 0xFF. Write the new value before erasing the old one from the previous location. Whatever scheme you pick, you may still have to deal with loss of power *during* an EEPROM write or erase operation. This would basically leave garbage in the EEPROM. You can do this without sensing power loss, but it is much easier if you just check that all is well before starting the write or erase. In other words, don't start the write or erase if it looks as if power is going down. You will then only need a holdup time long enough to complete the write or erase. Your idea of sensing an impossibly sudden change in the temperature sensor output should work if you're sampling it fast enough. If you can't tolerate the possibility of power loss during a write or erase producing garbage and you really can't sense power loss with even just enough hold-up time to complete a write or erase then you have a more difficult problem that you thought you had. Graham.