Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Questions about the rotary encoder

Status
Not open for further replies.

bhl777

Full Member level 6
Joined
Sep 30, 2008
Messages
363
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,296
Activity points
5,140
Hi all,

I am learning the operation of a rotary encoder, and I have used this one (https://www.epitran.it/ebayDrive/datasheet/25.pdf) to connect to Arduino Uno. The schematic is shown below.
When I rotate the encoder, I also captured the waveform of channels A and B.
We can tell the orientation by looking at that channel A is leading channel B. In addition to this, I also want to see how much more information we can get from this waveform.
rotary encoder waveform.png

My questions are:
(1) are the numbers of the pulses or anything else helpful to figure out the rotation speed when I turned the encoder?
(2) does the pulse width matter? Using channel A (the yellow trace) as the example. Since the default state is high, if I define the "pulse" as the one that goes from high to low, we can tell there are five "pulses", the first four pulses are with a similar width of "low", while the last one's width is much higher. How can we relate the pulse width to any physical performance of the rotary encoder?
(3) in addition to the number of pulses and their width of them, is there anything else we can tell by observing this waveform?
Thank you!
 

Each channel state transition indicates an incremental rotation, either clock- or counter-clockwise depending on the state of the other channel. Respectively pulse groups 1-4 indicate an unidirectional (clockwise) rotation, continued by 5 falling edge. 5 rising edge is CCW. For a detailed explanation of incremental encoder operation see https://en.m.wikipedia.org/wiki/Incremental_encoder

Pulse width is inversely proportional, however you'll decode individual transitions rather than "pulses". The Arduino code in the manual is no good decoder algorithm, it counts only half of the available transitions.
 
  • Like
Reactions: bhl777

    bhl777

    Points: 2
    Helpful Answer Positive Rating
Hi all,

I am learning the operation of a rotary encoder, and I have used this one (https://www.epitran.it/ebayDrive/datasheet/25.pdf) to connect to Arduino Uno. The schematic is shown below.
When I rotate the encoder, I also captured the waveform of channels A and B.
We can tell the orientation by looking at that channel A is leading channel B. In addition to this, I also want to see how much more information we can get from this waveform.
View attachment 182238
My questions are:
(1) are the numbers of the pulses or anything else helpful to figure out the rotation speed when I turned the encoder?
(2) does the pulse width matter? Using channel A (the yellow trace) as the example. Since the default state is high, if I define the "pulse" as the one that goes from high to low, we can tell there are five "pulses", the first four pulses are with a similar width of "low", while the last one's width is much higher. How can we relate the pulse width to any physical performance of the rotary encoder?
(3) in addition to the number of pulses and their width of them, is there anything else we can tell by observing this waveform?
Thank you!
1) when more than 1 pair of AB pulses have the same phase , either A leading or B leading , then speed is the fixed distance divided by some Time interval count. When the direction is known to be determined by which phase is leading A or B, then distance is counted up or down.
2) Pulse width increases as speed reduces. When Yellow Toggles 111000111 while Blue stays high, we know the direction has changed momentarily but far enough to be counted as Blue both must cycle to count distance
3) yes , we can observe both A,B detectors are not equidistant because the duty cycle is not 50% in quadrature, so you cannot interpolate and need a full cycle to count distance.

__-___-___-___-__
___-___-___-___-__ so the quadrature is not 50% duty cycle, but this is not essential.

the State Diagram below

1681135398659.png

The Error above is eliminated using synchronized latch input sampling which is the AB sum of XOR of input and previous sample

Quadrature decoders can be used with Flip Flops and Gates or in firmware logic alike have been around for a very long time.
 
Last edited:
  • Like
Reactions: bhl777

    bhl777

    Points: 2
    Helpful Answer Positive Rating
Hi D.A.(Tony)Stewart and FvM,
Thank you both for your education!
In my project, I want to use the turning of this rotary encoder to turn on the motor. And the block diagram I was thinking of is like this:
close loop question.png

