Shop OBEX P1 Docs P2 Docs Learn Events
Running multiple programs at once — Parallax Forums

Running multiple programs at once

Gary&LorenGary&Loren Posts: 8
edited 2015-06-25 09:51 in BASIC Stamp
Is it possible to run multiple programs at once? If it is, how? (I have the What's a Microcontroller? Parts and Text (https://www.parallax.com/product/90005).

Comments

  • ercoerco Posts: 20,257
    edited 2015-06-24 12:32
    No, the BS2 is a single thread processor. There is no multitasking, but of course things happen PDQ. Often, programs can be combined so that they run seamlessly together in a sequenced loop. On a Boebot, two or more servos each need a specified pulse every 20 milliseconds. In between sending those 20 ms pauses, the BS2 reads sensors and decisions (branches) are made.

    It seems a bit daunting at first, but the million of us who have already learned can't be wrong! :)
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2015-06-24 15:46
    Someone once told me (2005) that I couldn't blink multiple LEDs at different rates on the BS2. I said, "Challenge Accepted!" So he stated that the LEDs couldn't center on a fixed start/stop point. Basically that they could be staggered off a common start/stop point. So I wrote a program that went through a loop and one at a time looked up 16 bit values where the high bit was the on/off state of the LED and the other 15 bits were the toggle delay. When the program is run the five LEDs (could be expanded) are all blinking at their own rate completely independently of each other with non-synchronized on/off times. I can't seem to find the final version of the code, but the first draft without comments is attached in case it helps in any way.
  • ercoerco Posts: 20,257
    edited 2015-06-24 19:42
    Good challenge, Chris. I'm up for it. I have my own simplistic version of how to do it, along the lines of how Beau Schwabe modded my "BS2 runs 16 servos" program, incrementing, dividing and truncating.

    You know me, I say lets make it interesting. Who can write the smallest program to blink 5 LEDs at different rates?

    I'll start a new thread to avoid hijacking this one any further. I better post quick, 'cuz I'll get slaughtered right quick by all the real programmers.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2015-06-25 09:51
    erco,

    As a note I wasn't going for simplicity or compactness so much as showing an example of multi-tasking in a manner was less deterministic than a single loop updating everything at once. In my case each task is called in succession, but the time to return can vary depending on what each task does. Each task can also alter the path for the next task, so that they may not always run in sequence. This is more akin to a higher level O/S at a simpler MCU level. At the time I was trying to bang the program out while we were all hanging around my cubicle discussing it, so it's not very clean. But covers the aspects we were discussing that day.
Sign In or Register to comment.