Shop OBEX P1 Docs P2 Docs Learn Events
Out of variable space + PID problems — Parallax Forums

Out of variable space + PID problems

PorcelinaPorcelina Posts: 5
edited 2007-05-23 20:52 in BASIC Stamp
Hi all,

I am writing some code to control a mash tun as part of·a beer making process.

Output:
control of 220V heating element·with solid state relay

Input:
*Temperature readings (LM35)
*At start 5 temperature setpoints with the corresponding time to hold each temperature setpoint.
Example:
40°C for 15min
52°C for 30min
63°C for 30min
72°C for 30min
78°C for 1min

I am trying to use PID to control the temperature.
But soon after compiling my testcode, I received the message "Out of variable space".
I am using variables to read the temperature through the ADC, for loops (temperature and time) and·for the PID code.
I have 11 Word variables, 4 Byte variables and 1 bit variable.
The user-input for the temperatures and minutes are stored in the eeprom.

The code isn't very long so expanding it with extra features isn't an option I think because of the lack of space to store my variables. I already began to double use some variables but still it isn't enough.

What could I do to solve my problem?

Best regards



Post Edited (Porcelina) : 5/22/2007 8:57:33 PM GMT

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-05-22 19:04
    Hello,

    Please post your code so we can help determine what may be happening.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • allanlane5allanlane5 Posts: 3,815
    edited 2007-05-22 19:07
    And by "post your code", he means click "post reply", and use the "Attachments" button to upload a copy for us.

    It's usually quite possible to re-use 'temp' variables to reduce the memory space needed. But we'd have to see your code to be sure.
  • Mike GreenMike Green Posts: 23,101
    edited 2007-05-22 19:07
    The only thing you can do is to share variables if you're using a BS2. The later models (BS2e,BS2sx,BS2p/pe/px) have various amounts of RAM memory (63-126 bytes) that's accessible with the GET and PUT statements that you can sometimes use to hold part of your information. All of the Stamps have only 26 bytes of variable space and there's no way to expand that. Most of the time, sharing variables helps a lot.
  • PorcelinaPorcelina Posts: 5
    edited 2007-05-22 20:36
    Hi,

    Thank you for responding!

    Attached you can find my code.
    There are still some problems with the PID part, I have difficulties with that.
    I also realise that the code is far from finished.

    Best Regards

    See further for updated code

    Post Edited (Porcelina) : 5/23/2007 7:55:21 PM GMT
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-05-22 20:45
    Porcelina said...(trimmed)
    I have 11 Word variables, 4 Byte variables and 1 bit variable.
    The user-input for the temperatures and minutes are stored in the eeprom.
    Somehow I missed the 11 Word variables when I first read the post...You have 26 bytes available total.· 11 Words is 22 bytes, leaving 4 bytes.· You're 1 bit over the limit.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • Mike GreenMike Green Posts: 23,101
    edited 2007-05-22 20:48
    It looks like "y" could fit in a nibble (NIB). I can't tell whether "x" can fit in a nibble as well. Some uses of "a" can fit in a nibble.

    It looks like you could do a little more analysis of the range of the various variables.

    I'd suggest you use the "alias" VAR declaration for the sharing rather than just reusing the name. It makes the program clearer.
  • allanlane5allanlane5 Posts: 3,815
    edited 2007-05-23 14:30
    Very nice code. Well structured.

    It does look like a few ('y', 'a') variables could be nibbles (since they only go from zero to 15 or less). That might save enough space.

    One other possible problem -- your 'Main' loop doesn't have 'goto main' at the bottom (or a 'main:' label, for that matter). This means your code will 'run-off' the bottom of the 'main' loop into your subroutines.
  • PorcelinaPorcelina Posts: 5
    edited 2007-05-23 19:52
    Hi,

    Thank you all for responding!

    Attached you can find my·new code.
    I updated it with the suggestions you all gave me and I solved some small extra bugs.
    At this moment I have a temperature overshoot of about 2°C for each temperature setpoint.
    I think I have to finetune the·Kp, Ki and Kd·constants.

    The following steps are to link the code with a visual basic application.
    The VB program will only retrieve·temperature data and·should send the setpoints to the BS2 at the beginning.
    As soon as I have more code I will post it.

    Feel free to give suggestions·...

    Best Regards

    Post Edited (Porcelina) : 5/23/2007 8:00:00 PM GMT
  • allanlane5allanlane5 Posts: 3,815
    edited 2007-05-23 20:52
    Very nice.
Sign In or Register to comment.