ROTARY ENCODERS.
Some thoughts and research.
Arduino stuff at bottom of page.
10 Aug 2013 ,,,
Updated (See below)
RESEARCH
AND INFORMATION,,,,
Rotary encoders
keep popping up with cockpit building and its only natural that they get
integrated with the projects that we build.
Although rotary
encoders are basically a simple item in themselves, all too often the playing
we do with them turns to custard and the end result is a "work
around". (With speed and reliability)
ROTARY ENCODERS
,,, What are they ????
Rotary encodes
enable a means of, by rotating a knob, increasing or decreasing the value of
something. The most common ones that domestic users will come across is the
volume control on modern car radios. (If it’s not done with buttons !)
There is no
mechanical “stop” to them ,, you can physically turn them for ever and not bust
them.
Although there is
many exotic types out there (more exacting,, positioning etc) we will only dig
deep into the common ones that will be used by the average cockpit builder.
FIRSTLY ,,,, They
are NOT rotary switches !!!!! Countless times a “Newbie” pops up in forums
somewhere and after a lot of confusion ,, it turns out he though “rotary
encoder” is just a fancy name for a rotary switch ,,, In reality ,, I suppose you can relate to this because they are
both presented to the end user as a “knob on the panel” that you turn to adjust
something.
A rotary switch (in
simple terms) changes a common terminal from one terminal to another terminal.
Keep turning and (depending on the switchs design) it will change the common to
even more terminals. ,,, so basically
you can choose which terminal is selected by turning the knob.
A rotary encoder is a different beast altogether. Inside a rotary encoder there are actually 2
rotary switchs ,, one making contact
before the other one and the same sequence on opening, also during the turning, both can be ‘open’
or both can be ‘closed’.
Its best to
describe it in the term you will commonly see in DATA SHEETS.

Interpreting the
above …..
The dotted lines
are the indent position ,, the “Click”. (Watch out here ,, sometimes dotted
lines are shown as “transition points”.)
CH A is the same
as “Switch A” ,,, CH B is the same as
“Switch B”
So in the above
diagram ,,, pin C is the common and the 2 switches (Channels) are pins A and B.
Both switches are
open (off) in the start position.
We move from left
to right by turning the knob clockwise.
As the encoder is
turned clockwise, switch A makes contact first ,, then switch B makes contact.
Now ,, on the
first click (not counting the start position) ,, they are both closed. (on).
Turn it further
clockwise and switch A opens first,, followed by switch B ,,, now they are both
open (off) again.
The software
detects from the above sequence that the knob is being turned in the clockwise
direction.
In the above
example, you have just turned it through a complete cycle ,, where the switch
contacts are back to what they were to start.
OK, lets see what you know about these
things ,,,,,
Spot the
difference ,,,,

OK ,, they are all the same. The point I’m trying to make is ,,,
JUST BECAUSE THEY LOOK
LIKE ROTARY ENCODERS ,, IT’S PROBABLY NOT WHAT YOU WANT.
Some important
considerations ,,,,
Get ones that can
also be “panel mounted”
so, if you want to,, you can mount them directly to the panel. (They have a
thread and a nut on the shaft housing)
Rotary encoder
terminals are made to suit mounting on a PCB ,, that’s fine for high volume
production but for your “one of” project you probably want to mount it on a
panel and run wires to the input card.
Ensure you can get
Knobs that suits your chosen
rotary encoder.
There’s a huge
variation in shaft lengths, styles and mounting systems (for the knob).
All to often, the
biggest problem is getting knobs that “look right” in your project and to
actually find a knob that suits the encoder you are looking at buying is a huge
mission. A lot of times ,,, looking for a knob to suit those cheap encoders you
bought ,, ends in disaster.
Its no use paying
$2 for a rotary encoder and then finding out the only “suitable” knob is going
to cost you another $10.
Getting knobs for
DUAL concentric encoders
is even a bigger nightmare so be very careful if that’s what you need.
The only reseller
I’ve struck that relates to this problem is Leo ,,, he sells dual encoders WITH the suitable knobs.
Not the cheapest
in town, but at least it’s all together.
http://www.leobodnar.com/products/BU0836X/ (Near the bottom of the page)
Built-in “Push
switch” ,,, Get the one with the inbuilt switch (push the knob and
it switch’s something) ,, real handy
for a lot of purposes. (Mhz to Khz change-over or change input from one radio
to the other. etc etc)
Choose the correct
number of indents
per revolution for the designed purpose. (The indent is the “click”)
Again,, this depends
on what you are doing with them.
General flight sim stuff seems to suit 15 to 20 indents per revolution.
At 30 indents it
gets a bit touchy to set a figure and 12 indents is getting a bit slow to make
progress with your turn.
Another figure to
think of here is built-in software acceleration ,, where the faster you turn it
,, or ,, the longer you turn it, then
the software takes bigger jumps in the output. The notes from the software
developer should indicate if acceleration is “built in”.
Choose the correct
“cycle per indent ratio”.
This is a real
nightmare for the unskilled buyer. Even
big manufactures get this wrong sometimes. (Just ask anyone that bought an
early Saitek radio unit) Lots of
sellers on ebay don’t even talk about this and don’t supply this crucial
information.
Have you ever used
something that for each click it jumps forward 2 or 4 places ??? ,,, or
,,, you need to turn it 2 clicks for it
to go forward 1 place ?? Well this is
the area we are talking about.
There are 2 area’s of concern here ,,, Obviously the
encoder ,, the other one is the software.
The intended software should say if its ¼ cycle,, ½ cycle or full cycle.
(Or some other way to describe the indents per switching cycle)
Once you know
this,, you buy the encoder to suit that cycle.
NOW ,, Armed with
all this knowledge ,,, Spot the difference in these three ,,,

