Finger vector motor control
- Tutorial
- What is vector management?
- Keep current at 90 degrees.
The term "vector control" of electric motors is familiar to everyone who is at least somehow interested in the question of how to control an AC motor using a microcontroller. However, usually in any book on electric drives, the chapter on vector control is somewhere closer to the end, consists of a bunch of hairy formulas with references to all other chapters of the book. Why do not want to understand this issue at all. And even the simplest explanations still go the way through differential equations of equilibrium, vector diagrams and a bunch of other mathematics. Because of what about theseattempts to somehow spin the engine without using the mat.part. But in fact, vector control is very simple, if you understand the principle of its work "on the fingers." And there it will be more fun to deal with formulas if necessary.
Consider the principle of operation of the simplest AC motor - a synchronous machine with permanent magnets. A convenient example is a compass: its magnetic needle is the rotor of a synchronous machine, and the Earth’s magnetic field is the stator’s magnetic field. Without an external load (and it is not in the compass, except for friction and fluid damping the oscillations of the arrow), the rotor is always oriented along the stator field. If we hold the compass and rotate the Earth beneath it, then the arrow will spin after it, doing the work of mixing the fluid inside the compass. But there is also a slightly simpler way - you can take an external magnet, for example, in the form of a rod with poles at the ends, the field of which is much stronger than the Earth’s magnetic field, bring it to the compass from above and rotate the magnet. The arrow will follow the rotating magnetic field. In a real synchronous motor, the stator field is created by electromagnets - current coils. The winding circuits there are complex, but there is one principle - they create a stator magnetic field directed in the right direction and having the desired amplitude. Let's look at the following figure (Figure 1). In the center is a magnet - the rotor of a synchronous motor (compass needle), and on the sides are two electromagnets - coils, each creating its own magnetic field, one in the vertical axis and the other in the horizontal.

Figure 1. The principle of operation of a synchronous electric machine The
magnetic flux of the coil is proportional to the current in it (in a first approximation). We will be interested in the magnetic flux from the stator in the place where the rotor is located, i.e. in the center of the figure (we neglect the edge effects, scattering, and everything else). The magnetic fluxes of two perpendicularly arranged coils are vectorized, forming one common flux for interaction with the rotor. But since the flow is proportional to the current in the coil, it is convenient to draw directly the current vectors, aligning them with the flow. The figure shows some currents I α and I β , creating magnetic flux along the axes α and β, respectively. The total stator current vector I screates a co-directional magnetic flux of the stator. Those. in fact, I s symbolizes an external magnet, which we brought to the compass, but created by electromagnets - coils with current.
In the figure, the rotor is in an arbitrary position, but from this position the rotor will tend to rotate according to the magnetic flux of the stator, i.e. according to the vector I s (the position of the rotor in this case is shown by a dashed line). Accordingly, if the current is applied only to phase α , say, I α = 1A, the rotor will rise horizontally, and if in β, vertically, and if I β = -1A, then it will turn 180 degrees. If you feed current I αaccording to the law of sine, and I β according to the law of cosine from time to time, a rotating magnetic field will be created. The rotor will follow it and spin (as the compass needle follows the rotation of the magnet with his hands). This is the basic principle of a synchronous machine, in this case, two-phase with one pair of pluses.
Let's draw a graph of the motor torque depending on the angular position of the rotor shaft and the stator current vector I s — the angular characteristic of the synchronous motor. This relationship is sinusoidal (Figure 2).

Figure 2. The angular characteristic of the synchronous machine (there is some historical confusion with the signs of the moment and angle, because of which they often draw the characteristic inverted relative to the horizontal axis).
To get this graph in practice, you can put a torque sensor on the rotor shaft, then turn on any current vector, for example, just apply current to phase α. The rotor will rotate to the appropriate position, which must be taken as zero. Then, through the moment sensor “by hands”, it is necessary to turn the rotor, fixing the angle θ at each point on the graphturned on, and the moment the sensor showed. Those. you need to stretch the "magnetic spring" of the engine through a torque sensor. The largest moment will be at an angle of 90 degrees from the current vector (from the beginning). The amplitude of the resulting maximum moment M max is proportional to the amplitude of the applied current vector. 1A will be applied, we get, say, M max = 1 N ∙ m (newton * meter, unit of torque), if we give 2A, we get M max = 2 N ∙ m.
From this characteristic it follows that the motor develops the greatest moment when the rotor is at 90 ° to the current vector. Since when creating a control system on a microcontroller we want to get the greatest moment from the motor with a minimum of losses, and the loss, first of all, is the current in the windings, it is most rational to set the current vector always at 90 ° to the rotor magnetic field, i.e. perpendicular to the magnet in Figure 1. You need to change the opposite - the rotor does not go to the current vector we set, but we set the current vector always at 90 ° to the rotor, no matter how it rotates there, i.e. "Beat" the current vector to the rotor. We will regulate the motor torque by the amplitude of the current. The larger the amplitude, the higher the moment. And the rotation frequency, the frequency of the current in the windings is already “not our” business - what happens, how the rotor will rotate, it will be so - we control the moment on the shaft. Oddly enough, this is what is called vector control - when we control the stator current vector so that it is 90 ° to the magnetic field of the rotor. Although some textbooks give broader definitions, to the extent that any control laws where “vectors” are involved are called vector control, but usually vector control refers to the above control method.
But how is vector control achieved in practice? Obviously, for starters, you need to know the position of the rotor, so that you can measure 90 ° relative to what. This is easiest to do by installing, in fact, a position sensor on the rotor shaft. Then you need to figure out how to create a current vector, maintaining the desired currents in the phases α and β . We apply voltage to the motor, not current ... But since we want to support something, we need to measure it. Therefore, for vector control, phase current sensors are needed. Next, you need to assemble the vector control structure in the form of a program on the microcontroller, which will do the rest. So that such an explanation does not resemble the instruction “how to draw an owl”, let's continue the dive.
The microcontroller can maintain current using the software PI (proportional-integral) current controller and PWM. For example, a structure with a current regulator for a single phase α is shown below (Figure 3).

