The current loop of a controller: PI regulators, gains, and bandwidth
When you accelerate, you're not commanding a voltage, but a torque, and therefore a current. The controller must ensure that the actual current in the motor follows this command, despite changes in speed, battery discharge, and motor temperature. This task is handled by a current loop, built around so-called PI regulators. Their tuning makes the difference between a smooth and precise motor response and a motor that whistles, vibrates, or reacts sluggishly.
The essentials
- A controller compares the measured current to the setpoint and adjusts the applied voltage to correct the difference.
- The proportional term reacts immediately to the error; the integral term eliminates the error that persists.
- The optimal power output is calculated based on the motor's resistance and inductance.
- A loop that is too fast becomes unstable and noisy; a loop that is too slow makes the motor feel sluggish and imprecise.
The role of the current loop
In vector control, two currents are regulated: the q-axis current, which generates torque, and the d-axis current, which is kept at zero or used for field weakening. Each axis has its own controller. At each sampling period, they receive the difference between the setpoint and the measured value, and calculate the voltage to be applied.
P stands for proportional
The proportional term applies a correction that is proportional to the error: a larger error results in a larger correction. It reacts immediately. However, on its own, it leaves a small, persistent error because a certain amount of error is required for it to take action. Furthermore, if its gain is too high, it overcorrects, causing the current to oscillate around the target value.
I, as in "intégral" (meaning "complete" or "integral")
The integral term accumulates the error over time. As long as an error persists, even a small one, its correction grows until it eliminates the error. This is what compensates for, for example, the voltage produced by the motor as it rotates, which increases with speed. If the integral gain is too high, it can cause overshooting and slow oscillations.
Calculate the gains based on the motor
A motor winding, for the current loop, behaves like a resistance in series with an inductance. This allows for a systematic adjustment:
- You choose the desired speed of the loop and its bandwidth;
- The proportional gain is equal to the inductance multiplied by this bandwidth
- The total gain is equal to the resistance multiplied by the same bandwidth.
With this setting, the controller precisely compensates for the behavior of the windings, and the current follows the setpoint with the chosen speed, without overshoot. That's why the motor detection measures resistance and inductance: the benefits are derived from these measurements.
How far can you push the speed?
We want a loop that is as fast as possible. However, it is limited by the frequency at which the controller measures and corrects, which is the PWM switching frequency, and by the measurement and calculation delays. In practice, we keep the loop's bandwidth significantly below the switching frequency. Beyond that, the loop becomes unstable: the motor emits a whistling sound, the current oscillates, and the controller may trigger an overcurrent fault.
When the voltage is insufficient: saturation
At high speeds, the controller may request more voltage than the battery can provide. The applied voltage reaches its maximum, the current no longer follows, and the integral term continues to accumulate the error. When the situation resolves itself, this accumulation causes a sudden jerk. Therefore, serious controllers limit the accumulation during saturation: this is the integrator anti-windup feature. It is also in this area that field weakening is used.
Loops around the current loop
The current loop is the fastest and innermost. Other loops, which are slower, can rely on it:
- A speed loop, which sets the current target to maintain a specific speed (speed controller, speed limiting)
- A position loop, for robots and actuators;
- limiters, which reduce the target output based on the battery temperature or voltage.
On an electric scooter, the throttle typically directly controls the current setting: this is what provides a feeling of responsive and controllable torque.
Frequently Asked Questions
Why is my motor making a loud whistling noise after a manual adjustment?
It's likely a too-fast current loop or gain settings that are not appropriate for the motor. The current is oscillating at a high frequency, causing the windings to vibrate. Reverting to the gains calculated during the motor detection process usually resolves the issue.
Should the gains be adjusted manually?
Rarely. They are calculated based on the measured resistance and inductance and are suitable in the vast majority of cases. You should only adjust them for a specific purpose, and only if you have a way to monitor the current.
What happens if the motor parameters are incorrect?
The gains are being miscalculated, which results in a system that is either too soft or unstable. This is one of the reasons why we recommend re-running the motor detection process after changing the motor or phase cables.