| General > General Technical Chat |
| Schmitt Buffer/Trigger with Encoder and buttons - Inverting... |
| << < (3/8) > >> |
| julian1:
The rotary encoder has a 90degree relationship between edges, which provides lots of setup and hold time, when sampling levels. Unlike a (tactile) switch, I *don't think* hardware debouncing actually gains you anything - regardless of whether decoding is done software or hardware. |
| Buriedcode:
If you don't want inverted outputs - just use two inverters in series? Also, with regards to reading rotary encoders, I've found sampling is far more reliable than running on interrupts. Sure, you can use interrupts at the start to interrupt your code to tell it someone is using the encoder, but a timer, periodically checking the status at a reasonable rate (200-500Hz?) once its detected provides more reliable results. Micros run so fast that routines that just constantly check the encoders output are effectively sampling at MHz and will pick up glitches. Of course, an RC filter + schmitt trigger will help to cut these down, but you have to handle the encoder in software anyway, and you might have to play around with RC values if you want to get nice "clean" phasing between the two channels of the encoder. It's extra hardware for something that can (and should) be done in software. I generally just put on 10k/2.2n and connect straight to an IO. |
| MarkF:
--- Quote from: elcrni on March 16, 2021, 01:39:41 pm ---Thanks MarkF! Yes, that's the way i have it, sorry my scheme doesn't show that resistor on the signal line, just the pull-up one. But yes, i am using RC filter the way you have it in your scheme, but, i have 220 ohm resistor on the signal line instead of 10k. Many thanks, Alek --- End quote --- A 220 Ω resistor and a 47nF capacitor really are NOT doing much for you. Remember the RC cutoff frequency is: f = 1 / (2 * π * R * C) 220Ω and 10nF = 15000 Hz (very little impact on response) 10KΩ and 10nF = 1600 Hz (recommended values by Bourns PEC11 encoders) 10KΩ and 47nF = 340 Hz (okay if you don't turn the knob very fast) |
| elcrni:
Many thanks for all your help guys! Lots of helpful tips. As for the encoder, i have always and exclusively used it on interrupt pins, which was ok for most of the projects but now i have a radio signal encoder and analyzer, and once i activate encoder and start turning the knob, i get radio signal decoding errors, i would guess this is due to the fact that interrupt is stopping other processes to execute encoder input. So, i would gladly try the other way suggested by "Buriedcode"... but not sure how the code would look like, will search for examples. thanks again guys! Alek |
| MarkF:
I assume you're saying 'interrupt on change'? In which case, you will get many many interrupts if the encoder is noisy. I use a fixed 500Hz interrupt to sample the encoder lines and only decode the encoder gray_code setting a global variable with a positive or negative number with the number of turns/detentes. Increment the global count for clockwise turns and decrement the count for counter-clockwise turns. After which, you use the global count outside the interrupt routine (i.e. the main loop) and clear it for the interrupt routine to restart the counting. Inside the main loop, I copy the global count into a local variable and clear the global variable right away to avoid missing any counts. Use the local variable count inside the main loop. Note that you will NOT be processing each individual change but the number of counts since your last pass through the main loop. The 500Hz sample rate works pretty well for me. I would not sample much slower the 500Hz. A 'fixed' sample rate avoids bursts of interrupts from noisy encoder lines. You could almost consider it a form of debounce because the encoder lines can settle some between samples. |
| Navigation |
| Message Index |
| Next page |
| Previous page |