Re-enabling an interrupt outside the setint subroutine

matchbox

Senior Member
The title says it.
The manual says it has to be done in the interrupt sub. But is there a way around doing it somewhere else in the program?

My reason being. Is that I don't what the interrupt to be continuously triggered, until an input state of its pin changes within the program.
Then I would re-enable the interrupt.

example :
Code:
setint %00000000, %000000010             ;interrupt low C.1
 

start:

     do
         if pinc.1 = 1 then              ;re-enable interrupt when the state changes on the pin the interrupt is looking at
 
    
         setint %00000000, %000000010    ;do stuff....until called again
 
    
         endif
      
     loop   

interrupt:
  
        low b.1                           ;turn off stuff

  
           return
 

lbenson

Senior Member
I think this issue was recently addressed. The solution is within the interrupt to check for pin high or low; if high (and that is your intended target condition), set your flags and set to interrupt on pin low; if low, just set to interrupt on pin high.
 

matchbox

Senior Member
I think this issue was recently addressed. The solution is within the interrupt to check for pin high or low; if high (and that is your intended target condition), set your flags and set to interrupt on pin low; if low, just set to interrupt on pin high.
Thank you for the reply.
I forgot to say that this is using an M2 picaxe.

Is there any documentation surrounding the addressing of this?
 

lbenson

Senior Member
Untested, but I think it would go something like this for an intended interrupt action on C.1 low.
Code:
setint %00000000, %000000010             ;interrupt low C.1
 
start:

     do
     loop   

interrupt:
  if pinC.1 = 1 then
        setint %00000000, %000000010    ; interrupt on C.1 low
  else
        low b.1                           ;turn off stuff
        setint %00000010, %000000010    ;do stuff....until called again
  endif
  return
 

matchbox

Senior Member
I was thinking of something like that, but it seemed to simple :)

I gave it a go on the Sim. And it does the job well.

Code:
let pinc.1 = 1
setint %00000000, %000000010             ;interrupt low C.1
high b.1

start:

     do
         if pinc.1 = 1 then          

         high b.1
         endif
     loop 

interrupt:
  if pinC.1 = 0 then
        setint %00000010, %000000010 
        low b.1                          ;do stuff....until called again
  else
        setint %00000000, %000000010     ;interrupt on C.1 low
  endif
  return
Thanks once more
 
Last edited:

lbenson

Senior Member
You can also put your HIGH B.1 in the interrupt routine after the ELSE. Where you have it it will repeatedly set B.1 high with every loop, so long as pinC.1 is high.
 

hippy

Technical Support
Staff member
The manual says it has to be done in the interrupt sub. But is there a way around doing it somewhere else in the program?
I think that's a misreading of the manual. After an interrupt one doesn't have to issue another SETINT within the interrupt routine if one doesn't want to. That can be done outside the interrupt routine as you desire.

What must be done is for the interrupt routine to exit with a RETURN statement. Executing a "Goto Main" or similar to restart the program from within the interrupt will prevent interrupts from subsequently being re-enabled with a SETINT command.
 

lbenson

Senior Member
Note that unless your main loop is doing other things, you can provide the function of the code shown without interrupts:
Code:
start:
  do
    do while pinC.1 = 1 : loop ' wait until C.1 goes low
    high b.1
    do while pinC.1 = 0 : loop ' wait until C.1 goes high
    low b.1
  loop
Similar variations can do more things (code within the tight "do : loop"s ).
 

matchbox

Senior Member
I think that's a misreading of the manual. After an interrupt one doesn't have to issue another SETINT within the interrupt routine if one doesn't want to. That can be done outside the interrupt routine as you desire.

What must be done is for the interrupt routine to exit with a RETURN statement. Executing a "Goto Main" or similar to restart the program from within the interrupt will prevent interrupts from subsequently being re-enabled with a SETINT command.
I'm glad it works the way it does, for practicality. I'm not doughting that its the way you say Hippy; but it sure reads to me, the way I stated it:unsure:. Or the manual could be expounded a little more, to make it clearer.

2) When the interrupt occurs, the interrupt is permanently disabled. Therefore to
re-enable the interrupt (if desired) a SETINT command must be used within
the interrupt: sub-procedure itself
.
The interrupt will not be enabled until the
‘return’ command is executed.

Note that unless your main loop is doing other things, you can provide the function of the code shown without interrupts:

Similar variations can do more things (code within the tight "do : loop"s ).
Thanks for the extra idea.
The main thing i'll have to work out. Is the way the interrupt will interact with the rest of my program.
Its great that the interrupt will trigger instantly. But there are lines of code in the main routine, that look for the HIGH state that the interrupt pin also uses. To tell it to move to another location in the program.
The problem may be, that the interrupt is instantaneous. While the line that I spoke of above, may not occur for a few hundred millisecond later.
I'm just writing atm. Once its complete ill work out the debugging and modify it more, around your suggestions.
 
Last edited:

Aries

New Member
the manual could be expounded a little more, to make it clearer.
2) When the interrupt occurs, the interrupt is permanently disabled. Therefore to re-enable the interrupt (if desired) a SETINT command must be used within the interrupt: sub-procedure itself. The interrupt will not be enabled until the ‘return’ command is executed.
I think what they are getting at here is that after the interrupt routine returns, the program continues where it left off. Unless you have SETINT commands scattered throughout your program, the interrupt will not be reinstated as soon as the interrupt routine exits. Therefore, in order to ensure that SETINT reactivates as soon as the interrupt routine finishes, you need to put SETINT inside the interrupt routine itself (and it will not be enabled until the return command is executed).
 

hippy

Technical Support
Staff member
Or the manual could be expounded a little more, to make it clearer.

2) When the interrupt occurs, the interrupt is permanently disabled. Therefore to
re-enable the interrupt (if desired) a SETINT command must be used within
the interrupt: sub-procedure itself
.
The interrupt will not be enabled until the
‘return’ command is executed.
The online pages are the primary documentation these days, and that does describe it sightly differently -
When the interrupt occurs, the interrupt is then disabled and does not automatically re-enable. Therefore to re-enable the interrupt (if desired) when the interrupt processing is finished another SETINT command must be used within the interrupt sub-procedure itself. This interrupt will not be enabled until the interrupt sub-procedure's 'return' command is executed.
http://www.picaxe.com/BASIC-Commands/Interrupts-and-Multi-Tasking/setint

It is always hard trying to find a form of words which covers every possibility without making things so complicated that none of it can be understood but we will take a look at making it clearer that a SETINT does not need to be issued within the interrupt routine itself.
 
Top