Shop OBEX P1 Docs P2 Docs Learn Events
How to create additional space for variables ? — Parallax Forums

How to create additional space for variables ?

W3ZWW3ZW Posts: 2
edited 2005-01-17 05:31 in BASIC Stamp
·
· 26 variables is just not enough ! Can additional outboard·ram or an eeprom (to be used for variables) be accessed by the BS2 ?

· If so, I would greatly appreciate an explanation of how to implement this.

· Bob - w3zw

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-01-16 20:09
    No. It's best to learn to conserve. In many programs variables can be reused, and PBASIC allows you to give the same variable more than one name to make the code easier to read.

    To be candid, in 11 years of writing BASIC Stamp programs I have only had one project where I ran out of variable space. Still, the project was a success. How? Well, it had two modes: operational and programming. During the programming mode I saved all the operational variables to EEPROM with the WRITE command, then used READ to get them back when programming (new data from a PC) was complete.

    NOTE: You should NOT use the EEPROM (with WRITE and READ) like common variables; the EEPROM has a finite number of write-cycles and if not careful, you could actually wear it out.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas, TX· USA
  • achilles03achilles03 Posts: 247
    edited 2005-01-16 21:24
    Bob,

    First, see if you can't use the same variable more than once. I have one program that uses a couple variable bytes to store values, performs some functions, then reuses those same variables to store another type of data once the first data is not needed anymore.

    Secondly, you can have more that 26 variables, but you can't have more that 26 BYTES of variables. One thing I do is check my variables and see if I can reduce the memory space needed for them. For instance, if I have "data1" defined as a byte, but it's only going to have a max value of 10, then I'll redefine that as a NIB and save some space that way. See how many variables you can do that too if you haven't already.

    Next, check your program to see if you REALLY need the variable. Is it there because it makes coding easier, or is it there because it's absolutely vital?

    Lastly, if you post your code, we can go through it to see all you might be able to do to reduce variable space.

    If you absolutely need extra variables, I'd record them on an extrernal eeprom and access them as needed with common variables (as Jon said, don't use the write command too much, as it'll wear out your BS2's eeprom).

    Dave
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-01-16 21:26
    Achilles03 makes an excellent point and I'm sorry I didn't mention it in my post: make sure that you declare variables appropriate to what they're going to do.

    Bit ... value is 0 or 1
    Nib ... could exceed 1, but not 15
    Byte ... could exceed 15, but not 255
    Word ... could exceed 255 (capped at 65535)

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas, TX· USA
  • W3ZWW3ZW Posts: 2
    edited 2005-01-17 04:28
    · I greatly appreciate the tutorials from both Jon & Dave.

    ·I am an amateur radio operator & wanted to create a command interface between two radios, having just purchased an BS2 & Programming Board I have been burning the candle late into the night·over the past few days while learning about the Stamp, PBasic & constructing the hardware circuits for this project.

    ·Before posting to this fourm, I was under the impression that all ASCII serial data bytes had to be sent out of the stamp in the form of string variables, after reading your replies I began using constants in the following form:

    ·RT1a CON 82·····'ascii·"R"

    ·RT1b CON 84···· 'ascii·"T"

    ·RT1c CON 49···· 'ascii· "1"

    ·RT1d CON 59····· 'ascii ";"

    ·The above being sent as: " SEROUT 2, 16468, [noparse][[/noparse]RT1a,RT1b,RT1c,RT1d]"

    ·The above represents a typical command for the radios, at 9600 baud this is working just fine. I am on a steep learning curve & being able to draw on the knowledge & expertise of people like you Jon & you Dave make learning something new a real pleasure.

    ·Thanks,

    · Bob - W3ZW
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-01-17 05:31
    You're making things pretty tough; you can simplify like this:

    SEROUT 2, 16468, [noparse][[/noparse]"RT1;"]

    The BASIC Stamp compiler knows how to translate a string of characters into the proper sequence of bytes.· Note that while PBASIC does not have a string type, several instructions (like SEROUT) will accept a string constant embedded in the command.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas, TX· USA
Sign In or Register to comment.