PDA

View Full Version : Program returns to beginning at interupt



BGreen
- 22nd April 2005, 20:56
I'm using a 12F629 . The program is suposed to make the LED on the board come on for 2 seconds, then wait for 20 seconds and come on again for 2 seconds, then sleep unles interupted for 5 min. If interupted it is to make the LED shine for 2 seconds and return to the 5 min routine. At the end of the 5 min period with no interupts it is to go to the main program where there is a different interupt routine.

What is happening is whenever it is interupted in the 5 min period, it seems to stall for about 2 seconds and then returns to the beginning of the program. I have confirmed the return to the beginning. It never seems to end the 5 min period and go to the main portion of the program.

Any help would be appriciated.

@ DEVICE pic12F629, INTRC_OSC_NOCLKOUT ; System Clock Options
@ DEVICE pic12F629, WDT_ON ; Watchdog Timer
@ DEVICE pic12F629, PWRT_ON ; Power-On Timer
@ DEVICE pic12F629, MCLR_OFF ; Master Clear Options (Internal)
@ DEVICE pic12F629, BOD_OFF ; Brown-Out Detect
@ DEVICE pic12F629, CPD_ON ; Data Memory Code Protect
@ DEVICE pic12F629, PROTECT_OFF
;
; Set Variables and aliases
; SENSOR input on GPIO.2 - PULL PIN HIGH to trigger
SYMBOL LED = GPIO.0
SYMBOL SENSOR = GPIO.2
SYMBOL CAMPOW = GPIO.4
SYMBOL CAMSHUT = GPIO.5
BO VAR word
BO = 0
;
; Set External interrupt (GPIO.2) with rising edge trigger...
OPTION_REG = %00001100 ; Enable pullups, riseing edge trigger on GP.2, etc
CMCON = %00000111 ; Comparators OFF
INTCON = %10000000 ; Set GIE - clear interrupt enable bit and flags.
;
;
LOW CAMPOW : LOW CAMSHUT : low LED ;Set output pins
pause 2000
high led
pause 20000
low led
pause 2000
high led
WALKTEST:
INTCON = %10010000 ; Set/re-set interrupt enable bit - clear flags
ON INTERRUPT GOTO LTINT
SLEEP 270 'SLEEP FOR 5 MIN
GOTO BASE
;
; LED Interrrupt handler
LTINT:
INTCON = %10000000 ; clear interrupt enable bit and flags
low LED
PAUSE 2000
high LED
resume WALKTEST
;
; Interrrupt handler
MYINT:
INTCON = %10000000 ; clear interrupt enable bit and flags
; Camera Shutter & Power control
HIGH CAMPOW 'PRESS POWER
PAUSE 2000 'HOLD POWER FOR 500 MILLISECOND
LOW CAMPOW 'RELEASE POWER
pause 500
HIGH CAMSHUT 'PRESS SHUTTER FOR 2 SECONDS
PAUSE 2000
LOW CAMSHUT 'RELEASE SHUTTER
PAUSE 10000 'ALLOW 6 MORE SECONDS TO SAVE AND TURN CAMERA OFF
HIGH CAMPOW 'TURN CAMERA OFF
PAUSE 3000
LOW CAMPOW
pause 3000
RESUME BASE ; resume at BASE section
;
; Refresh routine
REFRESH:
HIGH CAMPOW 'PRESS POWER FOR 1 SECOND
Pause 1000
LOW CAMPOW 'RELEASE POWER
PAUSE 3000
HIGH CAMPOW 'PRESS POWER FOR 3 SECONDS
PAUSE 3000
LOW CAMPOW 'RELEASE POWER
RESUME BASE
; Main program
BASE:
INTCON = %10010000 ; Set/re-set interrupt enable bit - clear flags
;
LOOP:
ON INTERRUPT GOTO MYINT
SLEEP 1200 'SLEEP FOR 20 MIN
goto refresh
GOTO LOOP

jmgelba
- 22nd April 2005, 20:59
It would be helpful if you could post the rest of your code. We might then be able to diagnose the problem.

BGreen
- 22nd April 2005, 21:01
Thanks, I did in an edit. something screwed up the original post. You may have to refresh.

BGreen
- 23rd April 2005, 03:59
By the way, I did notice some of my comments are not up to date. All interupts are on rising edge and some of the timing has been revised from the comments. Hope this didn't cause any confusion.

Archilochus
- 24th April 2005, 00:30
Hi Butch,
Have not gone over the code carefully, but there are a few things that don't look quite right...

It looks like OPTION_REG is set for falling edge trigger (though I guess you mentioned that already).

Pullups are ENABLED, but the WPU register is not configured to set which pins have pullups enabled.

Can't find "SENSOR" GPIO.2 set as input. Don't know what it defaults to in the '629.

There should be a DISABLE instruction before your interrupt service routines, with an ENABLE to restart interrupts when needed.
You might try tossing the interrupt service sub-routines up at the top of your code before the "ON INTERRUPT" command is first used. Than just jump around them with a "GOTO StartHere". Others prefer to put the subs at the end of their code.

There's a "RESUME BASE" at the end of your "REFRESH" section. Since you jumped to REFRESH with a "GOTO", the RESUME is not needed (don't know if including it would actually cause problems or not).

Arch

BGreen
- 25th April 2005, 11:20
Arch, thanks for the reply. I ended up redefining a few things and moving a couple of things around and got it to work.