質問

I have started hobby development on a netduino 2. I'm struggling with interrupts on the onboard button. My problem is, that the interrupt is called several times for each time i press the button.

    public static void Main()
    {
        dac = new Dac();
        InterruptPort button = new InterruptPort(Pins.ONBOARD_SW1, true, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeHigh);
        button.OnInterrupt += new NativeEventHandler(button_OnInterrupt);

        Thread.Sleep(Timeout.Infinite);
    }

    static void button_OnInterrupt(uint data1, uint data2, DateTime time)
    {
        if(data2 == 1) 
        {
            dac.nextDACState();
        }
    }

*Dac is a custom Digital To Analog Converter. Nothing fancy here.

Is this a implementation fault, og maybe a faulty button, that flickers?

役に立ちましたか?

解決

Welcome to the joy of embedded and electronics!

What you are experiencing is called contact bounce: http://www.elexp.com/t_bounc.htm

It is typical in all uses of buttons and is caused by the electromechanical characteristics of the button.

There are 2 ways of dealing with this. Either add a debouncing circuitry or in software. Typically the software way this is to ignore all interrupts that occurs withing a few milliseconds of the first. There is a very good paper on debouncing strategies here: http://cseweb.ucsd.edu/classes/sp09/cse140L/slides/debouncing.pdf

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top