Perform control parameter tuning for the speed and the torque control loops that are part of the Field-Oriented Control (FOC) algorithm. Motor Control Blockset™ provides you with multiple methods to compute the control loop gains from the system or block transfer functions that are available for the motors, inverter, and controller:
Use the Field Oriented Control Autotuner block.
Use Simulink® Control Design™.
Use the model initialization script.
The Field-Oriented Control Autotuner block of Motor Control Blockset enables you to automatically tune the PID control loops in your Field-Oriented Control (FOC) application in real time. You can automatically tune the PID controllers associated with the following loops (for more details, see How to Use Field Oriented Control Autotuner Block):
Direct-axis (d-axis) current loop
Quadrature-axis (q-axis) current loop
Speed loop
For each loop that the block tunes, the Field-Oriented Control Autotuner block performs the autotuning experiment in a closed-loop manner without using a parametric model associated with that loop. The block enables you to specify the order in which the block tunes the control loops. When the tuning experiment runs for one loop, the block has no effect on the other loops. For more details about FOC autotuner, see Field Oriented Control Autotuner and Tune PI Controllers by Using Field Oriented Control Autotuner.
Simulink Control Design enables you to design and analyze the control systems modeled in Simulink. You can automatically tune the arbitrary SISO and MIMO control architectures, including the PID controllers. You can deploy PID autotuning to the embedded software to automatically compute the PID gains in real time.
You can find the operating points and compute the exact linearizations of the Simulink models at different operating conditions. Simulink Control Design provides tools that let you compute the simulation-based frequency responses without modifying your model. For details, see https://www.mathworks.com/help/slcontrol/index.html
This section explains how the Motor Control Blockset examples estimate the control gains needed to implement field-oriented control. For example, for a PMSM that is connected to a quadrature encoder, these steps describe the procedure to compute the control loop gain values from the system details by using the initialization script:
Open the initialization script (.m
) file of the example
in MATLAB®. To find the associated script file name:
Select Modeling > Model Settings > Model Properties to open the model properties dialog box.
In the Model Properties dialog box, navigate to the Callbacks tab > InitFcn to find the name of the script file that Simulink opens before running the example.
This figure shows an example of the initialization script
(.m
) file.
Use the Workspace to edit the control variables
values. For example, to update Stator resistance (Rs
),
use the variable pmsm
to add the parameter value to the
Rs
field.
The model initialization script associated with a target model calls these functions and sets up the workspace with the necessary variables.
Model Initialization Script | Function Called By Model Initialization Script | Description |
---|---|---|
Script associated with a target model |
| Input to the function is motor type (for example, BLY171D). The function populates a structure
named It also computes the permanent magnet flux and rated torque for the selected motor. You can extend the function by adding an additional switch-case for a new motor. This function also loads the
structure |
| Input to the function is inverter type (for example, BoostXL-DRV8305). The function
populates a structure named The function also computes the inverter resistance for the selected inverter. You can extend the function by adding an additional switch-case for a new inverter. | |
| Inputs to the function are processor type (for example, F28379D) and the Pulse-Width Modulation (PWM) switching frequency. The function populates
a structure named The function also computes the PWM counter period that is a parameter for the ePWM block in the target model. You can extend the function by adding an additional switch-case for a new processor. | |
| Inputs to the function are motor and inverter parameters. The function computes the base speed for PMSM. Type | |
| Inputs to the function are motor and inverter parameters. The function sets the base values of the per-unit system for voltage, current, speed, torque, and power. The function
populates a structure named | |
| Inputs to the function are motor and inverter parameters, per-unit system base values, PWM switching time period, sample time for the control system, and sample time for the speed controller. The function computes the Proportional Integral (PI) parameters (Kp, Ki) for the field-oriented control implementation. The function populates a
structure named See section Obtain Controller Gains for more details. |
This table explains the useful variables for each control parameter that you can update.
Note
You can try starting MATLAB in the administrator mode on Windows® system, if you are unable to update the model initialization scripts associated with the example models.
Control Parameter Category | Control Parameter Name | MATLAB Workspace Variable |
---|---|---|
Motor parameters | Manufacturer’s model number | pmsm.model |
Manufacturer’s serial number | pmsm.sn | |
Pole pairs | pmsm.p | |
Stator resistance (Ohm) | pmsm.Rs | |
d-axis stator winding inductance (Henry) | pmsm.Ld | |
q-axis stator winding inductance (Henry) | pmsm.Lq | |
Back emf constant (V_line(peak)/krpm) | pmsm.Ke | |
Motor Inertia (kg.m2) | pmsm.J | |
Friction constant (N.m.s) | pmsm.F | |
Permanent Magnet Flux (WB) | pmsm.FluxPM | |
Trated | pmsm.T_rated | |
Nbase | pmsm.N_base | |
Irated | pmsm.I_rated | |
Position decoders | QEP index and Hall position offset correction | pmsm.PositionOffset |
Quadrature encoder slits per revolution | pmsm.QEPSlits | |
Inverter parameters | Manufacturer’s model number | inverter.model |
Manufacturer’s serial number | inverter.sn | |
DC link voltage of the inverter (V) | inverter.V_dc | |
Maximum measurable currents by ADCs (A) | inverter.I_max | |
Maximum permissible currents by inverter (A) | inverter.I_trip | |
On-state resistance of MOSFETs (Ohm) | inverter.Rds_on | |
Shunt resistance for current sensing (Ohm) | inverter.Rshunt | |
Per-phase board resistance seen by motor (Ohm) | inverter.R_board | |
Current scaling | inverter.MaxADCCnt | |
ADC Offsets for current sensor (Ia and Ib) |
| |
Enable Auto-calibration for current sense ADCs | inverter.ADCOffsetCalibEnable | |
Processor | Manufacturer’s model number | target.model |
Manufacturer’s serial number | target.sn | |
CPU Frequency | target.CPU_frequency | |
PWM frequency | target.PWM_frequency | |
PWM counter period | target.PWM_Counter_Period | |
Per-Unit System | Base voltage (V) | PU_System.V_base |
Base current (A) | PU_System.I_base | |
Base speed (rpm) | PU_System.N_base | |
Base torque (Nm) | PU_System.T_base | |
Base power (Watts) | PU_System.P_base | |
Data-type for target device | Data-type (Fixed-point Or Floating-point) selection | dataType |
Sample time values | Switching frequency for converter | PWM_frequency |
PWM switching time period | T_pwm | |
Sample time for current controllers | Ts | |
Sample time for speed controller | Ts_speed | |
Simulation sample time | Ts_simulink | |
Simulation sample time for motor | Ts_motor | |
Simulation sample time for inverter | Ts_inverter | |
Controller parameters | Proportional gain for Iq controller | PI_params.Kp_i |
Integral gain for Iq controller | PI_params.Ki_i | |
Proportional gain for Id controller | PI_params.Kp_id | |
Integral gain for Id controller | PI_params.Ki_id | |
Proportional gain for Speed controller | PI_params.Kp_speed | |
Integral gain for Speed controller | PI_params.Ki_speed | |
Proportional gain for Field weakening controller | PI_params.Kp_fwc | |
Integral gain for Field weakening controller | PI_params.Ki_fwc |
Note
For the predefined processors and drivers, the model initialization script uses the default values.
The model initialization script uses these functions for performing the computations:
Control Parameter Category | Function | Functionality |
---|---|---|
Base speed of the motor | mcb_getBaseSpeed | Calculates the base speed of PMSM at the rated voltage and rated load. For details, type |
Motor characteristics for the given motor and inverter | mcb_getCharacteristics | Obtain these characteristics of the motor.
For details, type |
Control algorithm parameters | mcb.internal.SetControllerParameters | Compute the gains for these PI controllers:
For details, see section Obtain Controller Gains. |
Control analysis for the motor and inverter you are using | mcb_getControlAnalysis | Performs frequency domain analysis for the computed gains of PI controllers used in the field-oriented motor control system. Note This feature requires Control System Toolbox™. For details, type |
The function mcb_getBaseSpeed
computes the base speed of
the PMSM at the given supply voltage. Base speed is the maximum motor speed at
the rated voltage and rated load, outside the field-weakening region.
When you call this function (for example, base_speed =
mcb_getBaseSpeed(pmsm,inverter)
), it returns the base speed (in
rpm) for the given combination of PMSM and inverter. The function accepts the
following inputs:
PMSM parameter structure.
Inverter parameter structure.
These equations describe the computations that the function performs:
The inverter voltage constraint is defined by computing the d-axis and q-axis voltages:
The current limit circle defines the current constraint which can be considered as:
In the preceding equation, is zero for surface PMSMs. For interior PMSMs, values of and corresponding to MTPA are considered.
Using the preceding relationships, we can compute the base speed as:
where:
is the electrical speed corresponding to frequency of stator voltages (Radians/ sec).
is the mechanical base speed of the motor (Radians/ sec).
is the d-axis current (Amperes).
is the q-axis current (Amperes).
is the d-axis voltage when is zero (Volts).
is the q-axis voltage when is zero (Volts).
is the d-axis winding inductance (Henry).
is the q-axis winding inductance (Henry).
is the stator phase winding resistance (Ohms).
is the permanent magnet flux linkage (Weber).
is the d-axis voltage (Volts).
is the q-axis voltage (Volts).
is the maximum fundamental line to neutral voltage (peak) supplied to the motor (Volts).
is the dc voltage supplied to the inverter (Volts).
is the maximum phase current (peak) of the motor (Amperes).
is the number of motor pole pairs.
The function mcb_getCharacteristics
calculates the torque
and speed characteristics of the motor, which helps you to develop the control
algorithm for the motor.
The function returns these characteristics for the given PMSM:
Torque as opposed to Speed
Power as opposed to Speed
Iq as opposed to Speed
Id as opposed to Speed
The function mcb.internal.SetControllerParameters
computes
the gains for the PI controllers used in the field-oriented motor control
systems.
When you call this function (for example, PI_params =
mcb.internal.SetControllerParameters(pmsm,inverter,PU_System,T_pwm,Ts_control,Ts_speed)
),
it returns the gains of these PI controllers used in the FOC algorithm:
Direct-axis (d-axis) current loop
Quadrature-axis (q-axis) current loop
Speed loop
Field-weakening control loop
The function accepts these inputs:
pmsm object
inverter object
PU system params
T_pwm
Ts_control
Ts_speed
The function does not plot any characteristic.
The design of compensators depends on the classical frequency response analysis applied to the motor control systems. We used the Modulus Optimum (MO) based design for the current controllers and the Symmetrical Optimum (SO) based design for the speed controller.
The function automatically computes the other required parameters (for example, bandwidth, damping) based on the input arguments.
The function mcb_getControlAnalysis
performs the basic
control analysis of the PMSM FOC current control system. The function performs
frequency domain analysis for the computed PI controller gains used in the
field-oriented motor control systems.
Note
This function requires the Control System Toolbox.
When you call this function (for example,
mcb_getControlAnalysis(pmsm,inverter,PU_System,PI_params,Ts,Ts_speed)
),
it performs the following functions for the current control loop or
subsystem:
Transfer function for the closed-loop current control system
Root locus
Bode diagram
Stability margins (PM & GM)
Step response
PZ map
The function plots the corresponding plots: