Shop OBEX P1 Docs P2 Docs Learn Events
can the bs2 do this? — Parallax Forums

can the bs2 do this?

ERMERM Posts: 34
edited 2005-07-22 12:59 in BASIC Stamp
Is there any way for the BS2 to start where it left off after a power failure? Let's say you have a set of flash patterns all with their own loop. You advance to the next loop by the push of a button. It stays in that loop until you push the button again. If you pull the power, can you have a code that will pick up where it left off when power is re-applied, or will it start at the very beginning of the code? If not, which BS2 would be better for this application? Thanks.

Comments

  • Bruce BatesBruce Bates Posts: 3,045
    edited 2005-07-22 07:41
    Tony -

    There is no "natural" or built-in method of doing what you are suggesting, easily. That being said, it CAN be done, but there is a bit of work to it. You will need to perform "checkpoints" of where you are, so you will know where to return to, after the power failure.

    The way you do this is by writing the "status" to EEPROM (either internal or external to the Stamp), and using that "status" whenever the Stamp is powered up. Not only can this become a bit confusing, but you have the issue of EEPROM write endurance to contend with. There is a finite "life" to the numnber of times you can write to most EEPROMs before they will eventually fail. I've seen figures bandied about ranging from 100,000 to 1,000,000 writes, so I guess you'd have to check the particular EEPROM data sheet for exact specifications.

    From my point of view a secondary source of power is a much more logical choice. If the unit normally operates off a wall wort (plug-in transfomer), provision for a carry-over battery might be an appropriate method. If the battery is rechargable, all the better. Solar power may or may not be available to you to maintain such a battery, or to run the entire system, depending on the current demands.

    Just some thoughts.

    Regards,

    Bruce Bates
  • Paul BakerPaul Baker Posts: 6,351
    edited 2005-07-22 12:48
    Everything Bruce said is correct. There is additional consideration, whether your program is stateless. Checkpointing is required, but if your program is state dependant (if you have any variables whose values determine program flow (such as IF VAR1 = 10 THEN ...) you will need each and every variable for each and every task that has this power loss safe functionality into EEPROM as well. As you can see recovering from powerloss in a stateful system quickly becomes complex, and the backup power option looks more and more attractive.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·1+1=10

    Post Edited (Paul Baker) : 7/22/2005 12:51:59 PM GMT
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-07-22 12:59
    If you're buidling a light flasher you could always save the flash mode to EEPROM when you change it and then jump to that mode on start-up. Since there's be an interruption anyway, will it matter if you restart the pattern? -- you will at least be int he correct mode. By saving just your mode value you can add that code into the button press section that handles the mode change.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
Sign In or Register to comment.