Shop OBEX P1 Docs P2 Docs Learn Events
using eeprom for persistent store — Parallax Forums

using eeprom for persistent store

alpinekidalpinekid Posts: 8
edited 2011-10-07 08:44 in Propeller 1
I designing a propeller based product for a client and they need one variable to be persistent over a power cycle. I'm trying to figure out if the address of the variable returned by the @ operator in spin is useful to get the address of the variable in the EEPROM. The plan is to write the value to the EEPROM every minute.

I'm hoping that I can just use the I2C and rewrite that location with an updated value. Sort of like self modifying code.

I have declared the variable.

DAT
varName WORD 0


Does the @varName match or is a fix constant offset to the physical place in the EEROM?

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2011-10-06 15:52
    A number of people have done what you suggest, namely writing data to the location(s) in EEPROM where the data will be loaded from so that variable becomes a persistent store for the data. It works fine. You use the @ operator as you mentioned for the address in EEPROM.

    Very important is to not write to EEPROM too often. It's too easy to wear out locations in the EEPROM. One thing that's useful is to read the data already in EEPROM and compare it to the data you intend to write. If they're the same, skip the write operation.

    Do remember that, if you upload a new version of your program to the EEPROM, it replaces everything in the first (or only) 32K including any persistent values stored there.
  • alpinekidalpinekid Posts: 8
    edited 2011-10-06 16:14
    Thanks for your quick reply. I have already advised the client on the issue of wear. I see in the microchip spec that the eeprom has a milliion write cycles of life. That gives them about 2 years of life at once a minute updates.

    I like your idea of reading first.
  • Kevin WoodKevin Wood Posts: 1,266
    edited 2011-10-07 06:27
    > That gives them about 2 years of life at once a minute updates.

    That's just for the location being written. Ideally you would write to new locations over time to maximize the life of the EEPROM.

    That is, unless you get $$$$$ for swapping out the EEPROM... :)
  • Mike GreenMike Green Posts: 23,101
    edited 2011-10-07 08:27
    If the issue of # of write cycles is important, have a look at Ramtron's FRAM. These are persistent memories essentially plug-compatible with standard EEPROMs. They have much higher maximum write cycle limits. You have to keep in mind that read cycles are destructive with an automatic refresh cycle, so read and write cycles both count against the maximums (typically 10^15).
  • Dave HeinDave Hein Posts: 6,347
    edited 2011-10-07 08:44
    As Kevin said, you could use multiple locations in hte EEPROM to increase the life time. This could be done by writing the new value to a circular buffer along with a sequence number. On start up, you would look for the value with the largest sequence number, and then write new values after that. If you use an 8-bit or 16-bit sequence number you will have to handle the case when it wraps back to zero, but that's fairly easy to detect.
Sign In or Register to comment.