Eeprom use?

magicjohn

New Member
I've written a program which frequently changes the data in the pic's eeprom memory - so that the data is preserved when the power is switched off.

I understand the eeprom memory has a limited number of read/write cycles before failing, so would I be better off rewriting my code to use conventional memory and save the data to eeprom say every 10 seconds or so, or am I worrying unduely?
 

Jamster

Senior Member
Most EEPROM has +100,000 writes life.
Even saving every ten second will wear it down quickly.

In your case it may be an idea to have a button that saves the data to the eeprom when pressed, it may also be possible to use a JK flip flop to create a one button on/off switch that when pressed to turn on it puts the flip flop in state "1" and when you press it with the PICAXE on it saves and then outputs the pulse to the flip flop to turn to state "2".

Hope this helps Jamster.
 

srnet

Senior Member
Once every 10 seconds is 6 times a minute, 360 times an hour, 8640 times a day.

EEPROM life is quoted at 1,000,000 cycles, so it could fail at 116 days.

Do you feel lucky ?
 

BillyGreen1973

Senior Member
I think I would be tempted to use an external EEPROM, and only save every 15mins for example. This way if the EEPROM does give up the ghost, it can easily be replaced and you haven't ruined a Picaxe!
Also using this method, the hardware will still continue with it's main function, but just not save the data, it would fall back to preset values set at programming time.
If the Picaxe internal EEPROM fails, the program will probably stop running too (depending on the Picaxe type).

Another solution would be to use an SPI flash card (SD or Compact Flash) to store the data. These devices are good for roughly the same amount of writes, but are easier to remove and replace/backup.

Also saving data out to a PC is another option that will theoretically give infinite write cycles
 

MartinM57

Moderator
You could use external FRAM (Ramtron FRAM, Google it) as an external device with ~10^15 writes - you're unlikely to wear that out ;)

....or, a bit more complex, design the hardware so that the PICAXE can detect when the main power input power fails/is switched off, and it has time to write its data to EEPROM. More details on request... ;)
 

westaust55

Moderator
Battery backed RAM does no have the "life" problems in terms of number of writes.
Do you have a DS1307 RTC chip?
That RTC (also DS1338) have 56 bytes of battery backed (NV) RAM onboard
 
Last edited:

donrecardo

Senior Member
If you put a reasonably large capacitor across the PSU to your chip and take a trigger wire from the PSU side of the capacitor, seperated from the capacitor with a diode. When you turn off the psu the trigger wire drops to 0V very quickly but the capacitor continues to power the picaxe for a short while ( long enough to do a data save) . You use the trigger wire to trip an interupt which then does a data save . That way you only need to save once each time you turn off the power and you cant even forget to do it , it happens all by itself

Don
 

MartinM57

Moderator
Thanks DR - the detail for the second part of my post #5 :)

You just have to make sure there is enough time to write the EEPROM before the supply fails at the PICAXE enough for the BOD to kick in before you've finished - depends how many bytes are to be written...but Magic John hasn't told us that (or replied to anything in this thread, yet)
 

magicjohn

New Member
Hi,

Further to your advice I've rewritten the code to use scratchpad memory and save the data to eeprom - providing that the data has changed, and there has been no "activity" for two minutes.

It's a short term use device that shouldn't be running for more than twenty minutes at a time (once I've finished testing and debugging it!), and then it will only be used about once every two weeks or so. (Should last nearly 400 years?)

I'm intrigued by the idea of an automatic save on power-down and would be grateful for any more information that anyone might have. - I'm saving 117 bytes of data (conveniantly from scratchpad addresses 0 - 116 to eeprom addresses 0 - 116) and running from a 4.5v supply.
 

hippy

Ex-Staff (retired)
Save on loss of power is relatively easy in theory requiring just three things ...

1) A means to detect and indicate loss of power.

2) Software, often an interrupt, which can be called when power is lost. The code simply writes all data to Eeprom then usually stops.

3) Some means to supply power to the PICAXE ( and Eeprom if external ) for long enough that it completes whatever it's doing, the loss of power is recognised, and all data is written to the Eeprom.

Things to watch out for are the PICAXE doing things which take a long time or 'forever', so the power fail is never seen, plus the 'emergency power supply' not lasting long enough for the data to be written or reliably. Also resets or program restarts which might occur if power comes back before the writing is complete.
 
Top