Interrupts stop responding?

I have Fez Cobra 2 and i am using interrupts for some pins. The interrupts work fine for a couple hours then stop responding?

Any suggestion or technique to determine why this is happening? The Fez Cobra is still running when the interrupts stop responding( i have a hear bear that is alive).

May I ask what that is?

lol I mean heart beat!

3 Likes

Certainly made me laugh. :clap:

1 Like

Maybe an unhandled exception in your interrupt handler?

I have a try…catch in my interrupt method so i would assume that an exception would not break it…can i restart the interrupt or something?

ok…trying this…lets see what happens…added clear interrupt on finally just in case that is casuing the issue.

static void IntButton_OnInterrupt(uint port, uint state, DateTime time)
        {
            try
            {
                if (port == 13)
                {
                    Logit("IntB[" + port + "|" + state + "|" + intcount + "]..", bLCD: true);
                    Logit("***** IntButton_OnInterrupt Port[" + port + "|" + state + "|" + System.Environment.TickCount + "]..");
                    if (!MuxLedsRelays.ReadPin(Pin.GP4A))
                    {
                        Logit("GP4A Button pressed");
                        oAPI.ProcessApi("sensors/RELAY07/toggle", null, 2, "RelayDevice", true);
                    }
       
                }
            }
            catch (Exception)
            {
                Logit("Exc[-56]..", bLCD: true);
                Logit(LoggingLevel.error, "***** IntButton_OnInterrupt Port[" + port + "|" + state + "|" + System.Environment.TickCount + "]..");
            }
            finally
            {
                MuxLedsRelays.ClearInterruptA();

            }
        }

//this is i setup interrupts...all using the same method?  Is this good practice?
            InterruptPort IntButton = new InterruptPort(GHI.Pins.G120.P2_12, false, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeHigh);
            IntButton.OnInterrupt += new NativeEventHandler(IntButton_OnInterrupt);

            InterruptPort IntA = new InterruptPort(GHI.Pins.G120.P0_13, false, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLow);
            IntA.OnInterrupt += new NativeEventHandler(IntButton_OnInterrupt1);

            InterruptPort IntB = new InterruptPort(GHI.Pins.G120.P0_12, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLow);
            IntB.OnInterrupt += new NativeEventHandler(IntButton_OnInterrupt2);





Still stops responding? Anyone suggest any way to determine why my interrupts are stopping?

Are you creating new interrupt classes on every call? Why are you re-declaring the interrupts

The interrupts are declared once in the program main procedure…sorry for the mis-communication.

So the switch is being pressed and released right? Also, is your glitch filter off?

new InterruptPort(GHI.Pins.G120.P2_12, false, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeHigh);

Your interrupt port instance is probably getting collected by the garbage collector.

1 Like

Ah, it’s probably going out of scope. Declare them outside of the main program function, or ensure that function never ends Thread.Sleep(Timeout.Infinite) style.

1 Like

Glicth filter is off. GUs…why would garbage collector take my instance…shouldn’t it ask for permission :slight_smile:

@ anthonys - because your reference was lost. This is explained in our netmf manual.

Thanks Guys…i should read the manual one day. I have declared the variables outside the main program section which should fix the issue.

let us know if it does then mark as answered.

Yes…variables had not been declared outside main. First issue fixed.

It appears introducing Monitor.Enter…Exit solved my app crashing randomly…mmm…does everyone use Monitor.Enter…Exit as standard interface when talking to hardware? Its new to me…is it best practice?

Thanks people!

@ Mr. John Smith -

Thanks for your reply. Could not have come at a better time because I was having this problem and…
Yes… I had mine in Main. I forgot all about that issue.