In the block diagram above,
(1) the rotary encoder is the one I was talking about in the discussion above.
(2) And I want to convert the signal from both channel A and channel B to a STEP command and a DIR command through an unknown red circuit, which can be either a dedicated signal processing circuit or part of the microcontroller (MCU) that will use to process. From a high level perspective, what I want includes:
- when I turn the rotary encoder clockwise, the motor is turning in one direction
- similarly, when the rotary encoder is turned counterclockwise, the motor is turning toward the reverse direction
- ideally, when I turn the rotary encoder at a higher speed, the motor should move faster. But from the first-order implementation, this is not required.
(3) then once I get a command for STEP and DIR, the closed-loop implementation has been done in several projects, such as https://www.hackster.io/news/transf...h-driver-and-servo-functionality-678d15fe052a.

My questions are:
1. for the red unknown block, if the red block should be a standalone IC for this signal processing, what type of circuits can I use to convert the signal from the rotary encoder's channel A and channel B to the step signal and the direction signal?
2. if this conversion can be done using part of the circuit of the MCU (this means the red and the green blocks can belong to the same board, like Arduino UNO), what information do I need to do the coding?
3. what kind of correlation should I establish between the rotary encoder's channel A&B waveform and the STEP command regarding speed control?

Thank you!
 

Hi,

I'm a bit surprised about all the questions..it seems you don't understand step/dir and don't understand encoder.
All in all your sketch (to me)shows a solution for a non existing problem.

If you just want the functions 1), 2) and 3) .... what keeps you from directly connecting the encoder to the step/dir driver (no need for red and blue boxes at all)

Red box:
What's the benefit of a rotary-to-step/dir interface in front of a microcontroller? The red box has two digital inputs and two digital outputs, and the "position information" comes with the same frequency on both sides. So in either case you need to decode a two-input-signal "simultaneously" because you never know which one comes first.
The red box usually is used when there is a solution without microcontroller.
Thus for every solution:
* hardware using logic ICs
* hardware using PLD including code
* microcontroller solution using interrupts, including code
* microcontroller polling mode, including code
... there are many thousands sites, documents, examples, even videos in the internet. Just do a search.

Blue box:
As said, for the given requirements you don't need a microcontroller at all. We just see: step/dir in, step/dir out. So we miss informations what it is good for. Please tell us.

In either case I recommend to do an internet search and to watch some videos ... to understand how the encoder and the driver works.
Then find out "if there is a problem at all".
And if there is:
* tell us your requirements (especially the problematic ones)
* tell us the problem you see
* don't try to find a solution without a clear description of the problem

Klaus
 

microcontroller solution using interrupts, including code
* microcontroller polling mode, including code
... there are many thousands sites, documents, examples, even videos in the internet. Just do a search.

Blue box:
As said, for the given requirements you don't need a microcontroller at all. We just see: step/dir in, step/dir out. So we miss informations what it is good for. Please tell us.
Hello KlausST,

While I acknowledge your statement about my NOT understanding of step/dir and encoder, I disagree with your conclusion that I am trying to find a solution for a non-existent problem.

The context is, I want to learn the encoder, the step/dir, and the microcontroller programming and I want to combine everything together and learn the mechanism by playing with the code and probing the waveforms.

Here are my inputs to your comments and any feedback is highly appreciated.
(1) [KlausST] If you just want the functions 1), 2) and 3) .... what keeps you from directly connecting the encoder to the step/dir driver (no need for red and blue boxes at all)
[ my Answer:
(a) direct connect the rotary encoder to the step/dir driver is to create an open loop system, while in my case this is a closed loop system, which uses the step/dir signals and also the feedback signal from the encoder signal from the motor's rotation. This encoder is not the rotary encoder
(b) you can say a typical use case is to let dir/step run in an open loop condition. However, in my case, I want to follow the multiple examples online to create the closed-loop system, so I can play with the PID control library.
(c) in addition to the closed loop one, if you look at my signal from the rotatry encoder, you can see we definably cannot connect them together to the step/dir directly. The rotary encoder's output in channel A and channel B are normally high and only dips to 0V, while the step signal should be a normally low signal with some pulses, and the dir signal is either high or low. I think you also realized this because you also mention this in some of your comment
(d) in my immediate need, I t want the functions 1), 2) and 3) ...., but in my final implementation, I want to use my manual rotation speed to control the speed of the motor as well. Therefore, I want to solve the problem one by one.

