bibre:
I've read that these non-volatile memory on the Arduino have a limited life.
They do. What you have read is correct.
Say, if I write and read a 2 byte word to/from the same addresses many times, over their life expectancy, what happens?
I have read these are possible failures: erase failure (byte is stuck at the previous value), write failure (byte is stuck at 0xFF), stuck bit (either high or low), retain failure (value gradually turns back to 0xFF).
Will all memory start performing erraticly? Or just those 2 bytes?
With EEPROM, just those two bytes. I believe Flash is also byte-wise so just those two bytes would fail. In the worst case, Flash is page-wise so the page would have problems.
Will the Atmega chip be worthless after that?
In my opinion, yes. It is not worth the potential headache when a replacement processor costs about $5.
I am currently saving and reading back that word (thru the serial port) on my host PC hard disk to avoid that. But is it really necessary to do that?
Let's do some math... In simple terms, Atmel guarantees 100,000 EEPROM writes over 20 years. That is 5000 writes per year. ~13.7 writes per day. 13.7 writes per day every day for 20 years. Guaranteed to work.
Well, ideally every time I change the position of a turnout (switch or point in the UK) in my model railroad. I do not change the turnouts very often anyway.
It is not really important since it's just my hobby but that's a way to really know what the last turnout status is for the next running session, specially if there's a power interruption or something.
I guess I'll stick to my current sketch talking to my FreeBasic host program. It's not worth to risk the whole chip, specially if its not in a socket.
I was just curious of what would happen. And yes, I agree that those bytes will tend to be 0xFF.
I forgot to mention that in 20 years I know where I'll be and the trains and electronics will not be as important as my Celestial harp. Just check my profile, I'm a class 46 baby boomer, he he!
EEPROM is organized into pages of 4 bytes. So you will wear out 4 bytes at a time. It hopefully goes without saying that you wouldn't write to it unless the relevant thing has changed (eg. the points).
What you might do is write in those 4 bytes something like:
Current value (2 bytes)
Counter (unsigned int)
Each time you write, you decrement the counter (it would start at 0xFFFF if I'm not mistaken). Once it hits zero you "discard" (ignore) those 4 bytes and move onto the next 4.
That would give you 65535 writes per 4 bytes. So for 1024 bytes of EEPROM, then 65535 * 256 = 16776960 writes you could do.
Let's assume you change the points once every minute, and don't bother sleeping ever. You could change the points for 31 years before you use up all the EEPROM.
Of course the "current value", being 16 bits, could hold information about 16 sets of points/signals.