- Last edited 3 weeks ago ago
Frequently asked questions (FAQ)
This page contains some frequently asked questions (FAQ) related to motor control with STM32 (STM32 MC).
Acronyms and abbreviations
- FOC = field oriented control (algorithm)
- MC = motor control
- PMSM = permanent magnet synchronous motor
- SDK = software development kit
1 STM32 motor control ecosystem
1.1 Overview of the STM32 MC SDK
The ST motor control ecosystem includes the STM32 motor control software development kit (to install it, download it from the X-CUBE-MCSDK web page). Its purpose is to speed up the evaluation and development of a FOC or 6-step algorithm for permanent magnet synchronous motor (PMSM) applications.
The STM32 MC SDK is running on STM32 MCUs that implement an advanced timer (refer to the appropriate release note for more information). It is composed of:
- STM32 MC firmware (STM32 MC FW) library
- Currently only the PMSM FOC control is available for all configurations
- PMSM 6-step and asynchronous motor FOC getting started examples, available within X-CUBE-MCSDK
- STM32 MC workbench (STM32 MC WB)
- PC graphical user interface (GUI) tools to configure the FOC firmware library parameters and to perform real-time monitoring (monitoring with the STM32 MC WB only, up to version 5.4.6)
- STM32 MC motor profiler (STM32 MC MP)
- PC tools able to measure the motor parameters automatically and to update the STM32 MC FW library, through the ST MC workbench
1.2 Changes from previous version
Refer to the STM32 MC SDK release note provided with each released version.
1.3 Overview of the STM32 MC SDK version 5.Y
The STM32 MC SDK is available in two versions of the X-CUBE-MCSDK deliverable:
- STM32 MC SDK version 5.4.6, that corrects few problems of the 5.4 series. It is fully compatible with previous versions.
- STM32 MC SDK version 5.Y, that is a first step in our innovative roadmap. It includes:
- A new communication protocol and its associated monitoring tools, the SM32 MC motor pilot
- New algorithms, such as discontinuous PWM, single shunt phase shift, and overmodulation
- New 6-step examples compatible with the new STM32 MC motor pilot
- A new sensorless asynchronous motor example compatible with the new STM32 MC motor pilot
- New STSPING4 support.
The main limitations of STM32 MC SDK version 5.Y are:
- The projects generated with STM32 MC SDK version 5.4 deliveries are not compatible with version 5.Y.
- STM32 MC SDK version 5.Y does not support STM32F1 Series.
- STM32 MC SDK version 5.Y does not support dual-motor applications.
1.4 Choosing between STM32 MC SDK 5.4.6 and 5.Y versions
- If you are already using STM32 MC SDK version 5.4 and need to keep the compliance, use version 5.4.6.
- If you want a well-established mature SDK version, use version 5.4.6.
- If you use an STM32F1 MCU, choose version 5.4.6.
- For dual-motor applications, use version 5.4.6.
- If you need new debug capabilities and dumping features to mature your application, use version 5.Y.
- If you are interested by the PWM, single shunt phase shift, or overmodulation feature, use version 5.Y.
- If you want to use the new STSPING4, use version 5.Y.
- For asynchronous motor applications, use version 5.Y.
1.5 STM32 MC motor profiler
This tool automatically measures the electrical parameters of PMSM motors. The characteristics of an electric motor may not be known and can be determined in less than a minute.
The algorithm determines the motor parameters required to configure the STM32 MC FW library: stator resistance Rs, stator inductance Ls, back EMF constant, motor inertia, and friction.
Refer to the STM32 motor control SDK user manual for more details (UM2380).
1.6 STM32 MC motor pilot
The STM32 MC motor pilot is a new control and monitoring PC tool, available in version 5.Y. It replaces the monitoring tool currently delivered with the STM32 MC motor workbench.
It is built on a brand-new communication protocol that allows faster and more reliable communications while consuming less MIPS from the MCU.
With this protocol, internal motor control signals are monitored in real-time with no or controlled subsampling.
2 Using the STM32 MC SDK
2.1 How to create a motor control project
First read the STM32 MC SDK getting started manual (UM2374). Then, start either from a motor control example project, or design a new project.
2.2 How to handle a project made with a previous version of the STM32 MC workbench
The STM32 MC workbench automatically migrates an older *.stmcx file to the current version. Before the migration, an information window pops up requesting confirmation. Click yes if you agree with this conversion (after migration, the previous configuration is lost).
Regarding the user application software itself, refer to "How to migrate motor control application software from STM32 MC SDK v4.3 to v5.x" (AN5143).
2.3 How to get a project framework for a particular IDE (such as IARTM or Keil®)
Two solutions are possible:
- Start from a motor control application software example provided in the “./Projects” directory for all supported IDEs, IARTM, Keil® or GCC based (read the attached ReadMe.txt file).
- Use a preconfigured motor control application example project or a newly created one, via the STM32 MC workbench. Then, select the required IDE as well as the STM32CubeMX version, and generate the motor control application software example.
2.4 Why does not the STM32 motor profiler tool recognize my motor?
If the STM32 motor profiler tool does not recognize your motor, proceed as follows:
- Apply a nominal voltage.
- Select the power stage with the proper current range.
- Fill the nominal motor speed parameter or play with this value.
- Decrease the nominal current parameter.
- Decrease the applied bus voltage.
If you still face problems, profile your motor manually using the following procedure: How To manually configure the motor parameters.
2.5 Why does not my motor start immediately?
Although your motor is running fine, it does not start immediately. The reason can be one of the following:
- During initialization, a motor alignment is required to start from a known position. In other words, it means that the initialization phase sets a static stator vector and waits until the rotor vector aligns with this position.
- When the “on-the-fly startup” feature is enabled, this feature starts a detection phase before driving any motor:
- When the rotation is detected, it skips the startup phase and runs directly in the close-loop mode.
- When no rotation is detected, it launches the startup phase, such as alignment or ramp-up.
2.6 How to choose the basic set of ramp-up parameters for a given motor
Most of the time, setting the ramp-up parameters as follows ensures a correct start of the motor:
- Check the box “Include alignment before ramp-up”.
- Set the motor alignment “Duration” to 2000 ms.
- Set the motor alignment “Final current ramp value” to ½ of the nominal motor current (in A).
- Set the “Speed ramp duration” to 3000 ms.
- Set the “Speed ramp final value” to 30% of the maximal motor speed (in RPM);
- Set the “Current ramp final value” to ½ of the nominal motor current (in A).
- Set the “Minimum start-up output speed” to 15% of the maximal motor speed (in RPM).
After a first successful start, fine-tune these parameters.
2.7 How to choose the PWM frequency and the FOC execution rate
The choice of the PWM frequency and the FOC execution rate is a compromise between available speed and switching losses:
- For high-speed or low-inductance motors, use a high PWM frequency (for example, 30 kHz).
- Whatever the motor, a lower PWM frequency (for example, 16 kHz) is sufficient.
- Whatever the motor, check the maximum PWM frequency capability for the selected MCU.
- For low-inductance motors, the FOC execution rate can be increased while keeping a high PWM frequency to save CPU load, or migrate to a lower performance MCU (for example PWM = 30 kHz and FOC execution rate = 2 mean that the FOC algorithm runs at 15 kHz).
2.8 Why do I have an “FOC duration” fault message and the motor does not even try to start?
This fault message appears when the FOC execution rate is too high and the FOC algorithm computation does not fit in the PWM period.
Open the "Drive Settings" window and decrease the ratio between the PWM period execution rate in the "Torque and flux regulators" section as shown below (for example increase this execution rate by one).
2.9 Why do I have an “Over current” fault message and the motor does not even try to start?
This fault message appears in the following situations:
- A wrong current sensing topology is selected. In this case, check and select the right current sensing configuration.
- A wrong current sensing parameter is set. To solve this issue, check and correct the current sensing parameters.
- The current regulation loop bandwidth is too high for the hardware setup. In this case, open the "Drive Settings" window and decrease the current regulation loop cut-off frequency (for example down to 2000 rad/s for a 3-shunt topology and 1000 rad/s for a 1-shunt topology). Typical maximum current regulation loop bandwidth values are 9000 rad/s for a 3-shunt topology and 4500 rad/s for a 1-shunt topology.
2.10 Why do I have a “Speed feedback” fault message during the acceleration phase and why does the motor stop?
This fault message often appears following an abrupt torque variation demand at the end of the startup phase. As a result, the "Back-EMF estimator" is spoilt.
- The observer gain G2 is too high. This makes the speed reconstruction too noisy to be used by the speed PI gains, thus causing an estimator reliability issue. The possible solutions are the following:
- Decrease the observer gain G2 by successive steps : /2, /4, /6, /8.
- Run the motor in torque mode until the issue disappears. The drawback is that the speed regulator gains are not optimal. Trim the gain values (refer to the dedicated FAQ).
- The startup phase ends too early. The possible solutions are the following:
- Increase the “Consecutive successful start-up output tests” parameter (it must not be set to a value higher than 4-5);
- Set the “Minimum startup output speed” parameter to 15% of your maximum application speed, then decrease it progressively.
2.11 Why do I have a “Startup failure” error message during the rev-up phase and why does the motor stop?
This fault message typically appears because the current provided to support the required speed acceleration is not sufficient. To solve this issue, proceed as follows:
- Decrease the speed acceleration rate:
- Increase the “Speed ramp duration” parameter.
- Set the “Speed ramp final value” parameter to 30% of your maximum application speed.
- Increase the startup current:
- Increase the “Current ramp initial value” parameter.
- Increase the “Current ramp final value” parameter up to the “Nominal Current” parameter of the motor.
- Check the “Include alignment before ramp-up” box to make the startup phase more deterministic, and follow the FAQ on "Basic parameters settings for the ramp-up".
2.12 Why do I have a “Startup failure” error message during the acceleration following the rev-up phase and the motor stop?
This fault message often appears following an abrupt torque variations demand at the end of the startup phase. This spoils the Back-EMF estimator.
- The observer gain G2 is too high. This makes the speed reconstruction too noisy to be used by the speed PI gain, thus causing an estimator reliability issue. The possible solutions are the following:
- Decrease the observer gain G2 by successive steps : /2, /4, /6, /8.
- Increase the “Variance threshold” parameter to release the check mechanism: up to 80% for Observer+PLL, up to 400% for Observer+CORDIC.
- The reliability capture window of the estimator is too small. The possible solutions are the following:
- Increase the “Speed ramp final value” parameter up to 40% of the maximum application speed.
- Decrease the “Minimum startup output speed” parameter down to 10% of the maximum application speed.
2.13 How to interface the STM32 MC firmware library
Several motor control APIs are implemented to offer basic interactions with the firmware library.
Refer to the online firmware reference information that contains the below information and more:
- From the STM32 MC workbench menu: select Documentation and select Firmware Reference.
- From the Windows Startup menu: select an ST Motor Control SDK and open the corresponding reference manual.
2.14 How to choose the hardware power board
While it is not true for the nominal bus voltage, the maximum current (torque) used by your application is usually different from the maximum current of the motor.
As a consequence, the motor spin must be adapted to the selected power board range.
The best case is of course when the maximum current of the motor is part of the current range offered by the selected power board.
2.15 How to debug a motor control application
A motor control application cannot use the standard debug mechanism which consists in hardware or software breakpoints for holding the program.
The reason is that during the break, the application loses the real rotor position with respect to the needed magnetic field computation phasing defined by the firmware execution.
So, the DAC (or an emulated DAC, thanks to a PWM output) and/or the USART communication are used as outlined below:
- The DAC generates a voltage that reflects the internal signals (for example currents, B-EMF voltage, or reconstructed angle). Then, it provides the capability to scope this waveform during the motor spin. The best solution is to dedicate two DAC output pins.
- The USART provides data, but at a lower rate than the DAC. It requires the two Tx/Rx pins and the STM32 MC workbench tool to monitor the data.
2.16 How to make the current more sinusoidal when the motor spins
One possible cause is that the PI gains of the speed regulator are incorrect.
Decrease the KP gain and adjust the KI gain (evaluating the speed regulation) to check over/undershooting during transients.
2.17 How to tune the PI speed regulator
Among the possible ways, an example is described below:
- Run the motor and connect it to the STM32 MC workbench.
- Open the monitor mode and switch on the plotter window.
- In the “Final ramp speed” box, enter the new reference speed (for example change the speed from 2,000 RPM to 4,000 RPM).
- In the plotter windows, check the measured speed reaction. It may either exhibit a fast reaction with oscillations around the final value, or have a slow reaction. Refer to the following solutions:
- If the regulated variable oscillates around a value, decrease KI or increase KP.
- If the trend of regulated variable is too slow or not stabilize, then increase KI.
2.18 How to connect ICS with the MC FW library
The implemented ICS requires using two phases from a three-phase power supply.
The STM32 MC FW library operates only on phase U and phase V. Connect each ICS to these phases.
2.19 Why using FOC as opposed to 6-step control for PMSM drive?
FOC brings the following benefits:
- Better energy efficiency
- Improved responsiveness of speed control
- Accurate positioning control
- Lower acoustic noise
2.20 Why using 3-shunt as opposed to a 1-shunt resistor implementation for current measurement?
Using the 1-shunt implementation for measurement is the cheapest solution.
However, some motors (such as low-inductance motors) require current measurements on two phases simultaneously. Only the 3-shunt implementation manages this configuration.
3 STM32 MC SDK features
3.1 Does the STM32 MC SDK support power factor corrector?
Yes, it does.
Power factor correction examples are accessible from the STM32 MC Workbench first page, in the example list.
3.2 Does the STM32 MC SDK support dual drive motors?
Yes, the STM32 MC SDK supports dual-drive motors using only one MCU.
3.3 Does the STM32 MC SDK provide project examples using FOC or 6-Steps control for PMSM drive?
Yes, the STM32 MC SDK provides project examples to demonstrate FOC and 6-Steps control implementations.
They are accessible from STM32 MC Workbench first page.
3.4 What are the new features of STM32 MC SDK version 5.Y?
The STM32 MC SDK version 5.Y is a first step in our innovative roadmap. It includes:
- A new communication protocol and its associated monitoring tools, the STM32 MC motor pilot
- New algorithms such as discontinuous PWM, single shunt phase shift and overmodulation
- New 6-step examples compatible with the new STM32 MC motor pilot
- New sensorless asynchronous motor example compatible with the new STM32 MC motor pilot
- New STSPING4 support
- MISRA support for STM32G4 Series