I built a simple project using an arduino to control a I2C digital potentiometer being controlled by a remote control via a IR Detector. The purpose is to be able to control the input signal of a audio amp using a remote control. It works just fine, but at the point I set the power up volume to default at -49dB.
But I thought in using the internal EEPROM to hold the volume between power cycles. But my question is when should I write to the EEPROM? Because I don't have a power down signal, and I don't want to write on every key press, because someone can change the volume a lot in a day.
Should I set a counter variable and watch for changes like every 30 seconds or so, and write to the EEPROM?
The value I want to store is a uint8_t.
I'm very new to the field, so I'm looking for any clever tricks.
Best Answer
The ATmega328 data sheet, in section "8.4 EEPROM Data Memory" says The EEPROM has an endurance of at least 100,000 write/erase cycles
So a reasonable strategy should be okay.
If the number of writes/day is still an issue, detect 'power down', and change the strategy to only saving when power is being removed.
The chip will need several milliseconds to ensure it can do the EEPROM write. The best data I've found about EEPROM write time is "Table 28-18, Typical Wait Delay Before Writing the Next Flash or EEPROM Location" says the delay is "3.6ms".
So the local power supply to the ATmega will need a maintain an operating voltage for longer than that to ensure EEPROM is correctly written. That might be a bit awkward to do on an Arduino. IIRC the power supply capacitance within the power supply is about 100uF, which is marginal, and probably too little to be sure of doing the write, especially if any significant loads were being driven at the same time.