4.4. Field-Oriented Control (FOC)¶
FOC consists of a velocity controller, a current controller, and commutation and estimation subcomponents. A high-level block diagram of the FOC components is shown in Figure 4.2.
This diagram shows a number of features that are described in the test harness.
4.4.1. Velocity Control¶
The velocity control loop is a straightforward, scalar PI controller, with managed saturation features to prevent integrator windup when either the velocity or current controller saturates.
It is preceded by a rate limiter, to provide more gentle trajectory shaping and reduce transient overshoot.
Saturation and antiwindup features are present and covered in a separate document.
4.4.1.1. Voltage Control¶
Voltage control is an alternative control structure available in MCAF R7. In voltage control, back-emf is used as a proxy for velocity control, with some compliance due to the stator resistance. When this feature is active, the current control loop and the active position/velocity estimators are operating normally.
4.4.2. Current Control¶
The current control loop is a vector control loop that operates in the dq reference frame, with reference transforms to convert to/from the ABC stationary reference frame in which currents are measured and duty cycles are commanded. The vector control loop itself is a straightforward pair of PI controllers, with managed saturation features to prevent integrator windup when the current controller saturates. (Saturation and antiwindup features are covered in more detail in a separate document.)
Figure 4.2 shows a filter block preceding the current controller. It is intended to slow down incoming commands from the velocity loop, which typically executes at a slower rate.
Figure 4.2 also shows DC link voltage compensation following the Inverse Park Transform.
4.4.3. Position and Velocity Estimator¶
MCAF provides several position and velocity estimators used for commutation and velocity control:
4.4.4. Implementation Notes¶
4.4.4.1. FOC feature support¶
4.4.4.1.1. Flux weakening¶
In MCAF R1 – R5, flux weakening was not provided, and the velocity controller set the d-axis current command to zero.
Since MCAF R6, flux weakening has been provided as part of the Flux control module.
4.4.4.1.2. Current command prefilter¶
The filter just prior to the current controller is unimplemented in MCAF R1 – R7, but is reserved for a future version.
4.4.4.1.3. DC link voltage compensation¶
DC link voltage compensation was not implemented for MCAF R1, but has been implemented since MCAF R2. In MCAF R1, the multiply between \(V_{dq}\) and \(D_{dq}\) is not present.
4.4.4.1.4. PWM duty cycle realization¶
MCAF R1 used an implementation of conventional space-vector PWM (CSVPWM)
from the Microchip Motor Control Library (MC_CalculateSpaceVectorPhaseShifted_Assembly
).
Starting with MCAF R2, this has been switched to use a Zero Sequence Modulation block,
which includes clipping within realizable limits (minimum and maximum duty cycle limits)
in order to support overmodulation. See MCAF_FocStepIsrForwardPath()
.
For more information on ZSM, see Microchip’s Zero Sequence Modulation Tutorial.
4.4.4.1.5. Velocity loop current limit¶
The velocity loop controller has upper and lower limits for its output, a q-axis current reference.
MCAF R1 – R5 used fixed upper and lower limits, equal to \(\plusmn I_{\max}\), the rated continuous drive current or rated continuous motor current, whichever is loewr.
Since MCAF R6, the velocity controller uses a limit computed by the flux control module, that is bounded by \(\plusmn I_{\max}\). Depending on the type of current limit region used, this limit may be fixed or may be changing dynamically. For more details, see Calculation of q-axis current limit.
4.4.4.1.6. Saturation and anti-windup¶
Velocity loop error integration is inhibited when certain velocity anti-windup conditions occur.
In MCAF R1 – R5, velocity anti-windup conditions include detection of current and voltage saturation.
Since MCAF R6, voltage saturation is not used for velocity anti-windup, when flux weakening is enabled, to allow entry into the flux-weakening region. When flux weakening is disabled, voltage saturation is used for velocity anti-windup.
4.4.4.1.7. Flux control¶
Flux control, including flux weakening and MTPA, was added as an option in MCAF R6.
4.4.4.1.8. Current measurement / gain and offset compensation¶
Gain and offset compensation are included in MCAF to handle several aspects of current measurement:
run-time compensation of current offset error
compile-time compensation of current gain error, for cases such as the MCLV-2
use of single/dual/triple-channel measurement
4.4.4.1.9. Dead-time compensation¶
Dead-time compensation was added as an option in MCAF R6.
4.4.4.2. Numerical values for PWM duty cycle and dead time¶
It is important to understand some of the subtleties of PWM duty cycle in MCAF, in the presence of dead time. Interpretation of particular numeric duty cycles (for example, d = 0.1) can be slightly tricky. This section documents how they are used, and how to determine the correct values given known limits of the power electronics. Figure 4.3 shows several important points related to PWM duty cycle and dead time.
A typical PWM peripheral for use with a half-bridge circuit produces three waveforms:
a raw generated pulse waveform G with duty cycle \(D\)
high-side output H with the leading edge delayed by dead time \(\delta_1\),
low-side output L inverted and with the trailing edge delayed by dead time \(\delta_1\).
Other implementations may split dead time in half symmetrically. (see note on dsPIC33 PWM)
The intended duty cycle of the entire half-bridge is \(D\).
The duty cycle of the high-side gate drive is \(D-\delta_1\). (with \(\delta_1\) expressed as a fraction of total PWM period)
The duty cycle of the low-side gate drive is \(1-D-\delta_1\).
With inductive loads, and transistor on-time and off-time roughly equal, the effective duty cycle of the entire half bridge is
\(D-\delta_1\) if current is flowing out of the half bridge (the low-side diode conducts during dead time),
\(D+\delta_1\) if current is flowing into the half bridge (the high-side diode conducts during dead time),
or somewhere in between if current does not stay positive or negative during the entire dead time — this represents discontinuous conduction.
Circuit designers of the half bridge should record the following quantities:
Minimum duty cycle \(D_{HMIN}\) and maximum duty cycle \(D_{HMAX}\) of the high-side transistor
Minimum duty cycle \(D_{LMIN}\) and maximum duty cycle \(D_{LMAX}\) of the low-side transistor
Desired dead time \(\delta_1\)
The relevant parameters that should be entered into motorBench® Development Suite are:
Minimum duty cycle of the bridge \(D_{BMIN}=\max(D_{HMIN},1-D_{LMAX}-2\delta_1)\)
Maximum duty cycle of the bridge \(D_{BMAX}=\min(1-D_{HMIN},D_{HMAX}+2\delta_1)\)
This will produce the range of duty cycles shown in Table 4.1.
Waveform |
Minimum duty cycle |
Maximum duty cycle |
---|---|---|
G |
\(D_{BMIN} + \delta_1\) |
\(D_{BMAX} - \delta_1\) |
H |
\(D_{BMIN}\) |
\(D_{BMAX} - 2\delta_1\) |
L |
\(1-D_{BMAX}\) |
\(1-D_{BMIN} - 2\delta_1\) |
Usually the two minimum duty cycles \(D_{LMIN}\) and \(D_{HMIN}\) determine the duty cycle limits, not the maximum duty cycles.
To help clarify how this works, some concrete examples are given below.
4.4.4.2.1. PWM peripheral in dsPIC33 devices¶
The PWM peripheral in dsPIC33EP parts splits the dead time in half, calculating edges for the low-side and high-side outputs so that they are centered in time around the “ideal” switching instant if there were no dead time. The widths of waveforms G, H, and L in Figure 4.3 are the same, but waveforms H and L are advanced in time by \(\delta_1/2\).
4.4.4.2.2. Example 1¶
High-side transistor must be limited between \(D_{HMIN}=1.2\%\) duty cycle and \(D_{HMAX} = 99\%\) duty cycle
Low-side transistor must be limited between \(D_{LMIN}=3.0\%\) duty cycle and \(D_{LMAX} = 99.5\%\) duty cycle
Dead time of 2%
This is a realistic case for a bootstrap gate drive, where \(D_{LMIN}\) is larger, to ensure adequate recharge time of the bootstrap capacitors.
We calculate
The waveform values produced by this are shown in Table 4.2.
Waveform |
Minimum duty cycle |
Maximum duty cycle |
---|---|---|
G |
0.032 |
0.95 |
H |
0.012 |
0.93 |
L |
0.03 |
0.948 |
Note that in this case, the limits are determined by the minimum duty cycles; the maximum duty cycles of the H and L waveforms are comfortably below their required maximum.
4.4.4.2.3. Example 2¶
High-side transistor must be limited between \(D_{HMIN} = 1.2\%\) duty cycle and \(D_{HMAX} = 90\%\) duty cycle
Low-side transistor must be limited between \(D_{LMIN} = 3.0\%\) duty cycle and \(D_{LMAX} = 80\%\) duty cycle
Dead time of 2%
We calculate
The waveform values produced by this are shown in shown in Table 4.3.
Waveform |
Minimum duty cycle |
Maximum duty cycle |
---|---|---|
G |
0.18 |
0.92 |
H |
0.16 |
0.90 |
L |
0.06 |
0.80 |
In this case, the limits are determined by the maximum duty cycles; the minimum duty cycles of the H and L waveforms are comfortably above their required minimum.
4.4.4.2.4. Recommended values for use with motorBench® Development Suite and MCLV-2¶
High-side transistor must be limited between \(D_{HMIN} = 0.5\%\) duty cycle and \(D_{HMAX} = 99.5\%\) duty cycle
Low-side transistor must be limited between \(D_{LMIN} = 2.23\%\) duty cycle and \(D_{LMAX} = 99.5\%\) duty cycle
Dead time of 4%
We calculate
The waveform values produced by this are shown in Table 4.4.
Waveform |
Minimum duty cycle |
Maximum duty cycle |
---|---|---|
G |
0.045 |
0.9377 |
H |
0.005 |
0.8977 |
L |
0.0223 |
0.915 |
Note that in this case, the limits are determined by the minimum duty cycles; the maximum duty cycles of the H and L waveforms are comfortably below their required maximum.
4.4.4.2.5. Affected source code files¶
Since MCAF R3, the generated file parameters/hal_params.h contains #define
symbols to determine minimum and maximum duty cycles.
There is also a comment that appears as follows:
/*
* Minimum and maximum duty cycles,
* from the perspective of the PWM duty cycle registers.
*
* The actual minimum and maximum duty cycles created by the PWM generators
* will have dead time (=0.04) added and subtracted.
*
* NOTE: this assumes identical dead time,
* and no significant difference in propagation delay between gate drive channels.
*
* Effective limits for duty cycle as seen on the PWM outputs:
* Minimum duty cycle on PWMxH: 0.005
* Minimum duty cycle on PWMxL: 0.0223
* Maximum duty cycle on PWMxH: 0.8977
* Maximum duty cycle on PWMxL: 0.915
*/
/* The minimum duty cycle of the half-bridge affects
* the minimum duty cycle of upper transistors
* and maximum duty cycle of lower transistors.
*/
/* Minimum duty cycle register value in counts */
#define HAL_PARAM_MIN_DUTY_COUNTS 157 // Q0(157.00000) = +44.85714 m = +45.00000 m - 0.3175%
/* Minimum duty cycle register value, as ratio */
#define HAL_PARAM_MIN_DUTY_Q15 1475 // Q15( 0.04501) = +45.01343 m = +45.00000 m + 0.0298%
/* Maximum low-side duty cycle register value in counts */
#define HAL_PARAM_MAX_LOWER_DUTY_COUNTS 3342 // Q0(3342.00000) = +954.85714 m = +955.00000 m - 0.0150%
/* The maximum duty cycle of the half-bridge affects
* the maximum duty cycle of upper transistors
* and minimum duty cycle of lower transistors.
*/
/* Maximum duty cycle register value in counts */
#define HAL_PARAM_MAX_DUTY_COUNTS 3282 // Q0(3282.00000) = +937.71429 m = +937.70000 m + 0.0015%
/* Maximum duty cycle register value, as ratio */
#define HAL_PARAM_MAX_DUTY_Q15 30727 // Q15( 0.93771) = +937.71362 m = +937.70000 m + 0.0015%
/* Minimum low-side duty cycle register value in counts */
#define HAL_PARAM_MIN_LOWER_DUTY_COUNTS 218 // Q0(218.00000) = +62.28571 m = +62.30000 m - 0.0229%
4.4.4.2.6. Support for full on/off time in MCAF¶
MCAF does not support full on-time or off-time of either high-side or low-side transistor. This is a tricky feature to implement, because it represents a small jump discontinuity of the intended duty cycle.
4.4.4.3. Modules¶
4.4.4.3.1. Core FOC¶
Module |
Files |
Description |
Comments |
---|---|---|---|
deadtimecomp |
deadtimecomp.c deadtimecomp.h deadtimecomp_types.h parameters/deadtimecomp_params.h |
||
dyn_current |
dyn_current.c dyn_current.h dyn_current_types.h parameters/dyn_current_params.h |
||
foc |
foc.c foc.h foc_types.h parameters/foc_params.h |
Top-level FOC |
These functions are called from the state machine modules, as described in the implementation notes. |
sat_PI |
parameters/sat_PI_params.h sat_PI.c sat_PI.h sat_PI_types.h |
PI loop saturation management |
|
parameters/init_params |
parameters/init_params.c parameters/init_params.h |
Initialization of FOC control parameters |
|
parameters/outerloop_params |
parameters/outerloop_params.h |
Parameters for specifying the outer loop type (velocity or voltage control) |
4.4.4.3.2. Commutation¶
Module |
Files |
Description |
Comments |
---|---|---|---|
commutation |
commutation.c commutation.h commutation_types.h |
Top-level commutation / estimation |
|
commutation_excitation |
commutation_excitation.h |
Handling of output excitation for intrusive estimators |
Contains functions to compute required excitation voltage — or zero, if only non-intrusive estimators are used. |
commutation/atpll |
commutation/atpll.c commutation/atpll.h parameters/atpll_params.h |
||
commutation/common |
commutation/common.h |
Common features used in all estimators |
|
commutation/pll |
commutation/pll.c commutation/pll.h parameters/pll_params.h |
||
commutation/qei |
commutation/qei.c commutation/qei.h commutation/qei_types.h |
The quadrature encoder can be used as the primary estimator for commutation and velocity feedback, or to obtain a reference position and velocity for testing estimator performance. |
|
commutation/qei_sync |
commutation/qei_sync.c commutation/qei_sync.h commutation/qei_sync_types.h |
||
commutation/zsmt |
commutation/zsmt.c commutation/zsmt.h commutation/zsmt_hybrid.c commutation/zsmt_hybrid.h commutation/zsmt_hybrid_interaction.h commutation/zsmt_types.h commutation/zsmtlib.h parameters/zsmt_hybrid_params.h parameters/zsmt_params.h |