Figure 3. Current-closed control structure for one phase.
Here, the current setting i α_set is a certain constant, the current that we want to maintain for this phase, for example, 1A. The task goes to the adder of the current regulator, the disclosed structure of which is shown above. If the reader does not know how the PI controller works, then alas, ah. I can only advise any of this . The output current regulator sets the phase voltage U α . The voltage is supplied to the PWM block, which calculates the duty cycle settings (comparison settings) for the PWM timers of the microcontroller, forming the PWM on the bridge inverter from four keys to form this U α. The algorithm can be different, for example, for a positive PWM voltage with the right rack in proportion to the voltage setting, the lower key is closed on the left, for the negative PWM voltage with the left, the lower one is closed. Do not forget to add dead time! As a result, such a structure makes the software “current source” at the expense of the voltage source: we set the desired value i α_set , and this structure implements it with a certain speed.
Further, perhaps some readers already thought that it was up to the vector control structure - you need to put two current regulators, one regulator for each phase, and form a task on them depending on the angle from the rotor position sensor (DPR), t. e. do something like this structure (Figure 4):

Figure 4. Wrong (naive) structure of vector control
This cannot be done. When the rotor rotates, the variables i α_set and i β_set will be sinusoidal, i.e. the task for current regulators will change all the time. The speed of the regulator is not infinite, therefore, when changing a task, it does not instantly work it out. If the task is constantly changing, then the regulator will catch up with it all the time, never reaching it. And with an increase in the motor rotation speed, the lag of the real current from the set one will be more and more, until the desired angle of 90 ° between the current and the rotor magnet completely ceases to be similar to it, and vector control does not cease to be like that. Therefore, they do it differently. The correct structure is as follows (Figure 5):

Figure 5. The structure of the vector sensor control for a two-phase synchronous machine
. Two blocks are added here - BKP_1 and BKP_2: blocks of coordinate transformations. They do a very simple thing: they rotate the vector at the input by a given angle. And BPC_1 turns by + ϴ , and BKP_2 by - ϴ . This is the whole difference between them. In foreign literature, they are called Park transformations. BKP_2 does the coordinate transformation for currents: from the fixed axes α and β , attached to the motor stator, to the rotating axes d and q , attached to the motor rotor (using the rotor angle угол) And BKP_1 does the inverse transformation, from setting the voltage along the axes d and q makes a transition to the axes α and β . I don’t give the formulas for the transformation of coordinates, but they are simple and very easy to find. Actually, there is nothing more complicated in them than school geometry (Figure 6):

Figure 6. Coordinate transformations from the fixed axes α and β, tied to the motor stator, to the rotating axes of the d and q axes , tied to the rotor.
That is, instead of “rotating” the task of the regulators (as in the previous structure), their inputs and outputs rotate and the regulators themselves operate in static mode: the currents d , q and the outputs of the regulators in the steady state are constant. The d and q axes rotate together with the rotor (as the signal from the rotor position sensor rotates them), while the q axis regulator regulates exactly the current that I called “perpendicular to the rotor field” at the beginning of the article, that is, it is a moment-forming current, and the current daligned with the “rotor magnet”, so we do not need it and we set it equal to zero. Such a structure is spared the lack of the first structure - current regulators do not even know that something is spinning somewhere. They work in a static mode: they adjust each of their currents, reach a given voltage - and don’t even run away from them like a rotor, they don’t even know about it: all the rotation work is done by blocks of coordinate transformations.
The above structure really works and is used in modern electric drives. Only it lacks a whole bunch of small "improvements", without which it is no longer customary to do it, such as compensating for cross-links, various restrictions, weakening the field, etc. But the basic principle is just that.
And if you need to adjust not the drive torque, but still the speed (according to the correct angular speed, speed)? Well then, put another PI controller - speed controller (PC). At the input we give the speed reference, and at the output we have the task of the moment. Since the current of the q axis is proportional to the moment, for simplicity, the output of the speed controller can be fed directly to the input of the current controller of the q axis , like this (Figure 7):

Figure 7. Speed controller for vector control
Here, the ZI is the intensity adjuster, smoothly changes its output so that the engine accelerates at the desired pace, and does not drive at full current until the speed is set. The current speed ω is taken from the processor of the rotor position sensor, since ω is the derivative of the angular position ϴ . Well, or you can just pinpoint the time between sensor pulses ...
How to do the same for a three-phase motor? Well, actually, nothing special, add another block and change the PWM module (Figure 8).

Figure 8. Vector sensor control structure for a three-phase synchronous machine
Three-phase currents, just like two-phase ones, serve one purpose - to create a stator current vector I s directed in the right direction and having the desired amplitude. Therefore, three-phase currents can simply be converted to two-phase, and then leave the same control system that was already assembled for a two-phase machine. In English literature, such a “recount” is called the Clark transformation - Clarke transformation (Edith Clark is it), in our country - phase transformations. In the structure in Figure 8, respectively, this operation is performed by a block of phase transformations. They are done again using the school geometry course (Figure 9):

