The quadrature encoder has been tested and proven to work ( thank you, Ken Chapman), detecting every transition as a count pulse, never an accumulated error. The only flaw is a one-pulse backlash. That means, it does not recognize the first change after a reversal of direction. You could call it hysteresis, analogous to a +/- 1 count ambiguity, known to exist in many conversions. Peter Alfke
Below is the vhdl file, courtesy of my friend Ken Chapman:
---------------------------------------------------------------------------------------------------------------------------------- -- Shaft Encoder
---------------------------------------------------------------------------------------------------------------------------------- -- -- Interface to rotary encoder. -- Detection of movement and direction. -- -- The rotary switch contacts are filtered using their offset (one- hot) style to -- clean them. Circuit concept by Peter Alfke. -- Note that the clock rate is fast compared with the switch rate. --
rotary_filter: process(clk) begin if clk'event and clk='1' then
--Synchronise inputs to clock domain using flip-flops in input/ output blocks. rotary_a_in