CYCLE TO INDENT
RATIO ,,,,
Encoder “A” has only gone thru 1 click and the 2 internal switches
are back to the same electric state as what it was when it started ,, so it’s a “full cycle” encoder.
Encoder “B” has gone thru 2 clicks to get back to the switches
starting state ,, so it’s a “half
cycle” encoder.
Encoder “C” has gone thru 4 clicks to get back to the switches
starting state ,, so it’s a “quarter
cycle” encoder.
There are other’s
out there but that’s the main (common) three types.
What’s missing in
the above picture is Indents or Cycles
per revolution ,, a very needed figure but it’s generally given elsewhere in
the datasheet.
So my best advise
before buying encoders is ,,,,
Research it’s ,,, MOUNTING,, KNOBS ,, PUSH SWITCH ,, INDENTS ,,, CYCLE TO INDENT RATIO.
Study the
datasheet on any rotary encoder that catch’s your eye.
Note .. There
seems to be no set standard between manufacturers to describe the info needed
for the “cycle to indent ratio” ,, but now you know what to look for. You need to put this “Cycle to indent ratio”
together yourself out of the different
specifications in the data sheets ,,, but it’s generally presented in a picture
simular to the above.
“Specials” or “Real cheap” ,,, There are some odd-ball
ones out there, so be careful with “specials”. Some have no indents at all. !!!
OTHER OPTIONS
PULSE SWITCHS,,,
These are real
easy to integrate into our projects as its wired is just as a basic switch.
Alps and Knitter
make pulse switch (turn them one way and a switch pulses, turn them the other
way and another switch pulses with each click)
Although,, on a
quick look I couldn’t find any knitter ones ,,, maybe they’ve stopped making
them.
http://www.alps.com/WebObjects/catalog.woa/E/HTML/Switch/Rotary/SRBM/SRBM1L1400.html
The disadvantage
with these, is they are hard to find and are more expensive.
Rotary encoders
with the Arduino.
As you know,, I
love the Arduino cards and use them with my cockpits.
I liked pulse
switches so rotary encoders was a bit of a new adventure for me but I had
strict criteria for their use within my set-up.
My requirements
were ,,,
Had to be fast ,,,
FAST !!!!
Minimal errors on
reasonably “cheapie” rotary encoders.
Ability to have
heaps of them into one card.
Ability to handle
¼ , ½, and full cycle per indent.
Coding had to be
simple to integrate into larger programs.
And the most
important one ,,, It still had to perform well on an “already busy card” !!!!
Well there seemed
to be no contest here ,, I fiddled for ages with different ways to do
this ,, some were great but fell down on one thing or another. Towards the end of my research, I stumbled
across Keith Neufeld’s blog and what a
surprise. This Guys is a very talented man, not only in coding but also in
electronics.
I can recommend with no hesitation Keith’s
Quadrature library for the Arduino.
(Only for IDE’s 0022 and 0023)
His website …. http://www.neufeld.newton.ks.us/electronics
His talk on this library ,, http://www.neufeld.newton.ks.us/electronics/?p=248#more-248
His actual
download file only worked with the early Arduino IDE’s but attached in my
download (below) is a corrected version.
In the download
the demo is set up for using with a Uno card (max pin = 14) but to use it with
a Mega card ,, all that needs doing is to open out the 'quadrature.h'
file and edit the line '#define DIGITAL_PINS (14)'. Change the 14 to what ever pin no. is going to be your highest.
Thank you Keith !!
Unfortunately
Keiths Quadrature library failed to work in
the newer Arduino IDE version 1.
Bill Holland had the first fix and
then I had another ,,,, so now it works with the newer versions of the IDE as
well as the older ones.
UPDATE
,,,
Keiths library
does half and full cycle encoders ,, there is however a another type on the
block that is getting more
and more prevalent
and that is a QUARTER CYCLE encoder. (One state change per click)
If your encoders
are quarter cycle type then you don’t need to use a library at all.
I have enclosed a
demo in the download called "quarter_cycle_encoder_demo" that has 2
different types of code showing how to do it.
DON'T USE A LIBRARY if you have quarter cycle
encoders.
You can download the new one here ,,,,
www.jimspage.co.nz/quadrature2.zip
ALTERNATIVE
METHODS ,,,
James's method as
detailed in ,,,,
http://www.mycockpit.org/forums/showthread.php/22636-Arduino-COM-NAV-LED-display-FSX
Other links that
use the common rotary switch are about the net in different formats ,, 1 pole
12 pos,, 2 pole 12 pos etc etc.
Somewhere on my
travels I struck a guy using a potentiometer to "dial up" the
required figure. (input to analogue pin)
Somewhere also I
seen a circuit of fixed resistors
around a 12 position switch to again give different analogue values.
In some of the
above switch modes ,, the "stop" was removed from the switch so it
could endlessly rotate.
Writing Code for
Rotary encoders ,,,,
OK,, now you know the
in’s and out’s of rotary encoders, the normal thing is to take it all in and
make the code to suit your project and the type of rotary encoder you have
,,, that’s fine until you share it with
some-one else. What you need to do is
include in your project notes, explanations on changing the rotary encoder
input cycle to suit whatever they have. (Assuming their rotary encoders are
different)
Keep
at it Guys ,,, Jim
Dated
18 July 2011
Updated 3 Dec 2011
Updated
22 Aug 2012 added IDE v1 fix on Keith’s library
Updated
10 Aug 2013 general update (core library is the same)
![]()