Figure 9. Phase transformations - from three phases to two. For convenience, we accept the equality of the amplitude of the vector I s to the amplitude of the current in the phase.
I think no comments are needed. A few words about the phase C current. There is no need to put a current sensor there, since the three phases of the motor are connected to a star, and according to Kirchhoff’s law, everything that flows through two phases must flow out of the third (unless, of course, your engine is broken insulation, and half didn’t leak somewhere on the housing), therefore, the current of phase C is calculated as the scalar sum of the currents of phases A and B with a minus sign. Although the third sensor is sometimes set to reduce the measurement error.
A complete redesign of the PWM module is also needed. Typically, for three-phase motors, a three-phase six-key inverter is used. In the figure, the voltage reference is still supplied in two-phase axes. Inside the PWM module, using the inverse phase transformations, this can be converted to phase voltages A, B, C, which must be applied at this moment to the motor. But what to do next ... Options are possible. The naive method is to set the duty cycle for each inverter rack, proportional to the desired voltage plus 0.5. This is called a sinusoidal PWM. It is this method that the author applied in habrahabr.ru/post/128407. Everything is good in this method, except that the voltage inverter will be underused by this method - i.e. the maximum voltage that will be obtained will be less than what you could get if you used the more advanced PWM method.
Count. Suppose you have a classic frequency converter, powered by an industrial three-phase network 380V 50Hz. Here 380V is a linear (between phases) effective voltage. Since there is a rectifier in the converter, it will rectify this voltage and a voltage equal to the amplitude linear voltage will appear on the DC bus, i.e. 380 ∙ √2 = 540V DC (at least without load). If we apply a sinusoidal calculation algorithm in the PWM module, then the amplitude of the maximum phase voltage that we can do will be equal to half the voltage on the DC bus, i.e. 540/2 = 270V. We recalculate the current phase: 270 / √2 = 191V. And now in the current linear: 191 ∙ √3 = 330V. Now we can compare: 380V entered us, and 330V came out ... And there is no way anymore with this type of PWM. To fix this problem, the so-called PWM vector type is used. It will output 380V again (in the ideal case, without taking into account all voltage drops). The vector PWM method has nothing to do with vector motor control. It's just that a little school geometry is again used in its justification, which is why it is called vector geometry. However, his work on the fingers cannot be explained, so I will send the reader to books (at the end of the article) or toWikipedia . I can also give a picture that hints a little at the difference in the work of the sinusoidal and vector PWM (Figure 10):

Figure 10. Change in phase potentials for scalar and vector PWM
By the way, what position sensors are used for vector control? Four types of sensors are most commonly used. This is a quadrature incremental encoder, a sensor based on Hall elements, an absolute position sensor and a synchro sensor.
Quadrature encoderit does not give out the absolute position of the rotor - by its impulses it only allows you to determine how much you traveled, but not where or where (how the beginning and end are related to the location of the rotor magnet). Therefore, for vector control of a synchronous machine by itself, it is not suitable. The reference mark (index) saves the situation a little - it is one per mechanical revolution, if you reach it, then the absolute position becomes known, and you can already count from it how much you traveled with a quadrature signal. But how to get to this mark at the beginning of work? In general, this is not always convenient.
Hall sensor- This is a rude sensor. It gives out only a few pulses per revolution (depending on the number of Hall elements, for three-phase motors there are usually three, i.e. six pulses), allowing you to know the position in absolute value, but with low accuracy. Accuracy is usually enough to hold the angle of the current vector so that the motor at least travels forward and not backward, but the moment and currents will pulsate. If the engine accelerates, then you can start to programmatically extrapolate the signal from the sensor over time - i.e. build a linearly varying angle from a coarse discrete angle. This is done on the basis of the assumption that the engine rotates at an approximately constant speed, something like this (Figure 11):

Figure 11. Operation of the position sensor on the Hall elements for a three-phase machine and extrapolation of its signal.
For servomotors, a combination of an encoder and a Hall sensor is often used. In this case, it is possible to make a single software module for processing them, removing the shortcomings of both: extrapolating the angle given above, but not in time, but according to marks from the encoder. Those. An encoder works inside from front to front of the Hall sensor, and each Hall front clearly initializes the current absolute angular position. In this case, only the first movement of the drive will turn out to be non-optimal (not under 90 °), until it reaches some front of the Hall sensor. A separate problem in this case is the processing of non-ideality of both sensors - symmetrically and uniformly, rarely does anyone have Hall elements ...
In even more expensive applications, they use an absolute position sensor with a digital interface (absolute encoder), which immediately gives an absolute position and eliminates the problems described above.
If the electric motor is very hot, and also when increased accuracy of angle measurement is required, use an “analog” selsyn sensor (resolver, rotating transformer). This is a small electric machine used as a sensor. Imagine that in the synchronous machine we examined in Figure 1, instead of magnets, there is another coil, to which we feed a high-frequency signal. If the rotor is horizontal, then the signal will be guided only into the stator coil of phase α , if vertically - only in βif you flip it 180, then the phase of the signal will change, and in intermediate positions it is induced both here and there according to the sine / cosine law. Accordingly, by measuring the amplitude of the signal in two coils, the position can also be determined by the ratio of this amplitude and the phase shift. By installing a machine such as a sensor to the main one, you can find out the position of the rotor.
There are many more exotic position sensors, especially for ultra-high-precision applications, for example, for the manufacture of electronic chips. Any physical phenomena are already used there, only to find out the situation most accurately. We will not consider them.
As you understand, vector control is quite demanding - and position sensors to it, and current sensors, and PWM it is vector, and the microcontroller is not anyhow to calculate all this mathematics. Therefore, for simple applications it is simplified. To begin with, you can exclude the position sensor by making a sensorless vector control. To do this, use a little more mathematical magic in the yellow rectangle (Figure 12):

