
Brushless Hall Sensors: Return of Quadrature Encoders
- Tutorial
This is the third article about quadrature decoders, this time applying to the management of brushless motors.
Task: there is an ordinary Chinese brushless collector, you need to connect it to the Copley Controls 503 controller. Unlike the cheap penny controllers, the 503rd wants a signal from hall sensors that are not on the engine. Let's figure out what the sensors are for and how to put them.
As an illustration, I'll take a very common motor with twelve coils in the stator and fourteen magnets in the rotor. There are many options for winding and the number of coils / magnets, but the essence is always the same. Here is a photo of my copy on both sides, both the coils and magnets in the rotor are clearly visible:

To make it even clearer, I drew its diagram, the poles of the rotor magnets are indicated in color, red for the north and blue for the south:

Pay no attention to the hall sensors they are not there anyway :)
What happens if you apply a plus to pin V and a minus to pin W (we don’t connect pin U to anything)? Obviously, current will flow in the coils wound with a green wire. The coils are wound in different directions, so the upper two coils will be attracted to magnets 1 and 2, and the lower two to magnets 8 and 9. The remaining coils and magnets practically do not play a role in this configuration, so I highlighted magnets 1,2,8 and 9. With such a power-up of the motor, it obviously will not spin, and will have seven stable rotor positions evenly distributed over the entire circumference (the left upper green stator coil can attract magnets 1, 3, 5, 7, 9, 11, 13).
Let's write down our actions here in such a plate:
But what happens if we now apply a plus to U and a minus to W? Red coils will attract magnets 3,4,10 and 11, thus turning the rotor slightly (I still highlight the magnets that the rotor pulls):

Let's calculate how much the rotor will turn: between the slots of magnets 1-2 and 3-4, we have 51.43 ° (= 360 ° * 2/7), and between the corresponding slots in the stator 60 ° (= 360 ° / 12 * 2). Thus, the rotor will be turned at 8.57 °. Update our nameplate:
Now God himself ordered to submit + to U and - to V!

Now again it’s time to align the magnets with the green coils, so we apply voltage to them, but the red and blue magnets have switched places, so now we need to apply the reverse voltage:

With the remaining two configurations, everything is exactly the same:


If we repeat the very first step again, then our rotor will crank exactly one seventh revolution. So, in total, our motor has three outputs, we can apply voltage to two of them in six different ways 6 = 2 * C 2 3 , and we have already sorted them all out. If the voltage is applied not randomly, but in a strict order, which depends on the position of the rotor, the engine will rotate.
Let us write again the whole sequence for our engine:
There is one caveat: in a conventional collector motor, brushes are responsible for switching the windings, and here we need to determine the position of the rotor ourselves.
Now let's put the three hall sensors in those black dots indicated on the diagram. Let's agree that the sensor produces a logical unit when it is opposite the red magnet. In total there are six (surprise!) Possible states of three sensors: 2 3 - 2. There are 8 possible states in total, but due to the distance between the sensors they cannot all three be in a logical zero or in a logical unit:

Note that they generate three signals shifted relative to each other by 1/3 of the period. By the way, electricians use the word degrees, talking about 120 °, than completely confuse noobs like me. If we want to make our own motor controller, then just read the signal from the sensors, and accordingly switch the voltage on the windings.
To place the sensors, I used just such a scarf, the design of which I took here . The eagle project is under the link, so I just ordered a lot of similar

scarves from the Chinese: These scarves carry only three hall sensors, nothing more. Well, to the taste you can put capacitors, I did not bother. Very conveniently made long slots to adjust the position of the sensors relative to the stator.
Still would! The only difference is that incremental encoders give two signals shifted by 90 ° relative to each other, and we have three signals shifted by 120 °. What happens if you get any two of them on a regular quadrature decoder, for example, the same blue tablet ? We will be able to determine the position of the shaft with an accuracy of four counts per one seventh revolution, or 28 counts per revolution. If you do not understand what I mean, read the principle of operation of the quadrature decoder in the first article.
I thought for a long time, how can I use all three signals, because we have six events per one seventh revolution, we should be able to get 42 counts per revolution. As a result, I decided to go brute force, since the blue tablet has a bunch of hardware quadrature decoders, so I decided to get three counters in it:

It is clear that at each event we increase two of them, so adding up three counters and dividing by two, we we get a uniformly ticking shaft position determinant, with an accuracy of 6 * 7 = 42 counts per revolution!
This is how the layout of connecting Hall sensors to a blue tablet looks like:

