Thanks bert :-)
Ok, I've removed all the gosubs from the interrupt routine, but I'm still getting erratic results...I kinda know what's not causing my PIC to go to sleep , but the workaround is ugly.
I think I'm hitting diffs with nested gosubs. Imagine this scenario (this is just high evel *not* my actual code - just to get my problem across)...
Code:
loop1:
if pattern = 2 then goto loop2
IF sleep_flag = 1 THEN GOTO SLEEP_ROUTINE
pause 10
gosub decrease duty
gosub select_LED1
pause 10
gosub increase_duty
goto loop1:
'
loop2:
if pattern = 1 then goto loop1
IF sleep_flag = 1 THEN GOTO SLEEP_ROUTINE
pause 10
gosub decrease duty
gosub select_LED2
pause 10
gosub increase_duty
goto loop2
'
SLEEP_ROUTINE:
debug "PIC off to sleep",13,10
pause 200
@sleep
' program continues here afteran IOC interrupt....
pause 100
debug "PIC awake",13,10
IOC_Int:
@ INT_DISABLE IOC_INT
if sleep_flag = 1 then ' if we wake from asleep, this flag will be set still need to clear it & retun to the main program
sleep_flag = 0
goto INTERRUPT_END
endif
LOOP3:
IF SW1 = 0 THEN
COUNT3 = COUNT3+1
IF COUNT3 >300 THEN 'if Sw1 held for 300mS then set sleep_flag
SLEEP_FLAG =1
goto INTERRUPT_END
ENDIF
pause 1
GOTO LOOP3
ENDIF
if pattern <2 then pattern=pattern+1 'cycle between pattern1 & pattern 2
else
pattern=1
endif
INTERRUPT_END:
COUNT3 =0
while sw1=0
wend
PAUSE 180
IOCAF = 0 'CLEAR THE INTERRUPT FLAG
@ INT_ENABLE IOC_INT
'**************
@ INT_RETURN
It seems the interrupt routine (or program!) doesn't like the highlighted Gosubs in the loop1 & loop2 - if I remove the gosubs & instead locate the actual code contents of the gosubs in each loop - then everything is dandy (i.e. the PIC always goes to sleep & awakes fine) , but if I have gosubs in those two main loops - it looks like the interrupt routine (or some other aspect of my program) doesn't return to the main two loops & then trap the sleep_flag being hit! (the problem here is that by not using gosubs I run out of program space *very* quickly!)
What am I missing here?
Bookmarks