PMSM Control (uz_pmsm_control)#

Description#

The PMSM control module combines Speed Control, Set Point, CurrentControl, coordinate transformations, and Space vector Modulation to provide a complete field-oriented control (FOC) for permanent magnet synchronous machines. The module supports two operating modes: current-control mode and speed-control mode. In current-control mode, the externally supplied \(i_d\)/\(i_q\) references are used. In speed-control mode, the module calculates the current reference from a speed reference using the Set Point, CurrentControl.

The module outputs can be requested either as a dq-voltage vector or as duty cycles for an inverter where space vector modulation is used by the module. Thus, the output can be fed to the PWM and SS Control V4. The module offers reference limitation, optional first-order setpoint and speed filtering, rotor-angle compensation, controller reset behavior, and safe operating region monitoring.

Control#

Call one of the two available sample functions exactly once per control tick, i.e., in the interrupt service routine. Use uz_pmsm_control_sample_dq if the next layer needs dq-voltages, e.g., for controller in the loop or when using the software PMSM model. Use uz_pmsm_control_sample_duty if the next layer needs duty cycles; this function calls uz_pmsm_control_sample_dq internally before running Space vector Modulation.

For each sample, the implementation performs the following steps:

  1. Saturate the speed reference, current references, and disturbance torque input to setpoint_limits.

  2. Optionally low-pass filter the measured mechanical speed if speed_actual_value_filter_cutoff_frequency is non-zero.

  3. Store the measurements and calculate actual control values:

    \[\omega_{el} = p \omega_{mech}\]
    \[n_{mech} = \omega_{mech} \frac{60}{2 \pi}\]
    \[\theta_{el} = \operatorname{wrap}(p \theta_{mech}, 2 \pi) - \theta_{offset} + k_{sampling} \omega_{el} T_s\]

    After this sampling compensation, theta_el is wrapped to \(2 \pi\). theta_el_advanced is calculated by the following equation:

    \[\theta_{el,advanced} = \theta_{el} + k_{svm} \omega_{el} T_s\]

    where \(p\) is machine_data.polePairs, \(T_s\) is sample_time, \(k_{sampling}\) is theta_sampling_compensation, and \(k_{svm}\) is theta_svm_delay_compensation. The measured phase currents are transformed to dq with theta_el. The measured phase voltages are transformed with the following angle:

    \[\theta_{voltage} = \theta_{el} - k_{voltage} \omega_{el} T_s\]

    where k_voltage is voltage_theta_shift and theta_el is the offset- and sampling-compensated angle before the final wrapping step.

  4. Check the safe operating region.

  5. Optionally low-pass filter the speed reference if setpoint_filter_speed_cutoff_frequency is non-zero.

  6. If the controller is enabled and no safe operating region violation is active, execute either current-control mode or speed-control mode.

  7. Saturate the generated dq-current reference to setpoint_limits.i_d_in_A and setpoint_limits.i_q_in_A.

  8. Run the current controller and transform the resulting dq voltage to the abc-frame with theta_el_advanced.

  9. If duty cycles were requested, run SVM with the dq-voltage output, v_dc_in_V, and theta_el_advanced.

When the controller is disabled or a safe operating region violation is active, uz_pmsm_control_sample_dq resets the internal controller and filter states and returns a zero dq-voltage vector. In the same condition, uz_pmsm_control_sample_duty returns default_duty_cycle from the configuration. Choose this default value to match the safe state of the inverter hardware.

        ---
config:
  layout: elk
---

