Run Initialization code only on power-up
edi
Posts: 19
How to run Initialization Code only on Power-Up & not when switching slots.
e.g.
Slot 0 code :
Initialization Code
.
.
.
Main
· Do
··· .
··· .
··· if (blah...blah) THEN
····· · RUN 1
··· ENDIF
··· .
··· .
· Loop
Slot 1 code :
.
.
.
.
.
RUN 0
When slot 1 returns control to slot 0, the initialization section is run again.
I do not want that to happen·....... how is this avoided ?
Thanks in advance .......
·
e.g.
Slot 0 code :
Initialization Code
.
.
.
Main
· Do
··· .
··· .
··· if (blah...blah) THEN
····· · RUN 1
··· ENDIF
··· .
··· .
· Loop
Slot 1 code :
.
.
.
.
.
RUN 0
When slot 1 returns control to slot 0, the initialization section is run again.
I do not want that to happen·....... how is this avoided ?
Thanks in advance .......
·
Comments
Set a switch in EEPROM after you've done the initialization. In the beginning of the Initialization code, check to see if that switch is set. If not, do the initialization. Just before you end the program, you can reset the switch if you need to, depending on how your program terminates.
Regards,
Bruce Bates
Just to expand this topic a bit, and add a bit more clarification, I offer the following.
Your method will only work for those Stamps which supports scratchpad memory. The method I suggested will work with any Stamp platform. Obviously the questioner here IS using a Stamp which has scratchpad memory (since it has multiple programming slots).
Your method is limited to one-time-after power-up or reset. Mine will work for that case, as well as one-time-only. ever.
By way of example, this latter would be the case if clearing an external EEPROM the first, and only the first time, or setting a non-voltile RTC chips to the correct time/date initially, when the program is first run. So too some sensors may need to be first-time calibrated, just on the initial iteration of the program, and never again.
Either or both methods may be correct, depending on the exact circumstances, and how or when "first time only" is defined.
Regards,
Bruce Bates
RunFlag····· DATA····· $FF
Reset:
· READ RunFlag, checkVal
· IF (checkVal = $FF) THEN
··· ' do one-time initialization
··· WRITE RunFlag, 0
· ENDIF
When you download this program, the location called RunFlag will contain $FF.· This is read during the Reset section.· If $FF is detected, you run your initialization code then write 0 back to the RunFlag location.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
e.g.
That works if you want to run the initialization at every power up. On the other hand, as Bruce and Jon have pointed out, if you store the flag in eeprom, the initialization is run only once when you first load in the program. There are variations on eeprom theme too, for example, you can either store the eeprom flag in a location where it will be reinitialized every time you reload the program code, or you can sequester the eeprom flag in a location (like bank #15 on a bs2pe, or in an unallocated eeprom block), where it will take a special effort to rerun the initialization. Both kinds of initialization can be useful. The ram-based kind for ordinary bank swapping, the more durable kind for storing things like device serial numbers and one-time parameters.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
"Initialization Code only on Power-Up"
I'm assumed that meant running the init code once on each power up. Not running init only once even after another power up / reset.
Something like running the code to init a LCD display that needs to be done each reset. I see the value of the other for senor cal or setting RTC.
Thanks for your inputs.
I think that using a (Scratchpad) RAM bit in the BS2e as my "init-code-run" flag will work the best for my application. I do want the init code to be run at every power up (and·also after a hardware reset - although not stated in the first posting). This flag is cleared on power-up (& after hardware reset ???). Hardware reset means actually pushing the reset button on my super carrier board.
I want to use a Scratchpad RAM bit, however the BS2 manual says that the RAM will
be cleared after reset ...... does this mean that both the main Registers + Scratchpad RAM OR does it just mean the main Registers.
Can this specification of RAM reset at power-up be relied upon in future BS2's or is it left up to the whim of the manufacturer of the microprocessor chip (i.e. ubicom, microchip, etc.) ??
Regards,
Richard
·
If you look at any of my programs I usually have a section above the main body of code like this:
Reset:
· ' this code runs after a power-up or device reset
Main:
· DO
··· ' main program code here
· LOOP
You see, there is nothing special to do -- by having the reset code available at a program label the program logic can actually send it back if the some condition dictates that necessary.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Thanks for clarifying what is responsible clearing RAM at power-up/reset. I.e that it
is deliberate & done by BS2 interpreter. This is what I needed.
Regards,
Richard
PS - Thanks Mr. Allen, Mr. Bates, & Orion (alphabetical order) for helping me to narrow
······ down my chioces on how to solve my problem.