2016年4月24日 星期日

按鈕或開關彈跳的問題 (Button Debounce)


今天找到一個更好的解決方法,網址如下:

https://electrosome.com/switch-debouncing/


I think the best solution is "Hardware" solution, if there is no limitation of dimension.  I use a sample RC circuit (shows as below) which can be found on Internet easily. The resister and capacitor values which I used are 250K ohm and 0.1 uF. The basic rule to choose the value of R and C are, small C can be discharged quickly when switch closed, and high value of R will charge slowly. I think the limitation of this debounce circuit is that this circuit can not handle the high frequency switch action. Regarding the values of RC, it will take about 0.125 second to charge capacitor from 0 V to 5 V. The RC value can be calculated in fact. 5 * R * C is time of C charge to 5V, and discharge time will be 5 * C (assumed the resistor in switch is 1 ohm). and the rule is discharged time is sorter than bounce cycle time, and charge time much longer than bounce cycle time. Regarding measurement, the bounce cycle time of the switch is about 50 us.

如果沒有硬體空間限制的問題的話,我想採用硬體的對策是最好的消除彈跳的方法。我這次使用的數值是250K歐姆的電阻,以及0.1uF的電容器。電路如下圖所示。我想這個電路的限制是,無法使用在高速切換的開關電路上,因為充電的時間比較長。依照電容充放電的特性,與所選的數值。在開關打開後約須0.125秒的時間,電容器才能充電到5伏特。電阻電容值事實上可以通過計算決定。5 *R*C為充電時間,5*C為放電的時間(假設開關電路阻抗為1歐姆)。充電的時間必須要比跳跳訊號的週期長,而放電的時間則是要比彈跳的週期短。依據視波器的量測,彈跳週期約為50 us。






Bounce signal when R C values are not good enough.