flowchart TD

    subgraph Inputs
        direction TB
        i_abc_in_A
        v_abc_in_V
        omega_mech_rad_per_sec
        theta_el
        v_dc_in_V
        i_dc_in_A
        disturbance_input_in_Nm
        reference_speed_in_rpm
        i_dq_ref_A
    end

    subgraph uz_pmsm_control_sample_dq
        direction LR

        uz_signals_saturation_speed["uz_signals_saturation"] --> uz_signals_IIR_Filter_reference_speed["uz_signals_IIR_Filter_sample"] --> uz_speedControl_sample
        uz_speedControl_sample ~~~ plus
        uz_speedControl_sample --> plus(["+"])
        uz_signals_saturation_disturbance["uz_signals_saturation"] --> plus

        plus --> clamping
        clamping --> uz_speedControl_sample

        plus --> uz_signals_saturation_after_speed["uz_signals_saturation"]
        uz_signals_saturation_after_speed --> uz_SetPoint_sample --> OR["Speed/Current Control"]
        OR --> uz_signals_saturation5["uz_signals_saturation"]
        uz_signals_saturation5 --> uz_CurrentControl_sample
        uz_CurrentControl_sample --> revDQ
        advance --> revDQ
        uz_CurrentControl_sample -->|v_dq_in_V| uz_Space_Vector_Modulation
        advance --> uz_Space_Vector_Modulation
        dq --> uz_CurrentControl_sample
        omega_mech_rad_per_sec --> uz_signals_IIR_Filter_sample_actual_speed["uz_signals_IIR_Filter_sample"] --> uz_speedControl_sample
        v_dc_in_V --> uz_Space_Vector_Modulation
        i_dq_ref_A --> uz_signals_IIR_Filter_dq_setpoint --> OR
        v_abc_in_V --> advance_voltage
        advance_voltage --> dq2
    end

    uz_Space_Vector_Modulation --> duty_cycle
    revDQ --> ref_v_abc_in_V
    i_abc_in_A --> dq
    theta_el --> dq
    theta_el --> advance
    disturbance_input_in_Nm --> uz_signals_saturation_disturbance
    reference_speed_in_rpm --> uz_signals_saturation_speed
    dq2 --> actual.v_abc_in_V
    

Fig. 388 Control flow of uz_pmsm_control_sample#

Operating modes#

Current-control mode#

Current-control mode is active when enable_speed_control is false. The reference_currents argument of the sample function is used as the \(i_d\)/\(i_q\) reference. The current references are first saturated to setpoint_limits.i_d_in_A and setpoint_limits.i_q_in_A. If setpoint_filter_i_dq_cutoff_frequency is non-zero, both current references are filtered. The resulting dq-current reference is saturated again before it is passed to the current controller.

Speed-control mode#

Speed-control mode is active when enable_speed_control is true. It can be selected in the initialization configuration or changed at runtime with uz_pmsm_control_enable_speed_control. In this mode the reference_speed_in_rpm argument is used and the reference_currents argument is ignored. The speed controller samples the measured mechanical speed in rad/s and the speed reference in rpm. Its torque output is added to disturbance_input_in_Nm. The sum is limited by setpoint_limits.speed_controller_torque_in_Nm and passed to the setpoint module, which calculates the dq-current reference for the selected motor type and field-weakening setting. If the torque sum would exceed the configured torque limits, the speed controller receives an external clamping signal to support anti-windup behavior.

Safe operating region#

The safe operating region is checked every time a sample function is called, independent of whether the controller output stage is enabled. If a violation is detected, the controller output is suppressed until the fault is acknowledged. The following values are monitored:

Limit

Check

i_abc_in_A

Absolute value of each measured phase current against upper_bound.

speed_in_rpm

Mechanical speed calculated from omega_mech_rad_per_sec against lower and upper bounds.

v_dc_in_V

Measured DC-link voltage against lower and upper bounds.

i_dc_in_A

Measured DC-link current against lower and upper bounds.

i_d_in_A

Measured d-current after abc-to-dq transformation against lower and upper bounds.

i_q_in_A

Measured q-current after abc-to-dq transformation against lower and upper bounds.

The first sample with an active violation latches a uz_pmsm_control_safe_operating_region_violation value. While a violation is latched, later samples do not overwrite it. If several limits are violated during the same fresh check, the violation checked later in the implementation order is the one stored. The table above follows the source-level check order. Use uz_pmsm_control_acknowledge_and_reset_error to acknowledge the latched fault. The function stores the supplied measurements, recalculates actual values, clears the violation flag, and immediately checks the safe operating region again. Therefore, the violation remains active if the supplied measurements are still outside the configured safe operating region.

Configuration#

uz_pmsm_control_init asserts that the PMSM configuration is valid, the sample time is positive, all controller gains and filter cutoff frequencies are non-negative, and every configured upper bound is greater than or equal to its lower bound. Each instance allocates one current controller, one speed controller, one setpoint module, and the optional filters. The number of available instances is configured with UZ_PMSM_CONTROL_MAX_INSTANCES. Important configuration groups:

