Interrupt possible?
Ruben Jacobs
Posts: 4
I am using the Basic Stamp 2 for a cleaning robot project. I would like to know if a interrupt is possible of some other method of being able to detect quickly if one of 5 microswitches are detected and perform a specific routine. I would also like to be able to give priority to specific buttons. If this is not possible I have to resort to a PIC microcontroller...
Rubenes
Post Edited (Ruben Jacobs) : 1/31/2005 6:19:59 PM GMT
Rubenes
Post Edited (Ruben Jacobs) : 1/31/2005 6:19:59 PM GMT
Comments
The BS2 has no hardware interrupts, and in general its software is single-tasking. However, Jon can show you a technique to implement a form of multi-tasking in the PBasic environment. This requires 'sampling' the signals of interest -- the BS2 can implement a sampling algorithm with a latency of less than 10 mSecs. Latencies of less than 1 mSec can be done with the BS2, but less than 100 uSec would be impossible.
Basically, the approach has a 'main loop' which samples the signals of interest. Based on the samples, the 'main loop' calls subroutines to do the actual work, and the 'main loop' can maintain a state_variable to run a state machine in code.
As you can see, the program is broken into small tasks.· Between each task the Scan_Switches subroutine is called and can be dealt with.· Each task takes care up setting the next task, letting the program run in order, or if needed, in a new order to handle events that come up.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas, TX· USA
P.S.: Do you have any circuits to debounce switches? The BUTTON instruction is not very flexible.
This routine scans all the switch inputs and if any stays active for the entire cycle (~25 ms), then it will be reported as active.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas, TX· USA
However, the BS2 solution will be simpler and easier to code and debug. It's up to you at this point. 1/2 second is 500 mSecs, which is a Long time to the BS2.
Thank you. I will see if I can get some software programmed.
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas, TX· USA