PDA

View Full Version : 12F629 Strange interupt behavior



BGreen
- 24th May 2007, 02:09
Below is my code. What I dam doing is controlling a camera. Initially I have 1 button that sets a variable from 1 to 3. Under each variable I set certain functions. Under #1 I set delays between pictures, under #2 I set 24hour, day only, or night only pictures. Under #3 I set standard camera mode, double picture mode or video mode. GPIO.1 sets the 3 variables and GPIO.3 sets the stuff under each variable. An led blinks a corresponding number of times for these. GPIO.0 triggers the pic to take pictures.

The problem I am having is in the routine that determines if it should take a picture if its day or night. In either case the led starts blinking and it increments the variables. If it is set to 24 hour it works fine. If someone could take a look and possibly see anything that would cause this I'd appreciate it. I've about pulled all my hair out. BTW, some labeling is wrong, ignore it.

@ 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 as needed.
;
symbol TRIG = GPIO.0
SYMBOL CAMPOW = GPIO.4
SYMBOL CAMSHUT = GPIO.5
GPIO0NEW VAR BYTE
GPIOOOLD VAR BYTE
GPIO1NEW VAR BYTE
GPIO1OLD VAR BYTE
GPIO3NEW VAR BYTE
GPIO3OLD VAR BYTE
I VAR BYTE
J VAR BYTE
K VAR BYTE
L VAR BYTE
M VAR BYTE
N VAR BYTE
O VAR BYTE
P VAR BYTE
Q VAR BYTE
OUTPUT GPIO.2
HIGH GPIO.2
TRISIO = %00001011
OPTION_REG = %00001000;
WPU = 00001011
CMCON = 7 ;
INTCON = %10000000 ; Set GIE - clear interrupt enable bit and flags.
IOCB = %00001011
low CAMPOW
LOW CAMSHUT
J = 0
i = 0
M = 0
K = 0
L = 0
N = 0
O = 0
P = 0
PAUSE 20000
low GPIO.2
PAUSE 500
HIGH GPIO.2
GOTO BASE
MYINT:
GPIO0NEW = GPIO.0
GPIO1NEW = GPIO.1
GPIO3NEW = GPIO.3
INTCON = %10000000 ; Set GIE - clear interrupt enable bit and flags.
IF GPIO0NEW <> GPIOOOLD THEN
Q = 1
GOTO CAM
ENDIF
IF GPIO1NEW <> GPIO1OLD THEN
L=1
M = 1 + M
IF M > 3 THEN
M = 1
ENDIF
FOR i = 1 TO M
LOW GPIO.2
PAUSE 200
HIGH GPIO.2
PAUSE 200
NEXT I
GPIO1OLD = GPIO.1
GPIO3OLD = GPIO.3
GPIOOOLD = GPIO.0
RESUME BASE
ENDIF
IF GPIO3NEW <> GPIO3OLD THEN
j = 1
IF M = 1 THEN
GOTO DELAYS
ENDIF
IF M = 2 THEN
GOTO DNB
ENDIF
IF M = 3 THEN
GOTO CMODE
ENDIF
ENDIF
DELAYS:
K = K + 1
IF K = 6 THEN
K = 1
ENDIF
FOR i = 1 TO K
LOW GPIO.2
PAUSE 500
HIGH GPIO.2
PAUSE 500
NEXT I
IF K = 1 THEN
N = 1
ENDIF
IF K = 2 THEN
N = 25
ENDIF
IF K = 3 THEN
N = 51
ENDIF
IF K = 4 THEN
N = 257
ENDIF
IF K = 5 THEN
N = 1029
ENDIF
GPIO3OLD = GPIO.3
GPIO1OLD = GPIO.1
GPIOOOLD = GPIO.0
RESUME BASE
DNB:
K = K + 1
IF K > 3 THEN
K = 1
ENDIF
FOR i = 1 TO K
LOW GPIO.2
PAUSE 500
HIGH GPIO.2
PAUSE 500
NEXT I
O = K
GPIO3OLD = GPIO.3
GPIO1OLD = GPIO.1
GPIOOOLD = GPIO.0
RESUME BASE
CMODE:
K = K + 1
IF K > 3 THEN
K = 1
ENDIF
FOR i = 1 TO K
LOW GPIO.2
PAUSE 500
HIGH GPIO.2
PAUSE 500
NEXT I
P = K
GPIO3OLD = GPIO.3
GPIO1OLD = GPIO.1
GPIOOOLD = GPIO.0
RESUME BASE
CAM:
INPUT GPIO.2
WPU = 00001111
IF O = 2 AND GPIO.2 = 1 THEN
OUTPUT GPIO.2
WPU = 00001011
GPIO3OLD = GPIO.3
GPIO1OLD = GPIO.1
GPIOOOLD = GPIO.0
RESUME BASE
ENDIF
IF O = 3 AND GPIO.2 = 0 THEN
OUTPUT GPIO.2
WPU = 00001011
GPIO3OLD = GPIO.3
GPIO1OLD = GPIO.1
GPIOOOLD = GPIO.0
RESUME BASE
ENDIF
OUTPUT GPIO.2
WPU = 00001011
IF P = 1 THEN
GOTO SCAMR
ENDIF
IF P = 2 THEN
GOTO DPM
ENDIF
IF P = 3 THEN
GOTO MOVMODE
ENDIF
SCAMR:
HIGH CAMPOW 'PRESS POWER
PAUSE 500 'HOLD POWER FOR 500 MILLISECOND
LOW CAMPOW 'RELEASE POWER
pause 2200
HIGH CAMSHUT 'PRESS SHUTTER FOR 2 SECOND
PAUSE 3000
LOW CAMSHUT 'RELEASE SHUTTER
PAUSE 8000 'ALLOW 8 MORE SECONDS TO SAVE AND TURN CAMERA OFF
HIGH CAMPOW 'TURN CAMERA OFF
PAUSE 500
LOW CAMPOW
GPIOOOLD = GPIO.0
GPIO3OLD = GPIO.3
GPIO1OLD = GPIO.1
RESUME BASE
;
DPM:
HIGH CAMPOW 'PRESS POWER
PAUSE 500 'HOLD POWER FOR 500 MILLISECOND
LOW CAMPOW 'RELEASE POWER
pause 2200
HIGH CAMSHUT 'PRESS SHUTTER FOR 2 SECOND
PAUSE 3000
LOW CAMSHUT 'RELEASE SHUTTER
PAUSE 6000 'ALLOW 8 MORE SECONDS TO SAVE AND TURN CAMERA OFF
HIGH CAMSHUT 'TURN CAMERA OFF
PAUSE 500
LOW CAMSHUT
PAUSE 8000 'ALLOW 8 MORE SECONDS TO SAVE AND TURN CAMERA OFF
HIGH CAMPOW 'TURN CAMERA OFF
PAUSE 500
LOW CAMPOW
GPIOOOLD = GPIO.0
GPIO3OLD = GPIO.3
GPIO1OLD = GPIO.1
RESUME BASE
;
MOVMODE:
HIGH CAMPOW 'PRESS POWER
PAUSE 500 'HOLD POWER FOR 500 MILLISECOND
LOW CAMPOW 'RELEASE POWER
pause 2200
HIGH CAMSHUT 'PRESS SHUTTER FOR 2 SECOND
PAUSE 3000
LOW CAMSHUT 'RELEASE SHUTTER
PAUSE 17000 'ALLOW 8 MORE SECONDS TO SAVE AND TURN CAMERA OFF
HIGH CAMSHUT 'TURN CAMERA OFF
PAUSE 500
LOW CAMSHUT
PAUSE 8000 'ALLOW 8 MORE SECONDS TO SAVE AND TURN CAMERA OFF
HIGH CAMPOW 'TURN CAMERA OFF
PAUSE 500
LOW CAMPOW
GPIOOOLD = GPIO.0
GPIO3OLD = GPIO.3
GPIO1OLD = GPIO.1
RESUME BASE
;
REFRESH:
HIGH CAMPOW 'PRESS POWER
PAUSE 500 'HOLD POWER FOR 500 MILLISECOND
LOW CAMPOW 'RELEASE POWER
PAUSE 5000
HIGH CAMPOW 'PRESS POWER
PAUSE 500 'HOLD POWER FOR 500 MILLISECOND
LOW CAMPOW 'RELEASE POWER
GOTO LOOP
BASE:
IF J = 1 THEN
WRITE 1,K
WRITE 3,N
WRITE 4,O
WRITE 5,P
ENDIF
IF L = 1 THEN
WRITE 2,M
ENDIF
J = 0
L = 0
READ 1,K
READ 2,M
READ 3,N
READ 4,O
READ 5,P
INTCON = %10001000 ; Set/re-set interrupt enable bit - clear flags
ON INTERRUPT GOTO MYINT
IF Q = 1 THEN
GOTO DSLEEP
ENDIF
LOOP:
SLEEP 3088
GOTO REFRESH
GOTO LOOP
DSLEEP:
IOCB = %00001010
SLEEP N
IOCB = %00001011
Q = 0
GOTO LOOP

