Nested Interrrupts

cpedw

Senior Member
I am developing a device that incorporates a clock (an MSF device that operates through an 08M2) and other functions. The clock updates each minute, using an interrupt to the main controller (14M2) before sending the new time data which the 14M2 forwards to the display.

Meanwhile, other functions are activated by interrrupts too. Is it permissible to re-enable the clock interrupt while another interrupt is being processed? In particular, will a new clock interrupt get handled correctly while a non-clock interrupt hasn't finished?

This is an outline of the code I'm thinking of, which compiles OK:
Code:
#PICAXE 14M2
SYMBOL intrp    = %00000011        ' Interrupt flag/mask using C.1 (mode switch) or C.0 (clock in)
SYMBOL intrc    = %00000001        ' Interrupt flag/mask using C.0 (clock in) only
'.....
INTERRUPT:                         ' Interrupt on Mode switch OR Clock
    IF PinC.0=1 THEN
        GOSUB Clockout
    ELSE
        SETINT intrc, intrc        'Allow Clock interrupts only
        GOSUB settings             'Deal with Mode switch
    ENDIF
    SETINT OR intrp,intrp          'Reset all interupts
RETURN
 

oracacle

Senior Member
The problem i can see is: if you are in the settings sub and you get a clock interrupt it will call the the interrupt and then try and return and most likely clear the flag, and first return address, so once you leave the settings it will drop out of the interrupt procedure and and in doom.
I ahve not actually tried it, but can't imagine it end too well.

Is there a reason you can't have the setting subprocedure called from the main programme loop?
 

AllyCat

Senior Member
Hi,

AFAIK, PICaxe doesn't support Nested Interrupts; There is only one level of interrupts which is not (re-)enabled until a RETURN (from Interrupt) is executed.

Assuming you are using "legal" subroutines inside the Interrupt routine (i.e. they will terminate with a RETURN and not a GOTO), then the SETINT intrc, intrc will have no effect because interrupts are disabled anyway, and then the SETINT OR intrp,intrp will over-ride it before interrupts do become active (after the RETURN from the Interrupt).

Also beware that the interrupt inputs are not Latched in themselves, so any flag status read inside the routine might not be the same as that which initiated the Interrupt.

Cheers, Alan.
 

cpedw

Senior Member
That sounds like a conclusive NO then. A shame but I can work around it. Thanks for saving me some time up a dead end.
 
Top