Some data on encoder frequencies from rotary encoders
Paul,
Regarding overflow/underflow/race-condition issues in encoder software:
From my reading of the data (I have trouble calling a 1200+ page document a) sheet section, the chip designers included some hardware to make handling overflow/underflow/race-conditions easier. Search for TOFDIR. Unlike many hardware encoder interfaces, this one
not only has a flag for counter rollover, TOF, it also has one for the **direction** of the rollover, TOFDIR. Those flags would have made my grad-school experimental software much, much easier. Without any such flags, the only way I know to maintain an accurate encoder count is to (a) bound the maximum counting rate and then (b) make sure you sample the counter faster than it could possibly count halfway. With those constraints, extending the counter width is doable. With those two flags, one doesn't need to check the counter nearly so often (I think it'd now be the time to count one less than twice the counter's max count -- almost 4 times as long permitted between reads.)
Regarding the filter. I was quite pleased to see they have a filter; not all encoder interfaces have that. Much better with.
Can anybody reading this give an example of anything other than in the guts of a software-defined (really software-morphable) radio that produces digital signals in quadrature at frequencies above 2 MHz.?
I suspect I've used higher resolution encoders than most reading this -- 81,000 lines on the encoder disk, giving 324,000 quadrature counts per revolution. (Has anybody here used an encoder with more lines/disk? If so, please speak up!) That number, by itself, might make you think we'd need a counter that could handle tens or hundreds of MHz. Not so. If you take a look at the specsheet for that 81,000 line encoder,
http://usa.canon.com/CUSA/assets/app/pdf/encoder/LaserRotaryEncoder.pdf
you'll see that there's now an even higher resolution version, the R1P20!?! However, if you take a look at the "Max Response" row in those specs, you'll see that the fastest that the raw quadrature signals can go is 2 MHz (and it isn't even for the highest resolution encoder.) Typical encoders used in motion control have no more than 4096 lines/disk (often significantly less.) even spinning at 10,000 RPM (which is cooking along!) that gives 4096*10,000 / 60 = approx 683 KHz. Most shaft encoders have a spec for maximum count rate -- which may well be significantly less than the max. speed constraints from the bearings, etc. involved.
Another data point re filtering: H-P, back before they split up, made an encoder interface chip (originally for their printer division.) That chip used a best-3-out-of-4 filter, fixed thus not programmable. So I suspect that a default of 4 should work well on the high-frequency range. There might be an issue on the other end of frequencies. Mechanical encoders with (inevitably) bouncy contacts will probably bounce too slowly to be caught by the hardware filter. Hopefully mechanical encoders are made such that one phase's bouncing ends before the other phase transitions (and probably starts bouncing.) I haven't used those, though I expect to soon. Optical or magnetic encoders should be fine with the encoder interface hardware on this chip.
What I see as the main benefit of the hardware quad decoder is that, once some poor bastard [1] publishes a timer-interrupt driven ISR to read the encoder periodically and extend the count to 32 or 64 bits (ISR shouldn't take more than a small fraction of the CPU), all we'll have to do (after a few calls to set up the decoder as desired) is call readEncoder()
[1] My intent in this post is to provide some data to assist that poor bastard.