rotary encoder : hardware debouncing

Status
Not open for further replies.

iniitu

Member
hello all,
i have been working on a project including 7 rotary encoders and noticed after a lot of use that it sometimes had debouncing issues : the encoders are used to navigate menus and the display was sometimes jumpy.
so i am trying to isolate an encoder and work on its stability.
here i added some hardware debouncing and used a simple code to test how jumpy the numbers are :

here is the schematics of the hardware part :

20200413_185817.jpg

R = 10kO
C = 0.01uF

ABC are of course the 3 legs of the rotary encoder

Code:
#include <Arduino.h>
#include <Encoder.h>

int pinRotaryEncoder1A = 30;  
int pinRotaryEncoder1B = 29;

Encoder rotKnob1(pinRotaryEncoder1A, pinRotaryEncoder1B);

int counterEndUser;
int oldCounterEndUser;

void setup()
{
  Serial.begin(115200);
}

void loop()
{
  counterEndUser = rotKnob1.read();
  //  counterEndUser /= 4 ;

  if (counterEndUser != oldCounterEndUser)
  {
    Serial.print(counterEndUser);
    Serial.print(" ");
    oldCounterEndUser = counterEndUser;
  }
}

this is what i get when running the code and turning the rotary encoder, quite slowly i admit :

.. 237 238 239 240 241 242 243 244 245 244 245 246 247 248 249 250 251 252 ..

you can see there is still a bit of chatter ( i isolate this line from about 20 more lines, all working proper )
is this a very reasonable outcome or is there another way to improve the situation, hardware or software-wise ?

best,
Sylvain
 
Hiya - I'd suggest maybe trying optical encoders, rather than mechanical ones. They're more expensive, 7-8 pounds or so from HK or aliexpress, and unfortunately physically larger, but I've found them much more reliable in my little projects, especially when needing to use more than one encoder. They seem to work well with the encoder libraries, if used with interrupt pins.
 
Status
Not open for further replies.
Back
Top