Shop OBEX P1 Docs P2 Docs Learn Events
How to use different Memory Slots in BS2P40? — Parallax Forums

How to use different Memory Slots in BS2P40?

shashashasha Posts: 5
edited 2007-09-04 16:02 in BASIC Stamp
we·have being using BS2P40 the new Chip for a long time, but now we are facing a problem that our EPROM is fulled. But as i know we haven't used our all 8 memory slots in our chip & still we don't know how to get it worked.
Eventhough we divided our full programme coding to two different files still we face problem in switching it from Slot0 to Slot1 &· vicevarsashakehead.gif
Some cases though we could switch it from Slot0 to Slot1, then we can't make it returned to Slot0 to Slot1 ..confused.gif so thats where the main problem for us.
If anyone has any idea of solving this matter please help me on this.
Thanks.turn.gif

Comments

  • RDL2004RDL2004 Posts: 2,554
    edited 2007-08-29 22:27
    This thread should have some information that will help:

    http://forums.parallax.com/showthread.php?p=664324

    and this one also:

    http://forums.parallax.com/showthread.php?p=664914


    edit: Maybe you should post your program also.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Rick

    Post Edited (RDL2004) : 8/29/2007 10:32:49 PM GMT
  • ZootZoot Posts: 2,227
    edited 2007-08-29 23:17
    www.emesystems.com/BS2SX.htm#variables
    and
    www.emesystems.com/BS2SX.htm#Crossbank

    Both have really good info about some neat tricks with multi-slot programs. These are written up for the BS2SX but the technique is identical for any of the multi-slot Stamps.

    The most crucial thing to remember if you are using the "same" (i.e. persistent) variables from slot to slot is define them the same, and in the same order, in each program for each slot, otherwise the variables may "change value" when you switch slots.

    Beyond that, if you put

    RUN 0

    in any code, anywhere, the program will go to slot 0 AND START AT THE BEGINNING. You must take this into account if you don't want any initialization (or start) routines to run more than once in slot 0.

    Same goes for subsequent slots. You can make it somewhat easier by using slot 0 only for setup stuff, then go to the other slots (and don't come back), e.g.

    'slot 0 code...
    start:
    'initialize a bunch of stuff
    'more stuff
    RUN 1 ' go to slot 1

    'slot 1 code...
    ' do a bunch of stuff
    RUN 2 ' go to slot 2

    'slot 2 code...
    'do a bunch of stuff
    RUN 1 'go to slot 1 --- don't run slot 0 again because it's your "setup" slot

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST
  • Bill ChennaultBill Chennault Posts: 1,198
    edited 2007-08-31 15:05
    Zoot--
    RUN 1 'go to slot 1 --- don't run slot 0 again because it's your "setup" slot said...
    (replace this text with what was said)
    Something I have always been confused about is what happens when you DO perform code as you mentioned. In other words, MyCode has executed the something like this . . .

    Run 0

    Run 1

    Run 2

    Run 1

    Does program execution start at the beginning of slot 1 upon execution of the last "Run 1"?

    Thanks!

    --Bill



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    You are what you write.
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2007-08-31 15:18
    Bill -

    The simple answer is YES it does. However, you can certainly change that programatically through the use of PBASIC commands like ON...GOTO or BRANCH at the beginning of slots 1-N, having set the "offset variable" in the prior slot. Slot 0 is something of a special case.

    At least that's how I do it, but there are probably other viable methods as well.

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • Bill ChennaultBill Chennault Posts: 1,198
    edited 2007-08-31 15:24
    Bruce--

    Got'cha! Simple solution!

    Thanks.

    --Bill

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    You are what you write.
  • ZootZoot Posts: 2,227
    edited 2007-08-31 22:11
    e.g.

    THISSLOT CON 2 '0..7 -- which slot is THIS
    initState VAR Byte  'remember that whatever vars you use, put them exactly the same way, same order in every slot program
    
    
    Start:    'upon reset or run (slot 0) or run (any slot), code *always* starts at the beginning
       initState.BIT0(THISSLOT) = 1   'set bit flag that this slot has "initialized" the first time
       ON 1 - initState.BIT0(THISSLOT) GOTO Main 'bit for this slot is 1, skip init stuff
        'do initialization or setup stuff for this slot 
        'more stuff
        'more stuff
    
    Main:   'you initialized first time, now you're just running
        'program
         'program
    
    SlotDone:
        RUN THISSLOT+1   'run next slot, or whatever
    
    END
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-09-04 16:02
    Bill Chennault said...(trimmed)
    Something I have always been confused about is what happens when you DO perform code as you mentioned. In other words, MyCode has executed the something like this . . .

    Run 0

    Run 1

    Run 2

    Run 1

    Does program execution start at the beginning of slot 1 upon execution of the last "Run 1"?

    Bill, in the Above code the program would be stuck in an infinite loop re-running slot 0.· You can't have a list of run commands in a program.· As soon as a RUN command is encountered the code in the new slot is executed.· It never returns to execute the next RUN command.· Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
Sign In or Register to comment.