[sdiy] dave smith *instruments*
Antti Huovilainen
ajhuovil at cc.hut.fi
Mon Feb 1 20:02:31 CET 2010
On Mon, 1 Feb 2010, Eric Brombaugh wrote:
> That's a good way to go if you want high resolution. A somewhat simpler
> approach with less resolution is to hook one of the encoder phases to an
> IRQ. When you get an interrupt, debounce and check if rising or falling.
> If rising, the state of the other phase indicates if you need to
> increment or decrement the controlled parameter. Exit without update if
> falling.
I'd be very vary of ever hooking an unconditioned switch to IRQ pin. The
beauty of the timer method is that you don't need any debouncing as long
as you consider the properties of gray code (which encoders use).
In a typical cheap encoder, you have four possible states as follows:
0 A b
1 A B
2 a B
3 a b
Only a single bit at a time will change state whenever the encoder is
rotated. Therefore only transitions between adjacent states (and 0 <-> 3)
are valid. If you then encounter an invalid transition, you know it's a
glitch and you can keep ignoring changes until you've found one or two
sequential valid transitions again.
> If you're using encoders with detents this yields one pulse per detent
> which is probably all you really want. If you've got continuous encoders
> then Antti's suggestion is probably the better approach since it allows
> the rotation to stop anywhere and still take advantage of every
> transition on both phases.
I have detented encoders and still use my method as it's inherently
glitch-safe (meaning a glitch will only mean missing one or two ticks but
never outright corruption). An extra bonus is that you can switch to
undetented encoders without needing to change the logic.
Antti
"No boom today. Boom tomorrow. There's always a boom tomorrow"
-- Lt. Cmdr. Ivanova
More information about the Synth-diy
mailing list