PDA

View Full Version : Another 12F629 Rookie problem



BGreen
- 12th November 2004, 02:44
I'm using a base code that worked to run a camera with a switch, added some fuses and was attempting to use the sleep command and an interupt to bring it out of sleep and operate the camera. I wanted the pic to basically sleep until the interupt occured. using the sleep with no period I get an error when compiling. If I add a period of 0, it will compile but the program doesn't do anything at all now. I guess I need help again.

@ DEVICE pic12F629
@ DEVICE pic12F629, MCLR_OFF
@ DEVICE pic12F629, CPD_OFF
@ DEVICE pic12F629, BOD_OFF
@ DEVICE pic12F629, PWRT_ON
@ DEVICE pic12F629, PROTECT_OFF
SEN VAR GPIO.4
POW VAR GPIO.1
SHT VAR GPIO.2
LOW SEN
LOW POW
LOW SHT
INPUT SEN
OUTPUT POW
OUTPUT SHT
BASE:
ON INTERRUPT GOTO LOOP
SLEEP
GOTO BASE
LOOP:
HIGH sht
PAUSE 100
HIGH pow
PAUSE 2000
LOW POW
PAUSE 4000
LOW SHT
PAUSE 6000
HIGH POW
PAUSE 1000
LOW POW
RESUME

BGreen
- 12th November 2004, 13:49
Read a Bunch more last nite and put an amp meter on my breadboard. Circuit draws around 700uA when button is pushed, then drops off to nearly 0. This is indicating to me that its not comming out of sleep. Refined the fuses a little and tried to add the GPIE commands to enable and disable change on pin interupts, but I get a syntax error. Anyone got any quips of wisdom?

@ 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
SEN VAR GPIO.4
POW VAR GPIO.1
SHT VAR GPIO.2
LOW SEN
LOW POW
LOW SHT
INPUT SEN
OUTPUT POW
OUTPUT SHT
BASE:
GPIE = 1
ON INTERRUPT GOTO LOOP
SLEEP 100
GPIE = 0
GOTO BASE
LOOP:
HIGH sht
PAUSE 100
HIGH pow
PAUSE 2000
LOW POW
PAUSE 4000
LOW SHT
PAUSE 6000
HIGH POW
PAUSE 1000
LOW POW
RESUME

Archilochus
- 12th November 2004, 17:38
Hi Butch,
Don't know all the names and such for the '629 - but along with the interrupt type you're using, you'll need the GIE bit set too. GPIE can be a bit tricky sometimes (check the data sheet) - I like the INTE (GPIO.2) interrupt (remember to set the edge triggering as needed).

Then you'll need to DISABLE the interrupts in "LOOP" - or use a dedicated interrupt handler - and maybe turn off the associated interrupt enable bit and clear the flag bit - INTCON = $80 (or something similar - device specific).

You'll also need to loop back to SLEEP 100 after the SLEEP 100 command - or your code will just contiue after waking up.

Arch

BGreen
- 12th November 2004, 17:49
Thanks Arch. I know once I've gotten a couple these done and understand the proceedure it will appear fairly simple, but been beating my head against a wall right now.

Archilochus
- 12th November 2004, 18:28
Hey Butch - wait till you get started with the assembly stuff - Arrggh!

Give this a try - it compiled for the '629, but I didn't program a chip to try 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.
; SENSOR (button) input on GPIO.2 - PULL PIN LOW to trigger
POW VAR GPIO.3
SHT VAR GPIO.4
;
; Set External interrupt (GPIO.2) with falling edge trigger...
OPTION_REG = %00001000 ; Enable pullups, falling edge trigger on GP.2, etc
CMCON = %00000111 ; Comparators OFF
INTCON = %10000000 ; Set GIE - clear interrupt enable bit and flags.
; The 'ANSEL' register should probably be set too -
; but I can't figure what to call it for the '629
; ANSEL = %00000000 ; Other Analog stuff OFF
;
; Using the 'LOW' or 'HIGH' command sets the pins to outputs
LOW POW : LOW SHT ; Set In/Out states.
;
GOTO BASE ; Skip past interrupt handler
;
; Interrrupt handler (maybe move shutter control elsewhere).
MYINT:
INTCON = %10000000 ; clear interrupt enable bit and flags
; Camera Shutter & Power control
HIGH sht : PAUSE 100 : HIGH pow : PAUSE 2000
LOW POW : PAUSE 4000 : LOW SHT : PAUSE 6000
HIGH POW : PAUSE 1000 : LOW POW
RESUME BASE ; resume at BASE section
;
; Whatever code needed added in here
;
BASE:
; Might blink an LED here just to know code started.
INTCON = %10010000 ; Set/re-set interrupt enable bit - clear flags
;
ON INTERRUPT GOTO MYINT
;
LOOP: ; Loop here until interrupted in low power SLEEP state
SLEEP 10
;
; Might blink an LED here to know loop is working.
;
; Do any 'housekeeping' here.
;
GOTO LOOP
;
END

