Two contacts out of step
Inside the encoder, two contacts close and open as the shaft turns, a quarter of a cycle apart. Either one alone says the knob moved. The order between them says which way: turned one way CLOCK falls first, turned the other DATA does.
One contact is not enough
Inside the encoder, a ring of metal teeth turns with the shaft, and two springy contacts touch it as it goes past. On this board each contact is joined to GND while it touches metal, so its line reads LOW; between teeth it is open, and the pull-up holds the line HIGH.
Watch one contact and you see it go LOW and HIGH again once a cycle as the knob turns. That tells you the knob moved. It cannot tell you which way: a turn to the left and a turn to the right make exactly the same pattern on one wire.
Two contacts, a quarter apart
The second contact sits a quarter of a cycle along from the first. So the two lines have the same shape, shifted: whichever way you turn, one falls first and the other follows a quarter of a cycle later.
Run it forward: CLOCK falls, then DATA. Run it back: DATA falls, then CLOCK. Nothing else is different. The order is the direction, and the number of cycles is the distance.
Two signals a quarter of a cycle apart are said to be in quadrature, and an encoder like this one is a quadrature encoder. The pin names are the encoder world's usual ones; there is no clock in the sense a data bus has one, just two contacts.
Reading the direction
The rule the first sketch uses fits in one line: when CLOCK falls, look at DATA. If DATA is still HIGH, CLOCK went first. If DATA is already LOW, DATA went first. Which of those two is clockwise depends on which contact the part calls A, so the sketch finds it out by being turned rather than by trusting a diagram.
The other way to read it is to track all four states the two lines can be in, 11, 01, 00 and 10, and score every move between them. That is the state table, and it is the version that copes with bounce.
How far a click goes
Turning the knob, you feel clicks. Most EC11 encoders give 20 of them a turn, and on many of those one click is one full cycle of both contacts, resting with both open. This part's number of clicks has not been counted, so treat 20 as a starting point: mark the knob, turn it once round, and count.
When it does not work
It depends on which contact the part calls A, and the BOM for this board names no part number to look it up in. Do not guess: run the first sketch, turn the knob clockwise, and see which way the count goes. If it goes down, swap the + and - in the sketch.
Most EC11 encoders give 20 clicks a turn, and this one was modelled on a 20-pulse part, but nobody has counted a TK06. Count yours: mark the knob, turn it once round, and count. None of the sketches in this book depends on the number.
No. A potentiometer has two ends and reports where the knob is, as a voltage. An encoder has no ends and reports only that it moved and which way. The program keeps the count, so the knob can start from any position and turn for ever.
On many EC11 parts it does, but not on all, and not verified on this one. The sketches here do not depend on it: the first counts falls of CLOCK, and the state table counts every change of either pin.
What the 10 kΩ and the 100 nF on each line do, and what they cannot.
The pull-ups and the capacitors →Edit this page — content/books/rotary-encoder/two-contacts-out-of-step.mdx
Questions about this product
See what other owners have asked, and read their solutions.
Rotary Encoder
Loading discussions…
Discuss this article
Ask about this page. The answer stays here, on the page it belongs to, for whoever hits the same wall next.