The pull-ups and the capacitors
Each rotation contact has a 10 kΩ pull-up to VCC and a 100 nF capacitor to GND. The pull-up gives the line a level when the contact is open. The capacitor, with it, makes a 1 ms filter that swallows short bounces. It helps; it does not make bounce impossible.
The pull-up gives the line a level
A contact can only connect or not. Closed, it joins its line to GND, and the line is plainly LOW. Open, it connects the line to nothing, and a line connected to nothing is not HIGH: it floats, and reads whatever it picks up.
The 10 kΩ pull-up fixes the open case. It holds the line at VCC while the contact is open, and when the contact closes, the contact wins, because it joins the line to GND with next to no resistance. R4 does this for CLOCK and R3 for DATA. It costs VCC across 10 kΩ while a contact is closed: 0.5 mA from 5 V, 0.33 mA from 3.3 V.
The capacitor slows the rise
C2 on CLOCK and C1 on DATA are 100 nF each, from the line to GND. When a contact closes, it empties its capacitor at once, so the line still falls straight to 0 V. When a contact opens, the line cannot jump back to VCC: the pull-up has to charge the capacitor first, and 10 kΩ × 100 nF is a time constant of 1 ms. The line climbs a little under two-thirds of the way in 1 ms, and passes half of VCC after about 0.7 ms.
Play it with the capacitor fitted, then with 10 kΩ only. The bounce is illustrative: nobody has put this encoder on a scope. The arithmetic is the real RC one.
Bounce, and what the filter does to it
A contact does not close cleanly. It touches, springs apart, and touches again for a short while, and so does it when it opens. Without the capacitor the line follows every one of those, and a sketch that counts falls counts them all. The TK04 push button has the same problem, and the same cause.
With the capacitor, a contact that springs open for a fraction of a millisecond lets the line climb only a small part of the way before it closes again. The line never crosses the switching point, and the pin never sees that bounce. In the figure, three closes become one fall.
What it cannot do
The filter has limits, and they are why the sketches do not rely on it. A bounce that holds the contact open for more than a few tenths of a millisecond can get through as a real HIGH; exactly how long depends on where your chip's input switches. A brief accidental close still pulls the line straight to 0 V, and then it takes the best part of a millisecond to climb back, so the pin sees a LOW. A worn encoder tends to chatter for longer than a new one.
So the filter helps, and the software still has to cope. The last article but one, a state table, is the version that treats any bounce that gets through as a step forward and a step back, which add up to nothing.
When it does not work
No. The board already has 100 nF from each line to GND, C1 on DATA and C2 on CLOCK. Old advice to add 0.1 µF per phase was written for bare encoders; 0.1 µF is the same 100 nF, and it is fitted.
No, INPUT. The block's 10 kΩ pull-ups are already on CLOCK and DATA, so the chip's own would only sit in parallel with them and add nothing. On BTN it would be worse: it would fight the pull-down.
Because the filter only swallows bounces shorter than a fraction of a millisecond. A contact that chatters for longer still gets through, and a worn encoder tends to chatter more. The state table cancels bounce that gets through, as long as it sees each change.
It delays each rise by about 0.7 ms to half of VCC. At 20 clicks a turn a quarter-cycle is still 2.5 ms when you flick the knob at five turns a second, so a hand-turned knob stays well inside it. A motor-driven encoder would be another matter.
Five wires and a sketch that counts clicks by watching CLOCK fall.
The first count →Edit this page — content/books/rotary-encoder/the-pull-ups-and-the-capacitors.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.