Question about hardware interrupt handling

pjrebordao

Senior Member
On a 40X2, inside the interrupt processing routine, should I clear the interrupt flags right at the beginning ?

In this case:

setintflags off
hint0flag = 0
hintflag = 0

And at the end of the routine, should I end with ?

hintsetup %00000001
setintflags %00000001, %00000001
 

pjrebordao

Senior Member
Oops ! Just discovered that some months ago, I've made the same question and got some answers.

However, it's still not clear to me how to disable interrupts upon entering the ISR. Is "setintflags off" enough, right at the beginning ?
 
Last edited:

Technical

Technical Support
Staff member
You can't interrupt the 'interrupt:' sub routine, so as soon as it is entered interrupts are disabled automatically.

The actual position of the new setint/setintflags within that routine is not important, as they are only enabled again after the 'return' of that sub has been processed.

The actual flags themselves may change whilst in the routine, but this cannot trigger another interrupt. Most people reset the flags just before the return command.
 

matchbox

Senior Member
The actual position of the new setint/setintflags within that routine is not important, as they are only enabled again after the 'return' of that sub has been processed.
This is an issue that i am trying to find a work around to....
I have an OLED display scrolling through a message that states an error. And an interrupt that can be trigger by a switch to reset that error anytime through that scrolling message.
The problem i have is that once the interrupt clears the error, it then returns and continues to scroll the rest of the error message it just cleared.
I really need it to be a GOTO after the setint subprocedure. But it appears that just will not work. Does anyone out there have any ideas of a way to over come this problem?
 

inglewoodpete

Senior Member
I think you need to set a flag bit (Reserve a byte variable and use one of its bits) as a binary memory of when the "error reset" switch is operated. The display routine would then check that bit to determine whether to continue with the error message or return to the "normal" message. The bit flag would then be cleared when the normal display sequence is resumed.
 

rossko57

Senior Member
It's probably a case of restructuring your code.
In general, you aim to do as little as possible within the interrupt routine, and return to normal flow as soon as sensible.
If you have a repetitive routine doing something, that needs to affected by "external" events like interrupt, you might check to see if something has happened between the repeats.
In this case, it sounds like your scrolling routine should check to see if "error" is still present before the next iteration?
 

matchbox

Senior Member
I was thinking of something like that Pete, but im only using a M2 series chip, not an X2 with flag ability. Shame..

I can get it to check for and error Rossko, before the scroll routine starts. But its when the scrolling routine has started, that my problem occures. If a setint is triggered in that time period, then it will continue the rest of the scrolled message after the interrrupt returns.
 

rossko57

Senior Member
So, that sounds like the code you need to change? Someone may be able to help with that, if you share it.
 

matchbox

Senior Member
This part of the code cut-down to give an idea Rossko

Code:
[color=Navy]#picaxe [/color][color=Black]14M2
  [/color][color=Blue]setfreq m16                                [/color][color=Green];16Mhz pause intervals are 4x greater
  [/color][color=Blue]setint [/color][color=Navy][b]%00000100[/b][/color][color=Black],[/color][color=Navy][b]%00000100                 [/b][/color][color=Green];interrupt when pinc.2 high  

 [/color]
[color=Black]start:
  [/color][color=Blue]do
  loop[/color]

[color=Black]scroll:
  [/color][color=Blue]serout b.2[/color][color=Black],[/color][color=Blue]n2400_16[/color][color=Black],[/color][color=Blue]([/color][color=Navy][b]254[/b][/color][color=Black],[/color][color=Navy][b]208[/b][/color][color=Black],[/color][color=Red]"MESSAGE BEING SCROLLED"[/color][color=Blue])    
  do
  inc [/color][color=Purple]b0                                     
  [/color][color=Blue]if [/color][color=Purple]b0[/color][color=DarkCyan]=[/color][color=Navy][b]52 [/b][/color][color=Blue]then                              
  serout b.2[/color][color=Black],[/color][color=Blue]n2400_16[/color][color=Black],[/color][color=Blue]([/color][color=Navy][b]254[/b][/color][color=Black],[/color][color=Navy][b]1[/b][/color][color=Blue])               
  pause [/color][color=Navy][b]200 
  [/b][/color][color=Purple]b0[/color][color=DarkCyan]=[/color][color=Navy][b]0                                     
  [/b][/color][color=Blue]goto [/color][color=Black]start [/color][color=Blue]endif                               
  serout b.2[/color][color=Black],[/color][color=Blue]n2400_16[/color][color=Black],[/color][color=Blue]([/color][color=Navy][b]254[/b][/color][color=Black],[/color][color=Navy][b]24[/b][/color][color=Blue])               
  pause [/color][color=Navy][b]700                                  
  [/b][/color][color=Blue]loop
        
[b][u]interrupt: 
  [/u][/b]serout c.4[/color][color=Black],[/color][color=Blue]n4800_16[/color][color=Black],[/color][color=Blue]([/color][color=Purple]b22[/color][color=Black],[/color][color=Purple]b23[/color][color=Black],[/color][color=Purple]b26[/color][color=Black],[/color][color=Navy][b]%00000010[/b][/color][color=Blue])
  if [/color][color=Purple]pinc.2[/color][color=DarkCyan]=[/color][color=Navy][b]1 [/b][/color][color=Blue]then goto [/color][color=Black]interrupt            [/color][color=Green];loop interrupt while switch remains pressed
  [/color][color=Blue]serout b.2[/color][color=Black],[/color][color=Blue]n2400_16[/color][color=Black],[/color][color=Blue]([/color][color=Navy][b]254[/b][/color][color=Black],[/color][color=Navy][b]2[/b][/color][color=Black],[/color][color=Navy][b]253[/b][/color][color=Black],[/color][color=Navy][b]7[/b][/color][color=Blue])          [/color][color=Green];display eeprom message 
  [/color][color=Blue]pause [/color][color=Navy][b]8000                                 [/b][/color][color=Green];display message for 2second 
  [/color][color=Blue]serout b.2[/color][color=Black],[/color][color=Blue]n2400_16[/color][color=Black],[/color][color=Blue]([/color][color=Navy][b]254[/b][/color][color=Black],[/color][color=Navy][b]2[/b][/color][color=Blue])                [/color][color=Green];reset OLED display
  [/color][color=Blue]setint [/color][color=Navy][b]%00000100[/b][/color][color=Black],[/color][color=Navy][b]%00000100                 [/b][/color][color=Green];re-activate interrupt
  [/color][color=Blue]return [/color]
 

inglewoodpete

Senior Member
I was thinking of something like that Pete, but im only using a M2 series chip, not an X2 with flag ability. Shame...
I think you've missed the point of my post. A 'flag' in programming is a binary variable: its states are either True or False. In any PICAXE model, the lower order byte variables can have their bits addressed separately.
Code:
[color=Blue]Symbol [/color][color=Black]AckButtonMem [/color][color=DarkCyan]= [/color][color=Purple]bit8   [/color][color=Green]'Binary variable or flag[/color]
[color=Blue]Symbol [/color][color=Black]AckPressed   [/color][color=DarkCyan]= [/color][color=Navy]1[/color]
[color=Blue]Symbol [/color][color=Black]Released     [/color][color=DarkCyan]= [/color][color=Navy]0[/color]

[color=Black]AckButtonMem [/color][color=DarkCyan]= [/color][color=Black]AckPressed[/color]
[color=Green]'other code[/color]
[color=Blue]If [/color][color=Black]AckButtonMem [/color][color=DarkCyan]= [/color][color=Black]AckPressed [/color][color=Blue]Then
   [/color][color=Black]AckButtonMem [/color][color=DarkCyan]= [/color][color=Black]Released
   [/color][color=Green]'other code[/color]
[color=Blue]Else     [/color][color=Green]'ie AckButtonMem = Released
   'other code[/color]
[color=Blue]EndIf[/color]
 

matchbox

Senior Member
Sorry Pete, i thought you ment flag interrupt.
That sounds like an idea.
I could just use the counter variable in the scroll sub as the flag to let the setint know if the scrolling has started or not. Is that what you ment?

Interrupt:
Other stuff
If b0 >0 or b0<52 then let b0=52
Endif
Setint %00000100, %00000100
Return
 
Top