PDA

View Full Version : Interrupt only works in main loop, not in subroutines???



rgregor
- 28th November 2010, 22:23
Hello,
I am facing to the strange problem. I have the following program:

'interrupt for timer
OPTION_REG = $d5
INTCON = $a0 'enable TMR0 interrupts and global interrupt
PIE1 = 0
On Interrupt Goto intManagement

enable
while 1
if (PIR1.5==1) then
HSERIN 50, main, [wait ("GET /"), STR COMMAND\96\$2F]
GOSUB waitFiveSec
HSEROUT["Hello"]
endif
WEND
end


disable
intManagement:
if (INTCON.2 == 1) then
ticks = ticks + 1 ' Count pieces of seconds
If ticks < 61 Then tiexit
toggle ACTIVITY_LED
ticks = 0 'One second elasped
second = second + 1
If second >= 60 Then
second = 0
minute = minute + 1
If minute >= 60 Then
minute = 0
hour = hour + 1
if (hour >= 24) then
hour = 0
day = day + 1
if (day >= 7) then
day = 0
endif
endif
ENDIF
endif
endif
tiexit:
INTCON.2 = 0
INTCON.7 = 1
resume

enable
waitFiveSec:
for i = 0 to 5000
pause 1
next i
return


The interrupt is working, my activity led is blinking. But if I will send to serial port this "GET /",
then the LED will stop blink for these 3 seconds. For me it seems, that if the main program will jump to sub, then, it waits for its end and then it calls the interrupt. It looks like, that the interrupt doesn't work in sub programs. Am I right?

Archangel
- 29th November 2010, 03:11
You might be getting a stack overflow due to missing resume at the end of intManagement routine when it finally does exit there . . .

rgregor
- 30th November 2010, 11:39
You might be getting a stack overflow due to missing resume at the end of intManagement routine when it finally does exit there . . .

I have resume at the end of intManagement

mackrackit
- 30th November 2010, 14:10
That is one of the problems with ON INTERRUPT. Not sub routines but ON INTERRUPT waiting for certain commands to finish.

From the manual

When an interrupt occurs, it is flagged. As soon as the current PICBASIC PRO™ statement=s execution is complete, the program jumps to the BASIC interrupt handler at Label. Once the interrupt handler is complete, a RESUME statement sends the program back to where it was when the interrupt occurred, picking up where it left off.

PBP will not enter the BASIC interrupt handler until it has finished executing the current statement. If the statement is a PAUSE or SERIN, it could be quite a while before the interrupt is acknowledged. The program must be designed with this latency in mind. If it is unacceptable and the interrupts must be handled more quickly, an assembly language interrupt routine must be used.
So you will want to use ASM interrupts or DT's instant interrupts. DT basically makes ASM interrupts easy.

http://www.picbasic.co.uk/forum/showthread.php?t=3251