Figure 12. The structure of the sensorless vector control
An observer is such a unit to which information is supplied about the voltage applied to the engine (for example, from a task on the PWM module) and about the currents in the engine from the sensors. Inside the observer, an electric motor model is operating, which, roughly speaking, is trying to adjust its currents in the stator to those measured from a real motor. If she succeeded, then we can assume that the position of the rotor modeled inside the shaft also coincides with the real one and can be used for the needs of vector control. Well, this, of course, is completely simplified. There are no such types of observers. Each graduate student specializing in "electric drive" is trying to invent his own, which is something better than others. The basic principle is tracking EMF of an electric motor. Therefore, most often the sensorless control system is operable only at a relatively high speed, where the emf is big. And it also has a number of drawbacks compared to the presence of a sensor: you need to know the motor parameters, the speed of the drive is limited (if the speed changes dramatically, the observer may not have time to track it and “lie” for some time, or even “fall apart” completely) , setting up the observer is a whole procedure, for its high-quality work, you need to know the voltage on the motor accurately, accurately measure its currents, etc.
There is another simplification option. For example, you can make the so-called "auto-switching". In this case, for a three-phase motor, they abandon the complex PWM method, abandon the complex vector structure and begin to simply turn on the motor phases by the position sensor on the Hall elements, even sometimes without any current limitation. The current in the phases is not sine, but trapezoidal, rectangular or even more distorted. But they are trying to make sure that the average current vector is still at 90 degrees to the “rotor magnet” by choosing the moment the phases are turned on. Moreover, including the phase under voltage, it is not known when the current will increase in the phase of the motor. At a low speed, he does it faster, at a high one, where the EMF of the machine interferes, slower, and the rate of current rise depends on the inductance of the motor, etc. Therefore, even including the phases exactly at the right time, it is not at all a fact that the average current vector will be in the right place and with the right phase - it can either be ahead or late relative to the optimal 90 degrees. Therefore, in such systems, the “commutation advance” setting is introduced - in fact it’s just the time how much earlier it is necessary to apply voltage to the motor phase, so that as a result the phase of the current vector turns out to be closer to 90 degrees. In a simple way, this is called "timing settings." Since the current in the electric motor during auto-switching is not sinusoidal, if you take the sinusoidal machine discussed above and control it in this way, the moment on the shaft will pulsate. Therefore, in engines designed for auto-switching, the magnetic geometry of the rotor and stator is often changed in a special way, so that they become more suitable for this type of control: EMF of such machines is made trapezoidal, so that they work better in auto-switching mode. Synchronous machines optimized for auto-switching are called brushless direct current motors (DCBMs) or in English BLDC (Brushless Direct Current Motor). The auto-commutation mode is also often called the valve mode, and the engines working with it are called valve mode. But these are all just different names that do not affect the essence (but inveterate electric drives often suffer from SPGS in matters related to these names). There is a good video illustrating the principle of operation of such machines. It shows a reversed motor, where the rotor is outside and the stator is inside: optimized for auto-switching, they are called brushless direct current motors (DCBMs) or in English BLDC (Brushless Direct Current Motor). The auto-commutation mode is also often called the valve mode, and the engines working with it are called valve mode. But these are all just different names that do not affect the essence (but inveterate electric drives often suffer from SPGS in matters related to these names). There is a good video illustrating the principle of operation of such machines. It shows a reversed motor, where the rotor is outside and the stator is inside: optimized for auto-switching, they are called brushless direct current motors (DCBMs) or in English BLDC (Brushless Direct Current Motor). The auto-commutation mode is also often called the valve mode, and the engines working with it are called valve mode. But these are all just different names that do not affect the essence (but inveterate electric drives often suffer from SPGS in matters related to these names). There is a good video illustrating the principle of operation of such machines. It shows a reversed motor, where the rotor is outside and the stator is inside: nothing affecting the essence (but inveterate electric drives often suffer from LPS in matters related to these names). There is a good video illustrating the principle of operation of such machines. It shows a reversed motor, where the rotor is outside and the stator is inside: nothing affecting the essence (but inveterate electric drives often suffer from LPS in matters related to these names). There is a good video illustrating the principle of operation of such machines. It shows a reversed motor, where the rotor is outside and the stator is inside:
And here there is a course of articles on such engines and the control system hardware.
You can go even further simplification. Switch the windings so that one phase is always “free” and no PWM is applied to it. Then it is possible to measure EMF in it (the voltage induced in the phase coil), and when this voltage passes through zero, use this as a signal from the rotor position sensor, because the phase of this induced voltage depends on the rotor position. It turns out sensorless auto-switching, which is widely used in various simple drives, for example, in the "regulators" for propellers of aircraft models. It should be remembered that the EMF of the machine appears only at a relatively high speed, therefore, to start such control systems just slowly rush through the phases, hoping that the rotor of the motor will follow the supplied current. As soon as the EMF has appeared, the auto-switching mode is activated. Therefore, a sensorless system (such a simple, and difficult most often also) is not suitable for tasks where the engine must be able to develop a moment at near-zero rotation speeds, for example, for a traction drive of a car (or its model), a servo drive of some mechanism, etc. P. But the sensorless system is successfully suited for pumps and fans, where it is used.
But sometimes they make an even greater simplification. You can completely abandon the microcontroller, keys, position sensors and other things, by switching the phases with a special mechanical switch (Figure 13):

Figure 13. Mechanical switch for switching windings
During rotation, the rotor itself switches its parts of the windings, changing the voltage applied to them, while the current in the rotor flows alternating. The switch is positioned so that the magnetic flux of the rotor and stator is again close to 90 degrees in order to reach the maximum torque. Such motorsare naively called DC motors, but completely undeservedly: inside, after the collector, the current is still alternating!
All electric cars work in a similar way. In the theory of electric drive there even exists the concept of “generalized electric machine”, to which the work of others is reduced. The “on the fingers” explanations shown in the article can in no way serve as a practical guide to writing microcontroller code. The article considers well if one percent of the information that is required to implement this vector control. To do something in practice, you first need to know TAU , at least at the level of understanding how the PI controller works. Then you still need to study the mathematical description of both the synchronous machine and the synthesis of vector control. Also study vector PWM, find out what pairs of poles are, get acquainted with the types of windings of machines, and more. This can be done in the latest book "Anuchin A.S. Electric Drive Control Systems. MPEI, 2015 ”, as well as in“ Kalachev Yu. N. Vector regulation (practice notes)". The reader should be cautioned against immersing in the formulas of the “old” drive textbooks, where the main emphasis is placed on considering the characteristics of electric motors when powered directly from a three-phase industrial network, without any microcontrollers and position sensors. The behavior of engines in this case is described by complex formulas and dependencies, but for the vector control problem they have almost no benefit (if only studied for self-development). You should especially be cautious of the recommendations of old textbooks, where, for example, it is said that the synchronous machine should not work at the maximum of its moment, since the work there is unstable and threatens to tip over - all this is “bad advice” for vector control.
On which microcontroller you can make full-fledged vector control, read, for example, in our article New domestic motor-control microcontroller K1921VK01T of NIIET OJSC , and how to debug it in the article Methods for debugging software of microcontrollers in an electric drive . Also visit our website: there, in particular, twoboring videos are posted where it is shown in practice how to configure the PI current regulator, and also how the current-locked and vector sensorless control structure works. In addition, you can purchase a debugging kit with a ready-made sensor vector control structure on a domestic microcontroller.
Continuation of the article, which tells about asynchronous motorshere .
PS
I apologize to the specialists for the not quite correct treatment with some terms, in particular with the terms “flux”, “flux linkage”, “magnetic field” and others - simplicity requires sacrifice ...
- Keep current at 90 degrees.

The principle of operation of a synchronous machine
Consider the principle of operation of the simplest AC motor - a synchronous machine with permanent magnets. A convenient example is a compass: its magnetic needle is the rotor of a synchronous machine, and the Earth’s magnetic field is the stator’s magnetic field. Without an external load (and it is not in the compass, except for friction and fluid damping the oscillations of the arrow), the rotor is always oriented along the stator field. If we hold the compass and rotate the Earth beneath it, then the arrow will spin after it, doing the work of mixing the fluid inside the compass. But there is also a slightly simpler way - you can take an external magnet, for example, in the form of a rod with poles at the ends, the field of which is much stronger than the Earth’s magnetic field, bring it to the compass from above and rotate the magnet. The arrow will follow the rotating magnetic field. In a real synchronous motor, the stator field is created by electromagnets - current coils. The winding circuits there are complex, but there is one principle - they create a stator magnetic field directed in the right direction and having the desired amplitude. Let's look at the following figure (Figure 1). In the center is a magnet - the rotor of a synchronous motor (compass needle), and on the sides are two electromagnets - coils, each creating its own magnetic field, one in the vertical axis and the other in the horizontal.

Figure 1. The principle of operation of a synchronous electric machine The
magnetic flux of the coil is proportional to the current in it (in a first approximation). We will be interested in the magnetic flux from the stator in the place where the rotor is located, i.e. in the center of the figure (we neglect the edge effects, scattering, and everything else). The magnetic fluxes of two perpendicularly arranged coils are vectorized, forming one common flux for interaction with the rotor. But since the flow is proportional to the current in the coil, it is convenient to draw directly the current vectors, aligning them with the flow. The figure shows some currents I α and I β , creating magnetic flux along the axes α and β, respectively. The total stator current vector I screates a co-directional magnetic flux of the stator. Those. in fact, I s symbolizes an external magnet, which we brought to the compass, but created by electromagnets - coils with current.
In the figure, the rotor is in an arbitrary position, but from this position the rotor will tend to rotate according to the magnetic flux of the stator, i.e. according to the vector I s (the position of the rotor in this case is shown by a dashed line). Accordingly, if the current is applied only to phase α , say, I α = 1A, the rotor will rise horizontally, and if in β, vertically, and if I β = -1A, then it will turn 180 degrees. If you feed current I αaccording to the law of sine, and I β according to the law of cosine from time to time, a rotating magnetic field will be created. The rotor will follow it and spin (as the compass needle follows the rotation of the magnet with his hands). This is the basic principle of a synchronous machine, in this case, two-phase with one pair of pluses.
Let's draw a graph of the motor torque depending on the angular position of the rotor shaft and the stator current vector I s — the angular characteristic of the synchronous motor. This relationship is sinusoidal (Figure 2).

Figure 2. The angular characteristic of the synchronous machine (there is some historical confusion with the signs of the moment and angle, because of which they often draw the characteristic inverted relative to the horizontal axis).
To get this graph in practice, you can put a torque sensor on the rotor shaft, then turn on any current vector, for example, just apply current to phase α. The rotor will rotate to the appropriate position, which must be taken as zero. Then, through the moment sensor “by hands”, it is necessary to turn the rotor, fixing the angle θ at each point on the graphturned on, and the moment the sensor showed. Those. you need to stretch the "magnetic spring" of the engine through a torque sensor. The largest moment will be at an angle of 90 degrees from the current vector (from the beginning). The amplitude of the resulting maximum moment M max is proportional to the amplitude of the applied current vector. 1A will be applied, we get, say, M max = 1 N ∙ m (newton * meter, unit of torque), if we give 2A, we get M max = 2 N ∙ m.
From this characteristic it follows that the motor develops the greatest moment when the rotor is at 90 ° to the current vector. Since when creating a control system on a microcontroller we want to get the greatest moment from the motor with a minimum of losses, and the loss, first of all, is the current in the windings, it is most rational to set the current vector always at 90 ° to the rotor magnetic field, i.e. perpendicular to the magnet in Figure 1. You need to change the opposite - the rotor does not go to the current vector we set, but we set the current vector always at 90 ° to the rotor, no matter how it rotates there, i.e. "Beat" the current vector to the rotor. We will regulate the motor torque by the amplitude of the current. The larger the amplitude, the higher the moment. And the rotation frequency, the frequency of the current in the windings is already “not our” business - what happens, how the rotor will rotate, it will be so - we control the moment on the shaft. Oddly enough, this is what is called vector control - when we control the stator current vector so that it is 90 ° to the magnetic field of the rotor. Although some textbooks give broader definitions, to the extent that any control laws where “vectors” are involved are called vector control, but usually vector control refers to the above control method.
Building a vector management structure
But how is vector control achieved in practice? Obviously, for starters, you need to know the position of the rotor, so that you can measure 90 ° relative to what. This is easiest to do by installing, in fact, a position sensor on the rotor shaft. Then you need to figure out how to create a current vector, maintaining the desired currents in the phases α and β . We apply voltage to the motor, not current ... But since we want to support something, we need to measure it. Therefore, for vector control, phase current sensors are needed. Next, you need to assemble the vector control structure in the form of a program on the microcontroller, which will do the rest. So that such an explanation does not resemble the instruction “how to draw an owl”, let's continue the dive.
The microcontroller can maintain current using the software PI (proportional-integral) current controller and PWM. For example, a structure with a current regulator for a single phase α is shown below (Figure 3).

Figure 3. Current-closed control structure for one phase.
Here, the current setting i α_set is a certain constant, the current that we want to maintain for this phase, for example, 1A. The task goes to the adder of the current regulator, the disclosed structure of which is shown above. If the reader does not know how the PI controller works, then alas, ah. I can only advise any of this . The output current regulator sets the phase voltage U α . The voltage is supplied to the PWM block, which calculates the duty cycle settings (comparison settings) for the PWM timers of the microcontroller, forming the PWM on the bridge inverter from four keys to form this U α. The algorithm can be different, for example, for a positive PWM voltage with the right rack in proportion to the voltage setting, the lower key is closed on the left, for the negative PWM voltage with the left, the lower one is closed. Do not forget to add dead time! As a result, such a structure makes the software “current source” at the expense of the voltage source: we set the desired value i α_set , and this structure implements it with a certain speed.
Further, perhaps some readers already thought that it was up to the vector control structure - you need to put two current regulators, one regulator for each phase, and form a task on them depending on the angle from the rotor position sensor (DPR), t. e. do something like this structure (Figure 4):

