Every time you perform a GOSUB (or Interrupt Call), the return address is automatically pushed onto a stack within the processor core. When you perform a RETURN (or RESUME) that address is popped back out from the stack. All this happens automatically. All you must remember is that there should really be no more that FOUR actice events on the stack at any point in time. By that, the sum total of active GOSUBs and pending INTERRUPTS must not exceed FOUR, otherwise you risk losing the end stack contents as they are just pushed out into oblivion. You then have an unstable program.
I've not studied your problem, but if you think that every x interrupts you have a problem, then it seems to me you could be executing a new interrupt before you've completed handling the previous one. Make sure that Interrupts are DISABLED within your Interrupt Service Routine and that you exit your ISR with a RESUME before an new interrupt is allowed to happen.




Bookmarks