calling subroutine triggers interrupt


Closed Thread
Results 1 to 8 of 8

Hybrid View

  1. #1
    Join Date
    Dec 2009
    Location
    Canada
    Posts
    68


    Did you find this post helpful? Yes | No

    Default Re: calling subroutine triggers interrupt

    Hi Mister_E,

    Unfortunately this does not help. I removed all irrelevant code from the program to make it more clear, sorry for not doing this before. The code I have now for test is below. When it starts, calling empty Test subroutine always triggers interrupt so the GREENLED is ON. If I disable the GOSUB TEST, then it starts with GREENLED OFF (interrupt handler did not run)

    This is the first time I play with interrupt - most likely do something wrong. The MCU is PIC16F688

    @ DEVICE pic16F688, WDT_OFF, INTOSCIO, PWRT_ON, MCLR_ON, BOD_OFF

    define OSC 4
    clear
    '---------INTERRUPTS CONFIG-----------
    INTCON = %10000 'ENABLES RA2 (1,) OTHER INTERRUPTS ON PORTA ARE OFF (BIT 3)
    IOCA = %100 'ENABLES INTERRUPT ON PORTA.2
    ;---------VARIABLES----------------------

    BTN VAR PORTA.2
    YW VAR PORTC.2
    REDLED VAR PORTC.4
    GREENLED VAR PORTC.5
    N VAR BYTE


    '-----------PORTS CONFIGURATION------------
    OPTION_REG = 0
    ANSEL = %1000 'PORTA4/AN3 IS ANALOG
    TRISA = %111100 'SET PORT A FOR OUTPUTS ON PINS 0,1 (UNUSED) ALL OTHER INPUTS
    TRISC = %000010 'SET PORT C FOR INPUT ON PIN 1 (DIAG IN) ALL OTHER OUTPUTS
    'THE FOLLOWING DID NOT HELP
    N=PORTA 'JUST TO READ PORTA
    INTCON.0=0 'CLEAR INTERRUPT FLAG AFTER READING PORT (RAIF FLAG)
    INTCON.1=0 'CLEAR INTF FLAG FOR PORT RA2
    PORTC=0 'GREENLED SHOULD STAY OFF

    GOSUB TEST 'THIS SUBROUTINE ALWAYS CAUSES INTERRUPT!!!
    'NOW GREENLED ON PORT C5 IS ON !!!



    'THE FOLLOWING DID NOT HELP
    N = PORTA 'READ PORT A TO CLEAR MISMUTCH, NOTHING ELSE
    INTCON.0=0 'CLEAR INTERRUPT FLAG AFTER READING PORT
    INTCON.1=0

    ON INTERRUPT GOTO BTN_CHECK ' CHECK ON/OFF BUTTON

    START:
    GOTO START 'WAIT HERE TILL INTERRUPTED


    TEST: 'NO CODE IN THIS SUBROUTINE

    RETURN

    DISABLE
    BTN_CHECK:
    IF GREENLED = 0 THEN
    GREENLED = 1
    ELSE
    PORTC=0
    ENDIF
    '' PAUSE 1000 'ANTI VIBRATION
    N = PORTA 'READ PORT A TO CLEAR MISMUTCH, NOTHING ELSE
    INTCON.0=0 'CLEAR INTERRUPT FLAG AFTER READING PORT (RAIF FLAG)
    INTCON.1 = 0 'CLEAR INTF FLAG FOR PORT RA2
    RESUME
    ENABLE

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Re: calling subroutine triggers interrupt

    I think Steve meant to clear the flag before the GOSUB TEST, not before the ON INTERRUPT GOTO.

    It GOSUB's from an area that is DISABLEd to one that is ENABLED.
    If the flag is set, it will jump to the ISR.
    It may jump, even if it's not set.

    The ISR should verify that the flag is set before doing anything.
    Last edited by Darrel Taylor; - 19th May 2011 at 15:43.
    DT

  3. #3
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default Re: calling subroutine triggers interrupt

    Without INTCON.7 set before ON INTERRUPT, it's going to jump to your interrupt vector all the time in any code section where interrupt code is inserted. If you just set INTCON.7 it should never jump there until the hardware interrupt clears INTCON.7 automatically.

    INTCON = %10000 doesn't set INTCON.7 - so the ON INTERRUPT code inserted always assumes an interrupt condition exists.
    Last edited by Bruce; - 19th May 2011 at 19:28.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  4. #4
    Join Date
    Dec 2009
    Location
    Canada
    Posts
    68


    Did you find this post helpful? Yes | No

    Smile Re: calling subroutine triggers interrupt

    Darrel, Bruce,

    Thank you!

    I tried to move "On interrupt goto" to the very top and also check flag in the interrupt handler, either one works just fine.

    Will play with INTCON.7 tomorrow morning.

    Thanks again, the problem seems to be solved

    Alexey

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