打印
[中文设计文档]

开关抖动及消除的办法

[复制链接]
3632|57
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主

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


从上图可知。按键抖动时间大概为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:


使用特权

评论回复
5
杨寅辉|  楼主 | 2020-2-23 12:47 | 只看该作者
  • 软件滤波

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

/* SoftwareDebounce
*
* At each transition from LOW to HIGH or from HIGH to LOW
* the input signal is debounced by sampling across
* multiple reads over several milli seconds.  The input
* is not considered HIGH or LOW until the input signal
* has been sampled for at least "debounce_count" (10)
* milliseconds in the new state.
*
* Notes:
*   Adjust debounce_count to reflect the timescale
*     over which the input signal may bounce before
*     becoming steady state
*
* Based on:
*   http://www.arduino.cc/en/Tutorial/Debounce
*
* Jon Schlueter
* 30 December 2008
*
* http://playground.arduino.cc/Learning/SoftwareDebounce
*/

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

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

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

void setup()
{
  pinMode(inPin, INPUT);
  pinMode(outPin, OUTPUT);
  digitalWrite(outPin, current_state); // setup the Output LED for initial state
}


void loop()
{
  // If we have gone on to the next millisecond
  if(millis() != time)
  {
    reading = digitalRead(inPin);

    if(reading == current_state && counter > 0)
    {
      counter--;
    }
    if(reading != current_state)
    {
       counter++;
    }
    // If the Input has shown the same value for long enough let's switch it
    if(counter >= debounce_count)
    {
      counter = 0;
      current_state = reading;
      digitalWrite(outPin, current_state);
    }
    time = millis();
  }
}



使用特权

评论回复
6
keaibukelian| | 2020-3-7 08:29 | 只看该作者
非常感谢楼主分享

使用特权

评论回复
7
labasi| | 2020-3-7 08:30 | 只看该作者
非常感谢楼主分享

使用特权

评论回复
8
paotangsan| | 2020-3-7 08:34 | 只看该作者
非常感谢楼主分享

使用特权

评论回复
9
renzheshengui| | 2020-3-7 08:38 | 只看该作者
非常感谢楼主分享

使用特权

评论回复
10
wakayi| | 2020-3-7 08:43 | 只看该作者
非常感谢楼主分享

使用特权

评论回复
11
jstgotodo| | 2020-3-13 21:21 | 只看该作者
软件程序中对此触点的接通进行延时一段时间

使用特权

评论回复
12
iamaiqiyi| | 2020-3-13 21:21 | 只看该作者
硬件方法和软件方法。   

使用特权

评论回复
13
dzfansman| | 2020-3-13 21:21 | 只看该作者
开关上并联0.1uF电容可消除抖动和外部干扰信号

使用特权

评论回复
14
sanxingnote7| | 2020-3-13 21:21 | 只看该作者
rs触发器防抖动原理   

使用特权

评论回复
15
backlugin| | 2020-3-13 21:21 | 只看该作者
一定要使用无抖动开关  

使用特权

评论回复
16
sdCAD| | 2020-3-13 21:22 | 只看该作者
上电瞬间的开关抖动对后续电路有没有影响?

使用特权

评论回复
17
fengm| | 2020-3-13 21:22 | 只看该作者
提高按键输入可靠性  

使用特权

评论回复
18
10299823| | 2020-3-13 21:22 | 只看该作者
单脉冲开关还用加防抖动吗

使用特权

评论回复
19
10299823| | 2020-3-13 21:23 | 只看该作者
硬件消抖不消耗软件资源  

使用特权

评论回复
20
jimmhu| | 2020-3-13 21:23 | 只看该作者
按键消抖真的有必要吗?  

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

39

主题

295

帖子

2

粉丝