_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" }
Newbie on buttons & pull-up resistor
Started by kenNET, Jan 12 2011 09:11 AM
4 replies to this topic
#1
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.
#2
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
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
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
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.
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
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