Shop OBEX P1 Docs P2 Docs Learn Events
Paged Programming — Parallax Forums

Paged Programming

TinkersALotTinkersALot Posts: 535
edited 2009-05-11 14:55 in BASIC Stamp
PBasic Experts:

I have questions about program/memory layout in a 2pe device.

1) If I have literal strings in my program code, do these literal strings compile into the program space, or do these literal strings use up the more limited "memory space?"

2) Is there a working sample of locating literal strings into a different program page at compile time and then reading from those pages from the "main·program page"·(one sample may·have the literal strings looked up from one of the data only pages and/or the sample could have these literal strings be compiled into other program pages but still returned from there to the main requesting page)

Say, I have a number of literal strings that would be "standard text" in a 20-char-wide LCD row, and I want to locate these strings in a secondary page, excatly what would need to be done to make that work? For example, do I need to set aside a single 20-byte array in memory?

3) Is there any benefit to programming 2pe devices in that manner?

Thanks in advance for any responses.·

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2009-05-04 17:45
    Hello,

    Literal/Constant string data is compiled with the program. However storing this information in this manner is not very efficient. Your strings could be stored in DATA statements and read by passing the address to a print subroutine. This would also allow you to store these strings in another bank of memory and utilize them from any other program slot, since the BS2pe has the ability to read/write data across slots. I hope this helps. Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Engineering
  • TinkersALotTinkersALot Posts: 535
    edited 2009-05-04 18:15
    Hiya Chris,

    It helps a bit...I'll research DATA keyword and re-code accordingly. A couple of follow-on questions if you don't mind:

    1) With "DATA" does that mean I need only to allocate a "pointer" in the RAM space and then load data to that pointer?

    or--

    2) Do I need to allocate a 20-char space in RAM and push/copy "data" to that RAM location?


    Personally, I hope it is #1 and if it is, and this "should be apparent" to anyone that knows/uses the DATA statement, please forgive me if this is a numb-skull question...


    As an aside, can you point out any interesting samples in multi-page programs...it seems to me that paged programs could be written to create a simple form of multi-tasking system (recognizing that only a single task will run at a time)...I'm mostly curious about the possibilities of that and just trying to get a good gauge on how this feature works/can-be-used.

    Thanx again.
  • rixterrixter Posts: 95
    edited 2009-05-04 21:27
    Tinkersalot,

    Multiple slot BASIC Stamps have several advantages. One way to utilize these extra slots is for data and another is for program use. Or you can combine both concepts. I have applications that have an opening "menu" of choices where program flow goes to a different slot depending on a button that is pressed. Each of these programs performs different but related functions. For example, one I have has one program in slot #0 that reads data from a thumbdrive into EEPROM memory starting at slot #2 and continuing through slot #16. The second program is in slot #1 and it reads and displays the data read in the first program. Having another program space also gives you a fresh set of variable space. So you could theoretically split up a complex/large program into smaller segments that are spanned across the slots. Keep in mind that it is not straight forward to pass control back and forth between program slots and retain variable definitions. They are lost when you jump to another slot. You could stuff these into EEPROM or RAM and pull them back out when you jump to another slot, but that is extra work. You may be able to just have the separate segments not rely on the other program's variables as I did in my case.

    Rick
  • TinkersALotTinkersALot Posts: 535
    edited 2009-05-04 22:03
    rixter --

    thanx for the reply. I think what you are saying may confirm what I suspected may be possible (note, I do not yet say it would be a "good idea")....

    but what I have in mind is an "executive" that runs in the first slot, then "tasks" that would run in other slots. These "tasks" would "yield" which would simply "push all their state" into scratch-pad memory and then run the executive in slot zero.

    The executive would simply jump to slots in "round robin order" and would "invoke the tasks found there" by virtue of "jumping to that code"...The tasks would have to know how to "set the context" and resume based on what they find in the scratchpad.

    Does that make any sense?
  • rixterrixter Posts: 95
    edited 2009-05-04 22:31
    TinkerAlot,

    Use the following formula for all of your projects:

    BASIC Stamp + creativity = Good Idea

    It sounds like an interesting venture. Good luck with it. Remember that RAM will lose it;s contents on power down of the Stamp while EEPROM will retain it. If your Executive needs to resume operations after a power cycle, that is to be considered. In may case, I have my project off for periods of time but need to have the data I put in there available the next time I use it.

    Rick
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2009-05-05 22:37
    Okay, so what I was referring to, and what I have used before, is storing large blocks of text data into another slot. When I need to print this data I simply point to it and read it one character at a time to my output device (usually an LCD). This works well when you have a text-based menu/help system where the text consumes so much of your program space. You don’t need a lot of variable space or even scratch pad RAM for this. You can use a work variable and handle the data one character at a time, unless there is a reason to have it elsewhere. The STORE command is the key to reading/writing data in another slot. I hope this helps. Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Engineering
  • TinkersALotTinkersALot Posts: 535
    edited 2009-05-05 23:10
    Hiya Chris --

    Based on your recommendation, I have recoded my application to use DATA arrays for all literal strings. I also understand how this is used...Get a "pointer" to the base of the array and issue a series of eeprom-fetch and output-a-single-char...So, thank you for the "pointer" on how to do that (sorry I couldn't help myself...hehehe)...

    In looking at the memory map for this application, I can see that these arrays are stashed into program memory (but not "compiled into" the program logic proper)....So, I am clear on the operations of this now.

    As an aside, I was "wondering out loud" if the slots system could be used as a the basis for a simple cooperative multi-tasking system....I know its off-topic from the "literal strings" question....And I was mostly curious if anyone had ever done anything along those lines with these "higher end stamps"... Could be a fun project to "poke around on" when I get my current application completed.

    Thanx again for your always excellent responses and help...
  • rixterrixter Posts: 95
    edited 2009-05-06 02:38
    The description Chris gives about fetching data from EEPROM is exactly what I do.... a loop of code that grabs one byte at a time and sends it to a display. I just don't use DATA statements because the data that is in the EEPROM was stuffed there (one byte at a time) from an external TXT file because the data changes. Having help text and other string data for menu screens that is probably static in most cases stored in EEPROM is an interesting concept that I didn't think of.

    I would think that "multi-tasking" with respect to the program slots in the BASIC Stamp 2P series isn't practical because the programs can't run at the same time. You could have programs or segments that could work together in some way, but not at the same time. The biggest advantages are the ability to have more program space, more variable space and a physical separation of program segments for organizational purposes.

    A better approach if you wanted to experiment with the multi-tasking concept might be to attach a few BASIC Stamps together. People have done this before. The lack of true interrupts in the Stamp add to the challenge you would have getting more than one Stamp to work in unison with the others, but you could theoretically get the separate Stamps to perform separate functions and report results to one another at some interval of time.

    Rick
  • TinkersALotTinkersALot Posts: 535
    edited 2009-05-06 07:02
    Well, Rixter,

    I was just too curious about·this executive plus tasks idea·to just let it lay there....

    So, I did a quick implementation that illustrates the shell of the idea I have in mind....

    It "works" and could be the foundation for some kind of a future·idea....

    I agree that w/out interrupts pre-emptive multi-tasking is just not possible on this device....

    But this kind of "cooperative multi-tasking" can be useful for certain implementations and·I suspec that this resembles the multi-taskers·typically found in "embedded OS'es" that run on devices like the PIC that really don't have too much "stack space" for full·push/pop of·different task execution states..

    Again, this may be not·more than a·toy to goof around with, but was a fun exercise nonetheless....

    Later Gater.
  • vrossivrossi Posts: 38
    edited 2009-05-06 11:20
    Hi, Tinkers

    From the example you posted I see you are quickly developing an interesting "multitasking simulation" on BS2.

    You might be interested in some other application of the same concept.

    Penguin Big Brain: where I simply store six different independent programs in slots 1 to 6, and use the power-on button to allow the user to choose among them, without needing a connection to the PC. The program is made for the Penguin, which uses a BS2px, but can be used with any high level BS2.
    http://forums.parallax.com/showthread.php?p=765432

    If you wish to give a look to some example of a different approach (connecting different BS2 working in parallel), you may analyze my ABBot (a boe-bot using two communicating boards):
    http://forums.parallax.com/showthread.php?p=783408


    For a higher level of communication and integration, you can look at the Basic Stamp Supercomputer by humanoido:

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


    Please keep posting about your project.
  • TinkersALotTinkersALot Posts: 535
    edited 2009-05-06 14:05
    Hiya vrossi,

    Thanx for the links to other interesting/related projects. I'll give them some study. There are a couple more "core features" that could be useful in a framework like the one I am demonstrating here. For example, implementing a symbol event/signaling-system for "cross task messaging" comes to mind.

    I also want to figure out how to use "resource slots" well. These would be the additional slots that can contain data but no programming....That is still a mystery to me....I haven't seen/uncovered any example of how to pull data from "remote slots" yet.

    I am sure I can think of more things, but the risk is that the "multi-tasking framework" becomng larger than the application's it hosts. If that happens, then the approach will lose some of its value...
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2009-05-06 16:21
    TinkersALot -

    You may find this makes for interesting reading as well: http://www.emesystems.com/BS2SX.htm . Thanks go to Dr. Tracy Allen.

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When all else fails, try inserting a new battery.
  • TinkersALotTinkersALot Posts: 535
    edited 2009-05-06 16:37
    Bruce --

    Thanx for that info....I'll add that to my "reading list" [noparse]:)[/noparse]
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2009-05-07 15:55
    I think the only difference to what I was referring to is that since you’re using a multi-slot BASIC Stamp you can actually store the DATA statements in a separate program slot altogether. This way they don’t take up space in your main program slot.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Engineering
  • TinkersALotTinkersALot Posts: 535
    edited 2009-05-07 16:35
    Chris --

    thank you for your continued guidance on how to accomplish this using "best form"... Based on your guidance I am experimenting with STORE with READ/WRITE to get a generalized understanding of the use of these commands. If it is "applicable" I think I may include some use of those commands in the simple "multi-tasking OS" (I know that is a bit of stretch of the common understanding of that term) shell when I post an update to that.

    thanx again for your always excellent guidance and have a great day....
  • TinkersALotTinkersALot Posts: 535
    edited 2009-05-08 05:13
    I have updated this sample to include a form of "inter-task messaging." The "tasks" (those programs that run in slots 1-6) will immediately yield if they have no messages sent to them. If there is a message queed to them then they will run, and then yield when they have completed their processing. The inter-task queue is a "shared memory area" that is accessed with a pair of "get/put" functions. The message queue is a simple 2-byte structure that holds "message routing information" (the target and sending task-slots) and a single byte "message payload"....Other implementations may vary, but the purpose of this is simply to illustrate one possible technique.

    I think this shell is now "completed as a sample" for a simple "cooperative multi-tasking OS" and I hope that it is "somehow useful" to the community here. I will try to·use the techniques here in my next·2pe project (the one I am working on now fits well in a single slot, but if it "grows like all projects·do" then I think·that this programming architecture may·provide a·useful way to "logically partition" the project into a set of cooperative tasks that can "share" the device.

    In any event, this was a fun exercise, and I learned more than a couple of things about "next level coding" of these cool little·devices...

    Cheers.

    TinkersALot
  • TinkersALotTinkersALot Posts: 535
    edited 2009-05-09 03:20
    Another Update --

    With this update the following are included:

    1) Removed all "magic number" and replaced them with constants

    2) Added another method of task schedulding. The sample new includes a 4-level task priority scheme. The roound-robin scheduling is still in place (and the means to swich between round-robin scheduling and task-priority scheduling is controlled by a configuration value stored in the shadow-ram assigned to the executive slot).

    With this new scheme, the order of task execution can be "tuned" by the application developer by making entries into·up-to-four task-priority lists. The more times that a task·appears in these arrays, then the more it will run, and·thus the "higher priority" it will have.

    3) cleaned out a lot of the "debug code" that was in the project as it was·adding to a general-sense-of-clutter. If you think that you want some of this "trace code" back in then download version #2 and merge those code lines back into this updated version.

    Okay, well that is all this project has for now, and I am hard pressed to think of any additional features that would add·more value to this project shell.

    Again, I hope this project will be of interest and/or useful to somebody in this community.

    TinkersALot
  • JFReyesJFReyes Posts: 10
    edited 2009-05-11 12:20
    Thank you very much for your post. Some time ago I started coding a cooperative multitasking executive for a project I'm working on, but got stuck in the message passing algorithm between the state machines. Your code has brought me some great ideas that I'll try with my project.

    By the way, the project is a smart electrical (A/C) multioutlet box to be used for an aquarium. Its 8 outputs will control various pumps, skimmer, UV sterilizer, lights and its only A/C input will detect when there's a power blackout so it will adjust the outputs to work with an UPS backup.

    Keep up the good work and thanks again!

    Regards,

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jos
  • TinkersALotTinkersALot Posts: 535
    edited 2009-05-11 14:55
    Jose --

    I am glad that the concepts in the posted sample could be useful to you. The project you described sounds pretty cool.
Sign In or Register to comment.