Shop OBEX P1 Docs P2 Docs Learn Events
Non-volatile variable — Parallax Forums

Non-volatile variable

ScottLScottL Posts: 14
edited 2006-05-20 03:14 in BASIC Stamp
I need to keep the contents of a variable even with the power off. How?· -Scott

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2006-05-18 18:19
    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 SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-05-18 18:20
    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
  • ScottLScottL Posts: 14
    edited 2006-05-18 19:40
    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 SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-05-19 03:01
    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
  • ScottLScottL Posts: 14
    edited 2006-05-20 03:14
    No other SPI devices. Maybe I need to get a serial display. -Scott
Sign In or Register to comment.