Go Down

Topic: Hardware debounce analog switches (Read 275 times) previous topic - next topic

jbellavance

Dec 15, 2017, 07:11 pm Last Edit: Dec 15, 2017, 07:13 pm by jbellavance
Where would I place a capacitor and/or other components to hardware debounce this setup?

I can't see the image...
Here is a link to it...https://github.com/j-bellavance/Images/blob/master/Analog.png
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

larryd

#1
Dec 15, 2017, 07:13 pm Last Edit: Dec 15, 2017, 07:16 pm by larryd


For input stability, place a 100nF capacitor from A0 to GND.





Seasons greetings countryman.



No technical PMs.
The last thing you did is where you should start looking.

jbellavance

#2
Dec 15, 2017, 07:15 pm Last Edit: Dec 15, 2017, 07:19 pm by jbellavance
One would think that [img] a link to an image [\img] would hold an image...

Hey, Larry, How did you do that???
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

larryd

The actual url is:
https://raw.githubusercontent.com/j-bellavance/Images/master/Analog.png


Also, read the analog input twice, use the second reading.

No technical PMs.
The last thing you did is where you should start looking.

larryd

No technical PMs.
The last thing you did is where you should start looking.

jbellavance

Quote
Also, read the analog input twice, use the second reading.
That would be software debounce. How about hardware debounce?
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

larryd

Actually, it helps the analog input settle down.


For input stability, place a 100nF capacitor from A0 to GND.



.
No technical PMs.
The last thing you did is where you should start looking.

jbellavance

Quote
Why 470K ?
I tried first with another 4.7K and the readings were not as close to the values I wanted, so I increased the resistor to 47K and the results got closer. Finally, at 470K, the results are close enough to what I want.

I still have to do the math to clearly know why it works though ;) .

Jacques
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

jbellavance

#8
Dec 15, 2017, 08:01 pm Last Edit: Dec 15, 2017, 08:03 pm by jbellavance
Quote
For input stability, place a 100nF capacitor from A0 to GND.
Thanks and Seasons Greetings to you too.
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Mikeb1970

#9
Dec 16, 2017, 12:37 am Last Edit: Dec 16, 2017, 12:43 am by Mikeb1970
This is what I found, R being 10K (standard pull down resistor) and the capacitor 10nF. But how higher the capacitance the longer the "debounce effect" since the capacitor discharges itself over the in this case 10K resistor, so I do agree with 100nF.



I hope the image link works, it would be the first time for me. Here is a link to the Image.

http://prntscr.com/ho44ld



larryd

No technical PMs.
The last thing you did is where you should start looking.

Mikeb1970


jbellavance

Ok, I did the maths.

Voltage at A0 depends on which switch is pressed. Say R1 is the sum of all resistors above the switch that is pressed and R2 the sum of all resistors below the switch that is pressed.

Then Voltage at A0 = 5 * R2 / (R1 - R2).

Everyting is fine, and the setup behaves just like an ordinary potentiometer. But...

Now we can have the possibility that no switch is pressed. To avoid having A0 to "float", let's link it to ground via a resistor (R3).

Now R3 is parallel to R2 and old R2 becomes (R2*R3)/(R2+R3). To keep the new R2 as close to the original R2, we need (ideally) to have R3 = to be infinite.

So, here is where 470K comes from. 100 times 4.7K looks cool and is high enough to keep new R2 close enough to old R2 so that the system still behaves like a potentiometer with 0V when no switch is pressed.
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Mikeb1970

Oops, I only just got what you where trying to do, please except my apologies.

jbellavance

No need to apologize.

I was not clear that I was responding to Larry's question.

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Go Up