• AVR Freaks

Hot!PIC12F1572 External Interrupt constant firing

Author
momiccioli
New Member
  • Total Posts : 12
  • Reward points : 0
  • Joined: 2019/07/18 06:05:48
  • Location: 0
  • Status: offline
2019/07/21 11:33:23 (permalink)
0

PIC12F1572 External Interrupt constant firing

Hello,
 
I am trying to configure an external interrupt to trigger on change.  The Interrupt is firing constantly and I believe that it is because of voltage fluctuation.  I have tried adding a smoothing capacitor but I am not having any success.  According to my Oscilloscope the fluctuation is minimal.  I have this working fine via CPU hogging but want to be a bit more elegant.
Is there a way to address the tolerance of the change in voltage before it's considered Rising/Dropping?  This is for triggering when a switch is opened or closed.
 
Thanks.
 
I am using MPLABX 5.2 XC8 2.05
 
The switch is a hall sensor via a transistor to provide the on/off voltage tied to RA2.  Or is there a better approach to managing this?
#1

6 Replies Related Threads

    ric
    Super Member
    • Total Posts : 24639
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: PIC12F1572 External Interrupt constant firing 2019/07/22 13:43:47 (permalink)
    0
    What is the maximum toggle rate you need to detect?
    If it's not too fast, polling inside a timer interrupt could be a better way to go.
     
    Otherwise, and RC filter may help (capacitor AND resistor) for filtering glitches.
    What extremes is the voltage reaching? It must get below 20% Vdd for a low and 80% Vdd for a high on most pins.

    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!
    #2
    momiccioli
    New Member
    • Total Posts : 12
    • Reward points : 0
    • Joined: 2019/07/18 06:05:48
    • Location: 0
    • Status: offline
    Re: PIC12F1572 External Interrupt constant firing 2019/07/23 05:27:15 (permalink)
    0
    The toggle rate is very low, the switch will be acting as an end stop so a timer is not necessary.  It is good to know that there is an identifiable range to trigger the interrupt.  I think I had another interrupt firing at the same time. I made sure there were no other timers etc running and things have improved.  Since I need an on change event it's not clear that I can determine if the event was a falling or increasing event.  Is there a way the documentation is not clear.
     
    Thanks.
    #3
    ric
    Super Member
    • Total Posts : 24639
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: PIC12F1572 External Interrupt constant firing 2019/07/23 05:59:01 (permalink)
    +1 (1)
    momiccioli
    The toggle rate is very low, the switch will be acting as an end stop so a timer is not necessary.

    If it's slow, then polling it in a timer interrupt is by far the EASIEST way to do this.
     

    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!
    #4
    momiccioli
    New Member
    • Total Posts : 12
    • Reward points : 0
    • Joined: 2019/07/18 06:05:48
    • Location: 0
    • Status: offline
    Re: PIC12F1572 External Interrupt constant firing 2019/07/23 07:51:00 (permalink)
    0
    You are correct and it's better to do it via a Timer too.  Here is why;
     
    In this case the circuit is very simple when the switch is triggered, turn an LED on or off.  The user can decide by means of a jumper.  If the jumper is switched the user will need to reset the circuit.  Otherwise the LED will not reflect the correct state (based on jumper setting) until a reset or the next time the switch triggers an interrupt.  Although not a huge deal not ideal for smooth operation.
     
    This problem goes away if a timer is used since the Timer check will constantly be setting the LED to the correct state based on the (jumper setting).  When the switch is hit the LED will be changed.
     
    Since this circuit is simple and all that has to be done is flip an LED and a few other very simple commands (all to be done at the same time) do I even need an interrupt at all?  Why not just use the main loop and skip the timer all together?  Is there a down side to that?  The chip will be set to 4 Mhz so there are no concerns of delay if the switch is pressed while it's in mid loop.
     
    Thanks
    #5
    pcbbc
    Super Member
    • Total Posts : 1388
    • Reward points : 0
    • Joined: 2014/03/27 07:04:41
    • Location: 0
    • Status: offline
    Re: PIC12F1572 External Interrupt constant firing 2019/07/23 10:45:47 (permalink)
    +1 (1)
    momiccioliWhy not just use the main loop and skip the timer all together?  Is there a down side to that?

    Because the main loop may not execute freqently enough to meet your timing requirements for detecting the external event.  However, if it does, then fair enough.
     
    But some main loops may have inner loops (for example waiting for a key press).  In that case it is necessary to pepper the code with calls or duplicate code to do the background processing inside ever inner loop.  That can get ugly very quickly, and there's always the posibility you miss one.
     
    In these scenarios it may be better to use a timer interrupt to perform regular background processing.  Most reasonably complex designs will already be using a timer which can be dual porposed.  So it is not really adding any complexity or overhead.
    #6
    NorthGuy
    Super Member
    • Total Posts : 5817
    • Reward points : 0
    • Joined: 2014/02/23 14:23:23
    • Location: Northern Canada
    • Status: offline
    Re: PIC12F1572 External Interrupt constant firing 2019/07/23 11:28:59 (permalink)
    0
    Do you clear the INTF bit in your ISR?
    #7
    Jump to:
    © 2019 APG vNext Commercial Version 4.5