-
USART Interrupt + Pause
I know first hand that placing the Pause command in any code causes the interrupt service to not respond during the pause.
The problem I have is in a number of places in my code I want to stop to do something for say 500ms. For example an LED would light for 500ms or a timeout in a sub would occur after 30 seconds.
I'm left scratching my head on how to do this. Although pause is easy and works because this device is a node I want the host PC to be able to communicate with it whenever it wants.
Am I expect too much? What would be a good approach?
-
For immediate response to interrupts - use assembler interrupts.
For BASIC interrupts with a faster interrupt response time, break down
your pause times into smaller increments in a loop.
Instead of PAUSE 500 ' <-- 500mS delay before interrupt service
X VAR WORD
FOR X = 1 to 20000 ' ~500mS total
PAUSEUS 25 ' <-- 25uS delay before interrupt service
NEXT X
Just take into account that the time spent in your interrupt handler will add
to the overall time delay in your loop if the interrupt happens while in a delay
loop.
-
I want to stay out of ASM as much as possible That is, after all, the reason I use PicBasic and not ASM.
I had contemplated using shorter and more frequent Pause times. I will go that route. The actual times are not huge in this case, they just need to be close enough.
Thanks Bruce!