Searching \ for 'Rotary Encoder Implementation' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: techref.massmind.org/techref/io/sensors.htm?key=encoder
Search entire site for: 'Rotary Encoder Implementation'.

Truncated match.
PICList Thread
'Rotary Encoder Implementation'
2011\10\11@100840 by jim

flavicon
face

All,

I have been working with a rotary encoder that I am planning to use as
a control for a piece of test  equipment at work.  I have looked on the web for algorithms to decode
the outputs of said encoder,  and have found several.  Most of them work as advertised in my
application, but I have come up with a  version that works very well in my opinion.

I don't know whether it is new or novel, but all I have done is watch
for the "A" output to go high.
When it does, I then read the port that the encoder is attached to.  I
mask of the bits I am interested  in, and use this as an index into a table.  If the value is "01" I add
"1" to my variable.  If the value  is "10", I subtract "1" by adding 255.  Any other combination "00" or
"11" adds a zero for no change.

I have tried this out spinning the knob on the encoder as fast as I
can, and I can't see any missed  counts.  I am using a delay of 2.5 mS in my routine for debouncing.  
If anyone is interested, I can post the code.  But my guess is I have
just on my own rediscovered an old  method of decoding rotary encoders.

 Regards,

Jim

2011\10\11@103736 by Mike Hord

picon face
Thanks for sharing! Sounds like Gray code with twos complement math
to me. If you've never heard those two terms then I think you should be
justly proud in having come up with the solution on your own- it shows
insight into what's actually going on under the hood, so to speak.

Mike H.

On Tue, Oct 11, 2011 at 8:08 AM, <spam_OUTjimTakeThisOuTspamjpes.com> wrote:

{Quote hidden}

>

2011\10\11@113655 by Dwayne Reid

flavicon
face
Hi there, Jim.

You have discovered the easiest way to read a quadrature encoder.  This is the same technique that I first used many years ago when feeding an encoder directly into hardware: treat one of the encoder phases as the clock signal and use the other phase as the up / down direction control.

Although it does work, it suffers from poor noise rejection if you have any contact bounce on the clock phase and will lead to erroneous counts.  It also does not give you the maximum possible encoder resolution.

I don't use that technique any more because I got bit once too often when dealing with a noisy encoder.  The technique I use now is to monitor both encoder phases for a change, then feed both phases into a state machine.  Illegal state changes (such as those caused by noise or contact bounce) are ignored and I get to use the full resolution that the encoder offers - this is 4 times the resolution that your technique offers.

By all means - if your technique works for your application, use it.  Just keep in mind the alternative options if contact bounce rears its ugly head at some time in the future.

dwayne


At 08:08 AM 10/11/2011, .....jimKILLspamspam@spam@jpes.com wrote:

{Quote hidden}

-- Dwayne Reid   <dwaynerspamKILLspamplanet.eon.net>
Trinity Electronics Systems Ltd    Edmonton, AB, CANADA
(780) 489-3199 voice          (780) 487-6397 fax
http://www.trinity-electronics.com
Custom Electronics Design and Manufacturing

2011\10\11@114338 by Gary Crowell

picon face
I was just planning to use one myself.  I'd appreciate seeing the code.

Gary

On Tue, Oct 11, 2011 at 8:08 AM, <.....jimKILLspamspam.....jpes.com> wrote:

{Quote hidden}

>

2011\10\11@114830 by Harold Hallikainen

face
flavicon
face
I also had problems with contact bounce on rotary encoders, so I use the
state machine described at
http://www.piclist.org/techref/microchip/qenc.htm

Harold



{Quote hidden}

>

More... (looser matching)
- Last day of these posts
- In 2011 , 2012 only
- Today
- New search...