ATmega328 EEPROM Write Cycle Efficiency

Hi all,

I’m a little confused about the built in EEPROM. It’s supposed to be able to pass 100,000 write cycles, but what I’ve been unable to find out is if that means 100,000 different individual bytes can be rewritten or each byte can be rewritten 100,000 times. To further explain my issue, I have the following code:

  for (int i=0; i < 64; i++) { EEPROM.write (     i, array1[i] ); }
  for (int i=0; i < 64; i++) { EEPROM.write (  i+64, array2[i] ); }
  for (int i=0; i < 64; i++) { EEPROM.write ( i+128, array3[i] ); }
...etc...

I have a series of 6 of these arrays, each with up to 64 values - although these are going to be more like banks that can be filled if I so please - but for the most part only the first 10 values will be used. This segment of my code will only be run a couple times a day, so my questions are:

  1. Can each byte be rewritten 100,000 times or can only 100,000 bytes in total be rewritten?
  2. My code is set to go through the above for loops even if some values haven’t been changed. Are those values “rewritten”, even if the value doesn’t change? I’m assuming the answer for this question is the same answer for values that are zero and stay as a zero.

Thanks in advance for the help!

Pat

pattobrien: ...each byte can be rewritten 100,000 times.

Yes, 100,000 per address. May be more, factors such as times between writes, temperature, voltage, may allow even more to occur.

It would be best to avoid re-writing locations whose value has not changed as this will avoid wear on the EEPROM.

The failure mode of the EEPROM is that over time it may get a bit error i.e. the value you read back is not quite the same value that was written. If you write a value to EEPROM and then read it back repeatedly, eventually the stored value will get a bit error and you'll get the wrong value back. For a new EEPROM you would expect to be able to read it back over a very long period without any errors, but the more times you erase a location the sooner errors will occur at that location.

This failure mode has some interesting implications. If you only write to a location occasionally, the location won't wear out. If you write to a location frequently but [u]keep[/u] writing to it frequently, the fact that it's worn out won't impact you for a very long time because the data is being refreshed. The worst thing you can do is write to a location loads of times so that it wears out, and then stop writing to it and assume that last value will remain indefinitely.

a common technique to reduce the wearing a bit is to read before writing, see snippet below.

void myEepromWrite(addres, value) { if (eeprom.read(address) != value) eeprom.write(address, value); }

if values are often similar this simple trick can reduce the writing a lot.

robtillaart: a common technique to reduce the wearing a bit is to read before writing, see snippet below.

void myEepromWrite(addres, value) { if (eeprom.read(address) != value) eeprom.write(address, value); }

if values are often similar this simple trick can reduce the writing a lot.

Thanks everyone for the help, Rob this code in particular is perfect!

be aware its effect really depends on the distribution of values.

If you have all numbers 0..255 occurring equally, the gain is only 0.4% of 100.000 writes (still 400 writes).

If you have the chance of a repeating number (e.g. temperature every minute) but the difference between night and day is 10 .. 30 degrees C. so it only chances ~40 times per day it is only written 40 times per day instead of 60x24=1440 times per day.