Shop OBEX P1 Docs P2 Docs Learn Events
saving variables when stamp is not powered — Parallax Forums

saving variables when stamp is not powered

dwbowendwbowen Posts: 30
edited 2007-08-26 04:56 in BASIC Stamp
Hello,

I am writing to see if there is a way to save a variable while a basic stamp is turned off? Meaning I want the stamp to run through a routine where a specific number is reduced with each program cycle. If the stamp power is turned off it will store the reduced number and continue where it left of when power is returned. Does this make any since to anyone????? Here is an example of the code I'm using.....

' {$STAMP BS2}
' {$PBASIC 2.5}

scroll_time VAR WORD
scroll_time = 20000

main:

HIGH 14

PAUSE scroll_time

LOW 14

scroll_time = scroll_time - 13

PAUSE 1000

GOTO main

I want the stamp to store whatever variable it arrives at when the stamp is turned off. For example if the program cycles through say 50 times the scroll_time variable will be 19350. I would like to know if there is a way to store 19350 as the new scroll_time value while the stamp is turned off. So that when the stamp is powered up and the program begins again scroll_time = 19350. I'm sure there is a simple way to do this I just have not found it yet.


thank you,

david bowen

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-08-23 15:57
    David,

    The only non-volatile memory on the BASIC Stamp is the EEPROM, however, if you keep updating a location within a loop like that you will eventually wear it out. If you had some battery-backed external RAM (Such as that commonly found on RTC chips) then you could save it to that every iteration of the loop. Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • kelvin jameskelvin james Posts: 531
    edited 2007-08-23 17:09
    You could use a " save button ", a button switch that would run a subroutine to write the value to eeprom, before you turn it off. You would read that value back at the beginning of the program, when the stamp is powered up again. I can't think of any way to do it automatically. You could also add a button to reset the variable to the original value if needed.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-08-23 17:12
    It could be done automatically if it weren’t for the write speed of the EEPROM. Even with that I suppose if you had a custom power supply with large caps you could detect the loss of the AC mains and quickly store the data. The problem is that since you’re using a PAUSE you could be stuck there and miss the signal. Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • dwbowendwbowen Posts: 30
    edited 2007-08-26 01:06
    Thanks Guys,

    So I assume using the basic stamp's EEPROM involves using the READ and WRIGHT commands. Because I found I way to do what I needed to with those commands by writing, reading and rewriting the variable on two of the controllers pins. Chris, will doing this shorten the life of the controller or just the two pins? If so how many cycles do you think I can get before the thing quits working? The reason I ask is because the program sample I sent earlier was just a snippet of a much larger routine. This routine could cycle through every minute or it could cycle through in an hour or more. It is dependent on the movements of houseflies combined with the movements of people as they walk throughout a space and therefore extremely random. I'm in a time crunch (the exhibition goes up next week) and there are still many logistics to work out aside from this. I fear I do not have time to order and learn how to incorporate a battery/memory backup like you guys suggest. If the controller will not stand up the writing and rewriting on the pins I will probably just make sure it stays on all of the time.

    Thanks again,

    david
  • Mike GreenMike Green Posts: 23,101
    edited 2007-08-26 02:02
    READ and WRITE don't involve any of the controller pins, they simply use the on-Stamp EEPROM. A "page" in EEPROM, usually a block of 64 bytes, can be rewritten somewhere on the order of 1,000,000 times. The EEPROM fails by being unable to write zero bits into a location. One way to help reduce the wear on a location is to use READ to read the location before writing and skip the WRITE if the value you want is already written there.
  • Ol' GeoOl' Geo Posts: 30
    edited 2007-08-26 04:56
    Can't you just add a pushbutton that would store the last count unto EEPROM by using WRITE command? Press the button just before you turn the power off. The stored datum occurs only once each time you turn the power off, hereby, it would not "wore out" the rom.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Ol' Geo
    Retired Software Engineer

    An oscilloscope is a window of unseen electronic world. - GM
Sign In or Register to comment.