Figure 4. Wrong (naive) structure of vector control
This cannot be done. When the rotor rotates, the variables i α_set and i β_set will be sinusoidal, i.e. the task for current regulators will change all the time. The speed of the regulator is not infinite, therefore, when changing a task, it does not instantly work it out. If the task is constantly changing, then the regulator will catch up with it all the time, never reaching it. And with an increase in the motor rotation speed, the lag of the real current from the set one will be more and more, until the desired angle of 90 ° between the current and the rotor magnet completely ceases to be similar to it, and vector control does not cease to be like that. Therefore, they do it differently. The correct structure is as follows (Figure 5):

Figure 5. The structure of the vector sensor control for a two-phase synchronous machine
. Two blocks are added here - BKP_1 and BKP_2: blocks of coordinate transformations. They do a very simple thing: they rotate the vector at the input by a given angle. And BPC_1 turns by + ϴ , and BKP_2 by - ϴ . This is the whole difference between them. In foreign literature, they are called Park transformations. BKP_2 does the coordinate transformation for currents: from the fixed axes α and β , attached to the motor stator, to the rotating axes d and q , attached to the motor rotor (using the rotor angle угол) And BKP_1 does the inverse transformation, from setting the voltage along the axes d and q makes a transition to the axes α and β . I don’t give the formulas for the transformation of coordinates, but they are simple and very easy to find. Actually, there is nothing more complicated in them than school geometry (Figure 6):

Figure 6. Coordinate transformations from the fixed axes α and β, tied to the motor stator, to the rotating axes of the d and q axes , tied to the rotor.
That is, instead of “rotating” the task of the regulators (as in the previous structure), their inputs and outputs rotate and the regulators themselves operate in static mode: the currents d , q and the outputs of the regulators in the steady state are constant. The d and q axes rotate together with the rotor (as the signal from the rotor position sensor rotates them), while the q axis regulator regulates exactly the current that I called “perpendicular to the rotor field” at the beginning of the article, that is, it is a moment-forming current, and the current daligned with the “rotor magnet”, so we do not need it and we set it equal to zero. Such a structure is spared the lack of the first structure - current regulators do not even know that something is spinning somewhere. They work in a static mode: they adjust each of their currents, reach a given voltage - and don’t even run away from them like a rotor, they don’t even know about it: all the rotation work is done by blocks of coordinate transformations.
To explain “on the fingers”, we can give some analogy.
Для линейного движения пусть это будет, например, городской автобус. Он всё время то разгоняется, то тормозит, то едет назад и вообще ведёт себя как хочет: это ротор двигателя. Также есть вы на автомобиле рядом, едете параллельно: ваша задача быть ровно посредине автобуса: «держать 90°», вы – это регуляторы тока. Если автобус все время меняет скорость – вы тоже должны соответственно менять скорость и всё время её отслеживать. Но теперь сделаем для вас «векторное управление». Вы залезли внутрь автобуса, встали посередине и держитесь за поручень – как автобус не убегай, вы легко справляетесь с задачей «быть посередине автобуса». Аналогично и регуляторы токов, «катаясь» во вращающихся осях d, q ротора, живут легкой жизнью.
The above structure really works and is used in modern electric drives. Only it lacks a whole bunch of small "improvements", without which it is no longer customary to do it, such as compensating for cross-links, various restrictions, weakening the field, etc. But the basic principle is just that.
And if you need to adjust not the drive torque, but still the speed (according to the correct angular speed, speed)? Well then, put another PI controller - speed controller (PC). At the input we give the speed reference, and at the output we have the task of the moment. Since the current of the q axis is proportional to the moment, for simplicity, the output of the speed controller can be fed directly to the input of the current controller of the q axis , like this (Figure 7):

Figure 7. Speed controller for vector control
Here, the ZI is the intensity adjuster, smoothly changes its output so that the engine accelerates at the desired pace, and does not drive at full current until the speed is set. The current speed ω is taken from the processor of the rotor position sensor, since ω is the derivative of the angular position ϴ . Well, or you can just pinpoint the time between sensor pulses ...
How to do the same for a three-phase motor? Well, actually, nothing special, add another block and change the PWM module (Figure 8).

Figure 8. Vector sensor control structure for a three-phase synchronous machine
Three-phase currents, just like two-phase ones, serve one purpose - to create a stator current vector I s directed in the right direction and having the desired amplitude. Therefore, three-phase currents can simply be converted to two-phase, and then leave the same control system that was already assembled for a two-phase machine. In English literature, such a “recount” is called the Clark transformation - Clarke transformation (Edith Clark is it), in our country - phase transformations. In the structure in Figure 8, respectively, this operation is performed by a block of phase transformations. They are done again using the school geometry course (Figure 9):

