Shop OBEX P1 Docs P2 Docs Learn Events
how to get more variable space? — Parallax Forums

how to get more variable space?

verobelverobel Posts: 81
edited 2006-05-01 20:41 in BASIC Stamp
Hi fellow stampers:
I was recently programming my BS2pe and I got the error 126.. out of variable space. From what I read you only get 32 bytes of variable space. There is also program space which which must be a few K at least. Is there some way to reduce program space to get more variable space?
thanks, John

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-03-06 16:47
    Make sure that you're defining variables in the size you actually need: don't used Nibs when Bits will do, or Bytes when Nibs will do, or Words when Bytes will do. Also, look for opportunities to consolidate temporary variables. As always, posting your code is the best way to get very specific direction.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • Robert25Robert25 Posts: 53
    edited 2006-03-06 17:04
    Verobel,

    You should peruse the post I started asking a similar question with the BS2. I got several very good suggestions for trimming program space and variable definition length. It is located in this forum.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-03-06 19:33
    Here is a link to that thread.

    http://forums.parallax.com/showthread.php?p=574717

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • verobelverobel Posts: 81
    edited 2006-03-07 04:02
    thanks all.. about 2 minutes after I did the post I saw your thread.. and did read through.. was disappointed that there apparently is no way to expand the variable portion of memory. Is it a different type of memory as compared to the program memory.. if it was all in one block it would seem simple to have a variable endpoint.. perhaps the answer is to reprogram for the javelin chip.. maybey you can have more variable there..what do you think?
    John
  • OrionOrion Posts: 236
    edited 2006-03-07 22:57
    Are you using the scratch pad on the bs2pe? You can swap variables in and out of scratch pad to get more room.
  • verobelverobel Posts: 81
    edited 2006-03-08 21:06
    I was reading in the Basic Ref. Manual ...another approach is to use DATA in conjunction with READ and WRITE (to EPROM). So you could set a block of say 10 bytes aside at the start of the program .. with individual pointers like: temperature, speed, pressure.. (10 different variables) and then use them as required in the program. [noparse][[/noparse]could even program arrays like this]

    READ temperature VAR1 ' read the 'external variable' in to a temp variable (that is reused often)
    RESULT = VAR1 * CALIBRATION + OFFSET
    WRITE VAR1 temperature ' store the result.. for use later or elsewhere
  • Paul BakerPaul Baker Posts: 6,351
    edited 2006-03-08 21:09
    You need to be careful about extensively using the EEPROM. They have a limited writeability per location (10k-100k), this may sound like alot, but this is over the lifetime of your stamp. Some users have burnt out locations in thier stamps from excessive rewriting in weeks or even days.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·1+1=10
  • RealLaxRealLax Posts: 14
    edited 2006-05-01 19:38
    Paul Baker said...
    You need to be careful about extensively using the EEPROM. They have a limited writeability per location (10k-100k), this may sound like alot, but this is over the lifetime of your stamp. Some users have burnt out locations in thier stamps from excessive rewriting in weeks or even days.

    How much of a problem is burning out locations in EEPROM?
    What actions can cause that?
    What things should you do to prevent that?

    Post Edited (RealLax) : 5/1/2006 7:41:44 PM GMT
  • Mike GreenMike Green Posts: 23,101
    edited 2006-05-01 20:39
    Burning out locations in EEPROM is a problem. They are no longer usable. If you burn out locations close to the beginning of memory (near zero), you can change your programs to avoid using those locations. When you load a program into the memory, you are using EEPROM space, but programs start at the end of memory. If they don't fill memory, then the beginning is not used (that's why you can use that area for the READ/WRITE commands).

    How do you burn out locations? By programming the Stamp too many times (hard to do) or by using the WRITE instruction in a part of a program that's executed too often (easy mistake to make). Let's say you have a program that reads a digital thermometer, compares the temperature to a value stored in EEPROM, and tries to keep a maximum and minimum and writes all three values to a serial LCD. There's a PAUSE so that this process occurs once a second. Sounds like a practical application! If you update (WRITE) the maximum and minimum values every second, even if they haven't changed, you will burn out the EEPROM locations in 100,000 seconds or so, only 60 days. You need a piece of the program that compares the current minimum and maximum to the EEPROM value and only writes a new value if it has changed like ... (called with GOSUB UPDATE)

    UPDATE:
    READ 0, VALUE
    IF MINV = VALUE THEN SKIP1
    WRITE 0,MINV
    SKIP1:
    READ 2,VALUE
    IF MAXV = VALUE THEN SKIP2
    WRITE 2,MAXV
    SKIP2:
    RETURN
  • Paul BakerPaul Baker Posts: 6,351
    edited 2006-05-01 20:41
    RealLax said...
    How much of a problem is burning out locations in EEPROM?
    What actions can cause that?
    What things should you do to prevent that?
    It all depends on how often you rewrite the location. An EEPROM location is much like a lightbulb, there is a certain number of times you can turn it on and off before it burns out and can no longer be used. The precise reason this occurs is unimportant.

    There are a few ways you can help mitigate the issue, the easiest is writing programs which reduce the frequency of writing to the eeprom, if you can update a variable in RAM more than once before writing out to EEPROM this will extend the life of the EEPROM. The second·is using an external EEPROM, which you can replace when it goes bad. The third is using more than one location to store a variable, this is the most complex method. Instead of writing to the same location over and over, you use multiple locations. There are many different ways to do this. The easiest approach is if you dont need to remember the last value before a·power cycle (ie·true RAM).

    Say you need·4 bytes for·variables and only have room in·RAM for 3. Split two of the·bytes availible into four nibbles, each nibble is an index value into the EEPROM and each nibble can address 16 locations. When you need one of the 4 variables, fetch the value at the base address for that variable in EEPROM + the nibble index value into the 3rd byte availible. Modify the variable as needed, increment the index value, and write the modified value to the base address + incremented index. This method will use 16 values in EEPROM for 1 value, and reduces the number of times a specific location is written to by 1/16th. To reduce the likelyhood of wearing out the first few locations first, start out by randomizing the index nibble so the order isn't 0,1,2,3... everytime you start up the stamp.

    If you need to pickup where you left off between bootups (non-volatile storage), the methods can become more complex and which method is best depends on actual methods of use and how often a reboot occurs.

    You can combine these methods in any combination to get a multiplication effect on the life of the EERPOM. If you go with an external EEPROM, consider getting an FRAM from RAMTRON. They behave just like an EEPROM, but effectively dont wear out because its a different technology used. They are more expensive that equivalent sized EEPROMs but it may be worth the value for your peace of mind.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    1+1=10
Sign In or Register to comment.