• AVR Freaks

Hot!Using Interrupt Flags as Event Latches without Interrupt Enable/Firing

Author
acharnley
Super Member
  • Total Posts : 610
  • Reward points : 0
  • Joined: 2016/05/01 06:51:28
  • Location: 0
  • Status: offline
2020/01/19 07:04:20 (permalink)
0

Using Interrupt Flags as Event Latches without Interrupt Enable/Firing

I have a CLC working autonomously and a "task" timer working at 1Hz. The timer code needs to check whether a falling edge of the CLC has occurred at some point.

The CLC has a falling edge interrupt trigger. Some peripherals will set the interrupt flag even when disabled, others seem to set it only when the interrupt enable bit is set. Is there a universal handling?

My intention is to set the CLC to have the falling edge interrupt enable bit set, but keep the interrupt enable bit disabled. If the flag is still set I can use and clear that in the timer code. Alternatively I can enable the CLC interrupt and in that code disable the interrupt enable bit while not clearing the interrupt flag bit.

Attached Image(s)

#1

8 Replies Related Threads

    Mysil
    Super Member
    • Total Posts : 3706
    • Reward points : 0
    • Joined: 2012/07/01 04:19:50
    • Location: Norway
    • Status: offline
    Re: Using Interrupt Flags as Event Latches without Interrupt Enable/Firing 2020/01/19 08:15:58 (permalink)
    +1 (1)
    Hi,
    Do Not make this difficult for yourself.
    Do not construct problems that do not exist.
     
    Interrupt Flag bits, like CLCxIF,
    Do Not depend upon Interrupt Enable bit, like CLXxIE.
     
    Interrupt Flag bit  CLCxIF  belong to the CLC peripheral,
    and is set by the peripheral when conditions are right, independent of CLCxIE.
     
    Interrupt Enable bits,  CLCxIE  belong to the Interrupt controller hardware,
    and determine if interrupt controller shall react to the Interrupt Flag.
    Only when corresponding ...IF bit and ...IE bit are both 1, and GIE and PEIE are also both 1,
    will a interrupt be processed.
     
    You should have learned  a long time ago, that you may poll Interrupt Flag bits in software,
    when Interrupt Enable is Clear == 0.
     
    Be aware, that for some peripherals, Interrupt Flag bits go back to 0 == Clear,
    when the condition causing interrupt request is no longer there.
     
        Mysil
    #2
    mpgmike
    Super Member
    • Total Posts : 473
    • Reward points : 0
    • Joined: 2014/01/23 17:27:06
    • Location: NJ
    • Status: offline
    Re: Using Interrupt Flags as Event Latches without Interrupt Enable/Firing 2020/01/19 09:47:46 (permalink)
    0
    It might be possible to use the OUT bit for the target SFR instead of the IF.  Newer PICs allow you to choose triggers.

    I don't need the world to know my name, but I want to live a life so all my great-grandchildren proudly remember me.
    #3
    jtemples
    عُضْوٌ جَدِيد
    • Total Posts : 11982
    • Reward points : 0
    • Joined: 2004/02/13 12:31:19
    • Location: Southern California
    • Status: offline
    Re: Using Interrupt Flags as Event Latches without Interrupt Enable/Firing 2020/01/19 11:08:12 (permalink)
    +1 (1)
    others seem to set it only when the interrupt enable bit is set.

     
    Which one have you observed this behavior with?
    #4
    NorthGuy
    Super Member
    • Total Posts : 6289
    • Reward points : 0
    • Joined: 2014/02/23 14:23:23
    • Location: Northern Canada
    • Status: offline
    Re: Using Interrupt Flags as Event Latches without Interrupt Enable/Firing 2020/01/19 14:15:16 (permalink)
    0
    jtemples
    others seem to set it only when the interrupt enable bit is set.

    Which one have you observed this behavior with?



    It is relatively common for the peripheral module to have bits which control interrupts. You can use these settings to control whether the IF flag is set or not, and perhaps specify the exact conditions when the IF flag is set.
     
    For example CLC modules on many PIC16 have LCxINTP and LCxINTN bits which control whether the IF bit is set for rising and falling edges respectively. Setting both these bits to 0 will effectively disable interrupts because the IF flag never gets set.
     
    Going back to the OP's question, you should set at least one of the LCxINTx bits, but you shouldn't set the IE bit. Then you'll get the IF flag working, but the interrupts will be disabled.
    #5
    ric
    Super Member
    • Total Posts : 28368
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: Using Interrupt Flags as Event Latches without Interrupt Enable/Firing 2020/01/19 15:45:24 (permalink)
    +1 (1)
    I guess there is some ambiguity here about what "interrupt enable bit" meant.
    Many would have assumed it meant the matching xxIE bit.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #6
    jtemples
    عُضْوٌ جَدِيد
    • Total Posts : 11982
    • Reward points : 0
    • Joined: 2004/02/13 12:31:19
    • Location: Southern California
    • Status: offline
    Re: Using Interrupt Flags as Event Latches without Interrupt Enable/Firing 2020/01/19 16:10:45 (permalink)
    0
    ric
    I guess there is some ambiguity here about what "interrupt enable bit" meant. Many would have assumed it meant the matching xxIE bit.

     
    Yes, the OP specifically said "interrupt enable bit", not "interrupt polarity bit".
    #7
    acharnley
    Super Member
    • Total Posts : 610
    • Reward points : 0
    • Joined: 2016/05/01 06:51:28
    • Location: 0
    • Status: offline
    Re: Using Interrupt Flags as Event Latches without Interrupt Enable/Firing 2020/01/19 16:46:09 (permalink)
    0
    Thanks all, that confirms my expected behaviour for interrupt flag bits.
    #8
    NorthGuy
    Super Member
    • Total Posts : 6289
    • Reward points : 0
    • Joined: 2014/02/23 14:23:23
    • Location: Northern Canada
    • Status: offline
    Re: Using Interrupt Flags as Event Latches without Interrupt Enable/Firing 2020/01/19 16:59:26 (permalink)
    0
    jtemples
    ric
    I guess there is some ambiguity here about what "interrupt enable bit" meant. Many would have assumed it meant the matching xxIE bit.

     
    Yes, the OP specifically said "interrupt enable bit", not "interrupt polarity bit".



    The OP used the term "interrupt enable bit" in both senses in the same sentence:
     
    acharnley
    My intention is to set the CLC to have the falling edge interrupt enable bit set, but keep the interrupt enable bit disabled.



    Clearly, by "falling edge interrupt enable bit" he meant LCxINTN, while by "interrupt enable bit" he meant CCPxIE. So, he had the correct idea in the first place.
     
    Edit: The official name for LCxINTN is indeed "Configurable Logic Cell Negative Edge Going Interrupt Enable bit".
    post edited by NorthGuy - 2020/01/19 17:46:33
    #9
    Jump to:
    © 2020 APG vNext Commercial Version 4.5