Is a 1-line background program possible?
JPL
Posts: 8
I would like to run a 1 line program in the background while everything else is running on my BSp40. The 1 line would be:
IF IN10 = 1 THEN GOSUB [subroutine]
The only thing I can think of now is to put that 1 line in every loop that I have written, but is there another way?
IF IN10 = 1 THEN GOSUB [subroutine]
The only thing I can think of now is to put that 1 line in every loop that I have written, but is there another way?
Comments
There is no such thing as a background in the Stamps. They are single-threaded processors. They can do one thing at a time. Only
There is something called "polling" in the BS2p Stamps, where the Stamp can indeed check the status of an I/O pin in between instructions, but there's no way to call a subroutine. The Stamp can be forced to effectively do a GOTO, but there's no way to remember where it came from, so it can't return to the place where the poll succeeded.
It's pretty easy to add a little bit of external hardware to remember the change in state of an I/O pin (like a capacitor that's discharged when your input occurs and slowly gets recharged). If there's a delay of a sizable fraction of a second, you would only have to test for it occasionally, not in every loop.
Depending on what your program does, you might be able to rewrite it using a different structure where it's relatively easy to embed tests for the state of an I/O pin.
Thank you for your quick reply.
I made a program that polled an input while an led flashed and the same program without polling. I couldn't see a decrease in led flash speed. Which is a nice thing. The stamps are already pretty slow.
What if the Stamp was forced to reset as a result of some external stimulus, such as whatever external circuitry was originally planned to switch IN10 high (per the OP)?
In this configuration, the OP's GOSUB-type routine would be relocated to the very beginning of the program, so it would execute first after each forced reset. Afterward, the program could jump to a location dictated by a variable previously written into EEPROM. Of course, all variables used would also need to be written to EEPROM regularly, and read from EEPROM into RAM after each reset.
Uncurl your toes, it's just a thought. Although someone has probably done it already and Mike and Phil know the proper terminology for this type of routine.
What you're suggesting is not particularly different from the poll statements although it would work with all Stamp models, not just the BS2p models. With all the "checkpoints" needed to remember what the program was doing when the reset occurred, you'll quickly burn out the EEPROM. If you had a small amount of RAM like that built into a DS1302 real time clock, it would be easy to save the program's state.
So much for my "poor man's interrupt" theory...
But I'm still working on antigravity and perpetual motion!