Your FOC drive runs, but does it feel solid, quiet and predictable across the full operating range? This checklist walks through the key steps we use when we stabilise STM32-based FOC drives for OEM projects – from timing and current loops to speed control, protection and logging.
What you should have in place before tuning
- A working STM32-based FOC implementation that can spin the motor.
- Basic lab setup: power supply, load, current probe or shunt measurement, oscilloscope/logger.
- Motor and inverter parameters (at least approximate): Rs, Ls, pole pairs, max current, DC-link.
If your drive is not yet consistently spinning, it is usually better to first stabilise PWM/ADC timing and the core control structure. Our STM32 real-time optimisation and control loop integration services focus exactly on that foundation.
Step 1 – Get your timing and sampling under control
Before changing gains, make sure the real-time base is solid. FOC tuning on top of unstable timing is like adjusting suspension on a car with loose wheels.
- Verify PWM frequency and dead time match your original design intent.
- Check that ADC sampling happens in a quiet window of the PWM period (not on edges).
- Make sure DMA transfers complete before the control ISR uses the data.
A short oscilloscope session with PWM, ADC trigger and current measurement on the same screen often reveals more than hours of parameter guessing.
Step 2 – Check your motor and inverter parameters
FOC controllers rely on a reasonably accurate view of the plant. If the motor or inverter parameters are far off, you will be fighting the model instead of tuning the controller.
- Confirm stator resistance and inductance are at least in the right ballpark.
- Review DC-link voltage range and dead-time compensation settings.
- Check that current limits and voltage utilisation match your hardware capabilities.
For many projects, quick lab measurements and a simple spreadsheet are enough to improve the model significantly – without a full identification campaign.
Step 3 – Tune the d- and q-axis current loops
The current loops are the backbone of your FOC. If they are slow, poorly damped or saturating, everything above them (speed loop, torque control, position control) will suffer.
3.1 Decide on your target bandwidth
A common starting point is a current-loop bandwidth of roughly 1/10 to 1/5 of the PWM frequency, depending on switching frequency, motor inductance and noise level.
- Select a realistic target (not just “as fast as possible”).
- Use the same target bandwidth for both d- and q-axis, at least as a starting point.
- Check that FOC computation time fits comfortably in the ISR slot.
3.2 Set initial PI gains
Whether you start from formulas, ST’s MCSDK or your own experience, define a clear initial set of gains and document them. Then:
- Perform small step changes in current reference and observe rise time and overshoot.
- Adjust proportional gain to reach your bandwidth target without excessive overshoot.
- Add integral action to remove steady-state error, avoiding slow integrator wind-up.
3.3 Watch for saturation and numeric limits
Make sure the controller output does not saturate too early and that numeric scaling is appropriate:
- Are you clipping the voltage reference in normal operation?
- Do fixed-point limits cut off small signals at low speed or low torque?
- Are anti-windup mechanisms implemented and verified?
If you see heavy clipping, strange steps in the current or behaviour that changes with operating point, it is often worth revisiting scaling and numeric ranges.
Step 4 – Tune the speed loop with margin
Once the current loops are stable and well-behaved, you can turn to the speed loop. A common mistake is to tune the speed loop “as fast as possible” without considering interaction with the current loops.
- Start with a modest speed-loop bandwidth (e.g. 1/5 to 1/10 of the current-loop bandwidth).
- Apply small speed steps and observe response and current peaks.
- Ensure you keep enough margin so that current limits are not constantly hit.
In applications with strong load variation or compliance (e.g. gearboxes, belts) it is often better to accept a slightly slower speed response in exchange for higher robustness.
Step 5 – Give start-up and low-speed their own attention
Many drives feel great at nominal speed and load but behave poorly right where users notice it most: start-up and very low speed.
- Test open-loop alignment and rotor position detection explicitly.
- Verify that torque build-up at start is smooth and free of clunks.
- Check low-speed behaviour under different loads (no-load, partial load, high load).
Dedicated start-up and low-speed strategies – especially for PMSM and BLDC – are often the difference between a system that “works in the lab” and one that feels product-ready. This is a core topic in our FOC start-up & low-speed tuning work.
Step 6 – Validate protection and limits during tuning
Tuning is an ideal time to validate protection and limiting behaviour because you are already exploring the edges of the operating range.
- Trigger current limits in a controlled way and observe how the drive reacts.
- Check that speed and torque limits behave smoothly, not as hard “cliffs”.
- Log events where protection intervenes and correlate them with operating conditions.
Protection should keep the hardware safe without making the drive feel nervous or jerky. If thresholds or filters are wrong, you can introduce noise and instability while trying to be “safe”. We look at this systematically in motor drive protection & testing projects.
Step 7 – Add structured logging and repeatable test cases
Without repeatable tests and logging, FOC tuning quickly turns into guesswork. A minimal but effective structure looks like this:
- Define a small set of standard test cases (start-up, low-speed ramp, nominal speed, step load, regen).
- Log the same key signals for each case: phase currents, speed, torque reference, DC-link, key states.
- Keep test scripts and procedures under version control alongside your firmware.
Once you can reliably compare runs, it becomes much easier to see whether a parameter change is a real improvement or just a random variation.
Checklist – Are you ready to call your FOC “stable”?
| Area | Key question | Done? |
|---|---|---|
| Timing & sampling | Are PWM, ADC triggers and DMA aligned so each control step gets clean samples? | |
| Plant parameters | Are Rs, Ls, voltage range and limits in a realistic range for your hardware? | |
| Current loops | Do d- and q-loops reach their targets quickly and smoothly without saturation? | |
| Speed loop | Is speed response fast enough, but with margin to current limits and hardware stress? | |
| Start-up & low-speed | Do start-up and crawl speeds feel smooth under different loads? | |
| Protection | Do limits and protection behave predictably and without chatter? | |
| Logging & tests | Can you repeat test cases and compare logs across firmware revisions? |
FOC tuning FAQ
How long should proper FOC tuning take?
It depends on the complexity of the system and the quality of the starting point. With a decent base implementation and structured tests, we often see clear improvements within a few focused sessions. Without structure, teams can easily spend weeks tweaking parameters without understanding why the behaviour changes.
Can I reuse one tuning across similar products?
Often yes – if the motor, inverter and application profile are similar. We frequently help clients design FOC settings and protection concepts that can be reused across several product variants, with only small adjustments per model.
Do I need advanced tools to tune FOC?
High-end equipment helps, but is not mandatory. A reliable current measurement, a basic oscilloscope and structured logging already cover most tuning work. The bigger difference usually comes from having a clear process rather than from having the fanciest tools.
When does it make sense to bring in external support?
If you are close to validation or series, noise or instability persists and the team feels stuck, an external review can be very efficient. In our STM32 motor control consulting we typically combine remote log review with targeted lab sessions to get drives into a stable, shippable state.
Where this fits in your overall development
FOC tuning is only one piece of the puzzle. For robust products you also need a solid firmware architecture, tested protection concepts and a mechanical design that supports your control goals.
If you want to align FOC tuning with the rest of your development, these pages are a good next step:
0 Kommentare