I've been trying to develop a very low-overhead servicing routine for rotary encoders without having to add hardware debouncing. What I've done so far is found in a new "Arduino" folder in an old Github repo I started some years ago:
Included there are two Arduino demonstration sketches which use pin-change interrupts. The first uses the standard lookup table method where the previous and current pin states form an index into a table of all possible transitions. Interrupts are enabled on both encoder pin lines. In addition to blinking a CW or CCW LED for each tick, the sketch now prints to the serial monitor the total number of interrupts which have been serviced since the last tick, which provides an indication of how bouncy or noisy the encoder switches are.
An alternate sketch works the same way, but it enables only one interrupt at a time. When an interrupt occurs, the ISR disables further interrupts on that pin, and enables interrupts on the other pin. So none of the bouncing that may take place on the interrupting pin will trigger further interrupts because interrupts are no longer enabled on that pin. The other pin changed state some time ago and is presumed to be stable.
There's a PDF file in that folder that provides more detail, but what I've found so far is that the standard method can produce a very large number of interrupts - dozens to hundreds - for a single step from one detent to the next. Ideally, it would be four interrupts for a typical encoder. But the standard method deals very successfully with all that bouncing, and almost always comes up with the right result.
In contrast, the alternate method produces far fewer interrupts, but is a bit more error-prone, including producing some false direction ticks. The PDF includes some trial run information on both methods.
I was surprised at how many interrupts might be triggered in the standard method. I don't see any ringing on my scope, but the test Nano is running at 16MHz, so it's possible I'm not seeing what's really going on. Only the internal GPIO pullup resistors are used.
If anyone has an Arduino and an encoder laying around, I'm hoping maybe someone with more expertise than me could take a run at these sketches. No libraries are required.
The attached picture shows my "Minty" single-step encoder which I use to make sure my code produces the correct result for all possible transitions. The Minty produces a consistent run of 4's with the alternate sketch, but with the standard sketch I get this:
52 53 130 73 234 46 15 42 75 30
Assuming my code is ok, I would not have expected the Minty switches to bounce that much. They are genuine Radio Shack switches, not cheap imitations. But the PDF shows I get similar results with a real encoder. So I'm a bit puzzled by this result, and would like to know if others see the same thing, or if I'm doing something wrong and the number of interrupts reported isn't valid.