I have an issue with my hardware button connected to an InterruptPort of the FEZ Hydra. In prinicple it works, I do get the interrupt. But most of the time there are two interrupts when I press the button. This might be related to my poor hardware button, I don’t know…
Does anybody have the same issues? Can I solve them with a kind of debouce routine?
This is my initialization:
InterruptPort installedInterruptSwitch = new InterruptPort(FEZHydra.Pin.PC9, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeHigh);
its typically your switch, yes. Jack Ganssle has a great in-depth paper Debouncing Contacts and Switches but depending on your requirement and sensitivity, you can do lots of simple thing to address it in your handler.
The glitch filter did not work for me. No effect at all…
Now I use both the rising edge and falling edge interrupt to determine when a button was pressed. This works great. The strange thing here is that I always get two interrupts independent of the settings…
Dim myList As New ArrayList
Dim WithEvents button As New InterruptPort(DirectCast(24, Cpu.Pin), True, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeBoth)
Sub Main()
Cpu.GlitchFilterTime = New TimeSpan(0, 0, 0, 0, 100)
Debug.Print("Ready")
Thread.Sleep(-1)
End Sub
Private Sub button_OnInterrupt(port As UInteger, state As UInteger, time As Date) Handles button.OnInterrupt
myList.Add(state & " " & time)
If myList.Count = 50 Then
button.DisableInterrupt()
For i = 0 To myList.Count - 1
Debug.Print(myList(i).ToString())
Next
End If
End Sub
No. But that does not explain why in double edge mode we get multiple 1s or 0s in a row. Isn’t that supposed to be strictly 1010101010…10101010 sequence?
UPDATE: I found this explanation on MSDN: “Level interrupts, which are either InterruptEdgeLevelHigh or InterruptEdgeLevelLow interrupts, are dispatched when the value on a pin matches the specified high value or low value, respectively. The system dispatches [em]only the first occurrence of a level interrupt[/em] until it is cleared by means of the ClearInterrupt method. With nonlevel interrupts, [em]every specified edge is dispatched[/em].”
I wonder why level interrupts are still not supported by GHI hardware :think:
@ iamin - I wasn’t able to reproduce it in the handful of tests I tried using your exact code. Even if I disabled the glitch filter, I didn’t get any duplicates. What does your hardware setup look like?
@ John - Cobra II + Button module connected to port #4.
Code:
Public Module Module1
Dim myList As New ArrayList
Dim WithEvents button As New InterruptPort(DirectCast(25, Cpu.Pin), True, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeBoth)
Sub Main()
Cpu.GlitchFilterTime = New TimeSpan(0, 0, 0, 0, 100)
Debug.Print("Ready")
Thread.Sleep(-1)
End Sub
Private Sub button_OnInterrupt(port As UInteger, state As UInteger, time As Date) Handles button.OnInterrupt
myList.Add(state & " " & time)
If myList.Count = 50 Then
button.DisableInterrupt()
For i = 0 To myList.Count - 1
Debug.Print(myList(i).ToString())
Next
End If
End Sub
End Module
If you really want to get rid of button noise you should connect a flip flop or latch ( Q output) to the interrupt line and use a form C contact tied to the direct set and direct reset inputs of the latch/flip flop.