No, you cannot do interrupts in BASIC -- not with Parallax product, not with anybody's product. BASIC is not reentrant. As indicated above, the BS2p and BS2pe allow polling between instructions, and other vendors use this technique to a lesser or greater degree as well.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔ Jon Williams
Applications Engineer, Parallax
Dallas Office
What is polling?
What I am doing is controlling a standard RC car, I have so many IFs and Subroutines Im afraid of running out of memory or sensors lagging since it check only one at a time.
On the BS2p and BS2pe, polling allows the BASIC Stamp to check the status of designated IO pins an take an action (within limits).· Have a look at the various POLL commands in the manual or help file (note: polling is a bit advanced).
Regarding your program, there is a strategy that many use that is the high-level equivalen of the way a lot of assembly programs are designed.· The idea is to create a task switcher such that important code runs every time through the main control loop.· After the important code, then next task is run.· Under normal operation each task simply points to the next, but it has the ability to redirect to a new task if conditions warrant.· Here's a bit of pseudo-code to give you an idea:
Main:
GOSUB Very_Important_Stuff ' -- like background code
ON task GOSUB Task0, Task1, Task2, ...
GOTO Main
Task0:
' do task code first
IF (conditions are okay) THEN
task = task + 1 // NumTasks ' point to "normal" next task
ELSE
IF (condtion is really bad)
GOSUB Emergency_Handler
ELSE
task = xx ' point to next task that should run
ENDIF
ENDIF
RETURN
By placing your task code in subroutines, the code can be called from anywhere within your program -- including other tasks.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔ Jon Williams
Applications Engineer, Parallax
Dallas Office
The examples in the manual barely scratch the surface, and the tutorial does not get very deep into it either. You have to understand the role of the extra read-only locations in the scratchpad ram, how they can latch the occurance of events that occur on input pins while the program is off doing other things. I have made use of the pollwait command in the context of having the Stamp sleep until any of several different triggering events occur.
If your program is getting too many IFs and branches, it will really be a good idea and follow Jon's advice about program organization.
Actually, on NetMedia's BX-24 you can set up a task and then tell it to wait for an external interrupt. That task stays blocked until the interrupt occurs. When it does, the waiting task is run on the next instruction cycle.
It's true that this is nowhere near what the interrupt response that you'd get by programming a microcontroller in assembly language or a compiled language but it does give you a reasonable ability to respond to an asynchronous event.
Comments
On the BS2p and BS2pe you have the POLL instructions, though, but no real interrupts.
Maybe there is a way around it.
Terry
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office
What I am doing is controlling a standard RC car, I have so many IFs and Subroutines Im afraid of running out of memory or sensors lagging since it check only one at a time.
Regarding your program, there is a strategy that many use that is the high-level equivalen of the way a lot of assembly programs are designed.· The idea is to create a task switcher such that important code runs every time through the main control loop.· After the important code, then next task is run.· Under normal operation each task simply points to the next, but it has the ability to redirect to a new task if conditions warrant.· Here's a bit of pseudo-code to give you an idea:
By placing your task code in subroutines, the code can be called from anywhere within your program -- including other tasks.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office
www.emesystems.com/BS2pe.htm#spram_specials
The examples in the manual barely scratch the surface, and the tutorial does not get very deep into it either. You have to understand the role of the extra read-only locations in the scratchpad ram, how they can latch the occurance of events that occur on input pins while the program is off doing other things. I have made use of the pollwait command in the context of having the Stamp sleep until any of several different triggering events occur.
If your program is getting too many IFs and branches, it will really be a good idea and follow Jon's advice about program organization.
-- Tracy
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
It's true that this is nowhere near what the interrupt response that you'd get by programming a microcontroller in assembly language or a compiled language but it does give you a reasonable ability to respond to an asynchronous event.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Don Kinzer
·