[sdiy] Rotary encoders: is there a clever way to handle many?
Hugh Blemings
hugh at blemings.org
Mon Aug 10 14:06:03 CEST 2015
Hiya,
On 10/08/2015 21:45, Rick Jansen wrote:
> Well, that was fun, or was it. Handling a rotary encoder with an Arduino
> can be done, but there's a lot to take care of! The signals from my
> (simple) €1,50 encoder bounce all over the place. My current
> implementation uses one of the two interrupt pins of the Arduino,
> although a polling solution is possible as well. I'm not sure if it is
> because of the "quality" of this encoder, but at times there are nearly
> as many pulses clockwise as anti-clockwise.. I ended up counting both
> clockwise and anti-clockwise pulses, the greater of which determines
> actual direction. Even an "acceleration" is detected, if you turn the
> rotary fast the value will change more dramatically.
>
> It works quite well, but at the same time I wonder how other machines
> work, that track 8 or 16 rotary encoders.. An Arduino Mega has many more
> interrupt pins than the measly Arduino Uno, but still. Is there a clever
> trick to track many rotary encoders that I am missing?
I haven't done this for a loong time, but back on the 68HC11 when I did
a similar thing it had to be a polling system as there weren't
sufficient interrupt pins for each encoder.
Fed the outputs of each encoder into parallel input pins. Four encoder
per 8 bit port, but one could presumably multiplex them too.
I seem to recall a scan rate of a kHz or so, a state machine that
changed based on the previous and current state of each encoders
quadrature output pins did the trick and would deal with the debounce as
well.
With a little trickery the same state machine code could be used for
each encoders' pair of pins, some bit shifting to turn it into a two bit
value that the state machine logic could use with the assembly
equivalent of a C switch() statement.
Above is a bit rambly, but might point you in the right direction, if
not I'm sure smarter minds than mine will interject :)
Cheers,
Hugh
More information about the Synth-diy
mailing list