too many interrupts


Closed Thread
Results 1 to 6 of 6
  1. #1
    trying's Avatar
    trying Guest

    Default too many interrupts

    In the code below the mode button is working
    but after you select which mode and it gets to the
    "on interrupt" it does not stop and wait for a interrupt
    if I take out the "on interrupt" and replace it with "if sensor =0"
    it seams to work ok. So I'm thinking it is seeing another interrupt.
    In the finished program the only interrupt I need to use is portA.2
    how do I turn all OTHER interrupts off? Or do you see another problem
    thanks
    trying to learn

    @ DEVICE pic16f630
    @ DEVICE pic16f630, INTRC_OSC_NOCLKOUT
    @ DEVICE pic16f630, WDT_ON
    @ DEVICE pic16f630, MCLR_OFF
    @ DEVICE pic16f630, CPD_OFF 'MODE TEST
    @ DEVICE pic16f630, BOD_OFF 'BOARD TEST
    @ DEVICE pic16f630, PWRT_ON
    @ DEVICE pic16f630, PROTECT_OFF
    DEFINE OSC 4
    Pause 10000 ' Allow pic to Stabilize

    CMCON = 7 'COMPARATOR OFF
    VRCON = 0 'VOLTAGE REF. DISABLE
    TRISA = %00011100 'MAKE A.2, A.3, A.4 INPUTS
    TRISC = %00000000 'MAKE ALL PORTC OUTPUTS

    OPTION_REG = 0 'ENABLE WEEK PULLUPS (CLEAR RAPU)
    WPUA = %00111111 'WEAK PULLUPS ON PORTA
    INTCON=$80
    IOCA=0



    SYMBOL SENSOR = PORTA.2 'TRIGGERING DEVICE PIN 3
    SYMBOL MODE= PORTA.4 'MODE BUTTON (FLASH/LONG) PIN 12 INPUT
    SYMBOL LED = PORTA.5 'LED POWER UP PIN 2 OUTPUT
    SYMBOL RED= PORTC.3 'RED LED PIN 7 OUTPUT
    SYMBOL GREEN = PORTC.4 'GREEN LED PIN 6 OUTPUT




    MODE=0
    SENSOR=0
    LED=0
    RED=0


    LED=1
    Pause 4000 'POWER UP OK
    LED=0

    IF MODE =1 Then GoTo LONG
    GoTo SHORT

    SHORT:

    RED=1
    Pause 1000 'FLASH RED LED YOUR IN SHORT MODE
    RED= 0
    Pause 2000
    RED=1
    Pause 1000
    RED= 0
    Pause 3000




    MAIN
    OPTION_REG=$0
    INTCON.4=1 'ENABLE PORTA.2 INTERRUPT
    ON INTERRUPT GoTo FLASH
    INTCON=$90 'DISABLE ALL INTERRUPTS


    FLASH:


    LED=1
    Pause 1000 'FLASH RED & GREEN LED FOR TESTING FLASH MODE
    LED=0
    Pause 1000
    RED=1
    Pause 1000
    RED=0
    Pause 1000
    LED=1
    Pause 1000
    LED=0
    Pause 1000
    RED=1
    Pause 1000
    RED=0
    Pause 1000

    INTCON.4=0 'DISABLE A.2 INTERRUPT
    Disable
    Sleep 60
    GoTo MAIN

    Enable


    LONG:
    GREEN=1
    Pause 1000 'GREEN LED FLASH YOUR IN LONG MODE
    GREEN=0
    Pause 2000



    DOIT:
    OPTION_REG=$0
    INTCON.4=1 'ENABLE INTERRUPT A.2
    ON INTERRUPT GoTo GREENON
    INTCON=$80 'DISABLE ALL INTERRUPTS


    GREENON:
    GREEN=1 'GREEN ON AND LED FLASHING FOR
    LED=1 'LONG MODE TESTING
    Pause 7000
    LED=0
    Pause 1000
    LED=1
    Pause 7000
    LED=0
    GREEN=0
    INTCON.4=0 'DISABLE INTERRUPT A.2
    Disable
    Sleep 120
    GoTo DOIT

    Enable

  2. #2
    Join Date
    Oct 2004
    Location
    Hangover, Germany
    Posts
    289


    Did you find this post helpful? Yes | No

    Default

    I think you turn on and off the Interrupt-enable-bits in order to handle the waste off interrupts....

    Just enable an interrupt,
    clear the interrupt-flag inside the Interrupt-service-routine,
    and wait inside your Main-Loop forever.

    And look into the PBP-help for such directives as DISABLE... !
    PBP 2.50C, MCS+ 3.0.0.5, MPLAB 8, MPASM 5.14, ASIX Presto, PoScope, mE mikroBasic V7.2, PICKIT2

  3. #3
    Join Date
    Feb 2005
    Location
    Kolkata-India
    Posts
    563


    Did you find this post helpful? Yes | No

    Default You should end your interrupt routine with a resume

    Hi,

    PBP handles interrupt in a rather lazy way. It traces an interrupt by polling the interrupt flags and when found flags it in software, clears the hardware flag and jumps to the on interrupt routine after it has fininshed the current execution.
    So you should :

    1. Place the on interrupt statement in top part of your code

    2. Always end it with a resume (otherwise it executes it forever)

    3. To temporarily disable interrupt, just clear the int sources, without turning off the global bit.

    Regards

    Sougata

  4. #4
    trying's Avatar
    trying Guest


    Did you find this post helpful? Yes | No

    Default

    thanks for the replys. Sorry but I did leave out the disable at the interrupt handlers when I posted. (long night). sougata would please show me more of what you mean. I'm just getting started at this.
    Thanks

  5. #5
    Join Date
    Feb 2005
    Location
    Kolkata-India
    Posts
    563


    Did you find this post helpful? Yes | No

    Default Do Not have much time

    Hi,

    I have hastily modified your code. It does a red blink normally , but when you pull down the mode pin it goes to the interrupt routine and does a green blink there. Hope this helps.

    Code:
    @ DEVICE pic16f630
    @ DEVICE pic16f630, INTRC_OSC_NOCLKOUT
    @ DEVICE pic16f630, WDT_ON
    @ DEVICE pic16f630, MCLR_OFF
    @ DEVICE pic16f630, CPD_OFF 'MODE TEST
    @ DEVICE pic16f630, BOD_OFF 'BOARD TEST
    @ DEVICE pic16f630, PWRT_ON
    @ DEVICE pic16f630, PROTECT_OFF
    '//////////////////////////////////////////////////////////////////
    DEFINE OSC 4             ' Tell PBP that the PIC is running @ 4MHz
    '//////////////////////////////////////////////////////////////////
    ON INTERRUPT GOTO INT_GREEN  ' DEFINE THE PBP INTERRUPT HANDLER HERE
    DISABLE                  ' DO NOT PROCESS THE INERRUPT CALLS NOW
    
    '//////////////////////////////////////////////////////////////////
    CMCON = 7                'COMPARATOR OFF
    VRCON = 0                'VOLTAGE REF. DISABLE 
    TRISA = %00011100        'MAKE A.2, A.3, A.4 INPUTS
    TRISC = %00000000        'MAKE ALL PORTC OUTPUTS
    '//////////////////////////////////////////////////////////////////
    
    'SETUP THE INTERRUPT PROPERTIES HERE********************************************
    '///////////////////////////////////////////////////////////////////////////////
    OPTION_REG = 0           'ENABLE WEAK PULLUPS (CLEAR RAPU), INTERRUPT ON FALLING EDGE
    IOCA       = 0           'DISABLE INTERRUPT ON CHANGE
    WPUA       = %00111111   'WEAK PULLUPS ON PORTA 
    INTCON     = 0           'LET INTERRUPTS BE-OFF AT THIS MOMENT
    '///////////////////////////////////////////////////////////////////////////////
    
    
    ' ALIAS-SYMBOL  DEFINITIONS GOES HERE //////////////////////////////////////////
    SYMBOL SENSOR = PORTA.2 'TRIGGERING DEVICE PIN 3
    SYMBOL MODE   = PORTA.4 'MODE BUTTON (FLASH/LONG) PIN 12 INPUT
    SYMBOL LED    = PORTA.5 'LED POWER UP PIN 2 OUTPUT
    SYMBOL RED    = PORTC.3 'RED LED PIN 7 OUTPUT
    SYMBOL GREEN  = PORTC.4 'GREEN LED PIN 6 OUTPUT
    ' END OF ALIAS-SYMBOL  DEFINITIONS  ////////////////////////////////////////////
    
    ' DEFINE VARIABLES HERE ////////////////////////////////////////////////////////
    I VAR BYTE                 ' TO BE USED IN FOR-NEXT LOOP
    ' DEFINE VARIABLES HERE ////////////////////////////////////////////////////////
    
    ' INITIALIZATION ROUTINE ///////////////////////////////////////////////////////
    LED   = 0                  ' TURN-OFF THE POWER LED
    RED   = 0                  ' TURN-OFF THE RED LED
    GREEN = 0                  ' TURN-OFF THE GREEN LED
    LED = 1                    ' TURN-ON THE POWER LED
    PAUSE 4000                 ' POWER UP OK
    LED = 0                    ' NOW TURN IT OFF
    ' END OF INITIALISATION ROUTINE ////////////////////////////////////////////////
    
    '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    INTCON = $90               ' SET UP THE GIE BITS AND RA2 INT BIT 
                               ' TO ENABLE INTERRUPT PROCESSING
    '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    
    ENABLE   ' INSTRUCT THE COMPILER TO PUT THE INTERRUPT HANDLING CALLS FROM NOW ON
    
    '////////////// THE MAIN ROUTINE THAT DOES SHORT RED FLASH /////////////////////
    MAIN: 
    RED = 1                    ' TURN-ON THE RED-LED
    I   = 0                    ' RESET THE VARIABLE (FOR-NEXT LOOP)
    
    FOR I = 1 TO 200           ' DO A PAUSE IN A LOOP 200 X 5 = 1000mS 
    PAUSE 5                    ' REDUCES INTERRUPT PROCESSING LATENCY BY PBP
    NEXT I
    
    RED = 0
    
    FOR I = 1 TO 200           ' DO A PAUSE IN A LOOP 200 X 5 = 1000mS 
    PAUSE 5                    ' REDUCES INTERRUPT PROCESSING LATENCY BY PBP
    NEXT I
    
    GOTO MAIN                  ' DO-IT FOR-EVER
    
    '///////////////////////////////////////////////////////////////////////////////
    
    
    DISABLE ' INSTRUCT THE COMPILER NOT TO PUT THE INTERRUPT HANDLING CALLS FROM NOW ON
    
    '/// THE ACTUAL INTERRUPT HANDLER IS RIGHT BELOW ///////////////////////////////
    INT_GREEN:
    INTCON = $80               ' CLEAR THE INTERRUPT FLAG BUT KEEP GLOBAL ENABLED
                               ' OTHERWISE PBP WILL RE-ENTER THIS ROUTINE
    LED   = 1                  ' ON-TILL IN THIS ROUTINE
    RED   = 0                  ' TURN-OFF THE RED LED IF IT WAS ON BY A PREVIOUS INSTANCE
    GREEN = 1                  ' TURN-ON THE GREEN TO SHOW THAT INSIDE THIS ROUTINE
    PAUSE 1000                 ' WAIT A SECOND
    
    GREEN = 0 : PAUSE 1000     ' TURN-OFF AND WAIT
    GREEN = 1 : PAUSE 1000     ' TURN-ON AND WAIT
    GREEN = 0 : PAUSE 1000     ' TURN-OFF AND WAIT
    GREEN = 1 : PAUSE 1000     ' TURN-ON AND WAIT
    GREEN = 0 : PAUSE 1000     ' TURN-OFF AND WAIT
    
    LED = 0                    ' GREEN-BLINK DONE NOW TIME TO QUIT
    INTCON = $90               ' TURN-ON THE RA2 INTERRUPT BIT  FOR FURTHER PROCESSING
    RESUME                     ' GO BACK TO WHAT IT WAS DOING
    ENABLE
    BTW I commented out the device command as I use MPASM and it compiled okay. Hope this helps.

    Copy the code and paste it in MICROCODE STUDIO for better readability.

    Regards

    Sougata

  6. #6
    trying's Avatar
    trying Guest


    Did you find this post helpful? Yes | No

    Default thanks

    thanks sougata it compiled with cdlite. but I have not had time to play with it.
    But it has helped me understand a few things better. I'm learning 1 project at time thanks again

Similar Threads

  1. Instant Interrupts - Revisited
    By Darrel Taylor in forum Code Examples
    Replies: 772
    Last Post: - 17th February 2016, 22:14
  2. Clock using Instant Interrupts
    By PICpocket in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 16th February 2009, 21:43
  3. Microcode studio - PIC16F877A Interrupts
    By mcbeasleyjr in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 8th January 2009, 06:10
  4. DT's Instant Interrupts trouble
    By Tomexx in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 24th November 2008, 20:48
  5. help: TMR0 interrupts disabling PORTAchange interrupts???
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 19th August 2008, 15:10

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