12F629 Strange interupt behavior


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

    Default 12F629 Strange interupt behavior

    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

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


    Did you find this post helpful? Yes | No

    Default

    Never mind, I evidently was losing my hair from head up the butt disease.

  3. #3
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by BGreen View Post
    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?

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


    Did you find this post helpful? Yes | No

    Default

    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

  5. #5
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by BGreen View Post
    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.

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


    Did you find this post helpful? Yes | No

    Default

    You are right. That command will never be executed. Actually it was redundant and a waste of code space. Thanks.

  7. #7
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by BGreen View Post
    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?

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


    Did you find this post helpful? Yes | No

    Default

    My problem was fixed when I pulled my head out of my butt.

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


    Did you find this post helpful? Yes | No

    Default

    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
    "Data sheets? I ain't got no data sheets. I don't need no data sheets. I don't have to read any stinking data sheets!"

Similar Threads

  1. Help! My 'interupt', erhm ...only interupts the one time?!!!
    By HankMcSpank in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 2nd November 2009, 12:49
  2. Strange LCD Behavior
    By chips123 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 1st November 2009, 00:48
  3. Strange behavior - PORTG.2, 18F8720
    By Charles Linquis in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 11th January 2009, 23:30
  4. Strange electrical behavior with PIC16F684
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 28th March 2008, 06:58
  5. Strange PortA behavior on 18F PIC
    By Terry in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 17th August 2007, 22:31

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