Shop OBEX P1 Docs P2 Docs Learn Events
More RAM? — Parallax Forums

More RAM?

larryp1larryp1 Posts: 8
edited 2011-10-04 12:56 in BASIC Stamp
I am creating a sensor package for a weather balloon and while attempting to add a Thumbdrive to log the data to I am getting the error that I am out of space for variables, If I buy an EPROM,can I make the problem go away? How do I instruct the chip there is more memory?

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2011-09-28 14:27
    You can't "make the problem go away". It will take some work on your part.

    There are only 26 bytes of variable space on the Stamps. There's no way to increase this. The way this is usually handled is to identify which variables are used in which portions of the program. Commonly many variables are used in only a limited portion of a program and can be reused for some other purpose in other portions of the program. You can assign several different names to the same portion of variable storage. You can assign those names to different portions of the same variable storage, like two bytes can be allocated to the same storage as a single word or two 4-bit nibbles can use different halves of the same byte. Look at the section of the Stamp Manual that discusses aliases.

    The thumbdrive software tends to use a lot of variable space, particularly for receiving status messages. Often that variable area can be used for other temporary functions in-between read/write operations.
  • larryp1larryp1 Posts: 8
    edited 2011-09-29 13:15
    I was hoping that wasn't going to be the answer. I'll have to start analyzing what variables are active where. I program more in C than basic and the thing you seem to be referring to is called a pointer in C. How do you implement a pointer in PBASIC?
  • Mike GreenMike Green Posts: 23,101
    edited 2011-09-29 16:02
    There are no pointers in PBasic, at least not for variables. There are arrays and subscripts.

    These are called aliases in PBasic. They're a little like constant pointers where the only thing you can do is define another name for a specific address (variable). Strictly speaking, you could treat all of variable space as a byte array or word array (or even bit array) and the subscript you'd use would effectively act as an address (pointer).
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2011-09-29 16:08
    Larry,

    Numerous times in the past I have worked with individuals to help optimize code and variable use to make things more efficient. Many time a program that was too big or used too many variables would later fit just nicely on the BASIC Stamp. As Mike said, you must often reuse your variables and one thing you can do with the Datalogger is use the non-verbose (reduced?) mode to reduce the receive buffer size required. Not long ago I wrote a GPS Datalogger using the same device and was able to create a KML file on the drive which could be directly used with Google Earth. Things can get tight, but quite often are achievable. A quick look at your code might offer some insight.
  • MoskogMoskog Posts: 554
    edited 2011-09-30 00:20
    Would another kind of Stamp solve the problem? Like the BS2-pe with bigger EEPROM and 128 bytes of SP-RAM that is accessable from all eight cogs? Parallax sells them these days for same price as a standard BS2.
  • Mike GreenMike Green Posts: 23,101
    edited 2011-09-30 07:26
    Moskog,
    I don't think another Stamp model would "solve" the problem. There's the same amount of variable space. The ScratchPad RAM area is not usable as variable storage although it could be used for receiving some of the responses from the Memory Stick Datalogger ... not a bad thing. It would still take some work to modify the program to make use of it and I think larryp1 was hoping for a fix that would not require a significant amount of work other than a simple hardware change.
  • larryp1larryp1 Posts: 8
    edited 2011-10-03 19:48
    I spent some time with the documentation and have been trying to alias. If I were going from a word to a smaller portion of memory such as a byte it seems to work. However I need an array and I get an error when I have a subscript either as the declared variable or on the memory location to reference. Such as:

    buffer(1) VAR wadospace1

    or

    axis VAR wadospace(1)

    The error is "expecting end of line or ;" and its pointing at the open parenthesis.

    I'm not getting an error if its a single variable loading into another single variable. Just when I'm trying to do arrays.
  • Mike GreenMike Green Posts: 23,101
    edited 2011-10-03 20:03
    Really any variable can be treated as an array. The VAR declaration of something like byte(5) or word(3) is just intended to reserve space for the array. When making aliases, you just create a new name for the first element of the array. If you have a byte called "foo", you can create a bit array called "bits" for bits 2 through 5 by having:

    bits VAR foo.bit2

    You'd reference the bits with subscripts starting at 0 with bits(i)
  • john_sjohn_s Posts: 369
    edited 2011-10-03 20:30
    larryp1 wrote: »
    I am creating a sensor package for a weather balloon and while attempting to add a Thumbdrive to log the data to I am getting the error that I am out of space for variables, If I buy an EPROM,can I make the problem go away? How do I instruct the chip there is more memory?

    I figure you use BS2 that has just 2k EE memory. Did you look at BS2e or BS2sx - they both have 8 times more memory than plain BS2...
  • Mike GreenMike Green Posts: 23,101
    edited 2011-10-04 10:31
    The other Stamp models do have more program memory (EEPROM), but it's not just added on the the existing memory. You have to break your program into 2K pieces ("slots") and you can't call and return between slots. For some applications it's quite manageable, but it's not straightforward.
  • MoskogMoskog Posts: 554
    edited 2011-10-04 11:15
    Mike Green wrote: »
    Moskog,
    ..The ScratchPad RAM area is not usable as variable storage although it could be used for receiving some of the responses from the Memory Stick Datalogger ....

    Why won't you recommend using SP-RAM for variable storage? In a project I save values using PUT-statements, then the loop goes through many different slots and back again and I still can GET the variables back again without any problems.
  • Mike GreenMike Green Posts: 23,101
    edited 2011-10-04 11:25
    Moskog,
    I wanted to make clear that the ScratchPad RAM is separate from the memory used for variable storage. You can certainly use it and it's handy for receiving strings using SERIN and some other input statements, but you have to use special statements (PUT and GET) to access the storage. You can't directly use the values stored there in other statements, etc. ScratchPad RAM can make some things possible that might not be so otherwise, but its use tends to make programs larger because of the extra statements needed and it sometimes makes programs more difficult to write and understand because of the need to constantly copy values back and forth between ordinary variables and the ScratchPad RAM.
  • MoskogMoskog Posts: 554
    edited 2011-10-04 12:56
    OK, Mike , thats a good explanation. Sure the programs will be larger and more difficult to write and understand, but it doesn't have to be too bad. In my project I was dealing with so many different variables, many of them words, that I quickly ran out of space. I tried using aliases but found that to be so difficult to handle, and so easy to become a source of hard-tracking errors that I instead changed to a -pe. So for me, handling variables over to SP-RAM and back was a good solution, very comfortable even though the program expanded a little.
Sign In or Register to comment.