Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Message

Re: [AVR-Chat] Rotary encoder

2009-12-09 by Dave Hylands

Hi Jeff,

On Wed, Dec 9, 2009 at 9:17 AM, Jeff Blaine AC0C
<keepwalking188@yahoo.com> wrote:
> Gentlemen,
>
> Sorry for the confusion on the initial question.  I do understand the various basic aspects of the encoder function and the trade off of IRQ vs poll, etc.
>
> What I am really wanting to do is to build a generic set of polished functions so that the code is clean and easy to reuse in the future as a generic library function set.  And the code covers all the typical variations one is likely to encounter.
>
> As several have suggested, getting a set of code that works for a single application is not hard.  My rookie hack at making the encoder function will be fine for the project in front of me.
>
> And I believe someone may have a more robust implementation - that would cover a wider range of eventual complications and have considered things that I may not have initially.
>
> By eventual complications, for example, would be the ability to cover the various types of encoders configurations on the market or a debounce strategy that is robust enough to work with many encoders even if some tend to wiggle onward for what seems an eternity - things like that.

My solution is here (QD.h and QD.c)
<http://websvn.hylands.org/filedetails.php?repname=Projects&path=%2Fcommon%2Favr%2FQD.h&rev=0&sc=0>
<http://websvn.hylands.org/filedetails.php?repname=Projects&path=%2Fcommon%2Favr%2FQD.c&rev=0&sc=0>

It doesn't do any debouncing, and doesn't deal with index pulses.

It does use lookup tables, and you can swap out the lookup table to
count A & B, just A, or just B.

The compiler will optimize out the unused side of the if statement in
the QD_CountInternal and QD_SetCountInternal function (since it uses a
constant expression).

Personally, I prefer to use a polling approach, rather than an ISR
based approach. The polling approach is self-correcting for noise. The
polling approach also represents what I call "constant load" in terms
of CPU cycles, which is generally better from a real-time perspective
(more deterministic - not necessarily better performance).

-- 
Dave Hylands
Shuswap, BC, Canada
http://www.DaveHylands.com/

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.