Teensy3.1 has hardware quadrature counting support, however it is only a 16 bit counter, giving 64K counts. The issue, and the reason for the interrupts is if the system requires more than 64k encoder counts. If your system is always below 64K counts, just reading the counter is okay. Also, if your system is uni-directional it is much simpler. Just read the counter, look at the TOF (Timer Overflow) bit for when to increment the base count by 64K and clear the TOF for next time. As long as you read the counter often enough so that it doesn't overflow twice between reads, it is fairly straightforward.
The reason for the code is a system with greater than 64K counts and that can change direction at any time. This is a situation that the hardware doesn't handle very cleanly. If you reverse around the overflow region, it gets complicated. And unlike pieces of code where you don't want unscheduled interrupts, you can't temporarily shut off the encoder signal. And then I also have other interrupts to the system of somewhat unknown duration and latency. I don't have a lot of time to spend monitoring the encoders. The quadrature code has interrupts, however, the latency (how soon you have to answer the interrupt) and overhead requirement is fairly low.
Just monitoring a spinning encoder always going the same direction, you can simplify. If it reverses, you need the code.
TLB
The reason for the code is a system with greater than 64K counts and that can change direction at any time. This is a situation that the hardware doesn't handle very cleanly. If you reverse around the overflow region, it gets complicated. And unlike pieces of code where you don't want unscheduled interrupts, you can't temporarily shut off the encoder signal. And then I also have other interrupts to the system of somewhat unknown duration and latency. I don't have a lot of time to spend monitoring the encoders. The quadrature code has interrupts, however, the latency (how soon you have to answer the interrupt) and overhead requirement is fairly low.
Just monitoring a spinning encoder always going the same direction, you can simplify. If it reverses, you need the code.
TLB