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

Newbie on buttons & pull-up resistor


  • Please log in to reply
4 replies to this topic

#1 kenNET

kenNET

    Advanced Member

  • Members
  • PipPipPip
  • 69 posts
  • LocationSweden

Posted 12 January 2011 - 09:11 AM

I'm struggling with external buttons, the event fire several times when pressing the button. I need some advise on how to wire it up and values for the resistor (I use 10k now). If I use ONBOARD_SW1 then all works just fine. See picture how I wire it up now.



_btn1 = new InterruptPort(Pins.GPIO_PIN_D6, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLow);
_btn1.OnInterrupt += new NativeEventHandler(_btn1_OnInterrupt);

static void _btn1_OnInterrupt(uint data1, uint data2, System.DateTime time)
{
   _numClicks++;

   if (_numClicks> 10)
      _numClicks= 1;

   //code for LCD show "_numClicks"
}

Attached Files



#2 Jim Davies

Jim Davies

    Advanced Member

  • Members
  • PipPipPip
  • 48 posts
  • LocationBrighton & Hove, UK

Posted 12 January 2011 - 09:23 AM

Hi Ken,

You're probably seeing contact bounce on your buttons. You can either debounce in software or add a small capacitor from each digital input to ground, to 'smooth' the signal a bit. Also, have you tried the 3.3V instead of the 5V - might make a difference?

See for example:

Interrupting

Also try searching for 'glitch' or 'bounce' in the Forums search box.

Jim

#3 Fred

Fred

    Advanced Member

  • Members
  • PipPipPip
  • 302 posts
  • LocationUK

Posted 30 January 2011 - 12:25 PM

Try this to ignore any button presses within 200ms.

const int DEBOUNCE_TIME = 200;
DateTime _lastButtonPress = DateTime.Now;

_btn1 = new InterruptPort(Pins.GPIO_PIN_D6, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLow);
_btn1.OnInterrupt += new NativeEventHandler(_btn1_OnInterrupt);

static void _btn1_OnInterrupt(uint data1, uint data2, System.DateTime time)
{
    // Debounce - ignore multiple presses within 200ms
    if (time < _lastButtonPress.AddMilliseconds(DEBOUNCE_TIME)) return;
    _lastButtonPress = time;

   _numClicks++;
   if (_numClicks> 10)
      _numClicks= 1;

   //code for LCD show "_numClicks"

}


#4 Driver A

Driver A

    Member

  • Members
  • PipPip
  • 13 posts

Posted 20 February 2011 - 03:53 PM

Why not play with the Cpu.GlitchFilterTime instead? I think it's meant to be used for handling bounces.

I've noticed it is set to 0 by default so I'm not sure what an InterruptPort with "glitchFilter = true" does.

// set glitch filter to 1 second
Cpu.GlitchFilterTime.Add(new TimeSpan(TimeSpan.TicksPerSecond));


#5 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 25 February 2011 - 01:07 AM

Why not play with the Cpu.GlitchFilterTime instead? I think it's meant to be used for handling bounces.


The .NET Micro Framework handles glitch filtering different ways on different on microcontrollers.

On some of the microcontrollers, it uses a timespan (Cpu.GlitchFilterTime) to filter out glitches over a set time period.

On others (like the AT91SAM7X used on Netduino), it polls the input a few times to get a consistent reading instead.

I don't know of any reason that the SAM7X microcontroller couldn't support Cpu.GlitchFilterTime though...if you wanted to tweak the source to support it you could do so.

Chris




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.