Field-oriented control on STM32 can look fine on paper and in block diagrams – but the real question is: does the drive feel stable, predictable and repeatable across its whole operating range? This article gives you a concrete tuning process you can follow step by step.
Before you start: what “good” looks like
- Current follows its reference quickly and smoothly.
- Speed control is predictable, without hunting or long tails.
- Start-up and low-speed behaviour feels controlled, not “fragile”.
- Protection intervenes when needed – but not all the time.
If your STM32 drive is not yet consistently spinning or your timing is unclear, it’s usually better to stabilise the foundation first. That is what we cover in our STM32 real-time optimisation and PWM/ADC integration work.
Step 1 – Define your tuning targets
Tuning without clear targets turns into endless tweaking. Start by writing down what “good enough” means for this project:
- Maximum allowed current overshoot on step changes (e.g. < 20%).
- Maximum settling time for speed steps (e.g. within 200 ms).
- Maximum torque ripple or speed ripple in steady state.
- Operating envelope: min/max speed, load, DC-link voltage and temperature.
These targets don’t have to be perfect – you can refine them later. But having explicit numbers stops endless “it feels okay / not okay” discussions.
Step 2 – Set up a repeatable test bench
Good tuning needs repeatable tests. You don’t need a full HIL system, but you do need a stable way to excite the drive and capture what happens.
- Prepare a few standard test profiles: start-up, low-speed ramp, nominal-speed step, load step, regen.
- Decide which signals you always log: phase currents, DC-link, speed/position, torque reference, key internal states.
- Automate as much as is reasonable (scripted profiles, fixed logging durations, consistent scaling).
Store these test definitions alongside your firmware project so everyone on the team works with the same scenarios.
Step 3 – Stabilise the inner current loops
The d- and q-axis current loops are the core of your FOC. You only tune outer loops once these are behaving well.
3.1 Pick a realistic bandwidth
As a rule of thumb, target a current-loop bandwidth significantly below your PWM frequency, but high enough to reject disturbances:
- Start with something like 1/10 to 1/5 of the PWM frequency as a guideline.
- Adjust for motor inductance and inverter characteristics (very low inductance may force you slower).
- Make sure your ISR execution time and any FPU/DMA use fit comfortably within the PWM period.
3.2 Tune d- and q-axis one at a time
Don’t try to guess everything at once. Use step tests:
- First tune the d-axis with the q-axis reference at zero; then do the opposite.
- Apply small current steps and look at rise time, overshoot and ringing.
- Increase proportional gain until you are close to your speed target, then add integral action to remove offset.
3.3 Check saturation and limits explicitly
FOC on STM32 is often implemented in fixed-point or with tight numeric constraints. Make saturation behaviour part of your tuning, not an afterthought:
- Verify where voltage references clip relative to your normal operating region.
- Test that anti-windup actually prevents long recovery from saturation.
- Confirm that current limits are enforced consistently on both axes.
If you find yourself fighting numeric limits more than dynamics, it may be time to revisit scaling. That’s a typical topic in our real-time optimisation reviews.
Step 4 – Tune speed and torque control around the current loops
Once current is under control, you can build a robust speed or torque controller on top.
- Start with a relatively slow speed-loop bandwidth (e.g. 5–10x slower than the current loops).
- Apply small speed steps and monitor current peaks and overshoot.
- Increase gains until you reach your response-time targets without hitting current limits all the time.
For torque-controlled applications, treat the torque reference generator in the same way: define response-time targets and test them systematically.
Step 5 – Treat start-up and low speed as separate operating modes
Many FOC implementations apply the same tuning everywhere, but start-up and very low speed often need dedicated strategies:
- Characterise open-loop alignment and rotor position detection behaviour.
- Test current control at very low speeds where back-EMF is small.
- Consider separate parameter sets or logic branches for “start-up / low-speed” vs “normal operation”.
If these phases are business-critical (e.g. for power tools or mobility), it is worth treating them almost as their own mini-project. That’s why we run a dedicated track for this in FOC start-up & low-speed tuning.
Step 6 – Integrate protection into your tuning process
Protection settings and FOC tuning should evolve together. If you tune everything first and bolt on protection at the end, you’ll often end up destabilising a system that felt fine in the lab.
- Define current, speed and voltage limits early and keep them visible in your test plans.
- During tuning, deliberately trigger limits in controlled scenarios and observe behaviour.
- Introduce filtering and hysteresis where needed so protection is firm but not “nervous”.
We usually capture these concepts in a simple protection concept document and validate them formally as part of motor drive protection & testing.
Step 7 – Lock in results: parameter sets, documentation and reuse
Once the drive behaves the way you want, don’t treat the tuned parameters as “magic numbers”. Make them part of your product knowledge:
- Store parameter sets (current-loop gains, speed-loop gains, limits) in source control.
- Document which tests were used to validate them and what the acceptance criteria were.
- Define rules for reusing or adapting parameter sets across product variants.
This makes it much easier to onboard new team members, scale to new motors and keep behaviour consistent from prototype to series.
FOC tuning checklist (one-page view)
| Step | Key question | OK? |
|---|---|---|
| Targets | Are response times, overshoot limits and operating ranges clearly defined? | |
| Test bench | Do you have repeatable test profiles and logging for key signals? | |
| Current loops | Are d/q loops tuned with clear bandwidth and without problematic saturation? | |
| Speed / torque | Is outer-loop behaviour fast enough but robust to load and supply changes? | |
| Start-up / low-speed | Do start-up and crawl speeds behave as specified under different loads? | |
| Protection | Are limits and protections integrated into your tuning and validated? | |
| Documentation | Are tuned parameter sets, tests and criteria captured and versioned? |
FOC tuning FAQ
Is this process different from “fixing a noisy drive”?
Yes. This checklist is about designing a stable, predictable control behaviour from the ground up. Noise is one possible symptom, but here we focus on clear targets, structured tests and reproducible tuning steps. For typical acoustic issues, see our article “Why Your FOC Drive Sounds Noisy – 7 Common Mistakes in STM32 Motor Controllers”.
Do I need to run all steps for every project?
In smaller or derivative projects you may be able to reuse parts of the work – especially if the motor and inverter are similar. But it’s still useful to at least walk through the checklist and consciously mark which steps you’re reusing and which you’re redoing.
Can you support us with only part of the tuning?
Yes. In our STM32 motor control consulting we often focus on a specific stage: for example, current-loop stabilisation, start-up robustness, or formalising protection and test concepts for validation.
How does this tie into the rest of our development?
FOC tuning is one element in a larger system: firmware architecture, mechanics, test strategy and product requirements. We normally align tuning work with the broader picture through engineering & firmware services, drive systems and complete product development services.
Next steps if you want help with tuning
If you have an STM32-based FOC drive that runs but does not yet feel “production ready”, we can either review your existing implementation or join you in the lab for structured tuning sessions.
A good starting point is to share:
- A short description of your application and motor/inverter.
- Your current parameter set and main issues (instability, slow response, unexplained trips, etc.).
- Example logs or scope screenshots from your standard test cases.
You can reach us via the contact page or through the overview on engineering & firmware consulting.
0 comments