Figure 9. Phase transformations - from three phases to two. For convenience, we accept the equality of the amplitude of the vector I s to the amplitude of the current in the phase.
I think no comments are needed. A few words about the phase C current. There is no need to put a current sensor there, since the three phases of the motor are connected to a star, and according to Kirchhoff’s law, everything that flows through two phases must flow out of the third (unless, of course, your engine is broken insulation, and half didn’t leak somewhere on the housing), therefore, the current of phase C is calculated as the scalar sum of the currents of phases A and B with a minus sign. Although the third sensor is sometimes set to reduce the measurement error.
A complete redesign of the PWM module is also needed. Typically, for three-phase motors, a three-phase six-key inverter is used. In the figure, the voltage reference is still supplied in two-phase axes. Inside the PWM module, using the inverse phase transformations, this can be converted to phase voltages A, B, C, which must be applied at this moment to the motor. But what to do next ... Options are possible. The naive method is to set the duty cycle for each inverter rack, proportional to the desired voltage plus 0.5. This is called a sinusoidal PWM. It is this method that the author applied in habrahabr.ru/post/128407. Everything is good in this method, except that the voltage inverter will be underused by this method - i.e. the maximum voltage that will be obtained will be less than what you could get if you used the more advanced PWM method.
Count. Suppose you have a classic frequency converter, powered by an industrial three-phase network 380V 50Hz. Here 380V is a linear (between phases) effective voltage. Since there is a rectifier in the converter, it will rectify this voltage and a voltage equal to the amplitude linear voltage will appear on the DC bus, i.e. 380 ∙ √2 = 540V DC (at least without load). If we apply a sinusoidal calculation algorithm in the PWM module, then the amplitude of the maximum phase voltage that we can do will be equal to half the voltage on the DC bus, i.e. 540/2 = 270V. We recalculate the current phase: 270 / √2 = 191V. And now in the current linear: 191 ∙ √3 = 330V. Now we can compare: 380V entered us, and 330V came out ... And there is no way anymore with this type of PWM. To fix this problem, the so-called PWM vector type is used. It will output 380V again (in the ideal case, without taking into account all voltage drops). The vector PWM method has nothing to do with vector motor control. It's just that a little school geometry is again used in its justification, which is why it is called vector geometry. However, his work on the fingers cannot be explained, so I will send the reader to books (at the end of the article) or toWikipedia . I can also give a picture that hints a little at the difference in the work of the sinusoidal and vector PWM (Figure 10):

Figure 10. Change in phase potentials for scalar and vector PWM
Types of position sensors
By the way, what position sensors are used for vector control? Four types of sensors are most commonly used. This is a quadrature incremental encoder, a sensor based on Hall elements, an absolute position sensor and a synchro sensor.
Quadrature encoderit does not give out the absolute position of the rotor - by its impulses it only allows you to determine how much you traveled, but not where or where (how the beginning and end are related to the location of the rotor magnet). Therefore, for vector control of a synchronous machine by itself, it is not suitable. The reference mark (index) saves the situation a little - it is one per mechanical revolution, if you reach it, then the absolute position becomes known, and you can already count from it how much you traveled with a quadrature signal. But how to get to this mark at the beginning of work? In general, this is not always convenient.
Hall sensor- This is a rude sensor. It gives out only a few pulses per revolution (depending on the number of Hall elements, for three-phase motors there are usually three, i.e. six pulses), allowing you to know the position in absolute value, but with low accuracy. Accuracy is usually enough to hold the angle of the current vector so that the motor at least travels forward and not backward, but the moment and currents will pulsate. If the engine accelerates, then you can start to programmatically extrapolate the signal from the sensor over time - i.e. build a linearly varying angle from a coarse discrete angle. This is done on the basis of the assumption that the engine rotates at an approximately constant speed, something like this (Figure 11):

Figure 11. Operation of the position sensor on the Hall elements for a three-phase machine and extrapolation of its signal.
For servomotors, a combination of an encoder and a Hall sensor is often used. In this case, it is possible to make a single software module for processing them, removing the shortcomings of both: extrapolating the angle given above, but not in time, but according to marks from the encoder. Those. An encoder works inside from front to front of the Hall sensor, and each Hall front clearly initializes the current absolute angular position. In this case, only the first movement of the drive will turn out to be non-optimal (not under 90 °), until it reaches some front of the Hall sensor. A separate problem in this case is the processing of non-ideality of both sensors - symmetrically and uniformly, rarely does anyone have Hall elements ...
In even more expensive applications, they use an absolute position sensor with a digital interface (absolute encoder), which immediately gives an absolute position and eliminates the problems described above.
If the electric motor is very hot, and also when increased accuracy of angle measurement is required, use an “analog” selsyn sensor (resolver, rotating transformer). This is a small electric machine used as a sensor. Imagine that in the synchronous machine we examined in Figure 1, instead of magnets, there is another coil, to which we feed a high-frequency signal. If the rotor is horizontal, then the signal will be guided only into the stator coil of phase α , if vertically - only in βif you flip it 180, then the phase of the signal will change, and in intermediate positions it is induced both here and there according to the sine / cosine law. Accordingly, by measuring the amplitude of the signal in two coils, the position can also be determined by the ratio of this amplitude and the phase shift. By installing a machine such as a sensor to the main one, you can find out the position of the rotor.
There are many more exotic position sensors, especially for ultra-high-precision applications, for example, for the manufacture of electronic chips. Any physical phenomena are already used there, only to find out the situation most accurately. We will not consider them.
Simplify vector management
As you understand, vector control is quite demanding - and position sensors to it, and current sensors, and PWM it is vector, and the microcontroller is not anyhow to calculate all this mathematics. Therefore, for simple applications it is simplified. To begin with, you can exclude the position sensor by making a sensorless vector control. To do this, use a little more mathematical magic in the yellow rectangle (Figure 12):

