Pauses skipped in interrupt during parallel processing

ro1

New Member
Hi

I'm noticing some weird behaviour using an interrupt with parallel processing.

This code looks for an input on C.1, then triggers into the interrupt. But instead of pausing at the line "pause 1000" it goes immediately to the next line.

Code:
setint %00000010,%00000010, C ' look for a high input on pin C.1

loop1: ' parallel task 0
' do nothing
goto loop1:

start1: ' parallel task 1
' do nothing
goto start1

interrupt:
high 1
pause 1000 ' no pause here
low 1
pause 1000 ' or here

setint %00000010,%00000010, C ' set the same interrupt

return

If you comment out the start1 / goto start1 lines (thus switching to single task mode), the program does indeed pause correctly at the pauses in the interrupt subroutine.
It happens in the simulator but also in hardware. I'm using an 18M2 but have tried 14M2 and 20M2 in the simulator which exhibit the same behaviour.

I assumed the problem was something to do with this (manual 1 p63):
"The start (“top”) of the program is always task 0. This is the first task that is started when the chip is reset."

So I thought that maybe when the interrupt is called, multithreaded task 0 goes back to the top of the program and retriggers the setint command, which would skip straight out of the pause.

However, also according to the manual (parallel processing section):
"There is one interrupt (setint command) which will interrupt all current tasks."

So all tasks should be suspended upon interrupt. I tried adding various things like
Code:
suspend 0
suspend 1
setint OFF
at the top of the interrupt subroutine but it still doesn't pause.
I also brought the setint command into the start1 task, and using start0, but still no pause.

Anyone any ideas why this is happening and/or how to get it to pause in the interrupt?

As I'm sure the first question everyone will ask is, what is the application? Obviously the code above can be done without multithreading. I'd prefer not to list my application, it's 3-4 pages of code at the moment, if I post that, everyone will focus endlessly on its quirks and talk about alternative ways of doing it. I've stripped down the code above to the bare minimum in order to isolate the problem, hopefully we can focus on that instead.
 

westaust55

Moderator
I recall a recent post relating to the impact of multi-task programs wuith the M2 PICAXE chips. As recalled (and in my own words);
While in general the PICAXE undertakes the tasks in a sequential round robin fashion between the various multiple tasks, when it comes to pauses, as nothing is being done within a pause period, the PICAXE firmware recognises this and undertakes the next command in the next task.

Thus it would seem possible that whereas a pause instigated in a intrreupt may impact upon the task being undertaken at the instant the interrupt was initiated, during the pause, commands within another task may still be performed.

This "moving on" aspect is discussed in general terms in PICAXE Manual 1 pages 62/63 although the interrupt case is not mentioend.
 
Last edited:

Technical

Technical Support
Staff member
We can confirm this is a bug on the M2 parts - a pause within an interrupt is not correctly processed *only when* parallel tasks are being processed. Single task programs will work correctly. Fortunately it can be resolved with a simple program edit.

If you have PE version 5.4.2 or later you can now use the special command 'pause_int' instead of 'pause' within the interrupt to resolve this issue. The special 'pause_int' command will correct the issue at compilation time so the program then works as expected.
 
Top