Below is a simple example of the issue I am seeing. This program is supposed to call the DoorBellPort_OnInterrupt method ONLY when GPIO_PIN_D7 changes from low to high or high to low. What I am experiencing, is that everytime it switches.....the method is called multiple times (sometimes the board actually runs out of memory). I discovered this by setting a break point in the method itself. I manually switch the connection to pin 7 between the 3.3V and Gnd pins on the Netduino Plus to ensure that my input is not in fact switching quickly.
public static void Main()
{
InterruptPort DoorBellPort = new InterruptPort(Pins.GPIO_PIN_D7, false, Port.ResistorMode.Disabled,
Port.InterruptMode.InterruptEdgeBoth);
DoorBellPort.OnInterrupt += new NativeEventHandler(DoorBellPort_OnInterrupt);
Thread.Sleep(Timeout.Infinite);
}
static void DoorBellPort_OnInterrupt(uint data1, uint data2, DateTime time)
{
return; //Breakpoint here. Called multiple times per edge??
}
Everytime the method is called, I do see that the data2 variable switches between 1 and 0 each time. What I dont understand is how this is even possible???
Looping issue with "InterruptEdgeBoth"
Started by Christopher Gilmore, Dec 07 2010 03:56 AM
3 replies to this topic
#1
Posted 07 December 2010 - 03:56 AM
#2
Posted 07 December 2010 - 08:29 AM
Physical switches bounce a lot when pressed. There's a glitch filter option that helps a bit, but you may need to add some debounce circuitry.
By the way, you're not the same Chris Gilmour I used to kitesurf with are you?
#3
Posted 07 December 2010 - 01:05 PM
Christopher,
If you connect D7 to GND and then start your app, how many times is the event called?
Chris
#4
Posted 08 December 2010 - 02:05 PM
Yeah.... Fred's suggestion worked (glitch filter = true and adding a debouncing circuit). I did a quick google on debouncing circuit and saw some examples.
The problem ended up being fixed by putting a 1uF capacitor between the input to the netduino and ground. Below shows an example of how i added a capacitor C1. Also, R1 = 10Kohms.
http://www.ikalogic....ng/debounce.jpg
After that, the interupt only got called once for each edge.
Thanks for the help!
I've never been kitesurfing....
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users