Shop OBEX P1 Docs P2 Docs Learn Events
Possible to condense this code? — Parallax Forums

Possible to condense this code?

JSGrewalJSGrewal Posts: 9
edited 2008-07-15 15:39 in BASIC Stamp
Hello all.

I have been working on this code for a humidor controller. It will control the thermoelectric cooler ( Peltier), fans, and a display. I have blatently stolen demo examples I found here from Tracy Allen ( Sensirion Demo) and Chris from Parallax ( LCD Demo and 1302 Demo). Thanks to the both of them! It works fairly well at doing what I want.

What I would like to include is recording min/ max values to the RTCs RAM location for display when a button is pressed. I honestly have no idea how to do that, but I cant even start because I seem to have used all the variable spaces.

Any ideas to condense the code to gain more variable space? Also, any suggestions to use the RTCs RAM? I looked at the code example in the demo, but I havent even tried it since the variables were full. Not to mention it confused the heck out of me...

Comments

  • MorrolanMorrolan Posts: 98
    edited 2008-07-15 09:34
    One option (which does require more investment sadly) is using something like a BS2e that also has Scratchpad RAM. Whilst this can't be aliased like a normal variable, nevertheless you can use it to temporarily store and retrieve data and if you're clever, you can do some pretty amazing things with it.

    I've had to overcome this problem with my BS2e Boe-Bot which I'm determined to push to it's limits - all 8 program slots are nearly full, all work as part of a bigger program (like 8 massive gosubs!) and by using Scratchpad RAM to store the location of the originating program and also the place in the originating program from whence the program execution left, I can almost code as if it was one big program. Any variables which I need to keep between changes of the program slot are written to Scratchpad RAM and then read back in when the program execution changes back to the original program slot.

    This does involve sharing of Scratchpad RAM space, but by carefully selecting SP RAM locations, I've managed to avoid too much conflict.

    Anyway, according to my calculations and the memory map, you have plenty of variable space left, you have a total of 25 bits!

    My best tip for trying to reduce the amount of used RAM is work out the highest value you are likely to require in each variable, and if you can step down from a byte to a nibble for example, do that.

    Morrolan

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Flying is simple. You just throw yourself at the ground and miss.

    "I think computer viruses should count as life. I think it says something about human nature that the only form of life we have created so far is purely destructive. We've created life in our own image."
    Stephen Hawking
  • HumanoidoHumanoido Posts: 5,770
    edited 2008-07-15 15:25
    One technique that works well to immediately reduce
    memory usage is variable sharing between isolated
    subroutines.

    humanoido
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2008-07-15 15:39
    Reusing variables when possible will certainly cut down on the number of variables required. Take an example where you have 5 sensors that each return a 16-bit value which needs to be displayed. You can really only deal with one at a time, so you don’t need a Word variable for each one to store, just use the same ‘temp’ variable. If for some reason you need to average the results and you have SPRAM, you can store each value into SPRAM or, worst case scenario use two variables, one work and one temp to average the current reading with the last average. It wouldn’t matter if you had 20 sensors, only two variables would be needed for a running average.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
Sign In or Register to comment.