Field

Purpose

setpoint_limits

Limits references and generated setpoints before they enter the control loop.

safe_operating_region

Defines runtime fault thresholds for measured and derived actual values.

sample_time

Sampling time of the control loop.

enable_speed_control

Selects speed-control mode on initialization.

*_kp and *_ki

Initial PI gains for speed, d-current, and q-current controllers.

setpoint_filter_i_dq_cutoff_frequency

Optional first-order low-pass filter for current references.

setpoint_filter_speed_cutoff_frequency

Optional first-order low-pass filter for speed references.

speed_actual_value_filter_cutoff_frequency

Optional first-order low-pass filter for measured mechanical speed.

decoupling_method

Selects the current-control decoupling strategy.

motor_type and enable_field_weakening

Configure the setpoint module used in speed-control mode.

relative_torque_tolerance

Numerical tolerance for setpoint generation.

theta_el_offset

Electrical rotor-angle offset in rad.

theta_sampling_compensation

Multiplier for sampling-delay compensation of the measured electrical angle.

theta_svm_delay_compensation

Multiplier for advancing the angle used for voltage output and SVM.

voltage_theta_shift

Multiplier for shifting the angle used to transform measured phase voltages to dq.

default_duty_cycle

Duty cycle returned while the output is disabled or faulted.

Set filter cutoff frequencies to 0.0f to disable the corresponding filter. Call the sample function with the period configured in sample_time.

Example#

The following example configures the controller for current-control mode and requests duty cycles in the control interrupt. The numerical values are example values and have to be adapted to the machine, inverter, and sampling time.

Listing 164 Initialize PMSM FOC in current-control mode#
 1#include "uz/uz_pmsm_control/uz_pmsm_control.h"
 2
 3static struct uz_PMSM_t machine = {
 4    .R_ph_Ohm = 0.51f,
 5    .Ld_Henry = 0.002f,
 6    .Lq_Henry = 0.002f,
 7    .Psi_PM_Vs = 0.042f,
 8    .polePairs = 4.0f,
 9    .J_kg_m_squared = 0.000108f,
10    .I_max_Ampere = 12.0f};
11
12static struct uz_pmsm_control_configuration_t config = {
13    .theta_el_offset = 0.0f,
14    .sample_time = 1.0f / 10000.0f,
15    .enable_speed_control = false,
16    .speed_controller_kp = 0.01f,
17    .speed_controller_ki = 0.05f,
18    .current_controller_d_kp = 5.8333f,
19    .current_controller_d_ki = 1500.0f,
20    .current_controller_q_kp = 5.8333f,
21    .current_controller_q_ki = 1500.0f,
22    .setpoint_limits = {
23        .speed_controller_torque_in_Nm = {.upper_bound = 2.0f, .lower_bound = -2.0f},
24        .i_d_in_A = {.upper_bound = 5.0f, .lower_bound = -5.0f},
25        .i_q_in_A = {.upper_bound = 5.0f, .lower_bound = -5.0f},
26        .speed_in_rpm = {.upper_bound = 1100.0f, .lower_bound = -1100.0f},
27        .disturbance_input_in_Nm = {.upper_bound = 10.0f, .lower_bound = -10.0f}},
28    .safe_operating_region = {
29        .speed_in_rpm = {.upper_bound = 1500.0f, .lower_bound = -1500.0f},
30        .i_d_in_A = {.upper_bound = 10.0f, .lower_bound = -10.0f},
31        .i_q_in_A = {.upper_bound = 10.0f, .lower_bound = -10.0f},
32        .i_abc_in_A = {.upper_bound = 20.0f, .lower_bound = -20.0f},
33        .v_dc_in_V = {.upper_bound = 28.0f, .lower_bound = 12.0f},
34        .i_dc_in_A = {.upper_bound = 15.0f, .lower_bound = -1.0f}},
35    .decoupling_method = linear_decoupling,
36    .setpoint_filter_i_dq_cutoff_frequency = 0.0f,
37    .setpoint_filter_speed_cutoff_frequency = 0.0f,
38    .motor_type = SMPMSM,
39    .enable_field_weakening = false,
40    .relative_torque_tolerance = 0.1f,
41    .speed_actual_value_filter_cutoff_frequency = 0.0f,
42    .theta_sampling_compensation = 0.0f,
43    .theta_svm_delay_compensation = 1.5f,
44    .voltage_theta_shift = 0.0f,
45    .default_duty_cycle = {.DutyCycle_A = 0.0f, .DutyCycle_B = 0.0f, .DutyCycle_C = 0.0f}};
46
47static uz_pmsm_control_t *pmsm_control = NULL;
48
49void init_control(void) {
50    pmsm_control = uz_pmsm_control_init(config, machine);
51    uz_pmsm_control_current_control_tune_magnitude_optimum(pmsm_control, 0.5f * config.sample_time);
52    uz_pmsm_control_enable(pmsm_control, true);
53}
Listing 165 Sample PMSM FOC in the control interrupt#
 1void ISR_Control(void) {
 2    struct uz_pmsm_measurement_values measurements = {
 3        .i_abc_in_A = {.a = 1.0f, .b = -0.5f, .c = -0.5f},
 4        .v_abc_in_V = {.a = 0.0f, .b = 0.0f, .c = 0.0f},
 5        .v_dc_in_V = 24.0f,
 6        .i_dc_in_A = 0.0f,
 7        .omega_mech_rad_per_sec = 10.0f,
 8        .theta_mech = 0.0f};
 9
10    uz_3ph_dq_t i_reference_A = {.d = 0.0f, .q = 1.0f, .zero = 0.0f};
11    struct uz_DutyCycle_t duty_cycle = uz_pmsm_control_sample_duty(
12        pmsm_control,
13        measurements,
14        0.0f,
15        i_reference_A,
16        0.0f);
17}