(2) [KlausST] Red box: What's the benefit of a rotary-to-step/dir interface in front of a microcontroller? The red box has two digital inputs and two digital outputs, and the "position information" comes with the same frequency on both sides. So in either case you need to decode a two-input-signal "simultaneously" because you never know which one comes first.
The red box usually is used when there is a solution without microcontroller.
Thus for every solution:
* hardware using logic ICs
* hardware using PLD including code
* microcontroller solution using interrupts, including code
* microcontroller polling mode, including code

[Answer:
in no.2 of my previous questions, I tried to do this as a part of the microcontroller, which means it is the same as the green box. As I mentioned in (d) part of the answer to your question 1, I do not know MCU, step/dir, and encoder enough to see if I should make its first order right]

(3) [KlausST] Blue box: As said, for the given requirements you don't need a microcontroller at all. We just see: step/dir in, step/dir out. So we miss informations what it is good for. Please tell us.
[Answer: if you look at my schematic carefully, you can see this is a closed-loop system. The blue box is a simple driver that converts the command signal to the power level, while the step/dir in of it should be a processed signal based on the PID control code inside the microcontroller]

(4) [KlausST] In either case I recommend to do an internet search and to watch some videos ... to understand how the encoder and the driver works. ..
Then find out "if there is a problem at all".
And if there is:
* tell us your requirements (especially the problematic ones)
* tell us the problem you see
* don't try to find a solution without a clear description of the problem
... there are many thousands sites, documents, examples, even videos in the internet. Just do a search.

[Answer:
I acknowledge that if I'm asking a straightforward question that can be easily answered with a quick Google search, it's my responsibility to search before asking. However, this project is something I came up with on my own, and I've put effort into learning both from theory and practical aspects. I'm asking questions based on the unique hardware on my bench and the specific problems I'm facing. It is not something I can get by a simple search.
While I appreciate your time and technical input, your comment doesn't directly address my issue or positively contribute to the community. It discourages me from further participating in discussions on this forum.]
 

Hi,

I spent half an hour to reply to your post from top to bottom. ... unitil I read your last sentence.

So I deleted the whole text, and just say: sorry, this was not my intention.


Bye
Klaus
 

Hi,

I spent half an hour to reply to your post from top to bottom. ... unitil I read your last sentence.

So I deleted the whole text, and just say: sorry, this was not my intention.


Bye
Klaus
Hello KlausST,
Again, all your technical input is highly appreciated, which is part of my previous reply.
Although I feel some of your non-technical inputs are discouraging, it does not mean I will not continue to ask questions in this forum. If you think it is a waste of your time to reply to me, I respect that and will not complain.
 

Step Pulse + Direction logic is how floppy and hard disks started with stepper motors that use quadrature phase position control in full steps and 200 steps per rev.

This is open-loop until it is calibrated with an index pulse 1/rev or an end stop or home switch.

BL+DC motors use quadrature phase direction to control the transition of FET bridges in Fans and other examples to spin at the maximum speed or at some synchronous speed. The Hall sensors detect the magnet polarity points needed to prevent the motor from stalling from error in detecting this magnetic null position for detecting polarity of magnetic force. If the null position drifts from aging or temperature drift, the fan will fail or needs a hand spin to get started.

Once you learn enough, then you can define a problem with specs and then work on a solution.
I suggest you keep learning about all the different servo designs, reading, then asking better questions to get better answers. Search engines will help at first.
 

    bhl777

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top