Shop OBEX P1 Docs P2 Docs Learn Events
Used up variables, program lines eeprom question — Parallax Forums

Used up variables, program lines eeprom question

Sutton MurraySutton Murray Posts: 88
edited 2006-10-23 22:21 in BASIC Stamp
I came to a stage of my program where the·uploaded was holted stating the i am out of variables. I imediately thought it was·due to·the small space capasity·of the·BS2 i am using. I changed the BS2 with a BS2P. i·still·had no luck. I the manual i saw that all stamp modules are limited to only 26 variables. The BS2 are limited to 500 programing lines and all other stamp modules to 4000 programing lines with also bigger eeprom space. Are their any way of increasing the amount of variables? I·counted 21 Variables in my program and not 26 as stated in the manual. What commands counts as a variables? My program is currently on 421 lines. I can probably make some changes to use limited variables, if my program was almost completed, but i don't think i have even reached the half way mark.
I·still need a lot more·variables and i am going to use a lot·more programming lines. Further more my project needs to be as cheap as possible and also needs as lot as possible eeprom space as well for recording purposes. To keep cost down i still want to change my pc board to use the OEM IC, adding a as big as possible eemprom on the board. Can i add any bigger eemprom to any OEM ic? Note that all pins(I/O) lines are used on my stamp, so i cannot add a second eeprom on the board.

Please help me?sad.gif

Comments

  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-10-22 10:27
    Sutton -

    I know of no limit on the NUMBER of variables in PBASIC, although I'd imagine it's in the hundreds or thousands. There IS a limit on the AMOUNT of variable space, and that IS 26 BYTES. If you have any variables defined as WORD length, that counts as TWO bytes. I suspect that to be the case.

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    <!--StartFragment -->
  • Sutton MurraySutton Murray Posts: 88
    edited 2006-10-22 10:40
    Thanks Bruce

    The book states 26 variables only. I have not thought of it as 26 bytes. I will be trying this and let you know if it works.
  • GadgetmanGadgetman Posts: 2,436
    edited 2006-10-22 11:46
    Don't forget that the BS2p has a Scratchpad RAM, which is NOT counted amongst variable space.
    It shouldn't be too difficult to 'switch out' variables to that area, when they are not needed, then switch them back in again later.

    also, while the BS2p has a larger EEPROM, it is divided into chunks of 2K, so any one program can't be larger than that on a BS2. To overcome this you'll need to very carefully section off the program, and use some sort of flag to transfer 'state' information from one program to another.
    A good start is to read Nuts&Volts #87: multibank programming

    If you can't spare the extra I/O-lines for an I2C-type EEPROM, you may want to look at a BS2pe instead, as it has 16 x 2K slots. (The first 8 can be both program and data, the last 8 are for data only)
    It's slower than the BS2p, though, but if your program ran OK with the BS2, that shouldn't be a problem.
    If that isn't enogh, you could try the BS2P40 version instead, as it has 32 I/O-pins and should be able to handle a large number of EEPROMs...

    May we ask what you're using up all your I/O on?
    (Someone may have a suggestion that can free up some... )

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Don't visit my new website...
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-10-22 11:51
    Sutton -

    The BS-2 models have 26 BYTES of RAM, but that does not imply that you can only have 26 variable names. Call this nit-picking if you like, but MANY BS-2 programs would be pretty much out of luck if the NUMBER of variables was limited so severely. Here is an example:

    DataArea1 VAR BYTE
    DataArea2 VAR DataArea1

    That set of definitions above describes ONE BYTE of RAM storage, and TWO VARIABLES. Thus, an alias counts as a variable name, but does not add to the amount of storage allocated. The 26 byte limitation refers to the total allocation of single byte RAM memory.

    If your source of information is the Stamp Comparison Table, look to the EXTREME LEFT of where it says "6 I/O, 26 variables" and it says "RAM Size", NOT number of variables.

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    <!--StartFragment -->
  • Sutton MurraySutton Murray Posts: 88
    edited 2006-10-22 18:25
    Thank Bruce

    I will be digging in to this for my program.

    Gadgetman

    As i have mentioned the projecrt must be as cheap as possible. I have mentioned going to the BASIC Stamp 2 OEM Interpreter Chip. Just to get cost down more. The BS2P40 is a high cost item. What is the limitation for the OEM interpreter to work with a big eeprom. My project drives a ADC0838, a Rotary switch on one line a DS1302, a Memsic 2125, 2x relays, a Serial LCD,a RF transmitter, a led used for a certain communication level, the last line for speed pick up pulsin command.
  • GadgetmanGadgetman Posts: 2,436
    edited 2006-10-22 22:08
    The Interpreter will not use any larger EEPROM than it was designed for.
    (you can usually stick a larger one in ther, but it will not know that it is larger, and the extra room cannot be used.)
    Adding extra EEPROMS that you access with your PBASIC program, though, is possible, and a 32KB or 64KB I2C EEPROM isn't very expensive. (The BS2p has built-in commands for I2C)

    As for freeing up pins, you could check out some sort of 8bit buffer chips, like the 74HC245(or the 4bit 242/243)
    Put two of them next to your BS2, and use a couple of pins to control them(one Enable pin for each, and a shared Direction pin) then hook them up to the same 8 I/O-pins.
    To read a unit on the first 245, set the direction to 'in', and use the enable for that chip.
    to write to it, set the direction pin to 'out'.

    As these aren't LATCHING buffers, though, you may also want to check out the 74HC373.
    (Stick all your Relays and stuff on that, and use a 245 for inputs)

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Don't visit my new website...
  • Tom WalkerTom Walker Posts: 509
    edited 2006-10-23 14:21
    ...and let's not forget that efficient coding can often reduce the number of variables necessary to accomplish the task. For example, if you have two things that are happening at different times, then you can re-use the variable space (with aliasing or whatever). Look for tasks that have values that you won't care about "later" and use dummy variables there.

    There are other techniques that optimize variable space usage discussed elsewhere in these fora.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Truly Understand the Fundamentals and the Path will be so much easier...
  • Sutton MurraySutton Murray Posts: 88
    edited 2006-10-23 19:09
    Thanks again guys, i clearly need to look at like you said it Tom efficient coding. I am probably used to normal programing languages where one don't think of saving variable space. I will re-do the the program with all the new tricks.

    Gadgetman, So my idea of adding a bigger eeprom to the interpreter will not work so as from your explanation i will only win by adding the 12c, freeing up more I/O pins. I was hoping to avoid this but, seems like i have no option.

    Again thanks for the input.
  • Steph LindsaySteph Lindsay Posts: 767
    edited 2006-10-23 22:21
    Hello Sutton,

    For some ideas on memory optimization, you might want to check out "Applied Robotics with the SumoBot."· Andy has included lots of examples of developing programs with temporary variables, and really optimizes space usage by using just one byte as an 8-bit sensor flag register.· He really gets a lot of mileage out of the BS2 with these programs.

    You can download the book and example BS2 source code for free from the bottom of this page:

    http://www.parallax.com/detail.asp?product_id=27403

    -Stephanie Lindsay
    Editor, Parallax Inc.
Sign In or Register to comment.