I'm using a reed switch to measure rotational speed and am trying to debounce the input. The problem that I am encountering is that at low speeds the bouncing is occurring at about 200ms. While at higher speeds the genuine input also occurs around 200ms. So if I set a debounce interval of 200ms then I cut off the high speed input.
Does anyone know of a way to debounce based on previous inputs. Seen as directly preceding a false input the time difference is large. Whereas a genuine high speed input is preceded by another high speed input.
Also, if you are detecting the speed of a rotating shaft one solution might be to have 2 reed switches at 90 (or so) degrees to each other, and use their output as if from a rotary encoder. There is no need to debounce a rotary encoder provided you deal with the output from it using a state based approach.
I think the second option might be what I'm looking for, that or using a hall effect sensor. The debouncing code I have been using is similar to yours:
That’s microseconds you have there not milliseconds …. Have another look at your timings , there is a limit to how fast a Reed switch can operate and it won’t bounce for 200mS ! 4mS is more like it ( 4000micro seconds)
Note also that the print statement takes time to process