旋转编码器可以用施密特触发器消抖么
旋转编码器中间的按键要做开关,但是悲剧的发现采用中断抖动没办法消除,电阻电容都加了,现在打算用施密特触发器对按键做消抖,同时也顺便对AB脚进行整形,请问这样应该是可行的吧,顺便求电路~mega2560#include <RotaryEncoder.h>
RotaryEncoder encoder(14, 15);
int selectpin1 = 2;
boolean selected = false;
void setup(void) {
PCICR |= (1 << PCIE1); // This enables Pin Change Interrupt 1 that covers the Analog input pins or Port C.
PCMSK1 |= (1 << PCINT9) | (1 << PCINT10);// This enables the interrupt for pin 14 and 15 of Port C.
pinMode(selectpin1, INPUT_PULLUP); // Button switch or pin for encoder built-in switch
attachInterrupt( digitalPinToInterrupt(selectpin1), button, FALLING);
}
void button (void)
{
selected =! selected;
}
ISR(PCINT1_vect) {
encoder.tick(); // just call tick() to check the state.
}
int Rotator()
{
static int pos = 0;
int newPos = encoder.getPosition();
if (pos != newPos) {
// Serial.print(newPos);
// Serial.println();
if(newPos < pos)
{ dir=1;
pos = newPos;
}
else if(newPos > pos)
{ dir=2;
pos = newPos;
}
}
}
如果对时序要求不高,完全可以用软件消抖!这也是常用的做法。另外像按键比较多的系统中,会用到按键输入模块。 164335413 发表于 2016-11-15 18:00
如果对时序要求不高,完全可以用软件消抖!这也是常用的做法。另外像按键比较多的系统中,会用到按键输入模 ...
因为说了,都是在中断模式下工作的,中断模式下貌似没有什么太好的软件消抖模式,因为中断中delay之类的函数无法用的。 看起来是没有人了~ SilentGrace 发表于 2016-11-22 10:08
看起来是没有人了~
可以参考我之前发的一个帖子,用轮询实现的,很稳定。 wwwymq 发表于 2016-11-22 12:48
可以参考我之前发的一个帖子,用轮询实现的,很稳定。
其实我现在用的这个头文件用的也是轮询的方式,同时采用的引脚中断来触发的
页:
[1]