Can an interrupt be called as a normal subproccedure?

oracacle

Senior Member
As the title really.
I have the interrupt doing a set off tasks that need to be carried out by another section of the programme but not quite so urgently and under more complex triggering requirements.
The compiler seems to accept it but I am unsure if its going to cause any other issues. If not this is going to save me a lot of code space and time.
 

hippy

Technical Support
Staff member
You can call the 'Interrupt:' routine just like any other but it's not recommended because it will likely get complicated or confusing quite quickly.

The best approach is to create the subroutine which 'does stuff' and call that both from your main loop and from within the interrupt. The following simulates calling 'DoStuff:' every 5 seconds or whenever Pin C.3 is taken high -

Code:
#Picaxe 08M2

MainLoop:
  Do
    Gosub Interrupt_Disable
    Gosub DoStuff
    Gosub Interrupt_Enable
    Pause 5000
  Loop

Interrupt:
  SerTxd( "Interrupt " )
  Gosub DoStuff

Interrupt_Enable:
  ;       543210  543210
  SetInt %001000,%001000
  Return

Interrupt_Disable:
  SetInt OFF
  Return

DoStuff:
  SerTxd( "Stuff", CR, LF )
  Return
If you don't disable interrupts when you are calling the shared routine outside the interrupt it is almost certain that things will go off-track very quickly.
 

oracacle

Senior Member
The interrupt isn't always reset. There is a flag to either allow to enable or disable after the interrupt has run. The interrupt is only enabled at certain point in the code as well meaning that there will not be any overlap in call the interrupt.
Code:
if cont_flag = 0 then
		let tempbyte0 = 10					'set flag so holding loop exits
	else
		'send tempword1 to dislay
		hserout 0, ("taken.val=",#tempbyte3,#tempbyte2,$FF,$FF,$FF)
		'gosub nextion_stop
		pause 600						'allow input to settle before reseting interrupt
		'setting 2 and 6 need mirror locked up
		if prg_flag =2 or prg_flag = 6 then
			pulsout shutter, 200
		end if
		let flags = 0     					'reset interupt flags
		setintflags %00010000, %00010000
	end if
 

hippy

Technical Support
Staff member
I would still recommend having the interrupt call the common code rather than have the interrupt as the common code.

If you really want it you can call it and comment that call out, let the Interrupt fall into the common code ...

Code:
Interrupt:
  ; -- Gosub DoStuff
  ; -- Return

DoStuff:
  ...
  Return
 
Top