Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Buttons and glitches


  • Please log in to reply
3 replies to this topic

#1 John West

John West

    Advanced Member

  • Members
  • PipPipPip
  • 51 posts

Posted 23 July 2011 - 09:51 PM

So I've got some code written that handles a button press. The code has been working great with the onboard button, but I've wired up two push buttons to the analog ports, and they're glitching bad. The button interrupt increments a counter, and sometimes it correctly gets called only once when the button is released, and sometimes 2-4 times. I've tried different values for the InterruptPort constructor (InterruptEdgeHigh, glitch = true, etc).

So, questions:

1) Is it not possible to use a pushbutton on an analog port?

2) What are the InterruptPort constructor values I need to use? Here is what I'm currently trying:

            button1 = new InterruptPort(Pins.ONBOARD_SW1, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeHigh);
            button1.OnInterrupt += new NativeEventHandler(button_OnInterrupt);
            button2 = new InterruptPort(Pins.GPIO_PIN_A0, true, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeHigh);
            button2.OnInterrupt += new NativeEventHandler(button_OnInterrupt);

Like I say, button2 is totally sporadic. Thoughts?

#2 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 23 July 2011 - 10:32 PM

Hi John, The analog ports are also true digital ports (lower mA ratings, but same functionality). You should be able to use pushbuttons there without any issue. The debouncing code ("glitch filter") for Netduino basically polls a button 2-3 times to make sure the reading is correct...but some switches bounce a lot more than that. The best thing to do is to implement a bit of software debouncing logic. There are a few examples of this on the forums. I'd look for "glitch filter" or "debounce". Chris

#3 Stefan W.

Stefan W.

    Advanced Member

  • Members
  • PipPipPip
  • 153 posts

Posted 23 July 2011 - 10:34 PM

How did you wire the button to the netduino? (well, since you "only" get glitching, i guess you've done it right - using some external pullup or pulldown). A simple solution for human-operated switches would be to block events from being triggered if they have been triggered in the last 50 ms or so - so, inside the interrupt handler, check if the last event was within 50 ms, if yes, discard the event, if no, update the time on the last event and do the action.
I believe that no discovery of fact, however trivial, can be wholly useless to the race, and that no trumpeting of falsehood, however virtuous in intent, can be anything but vicious.
-- H.L. Mencken, "What I Believe"

#4 John West

John West

    Advanced Member

  • Members
  • PipPipPip
  • 51 posts

Posted 24 July 2011 - 05:01 AM

I can do it programmatically; I was just hoping that wasn't necessary. I'd always do it the "right", built-in way rather than have write code for it.

If I can ask, what do you mean by external pullup or pulldown? I see where you can set this in the constructor, but I'm not totally sure what it is. It does seem you can only set it to pullup, not pulldown. I searched on this and didn't find much.

How did you wire the button to the netduino? (well, since you "only" get glitching, i guess you've done it right - using some external pullup or pulldown).

A simple solution for human-operated switches would be to block events from being triggered if they have been triggered in the last 50 ms or so - so, inside the interrupt handler, check if the last event was within 50 ms, if yes, discard the event, if no, update the time on the last event and do the action.






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.