Shop OBEX P1 Docs P2 Docs Learn Events
Stamp AI "END Statement" Ramifications — Parallax Forums

Stamp AI "END Statement" Ramifications

HumanoidoHumanoido Posts: 5,770
edited 2009-07-20 01:07 in BASIC Stamp
When a program is ended (BS1), and power is kept on,
the memory and variables are retained. This is a kind of
hibernation or suspended animation.

After the END statement is executed, and the program ends,
is there any simple way to retrieve data from the eeprom and/or
run the program again?

Obviously we cannot reset the stamp or recycle power, or
everything will be lost.

I am dealing with an AI life form and don't want it to die. Of
course, instead of an END statement, the code could end in
a continuous loop. Inside the loop, it looks at a pin. If the
pin goes high, the program goes back to the beginning or
somewhere in between.

Thoughts, ideas, comments welcome.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
humanoido
*Stamp SEED Supercomputer *Basic Stamp Supercomputer *TriCore Stamp Supercomputer
*Minuscule Stamp Supercomputer *Three Dimensional Computer *Penguin with 12 Brains
*Penguin Tech *StampOne News! *Penguin Robot Society

Comments

  • skylightskylight Posts: 1,915
    edited 2009-07-19 11:00
    not sure if you can direct address a goto label from the debug window?
  • Mike GreenMike Green Posts: 23,101
    edited 2009-07-19 14:19
    When you download a new program that has DATA or EEPROM statements, that data is copied to EEPROM. If you later use a WRITE statement to modify the EEPROM data, the modified data is retained. Say you have a byte value at EEPROM location zero that's initialized by an EEPROM statement to the value zero. When your program runs, it does something that produces a non-zero result which gets written to EEPROM location zero, then the program ENDs. If power comes on or the BS1 is reset, the first thing the program does is to READ location zero and initialize itself based on the value read. That state memory will be retained through on/off or reset/END cycles. By only saving the state at the end of the program, you avoid wearing out the EEPROM location. Note that you don't have to use only one byte, you could save all the variables to EEPROM, but many of them won't need to be saved.
  • HumanoidoHumanoido Posts: 5,770
    edited 2009-07-19 15:15
    Thanks Mike. It looks like I was mixed up about loading in a new program (which will wipe the eeprom to zeros). So mainly the eeprom is preserved as long as the original program is kept loaded, the power is recycled, or the stamp is reset. This is exactly what I need for the program.

    So before the END statement, the code should write all necessary variables to eeprom, then read the variables back in after a power recycle or reset. Does that sound correct?
  • Mike GreenMike Green Posts: 23,101
    edited 2009-07-19 15:33
    Yes

    You should define the initial state of the variable values using the EEPROM statement since that will be what's initially there when you download the program.
  • HumanoidoHumanoido Posts: 5,770
    edited 2009-07-20 01:07
    Very good - this gives several programming opportunities for maintaining an AI life form, both at the beginning of program loading and at the "end" of the program to maintain state. This information is greatly appreciated. Thank you sincerely.
Sign In or Register to comment.