Program returns to beginning at interupt


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

    Default Program returns to beginning at interupt

    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

  2. #2
    Join Date
    Feb 2004
    Location
    Michigan, USA
    Posts
    305


    Did you find this post helpful? Yes | No

    Default

    It would be helpful if you could post the rest of your code. We might then be able to diagnose the problem.

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


    Did you find this post helpful? Yes | No

    Default

    Thanks, I did in an edit. something screwed up the original post. You may have to refresh.

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


    Did you find this post helpful? Yes | No

    Default

    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.

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


    Did you find this post helpful? Yes | No

    Default

    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

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


    Did you find this post helpful? Yes | No

    Default

    Arch, thanks for the reply. I ended up redefining a few things and moving a couple of things around and got it to work.

Similar Threads

  1. Presetting Configuration Fuses (PIC Defines) into your Program
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 82
    Last Post: - 15th December 2013, 10:54
  2. Help! My 'interupt', erhm ...only interupts the one time?!!!
    By HankMcSpank in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 2nd November 2009, 13:49
  3. Replies: 1
    Last Post: - 23rd May 2009, 10:22
  4. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 09:26
  5. PIC16F684 Program question
    By Nicholas in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 28th December 2006, 15:30

Members who have read this thread : 1

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