Another 12F629 Rookie problem


Closed Thread
Results 1 to 10 of 10
  1. #1
    Join Date
    Oct 2004
    Location
    Fayetteville Arkansas
    Posts
    44

    Default Another 12F629 Rookie problem

    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
    Last edited by BGreen; - 12th November 2004 at 03:25.

  2. #2
    Join Date
    Oct 2004
    Location
    Fayetteville Arkansas
    Posts
    44


    Did you find this post helpful? Yes | No

    Default

    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

  3. #3
    Join Date
    May 2004
    Location
    New England
    Posts
    164


    Did you find this post helpful? Yes | No

    Default

    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

  4. #4
    Join Date
    Oct 2004
    Location
    Fayetteville Arkansas
    Posts
    44


    Did you find this post helpful? Yes | No

    Default

    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.

  5. #5
    Join Date
    May 2004
    Location
    New England
    Posts
    164


    Did you find this post helpful? Yes | No

    Default

    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

  6. #6
    Join Date
    Oct 2004
    Location
    Fayetteville Arkansas
    Posts
    44


    Did you find this post helpful? Yes | No

    Default

    Thanks again Arch. I'll see what I can do with this now.

  7. #7
    Join Date
    Oct 2004
    Location
    Fayetteville Arkansas
    Posts
    44


    Did you find this post helpful? Yes | No

    Default

    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

  8. #8
    Join Date
    May 2004
    Location
    New England
    Posts
    164


    Did you find this post helpful? Yes | No

    Default

    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

  9. #9
    Join Date
    Oct 2004
    Location
    Fayetteville Arkansas
    Posts
    44


    Did you find this post helpful? Yes | No

    Default

    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

  10. #10
    ratsnest's Avatar
    ratsnest Guest


    Did you find this post helpful? Yes | No

    Talking

    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.
    Last edited by ratsnest; - 22nd November 2004 at 07:27.

Similar Threads

  1. Problem with 12F629, servo and EEPROM
    By Atom058 in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 1st March 2008, 09:53
  2. USART Problem , but don't know where, in pc? or in PIC?
    By precision in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 15th July 2007, 08:12
  3. wierd problem with 12f629 Need Help Despretly
    By Nadeem in forum Off Topic
    Replies: 1
    Last Post: - 15th June 2005, 20:59
  4. Weird problem with 12F629
    By martarse in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 28th May 2005, 07:15
  5. Problem Pic 12f629
    By diegover in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 19th July 2004, 11:51

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts