SETINT on a Picaxe 20M2

FIREMANJIM

New Member
I am trying to set a interrupt on pin # c.4 on a Picaxe 20M2 chip .... I want it to only check pin c.4 and I want the interrupt to occur only when pin c.4 goes High. The correct binary code is SETINT %00010000, %00010000 Is this correct? and a Interrupt can be set up on c.4 can't it??? Thanks in advance for all you guys help
 

inglewoodpete

Senior Member
The code SETINT %00010000, %00010000 is correct for an interrupt when pin C.4 goes high on a 20M2.

While it is possible to use a GoSub and consequent Return to the interrupt routine, it is not good programming practice. In principle, interrupt routines should be executed and exitted as quickly as possible in order to minimise the time impact on your main routine. Try to limit code in the interrupt routine to setting flags or reading and/or saving values etc. rather than long calculations, loops or delays. Involved actions resulting from the interrupt are usually best handled in the main routine.
 

Goeytex

Senior Member
Also can you GoSub to something in the interrupt???
Absolutely. However, care must be taken in keeping the returns sorted. In Picaxe Basic the interrupt routine is just a subroutine, so calling another sub from within the ISR is simply nesting subroutines. IMO, it is no more bad programming practice than nesting subs in general. But you must be careful with the returns. Good code commenting is highly recommended to keep things organized in your mind.

In some cases it may be desirable to set a flag in the ISR and then test for the flag in the main loop, rather than calling a sub from within the ISR. However in other cases you may not want to return immediately to the calling routine and then have to test for a flag bit before the program can determine what to do next. This can slow down program execution. Calling a sub from within the ISR can speed things up if code execution speed is important.

As the Brits say, "Horses for courses".
 

AllyCat

Senior Member
Hi,

calling another sub from within the ISR is simply nesting subroutines.
It's not clear (at least to me) whether the OP wants to jump INTO the interrupt routine (to execute as a subroutine) or WITHIN the routine (I had assumed the former), but IMHO either is rather poor (if not positively bad) program structuring. As others have said, interrrupt routines generally should be small and fast, particularly as PICaxe has no interrupt priority capabilities.

Some microcontrollers have separate instructions for "Return from Subroutine" and "Return from Interrupt", but PICaxe Basic doesn't. I don't know if there's any risk of the PICaxe interpreter becoming "confused" about which is required, but I think there's a fair chance that a Program-writer might. ;)

Cheers, Alan.
 
Top