Thursday 16 June 2016

arduino - 100k EEPROM writes "per bit" or as a whole?


As I understand it, the life of an EEPROMs is usually rated at a certain number (e.g. 100k) of writes. Is this "per byte" or writes to the EEPROM system as a whole?


E.g. If the EEPROM has 4k bytes, could I conceivably make 400 million writes if they were evenly distributed?


Specifically, I'm talking about the EEPROM in the Arduino Mega 1280/2560.




Debrief: Thank you stevenvh and Majenko for your helpful explanations. I asked because I wanted to know whether I needed to bother updating only dirty variables when saving a lot of data (a large configuration). From a wear perspective, the answer seems to be 'no': wear happens at the "bit level" and is only caused by setting bits to zero. From a speed perspective, perhaps it would make sense to minimise the size of writes, but if this is not a consideration for your application, then you needn't stress out about it.




Answer



It's not just write cycles that's specified, but erase/write cycles. On the AVR EEPROM can be erased by byte. Erasing sets all bits to 1, writing selectively clears bits. You can't program a 1, just 0s. If you want to set at least one bit to 1 you have to erase that byte.
Erasing removes the charges from the FET's floating gate, but on each erase cycle some of the charge remains on the floating gate, which won't be removed through the quantum tunneling. This charges accumulates and after a number of cycles there's so much charge left on the floating gate that the bit still will read 0 after erasure. That's what determines EEPROM life, it's erasure rather than writing. So you can safely write additional 0s, as long as you don't erase.
As a result, if the datasheet specifies 100k erase/write cycles you can have maximum 800k write cycles, one bit at a time, for 100k erasures.


If you're using only part of the EEPROM memory space you can extend its life by distributing the data, like Matt says this is called wear leveling.
The simplest method of wear leveling when writing blocks of data is to include a counter with the data. Suppose you need to keep 14 bytes of data. Add a 17-bit counter as two bytes, you probably have a bit to spare for the 17th bit. Increment the counter before writing the block of 16 bytes. If the counter has reached 100 000 you know this block is becoming unreliable, so you move to the next 16 bytes. Use this until it is worn as well. And so on. A 4k memory consists of 256 sixteen byte blocks, so you can extend the original 100k cycles to 25 million.
It should be obvious that your gain is greater with smaller blocks of data.


further reading
data retention on a microcontroller


No comments:

Post a Comment

arduino - Can I use TI's cc2541 BLE as micro controller to perform operations/ processing instead of ATmega328P AU to save cost?

I am using arduino pro mini (which contains Atmega328p AU ) along with cc2541(HM-10) to process and transfer data over BLE to smartphone. I...