Shop OBEX P1 Docs P2 Docs Learn Events
variable transfer from bank0 to bank1 — Parallax Forums

variable transfer from bank0 to bank1

djgilmo32djgilmo32 Posts: 10
edited 2006-04-01 09:39 in BASIC Stamp
I am running a program in a BS2P40 and using multiple banks. I am having trouble finding out why an integer variable declared in memory bank0 changes when it arrives in bank1.

EX.···························· bank0················· bank1

keypad input 01··=·········· 8, 9···················· 1, 0
keypad input 02··=·········· 8, 0·····················2, 0
etc.

anyone that can help is welcome to view my code and see whats going on. I'm tearing my hair out trying to figure this out.

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-03-31 05:24
    If you variable declarations vary in any way there will be a problem -- the name of the variable does not matter; it's size and position in the assignment list determine the RAM location assigned. It's best to copy your variable declarations from bank 0 to bank 1.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • djgilmo32djgilmo32 Posts: 10
    edited 2006-03-31 06:13
    The variable declaration doesn't change but the integer does. attached is a copy of my code...look at the subroutine "quickmode" then bank 1. judging from the debug statements, the numbers differ. Code should be attached.
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-03-31 07:16
    Your declarations are not exactly the same.· Here's where the problem lies: the compiler lays variables into memory by size and order of declaration, starting with Words.· Both sets of declarations have four Words, so those are occupying RAM [noparse][[/noparse]byte] locations 0 - 7.· Bytes are next, and that's where the problem is; you have this declaration in one program:

    keycursor·········· VAR····· Byte
    inkey1············· VAR····· Byte ' first keypad character
    inkey2············· VAR····· Byte ' second keypad character
    found·············· VAR····· Byte

    ... and this in the other:

    inkey1············· VAR····· Byte ' first keypad character
    inkey2············· VAR····· Byte ' second keypad character
    found·············· VAR····· Byte

    So, in program #1, keycursor is in location 8, inkey1 in location 9, and inkey2 in location 10 -- but in program #2 inkey1 is in location 8 and inkey2 is in location 9; your variables have been skewed because keycursor is not defined in the second program.

    Back to the original suggestion: make your declarations in program #1 and then copy-and-paste them (without changes) to program #2.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • djgilmo32djgilmo32 Posts: 10
    edited 2006-03-31 09:56
    That makes sense, thank you. I'm gonna run it tomorrow morning but im sure it will work out.
  • djgilmo32djgilmo32 Posts: 10
    edited 2006-03-31 17:46
    I have set up my variables EXACTLY the same in both banks and now I am getting·zeros "0" when calling up the variables "inkey1" and "inkey2" in slot1. Basically I'm getting no transfer of variable·information from slot0 to slot1.
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-03-31 18:49
    The programs I've attached will prove that variables do in fact remain intact from slot-to-slot.· After you're convinced, you'll need to go through your program to find out what you're doing to cause the results you're getting.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-03-31 20:09
    djgilmo32 said...
    I have set up my variables EXACTLY the same in both banks and now I am getting·zeros "0" when calling up the variables "inkey1" and "inkey2" in slot1. Basically I'm getting no transfer of variable·information from slot0 to slot1.
    Hello,

    ·· Once again you do not have your variables delcared the same in both slots.· You are declaring a variable named, "temp" in slot 0 as a NIB.· This doesn't appear in your slot 1 program.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-03-31 20:14
    Remember, variable declarations are laid into RAM in order by size (Words first, Bits last) and then by the order they appear in the listing. It's not enough that you have the same names (with associated size) in your declarations, they MUST be in the exact same order or something will get skewed.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-03-31 20:16
    Before I forget, that last variable is not listed with the others, but further down in your program which may be why you missed it.
    initlcd:
    temp      VAR      Nib
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-03-31 20:18
    This is why I promote using a standardized template that keeps variable locations in one location. When we spread declarations through active code things like this can pop up and bite us.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • GadgetmanGadgetman Posts: 2,436
    edited 2006-03-31 21:00
    Why not forget about passing information in variables, and instead using the Scratchpad RAM?

    Then you don't have to declare exactly the same variables in all Program Slots.
    (We all know that we should be careful about defining too many variables lest we run out of space for them... )

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Don't visit my new website...
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-03-31 21:26
    Agreed; I describe how to do·that in this article: http://www.parallax.com/dl/docs/cols/nv/vol3/col/nv87.pdf

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • djgilmo32djgilmo32 Posts: 10
    edited 2006-04-01 06:19
    I would love to use the Scratchpad method but after looking over some of the example programs, it looks like all variables used throughout all banks must be declared in the first bank or the Main bank. I would like to add 8 more "word" sized variables to my program and that will exceed my 2MB. The fact that the additional 8 variables must be added is why I am trying to arrange my code into different banks. You guys seen to know PBasic up and down the board and it would be great to supply you with my existing code that works but is only in slot0 and needs the added variables, then maybe you could look over it and give me some options. It is only about 330 lines long.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-04-01 07:01
    While the ScratchPad RAM cannot contain variables, per se, you could use it to store your word variable data and then pull them into a temp word variable for operations.· This way one or two word variables could deal with most of your word-sized data.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • djgilmo32djgilmo32 Posts: 10
    edited 2006-04-01 07:23
    Here is what my code looks like and if it could all fit in slot0 it would work.
  • GadgetmanGadgetman Posts: 2,436
    edited 2006-04-01 09:39
    A couple of points...

       LCDOUT 0, 1, [noparse][[/noparse]"Enjoy Your Drink"]
       PAUSE 1500
       RETURN
    
    



    This bit is repeated several times...
    SUB IT!

     'setup valve times
       IF inkey1=0 THEN valve1msecs=msecsperounce*inkey2
       IF inkey1=1 THEN valve2msecs=msecsperounce*inkey2
       IF inkey1=2 THEN valve3msecs=msecsperounce*inkey2
       ...
       ...
    
    


    Sections like this just screams for optimisation...
    (Someone else is bound to tell you exactly how, though)

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Don't visit my new website...
Sign In or Register to comment.