Understanding and using quadrature encoders - The Byte Sized Engineer | DigiKey

  Рет қаралды 5,367

DigiKey

DigiKey

5 ай бұрын

When working on projects, sometimes it's really useful to be able to track the rotation of an object. Whether that's the shaft of a spinning motor, or a knob that you turn to select an item on a user interface. In this post I'll talk about how encoders work, and how to read them with a microcontroller. I'll even go over a couple of mistakes that I've made that you should avoid. Encoders come in two different varieties. There's the electromechanical kind that have physical switches that open and close inside them. Then there are the contactless kind that usually use magnetic fields or light to detect the rotating shaft.
Bill of materials
Rotary encoder: www.digikey.com/short/d4pn3mj2
Limit Switch: www.digikey.com/short/8j5jchvf
Nema 17 Stepper motor: www.digikey.com/short/b9fzpttt
Fluke 117 Multimeter: www.digikey.com/short/q2jqvjhj
Resistor Kit: www.digikey.com/short/q4w7wj75
Jumper Wire Kit: www.digikey.com/short/8n0p92pn
Rigol DS1054 Oscilloscope: www.digikey.com/short/3j4b3vrb
Geared DC motor with encoder: www.digikey.com/short/9bd8mh0v
Arduino Nano Microcontroller: www.digikey.com/short/bzc8j5wn
Breadboard: www.digikey.com/short/nbh4q298
Github project: github.com/bytesizedengineeri...
Learn More:
What is Switch Bounce and How to Debounce • What is Switch Bounce ...
Byte Sized Engineer channel - / @bytesizedengineering
Maker.io - www.digikey.com/en/maker
DigiKey’s Blog - TheCircuit www.digikey.com/en/blog
Connect with DigiKey on Facebook / digikey.electronics
And follow us on X: / digikey

Пікірлер: 14
@saddle1940
@saddle1940 5 ай бұрын
Watch out, the code doesn't miss pulses, it can now add phony pulses. Lots of jobs with quadrature encodered motors need to halt and hold position, but if yours bounces back and forward on the single interrupt edge, you may miss it being a pulse opposite to the last one. The best way to do this is to interrupt on one line, then change the interrupt to the other line. That way you can bounce up and down on one line, but after the first change, it will ignore it. You only look at the stable, non-interrupt input. The code should be: On an interrupt on line A, record the state of line B and change the active interrupt to line B. On an interrupt on line B, record the state of line A and change the active interrupt to line A. The recorded AB states tell you the rotation direction at each interrupt. Had many problems with software interrupted quadrature counting on long lead screws that "ring" (rotationally vibrate) as they hit a physical end stop or work piece.
@f-s-r
@f-s-r 5 ай бұрын
That's surprinsingly easy and very clever. Great explanation!!
@earthlightsmusic2743
@earthlightsmusic2743 5 ай бұрын
This is a good beginning. The ultimate is where your ISR handles a change of state on either input A or input B, so you get the maximum possible resolution of encoder position.
@paulz8750
@paulz8750 5 ай бұрын
Great video. Wish I'd seen it sooner. Just like you, I've spent days too, looking at everything else thinking the problem is elsewhere.
@parkesdj
@parkesdj 5 ай бұрын
Great video very clearly explained. I have a question though. If you are using CHANGE to trigger the interrupt, won’t it double count because you will trigger on both the rising and falling edges.
@danielatbasementtech
@danielatbasementtech 5 ай бұрын
Very clearly explained ... great lesson.
@JonathanRansom
@JonathanRansom 5 ай бұрын
I need to play with some encoders. Great video!
@larrybud
@larrybud 5 ай бұрын
Great stuff!
@bob_mosavo
@bob_mosavo 5 ай бұрын
Thanks, Zack 👍
@SweSausage
@SweSausage 4 ай бұрын
Very good video, thank you
@JonitoFischer
@JonitoFischer 5 ай бұрын
There are microcontrollers that have a dedicated peripheral to handle your quadrature encoder without handling gpio interrupts and checking pin state manually.
@jeremiahbullfrog9288
@jeremiahbullfrog9288 5 ай бұрын
Don't you also need to use an atomic_block to prevent the ISR from updating the long variable in the middle of trying to read it in the main loop? ...or does the arduino framework handle this autmotically?
@DanielSimu
@DanielSimu 5 ай бұрын
I'm confused about the comment that it's a bad idea to use mechanical switches. Aren't most basic dial encoders (the ones you typically turn by hand) operated somewhat like this? (but with contacts instead of bumps) Also, as for magnetic encoders, what's the benefit of using a quadrature encoder when it's also cheap and effective to read absolute position using a diametric magnet?
@LubosMedovarsky
@LubosMedovarsky 5 ай бұрын
Simply put, mechanical contacts make sparks, which translates to chaotic sequence of ones and zeros. This erroneous state is then interpreted incorrectly as missed counts and incorrect direction. Engineers prefer being sure instead.
This Component solves "All" Motor Problems?! (Motor Encoder) EB#58
11:34
Smart Sigma Kid #funny #sigma #comedy
00:25
CRAZY GREAPA
Рет қаралды 39 МЛН
Я нашел кто меня пранкует!
00:51
Аришнев
Рет қаралды 5 МЛН
Scientific Concepts You're Taught in School Which are Actually Wrong
14:36
Rotary Encoders: A Comprehensive Guide to Understanding and Using Them
7:44
Forget WiFi! This Wireless Method is WAY Better?
12:14
GreatScott!
Рет қаралды 510 М.
How to use rotary encoders
14:12
FriendlyWire
Рет қаралды 30 М.
The Micro Mechanisms in Your Phone
19:31
Breaking Taps
Рет қаралды 1,2 МЛН
477 Use the very attractive new ATTINY chips for your projects
14:34
Andreas Spiess
Рет қаралды 202 М.
Magnetic rotary encoder vs stepper motor accuracy
5:41
Matthias random stuff
Рет қаралды 142 М.
How to use encoders (Optical, Hall Effect, Quadrature)
20:44
Will Donaldson
Рет қаралды 103 М.
Отдых для геймера? 😮‍💨 Hiper Engine B50
1:00
Вэйми
Рет қаралды 1,3 МЛН
ОБСЛУЖИЛИ САМЫЙ ГРЯЗНЫЙ ПК
1:00
VA-PC
Рет қаралды 2,1 МЛН
Как бесплатно замутить iphone 15 pro max
0:59
ЖЕЛЕЗНЫЙ КОРОЛЬ
Рет қаралды 60 М.
Что делать если в телефон попала вода?
0:17
Лена Тропоцел
Рет қаралды 982 М.
КРУТОЙ ТЕЛЕФОН
0:16
KINO KAIF
Рет қаралды 6 МЛН
Samsung Galaxy 🔥 #shorts  #trending #youtubeshorts  #shortvideo ujjawal4u
0:10
Ujjawal4u. 120k Views . 4 hours ago
Рет қаралды 8 МЛН