Shop OBEX P1 Docs P2 Docs Learn Events
Out of variable space? — Parallax Forums

Out of variable space?

techstudenttechstudent Posts: 21
edited 2009-01-12 02:13 in BASIC Stamp
I am working on a program that has 25 CONstants and 23 VARiables... The program has many elements including LCD, RTC, temp/humidity, and more.. I am getting the error msg "Out of Variable Space" I still have a way to go and may need up to 18 or so more variables before I am done.. My question is would adding more EEPROM help? or maybe linking two Basic stamps and dividing tasks between them? Thanks for any ideas....

techstudent

Comments

  • allanlane5allanlane5 Posts: 3,815
    edited 2009-01-10 15:44
    Two stamps might help. The "variables" in the BS2 environment are basically 'registers' in the PIC -- and it only has so many registers, so 26 bytes of memory is all you get.

    Now, that memory can be VERY flexibly used, as bits, nibs, bytes, or words. Also, that memory can be 'reused' -- assign a couple of words as "temp" variables, and re-use them in subroutines.

    Note that a "CON' declaration takes up no space in the BS2 -- basically that is a 'compiler directive', and when you use a CON variable in your BS2 code it's replaced with the constant value. So you can have LOTS of CON declarations.

    One more thing you can do, is use READ/WRITE/DATA statements to store data in the 2K eeprom space. If you do that, you must be careful not to WRITE to the eeprom very often, because the eeprom only supports 1 million writes or so. This is a large number, but you can 'wear it out' with writing once a millisecond in about a week.

    You COULD add an external SPI interfaced eeprom, and use SHIFTOUT/SHIFTIN to write and read it. That can be very slow, however.

    Bottom line -- the "VAR" space is NOT expandable at all, nor is the "Code" eeprom space. Some BS2 'flavors' support multiple 2K byte EEPROM program "slots", if that seems helpful.
  • JonathanJonathan Posts: 1,023
    edited 2009-01-10 15:49
    Allan,

    The first thing I would look at is reusing variables. Show us your code and we may be able to help.

    You can add EEPROM. However, it is slow and has write limitations, so you can't use it as RAM per se. You can store data in it and retrieve it later, of course. With a write limit between 100k and 1M, if you are using it at any rate you will burn it's data storage. For example, one sample per second would be 86.4K uses per day.

    Jonathan

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
  • techstudenttechstudent Posts: 21
    edited 2009-01-10 17:23
    Thats mostly what i was wondering is if it was possible to expand the VAR space, I will go through the code and see what I can do with reusing variables, I could probably gain a few that way, but I have many variables like secs, day, minutes, hours, Fahrenheit, Humidity, ElapsedTime, and a few counters most of which are in the "Byte" size category that are difficult to reuse as I want them to be continually scrolling past on the LCD screen. I will also be controlling a few other things that are dependent on the temperature readings. Nothing I am doing is that complex, but it is just a lot of different stuff... READ/WRITE DATA may be an option as most of the operations I am doing do not require speed and could happen in a matter of minutes rather than milliseconds... I will see what I can do with reusing variables if I get stuck I will post my code...

    thanks for the info

    techstudent
  • SRLMSRLM Posts: 5,045
    edited 2009-01-10 17:40
    The BS2e+ has scratch pad ram, very handy in this sort of situation.
  • JonathanJonathan Posts: 1,023
    edited 2009-01-11 00:56
    Another thing you can do, if you aren't writing too much data: Get a large EEPROM (say 64k). You can make a little code to write the data to different addresses on the EEPROM, rotating through so you wear it evenly. Let's say you are storing 100 bytes of data. This gives you 640 secotrs to store your data in. Multiply that by the write limit and you have your total writes. Divide that by samples rate to get lifetime. More code over head, but if it's not too many variables and speed isn't an issue, this method can work for a long time. It will wear out eventually though.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2009-01-11 18:23
    Certainly consider moving up to a BS2p or BS2pe. Then you will have another 127 bytes of RAM that your program can use for uninhibited storage using PUT and GET commands. You mention that you have an RTC attached. Many RTCs have very useful RAM available, and what is more, that RAM can be backed up with a battery or capacitor for storing pointers and accumulations that you don't want to lose if the Stamp is reset or powered off for a while. The LCD module too may have RAM available. As your program grows, the BS2p or BS2pe will also get you past any impending "out of program space" error.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • techstudenttechstudent Posts: 21
    edited 2009-01-12 01:59
    Thanks for all the advice, I recently got a BS2P, so I am working with the scratch pad, as well as reusing some variables, which should be enough to do the trick.. thanks again to everyone for the brainstorming...

    ~techstudent
  • SRLMSRLM Posts: 5,045
    edited 2009-01-12 02:13
    Don't forget variable aliasing. Very powerful, or very dangerous depending on how you use it, but there you have it.
Sign In or Register to comment.