[sdiy] dave smith *instruments*

Eric Brombaugh ebrombaugh1 at cox.net
Tue Feb 2 00:22:22 CET 2010


On 02/01/2010 12:02 PM, Antti Huovilainen wrote:
>
> 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.

Not having to debounce is a nice feature, and time-based interrupts are 
good inasmuch as they're very much more friendly from a scheduling 
standpoint.

Gray-coding of course means that any bounce on the edge will only move 
you fwd/back one state, so if your scan period is set up to be a bit 
longer than the bounce duration you'll never have any edge jitter. One 
shudders to think what kind of mayhem would be required for the other 
phase to bounce and result in detecting an illegal state - perhaps 
someone chucking up the encoder to an electric drill and spinning really 
fast? Assuming a 32-step detent encoder, you'd have to be twisting the 
knob at more than 230 RPM to exceed a 500Hz scan rate.

> 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.

I guess the only change to the code you'd need would be to divide by 4 
since a detent encoder sees 4 code state changes per step.

Eric



More information about the Synth-diy mailing list