Using interupts with the BS2p24/40
How can i use interupts with the BS2p24/40?· The frequently asked questions on the website state that the microcontroller itself cannot support interrupts.· Is there an easy way to incorporate interrupts with the use of the BS2?· If not easy, then a good way?· Please reply.· Any helpful advice is well appreciated

Comments
With the BS2p you can setup a polling mode that checks the state of certain pins (you set them up) for certain states (you decide) and takes some action. This is called pin polling. It allows the high level to finish before the pins are scanned and other possible action taken. This is the only way to keep the high-level code working properly. It's not a true interrupt in that the inputs are not scanned until the currently-exectuing instruction is complete. The "POLL" instructions in the Help file can be used to setup pin polling and actions.
That said, often program architecture can help. Here is a structure that I use in many of my programs.
Main: DO GOSUB Background ON task GOSUB Task0, Task1, Task2 LOOP Background: ' do something important here RETURN Task0: ' task 0 code task = task + 1 // NumTasks RETURN Task1: ' task 1 code task = task + 1 // NumTasks RETURN Task2: ' task 2 code task = task + 1 // NumTasks RETURNAs you can see, the code in the subroutine Background runs every time at the top of the loop.· The variable called task is used to determine what the program does next.· I've made this very simple, but you can add more intelligence to the task updating to handle special conditions.
Task0: ' task 0 code IF (condition) THEN task = NewTask ' redirect task pointer ELSE task = task + 1 // NumTasks ' point to next task in order ENDIF RETURN Task1: ' task 1 code IF (condition) THEN GOSUB TaskX ' handle condition ENDIF task = task + 1 // NumTasks ' point to next task in order RETUN▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office
Post Edited (Jon Williams) : 12/15/2004 6:10:02 PM GMT