Any suggestions for an ADC based switch de-bouncer?

Does anyone have any suggestions on implementing an analogue solution to the common digital de-bounce problem?

The switch output is monitored via an ADC input. My language here is based on a momentary type device. So operationally, you’d have a voltage that hovers around value NP (not pressed). The voltage changes to around P (pressed) when the switch is pressed. The new thing here is that N and NP might be any DC voltage, eg. NP ~ 11V and P ~ 6V, but these are just examples and their relative magnitudes are arbitrary.

Without dwelling on the why, I’d like to ask about the how ::slight_smile:


Note:

  1. A simple stochastic solution seems to be to just calculate the mean ADC reading over X samples. If the mean reading is > or < than some (threshold + tolerance) then the switch state is known. Say 20% or 80%?
  2. The internal ADC can reliably operate > 50 kSa/s given a low impedance source.
  3. Should the ratio of N to NP be either ~0.5 or ~2, a simple resistor divider getup might not be easily used to map the monitored voltages to {logic high, logic low}. And clearly if N, NP << 5V, then resistor networks are inadequate. I wouldn’t want to develop the hardware beyond simple resistors.
  4. Is something similar already used in over current detection in industrial motors?

Post a wiring diagram of that setup with links to the used hardware!

A bouncing switch gives a digital output signal, so it's either 0V or any higher voltage, usually the Vcc of the system. If you get strange analog values I'd expect your circuit to be broken, so the de-bouncing isn't your major problem.

Depending on your actual circuit a comparator may produce the digital information from your analog output.

pylon:
A bouncing switch gives a digital output signal, so it’s either 0V or any higher voltage, usually the Vcc of the system.

Yeh, not really. What if it’s a current switch, not a voltage switch? So there’s little relation to any Vcc. Hence my point 4. And see the end of point 3.

I’ve included a schematic. The momentary switch features an LED and there are only two wires so I have to current detect it’s operation.

debounce.png

Use a capacitor and resistor. Keep it analog in front of the ADC.

Assuming the lefthand side goes to an Arduino pin, why the 24volt zener (tits on a bull?).

And why the 1N4148 diodes, with a Vf of ~0.7volt.
The internal pin protection of an Arduino pin most likely conducts before the diodes do.
Use at least schottky diodes there.

R3 could be much higher in value (>=10k).
Adjust C6 accordingly.
Leo..

Good point about the diodes, thanks.

But any views on the de-bounce algorithm? R3 is that to keep ADC impedance low to go fast. Are you simply assuming that the time constant prevents all bounce?

I don't get the voltage divider, 220 / 240 * 12V = 11V that would be clamped to 5.7V by D5. :confused:

It's not a voltage divider. It's a current shunty thingie to measure the current passed by the switch connected to the terminals on the schematic. There is an integral LED, over current protection and only two wires. So the voltage the ADC sees just changes between two values if the switch is pressed. Neither is 12V and not easily mapped to {0,5}. And a replacement switch might produce differing N,NP requiring a circuit change.

My specific concern was about de-bouncing the switch action. I'm suggesting a stochastic solution by calculating a timed mean and comparing it to a threshold boundary. Or should the standard bounce library be hacked?

(OTT, but this must be commonly resolved in industrial control. You wouldn't shutdown a 100kW drive if a 1ms over current fault was detected during operation.)

This sketch for debouncing multiple switches on an analog input may work. Shouldn't be too hard to modify it for only one switch.

cossoft:
Does anyone have any suggestions on implementing an analogue solution to the common digital de-bounce problem?

The switch output is monitored via an ADC input. My language here is based on a momentary type device. So operationally, you’d have a voltage that hovers around value NP (not pressed). The voltage changes to around P (pressed) when the switch is pressed. The new thing here is that N and NP might be any DC voltage, eg. NP ~ 11V and P ~ 6V, but these are just examples and their relative magnitudes are arbitrary.

Without dwelling on the why, I’d like to ask about the how ::slight_smile:


Note:

  1. A simple stochastic solution seems to be to just calculate the mean ADC reading over X samples. If the mean reading is > or < than some (threshold + tolerance) then the switch state is known. Say 20% or 80%?
  2. The internal ADC can reliably operate > 50 kSa/s given a low impedance source.
  3. Should the ratio of N to NP be either ~0.5 or ~2, a simple resistor divider getup might not be easily used to map the monitored voltages to {logic high, logic low}. And clearly if N, NP << 5V, then resistor networks are inadequate. I wouldn’t want to develop the hardware beyond simple resistors.
  4. Is something similar already used in over current detection in industrial motors?

The mean isn’t a great approach here, the mode would be much less likely to be confused if the button is pressed just while sampling, since it takes the most common value and doesn’t sum readings.

If the ADC readings oscillate a bit you can preprocess with a little hysteresis to lose the dithering before
determining the mode.