INTRODUCTION
In this article we are going to discuss a couple of aspects that you should expect when building complex applications like Motor Control Speed Control of PMSM based on Sensorless methods. As discussed in Module 9: Position Observer (Part 1/2) and Module 9: Position Observer (Part 2/2) there are numerous techniques for estimating the rotor speed and position and one method was chosen to be applied for our use-case.
Now, based on my personal experience with various motor setups and different techniques, I can honestly say that is not always easy to have such a setup working from the first try, and for each application there might be a slightly different approach, extra tuning or perhaps a trick to have it running as per expectations.
As the current publication date of this article proves, I've also run into various issues with this application. Perhaps my initial expectations were high or perhaps I was hopping that someone will glue together modules M8 with M9 and provide a final solution. I'm pleased to see that the articles part of this workshop 3-Phase PMSM Control Workshop with NXP's Model-Based Design Toolbox have thousand of views and lots of comments. But more important is the fact that viewers have started to build their own setups or to participate with articles to extend various functionalities presented in the main articles.
Anyhow, based on your requests passed via this community, personal messages and even direct feedback via FAE/Sales/Marketing (which I would like to thank you all for the interest and valuable feedback) I've decided that is time to put this to an end. Hence, I've started to work again full time on this and now after a couple of iterations, I'm ready to share with you all the final Simulink model that is controlling the S32K144 Development Kit for 3-phase PMSM | NXP in Sensorless Mode directly from MATLAB.
Nonetheless, this article (since it the last in this workshop) is going to be a little bit different than the rest of the ones you got used in this workshop. Instead of focusing how the model is implemented step-by-step and technical aspects (in fact all technicalities have been discussed previously) , I prefer to talk about:
How It Works
The zip file that you'll find at the end of this article contains three components:
To run the model on the hardware the next steps should be followed:
Implementation Details
The Simulink model for the sensorless speed control of the PMSM is a combination of the model shown in Module 8: Speed Control enhanced with the observers discussed in Module 9: Position Observer (Part 1/2) . The basic control structure is very similar, hence we are not going to repeat our self but instead we shall focus on differences and new features added.
The main control structure with fast and slow control loops is shown in Fig. 1
Fig. 1: Sensorless Speed Control of PMSM Simulink Model |
The main difference between this model and the one one shown in Fig. 34 within Module 8: Speed Control is the fact that actual motor speed is estimated in the Fast Loop rather than being estimated based on Hall Sensor transitions.
Slow Loop Subsystem
The Slow Loop subsystem has been slightly updated to reflect better the operations that takes place at each 1ms interrupt.
Fig. 2: Slow Loop Subsystem |
As shown in Fig. 2, the first operation is to deal with the Speed Reference profile during acceleration and deceleration regimes. The next operation is to compute the torque command based on a Speed Controller. In parallel with the speed controller we need to monitor the Speed Reference to select the mode of operation: open loop, tracking mode and closed loop. This information is need to switch from open loop to closed loop operation. The last operation done in Slow Loop is the Alignment procedure which is done only at startup.
In this subsystem the major modifications made compared with previous model in Fig. 33 within Module 8: Speed Control are:
Fig. 3: Speed Controller Subsystem |
Fast Loop Subsystem
The fast loop subsystem has been optimized further for getting the best possible performance and to keep some tuning options available. Compared with Fig. 30 in Module 8: Speed Control the new model adds 2 new subsystems highlighted below in blue foreground: Rotor Position and BackEMF Observer
Fig. 4: Fast Loop Subsystem |
The BackEMF Observer subsystem implements the model shown in Fig. 9 within Module 9: Position Observer (Part 1/2) but this time directly in floating point using the dedicated Automotive Math and Motor Control Library Set | NXP functions: AMCLIB_BemfObsrvDQ and AMCLIB_TrackObsrv
Fig. 5: Speed and Position Observers |
The parameters for these observers are computed according with the guidelines from the AMMCLIB User Manual.
The other subsystem that has been modified is the Rotor Position, that handles the merging speed/angle between the open loop, tracking and closed loop modes of operation.
Fig. 6: Speed and Position Observers |
In case of the closed loop operation, due to the delays added by the estimation procedure, we need to compensate for the the rotor phase advance from the moment we read the current/voltages and the moment we are ready to apply the new command voltages. During the computations the rotor will advance with some degrees depending on the commanded speed, hence the new angle needs to be advanced forwards.
Sensorless Run Time
The FreeMASTER project is giving you access to all important parameters and variables for tuning or monitoring actions.
Fig. 7, illustrates a typical startup, followed by an acceleration and deceleration regimes. Throughout these profiles, the Speed Controller manages to keep the motor speed within a decent error envelope of +/- 200 rpm. If better performance is required, then the FreeMASTER can be used to tune the PI controller gains in real time.
Fig. 7: Control system response at startup and change of speeds |
Further investigations and tuning may be deployed to achieved the best system stability. Fig. 8, shows the BackEMF observer output during startup of PMSM and show fast the estimator can cope with changes in the motor speed commands.
Fig. 8: Rotor Position and Speed Estimation during startup of PMSM |
Keep in mind that there are multiple parameters that influence the system response, hence you need to have an holistic view of the entire system. Fig. 9 shows how the current controllers behaves during startup (from 5 to 8 sec on the scope) and then during acceleration regime.
Fig. 9: Flux and Torque current controllers responses |
Some Things to Consider when Porting Applications
Let us presume you have a totally different system (motor and perhaps drive) that you need to configure for running in sensorless mode. If you hope that by simply taking a model like the one shown here, it will work then perhaps you are too optimistic. What are the main steps and procedures to have your system running ?
Fig. 10: Transition from open to closed loop |
Once you have the system up and running, then is time for another settings or improvements. Tune the Speed and Current Controllers to deal with the system dynamics and loads.
If you run into issues with this particular sensorless application then perhaps you wish to have a look to other implementations too like the S32K144 Development Kit for 3-phase PMSM | NXP Reference Design.
Improvements Proposals
As it was stated in the beginning of this workshop, the main reason for having these articles is to demonstrate how you can built applications with Model-Based Design Toolbox. These examples should be considered only for teaching aspects and promotion of the toolbox various functionalities. It is not in the scope of these articles to present a state of the art solution but rather to showcase various possibilities that can be address within this space.
In this particular use case, there are a few improvements that could be done to achieve a better control system starting from these examples:
If you have other ideas for improvements, let us know as comments below. We look forward to see more applications implemented on top of Model-Based Design Toolbox | NXP and show cased here in this community.
Good luck!
Update revisions:
May 06, 2020
I noticed that the position observer implementation in the final model is different from from the one in M9. Is there a reason? I tried both of them in an S32K144 project and I can't get the M10 version to work, whereas the M9 one seems to work as expected under the same conditions. Are they supposed to work in same way?
Thank you and best regards!
Hi @Daniel_Popa ,
I have version 4.2 of the MBDT and the mcspte1ak144 development kit. When I open the model in M10_Sensorless.zip, all of the toolbox functions are unlinked and broken. Is there a way that either you can port the model over to version 4.2?
Alternatively, what would happen if I also install v. 4.1? would I be able to then open the model and replace the functions one by one with their 4.2 counterparts? Any help would be appreciated. Thank you for the very educational course!
Best,
-Mark
Specifically I get this error when loading the model:
Failure in mbd_s32k_convert_mdl_to_latest_version: Unable to find system or file 'ammclib_bam_s32k14x'. The closest match is 'ammclib_bam_S32K14x' in 'C:\Users\mark.palframan\AppData\Roaming\MathWorks\MATLAB Add-Ons\Toolboxes\NXP_MBDToolbox_S32K1xx\mbdtbx_s32k14x\AMMCLIB_s32k14x\bam\ammclib_bam_S32K14x.slx'.
Thank you for your help.
The speed detected with respect to the command value is reversed when viewed with Freemaster.
Speed adjustment is also not possible.
Hall sensor is not connected.
The MATLAB I am using is R2019A.
Best regards
Hi hayaoki7,
The detected speed - can't be changed. It is a value computed by the observer at each 100ms.
The motor speed can be changed via:
In general all the variables can be converted from read-only to read/write from Variable/Modifying tab
In this example there is no hall sensor needed - the rotor angle estimation requires only the i_a/i_b phase currents and control voltages u_alpha and u_beta. In M8 we use the hall sensor to estimate the speed because the motor do not have an encoder. If you have motor with any other type of sensor mounted - then it would be much more easier and more robust to build a motor control application.
Best regards,
Daniel