In some applications (for example, for copters) all these troubles are not needed. The controllers are trying to guess what is happening with the rotor current in the coils. On the one hand, this is less of a problem, but on the other hand, it sometimes leads to problems with the moment the engine starts, so it is poorly applicable, for example, in robotics, where near-zero speeds are needed. Let's try to power our engine from the usual Chinese copter ESC (electronic speed controller).
My controller wants a PPM signal to enter: it is a pulse with a frequency of 50Hz, the pulse length sets the speed: 1ms - stop, 2ms - the maximum possible speed (considered as KV motor * voltage).
HereI uploaded the source code and Cuban files for the blue tablet. Timer 1 generates PWM for ESC, timers 2,3,4 count the corresponding quadrature signals. Since in the last article I painted in great detail where and what to click, here I only give a link to the source code.
At the entrance to my ESC, I give a sawtooth speed reference, let's see how it works. The output of the blue tablet lies here , and the code that draws the graph is here .
Since my engine has a rating of 400KV, and I applied 10V power, the maximum speed should be around 4000 rpm = 419 rad / s. Well, the schedule arrived in time:

It can be seen that the real speed corresponds to the task very approximately, which is tolerable for copters, but completely inapplicable in many other situations, which is why, in fact, I want to use more advanced controllers that need signals from hall sensors. Well, as a bonus, I get the angle of rotation of the rotor, which is extremely useful.
I spent my childhood in an embrace with this book, but I managed to smoke the principles of the work of brushless collectors only now.

It turns out that stepper motors and copter motors like this are (conceptually) the same thing. The difference is only in the number of phases: shagoviki (usually there are exceptions) are controlled by two phases shifted by 90 °, and brushless (again, usually) by three phases shifted by 120 °.
Of course, there are other, purely practical differences: the stepworms are designed to increase the holding torque and repeatability of the steps, while the copter engines speed and smoothness of rotation, which affects the number of windings, bearings, etc. But in the end, a conventional brushless collector can be used in step mode, and the step step in constant rotation, their control will be the same.
Update: beautiful animation from Arastas :

- Article one: the principle of operation of the quadrature decoder + code for arduino.
- Article two: quadrature decoder on stm32.
Task: there is an ordinary Chinese brushless collector, you need to connect it to the Copley Controls 503 controller. Unlike the cheap penny controllers, the 503rd wants a signal from hall sensors that are not on the engine. Let's figure out what the sensors are for and how to put them.
Likbez: the principle of operation of a brushless motor
As an illustration, I'll take a very common motor with twelve coils in the stator and fourteen magnets in the rotor. There are many options for winding and the number of coils / magnets, but the essence is always the same. Here is a photo of my copy on both sides, both the coils and magnets in the rotor are clearly visible:

To make it even clearer, I drew its diagram, the poles of the rotor magnets are indicated in color, red for the north and blue for the south:

Pay no attention to the hall sensors they are not there anyway :)
What happens if you apply a plus to pin V and a minus to pin W (we don’t connect pin U to anything)? Obviously, current will flow in the coils wound with a green wire. The coils are wound in different directions, so the upper two coils will be attracted to magnets 1 and 2, and the lower two to magnets 8 and 9. The remaining coils and magnets practically do not play a role in this configuration, so I highlighted magnets 1,2,8 and 9. With such a power-up of the motor, it obviously will not spin, and will have seven stable rotor positions evenly distributed over the entire circumference (the left upper green stator coil can attract magnets 1, 3, 5, 7, 9, 11, 13).
Let's write down our actions here in such a plate:
Rotor angle | U | V | W |
0 ° | nc | + | - |
But what happens if we now apply a plus to U and a minus to W? Red coils will attract magnets 3,4,10 and 11, thus turning the rotor slightly (I still highlight the magnets that the rotor pulls):

Let's calculate how much the rotor will turn: between the slots of magnets 1-2 and 3-4, we have 51.43 ° (= 360 ° * 2/7), and between the corresponding slots in the stator 60 ° (= 360 ° / 12 * 2). Thus, the rotor will be turned at 8.57 °. Update our nameplate:
Rotor angle | U | V | W |
8.57 ° | + | nc | - |
Now God himself ordered to submit + to U and - to V!

Rotor angle | U | V | W |
17.14 ° | + | - | nc |
Now again it’s time to align the magnets with the green coils, so we apply voltage to them, but the red and blue magnets have switched places, so now we need to apply the reverse voltage:

Rotor angle | U | V | W |
25.71 ° | nc | - | + |
With the remaining two configurations, everything is exactly the same:

Rotor angle | U | V | W |
34.29 ° | - | nc | + |