BGreen
- 12th November 2004, 18:45
Thanks again Arch. I'll see what I can do with this now.

BGreen
- 13th November 2004, 02:02
Arch, I worked with what you posted as well as what I had, and came up with whats below. I was able to test and see what its doing, which is going to the "BASE" routine and looping thru the sleep command. However, I can push the pushbutton til the cows come home and the interupt is ignored. This thing is kicking my butt. Figure its something real simple and I'm too inexperienced to see it. HELP!!!!!!!!

@ 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.
SEN VAR GPIO.4 ; PIN 3 IS TRIGGER PIN WITH PUSHBUTTON TO INTERRUPT
POW VAR GPIO.1 ; PIN 6 OPERATES THE POWER TO THE CAMERA
SHT VAR GPIO.2 ; PIN 5 OPERATES THE SHUTTER ON THE CAMERA
LOW POW ; MAKE POW LOW AND AN OUTPUT
LOW SHT ; MAKE SHT LOW AND AN OUTPUT
INPUT SEN ; REDUDNANT AND UNNECESSARY
OUTPUT POW ; REDUDNANT AND UNNECESSARY
OUTPUT SHT ; REDUDNANT AND UNNECESSARY
OPTION_REG = %01001000 ; Enable pullups, rising edge trigger on GP.2, etc
CMCON = %00000111 ; Comparators OFF
GOTO BASE ; Skip past interrupt handler
;
;
MYINT:
INTCON = %10000000 ; clear interrupt enable bit and flags
; Camera Shutter & Power control
HIGH sht : PAUSE 100 : HIGH pow : PAUSE 2000
LOW POW : PAUSE 4000 : LOW SHT : PAUSE 6000
HIGH POW : PAUSE 1000 : LOW POW
RESUME BASE ; resume at BASE section
;
;
BASE:
INTCON = %10010000 ; Set/re-set interrupt enable bit - clear flags
ON INTERRUPT GOTO MYINT
;
;
LOOP: ; Loop here until interrupted in low power SLEEP state
SLEEP 10
'HIGH POW - jUST USED FOR DIAGNOSTICS
'PAUSE 500 - jUST USED FOR DIAGNOSTICS
'LOW POW - jUST USED FOR DIAGNOSTICS
'PAUSE 3000 - jUST USED FOR DIAGNOSTICS
'HIGH POW - jUST USED FOR DIAGNOSTICS
'PAUSE 500 - jUST USED FOR DIAGNOSTICS
'LOW POW - jUST USED FOR DIAGNOSTICS
GOTO LOOP

Archilochus
- 13th November 2004, 14:54
Hi Butch,
The test code I posted above uses the 'external interrupt' on GPIO.2 (falling edge trigger with internal pullup resistor).

That's why I had re-assigned the pin variables as follows...

; Set Variables and aliases as needed.
; SENSOR (button) input on GPIO.2 - PULL PIN LOW to trigger
;
POW VAR GPIO.3
SHT VAR GPIO.4

It looks like you have changed it back to button trigger on GPIO.4 - which won't work with the code above.

To use the 'external interrupt' - you'll have to have your button on GPIO.2

Arch

BGreen
- 13th November 2004, 20:45
Arch, by now you ought to know how ignorant and hard headed I can get. Didn't catch the interupt had to be on GPIO.2. Well, what little hair I had left is thinner now, but it works. Thanks for the help.

Butch

ratsnest
- 22nd November 2004, 07:25
programming is is half the fun of trail camera building.
I noticed on you 1st post you did what I did the 1st time I use the sleep command
you got to turn on the WDT.