PDA

View Full Version : Non-volatile variable



ScottL
05-19-2006, 12:52 AM
I need to keep the contents of a variable even with the power off. How? -Scott

Mike Green
05-19-2006, 01:19 AM
The Stamp stores its program in an EEPROM (electrically erasable programmable read only memory) and, with the READ and WRITE statements, can also store data in the EEPROM in an area not usually used by the program. This is retained when the power is off. The variables are erased when the device is reset (like when power is restored). Read the section of the manual on the READ and WRITE statements and ask for help if that doesn't give you enough information.

Chris Savage
05-19-2006, 01:20 AM
Scott,

How often is the variable being updated? If only once in awhile like a set point you could store it in EEPROM each time it was changed then load it from that location upon startup. However if it's changing rapidly in the code you wouldn't want to write it to EEPROM since it would slow the program down and wear out the EEPROM location. One other possibility was if your hardware included an RTC such as the DS1302 or DS1307 you could store the value in the battery-backed RAM.


▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com (mailto:csavage@parallax.com)

ScottL
05-19-2006, 02:40 AM
Thanks guys, good information. My application is a vehicle odometer. Currently the resolution is 1 mile. You bring up a good point that brings to mind that the collected portion of a mile that has not incremented the mile digit will be lost when the power is turned off. Mmmm... If I incremented the EEPROM every 0.1 mile, then the tenths nibble would change at most 1 million times. But probably lots less in the life of a motorscooter. Is this too much?

I wanted to add a RTC in but I only have 1 unused I/O pin. Is there a way to multiplex the use of them (hardware wise)?

Chris Savage
05-19-2006, 10:01 AM
If you have any other SPI devices in the system it would take only 1 additional I/O pin to add a DS1302.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com (mailto:csavage@parallax.com)

ScottL
05-20-2006, 10:14 AM
No other SPI devices. Maybe I need to get a serial display. -Scott