variable space
Robert25
Posts: 53
OK folks... quick question.... When uploading a program from the PC to my BS2 robot, I get an error message stating there is no more variable space left.·
Any hints?
Any hints?
Comments
(Feel free to post that part of your code)
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Don't visit my new website...
There is only a finite amount of variable space on any PBASIC Stamp.·The amount of space for variables is limited to 26 bytes. It appears as though you may have exceeded this maximum. Not to worry!·Go through your program and check for the following:
Replace any WORD var with a BYTE var if that is all you need. Savings =·1 BYTE.
Replace any BYTE var with a NIB var if that is all you need. Savings = 4 BITs. Typical of this kind of replacement is a loop counter which only needs to count (say) from·0 to 12, when a BYTE would permit 0-255, which is unnecessary.
Replace any BYTE or NIB var with a BIT var if only ON / OFF is required.
Due to the way the PBASIC Stamp allocates variable space, you can end up with more space than you expect when you consolidate and condense your WORD, BYTE, NIB and BIT usage as shown above.
Reuse variables rather than allocating new ones. One variable named (say) Loop_Cnt could be used for ALL independent, non-nested FOR ... NEXT loops throughout the program, rather than using Loop_Cnt1, Loop_Cnt2, etc.
Rename variables if you wan to reuse them, but they need a more appropriate name, such as follows:
Initial_Value VAR BYTE
Revised_Value VAR Initial_Value
The PBASIC Stamp syntax is perfectly able to use an interim (unnamed) workspace for inline calculations. Force it to do so, rather than pre-allocating interim workspace variables unless absolutely necessary. Sometimes this may mean the creative use of parentheses in arithmetic expressions.
When all else fails, show us your entire·program, and we can generally make some creative suggestions for reducing the amount of allocated variable space.
Regards.
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
<!--StartFragment -->
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
However, assuming I am now very close to the max space allowable on the bs2, and knowing this is only the start of building a more complex program, how do I get more variable space?
I've read that some duties can be offloaded to a co-processor.· Can more space be used there?
I also read that memory in the stamp chips is allocated in blocks and there are some programming tools enabling you to access the extra memory.· Is this true and if so, what are those tools?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Any help or comments would be appreciated.·
Jon,· please keep in mind this is on an Arrick Arobot.
As long as folks are perusing the code, I am having some logic problem with the headlight routine.
Alas, the wife wants to go for a ride so I don't have much time to peruse yer code.
Still, I did load it into my BS Editor and you still have extra RAM (variables) unused.
You can save almost 200-bytes of EEPROM (program memory) by replacing redundant
phrases (e.g. "I'll head that way." and "seems to be clear.") with just one instance in
your DATA statements and add an extra BASIC command or two to have those
concatenated at the appropriate places.
FWIW, I had no problems downloading your code into my BoE other than I didn't have
any of the peripherals attached.
That's all for now. Good luck!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
-Rusty-
--
Rusty Haddock = KD4WLZ = rusty@fe2o3.lonestar.org
**Out yonder in the Van Alstyne (TX) Metropolitan Area**
Microsoft is to software what McDonalds is to gourmet cooking
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
If you come from a "computer programming" background, where you have (relatively speaking) unlimited memory for program and variables, you need to realize that the microprocessor is a whole different ball game. Because of limited resources (memory and processor time, etc.) you have to do things with a microprocessor that might be considdered "poor practices" in a different environment.
As and example I would not be very happy with a programmer working for me on a PC or Unix based project who used a common variable for different purposes. It makes the software harder to maintain, and while it works now could lead to a conflict at a latter point in time. You would also tend to frown on some tricky "if test" that might be more efficient, but harder to read for future (potentially less clever) programmers. You might tend to break up the statement into multiple tests or even nested statements. Less efficient, but with current processing and RAM, it makes the total cost of the software lower (long range maintenance is reduced).
On the other hand, if the project is on a microprocessor, I would lean the other way, and be unhappy of the save variable weren't reused, saving room for possible future enhancements.
Kind of like going back to the "old" days, when 640k of RAM on a PC was "a deluxe system". You have to make compromises and do things that in a different environment wouldn't make sense.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
John R.
8 + 8 = 10
Thanks for looking. I will review the program and try to uncover places where a variable can be reused... good point.
I am concerned about the future though. My plans are to keep expanding the capabilities (e.g., put in the PSC controller for additional servo controls etc.) I know I will quickly run out of space at this rate. Can you suggest what my alternatives might be?
Speaking of the PSC... ( I know probably a different post) but I'll ask it here anyway. I was toying around to get a feel for it and the programming. I ran the "find the PSC" routine and it worked fine... reply was version 1.4. However, when I tried the ramp program, nothing happens to any servo even though the PSC red led is on and the green led blinks.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
For your future variable needs; while you should always use the resources efficiently, as the other posters have suggested, the day will come when you need more space. Just switch to the BS2sx which will give you 8 times the variable space, in the form of 8 separated program slots. As well, there is a common scratchpad area accessible from from each program slot. Runs 2.5 times faster, too!
Tom Sisk
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Do you have a Stamp Tester yet?
http://hometown.aol.com/newzed/index.html
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
On a similar thought, one other possibility to this issue that I was thinking about was to adapt Herbert to go wireless; I have a 802 home network running and thought that the extra space and higher functions that I was thinking of adding (video, etc) could be handled by the computer on the system and local functions handled by the onboard stamp. I wouldn't know where to start with this option although I've been reading about PINK and other RF transceiver projects. Anyone have a best way to start this up???
·· I still think the original advice you got about condensing your variable and code space is your best option right now.· I have seen and helped reduce programs that use all variable space and program space down to usually 2/3 of the variables (in one case lesss than half!) and less than half the code space.·
·· I have released a few programs which make great use of BASIC Stamp resources by sharing I/O lines, re-using variables and using subroutines and data statements to reduce the number of times I use certain instructions.· Some demo programs I have done intentionally waste space in the interest of being clear, but I could easily take the same program (I have one that fills the BS2 EEPROM) and get it down to around half of that size with full functionality.··In this case I used a·lot of SEROUT and DEBUG statements, but I could've just as easily setup a subroutine to handle all of that and put all of the text blocks into data statements.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
I really appreciate you help (and all of the others as well).· My intro into computer programming years ago was with basic in a PC.· Thus the earlier comment about the "philosophy" of programming in PBasic in a uController vs. basic in a PC I really understood.· That being the case, I know I could probably reduce program and variable space by getting more streamlined (this will definetly test my programming skill).·
But one of your comments brings up another question.· In my program, I use DATA statements to store the EMIC text.· Also, the debug statements are there only as temporary to help 'debug" the program and will be removed eventually.· I don't think there is much more room in eeprom space either (according to the memory map).· How can I effectively use this space?
Isn't there a way of connecting two STAMPS together??? Could I get say an SX chip as the main and use the BS2 for other tasks???
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
When ready, I will post it. Right now, I will try trimming the program with everyones great suggestions.
Jon, as always, thanks for the help.
You may want to look at a BS2P24 as not only does it have 8 progam-spaces, 127Bytes of Scratchpad RAM and is faster than the BS2sx, but it also allows you to use othervise unused program-spaces to store DATA.
Also, I believe the SERIN/SEROUT commands can work with the Scratchpad RAM instead of the usual variables, which might just help you out a bit if you're running out of variable space...
And if you don't need the speed, the BS2Pe has double that number of program-spaces...
(you can only run programs from the first 8, the last 8 are for DATA only)
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Don't visit my new website...
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 RESULT temperature ' store the result.. for use later or elsewhere