Debounced rotary encoder module

  Рет қаралды 6,713

Curious Scientist

Curious Scientist

Күн бұрын

Check out PCBWay's website for rapid prototyping of printed circuit boards, CNC and 3D printing services and many more! pcbway.com/g/m...
Check out PCBWay's 6th Project design contest!
www.pcbway.com...
In this video, I show you my approach to making a rotary encoder module. One can buy different rotary encoder modules on Aliexpress for a very cheap price, and I have been doing that for years, too. However, I wanted to come up with my own version of such a module. Typical modules either only contain some pull-up resistors, or they even have RC low-pass filters, but I haven’t encountered any that have a built-in Schmitt trigger circuit that allows to produce perfect square waves.
Please subscribe to my channel!
Check my article: www.curioussci...
Support me on Patreon:
Get this circuit from PCBWay: www.pcbway.com...

Пікірлер: 12
@moeburn
@moeburn 10 ай бұрын
Here's how to do it in code: enum { PinA=2, PinB=3, IPINMODE=INPUT }; static byte abOld; // Initialize state volatile int count; // current rotary count int old_count; // old rotary count void setup() { pinMode(PinA, IPINMODE); pinMode(PinB, IPINMODE); attachInterrupt(0, pinChangeISR, CHANGE); // Set up pin-change interrupts attachInterrupt(1, pinChangeISR, CHANGE); abOld = count = old_count = 0; Serial.begin(115200); Serial.println("Starting Rotary Encoder Test"); } // On interrupt, read input pins, compute new state, and adjust count void pinChangeISR() { enum { upMask = 0x66, downMask = 0x99 }; byte abNew = (digitalRead(PinA)
@CuriousScientist
@CuriousScientist 10 ай бұрын
Thank you! I pinned this comment so other viewers can see it more easily. I will try this code and then probably make a short clip about it.
@Ender_Wiggin
@Ender_Wiggin 10 ай бұрын
Cool but have to say seems a bit overkill. For normal micro switches you want that level of debounce if you want a fast response but the encoder look quite good. Keep in mind most decent micro controllers already have a schmitt trigger input.
@CuriousScientist
@CuriousScientist 10 ай бұрын
Hi! Thanks! Yes, I know it is a bit of an overkill, I even mentioned this in my article on my website. However, it is a great project (at least for me) to understand the topic. Hopefully, others will also learn from it. I am also aware of the built-in Schmitt triggers, but as I said in the video, sometimes we want to use encoders in a circuit without a microcontroller. Maybe it is more useful there.
@ivolol
@ivolol 10 ай бұрын
The pulses of a two state rotary encoder have a set of valid state transitions. Given current state X,Y the only valid transitions are the previous state and the next, and there are four transitions from the combination of 2 bit states. If you use a very simple state machine algorithm in your MCU, which tracks the state, and at any time it receives interrupts from the encoder, it checks that the new state is either the valid next or previous state (for forwards/backwards) and if and only if it was, then advances in program logic, you already get a very satisfactory response that is 90% cleaned up from the naive algorithm, even with no RC filter etc. If you turn the big audio encoder on knobs on a bunch of different brands of cars, and check if they sometimes recedes backwards when you do a fast spin forwards or if it just gets glitchy, you can check if the people making the interface used the naive algorithm or the state machine one :)
@CuriousScientist
@CuriousScientist 10 ай бұрын
Absolutely! I also mentioned this that probably it is already solvable via code. I just wanted to take the hardware approach to learn more about it. There is a very nice article and discussion on Hackaday around this topic, you've probably already came across it: hackaday.com/2022/04/20/a-rotary-encoder-how-hard-can-it-be/
@lancelot4915
@lancelot4915 6 ай бұрын
Thanks a lot for the explanation and video. I'm building myself a diy generic sim cockpit and this circuit comes perfect to help solve the bouncing issues i have with the encoders. My trials to solve it by code have been poor on the results. And since i'm making my own pcb, and i have very limited knowledge on electronics, your circuit falls like a gift from heaven!! 🎁
@CuriousScientist
@CuriousScientist 6 ай бұрын
Hi! It is great to hear that my circuit can help you! I hope you'll have fun with the sim cockpit once it's done with the new encoders.
@sebastiannielsen
@sebastiannielsen 10 ай бұрын
A cool idea would be to convert this to a UP/DOWN pulse. Like this: A + B is connected to D and CLK of a D-flip flop A + B is also connected to a XOR gate Output of XOR gate, is connected to input A of 2 AND gates. Input B of And-gate 1 is connected to Q of D-flipflop. Input B of And-gate 2 is connected to /Q of D-flipflop. Now you have a up pulse when the encoder is rotated clockwise, and a down pulse when encoder is rotated anticlockwise. ---------------------------------------------------------------------------------------------------- Next addition to the circuit would be following: A shifted rotary encoder. By using the push button as shift mechanism. This requires 4 more and-gates + 1 NOT gate. A + B is connected to D and CLK of a D-flip flop A + B is also connected to a XOR gate Output of XOR gate, is connected to input A of 2 AND gates. Input B is connected to pushbutton output, BUT with a NOT-gate in front of one of the AND gate. Call these AND-gates P and /P. Output of P is connected to Input A of 2 AND-gates, call these 1 and 2. Output of /P is connected to input A of 2 additional AND-gates, call these 3 and 4. Input B of And-gate 1 & 3 is connected to Q of D-flipflop. Input B of And-gate 2 % 4 is connected to /Q of D-flipflop. Now you have 2 separate UP/DOWN pairs, one UP/DOWN pair that will actuate when you turn rotary encoder, and one UP/DOWN pair that will actuate when you PUSH and TURN the rotary encoder, acting as a shift level. Finish with some timer, that will extinguish the signal after half a second or 0.25 second, since some equipment don't like its up or down button being held down. After that, you will have a nice "Convert UP/DOWN button to rotary encoder circuit".
@CuriousScientist
@CuriousScientist 10 ай бұрын
Thanks! I don't know where I could use this circuit, but it definitely sounds interesting. At this point, I am happy with this debounced encoder, I do not want to (and I don't need it) make it more complicated.
@Aaron_Dayton
@Aaron_Dayton 10 ай бұрын
Good job! This is totally not overkill, I saw some kits on tindie a while back that converted the output to i2c. I really like your approach! minimal parts and great explanation. This kit should be the new standard on parts available on amazon/ebay/everywhere. I wouldn't mind paying a couple more nickels if it didn't mean pulling my hair out trying to troubleshoot these on an esp32. Cheers! Love the project and attention to detail.
@CuriousScientist
@CuriousScientist 10 ай бұрын
Thank you! I wonder if people will start to adopt this technique, but probably it is "too expensive" on a large (or industrial) scale to add the Schmitt trigger. You can save ~400 USD if you don't use it for every 1000 boards. Also, the double-sided PCB might be challenging to solder. However, I think it is still a cool project for hobby makers. If you end up trying this design for your ESP32 projects, please let me know how it went.
Stepper motor developing platform with TMC2209 and AS5600
37:48
Curious Scientist
Рет қаралды 5 М.
Pimp My Potentiometer (again)
27:19
upir
Рет қаралды 82 М.
Brawl Stars Edit😈📕
00:15
Kan Andrey
Рет қаралды 58 МЛН
HAH Chaos in the Bathroom 🚽✨ Smart Tools for the Throne 😜
00:49
123 GO! Kevin
Рет қаралды 16 МЛН
Rotary Encoder (KY-040) Debounce Circuit Tutorial
15:03
ForceTronics
Рет қаралды 18 М.
ADS1256-RP2040 DAQ module - Improved front panel GPIO connector
8:06
Curious Scientist
Рет қаралды 747
Mining Magnetite
16:20
Cody'sLab
Рет қаралды 370 М.
Introduction to Homemade CPUs (EP 62)
22:51
Doctor RG Plague
Рет қаралды 2,6 М.
This Component solves "All" Motor Problems?! (Motor Encoder) EB#58
11:34
Radxa X4: An N100 Pi
20:48
ExplainingComputers
Рет қаралды 54 М.
#96 Rotary Encoder Update - Stepless & Software Debounced
37:46
Ralph S Bacon
Рет қаралды 41 М.
Revolutionize Your ESP32 Projects with Live GPIO Pin Monitoring!
8:08
The Last Outpost Workshop
Рет қаралды 175 М.
Digital Potentiometer and Rotary Encoder Direct Control X9C103
14:05
Brawl Stars Edit😈📕
00:15
Kan Andrey
Рет қаралды 58 МЛН