Shop OBEX P1 Docs P2 Docs Learn Events
Too many varibles - Not enough varible space — Parallax Forums

Too many varibles - Not enough varible space

HIBITDACHIBITDAC Posts: 40
edited 2005-06-29 09:26 in BASIC Stamp
I need help with expanding the amount of variables and size of variables. If I add a 16K EEprom chip will that enable me to have more varibles?

Thanks

Comments

  • GadgetmanGadgetman Posts: 2,436
    edited 2005-04-27 08:40
    Sorry, but adding an EEPROM will not help.

    The usual tools in this case is to:

    1. Reuse variables. Not all variables are used at the same time, and often the content can be discarded afterwards.

    2. Compress variables. Try looking for ways to use smaller size variables.
    1. If it has little variation (like body temperature), shrink the size of the variable, then add an offset to it in your calculations.
    2. If it has larger, but known variations, like the different PULSOUT values when running servos, consider using a small variable and the LOOKUP/LOOKDOWN commands.

    3. If your BS2 model has a scratchpad RAM, use that to 'PUSH'/'POP' variables you need to keep unchanged.

    4. Identify varibales that are constants and replace them with constant declarations.
  • Paul BakerPaul Baker Posts: 6,351
    edited 2005-04-27 13:57
    If you find that Gadgetman's suggestions still don't yeild enough space for your variables, there is a work around. The company Ramtron has serial FRAM parts availible in parallel, I2C and SPI. If you have a stamp which has the I2C commands the get that part, otherwise get the SPI version. FRAM is a new technology that combines the speed of SRAM with the non-volatility of EEPROMs and can be written to in the billions to trillions of times before a memory location will fail. You would create a placeholder register in the stamp that would serve as an onboard copy of a location in the FRAM, do you operations on the placeholder, then write it back to the FRAM when your done.
  • HIBITDACHIBITDAC Posts: 40
    edited 2005-04-28 05:11
    Thanks for your help. Alot of my variables are going to be programmed through a menu and once there are set they wont change that often. I am using a BS2p40 and a DS1302 Time clock, my variables·turns output pins on and off at whatever time the varibles is set to. I·also have·2 ADC's·hooked up to my Bs2p40. Thanks again.
  • GadgetmanGadgetman Posts: 2,436
    edited 2005-04-28 08:34
    The BS2p40 you're using has a 128Byte scratchpad RAM which is ideal for 'little-used' variables that needs to be saved.

    How often will the variables change after being set from your menu?
    Depending on how often they change, they could be saved into one of the EEPROM banks.
  • HIBITDACHIBITDAC Posts: 40
    edited 2005-05-02 21:35
    Most od my variables are used for turning outputs on and off at whatever time is stored in them, they wont need to be changed that often but they will be changed. How do use the scratch pad?

    Thanks
  • HIBITDACHIBITDAC Posts: 40
    edited 2005-05-02 21:39
    This whole project is for a saltwater topoff system. Everything works execpt the varivles. Im trying to turn lights and pumps on and off at different times. If you want me to post the code I will but it is 6 pages long right now.

    Thanks
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-05-02 21:53
    Attache it as a text file so that it can be viewed in a separate browser page.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas, TX· USA
  • HIBITDACHIBITDAC Posts: 40
    edited 2005-05-02 23:03
    I tried explaining each line.·If you have any questions just ask.
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-05-02 23:28
    It seems to me that your "On" and "Off" times are not going to change very frequenty, so why note store them in EEPROM and read them as you need. The READ instruction does not harm the EEPROM as WRITE (after several thousands of cycles) ultimately will.

    I think, too, that your program -- especially being as big as it is -- would benefit from the guidelines set forth in "The Elements of PBASIC Style" (it's in the Help file).· You have several lines that use internal register names, like...

    · IF IN3 = 1 THEN Some_Label

    ... which can make a program difficult to follow and/or troubleshoot.· In one case:

    · IF IN4 = 1 THEN on

    ... you'll have a problem if you want to engage PBASIC 2.5 syntax as ON is a new keyword (in ON-GOSUB and ON-GOTO).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas, TX· USA


    Post Edited (Jon Williams) : 5/2/2005 11:32:54 PM GMT
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-05-02 23:41
    Posting a schematic (GIF or JPG) would also be helpful, as well as an outline of what you want your program to do. There seems to be opportunity to make improvements, but I don't want to take anything for granted based only on looking at your code.

    To give a specific example, if you free up your RAM space such that you can have a nib variable that points at an outlet, you could consolodate all of your on-off subroutines to just two:

    Outlet_On:
    · theOutlet = 15 - theOutlet + 1
    · AUXIO
    · HIGH theOutlet
    · RETURN

    Outlet_Off:
    · theOutlet = 15 - theOutlet + 1
    · AUXIO
    · LOW theOutlet
    · RETURN

    And if this project is still in development or you plan to build more than one, you could reduce your cost by adding a couple 74HC595s and a 74HC165 to a 24-pin Stamp module.· You don't seem to be taking advantage of any BS2p features, aside from the extra pins on the BS2p40.· With two 74HC595s you could turn three IO pins into 16 outputs, and by using just two more pins, you'd get eight digital inputs from the 74HC165.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas, TX· USA


    Post Edited (Jon Williams) : 5/2/2005 11:49:28 PM GMT
  • HIBITDACHIBITDAC Posts: 40
    edited 2005-05-03 01:26
    Here is my schematic, my Mulitsim disc is scratch so this is about as good as it will get for now.·I also·put my corrected code on. Those "things" all the way to the right are supose to be relays. I dont know the exact schematic symbol for them.
    3300 x 2550 - 1M
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-05-03 03:38
    I'm still trying to figure out what your code wants to do ... it jumps all over the place. Can you list, in order, what tasks your program needs to process and in what order. I'm still of the belief your program can be dramatically simplified.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas, TX· USA
  • allanlane5allanlane5 Posts: 3,815
    edited 2005-05-03 12:52
    You can use the 'DATA' keyword to define locations in EEPROM that you can use to store (and read) data that rarely changes.

    You then use the "READ" command to copy the data from EEPROM to a working variable, and "WRITE" to write the data from a working variable back to EEPROM. Note the EEPROM does have a write limitation of 1 million cycles or so -- so you don't want to write to it every 10 mSecs, because you can wear it out. But for rarely read data it is perfect.

    If you're concerned about that, you can use an external eeprom like the 26L640 using SHIFTOUT/SHIFTIN commands. Then should you wear out the external EEPROM, you simply replace it.

    And read up on the 'scratch pad' ram -- using 'GET' and 'PUT', you can read data from SP locations into working variables, use them, then 'PUT' the results back into scratch pad ram. It does not have the write-cycle limitation of EEPROM.
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-05-03 14:15
    To follow up on Allan's comment, if you rewrite your code using PBASIC 2.5 syntax you can PUT and GET Word values from the Scratchpad (you can also READ and WRITE Words from/to EEPROM). I'm suspicious that your on and off time values are not working because you're only using bytes -- I think these should be Words in the range of 9 (12:00 AM) to 1439 (11:59 PM). By using Words, the math for calculating durations is far easier.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas, TX· USA
  • nick bernardnick bernard Posts: 329
    edited 2005-05-03 21:28
    Gadgetman said...

    3. If your BS2 model has a scratchpad RAM, use that to 'PUSH'/'POP' variables you need to keep unchanged.

    push and pop arent commands... is there a way you can access the scratch pad like a stack? did someone develop a stack adt?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    " Hey! Why is there silicone on my hemostats?"
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-05-03 21:46
    What was meant was PUT and GET.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas, TX· USA
  • HIBITDACHIBITDAC Posts: 40
    edited 2005-05-04 01:04
    The program I attached works to turn and output on and off at a predetermined time, however it is not changable with out reprogramming the stamp. I want to use a variable instead so that i can change it through a menu on my LCD. The prolem that im having is that I want to switch 10 outputs at different times. I can get it to work with one, but when I add the other 9 there isnt enough space for·ALL of my variables.
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-05-04 01:10
    As has been suggested several times, you don't need to maintain your start and stop times in RAM. Use work variables to set the time, then record them to EEPROM. The advantage is that you can loose power and not your start and stop times. Before working for Parallax I created an alarm system with a BS2 and the entire database was in a big EEPROM table.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas, TX· USA
  • HIBITDACHIBITDAC Posts: 40
    edited 2005-05-04 01:28
    I'll try that and see if I can get it to work

    Thanks alot

    Samuel
  • HIBITDACHIBITDAC Posts: 40
    edited 2005-05-05 03:57
    How do you display the output state of aux pin15 to a serial display on main pin9? I dont know what to put in the brackets to signify the aux pins.

    serout 9,16624,[noparse][[/noparse]bin out15]---will display the output state for pin15 on the main side

    I've tried
    serout 9,16624,[noparse][[/noparse]bin aux15]
    and
    serout 9,16624,[noparse][[/noparse]bin aux15]

    Thanbks again

    Sauel
  • GadgetmanGadgetman Posts: 2,436
    edited 2005-05-05 08:05
    Check the MAINIO and AUXIO commands.

    note that you cn only have either the main or the aux set of pins active at one time. This means you'll have to store the value in a variable or Scratchpad RAM first.
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-05-05 13:04
    You need a temporary variable to hold the state of A15

    · AUXIO
    · state = OUT15
    · MAINIO
    · SEROUT Sio, Baud, [noparse][[/noparse]BIN1 state]
    HIBITDAC said...
    How do you display the output state of aux pin15 to a serial display on main pin9? I dont know what to put in the brackets to signify the aux pins.

    serout 9,16624,[noparse][[/noparse]bin out15]---will display the output state for pin15 on the main side

    I've tried
    serout 9,16624,[noparse][[/noparse]bin aux15]
    and
    serout 9,16624,[noparse][[/noparse]bin aux15]

    Thanbks again

    Sauel
    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas, TX· USA
  • HIBITDACHIBITDAC Posts: 40
    edited 2005-06-29 09:26
    An update just incase your wondering...it now takes up 5 slots and is working pretty good, no bugs but still have more to add.

    Thanks for all the help I really apprecite it.

    Samuel
Sign In or Register to comment.