Can a Flowcode DELAY be terminated via a hardware interrupt?

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
gtc
Posts: 69
Joined: Mon Mar 23, 2015 5:34 am
Has thanked: 30 times
Been thanked: 15 times
Contact:

Can a Flowcode DELAY be terminated via a hardware interrupt?

Post by gtc »

Can a Flowcode DELAY be terminated via a hardware interrupt?

I want to be able to bail out of a long delay via a hardware interrupt (using the INT0 pin on a PIC16F88).

The application is a fairly trivial timer, so the simple DELAY function is quite suitable rather than having to use a timer macro based on one of the chip's internal timers.

However, I gather that DELAY is implemented in code via a loop of NOOP instructions, so I guess the return from interrupt will continue execution from where it broke off within that loop, rather than after the delay loop itself -- is that true?

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times
Contact:

Re: Can a Flowcode DELAY be terminated via a hardware interr

Post by kersing »

You are right, an interrupt does not terminate a delay.

A simple solution would be to use a loop with delay in it, use and use a flag variable to terminate the loop. Set the flag variable to a value that exits the loop in the interrupt.

Something like:
terminate=false (global boolean variable)
count=0
while not terminate and count < 1000
delay 10ms
count = count+1
end loop

And in the interrupt routine:
terminate = true
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

gtc
Posts: 69
Joined: Mon Mar 23, 2015 5:34 am
Has thanked: 30 times
Been thanked: 15 times
Contact:

Re: Can a Flowcode DELAY be terminated via a hardware interr

Post by gtc »

Thanks, good idea.

Post Reply