 All right, let me begin a little bit about driving of the motors and especially the motors with a permanent magnet. From our experience, we have learned that there are some limitations of the motors that explore limitations and physical principles that explain the behavior of the motors and the driving strategies and why the motor can do this and cannot do that. So, I have prepared a little set of slides, no more than 10, that explain what happens in the motor and what shall bring you closer to the principles of the operating of the motor. It's not the rocket science and I will not test you at the end of this training, so you don't need to remember the equations. First, to understand what we use as different parameters to describe the physical model and electrical model of the motor, you can see how we write voltages, currents and so on. This is my simplified model of the electrical motor. You can see it consists from several parts, the electrical part, the magnetical part and the mechanical part. These cooperate together and bring you the benefits and the limitations of the motor. I will begin from the mechanics because this is what we need to understand first. I know that we are electrical engineers mostly and that we want to program it. The trouble is that we need to understand how the motor is connected and what we drive because you can spin the motor on your bench here, perfectly set with the library. But when you bring it to the real application and you connect the load and it can be water, it can be air, it can be a mechanical, it can be, for example, wheel of the car, it can be a servo. As soon as you load it or offload it, your system will change, the regulation loop changes and suddenly your application doesn't work. So you have to consider the fact that the motor is connected to the real world and that you need to identify or at least understand a couple of parameters. So let's look at it at the point where your motor spins with a steady speed. So it doesn't change the speed, it spins, it's controlled properly. At that moment it doesn't accelerate nor decelerate. So we can consider a stable torque equation that has a couple of elements. So the first one is the motor torque. This is the torque that we deliver to the motor to our mechanical system through electrical energy and through our control algorithm. The two other torques, the TT and TI, are losses. You have got mechanical losses, you have got electrical losses. So you need to cover these losses if you don't want to accelerate or decelerate. And finally you have got the torque applied, let's say from the load. So if you connect something heavy, which has its own resistance, it brings back some torque. You can imagine at that point it's a loss, but you need to cover it otherwise it starts decelerating and it will stop at some time. So when you think about such equation, I'd like to point out that if you want to keep everything steady, you only need to cover this torque. The torque of the losses that are some of the losses in your whole system. If you want to accelerate, you must increase the motor torque above these. If you want to decelerate, you can reduce the torque and the system will decelerate kind of automatically. So the whole control of your system is about maintaining the torque on the motor. The higher torque you apply, then it starts accelerating up to the point where it stabilizes again. If you want to decelerate, you have to reduce the torque. When we look at the equation of the net torque, we see that it can be expressed as the moment of inertia of our load multiplied by the derivation of the speed. So turning it vice versa, the speed is the integral over the delivered torque divided by moment of inertia integrated over time. So the remaining torque applied to the load will give me the acceleration or deceleration simply by changing the torque that I apply from the motor towards the load. That's not only this. If we look at it from the time point of view, we can express the torque equation in the dynamic way as a differential equation. And we will find out that there are some parameters like moment of inertia, dumping and spring constant that give us a little bit more fun. Why that? Because it's a system with several energias and when you try to accelerate it or decelerate it, when you apply a step change in the torque, it may oscillate. So when you control it, it may become unstable in the torque control, in the speed control and that may be quite a big issue. So you have to think, for example, when changing the torque, whether you will destabilize your system or not. So when you adapt your control loop for the torque or for the speed, you have to choose the bandwidth of your control loop good enough so that you dump the oscillations. But next level when your application is already in a good control and then you can look at the higher level control loops. I'd like to point out to one specific thing. When you accelerate or when you increase the speed of your motor, the losses will increase as well. Unfortunately, you can't deliver to your motor infinite torque because it's rated for a given current and a given voltage. And the bigger torque you want, the more current you must apply. And at some point, the motor will simply burn or melt. So we have got some maximum torque that we can apply and that's as well associated with some current. And as we increase the speed, if I apply high torque, the motor will start increasing the speed. The torque available for acceleration will be reduced and it will be reduced by losses. So at some point, the losses will be equal to the torque I give to the motor. And at that point, I am not able to deliver more torque for the load because everything will be burned in the losses. So at that moment, I reach my maximum mechanical speed for the nominal current and I can't reach more because I am not strong enough to overcome the losses. So this is the first limit in the speed of the motor that's simply eaten by losses. So you have a limitation in the maximum current that will give you maximum mechanical speed. Now if you want to calculate mechanical power on the load, it's very simple. If I avoid the losses, I can simply calculate the torque delivered to the motor multiplied by speed in radians per second. So this gives you mechanical power in watts. Now let's look further. We spoke about the torque, but we need to generate the torque somehow. And the torque is generated by application of the two fluxes. One flux generated by the permanent magnet and the flux generated by the coil, by the winding. If you apply a current to the winding, it generates a magnetic field. If you take two magnets, one freely rotating and the other that you have in the hand, the magnets try to align. So if you move with the magnet or magnetic field around your permanent magnet on the axis, the magnet on the rotating axis will try to align with the magnetic field that you push with the other magnet or with the coils. That's exactly the principle of the energy transfer. So you generate a magnetic field with some direction and the permanent magnet in the rotor will try to align to that and to create the torque, I need two components. I need the force, which is described by the Lorentz law, and I need the lever. And the lever is effectively equivalent to the radial length of your rotor. So if you take the construction of the motor and you calculate the length of the lever and you calculate the force applied along this length, you get the torque, mechanical torque. So Lorentz law and the construction of your motor give you this transition between the current flowing through the winding and the torque generated by the permanent magnet. Simple like that. There is one tweak, however, that you need to understand. When you look at the Lorentz law, there is a vector multiplication between the orientation of your lever and the magnetic flux. And this gives you the biggest force when the angle between the two is at 90 degrees. So if you imagine when the maximum efficiency will be achieved, when you deliver as small current as possible for a given torque, but at the best angle possible. You don't want to pump 10 amps into the motor with a very small angle. If you can pump just half amp and increase or improve the control strategy. And that's exactly about the field-oriented control algorithm. It maintains this angle at 90 degrees and at the same time reduces this current as much as possible to maintain the required way of operation. So from this simple equation, you can think about orienting your magnetic field in the coil to the orientation of the rotor and maintaining the current to generate the required torque. If you want to accelerate, you increase a little bit the current. If you want to decelerate, you decrease the current. Maintaining 90 degrees here, you always work in the most efficient region of operation. So these two things, the current and the angle, are the outputs of the field-oriented control. Now let's look at the electrical part of our system. We have got a voltage applied to our winding. That's what comes from the power stage. That's what the guys with the isolated power modules or integrated power modules can do. Give you hundreds of volts with tens of amps and put it on our motor. When we look at it, some of the voltages in the loop is equal to zero. So if I apply a voltage here on the terminals of the motor, the same voltage must be somehow eaten inside the construction of our motor. So I will begin with the easiest one, this resistive part of the equivalent schematics. This is purely resistive losses. You have got wire, copper wire or other materials. And it's wound, so it has some meters of length, which means resistance. And this is pure losses that we want to eliminate. But they are there, they create heating and when you increase temperature of the motor, they change so they offload the system and make a lot of stuff. By the way, it can be used for measuring the temperature of the motor if you want. Further, you have got a part that I can't say is useful. But yes, this part is a dynamo. Who remembers the old bikes with mechanical dynamo on the front wheel driving your lamp? So you know this is a dynamo, right? Unfortunately, the same dynamo works even in the spinning motor. You still have a permanent magnet and you have a coil and the permanent magnet spins. So it inducts a voltage in the winding. If we control it right, the voltage is with the opposite phase from the supply voltage. So the voltage inducted by this dynamo inside the motor is simply subtracted from the voltage we applied to the winding. So at one point, it limits us in the maximum achievable speed. The voltage of the dynamo is called back EMF voltage, back electromotive force. And it's calculated simply as the electric constant of the motor multiplied by the speed. So technically, the higher the speed we achieve, the bigger voltage is inducted on the dynamo. And because again, we don't have unlimited voltage here, at some point they will cross. And at this point, we lose the voltage in the inductive part of our system. So up to the maximum electrical speed of our motor, we are able to deliver some energy through our coil. Which, by the way, is described as inductance of the winding multiplied by the derivation of the current over time. We know that we need the current for driving the torque. But by increasing the speed, if we keep our current at the maximum, this will eat the useful part of our voltage. So the higher the speed we have, the lower torque we can afford because it's eaten by the dynamo. There is one advantage though, the dynamo doesn't eat the power. So it's not loss that we would eat in the motor. Speaking about the back EMF, if I come again to the same equation, we have got a constant multiplied by torque plus losses plus back EMF. We are effectively interested in this part, but this part goes against. So you can see a setup. We have got bus voltage, the supply voltage of the motor. Then we have got our back EMF constant and as we increase the speed of the motor, the back EMF voltages increase as well. So the useful part of operation is here and it decreases. However, we have got a possibility to modulate or to change our maximum speed, maximum electrical speed. If you remember this equation, the back EMF is an electrical constant multiplied by omega. And the electrical constant is effectively a thing that comes from the strength of our permanent magnet. So what if I am able to reduce the strength of my permanent magnet? If you imagine that we have a vector control over the current delivered to our motor, we don't only control the size of the current, but we control the angle. And if I put the current in the opposite direction of the permanent magnet flux vector, I am able to subtract them, which effectively creates a weaker electrical constant. So if I change the angle of control, I am able to extend the maximum speed and that helps us to go much higher. The price you pay is that for a given current, you have got approximately this curve of available torque. So if I decrease the magnetization, I am losing my torque. So as a best result, I am not able to achieve this speed, I am able to achieve this speed. Because at this point, I am not limited by the electrical constant, but I am limited by the torque delivered to the load. It will be a little bit lower. So the magnetization, as we call it, or flux weakening, can be used only if I have a light load. Because if the load is heavy and I need all my torque to spin it, by the magnetization I am losing the torque. But if the load is light and I still have a lot of torque available, I can reduce it and I am able to achieve higher speed. So you trade the speed versus available torque. Where this is very useful, where at low speed you need high torque and at high speed you have a light torque. There is one very specific application, washing machine. When it's full of water, it's really heavy. It has a really big moment of inertia. So to spin it, you need quite a lot of energy. But as you start extracting the water, the water goes away and suddenly the load becomes lighter and lighter and lighter. And when you spin at 1000 rpm, you can simply use the magnetization because most of the water is already away and the load is much lighter than at the beginning. So this algorithm came from the washing machine manufacturers. It allows them to use cheaper motors and their nominal parameters are not calculated for 1000 rpm, but for the regular spinning, the slow spinning. So this is a side effect of this use case. So let's come to the construction of our motor. We have got stator construction. We have got a rotor, simplified as a permanent magnet, fixed on the axis going from the screen. We have got a stator coil. And if I apply a current through the coil, it will magnetize, create a flux and it will pull the magnet so that their linkage is maximum and the system energy on a minimum level. So applying the current to the coil translated to the human speech will move the rotor. If I look at it from the vector point of view, you can see that both vectors of the magnetic field have orientation and size. I can relate them to the same axis. Now if I add second coil and again apply a current, the rotor will move again to align with the second coil. Then for effect we have got as well the third coil. Now if I connect the coils together and start driving them, if I apply the current through two coils, which is thanks to the Kirchhoff law very easy, what happens? The two magnetic fields will sum in a vector way and they create a new vector where the rotor will again try to align. So by changing the currents through the coils, I can create any vector in the 360 degrees plane and this way I can always align my rotor anywhere I want. That's principle of the three phase driving. In case the phase W is disconnected, the current going through phase V is equal to the current going through phase U only with the opposite side. Now when we know how the construction of the brushless DC motor is made, especially with the inner rotor, we can distinguish two different types of motors, permanent magnets in chronos motor and brushless DC motor. Effectively they are very similar in construction. The main difference between them is how the stator looks like and how the magnets are organized in the rotor. When you look at them, the permanent magnets in chronos motor characteristics, especially if you look at the electrical parameters of the motor and you spin it, it inducts almost perfect sinusoidal shape. So the PMSM is very well suited for the sinusoidal control. The brushless DC motor has a little bit different shape of the back EMF. It's driven by the fact that as the rotor spins, the magnetic linkage between the coils and the rotor is not uniform, but changes with the angle because, for example, a different placement of the magnets in the rotor. They can be placed on the surface of the rotor or they can be buried inside. Then the magnetic field emitted by the magnets, it has a different shape. So as it goes around the windings, it increases and decreases the linkage of the field. So you can see it as a kind of modulation. And the result in the back EMF voltage is that you see a more trapezoidal shape of the back EMF than sinusoidal. You can as well identify these motors by looking at the inductance of the windings. For the PMSM motor, the inductance within every angle of the rotor location of the rotor placement is uniform and almost constant. If you look at the BLDC and you measure the minimum and maximum inductance over different angles of the rotor, these two inductances, the minimum and maximum one, will be bigger and we typically distinguish these motors if the difference in the inductance is bigger than 15%. It's as well possible and it's probably more optimal to drive the BLDC motor not with the sinusoidal but a block commutation principle or six step principle. Let's now look at how to control current in the motor. You know how the power stage looks like. It's six transistors connected in three half bridges. This is always one half bridge. They are connected to the same supply voltage to the ground and the phases of the motor are connected to the middle of the two transistors. So I have got phase U, V and W and each phase drives some current to the motor. If you look at this construction of the transistors and we think because of the efficiency of operation only about transistor fully open and fully closed, we have six gates which we can control independently which means that if the transistor is on, it's one state. If the transistor is off, it's another state. So I have two power six combinations. This is how much? 64. But it's not safe. So if I take 64, only eight combinations out of these are safe and will not burn these transistors. Why? Because if any of these pairs connects or turns on both transistors what happens is called cross conduction where the current doesn't flow through the phase but through both transistors shorts the bus and the ground and delivers so much current that the transistors typically explode or in the better case they desolder and drop down from your PCB. I saw all these cases. So it's really important if your gate drivers are able to prevent this cross conduction. So you have eight cases where the setup is safe and out of the eight cases only six of them drive current towards the motor. In the case number zero and seven, bottom or top transistors are closed and the current circulates between the motor and the bus voltage or ground voltage connection. This can be used by the way for very effective stop of the motor or deceleration. So if you look at the currents through the motor again we have to apply first Kirchhoff law where sum of the currents is equal to zero. So we can always measure just two currents and the third one is simply a minus sum of the two others. I can calculate the currents from the measurement of the others. By the way that's principle of the three phase sampling. You always read two currents from different phases. The third one is simply a minus sum of the two. So let's look at the difference of the control principles. I will compare block commutation and field oriented control. The block commutation is used historically and it's rather simple. It's generating six different vectors towards these transistors and you only need to switch at the correct time. That's a block commutation. However it has some drawbacks. First you don't react quick enough. If you change your load you will learn it only after 60 electrical degrees. So at that moment the change of the current can be quite big one and your current control won't be really smooth. So you can expect some torque ripple and slow reaction on change of the load. The sinusoidal control has different positives and negatives. The negative of it is that it's more complicated and a little bit more expensive. Why? You need at least op-amp and you need a better microcontroller that's able to calculate quickly enough. Then I can say it's really more difficult to implement. You need to read the currents good enough. So you need to have probably op-amps and some performance of the core. But the really big benefit of the field oriented control is that it has a rapid reaction on change of the torque and load which means with every PWM cycle and you can generate PWM at 50 kHz if you want. So every 20 microseconds you know what is state of the motor how big are the currents if the load changed and you can start reacting on that immediately. So the field oriented control has a really smooth control over the torque and because the speed is the integral of the torque then as well over the speed. Additionally it allows for quadrant operation so you can deliver the energy, you can extract the energy you can return it back to your system if the hardware is ready for that. Now let's look at how we control the outputs. We know that we have got six transistors and with these six transistors we open them fully and close them fully. However, how to do it in a correct time and with a correct frequency? Normally we use a fixed frequency with which we open and close the transistors. So you can look here the duty cycle, the width or length of the time when the transistor is open with a fixed period is equivalent to the voltage that I want to generate on that transistor. So you see that as I change the voltage over the generating signal the size of the voltage is exactly proportional to the width. So you can see as the voltage is increasing towards the peak here the duty cycle is as well increasing from approximately 50% to 100% and then starts decreasing, decreasing, decreasing and when I'm at the minimum the duty cycle is zero so I'm not generating any pulse here and this all repeats with the generating signal frequency. So the high side is equivalent to the voltage the low side duty cycle is exactly opposite and when I look at the current this is a simulation with some inductance of the winding when you look at the current you can see that there is some ripple in the current and if you average it then it's a sinusoidal but that's how it looks like. Now I like to point out one thing you know that FOC needs to control the current we spoke about it when we spoke about the generating torque so I need to read the current to be able to control it when you look at this shape of the current you will find out that if the motor has high inductance of the windings typically the rise and the decrease of the current is very smooth it's slow so reading the current is rather easy because it doesn't change too much which means you can have a relaxed ADC sampling and you can afford nice and slow op amps and so on however if you need a very high speed operation your motor will have most probably very low inductance of the windings just couple of turns and that's it trouble with that is that such motor will eat quite a lot of current very quickly so the rise of the current and drop of the current will be very quick and this shape will be much noisier and trouble with a very noisy signal on the current is how you want to measure it when you want to measure it and how good ADC and how good op amps you need so for very fast motors or especially with motors with low inductance you need a very good current measurement because the current changes very quickly very rapidly so let's jump further with the FOC principle we have got the three phases we generate three currents or I say three voltages and these together create a rotating field multiplied by number of pole pairs in the motor then we have got a rotor with a set of permanent magnets that are as well oriented so that they have the same number of pole pairs quickly and when I put together the magnetic flux of the rotor and the magnetic flux of the stator of the generated field the principle of the control for the field oriented stuff is to maintain the angle with the best efficiency which normally is 90 degrees so to be able to spin the rotor with the best efficiency the smallest current for the same effect I need to maintain the 90 degrees then the upper loop will control the current to give you constant speed, constant torque or whatever else you want so to be able to do this I need to read the currents so current sensing is needed I need to read especially the position of my rotor because if I want to maintain 90 degrees I need to know where to place them so I need to read where the rotor is and align the statoric field along I need to control the currents which is the principle of the field oriented control so I need a set of regulators we work with the PI regulators but we can as well apply a feed forward so this is effectively the principle of the field oriented control because controlling the currents in a rotating system is quite complicated let's imagine like if you have a current on the chair somewhere here and you are spinning the chair how easily you can maintain track with the current and control it it's quite difficult, right? so I will first begin with the Clark transformation when you look at the currents that you read from the three phases you see that they are organized with a 120 degrees electrical displacement this is not nice we normally work with a 90 degree displacement so let's apply a Clark transformation that takes the currents with 120 degrees we align it to one of the phases which is typically phase A and we calculate the perpendicular part of the current which is 90 degrees apart so that simplifies our transformation or reference frame it's a very simple equation further as after Clark transformation the whole system still spins and I need to read and control the currents it's rather difficult if I do it in a rotating system so what about a little trick that demodulates the rotating currents with a rotating frame of the same speed but the opposite angle at that moment it's like if I wanted to read one current on the chair for example where the pointer is and I will be spinning with the chair it's quite difficult but if I take the same current and sit on the chair and spin with that then the current has always the same direction and always the same size so at this point after the park transformation I've got a perfectly steady and DC currents so that's the second principle of the FOC control to make our life easier you can see it here as on a block diagram so the Clark transformation takes three rotating currents and calculates two of them Park transformation transforms the rotating currents into the stationary and then I get the currents the D current that's parallel to the flux of the rotor and the quadratour current that's perpendicular to the flux of the rotor we can as well look at it as the magnetization or demagnetization current and the torque current then we take these currents through controllers like PI or PID or feed forward and we get as the outcome the voltage technically the Q controller will simply increase or decrease the torque request because if I want to accelerate I will boost it if I want to decelerate I will reduce so at the end it will give me a higher or lower voltage with the correct angle then I've got two voltages that are steady I've got a spinning motor so I need to do something with that to modulate these two steady voltages again through the inverse Park transformation so instead of demodulation sinus cosine matrix I'll multiply it to the modulation sinus cosine matrix just flipped plus and minuses in the matrix so rather easy through this stationary rotating transformation I get again two voltages and then I need to create from the two voltages three voltages or duty cycles for my power stage I can do the three times sinusoidal output but we know more effective ways and one of them is a space vector modulation so after the whole process from the three currents I read in my system I get three voltages that I apply back to the windings advantage I've got full control over the magnetization and the torque and I have this control independently so if somebody is interested in the equations and how it looks like on the oscilloscope for example you can read it here and that's about the field oriented control