From
https://msdn.microso...y/cc532335.aspx
"When configuring an interrupt port, note the differences between level and nonlevel interrupts. 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 only the first occurrence of a level interrupt until it is cleared by means of the ClearInterrupt method. With nonlevel interrupts, every specified edge is dispatched, and the ClearInterrupt method throws anInvalidOperationException.
In practice, it is best to use level interrupts when the interrupt condition needs to be checked only periodically."
Based on the above explanation, your interrupt will ONLY fire when the edge is high, so checking for both high and low states in the interrupt event is not necessary. I would also think that heartbeatInput.ClearInterrupt() should be called unconditionally from the interrupt event handler itself, before it exits the handler, (since your "handleHeartBeat()" will only be called from time to time.)
On first look of your code, the ClearInterrupt will not always be fired - it will only be called if ts.Ticks > 1500000.
Also - you might try using the GlitchFilter to de-bounce.... I believe that's one of the things it is supposed to be used for.
Brian M.
- bgreer5050 likes this