Rotor angle | U | V | W |
42.85 ° | - | + | nc |
If we repeat the very first step again, then our rotor will crank exactly one seventh revolution. So, in total, our motor has three outputs, we can apply voltage to two of them in six different ways 6 = 2 * C 2 3 , and we have already sorted them all out. If the voltage is applied not randomly, but in a strict order, which depends on the position of the rotor, the engine will rotate.
Let us write again the whole sequence for our engine:
Rotor angle | U | V | W |
0 ° | nc | + | - |
8.57 ° | + | nc | - |
17.14 ° | + | - | nc |
25.71 ° | nc | - | + |
34.29 ° | - | nc | + |
42.86 ° | - | + | nc |
There is one caveat: in a conventional collector motor, brushes are responsible for switching the windings, and here we need to determine the position of the rotor ourselves.
Hall sensors
Now let's put the three hall sensors in those black dots indicated on the diagram. Let's agree that the sensor produces a logical unit when it is opposite the red magnet. In total there are six (surprise!) Possible states of three sensors: 2 3 - 2. There are 8 possible states in total, but due to the distance between the sensors they cannot all three be in a logical zero or in a logical unit:

Note that they generate three signals shifted relative to each other by 1/3 of the period. By the way, electricians use the word degrees, talking about 120 °, than completely confuse noobs like me. If we want to make our own motor controller, then just read the signal from the sensors, and accordingly switch the voltage on the windings.
To place the sensors, I used just such a scarf, the design of which I took here . The eagle project is under the link, so I just ordered a lot of similar

scarves from the Chinese: These scarves carry only three hall sensors, nothing more. Well, to the taste you can put capacitors, I did not bother. Very conveniently made long slots to adjust the position of the sensors relative to the stator.
Wait, but this is very similar to a quadrature signal from a conventional incremental encoder!
Still would! The only difference is that incremental encoders give two signals shifted by 90 ° relative to each other, and we have three signals shifted by 120 °. What happens if you get any two of them on a regular quadrature decoder, for example, the same blue tablet ? We will be able to determine the position of the shaft with an accuracy of four counts per one seventh revolution, or 28 counts per revolution. If you do not understand what I mean, read the principle of operation of the quadrature decoder in the first article.
I thought for a long time, how can I use all three signals, because we have six events per one seventh revolution, we should be able to get 42 counts per revolution. As a result, I decided to go brute force, since the blue tablet has a bunch of hardware quadrature decoders, so I decided to get three counters in it:

It is clear that at each event we increase two of them, so adding up three counters and dividing by two, we we get a uniformly ticking shaft position determinant, with an accuracy of 6 * 7 = 42 counts per revolution!
This is how the layout of connecting Hall sensors to a blue tablet looks like:

And why are there no sensors on the engine right away?
In some applications (for example, for copters) all these troubles are not needed. The controllers are trying to guess what is happening with the rotor current in the coils. On the one hand, this is less of a problem, but on the other hand, it sometimes leads to problems with the moment the engine starts, so it is poorly applicable, for example, in robotics, where near-zero speeds are needed. Let's try to power our engine from the usual Chinese copter ESC (electronic speed controller).
My controller wants a PPM signal to enter: it is a pulse with a frequency of 50Hz, the pulse length sets the speed: 1ms - stop, 2ms - the maximum possible speed (considered as KV motor * voltage).
HereI uploaded the source code and Cuban files for the blue tablet. Timer 1 generates PWM for ESC, timers 2,3,4 count the corresponding quadrature signals. Since in the last article I painted in great detail where and what to click, here I only give a link to the source code.
At the entrance to my ESC, I give a sawtooth speed reference, let's see how it works. The output of the blue tablet lies here , and the code that draws the graph is here .
Since my engine has a rating of 400KV, and I applied 10V power, the maximum speed should be around 4000 rpm = 419 rad / s. Well, the schedule arrived in time:

It can be seen that the real speed corresponds to the task very approximately, which is tolerable for copters, but completely inapplicable in many other situations, which is why, in fact, I want to use more advanced controllers that need signals from hall sensors. Well, as a bonus, I get the angle of rotation of the rotor, which is extremely useful.
To summarize
I spent my childhood in an embrace with this book, but I managed to smoke the principles of the work of brushless collectors only now.

It turns out that stepper motors and copter motors like this are (conceptually) the same thing. The difference is only in the number of phases: shagoviki (usually there are exceptions) are controlled by two phases shifted by 90 °, and brushless (again, usually) by three phases shifted by 120 °.
Of course, there are other, purely practical differences: the stepworms are designed to increase the holding torque and repeatability of the steps, while the copter engines speed and smoothness of rotation, which affects the number of windings, bearings, etc. But in the end, a conventional brushless collector can be used in step mode, and the step step in constant rotation, their control will be the same.
Update: beautiful animation from Arastas :