To use speed-control mode, enable the speed loop and pass a speed reference in rpm. The current-reference argument is ignored in this mode.

Listing 166 Runtime selection of speed-control mode#
1uz_pmsm_control_enable_speed_control(pmsm_control, true);
2
3uz_3ph_dq_t unused_current_reference_A = {.d = 0.0f, .q = 0.0f, .zero = 0.0f};
4struct uz_DutyCycle_t duty_cycle = uz_pmsm_control_sample_duty(
5    pmsm_control,
6    measurements,
7    500.0f,
8    unused_current_reference_A,
9    0.0f);

Tuning and runtime access#

The current-controller tuning helpers wrap the corresponding uz_CurrentControl tuning functions and can be called after initialization. The speed- and current-controller gains can also be updated directly with the provided setter functions. Use uz_pmsm_control_get_actual_data, uz_pmsm_control_get_reference_values, and uz_pmsm_control_get_pmsm_measurement_values to inspect the stored values. The returned pointers refer to internal storage and remain owned by the PMSM control instance. uz_pmsm_control_set_theta_offset changes the electrical angle offset at runtime. uz_pmsm_control_get_pointer_to_theta_offset returns a direct pointer to the same offset variable, for example for integration with observer or calibration code.

Observability of internal data#

Internal data such as actual values, reference values, and measurement values are accessible by pointers, as shown in Listing 167.

Listing 167 Access to internal PMSM control data pointers#
struct uz_pmsm_actual_data *actual_data = uz_pmsm_control_get_actual_data(pmsm_control);
struct uz_pmsm_reference_values *reference_values = uz_pmsm_control_get_reference_values(pmsm_control);
struct uz_pmsm_measurement_values *measurement_values = uz_pmsm_control_get_pmsm_measurement_values(pmsm_control);

The pointers can be used to display the data in the Javascope like so:

Listing 168 Display of internal PMSM control data in the Javascope#
  js_ch_observable[JSO_dut_iq] = &actual_data->i_dq_in_A.q;

API Reference#

Configuration and data types#

enum uz_pmsm_control_safe_operating_region_violation#

Safe operating region violation flags.

Values:

enumerator uz_pmsm_control_no_violation#

No violation detected.

enumerator uz_pmsm_control_speed_violation_upper#

Mechanical speed exceeds upper limit.

enumerator uz_pmsm_control_speed_violation_lower#

Mechanical speed falls below lower limit.

enumerator uz_pmsm_control_i_d_violation_upper#

d-current exceeds upper limit.

enumerator uz_pmsm_control_i_d_violation_lower#

