Looping a WaitForInterrupt() independently of the main code

Discussion about the ZBasic language including the System Library. If you're not sure where to post your message, do it here. However, do not make test posts here; that's the purpose of the Sandbox.
Post Reply
spamiam
Posts: 739
Joined: 13 November 2005, 6:39 AM

Looping a WaitForInterrupt() independently of the main code

Post by spamiam »

I am trying to detect a Hall sensor and count the number of switching events. I can use a pin change interrupt, and once the interrupt is serviced, I want it to be ready to run again.

As I wrote this message, it made my sit down and explain what I was doing, and I realized that

1) The WaitForInterrupt() needs to be in its own task to be able to run autonomously. It is not an interrupt service routine in the manner it could be in C as an "ISR".

2) The task does not automatically restart after reaching the end of execution, the way a C ISR could. It needs a loop within the task to re-wait for the next pin change event.

It was pretty obvious once I cleared my mind and got out of "C" and "ISR" thinking mode.

-Tony
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Re: Looping a WaitForInterrupt() independently of the main c

Post by dkinzer »

spamiam wrote:WaitForInterrupt() [...] is not an interrupt service routine in the manner it could be in C as an "ISR".
Correct, as your other points.

You could, of course, configure the pin for a pin change interrupt and add your own ISR. That would eliminate the need for a task whose only purpose is to await the interrupt.
- Don Kinzer
Post Reply