 Let me continue with the following topic and that's about our sensor less capability to drive the Brushless DC motors. This morning you saw that we have a support for different types of sensors current reading topologies, speed sensors, position sensors but especially when speaking about external sensors they are expensive not only because you need to pay for the sensors, you need to pay for cables for connectors, for space on the PCB and so on. So if you have a choice to use a sensor less algorithm that doesn't need any extra wires doesn't need extra sensors and improves the robustness of the system the sensor less algorithm is a way to go. So let me show you how this sensor less mechanism works. First when you drive the motor you have three terminals connected to that and the only thing you can measure and that you have available in the system is the currents and the voltages. There is nothing more you can measure and you can deliver to the motor. So you have to live with these parameters and somehow you shall be able to simulate what physically happens in the motor. You should validate this and you should extract useful things from this model. We have chosen historically a model of the Luenberger Observer which is present here and it's called BeckyMF State Observer. Why BeckyMF State Observer? First it gives you as a result of intermediate calculations the representation of the BeckyMF voltage from the motor which is equivalent to the voltage inducted by the rotating rotor within the windings and it gives you as these two values the information about the amplitude which is effectively speed of the motor and the phase which is the position of the rotor that we need. Further State Observer means that it represents the physical state of the motor in terms of mathematical matrices and some calculations. When you look at it you find out that the State Observer takes as an input parameter exactly what I have spoke about. It's the current represented as a perpendicular iαiβ so a rotating current. It as well takes as an input the voltage delivered to the output to the power stage from the previous step as the αiβ and to have a scaling representation it as well takes the bus voltage. So with these three parameters with these three inputs it takes the physical model of your motor with the inductance resistance electrical constant and in an iterative loop it tries to estimate the BeckyMF and it tries to estimate or compare to the measured current because we give it an input the voltage on the power stage and we give it the output that it should as well simulate and compare. So it's able to lock itself on the measured current and adapt to it and the BeckyMF is let's say intermediate state variable of the model not a direct output. Further we use the BeckyMFs and we process them to get our speed and the angle of the rotor so electrical angle and this comes in a second block. This is a block put on top of the state observer and here we have two options. We have a PLL and a Cordic option. So if we look at the state observer we can find out that it effectively represents the physical behavior of the motor which means through the electrical constant it calculates what is the transmission from the delivered energy to the output torque it uses the resistance and inductance for the time constant of the integrator plemented inside and it as well uses a loop back where it works like a regulator self-adapting regulator from the currents that are estimated at this point and measured at this point and this is added with some feedback back to the beginning of the model. So advantage of the Luenberger observer is that it's self-adapting but to work properly it needs to know something about the motor which is the inductance resistance electrical constant. So speaking about the transformations you can begin with for example voltages inducted on the coils and you can build a complete model of your electrical motor and coming from the known parameters and the model of the motor you can come to the results that are quite a lot of simplified that at the end give us state variables representing the back EMF. With every PWM cycle the microcontroller reads the currents and at the same time it takes the voltages from the previous step this is what we put on the power stage on the space vector modulation block these voltages are the input to the motor and it reacts on a delivered voltage, right? So the model takes the same voltage and processes that within its physical representation of the motor. The outcome of this state observer model is the current flowing through the windows. So at the same time I read the real current which gives me the difference that gives me a verification of my assumptions of the model. So when I calculated the difference between the two I can react on the errors, on the differences between the calculation and the reading and through a feedback coefficient I can adapt the speed of reaction and the dynamics of the model. At the same time this parameter in the real model called G or C2 parameter and you will see it during debugging of your algorithms quite often you give it a bandwidth because it works like a regulator effectively and the bandwidth has very important features for debugging because if the bandwidth is too high the reading of the current brings some noise the calculation is as well not perfect so here at this point you would see quite a lot of noise if you amplify the noise too much what happens is that the model will be unbalanced and the regulation, the estimation of the angle won't be smooth so if you dump the error signal reasonably so that it's still able to lock itself on the physical properties of your motor but it doesn't react too much on the random noise it gives you much better results. Part of the internal variables of the motor model are the back EMFs. So when we complete the Luenberger observer model we calculate one step. This step will give us as two internal variables the eα and eβ. You can read how they are calculated so through the flux, through the number of pole pairs the speed of the rotor and the sinus and cosine of the angle so the most straightforward method of extracting the angle that we use for the FOC loop for the PARK transformation and inverse PARK transformation is to take the two values and make an arcustangent of that this is the most straightforward method. Unfortunately it has drawbacks and the drawback is that especially if eα is very small and nears to zero you'll see that it becomes really sensitive to the noise so at that point you know that the current reading is noisy it has got a limited resolution 16 bits so when it comes to this calculation the result of the arcustangent is unusable because you cannot guarantee in quite a big range of angles that this won't create any troubles so using arcustangent is a no-go that's why our engineers in Catania when they created the library many years ago they came with the closed loop regulator that takes the model of the PI regulator and the integrator and that works as a closed loop that tries to match its output the angle with the sinus and cosine as close as possible to the eα and eβ created by the Luenberger Observer it has got one disadvantage which is quite small the disadvantage of this model is that because it contains a time constant it needs a little time for locking on your signal and this time constant as well creates a limitation in the bandwidth so it has got a limited speed of estimation on the other side it can be tuned and it doesn't normally bring any issues and then come the advantages thanks to the time constant intrinsic to this loop and thanks to the fact that it adapts to both signals independently of their amplitude it's very stable and gives you a very good approximation of the angle and of the speed so it's very reliable and if you don't have a crazy motor that really changes the speed really quickly it's a perfect way of reconstructing the angle and the speed at the same time PLL PI is available if I enable manual editing in the dialog box of the speed position feedback management so if you want you can tune it manually but normally the workbench pre-calculates these values in a really reasonable way one additional thing when I spoke about the feedback parameter within the Luenberger, the K you can find it in the same dialog box as the G2 parameter if you work later in a runtime you will see the same parameter called C2 I don't know why in the workbench it has two representations but it's the same value simply by reducing it you are reducing the influence of the error and you are dumping sensitivity to the noise at the same time of course you are dumping the bandwidth of the Luenberger but it can really help for example if in this case it was pre-calculated to 21000 you can divide by 2 by 3 by 4 and you can really come to values of for example 2000 if the current reading is too noisy this parameter can be reduced quite a lot so the PLL is one of the two options that we use for the sensorless algorithm the second one is a CORDIC CORDIC was implemented on request of one customer that wanted to try it so we found it useful and we implemented CORDIC is let's say a simplified or algorithmically simplified version of the ARKUSTAN gap so it gets two values and with a predefined number of steps with a bit shift and multiplication so it's very cheap for implementation in software or in FPGAs it's able to approximate the angle and this is the result of the CORDIC by number of iterations you predefine the precision and you can see that with each single step it comes closer to the given input values so if you for example stop at the iteration number 8 you see that the maximum difference in the angle is 0.2 degrees if you iterate further and if the precision of the calculation allows you can improve the precision even more so this is kind of ARKUSTAN gap for us with a little bit more reliable result anyway because it doesn't give you any intrinsic filtering it's still influenced by the noise so it can give you quite a big angle steps angle jumps during the estimation which doesn't represent what really happens in the motor so at the end we still need to apply some small smoothing filter at the end of the CORDIC then the CORDIC has you choose it as the option for the main or auxiliary sensor a different set of settings now there is a question how the state observer works during startup when you start your motor at the moment when you start it the observer doesn't give any useful information and it doesn't give it up to the approximately 5% of your nominal speed so below that the information from the observer it's a physical limitation it's a limitation of the hardware design it's a limitation of the resolution of the variables so if you use 16 bits then you know that there will be a lot of digital noise in calculations so there is a reasonable limit of 5-10% of your nominal motor speed where you can't use it and that's why you need to help yourself during startup with some other method we have chosen to use a forced startup with an open loop approach what that means you prepare the acceleration ramp you prepare a current to frequency curve and you simply start it and you expect that at low speed the motor will be able to stick to the accelerating magnetic vector and it will accelerate along and during this time you will take the measured current and the voltage applied to the space vector and you put it in the Luenberger Observer so the startup has two tasks first one is physically start spinning and the second one is to collect enough data so that the Luenberger Observer can lock and start delivering useful information and during this startup we measure how the Luenberger Observer gives reliable data and if they are reliable enough we consider it a good startup and then close the loop and give the control to the Observer instead of the forced startup or forced speed ramp that's how we do it so it's open loop you generate accelerating ramp and when you consider the startup valid you close the loop there are two possibilities for the startup setup you have got the basic one and you have got advanced one the basic one gives you a simple acceleration ramp the red one is the speed so it goes from zero to the preset speed the blue one is the current you can see that there is as well one additional point turned on and this is the alignment you normally apply a DC vector in the winding with a fixed vector and increasing size increasing amplitude of the current and this builds the magnetic field in the stator and the rotor tries to lock to this position because when you stop the motor you don't know where it is at the moment when you want to restart it so what do you do? you apply a permanent magnet and the rotor will lock to this position there is however a little trouble the trouble is that locking to this position can be difficult if the motor is very light so if you have got a reasonably small load it will accelerate very quickly and it can overshoot the position and come back and then it will stabilize around this position through vibrations on the other side if the load is too heavy it can happen that it will not reach this position in a correct time and if the load is even heavier it may not be able to ally at all typical case would be a compressor if you have a fridge and you stop driving the motor with its inertia it will move towards the higher resistance when it pressurizes the air or the liquid with the piston and as the pressure inside rises it will become higher than the pressure of the pump itself and the pump will stop and now if you want to align to the direction of the higher pressure you simply don't have enough torque so you won't be able to do that and that's why we came with advanced startup that allows us not to define just a single ramp or single alignment but it allows us to define up to 5 steps where we can play with the currents with the speeds we can define a zero speed with a negative current or vice versa so the purpose of the advanced startup is that you can for example turn and align the motor backwards for the pump this has a very interesting result because instead of pushing against the higher pressure you can release the pressure when you turn backwards you are decreasing the pressure so you are moving the piston backwards and then when you start real acceleration you are coming over much smaller pressure when you gain some inertia you can overcome the highest pressure peak and when you gain more you don't feel it anymore so the advanced startup can help you in these situations when the startup could be too heavy further when it comes to acceleration you have to always adapt the current and the acceleration rate to a given load why if the motor tries to accelerate too slowly if the load is too heavy it can happen that the speed is reached imposed too early and you lose the track of the motor so it stalls this typically means that the speed at the end of the ramp is too high or that the current that you deliver to the motor is too low so that you are not able to deliver enough energy for the proper acceleration so you always have to tune the startup little bit manually the motor profiler helps you with the task but if you do it manually it's a little playing with the two parameters current strength and the maximum speed acceleration so let's look at the different steps of the startup and where you can find them in the startup parameters so the first thing is acceleration in the basic startup procedure we can see that the startup begins with a zero speed and we define duration of the speed ramp and we define the final value of the speed ramp these two parameters give us the acceleration fixed acceleration applied to the motor this is depicted as speed ramp duration in milliseconds and final value in RPM further we have to think about how much energy we deliver to the motor it's expressed in current in amps but it reflects the VF curve so at the beginning you probably don't need really high current but at the end the current should be big enough to give the boost to the energy of your motor and the load these values are depicted here current ramp initial value current ramp final value and the duration of the current ramp at the beginning normally you can start with the current that's let's say one half, one third of your nominal current of the motor to give it really a reliable boost at the beginning if it's not enough you can set it up to the nominal current further if we look at the advanced ramp we have different stages we have up to five stages and in each of them we define the end point with the duration, the final speed and the final current so we can play with the ramps independently for the current, for the speed we can define negative speeds, negative currents so this depends on us and the question is how we estimate that our startup is reliable because there are no speed sensors that would tell us okay now the observer and the PLL or CORDIC give us a good speed and good angle estimation we have to use other methods and for that we have developed a statistical method to create or to calculate the reliability so we take our feedback from the observer and from the PLL and we put it in the speed buffer so we have got estimation of the speed from the observer we put it in the speed buffer this has typically 64 items but we can choose by any number of powers of two so it can be 32, can be 128 64 is a good length but for systems with higher dynamics the length of the buffer needs to be reduced for example to 32 because if you accelerate slowly then for the 64 compared to the normal speed we have got a reasonable distribution of the speed but if we accelerate very quickly and we calculate the statistics from that we see that against the average speed we have got a very high variation so if we reduce the length of the buffer the variation will be smaller so we can play with length of the buffer and we can avoid unnecessary errors in our design so how this works during the startup we read the speed estimation we put it in the speed buffer we calculate the average value of the speed in the buffer and we calculate the variance the statistical variance that can be calculated this way and we compare this speed variance with the maximum factor that we allow and if the speed variance is wider than expected we consider it as a non-valid result if the variance and normally it's narrowing narrowing narrowing when it's considered valid within the limits we set up for the startup then we validate the startup as a good one so the comparison is done here we have got a parameter called variance threshold and we use it to compare the mean value squared times variance threshold against the calculated variance the variance threshold can be as well set up in the speed position and feedback management in the variance threshold field here normally it's set to quite a small value, 6% this value is good for detection of the motor stall because if the motor is stalled then the variance is typically higher but for a startup estimation and validation especially when you begin with a new motor you can increase it up to 50% or even more to give you a trial to see hey, we can turn the motor we can close the loop and it works but at the end the target of the speed variance threshold is to tune the proper startup to tune the Luenberger observer dynamics and reduce the variance threshold as much as possible because when you are sure that your motor starts reliably the second step is to use the same thing to validate that there are no issues with the motor rotor locked so as soon as you have a validated and good startup debug, reduce this parameter as much as possible when we validate the startup and in runtime as well the variance of the motor this is not the only parameter that we can use for a good validation because the motors, when we for example load them too much when they lose track of the rotating magnetic field they stop, they stall but if the magnetic field still spins around if the rotor, if it's not really firmly fixed it has got a very nice idea of oscillating around the stalled position so it oscillates and the stator still rotates around trouble with this situation is that from the current reading because it normally oscillates at the same frequency of spinning the current reading gives you a perfectly reliable speed estimation telling you hey, the motor rotates, everything's correct and it is not so the vibration is a really nasty thing for detection because frequency wise it's still perfect it vibrates at the correct speed so the current readings are as well correct so it's quite difficult from the statistical point of view to find this, if not impossible however we have a method to detect this and that's the second reliability check in run mode when the motor vibrates, when it doesn't spin like usual how big is the back EMF? it's much smaller so if we use the trick that we have got the back EMF estimation calculated from the currents we see the real result because we adapt to the real current reading so our amplitude of the back EMF coming from the observer gives us the information about the real speed on the other side I've got the estimated speed coming from the vibration which gives us an seemingly good result so I take the speed I multiply it by electrical constant of the motor I multiply it by some tolerance or consistency gate and I bring it to the comparison and now I compare the back EMF right from the motor and the back EMF estimated for a given speed and if they differ by more than a given consistency tolerance I know there is something wrong because the motor should spin at the given speed it should give me a given back EMF amplitude but the back EMF amplitude is much smaller so it doesn't spin, it vibrates this second method is used only if you change the consistency tolerance normally it's set to 100% so this test is bypassed but if you set it to a lower value you can activate this test and I recommend it again it's available in the speed and position feedback management dialog box alternative to this is that the SDK gives you a power estimation block so if you read the power delivered to the motor you will find out that for the rotor stalled the power is much smaller so if instead of expected 200 watts in your load it gives you 2 or 3 watts, you know you have an issue so the power estimation can be as well used for the same principle in fact it comes from the same parameters let's come back to the startup procedure because that's not the only way of validating the startup you know the Luenberger observer can for example detect the speed too early and it may not be reliable enough so we have a couple of other parameters that need to be fulfilled to validate our startup so the first one is the consistency or variance threshold second one is that the estimated speed is within limits of the forced speed so I am setting to the motor 550 rpm I am expecting that the observer will give me something between 540 and 516 if the speed is different, if it's out of these bounds it's not a valid reading so we need to wait a little longer for the Luenberger to lock so this is the second thing and the lower and higher limit is expressed in percent of the imposed speed at the same time we know that below a certain speed let's say below these 5% it's really unreliable to use the observer so we as well set up a minimum speed to exit the open loop and that means that the algorithm will wait at least to this imposed speed then it will validate the estimated speed and it will validate the variance and only then it will say now I have got a valid reading let's close the loop additionally this test has to be applied for n consecutive times two or three it's just one random reading that looks good it's not enough so we give it typically two consecutive readings and then everything seems good how to set it up? in the startup parameters you say consecutive successful startup output tests this is the n minimum startup output speed is this one the estimated speed band tolerance upper limit is this one and lower limit is this one plus variance threshold is in the sensor parameters let's see where these parameters come from and what they mean now I am coming to the point where we may have a startup issue this typically happens when you have quite a light load because when you impose a magnetic field in the stator and the rotor follows and it has a light load as you increase the current maintained at some value how far is the rotor the vector of the rotor from the vector of the statoric field not far at all because it's very light so it can very easily follow so the distance can be for example 15-20 degrees so with this angle 15-20 degrees what is the efficiency of the energy transfer? it's very low because the sinus of the vectorial multiplication is small by sinus of this angle and at the moment when you close the loop it will switch over to the angle estimated by the observer so what happens then? you are imposing 90 degrees at the same current what happens? yes exactly at this moment you can several times increase the torque so you are accelerating with some torque because of low efficiency and suddenly by changing the control angle you impose three times higher torque so what happens with the motor? it starts accelerating like hell and at this moment because we are still evaluating statistically whether the speed estimation is good and has low variance if I have got for example this speed acceleration and then suddenly it goes this way at this moment the variance will not fulfill the condition and our algorithm says sorry guys it's not a reliable speed reading let's stop so at that point you get a speed feedback error so what to do now? we have got the possibility to counteract this effect and that's exactly with the arrive up to FOC switch over this is an algorithm that changes the current from the imposed one to the one estimated by the observer fluently with a given duration so if you activate it it takes the current imposed at the moment of closing the loop and starts applying slowly in a ramp the current imposed by the let's say control loop so this way I'm going from the forced current to the regulated current slower which in many cases helps on the other side we know two types of motors ones that like this switch over and ones that hate it so you have to try if you get this error whether to turn it on or off unfortunately we tried different methods like calculating the efficiency of the motor control and changing fluently the angle or changing the current or imposing other currents and it's not that reliable so this simple method seems for now the best one and it allows to control the acceleration quite efficiently let's move to this picture this is a very nice picture that is measured with the current probe and two outputs of the DAC that are driven by the library so you can see a really nice start-up with all the parts of it perfectly adjusted so when we look at the beginning we can see that the current is rising up for the alignment further it imposes the ramp with acceleration and you can see that the observed back EMF one of the two back EMF signals first isn't really nice but then it becomes better and better same thing with the observed electrical angle at the beginning it's quite rough it has got steps in that and as the speed increases the readout of the angle, the calculation of the angle becomes smoother and smoother so exactly at this point the start-up was validated and we closed the loop so what happened because this is a speed mode it started the acceleration and wanted to reach 5000 rpm so what it did you can see that the speed algorithm increased the current to full one and it lets the motor accelerate to these 5000 rpm as soon as we reach the speed the regulation algorithm decreases the current and maintains it only so that it covers the losses and keeps the motor spinning at 5000 additionally you can observe that the back EMF here gives you some estimation of the little bit increases as the motor accelerates but as soon as we turn to the closed loop and we use the speed regulator the back EMF amplitude increases and the frequency as well increases so you can see a perfect representation of the back EMF calculated in the motor this is physically correct and this is just to represent that the angle calculation works well we would need to zoom to see the details but it would still be the saw the map is a really really nice representation of a good response well tuned system so remember it and make your designs this way the mtpa was developed to support motors with a brushless DC characteristics these motors are trapezoidal so their response of the back EMF is not a sinusoidal one and you can see that thanks to the fact that it has got a reluctance torque added on top of the synchronous torque so this is the equation for the torque in the motor and because for such motors you can identify two different inductances the minimum and maximum one which are perpendicular to each other and reflect different currents when you simplify the equation you can put it so that the torque relies on the quadratour current and there is a swell part that relies both on quadratour and magnetization current and this one because the two currents have the same frequency but multiplication brings a double frequency it brings a ripple in the torque when we look further the mtpa tries to use this reluctance torque and adapt the control strategy for better efficiency so we can continue further with the expression of the current torque that the first parameter is equal to the sinus omega or epsilon with the same frequency but then we have got the reluctance torque with a double frequency now if we put both torques on the same chart the synchronous torque, the blue one and the reluctance torque, the red one we can find out that if we sum both torques together it will create the yellow result and because we want to control the maximum torque transfer from the delivered energy to the motor we will look at the total torque and that means that if we want to transfer maximum energy we will not do it at 90° but we will do it a little bit further so if we have a motor with a reluctance torque which means trapezoidal shape of the back EMF or different inductances in the windings that we can identify we can calculate this phase shift and the phase shift changes with the amplitude of the current to the influence linear and here is the influence quadrature so at the end when we calculate the angle change we can calculate it for different points of the current from 0 up to the full nominal current and from the value of the two inductances we can identify the phase shift between these points so if I increase for example the current to 50% I get the phase shift of 110° if I calculate it to nominal I get 130° so this depends mainly on the ratio between the LD and LQ then we can play a little bit further in different coordinate systems and we can calculate the torque versus ID, torque versus IQ and at the end we will linearize this calculation it's pre-calculated by the motor control workbench it gives you several points pre-calculated by the workbench it lets the algorithm and TPA algorithm linearize between these points so at the end when we enable the MTPA it will prepare a table for us and the table will be applied on the demagnetization current depending on the value of the quadrature current so this way with increasing current it will change the angle and this implements better torque transfer or optimum torque transfer the algorithm is allowed only when you have a motor with a different LD and LQ if they are equal this algorithm is not present and you can't turn it on so the table here gives you a performance so simply by clicking that you want the MTPA you can gain the efficiency it's like a magical button yesterday we spoke about flux weakening in terms of the physics the principle is that if we have some spare torque we can exchange it for the demagnetization of the permanent magnet on the rotor and increase the speed because we reduce the effective electrical constant so the flux weakening is used for extending the speed range and in some cases it can be as well used for smoothing the regulation of your speed range because what it does it reduces the torque it reduces the strength and if you still have some available torque at the end of the speed range the regulator can unbalance it so when you reach the maximum speed it can start vibrating and the result is not really nice so applying flux weakening can help you either to overcome the maximum electrical speed or to smoothen the regulation at the end so typically flux weakening is used in applications like washing machines or air conditioning and it operates on the back EMF how the back EMF or flux weakening works from the FOC control principle normally when we regulate the motor we regulate the torque so we maintain IQ constant on some value equivalent to the torque reading but we keep the ID at zero because changing it from zero eats from our current budget in case of the magnetization we get or we impose a negative ID current and the negative ID current works against the vector of the rotor magnetic field so it simply subtracts in a vectorial way and reduces the effective effect on the statoric winding so by this our solution allows to increase the nominal speed and we have tested 5 times nominal speed which is quite a lot but still think about the multiplication factor when you reset the microcontroller 320 volts times 5 quite a lot so the flux weakening is suitable for both motors with internal permanent magnets and surface mounted permanent magnets so the ones with the reluctance torque the ones without reluctance torque our algorithm doesn't require the knowledge of the system because it uses a closed loop approach so it self adapts and cause the speed control relies on the bus voltage if we use the flux weakening we use the readout of the bus voltage to compensate against the effects of dropping of the supply voltage the block diagram of the flux weakening is imposed here you can see that it takes the input of the bus voltage here it puts it into the regulation loop which is expressed here as a PI controller and at the same time it takes the voltages from the FOC regulator it calculates their absolute value the amplitude of the voltage compares it against the available bus voltage and that is used for changing the ID so effectively how this works let's imagine that you're connecting your system at 320 volts standard supply from mains rectified mains then you apply a given speed to your motor this is effectively expressed in some voltage on the windings 200 volts do I need flux weakening at 200 volts? not at all so I increase the speed I increase it to 300 do I need flux weakening here? to the level of the V bus and approximately 97% of the V bus so this is 310 volts at this level the flux weakening starts operating you can set up in percent at which level the flux weakening operates so if the voltage calculated from the power stage reaches 97% of my V bus it starts thinking, it starts calculating what if I need higher voltage so it starts magnetizing you can see that there is the integrator that calculates from the requested voltage and from the available voltage how much I need to integrate the limiter then calculates the ID you know that the magnetization works only for the negative values of ID so the limiter cuts everything above and if there is still a higher request for the phase voltage it integrates more if there is a lower request it integrates less or again returns the integrator back to zero so the outcome is that if I need more voltage for acceleration equivalent to the higher speed it starts the magnetizing if I drop the speed it returns back the integral constant here and then it sums it with the result of the mtpa limits again then it applies as well the limit to IQ because it does not overcome the nominal current of the motor and then these newly calculated currents are applied to the FOC model so thanks to this fact that I am calculating the requested phase voltage versus the available voltage and I am using the integrator here I can adapt to any speed I want and if there is enough torque the magnetization will work if there is not enough torque the speed will drop down or return to zero so it will find some midpoint where it trades off between the magnetization and the available torque so effectively when you apply flux weakening you have to define at which voltage level it starts acting the default case is 97% and then the rest is the PI coefficients for the flux weakening regulator one thing here time constants the flux weakening regulator should be much slower than the speed regulator if their time constants would be similar they would move from one to the other and you will see very nasty oscillations now when you activate the flux weakening you can see that it's one of the additional methods or advanced methods and when it's activated it gives you P and I coefficients and the voltage limit so these are the parameters that you need to tune for the flux weakening to work properly then otherwise you can observe it in real time and see how it works because when you run it in run time you can see bus voltage allowed and measured and when they match flux weakening will start the magnetization so you will see it on the id ref current additionally with the older library with the GUI you could as well tune it on the display and the ST eval boards you had this graphical interface available so in run time you could change it directly on your eval board so you can see the performance of the flux weakening so in this case we are using a motor that runs at 5 times nominal speed and what is really interesting at this speed we have got 13 FOC slash PWM cycles per each electrical rotation so it's really rough regulation and it still works very well and you can see further the voltages the currents, the control the phase measurement of the DC bus and the regulation changes so let's speak about the feed forward this algorithm is normally again used as a algorithm that helps you to improve the efficiency in case of high CPU load and for example high speeds or high reaction high dynamics of your system the theory of the feed forward is that while the loop back system typically reacts after the change happens and tries to regulate it back so the closed loop always reacts with a delay which is sometimes unwanted behavior sometimes you want to react immediately and that's exactly the method of feed forward the feed forward mechanism reacts or can pre-calculate immediate change for example if you drop a supply voltage and you want to maintain the constant speed normally once you drop the supply voltage the microcontroller or the power stage will as well drop the effective voltage on the motor and the motor will immediately start decelerating and the speed loop will take some milliseconds to react on that and then it will take another milliseconds to come back to this speed so a closed loop will give you the effect but it will give it late while feed forward sees hey I've got a drop in the supply voltage that means that if it dropped by 20 volts I need this torque to give it back to maintain the same speed so it knows 20 volts at this speed means this amount of current let's put it immediately on the output to compensate so the advantage is that it reacts almost immediately a little disadvantage is that you need to understand what you are doing you have to make a quantization of your model you have to understand what is the energy of your load what are the parameters of your motor so it needs quite a lot of parameters we have got such system implemented it uses the parameters you put in the motor model it can compensate especially the drops in the bus voltage where this is useful if you have for example a system with two motors where one is accelerating and one is decelerating then the feed forward can compensate for changes of the bus voltage immediately so the reaction of such system is then much better feed forward effectively can help specifically if you have several motors and it can help with the cross coupling with the back EMF cancellation and it's implemented here on top of the FOC model so it takes the bus voltage it takes the speed and it compensates for the feed forward current regulation and bus voltage adding its output together with the current regulation so giving you the request for the stator voltages and we normally suggest only if we have some harsh conditions or regulation conditions that are difficult like a very fast motor operation when we have small amount of PWM periods per electrical cycle because in this case we don't have enough time for proper regulation so feed forward will improve the efficiency the parameters of the feed forward are calculated within the motor controller bench and it doesn't allow tuning another effect or another algorithm used inside the SDK is a circle limitation algorithm this is intrinsically implemented to all voltage commands to the stator and they effectively scale the voltage request from our control algorithm from the FOC loop to the available bus voltage so the scaling ratio the axis modulation index this is a constant and this voltage are pre-calculated from the nominal voltage of the model that we included in the MC workbench and it gives us a scaling factor for VQ and VD and when the circle limitation is applied it effectively takes the ratio of the VD and VQ requested from the FOC model it multiplies it with the pre-calculated factor and the result is then sent to the space vector modulation scheme so effectively the circle limitation is a thing that is able to scale down the voltage requests from full range to the available voltage it's implemented automatically pre-calculated by the workbench applied in the SDK further algorithm I'd like to speak about is a space vector modulation there exist several different methods how to bring up the freeface voltage on the phases the first one if you want a rotating field at the outputs of your power stage how would you do it so we can think about different ways of modulation of the motor and we can boost the energy transfer to the motor by modulating centered voltage so if I modulate it with cleverly designed shape I am able to bring for example 7-10% of the energy more because I gain the voltage by shifting the central point the space vector modulation is one of the algorithms that allows this and you can see that for different angles from 0 to 360 degrees it can split these angles by 60 degrees and then bring you a shape that looks like this this is a voltage on one of the phases this is a voltage on this case phase A and this is a linear transition for phase B so when you look at this 60 degrees cut it's very easily implemented this is a sinus table this is a sinus table inverted this is a linear transition so calculating such output is really easy additionally this is not a pure sinus but this is a sinus with third harmonics because this way I am able to boost the energy or the voltage by approximately 3% more additionally injecting third harmonics in voltage will increase the effective voltage on the motor but it will cancel in the current so the current will still be beautifully sinusoidal without the third harmonics seen in the current so by preparing a table with third harmonics and applying it this way of course scaling it depending on the duty cycle I can implement the output very easily and this is how we do it so you know what are the boundaries for the current reading where there are limitations for the current reading for ADCs you can for example imagine that at this point where both voltages here are very close to each other you have got an issue reading the current same situation happens here in the middle it's rather easy but if for example you are working with a very small duty cycle when all voltages come closer then again you start having problems reading the currents so depending on the phase each of these six steps the algorithm inside doesn't only generate the proper duty cycles but it as well generates a proper time and the proper input for ADC to read the currents so the control block that takes care about the space vector modulation generates both duty cycles and proper sampling times and proper sampling inputs at the same time