[sdiy] Need goog working rotary encoder in C code..
John Speth
johnspeth at yahoo.com
Fri Aug 6 21:19:04 CEST 2021
For a good HW model of how to debounce switches, take a look at:
https://www.onsemi.com/pdf/datasheet/mc14490-d.pdf
That's how I originally crafted my polling digital debouncer code.
JJS
On 8/6/2021 11:05 AM, John Speth via Synth-diy wrote:
> I have substantial experience with the application but not in a
> musical context. My extensive trials and errors has convinced me of
> the following:
>
> 1. You'll need to know when inputs change state, not just when the
> signals go low. Consider rising and falling edge interrupts on both
> inputs. You can detect rotation direction using this strategy.
>
> 2. There WILL be bouncing so plan for it. Contact type switches will
> bounce more than optical switches. Contact type switches will degrade
> over time.
>
> 3. Interrupts vs polling: Interrupts are great but they have a hidden
> hazard in that they can flood and overwhelm some MCUs (YMMV of
> course). A capacitor can help alleviate the problem but it's better to
> find a non-cap solution. I've found polling is better. I use a digital
> integration method (*) and a fast polling interval. That works so
> well, I automatically go to that design solution for most applications.
>
> * --- A digital integration method uses a counter that counts up and
> down and outputs a state change signal when a count threshold is
> reached. Increment the counter while the input is high and decrement
> the counter when the input is low. Reset the count when the output
> state changes. Adjust the polling interval for speed and accuracy. As
> a frame of reference, I use a 5 msec polling interval for keyboard
> debouncing. You'll probably want a faster interval if your encoder can
> be turned fast. I'll warn you that there can be a surprisingly large
> number of lines of code for such a simple task like digital debouncing.
>
> JJS
>
> On 8/6/2021 8:46 AM, Jean-Pierre Desrochers wrote:
>>
>> Hi everybody.
>>
>> I’m doing some tests on a rotary encoder and a PIC16F1783.
>>
>> A standard Bourns encoder like THIS
>> <https://www.google.ca/url?sa=t&rct=j&q=&esrc=s&source=web&cd=&ved=2ahUKEwjyoqDF3JzyAhUmhOAKHf3lAzoQFnoECAoQAw&url=https%3A%2F%2Fwww.bourns.com%2FPDFs%2Fpec11l.pdf&usg=AOvVaw2RyieyzPnujiOTS7LBcbpw>
>> .
>>
>> Connected using 2 x 10k pullups with 0.01uf caps to ground
>>
>> to PORTB of the micro. Interrupt calls (falling edges) used on
>> encoder pins A & B.
>>
>> I struggled so far to get clean increments/decrements out of it.
>>
>> Many missing counts occur..
>>
>> I tried many source codes on the web with no luck..
>>
>> Is there anybody who’d have worked on this in the past
>> and have a working c code ?
>>
>> No ARDIUNO please.
>>
>> Thanks !
>>
>>
>
> _______________________________________________
> Synth-diy mailing list
> Synth-diy at synth-diy.org
> http://synth-diy.org/mailman/listinfo/synth-diy
> Selling or trading? Use marketplace at synth-diy.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://synth-diy.org/pipermail/synth-diy/attachments/20210806/58bf14b1/attachment.htm>
More information about the Synth-diy
mailing list