>Way back in January, in message
><
RemoveMEubenfwmpp9.fsfKILLspam
helium.physik.uni-kl.de> Aschwin Gopalan
><
gopalanSTOPspam
spam_OUTPHYSIK.UNI-KL.DE> wrote:
>
>> Channel A
>> ++-------++ ++-------++ ++-------++
>> || || || || || ||
>> || || || || || ||
>> || || || || || ||
>> ----------++ ++------++ ++------++ ++-------
>>
>>
>> Channel B
>> ++-------++ ++-------++ ++-------++
>> || || || || || ||
>> || || || || || ||
>> || || || || || ||
>> -----++ ++------++ ++-------++ ++-------
>>
>> This is for clock-wise rotation for example.
>>
>> As you can see, if you trigger on the rising edge of A, B is always
>> high. For CCW rotation, at the rising edge of A, B is always low. So
>> you can use one of the channels as a trigger and the other as
>> direction output. All what is left is the debouncing.
>
>Looking at edges in this way is asking for trouble, hence you have to
>write things like debouncing routines etc. Really you should always look
>at examining the levels.
>
>A nice (fast!) compromise is documented in one of the Parallax data
>sheets, which is:
>
>Is the Current reading different from the previous?
>If so:
> Take the previous reading
> shift it to the right
> xor it with the current reading.
> Check bit 0 (or 2, 4, 6 etc...)
> If it is 0, then decrease the counter, else increase it.
>
>This works wonderfully. Consider the first two transitions in Aschwin's
>example (assume that count starts at 5, and the switch bounces a lot!)
>
> A: LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLHLLLLHHHHLLHHHHHHHHH
>
> B: LLLLLLLLLLHLLLLHHHLLHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
>
>Change: NNNNNNNNNNYYNNNYNNYNYNNNNNNNNNNNNNNNNNNNNNNNYYNNNYNNNYNYNNNNNNNN
>
>Count: 5555555555655556665566666666666666666666666676666777766777777777
>
>There's absolutely no way that the bounce can induce slippage, which it
>would with an edge-detecting algorithm.
>
>Using such a mechanism I've been keeping a serial-controlled resistor
>up to date and reading encoders at up to 12,000 pulses/sec on a 4MHz
>'84! (that's assuming one channel out of the 4 it's monitoring is
>changing, and guarantees that any pulse is seen)
>
>Fun!
>
>
>
>
>Stuart.
>--
>Stuart Tyrrell Developments
spamBeGoneStuartSTOPspam
EraseMEstdevel.demon.co.uk
>PO Box 183, OLDHAM. OL2 8FB
KILLspamstdevelspamBeGone
locust.co.uk (Mobile <> Email)
>Orange: 0976 255 256 (9am-9pm)
http://www.stdevel.demon.co.uk
>*Analogue joystick i/face 39.95* *Using an IR keyboard via PS2Mouse 24.95*
>