PDA

View Full Version : Safely getting out of an interrupt



MOUNTAIN747
- 11th February 2018, 19:12
Working with DT interrupts(-14), Darrel stated many times to get out of the interrupt as soon as possible. I think this is because of the limited stack. So what exactly does it mean to get out of the interrupt? Of course INT_RETURN gets you out, but what if you don’t want to return to where you were interrupted? I would think that all that is needed is to clear the flag bit, am I wrong? Will this do the trick? Offhand I can’t think of anything else that DT may have done that must be dealt with.

INT_Disable xxx_INT ;clear enable bit
INT_CLEAR xxx_INT ;clear flag bit
GOTO NewLocation
Once you are at the new location you do a INT_Enable when ready for the next INT? I’m working with Hserin.
Wayne

richard
- 11th February 2018, 20:13
am I wrong?

yes , totally


interrupts are really a special type of gosub, one that can occur not from a set point in code space but one that occurs when an external stimulus occurs.
secondly , a 14bit core chip has only one interrupt level only

MOUNTAIN747
- 11th February 2018, 21:38
Richard,
Thanks for responding.
So, your saying there is more to the interrupt than saving Status, w, saving address, enabling bits, setting or clearing flags? I want to receive an interrupt RX_INT and as soon as the program has jumped to the Label ( _ReciveData), I can stop the interrupt routine, take care of business, then go to somewhere in the program other than the program location of that interrupt. If I use INT_Disable and INT_CLEAR what is left hanging? What else needs to be taken care of? I don't care about the old w, I don't care about the old status, I don't care about the old address. Please explain what i'm missing.
Thanks,
Wayne

MOUNTAIN747
- 11th February 2018, 21:58
richard,
OK, so after I’ve thought about this perhaps its not my program that would have a problem but DT’s interrupt. If it acts as a special gosub then there may be some return address and flags that have to be taken care of. Is that correct? If so, how do you get out of it without using INT_RETURN?

richard
- 11th February 2018, 21:58
the problem is that it then becomes a once only event , the pic will never branch to another interrupt.

richard
- 11th February 2018, 22:17
If so, how do you get out of it without using INT_RETURN?
it can't be done any other way except with a reset

mpgmike
- 11th February 2018, 22:37
I believe you would have to POP the Stack, which is to remove the Saved Address the Interrupt was called from. Otherwise you'll eventually get Stack Overflow. If you only need that INT once after start-up, may not be an issue.

MOUNTAIN747
- 11th February 2018, 23:56
thanks for all the input. I've go to chew on this a while. perhaps DT_Handler macro may give some clues as to what would be required.
Wayne

richard
- 12th February 2018, 00:36
imagine driving down the road when ----
"there's a Howard Johnsons! want to eat some clams?" (an interrupt occured new direction required)
you turn the stering wheel to head towards the Howard Johnsons (the act of turning the wheel is the interrupt service) when the new direction is established you release the steering wheel car heads to the Howard Johnsons .
your holding the steering wheel on full lock and asking how can i straighten up without letting the steering wheel return to normal
its not goint to happen
apologies to frank zappa (billie the mountain)

MOUNTAIN747
- 12th February 2018, 01:57
Now I’m getting hungry! No Eldorado Cadillac. Not going to New York, Neeewwww Yooorrrrk!!! Did get drafted. Frank Zappa, Studebaker Hawk, RIP wherever you are!

amgen
- 12th February 2018, 16:38
so, on rcv-int.... save the character to mem or ram to work on in basic later, and raise some flag to be checked in basic that char is in system and leave int.... only takes few micro-seconds to bring chars into system. Can do a few machine code instructions to move character pointer, look for certain incoming character and/or reset character array in the int routine, again all few micro seconds depending on osc. Then always ready for next rcv.

tumbleweed
- 12th February 2018, 17:50
then go to somewhere in the program other than the program location of that interrupt
Perhaps the real question to ask is why do you feel you need to do that?

MOUNTAIN747
- 16th February 2018, 10:32
All I'm after is to transfer to a location other than where the INT occurred. I'm going to take a closer look at DT_INTs-14 and try to figure out if there are any system var that need to be dealt with. Other than that I think the only thing that is needed is to pop the stack and loose the address.

richard
- 16th February 2018, 11:01
I think the only thing that is needed is to pop the stack and loose the address

dream on

typical stack implementation from data sheet core14 non enhanced pic

4.3.2 STACK
The PIC16F627A/628A/648A family has an 8-level
deep x 13-bit wide hardware stack (Figure 4-1). The
stack space is not part of either program or data space
and the Stack Pointer is not readable or writable. The
PC is PUSHed onto the stack when a
CALL instruction
is executed or an interrupt causes a branch. The stack
is POPed in the event of a
RETURN, RETLW or a
RETFIE
instruction execution. PCLATH is not affected
by a PUSH or POP operation.





Note
1: There are no Status bits to indicate stack overflow or stack underflow conditions. 2:There are no instructions/mnemonics called PUSH or POP. These are actions that occur from the execution of the
CALL, RETURN, RETLW and RETFIE instructions, or the vectoring to an interrupt address.

Charlie
- 16th February 2018, 12:54
A safer approach is to simply have the interrupt set a flag and return. You main program can be a tight loop that checks flags. When to detects the flag, it GOSUBs to the new location.

mpgmike
- 16th February 2018, 19:03
;Interrupt Processor:
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler INT_INT, _OK, PBP, yes ;USART CS
INT_Handler AT1_INT, _Fire, PBP, yes ;Fires Coil
INT_Handler IOC_INT, _Wipe, PBP, yes ;Fires Output
INT_Handler RX_INT, _Grab, PBP, yes ;USART Transmission Received
INT_Handler T1G_INT, _Get_RPM, PBP, yes ;Count Pulses to Determine RPM
INT_Handler TMR3_INT, _Stall, PBP, yes ;RPM Below Limits of TMR1
endm
INT_CREATE ;Creates the interrupt processor
ENDASM

This is a typical DT_INT Declaration. As you can see, when an external interrupt occurs the program jumps to a Label called "OK". When an Angular Timer Interrupt occurs it jumps to "Fire". Each Interrupt has a different Label the DT_INT INCLUDE will sent the PC to. An IOC INT directs the PC to "Wipe", and so forth. This may be the part you missed based on your comment,

"All I'm after is to transfer to a location other than where the INT occurred."