d-current falls below lower limit.

enumerator uz_pmsm_control_i_q_violation_upper#

q-current exceeds upper limit.

enumerator uz_pmsm_control_i_q_violation_lower#

q-current falls below lower limit.

enumerator uz_pmsm_control_i_abc_violation_upper#

Phase current magnitude exceeds upper limit.

enumerator uz_pmsm_control_v_dc_violation_upper#

DC-link voltage exceeds upper limit.

enumerator uz_pmsm_control_v_dc_violation_lower#

DC-link voltage falls below lower limit.

enumerator uz_pmsm_control_i_dc_violation_upper#

DC-link current exceeds upper limit.

enumerator uz_pmsm_control_i_dc_violation_lower#

DC-link current falls below lower limit.

struct uz_limits_t#

Generic scalar upper and lower bounds.

Public Members

float upper_bound#

Upper bound.

float lower_bound#

Lower bound.

struct uz_pmsm_setpoint_limits_t#

Limits for reference inputs and generated setpoints.

Public Members

struct uz_limits_t speed_controller_torque_in_Nm#

Limits for speed-controller torque output in Nm.

struct uz_limits_t i_d_in_A#

Limits for d-current reference in A.

struct uz_limits_t i_q_in_A#

Limits for q-current reference in A.

struct uz_limits_t speed_in_rpm#

Limits for speed reference in rpm.

struct uz_limits_t disturbance_input_in_Nm#

Limits for disturbance torque input in Nm.

struct uz_pmsm_safe_operating_region_t#

Safe operating region limits checked during runtime.

Public Members

struct uz_limits_t speed_in_rpm#

Allowed mechanical speed range in rpm.

struct uz_limits_t i_d_in_A#

Allowed d-current range in A.

struct uz_limits_t i_q_in_A#

Allowed q-current range in A.

struct uz_limits_t i_abc_in_A#

Allowed phase current magnitude in A.

struct uz_limits_t v_dc_in_V#

Allowed DC-link voltage range in V.

struct uz_limits_t i_dc_in_A#

Allowed DC-link current range in A.

struct uz_pmsm_control_configuration_t#

Configuration for PMSM control module.

Public Members

struct uz_pmsm_setpoint_limits_t setpoint_limits#

Limits applied to references and controller outputs.

struct uz_pmsm_safe_operating_region_t safe_operating_region#

Safe operating region limits for fault detection.

float theta_el_offset#

Electrical rotor angle offset in rad.

float sample_time#

Control sample time in s, typically 1/PWM frequency.

bool enable_speed_control#

Enable speed controller on initialization.

float speed_controller_kp#

Proportional gain of speed controller.

float speed_controller_ki#

Integral gain of speed controller.

float current_controller_d_kp#

Proportional gain of d-current controller.

float current_controller_d_ki#

Integral gain of d-current controller.

float current_controller_q_kp#

Proportional gain of q-current controller.

float current_controller_q_ki#

Integral gain of q-current controller.

float setpoint_filter_i_dq_cutoff_frequency#

Cutoff frequency for dq setpoint filter in Hz. Disable filter if 0.

float setpoint_filter_speed_cutoff_frequency#

Cutoff frequency for speed setpoint filter in Hz. Disable filter if 0.

float speed_actual_value_filter_cutoff_frequency#

Cutoff frequency for measured speed filter in Hz. Disable filter if 0.

enum uz_CurrentControl_decoupling_select decoupling_method#

Decoupling method for current control.

enum uz_Setpoint_motor_type motor_type#

Motor type selection for setpoint generation.

bool enable_field_weakening#

Enable field weakening in setpoint generation.

float relative_torque_tolerance#

Relative torque tolerance for numerical solver.

float theta_sampling_compensation#

Multiplier for angle compensation based on sampling delay.

float theta_svm_delay_compensation#

Multiplier for SVM delay compensation in angle advance.

float voltage_theta_shift#

Multiplier for shifting measurement angle used for voltage transformation.

struct uz_DutyCycle_t default_duty_cycle#

Duty cycle returned while control is disabled or safe operating region is violated.

struct uz_pmsm_measurement_values#

Input measurement values for one PMSM control step.

Public Members

uz_3ph_abc_t i_abc_in_A#