BGreen
- 24th May 2007, 03:26
Never mind, I evidently was losing my hair from head up the butt disease.

skimask
- 24th May 2007, 03:34
LOOP:
SLEEP 3088
GOTO REFRESH
GOTO LOOP
DSLEEP:
IOCB = %00001010
SLEEP N
IOCB = %00001011
Q = 0
GOTO LOOP

You realize that the program will never get to that 2nd 'GOTO LOOP' right?

BGreen
- 24th May 2007, 03:41
If Q = 1 it does. I had rechecked resumes til I was blue in the face. I had left out an obvious one. Thanks for the input Skimask

skimask
- 24th May 2007, 03:50
If Q = 1 it does. I had rechecked resumes til I was blue in the face. I had left out an obvious one. Thanks for the input Skimask

Let me try that again...

LOOP:
SLEEP 3088
GOTO REFRESH
GOTO LOOP
DSLEEP:
IOCB = %00001010
SLEEP N
IOCB = %00001011
Q = 0
GOTO LOOP

I didn't mean the 2nd GOTO LOOP, I meant the 1st one.
GOTO REFRESH goes to REFRESH:
The GOTO LOOP after GOTO REFRESH will never get executed.

BGreen
- 24th May 2007, 04:11
You are right. That command will never be executed. Actually it was redundant and a waste of code space. Thanks.

skimask
- 24th May 2007, 05:09
You are right. That command will never be executed. Actually it was redundant and a waste of code space. Thanks.

So, did you fix the problem or what?

BGreen
- 24th May 2007, 11:18
My problem was fixed when I pulled my head out of my butt.

Archilochus
- 25th May 2007, 15:35
My problem was fixed when I pulled my head out of my butt.

LOL - That's how most of my problems get fixed too! :-()

Arch