Figure 12. The structure of the sensorless vector control
An observer is such a unit to which information is supplied about the voltage applied to the engine (for example, from a task on the PWM module) and about the currents in the engine from the sensors. Inside the observer, an electric motor model is operating, which, roughly speaking, is trying to adjust its currents in the stator to those measured from a real motor. If she succeeded, then we can assume that the position of the rotor modeled inside the shaft also coincides with the real one and can be used for the needs of vector control. Well, this, of course, is completely simplified. There are no such types of observers. Each graduate student specializing in "electric drive" is trying to invent his own, which is something better than others. The basic principle is tracking EMF of an electric motor. Therefore, most often the sensorless control system is operable only at a relatively high speed, where the emf is big. And it also has a number of drawbacks compared to the presence of a sensor: you need to know the motor parameters, the speed of the drive is limited (if the speed changes dramatically, the observer may not have time to track it and “lie” for some time, or even “fall apart” completely) , setting up the observer is a whole procedure, for its high-quality work, you need to know the voltage on the motor accurately, accurately measure its currents, etc.
There is another simplification option. For example, you can make the so-called "auto-switching". In this case, for a three-phase motor, they abandon the complex PWM method, abandon the complex vector structure and begin to simply turn on the motor phases by the position sensor on the Hall elements, even sometimes without any current limitation. The current in the phases is not sine, but trapezoidal, rectangular or even more distorted. But they are trying to make sure that the average current vector is still at 90 degrees to the “rotor magnet” by choosing the moment the phases are turned on. Moreover, including the phase under voltage, it is not known when the current will increase in the phase of the motor. At a low speed, he does it faster, at a high one, where the EMF of the machine interferes, slower, and the rate of current rise depends on the inductance of the motor, etc. Therefore, even including the phases exactly at the right time, it is not at all a fact that the average current vector will be in the right place and with the right phase - it can either be ahead or late relative to the optimal 90 degrees. Therefore, in such systems, the “commutation advance” setting is introduced - in fact it’s just the time how much earlier it is necessary to apply voltage to the motor phase, so that as a result the phase of the current vector turns out to be closer to 90 degrees. In a simple way, this is called "timing settings." Since the current in the electric motor during auto-switching is not sinusoidal, if you take the sinusoidal machine discussed above and control it in this way, the moment on the shaft will pulsate. Therefore, in engines designed for auto-switching, the magnetic geometry of the rotor and stator is often changed in a special way, so that they become more suitable for this type of control: EMF of such machines is made trapezoidal, so that they work better in auto-switching mode. Synchronous machines optimized for auto-switching are called brushless direct current motors (DCBMs) or in English BLDC (Brushless Direct Current Motor). The auto-commutation mode is also often called the valve mode, and the engines working with it are called valve mode. But these are all just different names that do not affect the essence (but inveterate electric drives often suffer from SPGS in matters related to these names). There is a good video illustrating the principle of operation of such machines. It shows a reversed motor, where the rotor is outside and the stator is inside: optimized for auto-switching, they are called brushless direct current motors (DCBMs) or in English BLDC (Brushless Direct Current Motor). The auto-commutation mode is also often called the valve mode, and the engines working with it are called valve mode. But these are all just different names that do not affect the essence (but inveterate electric drives often suffer from SPGS in matters related to these names). There is a good video illustrating the principle of operation of such machines. It shows a reversed motor, where the rotor is outside and the stator is inside: optimized for auto-switching, they are called brushless direct current motors (DCBMs) or in English BLDC (Brushless Direct Current Motor). The auto-commutation mode is also often called the valve mode, and the engines working with it are called valve mode. But these are all just different names that do not affect the essence (but inveterate electric drives often suffer from SPGS in matters related to these names). There is a good video illustrating the principle of operation of such machines. It shows a reversed motor, where the rotor is outside and the stator is inside: nothing affecting the essence (but inveterate electric drives often suffer from LPS in matters related to these names). There is a good video illustrating the principle of operation of such machines. It shows a reversed motor, where the rotor is outside and the stator is inside: nothing affecting the essence (but inveterate electric drives often suffer from LPS in matters related to these names). There is a good video illustrating the principle of operation of such machines. It shows a reversed motor, where the rotor is outside and the stator is inside:
And here there is a course of articles on such engines and the control system hardware.
You can go even further simplification. Switch the windings so that one phase is always “free” and no PWM is applied to it. Then it is possible to measure EMF in it (the voltage induced in the phase coil), and when this voltage passes through zero, use this as a signal from the rotor position sensor, because the phase of this induced voltage depends on the rotor position. It turns out sensorless auto-switching, which is widely used in various simple drives, for example, in the "regulators" for propellers of aircraft models. It should be remembered that the EMF of the machine appears only at a relatively high speed, therefore, to start such control systems just slowly rush through the phases, hoping that the rotor of the motor will follow the supplied current. As soon as the EMF has appeared, the auto-switching mode is activated. Therefore, a sensorless system (such a simple, and difficult most often also) is not suitable for tasks where the engine must be able to develop a moment at near-zero rotation speeds, for example, for a traction drive of a car (or its model), a servo drive of some mechanism, etc. P. But the sensorless system is successfully suited for pumps and fans, where it is used.
But sometimes they make an even greater simplification. You can completely abandon the microcontroller, keys, position sensors and other things, by switching the phases with a special mechanical switch (Figure 13):

Figure 13. Mechanical switch for switching windings
During rotation, the rotor itself switches its parts of the windings, changing the voltage applied to them, while the current in the rotor flows alternating. The switch is positioned so that the magnetic flux of the rotor and stator is again close to 90 degrees in order to reach the maximum torque. Such motors
Conclusion
All electric cars work in a similar way. In the theory of electric drive there even exists the concept of “generalized electric machine”, to which the work of others is reduced. The “on the fingers” explanations shown in the article can in no way serve as a practical guide to writing microcontroller code. The article considers well if one percent of the information that is required to implement this vector control. To do something in practice, you first need to know TAU , at least at the level of understanding how the PI controller works. Then you still need to study the mathematical description of both the synchronous machine and the synthesis of vector control. Also study vector PWM, find out what pairs of poles are, get acquainted with the types of windings of machines, and more. This can be done in the latest book "Anuchin A.S. Electric Drive Control Systems. MPEI, 2015 ”, as well as in“ Kalachev Yu. N. Vector regulation (practice notes)". The reader should be cautioned against immersing in the formulas of the “old” drive textbooks, where the main emphasis is placed on considering the characteristics of electric motors when powered directly from a three-phase industrial network, without any microcontrollers and position sensors. The behavior of engines in this case is described by complex formulas and dependencies, but for the vector control problem they have almost no benefit (if only studied for self-development). You should especially be cautious of the recommendations of old textbooks, where, for example, it is said that the synchronous machine should not work at the maximum of its moment, since the work there is unstable and threatens to tip over - all this is “bad advice” for vector control.
On which microcontroller you can make full-fledged vector control, read, for example, in our article New domestic motor-control microcontroller K1921VK01T of NIIET OJSC , and how to debug it in the article Methods for debugging software of microcontrollers in an electric drive . Also visit our website: there, in particular, two
Continuation of the article, which tells about asynchronous motorshere .
PS
I apologize to the specialists for the not quite correct treatment with some terms, in particular with the terms “flux”, “flux linkage”, “magnetic field” and others - simplicity requires sacrifice ...