Phase currents in abc-frame in A.

uz_3ph_abc_t v_abc_in_V#

Phase voltages in abc-frame in V.

float v_dc_in_V#

DC-link voltage in V.

float i_dc_in_A#

DC-link current in A.

float omega_mech_rad_per_sec#

Mechanical angular speed in rad/s.

float theta_mech#

Mechanical rotor angle in rad.

struct uz_pmsm_actual_data#

Actual control state values generated by the PMSM control algorithm.

Public Members

uz_3ph_dq_t i_dq_in_A#

Measured currents in dq-frame in A.

uz_3ph_dq_t v_dq_in_V#

Control voltages in dq-frame in V.

float omega_el_rad_per_sec#

Electrical angular speed in rad/s.

float speed_in_rpm#

Mechanical speed in rpm.

float theta_el#

Electrical rotor angle in rad.

float theta_el_advanced#

Delay-compensated electrical rotor angle in rad.

struct uz_pmsm_reference_values#

Internal reference values computed by PMSM control.

Public Members

float speed_in_rpm#

Speed reference in rpm.

float M_in_Nm#

Torque reference in Nm.

uz_3ph_dq_t i_dq_in_A#

Current reference in dq-frame in A.

uz_3ph_dq_t v_dq_in_V#

Voltage reference in dq-frame in V.

uz_3ph_abc_t v_abc_in_V#

Voltage reference in abc-frame in V.

struct uz_DutyCycle_t duty_cycle#

Generated duty cycle output.

Object and functions#

typedef struct uz_pmsm_control_t uz_pmsm_control_t#

Object definition for PMSM control.

uz_pmsm_control_t *uz_pmsm_control_init(struct uz_pmsm_control_configuration_t config, uz_PMSM_t machine_data)#

Initializes PMSM control module.

Parameters:
  • config – Configuration struct for PMSM control.

  • machine_data – Machine data for PMSM model parameters.

Returns:

Pointer to initialized PMSM control instance.

const struct uz_pmsm_actual_data *uz_pmsm_control_get_actual_data(uz_pmsm_control_t *self)#

Returns pointer to internal actual control data.

Parameters:
  • self – Pointer to PMSM control instance.

Returns:

Pointer to struct containing actual values.

const struct uz_pmsm_reference_values *uz_pmsm_control_get_reference_values(uz_pmsm_control_t *self)#

Returns pointer to internal reference values.

Parameters:
  • self – Pointer to PMSM control instance.

Returns:

Pointer to struct containing reference values.

const struct uz_pmsm_measurement_values *uz_pmsm_control_get_pmsm_measurement_values(uz_pmsm_control_t *self)#

Returns pointer to stored measurement values.

Parameters:
  • self – Pointer to PMSM control instance.

Returns:

Pointer to struct containing latest measurement values.

void uz_pmsm_control_enable(uz_pmsm_control_t *self, bool enable)#

Enables or disables the controller output stage.

Parameters:
  • self – Pointer to PMSM control instance.

  • enable – Set true to enable control output, false to disable.

struct uz_DutyCycle_t uz_pmsm_control_sample_duty(uz_pmsm_control_t *self, struct uz_pmsm_measurement_values measurements, float reference_speed_in_rpm, uz_3ph_dq_t reference_currents, float disturbance_input_in_Nm)#

Executes one control step and returns duty cycle output.

Parameters:
  • self – Pointer to PMSM control instance.

  • measurements – Latest measured values.

  • reference_speed_in_rpm – Speed reference in rpm.

  • reference_currents – Current references in dq-frame in A.

  • disturbance_input_in_Nm – Disturbance torque feedforward in Nm.

Returns:

Duty cycle command for inverter.

struct uz_3ph_dq_t uz_pmsm_control_sample_dq(uz_pmsm_control_t *self, struct uz_pmsm_measurement_values measurements, float reference_speed_in_rpm, uz_3ph_dq_t reference_currents, float disturbance_input_in_Nm)#

Executes one control step and returns dq-voltage output.

Parameters:
  • self – Pointer to PMSM control instance.

  • measurements – Latest measured values.

  • reference_speed_in_rpm – Speed reference in rpm.

  • reference_currents – Current references in dq-frame in A.

  • disturbance_input_in_Nm – Disturbance torque feedforward in Nm.

