avr-chat
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-chat] Using Rotary Encoders...


From: Richard Urwin
Subject: Re: [avr-chat] Using Rotary Encoders...
Date: Wed, 21 Sep 2005 17:41:21 +0100
User-agent: KMail/1.7.2

(Sorry about the previous one with no content. My fingers don't know 
what theyr'e doing.)

On Wednesday 21 Sep 2005 06:00, Vincent Trouilliez wrote:
> Hi gents,
>
>
> I would like your opinions/experiences about using rotary encoders. I
> have planned on using one for my project, so ordered one to
> experiment with (never used them before).
> It's a mechanical one, with the usual 2-bit gray code output.
>
> I was expecting loads of bounces, but got only a few glitches, so was
> impressed by the quality of the unit despite the affordable price
> (under 6 Euros). Wanting to get rid of these few glitches and make it
> perfect, I used a timer to allow 50ms for bounces to go away, plenty
> enough according to the datasheet which stated 5ms max, and my
> observations on the scope showing that pulses were mostly about 10 to
> 15ms wide max, under normal conditions (ie, not turning it too
> slowly). So, 15+5 = 20, 50ms should cover any amount of bouncing.

I would code for an interrupt on both edges of B and positive edges of 
A.
Then count on positive transitions of A with the direction indicated by 
B. Then following a transition on A disable A interrupts until B 
changes state.

So in ISR-A
 if B is positive incr count
 if B is negative decr count
 disable A interrupts

and in ISR-B
 reverse sense of B which causes interrupts.
 enable A interrupts.

You will get a lot of B interrupts as it bounces, but by then the 
bounces from A should have stopped. B is guaranteed to have changed 
state before the next transition on A, whatever happens.

-- 
Richard Urwin




reply via email to

[Prev in Thread] Current Thread [Next in Thread]