Where to place DISABLE/ENABLE INTERRUPT


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2009
    Location
    Utah, USA
    Posts
    427

    Default Where to place DISABLE/ENABLE INTERRUPT

    Hey Group,

    I am writing some code that depends on interrupts for keeping time.
    I am a bit confused in understanding where and how often I need to place the ENABLE and DISABLE INTERRUPT directive.

    So if I have, say, several subroutines in my code and want to have INTERRUPTS ENABLED in each and all of them (or most of them) then do I need to place an ENABLE / DISABLE before and after each of the subroutines even if they are placed in my code IDE one after another? Or do I just need to ENABLE the whole block of subroutines? and then place a DISABLE at the end of the block?

    for example...
    Code:
    ENABLE INTERRUPT
    
    Sub1:
    do some stuff
    RETURN
    '===========
    Sub2:
    do some other stuff
    RETURN
    
    DISABLE INTERRUPT

    or do I need to do this...
    Code:
    ENABLE INTERRUPT
    
    Sub1:
    do some stuff
    RETURN
    
    DISABLE INTERRUPT
    '===========
    ENABLE INTERRUPT
    
    Sub2:
    do some other stuff
    RETURN
    
    DISABLE INTERRUPT
    thanks in advance
    Dwight
    These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,517


    Did you find this post helpful? Yes | No

    Default Re: Where to place DISABLE/ENABLE INTERRUPT

    Hi,
    The ENABLE/DISABLE INTERRUPT are commands or directives for the actual compiler, they're not commands that gets exectuted when the PIC executes your code so it doesn't matter if there's a RETURN before the DISABLE INTERRUPT. Both of your example will produce the same result and the same code, there's no difference as far as I'm aware.

    /Henrik.

  3. #3
    Join Date
    Oct 2009
    Location
    Utah, USA
    Posts
    427


    Did you find this post helpful? Yes | No

    Default Re: Where to place DISABLE/ENABLE INTERRUPT

    Thanks Henrik,

    I knew that ENABLE/DISABLE were compiler directives but the PBP manual wasn't clear to me on whether each block of code needed the directive or if you could group several unrelated subroutines and then place the directive just once at the beginning and end of the block.

    Which leads me to ask is it necessary to have them in matched pairs?? I'm guessing not.
    That if you have a block of subroutines at the end of your code you could just place an ENABLE at the beginning of the block and assume that all the following code will have interrupts enabled.

    I guess it's time for me to dig into Darrel's INSTANT INTERRUPTS as I am seeing jitter in the timing of my interrupt service routine. I believe it is due to the interrupt not happening until the current statement finishes.

    I toggle a PortPin in the ISR and look at it on an o-scope. Based on my settings for TIMER1 it should INT every 5 msecs but instead of the the square wave being fairly solid it wanders slightly.

    here is the code for my ISR handler...

    Code:
    '***************************************************
    '  interrupt service routine
    '      H & L size determine INT timing
    '      INT should happen every .005 seconds
    '***************************************************
    disable interrupt
    MyInt:
        IntFlag=1             ' INT has fired so set this flag for Main code usage
        TMR1H = $FB       ' reset timer1h  
        TMR1L = $27        ' reset timer1l  
            
        toggle PortA.0      ' used for determining INT timing  
        PIR1.0 = 0           ' clear timer1 overflow flag 
    resume                   'to Main
    enable interrupt
    '=============================================================
    Last edited by Heckler; - 20th February 2016 at 00:25.
    Dwight
    These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.

  4. #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,517


    Did you find this post helpful? Yes | No

    Default Re: Where to place DISABLE/ENABLE INTERRUPT

    Hi Dwight,
    If you don't want to DISABLE the interrupt then you don't insert the DISABLE directive hence they does not need to be in matched pairs. You place the ENABLE directive prior to any code where you want the interrupt flag to be polled between statements and you place the DISABLE before any block of code where you don't want the flag to be polled. Since it's not a runtime command it doesn't matter if it's subroutines or whatnot.

    You won't regret Learning how to use DT-INTS. It's more complicated than ON INTERRUPT but much more powerful.

    /Henrik.

Similar Threads

  1. Disable/Enable DT interrupt
    By aratti in forum PBP3
    Replies: 10
    Last Post: - 16th June 2018, 17:50
  2. Disable/Enable in Interrupts
    By Ioannis in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 15th June 2015, 08:47
  3. PIC 16F616 Interrupt Enable/Disable?
    By Tobias in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 17th May 2009, 09:17
  4. Enable and Disable in Interrupts
    By stevecrunch in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 30th October 2007, 02:10
  5. Is there any place for a new section???
    By mister_e in forum Forum Requests
    Replies: 7
    Last Post: - 27th January 2005, 19:08

Members who have read this thread : 2

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