Shop OBEX P1 Docs P2 Docs Learn Events
Problem with "RUN"... — Parallax Forums

Problem with "RUN"...

04A23604A236 Posts: 18
edited 2004-12-16 23:18 in BASIC Stamp
Hi all,

I'm trying detect some pins from different program slots...
each detection should be independent from one another...

but from the manual, it says that:
The I/O pins retain their current state (directions and output latches) and all Variable and Scratch Pad RAM locations retain their current data during a transition between programs with the RUN command.

How do I reset conditions of pins when in a new program slot?
I've tried manually setting the value of pins to as expected...
but my debug shows otherwise...
cry.gif

Please HELP!!

Thanks in advance,
Rita

·

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-11-16 12:48
    That statement is true if your program doesn't do anything. If you want the IO pins to change, you simply need to write different levels to them. If you want to reset the pins to a "hard reset" condition (all inputs), you can do it like this:

    DIRS = $00
    OUTS = $00

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • 04A23604A236 Posts: 18
    edited 2004-11-16 13:12
    Thank you so much...

    You have been a great help...

    the DIRS= $00 solved the problem...

    Post Edited (04A236) : 11/16/2004 1:50:36 PM GMT
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2004-11-16 15:58
    04A238 -

    The order, type and size of all your variables MUST be IDENTICAL in all of the program slots, regardless of whether they are used in that slot or not. If they aren't, all sorts of strange errors which look like uninitialized or incorrect values may appear. The PBASIC Stamp Manual explains this in detail.

    Regards,

    Bruce Bates
  • 04A23604A236 Posts: 18
    edited 2004-11-16 16:31
    Hi, Bruce....

    does it matter if my variables in each slot are independent?
    because each slot has their own variable...

    please advice...
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2004-11-16 16:51
    04A236 -

    I'm not sure I uderstand what you mean by "independent". All varioable in all slots share the same memory. The reference to each variable within each slot is positionally DEPENDENT.

    You might add variables in progam slot two which don't exist in program slot one, but they MUST be added at the end of all the allocations of the variables which exist in program slot one. So too with program slots three and higher, using the same technique.

    The manual, which is free for the download, is much better at explaining this by the use of examples. The space here on the forum is limited. Please read the manual for further details on: program slots, declaring variables in program slots, and how they are used.

    Regards,

    Bruce Bates
  • NewzedNewzed Posts: 2,503
    edited 2004-11-16 16:59
    To amplify Bruce's statement ALL pin assignments, constants and variables

    must be the SAME in each slot and in EXACTLY the same order.· Constants and variables are read according to their position in the list.· If you add one variable at the end of the list on Bank0 and another variable at the end of the list in Bank 3, Stamp will read the variable called by the slot that uses it but it may read the value of the variable in the other slot.

    To be certain, organize all you pin assignments, constants and variables in Bank 0, then copy and paste the whole thing to all the other slots.· This way you are safe.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Sid Weaver
    New Combo LCD Backpack

    http://hometown.aol.com/newzed/index.html
    ·
  • 04A23604A236 Posts: 18
    edited 2004-11-16 17:33
    Hi,

    I think you're referring to this sentence (on page 270 of the manual v2.0c)??
    If [b]sharing[/b] data between programs within Variable RAM, make sure to keep similar variable declarations (defined in the same order) in all programs so that the variables align themselves on the proper word, byte, nibble and bit boundaries across programs.
    

    my independent means that variable in one slot (may be slot 0) has no relation to another slot (may be slot 1)...
    the problem i had was this...· when running slot 1,·values from slot 0 of the same variable is forwarded to slot 1 through pin detection (latched as mentioned below on the same page)... which is not as what i wanted...
    The I/O pins retain their current state (directions and output latches) and all Variable and Scratch Pad RAM locations retain their current data during a transition between programs with the RUN command.
    

    solution provided by Jon Williams does the trick of resetting all ports...

    When using a particular data from another slot...··I used the·"STORE" command (page 323)...
    STORE tells the BS2p which program slot to use when a READ or WRITE instruction is executed. The STORE command only affects the READ and WRITE instructions.
    


    I'm still learning and trying to grasp a hold of the coding...

    Please advise if i have misunderstood the text...

    The reason why i'm so concerned is that...· i'm running out of memory space for variable allocation...· that's why i can't afford to have exactly the same variables throughout all program slots...· cry.gif

    Thank you so much for your feedback...

    Regards,
    Rita
  • PaulPaul Posts: 263
    edited 2004-12-16 20:18
    Bruce Bates said...
    04A238 -

    The order, type and size of all your variables MUST be IDENTICAL in all of the program slots, regardless of whether they are used in that slot or not. If they aren't, all sorts of strange errors which look like uninitialized or incorrect values may appear. The PBASIC Stamp Manual explains this in detail.

    Regards,

    Bruce Bates

    OR....use a RAM table to store varibles then use GET/PUT. Be careful GETing and PUTing WORD vars.

    'SLOT 0                        
    a var byte            
    b var byte                        
    c var word                        
    a=2:b=4:c=5000               
    put 1,a     'ram table
    put 2,b
    'c uses ram bytes 3 and 4
    put 3,word c 
    run 1
    
    'SLOT 1:  
    a var byte
    get 1,a 
    debug DEC a        
    run 2                                              
    
    'SLOT 2: 
    b var byte       
    get 2,b            
    debug DEC b   
    run 3               
           
    'SLOT 3:
    c var byte
    get 3, word c
    debug DEC c
    c=c+1
    put 3,word c
    run 1 ' loop forever 
    
    
  • K de JongK de Jong Posts: 154
    edited 2004-12-16 22:20
    Hi Rita,

    I have a datalogger running in a testing environment and it uses multiple program slots, switching every second. It does NOT have the same variables declared in each slot but it does run quite well.

    The trick I use is that I copy crucial variables to the scratchpad RAM (PUT) before switching to an other slot and I reload them (GET) at first when I reenter the program slot.

    It seems to work in my situation.......

    Klaus

    PS this thing is still under development so the code has not matured yet wink.gif
  • 04A23604A236 Posts: 18
    edited 2004-12-16 23:18
    Yup! I did that too...· And it worked fine with me too...

    The solution Jon supplied has solved my problem...

    smile.gif·Thanks!!

    Regards

    Rita
Sign In or Register to comment.