I have been using the k8055 board with vb.net and utilizing the counterdebounce. I would like to migrate to the VM167 board but cannot find a debounce function in the DLL. I have a sensor connected to Digital input 1 which increments the counter when something passes but if you wave your hand around in front of it the counter flys up. On the K8055 i was able to set the debounce to 1/2 second to ensure this did not happen.
I there is no debounce in this DLL, can someone provide code to debounce the input on input 1 for vb.net???
[quote]I would like to migrate to the VM167 board but cannot find a debounce function in the DLL. [/quote]Yes, there is no debounce function in the VM167 DLL.
You may use timer in the VB.NET code to make software debounce.
Here is an example using 500ms timer:
Global variables:
Dim LastStableState As Boolean
Dim TimerEvents As Integer
Dim PulseCounter As Integer
Timer event handler code:
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
Dim a As Boolean
InOutMode(CardAddress, 1, 1)
a = ReadDigitalChannel(CardAddress, 1)
If a = LastStableState Then
TimerEvents = 0 ' reset the debounce time counter if same as previous input state got
Else
TimerEvents = TimerEvents + 1 ' input state has changed
End If
If TimerEvents = 5 Then ' input state has been stable for the debounce time
If a = True Then ' count 'high' states only
PulseCounter = PulseCounter + 1
Label19.Text = CStr(PulseCounter)
End If
TimerEvents = 0
LastStableState = a
End If
End Sub