Monday, October 12, 2020

Rotary encoder secret decoded ...

There are many pages that deal with rotary encoders in connection with Arduino. Numerous diagrams with square-wave signals are published and reports on a shift in the signals depending on the direction of rotation. All of this is correct. But I was often missing a small but important piece of information.

What exactly happens when the encoder is only rotated one stop point further?

Unfortunately, this is not understandable for me from the many technical descriptions.
I couldn't explain it clearly to myself, so I just hooked up my own oscillograph. An example from the ardino accessories was used as an encoder. Pull-up resistors are already built in here.


 

I operated this with 5v and tapped the signals at CLK (yellow) and DT (blue). And now it looks very simple:

This is the information that I have always lacked in order to understand it:

The (my own) rotary encoder generates a complete single pulse on the CLK and DT, while the rotation continues by one detent point. In the idle state, both connections are at HIGH level. 

Depending on the direction of rotation, there is a time lag between the two signals. The trigger point would be the edge from HIGH (logic 1) to LOW (logic 0) at the CLK connection (or alternatively the rising edge). In order to determine the direction of rotation, you only have to determine the level at which the 2nd output is at this point in time. Exactly at this moment the level at the DT connection is always LOW when turning in one direction or always HIGH when turning in the other direction. I have framed this point in time in red in the screenshots of my oscilloscope.

No comments: