[中文设计文档] 开关抖动及消除的办法

[复制链接]
 楼主| 杨寅辉 发表于 2020-2-23 12:43 | 显示全部楼层 |阅读模式

当按下和释放微动按键时,会由短时间的抖动现象才会到达想要的状态。如下图所示:


从上图可知。按键抖动时间大概为150us。

在一些对按键抖动敏感的情况下需要进行消抖设计,目前常见的消抖设计如下:


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×
 楼主| 杨寅辉 发表于 2020-2-23 12:43 | 显示全部楼层
  • 滤波电容

关于去抖硬件最简单的方式并联一颗100nF陶瓷电容,进行滤波处理。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×
 楼主| 杨寅辉 发表于 2020-2-23 12:44 | 显示全部楼层
本帖最后由 杨寅辉 于 2020-2-23 12:45 编辑

RC滤波+施密特触发器
要想更严谨设计消抖电路,会增加施密特触发器,更大程度的保证后端不受按键抖动影响,电路如下:


分别来看按键闭合断开时电路状态:


开关打开时:

电容C1通过R1 D1回路充电,Vb电压=Vcc-0.7为高电平,后通过反向施密特触发器使Vout输出为低。

开关闭合时:

电容C1通过R2进行放电,最后Vb电压变为0,通过反向施密特触发器使Vout输出为高。

当按下按键出现快速抖动现象时,通过电容会使Vb点电压快速变成Vcc或GND。在抖动过程时对电容会有轻微的充电或放电,但后端的施密特触发器有迟滞效果不会导致Vout发现抖动现象。

此电路中D1的使用使为了限制R1 R2一起给C1供电,增加充电时间影响效果。如果减小R1的值会使电流增加,功耗较高。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×
 楼主| 杨寅辉 发表于 2020-2-23 12:46 | 显示全部楼层
  • 专用消抖芯片

一些厂家会提供专用芯片,避免自搭电路的不稳定性, 如美信-Max6816:


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×
 楼主| 杨寅辉 发表于 2020-2-23 12:47 | 显示全部楼层
  • 软件滤波

软件消除抖动也是很常见的方式,一般形式是延时查询按键状态或者中断形式来消除抖动。
下面是Arduino的软件消抖代码:

  1. /* SoftwareDebounce
  2. *
  3. * At each transition from LOW to HIGH or from HIGH to LOW
  4. * the input signal is debounced by sampling across
  5. * multiple reads over several milli seconds.  The input
  6. * is not considered HIGH or LOW until the input signal
  7. * has been sampled for at least "debounce_count" (10)
  8. * milliseconds in the new state.
  9. *
  10. * Notes:
  11. *   Adjust debounce_count to reflect the timescale
  12. *     over which the input signal may bounce before
  13. *     becoming steady state
  14. *
  15. * Based on:
  16. *   http://www.arduino.cc/en/Tutorial/Debounce
  17. *
  18. * Jon Schlueter
  19. * 30 December 2008
  20. *
  21. * http://playground.arduino.cc/Learning/SoftwareDebounce
  22. */

  23. int inPin = 7;         // the number of the input pin
  24. int outPin = 13;       // the number of the output pin

  25. int counter = 0;       // how many times we have seen new value
  26. int reading;           // the current value read from the input pin
  27. int current_state = LOW;    // the debounced input value

  28. // the following variable is a long because the time, measured in milliseconds,
  29. // will quickly become a bigger number than can be stored in an int.
  30. long time = 0;         // the last time the output pin was sampled
  31. int debounce_count = 10; // number of millis/samples to consider before declaring a debounced input

  32. void setup()
  33. {
  34.   pinMode(inPin, INPUT);
  35.   pinMode(outPin, OUTPUT);
  36.   digitalWrite(outPin, current_state); // setup the Output LED for initial state
  37. }


  38. void loop()
  39. {
  40.   // If we have gone on to the next millisecond
  41.   if(millis() != time)
  42.   {
  43.     reading = digitalRead(inPin);

  44.     if(reading == current_state && counter > 0)
  45.     {
  46.       counter--;
  47.     }
  48.     if(reading != current_state)
  49.     {
  50.        counter++;
  51.     }
  52.     // If the Input has shown the same value for long enough let's switch it
  53.     if(counter >= debounce_count)
  54.     {
  55.       counter = 0;
  56.       current_state = reading;
  57.       digitalWrite(outPin, current_state);
  58.     }
  59.     time = millis();
  60.   }
  61. }



keaibukelian 发表于 2020-3-7 08:29 | 显示全部楼层
非常感谢楼主分享
labasi 发表于 2020-3-7 08:30 | 显示全部楼层
非常感谢楼主分享
paotangsan 发表于 2020-3-7 08:34 | 显示全部楼层
非常感谢楼主分享
renzheshengui 发表于 2020-3-7 08:38 | 显示全部楼层
非常感谢楼主分享
wakayi 发表于 2020-3-7 08:43 | 显示全部楼层
非常感谢楼主分享
jstgotodo 发表于 2020-3-13 21:21 | 显示全部楼层
软件程序中对此触点的接通进行延时一段时间
iamaiqiyi 发表于 2020-3-13 21:21 | 显示全部楼层
硬件方法和软件方法。   
dzfansman 发表于 2020-3-13 21:21 | 显示全部楼层
开关上并联0.1uF电容可消除抖动和外部干扰信号
sanxingnote7 发表于 2020-3-13 21:21 | 显示全部楼层
rs触发器防抖动原理   
backlugin 发表于 2020-3-13 21:21 | 显示全部楼层
一定要使用无抖动开关  
sdCAD 发表于 2020-3-13 21:22 | 显示全部楼层
上电瞬间的开关抖动对后续电路有没有影响?
fengm 发表于 2020-3-13 21:22 | 显示全部楼层
提高按键输入可靠性  
10299823 发表于 2020-3-13 21:22 | 显示全部楼层
单脉冲开关还用加防抖动吗
10299823 发表于 2020-3-13 21:23 | 显示全部楼层
硬件消抖不消耗软件资源  
jimmhu 发表于 2020-3-13 21:23 | 显示全部楼层
按键消抖真的有必要吗?  
您需要登录后才可以回帖 登录 | 注册

本版积分规则

39

主题

295

帖子

2

粉丝
快速回复 在线客服 返回列表 返回顶部