Returns:

dq-voltage command in V.

void uz_pmsm_control_reset(uz_pmsm_control_t *self)#

Resets internal controller states.

Parameters:
  • self – Pointer to PMSM control instance.

void uz_pmsm_control_enable_speed_control(uz_pmsm_control_t *self, bool enable_speed_control)#

Enables or disables internal speed control loop.

Parameters:
  • self – Pointer to PMSM control instance.

  • enable_speed_control – Set true to enable speed control.

void uz_pmsm_control_acknowledge_and_reset_error(uz_pmsm_control_t *self, struct uz_pmsm_measurement_values measurements)#

Acknowledges a safe operating region fault and reevaluates with current measurements.

Parameters:
  • self – Pointer to PMSM control instance.

  • measurements – Latest measured values.

enum uz_pmsm_control_safe_operating_region_violation uz_pmsm_control_get_safe_operating_area_violation(uz_pmsm_control_t *self)#

Returns current safe operating region violation state.

Parameters:
  • self – Pointer to PMSM control instance.

Returns:

Active safe operating region violation flag.

void uz_pmsm_control_set_theta_offset(uz_pmsm_control_t *self, float theta_offset)#

Sets electrical angle offset.

Parameters:
  • self – Pointer to PMSM control instance.

  • theta_offset – Electrical angle offset in rad.

const float *uz_pmsm_control_get_pointer_to_theta_offset(uz_pmsm_control_t *self)#

Returns pointer to electrical angle offset variable.

Parameters:
  • self – Pointer to PMSM control instance.

Returns:

Pointer to theta offset in rad.

void uz_pmsm_control_current_control_tune_magnitude_optimum(uz_pmsm_control_t *self, float tau_sigma_sec)#

Tunes current controller gains using magnitude optimum.

Parameters:
  • self – Pointer to PMSM control instance.

  • tau_sigma_sec – Equivalent delay time constant in s.

void uz_pmsm_control_current_control_tune_symmetric_optimum(uz_pmsm_control_t *self, float tau_sigma_sec)#

Tunes current controller gains using symmetric optimum.

Parameters:
  • self – Pointer to PMSM control instance.

  • tau_sigma_sec – Equivalent delay time constant in s.

void uz_pmsm_control_current_control_tune_bandwidth(uz_pmsm_control_t *self, float bandwidth_rad_per_sec)#

Tunes current controller gains for a target bandwidth.

Parameters:
  • self – Pointer to PMSM control instance.

  • bandwidth_rad_per_sec – Desired bandwidth in rad/s.

void uz_pmsm_control_current_control_set_Kp_iq(uz_pmsm_control_t *self, float Kp_iq)#

Sets proportional gain of q-current controller.

Parameters:
  • self – Pointer to PMSM control instance.

  • Kp_iq – Proportional gain for q-current loop.

void uz_pmsm_control_current_control_set_Ki_iq(uz_pmsm_control_t *self, float Ki_iq)#

Sets integral gain of q-current controller.

Parameters:
  • self – Pointer to PMSM control instance.

  • Ki_iq – Integral gain for q-current loop.

void uz_pmsm_control_current_control_set_Kp_id(uz_pmsm_control_t *self, float Kp_id)#

Sets proportional gain of d-current controller.

Parameters:
  • self – Pointer to PMSM control instance.

  • Kp_id – Proportional gain for d-current loop.

void uz_pmsm_control_current_control_set_Ki_id(uz_pmsm_control_t *self, float Ki_id)#

Sets integral gain of d-current controller.

Parameters:
  • self – Pointer to PMSM control instance.

  • Ki_id – Integral gain for d-current loop.

void uz_pmsm_control_speed_control_set_Kp_speed(uz_pmsm_control_t *self, float Kp_speed)#

Sets proportional gain of speed controller.

Parameters:
  • self – Pointer to PMSM control instance.

  • Kp_speed – Proportional gain of speed loop.

void uz_pmsm_control_speed_control_set_Ki_speed(uz_pmsm_control_t *self, float Ki_speed)#

Sets integral gain of speed controller.

Parameters:
  • self – Pointer to PMSM control instance.

  • Ki_speed – Integral gain of speed loop.