Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 18:45 23 May 2026 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : How do I disable interrupts ?

Author Message
58kk90
Regular Member

Joined: 14/06/2023
Location: United Kingdom
Posts: 77
Posted: 03:45pm 20 May 2026
Copy link to clipboard 
Print this post

Guys, I am completely baffled here, I have two pins on the Pico connected to two sensors, the pins are defined like this

SetPin GP10,INTH,HallEffectInterrupt1,PULLUP
SetPin GP11,INTH,HallEffectInterrupt2,PULLUP

In the Picomite user manual under the interrupts section, it states

"If you must call a subroutine that is also used by an interrupt you must
disable the interrupt first (you can reinstate it after you have finished with the subroutine)"


So my question is how exactly do I disable the interrupt?
What I want is when the HallEffectInterrupt1 has fired, and i'm dealing with it, setting the flag, doing a bit of code etc, I want to disable the HallEffectInterrupt2 and stop that firing until I have finished dealing with HallEffectInterrupt1.

I have searched the forum, and the manual but cannot find any mention of how to disable and re-enable the interrupt.

Tony
 
terekgabor
Regular Member

Joined: 02/01/2026
Location: Hungary
Posts: 78
Posted: 03:49pm 20 May 2026
Copy link to clipboard 
Print this post

Hello!

Do you mean this:
These interrupts can be disabled by setting ‘period’ to zero  (i.e.  SETTICK 0, 0, 3 will disable tick timer number 3).

G@bor
 
PhenixRising
Guru

Joined: 07/11/2023
Location: United Kingdom
Posts: 1913
Posted: 04:29pm 20 May 2026
Copy link to clipboard 
Print this post

If you have a target sub (mysub in this case) set-up to be triggered by an interrupt

SETPIN pin, INTH, mysub


do

'main code loop
pause 10
loop



sub mysub
'this is called when the pin goes high
.
.
.
'do stuff
.
.
.
end sub



But then you want to directly call the same sub:

SETPIN pin, INTH, mysub


do

'main code loop
pause 10
SETPIN pin, OFF, mysub  'switch off the interrupt
mysub                   'call the sub
SETPIN pin, INTH, mysub 'reinstate the interrupt

loop



sub mysub
'this is called when the pin goes high or directly
.
.
.
'do stuff
.
.
.
end sub

 
58kk90
Regular Member

Joined: 14/06/2023
Location: United Kingdom
Posts: 77
Posted: 04:50pm 20 May 2026
Copy link to clipboard 
Print this post

@terekgabor not quite as it's not a timer interrupt I am dealing with but a hardware interrupt, but thank you.


@PhenixRising thank you that is exactly what I want, I wasn't aware that you can change the pin function 'on the fly' so to speak I assumed they had to be done at the start of your code and once defined they were fixed, I was kind of looking for a disable interrupt HallEffectInterrupt2 type of command I guess that was why I couldn't find anything in the manual.

Tony.
 
ville56
Guru

Joined: 08/06/2022
Location: Austria
Posts: 493
Posted: 05:32pm 20 May 2026
Copy link to clipboard 
Print this post

58kk90,

you stated:

  Quote  What I want is when the HallEffectInterrupt1 has fired, and i'm dealing with it, setting the flag, doing a bit of code etc, I want to disable the HallEffectInterrupt2 and stop that firing until I have finished dealing with HallEffectInterrupt1.


As you are with both interrupts at the same interrupt level (I/O pin interrupt) you will not be interrupted as long as you do not RETURN from the interrupt SUB-routine. So, everything you need to do on interrupt-level, just do it and then return, keeping it as short as possible. In the manual on page 54/55 you will find the interrupt levels (priorities). Inyour case all interrupts except tick and pin I/O can take effect.
For me there is basically no difference between staying in the interrupt handler or disabling interrupts for your example, at least from your description.

Gerald
Edited 2026-05-21 03:33 by ville56
                                                                 
73 de OE1HGA, Gerald
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 8842
Posted: 07:13am 21 May 2026
Copy link to clipboard 
Print this post

AFAIK there is only one hardware interrupt accessible to the user and that is triggered by the high speed counter.

Under MMBasic all user interrupts are "soft". You define the trigger and a SUB that will run when that event is triggered. There is no "return from interrupt" as such as the next program command isn't executed until the END SUB in the interrupt routine has been executed. Interrupts are handled in a strictly defined priority after each MMBasic command.

In this case, define a GPIO pin, connected to the sensor, as the interrupt trigger and use that to trigger an interrupt SUB. That SUB should only set a global flag then END SUB. Now, within the program loop, simply test that flag to see if the sensor has been triggered. If it has then handle it and reset the flag. If you wish the main loop can call another SUB to do the work, it can do this at any time without involving the interrupt SUB as if the interrupt is triggered it will merely set the flag which will be tested in the normal way later.

.
Edited 2026-05-21 17:16 by Mixtel90
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 3222
Posted: 08:29am 21 May 2026
Copy link to clipboard 
Print this post

Micks method is best if you can afford the time to get back from the ISR and for the main loop to get around to reading the flag.

If that takes too long the processing needs to be done in the ISR.

So if that Sub is also called from the main loop then, as previously noted, SetPin GPxx, Off as the first line of the ISR and restoring it as the last line is needed.
 
Martin H.

Guru

Joined: 04/06/2022
Location: Germany
Posts: 1454
Posted: 08:31am 21 May 2026
Copy link to clipboard 
Print this post

Disabling (masking) further interrupts when an interrupt service routine (ISR) begins prevents the routine itself from being interrupted by another interrupt. This primarily serves to enhance stability, protect critical sections of the programme and prevent uncontrolled memory overflows.
  terekgabor said  Hello!
These interrupts can be disabled by setting ‘period’ to zero  (i.e.  SETTICK 0, 0, 3 will disable tick timer number 3).

You must therefore ensure that the interrupt routine is not interrupted and re-called mid-execution, as this could lead to unpredictable results.
  Quote  These interrupts can be disabled by setting ‘period’ to zero  (i.e.  SETTICK 0, 0, 3 will disable tick timer number 3).

So put that at the start of your subroutine, and at the end, set the interrupt back to its original value.
Edited 2026-05-21 18:33 by Martin H.
'no comment
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 11356
Posted: 08:32am 21 May 2026
Copy link to clipboard 
Print this post

Nope: The counter/frequency pins are H/W interrupts. The high speed counter isn't. The pin is directly clocking a timer register
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2026