Posted by Gregory Ross at 03/18/2001 2:15 AM EST
Engineer on team #330, Beach Bots, from Hope Chapel Academy and NASA/JPL.
In Reply to: Ahh! Program trick confusing!
Posted by Gui Cavalcanti on 03/17/2001 1:01 PM EST:
I can see a possible problem or two with your pseudo program.
Remember, every time you “run” one of the programs in your BASIC Stamp project, it is run from the beginning – including any initialization code. This will happen every time through the main loop – approximately 40 times per second. More than likely, this is not what you want to have happen.
Obviously, as with any programming problem, there will be more than one way to overcome it.
Probably the easiest way (and not the way I did it when I split up our program) is something like this:
Program 1:
Initialize
RUN Program 2
Program 2:
SERIN command
perform light routine
perform compressor control
RUN Program 3
Program 3:
perform steering functions
RUN Program 4
Program 4:
perform lift control functions
RUN Program 5
Program 5:
perform bridge balance function
SEROUT command
RUN Program 2
Note: In the initialization, everything needed for all programs should be initialized. The only exception is anything that needs to be initialized in EEPROM (which can be accessed only from its own program.) If you need to initialize anything in EEPROM, I would suggest something like:
Program 1:
Initialize
RUN Program 2
Program 2:
if first time then Initialize
SERIN command
perform light routine
perform compressor control
RUN Program 3
Program 3:
if first time then Initialize
perform steering functions
RUN Program 4
Program 4:
if first time then Initialize
perform lift control functions
RUN Program 5
Program 5:
if first time then Initialize
perform bridge balance function
SEROUT command
RUN Program 2
You also need to remember that all of the variable space and all of scratchpad RAM is common between programs. You need to be sure to use the same variable definitions and scratchpad memory map in all your programs. The easiest way to do so is to declare all your data in an include file, and use the BASIC Stamp Preprocessor which I wrote to insert my include file into all my project files. I’m still not quite ready to formally release it, but if you are interested in beta testing it, let me know, and I will e-mail it to you.
Gregory Ross
Team 330, Beach Bots (Los Angeles Regional co-champs!)
: OK… wait. I’ve just read that entire segment dedicated to the extended programming trick that involves multiple programs… but i’m confused. Do you add subroutines before or after the “RUN” command line in your programs? For example, i’ll give you the following…
: Program 1:
: Initialization
: SERIN command
: light subroutine
: RUN Program 2:
: -----
: Program 2:
: Initialization
: Major subroutines
: RUN Program 3:
: -----
: Program 3:
: Initialization
: minor subroutine
: SEROUT command
: RUN Program 1:
: -----
: Is that right, or did I really screw something up?
: -Gui Cavalcanti
: 422 (Mech Tech)