《开关抖动及消除》由会员分享,可在线阅读,更多相关《开关抖动及消除(8页珍藏版)》请在金锄头文库上搜索。
1、开关抖动及消除当按下和释放微动按键时,会由短时间的抖动现象才会到达想要的状态。如下图所示:bounce produced 的在这里插入图片描述 从上图可知。按键抖动时间大概为 150us。在一些对按键抖动敏感的情况下需要进行消抖设计,目前常见的消抖设计如下:滤波电容关于去抖硬件最简单的方式并联一颗 100nF 陶瓷电容,进行 滤波处理。在这里插入图片描述RC 滤波施密特触发器要想更严谨设计消抖电路,会增加施密特触发器,更大程度的保证后端不受按键抖动影响,电路如下:DIVaR2HGNDVoutA Switch debocmg在这里插入图片描述分别来看按键闭合断开时电路状态:在这里插入图片描述VD
2、开关打开时:电容C1通过R1 D1回路充电,Vb电压二Vcc-0.7为高电平,后通过反向施密特触发器使 Vout 输出为低。开关闭合时: 电容 C1 通过 R2 进行放电,最后 Vb 电压变为 0,通过反向施 密特触发器使Vout输出为高。当按下按键出现快速抖动现象时,通过电容会使 Vb 点电压 快速变成Vcc或GND。在抖动过程时对电容会有轻微的充电 或放电,但后端的施密特触发器有迟滞效果不会导致 Vout 发现抖动现象。此电路中D1的使用使为了限制R1 R2 一起给C1供电,增加 充电时间影响效果。如果减小 R1 的值会使电流增加,功耗 较高。专用消抖芯片一些厂家会提供专用芯片,避免自搭电
3、路的不稳定性, 如 美信-Max6816:OEBOJWCED OUTPUTRESCTIWAX6S16升农HATCAL 5WTT-CH在这里插入图片描述软件滤波软件消除抖动也是很常见的方式 ,一般形式是延时查询按键 状态或者中断形式来消除抖动。下面是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
4、 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 timescaleover which the input signal may bounce beforebecoming steady state* Based on:* http:/www.a
5、rduino.cc/en/Tutorial/Debounce* Jon Schlueter* 30 December 2008* http:/playground.arduino.cc/Learning/SoftwareDebounce*/int inPin = 7;/ the number of the input pinint outPin = 13;/ the number of the output pinint counter = 0;/ how many times we have seen newvalue/ the current value read from theint
6、reading;input pinint 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 sampledint debounce_count = 10; / nu
7、mber of millis/samples to consider before declaring a debounced inputvoid 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 millisecondif(millis() != time)reading = digitalRea
8、d(inPin);if(reading = current_state & counter 0)counter-;if(reading != current_state)counter+;/ If the Input has shown the same value for long enough lets switch itif(counter = debounce_count)counter = 0;current_state = reading;digitalWrite(outPin, current_state);time = millis(); 版权声明:本文为CSDN博主sternlycore的原创文章,遵 循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声 明。原文链接: https:/