Pause that's not interrupted

Jeremy Leach

Senior Member
This is a very simple idea, and demonstrates how useful Timer can be...

The SetInt command in the manual explains "After the interrupt code has executed, program execution continues at the next program line in the main program. In the case of the interrupted pause,wait, play or tune command, any remaining time delay is ignored and the program continues with the next program line."

So you might have a very quick interrupt routine, but that will mess up any long pauses in your program. To get round this you can have a special pause routine, which in pseudo-code might look like ...

Code:
TPause:
    Peek TimeValue 'the time you want to pause
    SetTimer <suitable preload value>
    Timer = 0
    Do
    Loop Until Timer > TimeValue
Return
So during the Do Loop, if the interrupt fires it will return to the do loop and if the Timer has exceed Timevalue will end, otherwise will carry on looping.

This whole idea will work most effectively when the interrupt routine is short compared to the Pause time. For instance my interrupt is 50ms and I want to pause for a second, or two seconds to keep LEDs lit.
 
Last edited:

Jeremy Leach

Senior Member
Hi
b1 = 1 to 2000

Well b1 is a byte variable and can't have a value of 2000, only a value 0 to 255.
But apart from this, if you were using a word variable like w1 = 1 to 2000 it depends what other code you have in the loop.

But for an 08M I'd do like InglewoodPete says and just use a stopwatch. Set the count as high as possible/practical, and light an LED after the loop has finished. So you have the time for x iterations of the loop, so you can then work out the time for one.

I find timing code execution quite fascinating, and by understanding the timing it allows you to do clever things, making LEDs flashing at constant rates, but executing things in the meantime etc.
 
Top