Motor Parameter Tuning

Overview — Motor Parameters for Sensorless FOC

Sensorless FOC requires accurate motor parameters to operate correctly. The observers (FAST and ESMO) and the current/speed PI regulators all depend on these values. Before running a motor, you must supply at minimum the nameplate electrical parameters. If you do not have them, the SDK provides two automated identification tools — InstaSPIN and TiTune — that measure the parameters directly from the motor.

The required parameters are:

Parameter

Motor_ParamsType field

Description

Pole pairs

NumPolePairs

Number of rotor pole pairs

Stator resistance

Rs_Ohm

Phase resistance (Ω)

D-axis inductance

Ls_d_H

D-axis stator inductance (H)

Q-axis inductance

Ls_q_H

Q-axis stator inductance (H)

Back-EMF constant

RatedFlux_VpHz

Back-EMF constant Ke (V/Hz) — measured when the motor runs in closed-loop current control at rated current and rated electrical speed. If the datasheet value is not available, use a typical value based on the application’s target operating speed range. Required by FAST as an initial estimate.

Rated current

RatedCurrent_A

Rated phase current (A)

Rotor inertia

Inertia_Kgm2

Rotor inertia (kg·m²) — used by TiTune

Rated speed

RatedSpeed_Hz

Rated electrical speed (Hz)

Rated voltage

RatedVoltage_V

Rated phase voltage (V)

Both identification tools work with either observer:

Identification Tool

FAST (ESTIMATOR_MODE_FAST)

ESMO (ESTIMATOR_MODE_ESMO)

InstaSPIN

Supported

Supported

TiTune

Supported

Supported

Note

FAST additionally uses RatedFlux_VpHz as an initial estimate for the flux observer. Provide a reasonable nameplate value even when using automated identification, as it seeds the FAST estimator during the open-loop phase.


Step 1 — Enter Nameplate Parameters

All motor parameters are stored in motor_params.h and motor_params.c. To add a new motor:

  1. Open motor_params.h and add a macro block for your motor. Use an existing motor block as a template:

    /* ---- MY_MOTOR nameplate parameters ---- */
    #define MOTOR_MY_MOTOR_NUM_POLE_PAIRS     (4U)
    #define MOTOR_MY_MOTOR_Rs_Ohm             (0.35f)
    #define MOTOR_MY_MOTOR_Ls_d_H             (0.000180f)
    #define MOTOR_MY_MOTOR_Ls_q_H             (0.000210f)
    #define MOTOR_MY_MOTOR_RATED_FLUX_VpHz    (0.0415f)
    #define MOTOR_MY_MOTOR_RATED_CURRENT_A    (5.0f)
    #define MOTOR_MY_MOTOR_INERTIA_Kgm2       (0.000010f)
    #define MOTOR_MY_MOTOR_RATED_SPEED_Hz     (200.0f)
    #define MOTOR_MY_MOTOR_RATED_VOLTAGE_V    (24.0f)
    

    Also update the MOTOR_PH_Ls_d_H and MOTOR_PH_Ls_q_H aliases at the bottom of the file (used by the MTPA look-up table generator):

    #define MOTOR_PH_Ls_d_H    MOTOR_MY_MOTOR_Ls_d_H
    #define MOTOR_PH_Ls_q_H    MOTOR_MY_MOTOR_Ls_q_H
    
  2. Open motor_params.c and add a const Motor_ParamsType entry for your motor:

    const Motor_ParamsType Motor_MyMotorParams = {
        .NumPolePairs   = MOTOR_MY_MOTOR_NUM_POLE_PAIRS,
        .Rs_Ohm         = MOTOR_MY_MOTOR_Rs_Ohm,
        .Ls_d_H         = MOTOR_MY_MOTOR_Ls_d_H,
        .Ls_q_H         = MOTOR_MY_MOTOR_Ls_q_H,
        .RatedFlux_VpHz = MOTOR_MY_MOTOR_RATED_FLUX_VpHz,
        .RatedCurrent_A = MOTOR_MY_MOTOR_RATED_CURRENT_A,
        .Inertia_Kgm2   = MOTOR_MY_MOTOR_INERTIA_Kgm2,
        .RatedSpeed_Hz  = MOTOR_MY_MOTOR_RATED_SPEED_Hz,
        .RatedVoltage_V = MOTOR_MY_MOTOR_RATED_VOLTAGE_V,
        /* Copy startup, ESMO gains, and timing fields from an existing motor entry */
    };
    
  3. Update the motorParams_M1 pointer in motor_params.c to point to your new entry:

    const Motor_ParamsType *motorParams_M1 = &Motor_MyMotorParams;
    

Note

If you do not yet know Rs_Ohm, Ls_d_H, Ls_q_H, or RatedFlux_VpHz, enter approximate values from the motor datasheet (or leave the defaults from a similar motor). The identification tools in the next steps will measure the actual values and you can update the macros afterwards.


Step 2 — Choose a Parameter Identification Method

Use the following decision tree to decide how to proceed:

Do you have accurate Rs, Ls, Ke values from a datasheet or previous measurement?
│
├── YES → Enter them in motor_params.h (Step 1) and skip identification.
│         Proceed directly to running the motor.
│
└── NO  → Use automated identification.
          │
          ├── Do you want a quick single-step identification?
          │   └── YES → Use InstaSPIN (Section below)
          │
          └── Do you want full identification including inertia and PI gains?
              └── YES → Use TiTune (Section below)

Both tools are triggered from the watch window at runtime — no recompile is needed to switch between them.


InstaSPIN Parameter Identification

Overview

InstaSPIN is TI’s on-the-fly motor parameter identification engine embedded in the FAST observer library. It estimates Rs, Ls_d, Ls_q, and Ke (flux) by injecting test signals at standstill and during a brief open-loop spin. It also computes initial current and speed PI gains. InstaSPIN runs as part of the FAST estimator state machine and completes in a single automated sequence.

How to Enable

Before triggering identification, set the estimator mode in the watch window:

Expression

Value

motorVars_M1.inputCtrl.estimatorMode

ESTIMATOR_MODE_FAST

Then trigger identification:

  1. Set motorVars_M1.inputCtrl.motorParamIdentifyMethod = MOTOR_PARAM_IDENTIFY_INSTASPIN

  2. Set motorVars_M1.inputCtrl.flagEnableMotorIdentify = true

  3. Enable the motor run command to allow the identification sequence to proceed.

  4. Monitor motorVars_M1.statusVars.flagMotorIdentified — it goes true when complete.

Warning

The motor shaft will rotate briefly during the flux (Ke) identification phase. Ensure the shaft is free to spin and the load is safe to move before triggering identification.

Tuning the Estimation (user_mtr1.h INSTASPIN_EST_ parameters)

The following parameters in user_mtr1.h control the test signal levels used during identification. Review and adjust them for your motor before running InstaSPIN.

Parameter

Default

Description

INSTASPIN_EST_RES_CURRENT_A

1.5

DC current for Rs estimation (A) — set to 50–70% of rated

INSTASPIN_EST_IND_CURRENT_A

-1

AC current for Ls estimation (A, negative) — set to 40–60% of rated

INSTASPIN_EST_Ls_d_COMP_COEF

0.15f

Ls_d compensation coefficient (0.0–0.5)

INSTASPIN_EST_Ls_q_COMP_COEF

0.35f

Ls_q compensation coefficient (0.0–0.5)

INSTASPIN_EST_Ls_MIN_NUM_COEF

0.55f

Ls minimum coefficient (0.5–1.0)

INSTASPIN_EST_FLUX_EXC_FREQ_Hz

60

Flux excitation frequency (Hz)

INSTASPIN_EST_FREQ_NEARZEROLIMIT_Hz

5

Near-zero speed frequency limit (Hz)

The estimation scale factors below fine-tune the FAST observer response. Adjust these if the observer shows oscillation or poor tracking at high speed:

Parameter

Location

Default

Description

USER_M1_EST_FLUX_HF_SF

user_mtr1.h

0.25f

Flux estimation scale factor (0.1–1.25)

USER_M1_EST_FREQ_HF_SF

user_mtr1.h

1

Frequency estimation scale factor (0.5–1.5)

USER_M1_EST_BEMF_HF_SF

user_mtr1.h

1

BEMF estimation scale factor (0.50–1.25)

Watch Window — Monitoring Identification

Expression

Description

motorVars_M1.inputCtrl.flagEnableMotorIdentify

Set true to start identification

motorVars_M1.inputCtrl.motorParamIdentifyMethod

Set to MOTOR_PARAM_IDENTIFY_INSTASPIN

motorVars_M1.statusVars.flagMotorIdentified

Goes true when identification is complete

motorVars_M1.statusVars.estState

Current FAST estimator state during identification

Results — Where to Find Identified Parameters

After InstaSPIN completes, the identified values are written to motorSetVars_M1:

Expression

Description

motorSetVars_M1.Rs_Ohm

Identified stator resistance (Ω)

motorSetVars_M1.Ls_d_H

Identified d-axis inductance (H)

motorSetVars_M1.Ls_q_H

Identified q-axis inductance (H)

motorSetVars_M1.flux_VpHz

Identified back-EMF constant (V/Hz)

motorSetVars_M1.Kp_Id

Computed d-axis current loop Kp

motorSetVars_M1.Ki_Id

Computed d-axis current loop Ki

motorSetVars_M1.Kp_Iq

Computed q-axis current loop Kp

motorSetVars_M1.Ki_Iq

Computed q-axis current loop Ki

motorSetVars_M1.Kp_spd

Computed speed loop Kp

motorSetVars_M1.Ki_spd

Computed speed loop Ki

Copy these values into the macro block in motor_params.h to make them permanent. See Applying Results to motor_params.h.


TiTune Parameter Identification

Overview

TiTune is TI’s automated motor parameter identification and PI tuning utility. It runs a structured state machine that measures Rs, Ld, Lq at standstill and Ke at low speed, then estimates rotor inertia (J) and damping (B) via a coast-down test. From these measurements it computes optimal current and speed PI gains. TiTune works with both FAST and ESMO observers.

TiTune is the recommended tool when you also need inertia estimation or want fully computed PI gains for the speed loop.

How to Enable

Set the estimator mode before triggering identification:

Expression

Value

motorVars_M1.inputCtrl.estimatorMode

ESTIMATOR_MODE_FAST or ESTIMATOR_MODE_ESMO

Verify the per-unit base values match your motor nameplate before starting:

Expression

Description

TiTune_M1.RatedCurrent_A

Per-unit current base — must match motor rated current (A)

TiTune_M1.RatedSpeed_Hz

Per-unit speed base — must match motor rated electrical speed (Hz)

Then trigger identification:

  1. Set motorVars_M1.inputCtrl.motorParamIdentifyMethod = MOTOR_PARAM_IDENTIFY_TITUNE

  2. Set motorVars_M1.inputCtrl.flagEnableMotorIdentify = true

  3. Enable the motor run command to allow the identification sequence to proceed.

  4. Monitor TiTune_M1.Status.state to track the current phase.

  5. Monitor motorVars_M1.statusVars.flagMotorIdentified — it goes true when complete.

Warning

The motor shaft will rotate during the open-loop ramp (TiTune_STATE_OL_RUN) and closed-loop settle phases. Ensure the shaft is free to spin and the load is safe to move before triggering identification.

Identification Sequence (state machine phases with tuning guidance)

TiTune progresses through the following states automatically. Each state has tuning parameters you can adjust if the identification fails or produces poor results.

TiTune_STATE_LDQ_EST — Inductance Estimation

The motor is at standstill with the rotor locked. TiTune injects a high-frequency AC voltage signal into the d-axis while scanning for the rotor position. At each angle step, the algorithm measures the current responses and identifies the minimum inductance (Ld) and maximum inductance (Lq) from the scan and also detects the initial rotor angle position.

LDQ Estimation Parameters

The parameters below are set in TiTune_LDQ_setParams() in ti_tune.c. The user-tunable values are defined in Section B of ti_tune.h.

Parameter

Location

Default

Description / Tuning Guidance

TI_TUNE_LDQ_ELEC_THETA_STEP

ti_tune.h Section B

0.004f

Electrical angle step per measurement point (per-unit, 0→0.5 = 180°). Default gives ~0.72° per step. For surface-mount PMSM with very similar Ld/Lq, reduce for finer resolution.

TI_TUNE_LDQ_INJ_HALF_PRD_INIT

ti_tune.h Section B

8.0f

Initial half-period samples — sets the starting injection frequency. Higher value = lower frequency.

TI_TUNE_LDQ_INJ_HALF_PRD_MAX

ti_tune.h Section B

30.0f

Maximum half-period samples — sets the minimum injection frequency. For motors with very high inductance (large motors), increase to allow lower injection frequencies.

TI_TUNE_LDQ_INJ_SETTLE_PRD

ti_tune.h Section B

2.0f

Injection periods for settling before DFT measurement begins.

TI_TUNE_LDQ_INJ_VOL_MAGN_INIT

ti_tune.h Section B

0.002f

Starting injection voltage magnitude (per-unit of Vdc). Intentionally small — the algorithm ramps up automatically. No need to change in most cases.

TI_TUNE_LDQ_IS_MAGN_MIN_LIM

ti_tune.h Section B

0.02f

Minimum acceptable current response (per-unit of rated current). For large motors with high inductance, consider reducing if the algorithm fails to find a suitable voltage.

TI_TUNE_LDQ_IS_MAGN_MAX_LIM

ti_tune.h Section B

0.5f

Maximum acceptable current response (per-unit of rated current). For small motors with low rated current, consider reducing to prevent overcurrent.

TI_TUNE_LDQ_INJ_VOL_MAGN_MAX_LIM

ti_tune.h Section B

0.98f

Hard ceiling on injection voltage (per-unit of Vdc). Do not increase above 1.0. If this limit is reached and current response is still insufficient, the algorithm automatically reduces the injection frequency instead.

Automatic Voltage Adjustment

The algorithm keeps the current response within the IS_MAGN_MIN_LIM / IS_MAGN_MAX_LIM window by adjusting the injection voltage automatically:

  • If the motor draws too little current → injection voltage is doubled until TI_TUNE_LDQ_INJ_VOL_MAGN_MAX_LIM is reached.

  • If the motor draws too much current → injection voltage is halved.

Watch Window — LDQ Estimation

Expression

Description

TiTune_M1.TiTune_LDQ.InjVolMagn

Current injection voltage magnitude (per-unit of Vdc)

TiTune_M1.TiTune_LDQ.InjVolFreq

Current injection frequency (per-unit)

TiTune_M1.TiTune_LDQ.IsMagn

Current response magnitude (per-unit of rated current)

TiTune_M1.TiTune_LDQ.ElecTheta

Current scan angle (0 to 0.5 per-unit = 0° to 180°)

TiTune_M1.TiTune_LDQ.LminApprox

Running minimum inductance (per-unit)

TiTune_M1.TiTune_LDQ.LmaxApprox

Running maximum inductance (per-unit)

TiTune_M1.TiTune_LDQ.Finish

Set to 1.0 when scan is complete

TiTune_M1.TiTune_LDQ.VoltageNotFound

Set to 1.0 if algorithm failed to find suitable voltage (error condition)

Results from LDQ Estimation

Expression

Description

TiTune_M1.TiTune_LDQ.ld_Final

Identified Ld in Henries

TiTune_M1.TiTune_LDQ.lq_Final

Identified Lq in Henries

TiTune_M1.TiTune_LDQ.InitialRotorAngle

Detected initial rotor angle (per-unit, 0→1 = 0°→360°)

These values are automatically used by subsequent TiTune phases: the Rs estimation phase uses the initial rotor angle, and the current controller gain computation uses Ld and Lq.

Troubleshooting LDQ Estimation
  • If VoltageNotFound = 1.0 after the scan: the motor inductance is too high for the current frequency range. Increase TI_TUNE_LDQ_INJ_HALF_PRD_MAX to allow lower injection frequencies.

  • If the scan completes but ld_Final and lq_Final are nearly identical: this is expected for surface-mount PMSM (non-salient). The algorithm still correctly identifies Ld = Lq.

TiTune_STATE_RS_EST — Resistance Estimation

The motor is at standstill. Before Rs estimation begins, TiTune sets up closed-loop current control using the Ld and Lq values identified in the LDQ phase. The current loop bandwidth is set by TI_TUNE_TORQUE_LOOP_BW_RADPS. TiTune then injects DC current at the rotor angle detected by the LDQ phase. Two distinct DC current levels are applied sequentially. The differential voltage and current measurements between the two levels cancel the inverter dead-time voltage offset, yielding an accurate stator resistance that includes cable and switch resistances. A voltage distortion compensation gain (Vdist) is also computed for use by the observer.

Current Loop Setup for Rs Estimation

Before the Rs measurement begins, TiTune computes the current PI gains from the Ld and Lq values identified in the LDQ phase and the configured current loop bandwidth TI_TUNE_TORQUE_LOOP_BW_RADPS:

  • D-axis: Kp = Ld × BW, Ki uses a bandwidth-squared design

  • Q-axis: Kp = Lq × BW, Ki uses a bandwidth-squared design

After Rs is measured, Ki is automatically updated to a pole-zero cancellation design using the measured Rs before the open-loop ramp phase begins. The user does not need to take any action for this update.

Set TI_TUNE_TORQUE_LOOP_BW_RADPS to match the motor’s electrical bandwidth. For motors with low inductance (high electrical bandwidth), increase the value. For motors with high inductance, reduce it. Typical range is 200–2000 rad/s.

Parameter

Location

Default

Description / Tuning Guidance

TI_TUNE_TORQUE_LOOP_BW_RADPS

ti_tune.h Section B

MATH_TWO_PI * 200.0f (≈ 1257 rad/s, 200 Hz)

Current loop bandwidth in rad/s used to compute PI gains from Ld/Lq. Increase for low-inductance motors; decrease for high-inductance motors. Typical range: 200–2000 rad/s.

Rs Estimation Parameters

The parameters below are set in TiTune_Rs_setParams() in ti_tune.c. The user-tunable values are defined in Section B of ti_tune.h.

Parameter

Location

Default

Description / Tuning Guidance

TI_TUNE_RS_TEST_CURRENT1_FRACTION

ti_tune.h Section B

0.4f

First DC test current as a fraction of rated current. Increase for motors with very low resistance where the voltage drop at 40% rated current is too small to measure accurately.

TI_TUNE_RS_TEST_CURRENT2_FRACTION

ti_tune.h Section B

0.5f

Second DC test current as a fraction of rated current. Keep the ratio between current 1 and current 2 approximately 1.25× for best differential accuracy.

Watch Window — Rs Estimation

Expression

Description

TiTune_M1.TiTune_Rs.Mode

Current test mode: 1.0 = first current level, 2.0 = second current level

TiTune_M1.TiTune_Rs.IdRef

D-axis current reference being applied (per-unit of rated current)

TiTune_M1.TiTune_Rs.IdFbk

D-axis current feedback (per-unit of rated current)

TiTune_M1.TiTune_Rs.AveragerEnable

1.0 when current has settled and averaging is active

TiTune_M1.TiTune_Rs.TimeOutError

1.0 if current failed to settle within the maximum settle time

TiTune_M1.TiTune_Rs.Finish

1.0 when Rs estimation is complete

TiTune_M1.TiTune_PI_Id.Kp

D-axis current loop Kp (set from Ld × BW)

TiTune_M1.TiTune_PI_Id.Ki

D-axis current loop Ki

TiTune_M1.TiTune_PI_Iq.Kp

Q-axis current loop Kp (set from Lq × BW)

TiTune_M1.TiTune_PI_Iq.Ki

Q-axis current loop Ki

Results from Rs Estimation

Expression

Description

TiTune_M1.TiTune_Rs.Rs_Final

Identified stator resistance in Ohms

TiTune_M1.TiTune_Rs.Vdist

Identified voltage distortion compensation gain (per-unit)

Note

After Rs estimation completes, TiTune automatically updates Ki to a pole-zero cancellation design using the measured Rs before the open-loop ramp begins. No user action is required. If the motor oscillates during the open-loop ramp, check TiTune_M1.TiTune_PI_Id.Ki and TiTune_M1.TiTune_PI_Iq.Ki to verify the gains are reasonable.

Troubleshooting Rs Estimation
  • If TiTune_M1.TiTune_Rs.TimeOutError = 1.0: the current loop could not settle within the maximum allowed time. The estimation continues with the best available data. To prevent the timeout, verify that the current PI gains are reasonable (check that LDQ estimation completed successfully) or reduce the test current fractions.

  • If Rs_Final appears too high or too low: verify that TiTune_M1.RatedCurrent_A matches the motor nameplate rated current. An incorrect base value shifts all per-unit calculations.

  • If the two test current levels are too close together, the differential measurement becomes noisy. Ensure TI_TUNE_RS_TEST_CURRENT2_FRACTION is at least 1.1× larger than TI_TUNE_RS_TEST_CURRENT1_FRACTION.

TiTune_STATE_OL_RUN — Open-Loop Ramp

The motor shaft begins to rotate in this phase. TiTune drives the motor in open-loop forced-angle mode, ramping the electrical frequency from zero to a target speed. The observer (FAST or ESMO) runs in parallel and acquires lock as the speed builds. Once the target speed is reached, TiTune blends the open-loop angle toward the observer angle and holds at the target speed for a configurable settle time before handing control to the observer.

Warning

The motor shaft rotates during this phase. Ensure the shaft is free to spin and the load is safe to move before starting identification.

Open-Loop Ramp Parameters

The parameters below are defined in Section B of ti_tune.h.

Parameter

Location

Default

Description / Tuning Guidance

TI_TUNE_OL_SPEED_TARGET_FRACTION

ti_tune.h Section B

0.2f

Open-loop target speed as a fraction of rated electrical speed. Must be above the minimum observer lock speed. Increase to 0.4–0.5 if the observer fails to lock reliably at the default 20%.

TI_TUNE_OL_CURRENT_FRACTION

ti_tune.h Section B

0.2f

Open-loop Iq current as a fraction of rated current. Increase for high-friction or high-inertia loads that require more torque to accelerate. Reduce if the motor oscillates during the ramp.

TI_TUNE_OL_ID_FRACTION

ti_tune.h Section B

0.05f

Open-loop d-axis current injection as a fraction of rated current. A small Id injection during OL startup improves angle convergence stability at low angle error.

TI_TUNE_OL_SETTLE_TIME_SEC

ti_tune.h Section B

4.0f

Time (seconds) to hold at the open-loop target speed before handing off to the observer. Increase if the observer needs more time to stabilize before the closed-loop transition.

Watch Window — Open-Loop Ramp

Expression

Description

TiTune_M1.OL.Speed_Hz

Current open-loop speed reference (Hz, electrical)

TiTune_M1.OL.SpeedTarget_Hz

Target open-loop speed (Hz, electrical)

TiTune_M1.OL.Current_A

Open-loop Iq current command (A)

TiTune_M1.OL.angleDelta_rad

Angle difference between open-loop and observer angles (rad) — approaches zero as blending completes

TiTune_M1.OL.count

Settle counter — counts up to the settle target after reaching target speed

TiTune_M1.Config.Speed_Hz

Observer estimated electrical speed (Hz) — should track OL.Speed_Hz

Troubleshooting Open-Loop Ramp
  • If the motor stalls or fails to accelerate: increase TI_TUNE_OL_CURRENT_FRACTION to provide more torque. For high-inertia loads, also consider reducing the speed ramp rate (Section C parameter TI_TUNE_OL_SPEED_RAMP_HZ_PER_SEC).

  • If the observer does not lock (speed estimate diverges from OL.Speed_Hz): increase TI_TUNE_OL_SPEED_TARGET_FRACTION so the observer has a higher speed to work with, or increase TI_TUNE_OL_SETTLE_TIME_SEC to give the observer more time to converge.

  • If the motor oscillates during the ramp: reduce TI_TUNE_OL_CURRENT_FRACTION. Excessive current on a lightly loaded motor can cause instability.

TiTune_STATE_CL_TORQUE_SETTLE — Closed-Loop Torque Settle

In this state the motor enters closed-loop torque control. TiTune switches the Park/iPark transforms to use the observer angle. The Iq reference is held constant at the value inherited from the open-loop handoff. The Id reference is ramped from the open-loop injection level down to zero over TI_TUNE_CL_ID_RAMP_TIME_SEC. This phase waits for the Id ramp to complete before entering inertia estimation.

Closed-Loop Torque Settle Parameters

The parameters below are defined in Section B of ti_tune.h.

Parameter

Location

Default

Description / Tuning Guidance

TI_TUNE_CL_ID_RAMP_TIME_SEC

ti_tune.h Section B

5.0f

Time (seconds) to ramp Id from the open-loop injection level to zero after the OL-to-CL handoff. Increase if the motor oscillates during the Id ramp-down.

Watch Window — Closed-Loop Torque Settle

Expression

Description

TiTune_M1.CL.IqRef_A

Iq reference held constant at OL handoff value (A)

TiTune_M1.CL.IdRef_A

Id reference ramping from OL injection level to zero (A)

TiTune_M1.CL.SettleCount

Elapsed settle time counter (samples)

TiTune_M1.CL.SettleTarget

Required settle time in samples (derived from TI_TUNE_CL_ID_RAMP_TIME_SEC)

TiTune_M1.Config.Speed_Hz

Observer estimated electrical speed (Hz) — should stabilize during this phase

TiTune_M1.Status.Idq_A.value[1]

Measured Iq feedback (A) — should track CL.IqRef_A

Troubleshooting Closed-Loop Torque Settle
  • If the motor oscillates during the Id ramp-down: increase TI_TUNE_CL_ID_RAMP_TIME_SEC to slow the ramp. Also verify that the current PI gains are reasonable (check that LDQ and Rs estimation completed without errors).

  • If the motor decelerates to a stop during this phase: the Iq inherited from OL handoff may be too low. Increase TI_TUNE_OL_CURRENT_FRACTION so the OL phase runs at a higher current.

  • If the motor accelerates beyond a safe speed: reduce TI_TUNE_OL_CURRENT_FRACTION.

TiTune_STATE_INERTIA_EST — Inertia and Damping Estimation

TiTune estimates rotor inertia (J) and damping (B) using a two-phase process:

  1. Upward current ramp with torque-speed capture: The algorithm ramps Iq upward from the CL handoff level toward a target speed (TI_TUNE_J_COAST_TARGET_SPEED_FRACTION). The speed range is divided into TI_TUNE_J_COAST_NUM_STEPS equal steps. At each step it waits for the speed to settle, then records the torque-speed operating point. A linear regression over the collected points estimates the DC plant gain (G_DC).

  2. Coast-down (freewheel): After the ramp, Iq is set to zero and the speed decay is recorded. An exponential fit of the speed decay yields the mechanical time constant (tau_estimated). Combined with G_DC and the identified Ke, the algorithm computes the speed PI gains Kp_spd and Ki_spd.

Inertia Estimation Parameters

The parameters below are set in TiTune_J_Coast_setParams() in ti_tune.c. The user-tunable values are defined in Section B of ti_tune.h.

Parameter

Location

Default

Description / Tuning Guidance

TI_TUNE_J_COAST_SETTLING_TIME_SEC

ti_tune.h Section B

5.0f

Settling time per speed-step test point (seconds). The motor is held at each speed step for this duration before recording data. Increase for high-inertia loads (fans, pumps) that take longer to reach steady state.

TI_TUNE_J_COAST_CROSSOVER_FREQ_FACTOR

ti_tune.h Section B

0.2f

Speed loop crossover frequency as a fraction of the estimated plant pole frequency. Increase for faster speed loop response; decrease for more conservative (stable) tuning.

TI_TUNE_J_COAST_COASTDOWN_STOP_FRACTION

ti_tune.h Section B

0.2f

Coast-down stop threshold as a fraction of the initial coast-down speed. The coast-down recording stops when speed falls below this fraction. Reduce for high-damping systems where speed decays slowly.

TI_TUNE_J_COAST_IQ_FILTER_CUTOFF_HZ

ti_tune.h Section B

10.0f

IIR low-pass filter cutoff frequency for Iq and Vq signals during speed-step settling (Hz). Reduce for noisy current measurements.

TI_TUNE_J_COAST_SPD_FILTER_CUTOFF_HZ

ti_tune.h Section B

2.0f

IIR low-pass filter cutoff frequency for speed signal during speed-step settling (Hz). Reduce for noisy speed feedback.

Watch Window — Inertia Estimation

Expression

Description

TiTune_M1.TiTune_J_Coast.state

Current sub-state of the inertia estimation state machine

TiTune_M1.TiTune_J_Coast.numSteadyStatePoints

Number of valid torque-speed data points collected so far

TiTune_M1.TiTune_J_Coast.speedFiltered_pu

IIR-filtered speed feedback during speed-step settling (per-unit)

TiTune_M1.TiTune_J_Coast.iqFiltered_pu

IIR-filtered Iq reference during speed-step settling (per-unit)

TiTune_M1.TiTune_J_Coast.G_DC

Estimated DC plant gain delta-we/delta-Iq (rad/s per A) — available after ramp

TiTune_M1.TiTune_J_Coast.tau_estimated

Estimated mechanical time constant from coast-down (seconds)

TiTune_M1.TiTune_J_Coast.lambda_PM

Estimated back-EMF constant lambda_PM (V*s/rad) — diagnostic cross-check against Ke

TiTune_M1.TiTune_J_Coast.finish

true when inertia estimation is complete

TiTune_M1.TiTune_J_Coast.error

true if estimation encountered an error

Results from Inertia Estimation

Expression

Description

TiTune_M1.Results.J_Kgm2

Identified rotor inertia (kg*m^2)

TiTune_M1.Results.Ke_VpHz

Identified back-EMF constant (V/Hz)

TiTune_M1.Results.Spd_Kp

Computed speed loop proportional gain

TiTune_M1.Results.Spd_Ki

Computed speed loop integral gain

Troubleshooting Inertia Estimation
  • If TiTune_M1.TiTune_J_Coast.error = true: the estimation failed. Common causes are that the motor speed does not change when current changes (motor stalled or load too heavy), or that the coast-down speed decays too quickly to collect enough samples. Check that the motor is spinning freely and that TI_TUNE_OL_CURRENT_FRACTION is high enough to keep the motor running into the inertia phase.

  • If numSteadyStatePoints stays at zero: the speed is not reaching the first step threshold. Increase TI_TUNE_OL_CURRENT_FRACTION so the motor enters the inertia phase at a higher speed, or reduce TI_TUNE_J_COAST_NUM_STEPS for fewer, larger speed steps.

  • If the speed loop is too aggressive after applying the computed gains: reduce TI_TUNE_J_COAST_CROSSOVER_FREQ_FACTOR (for example, from 0.2 to 0.1) to lower the crossover frequency and increase phase margin.

  • If the speed loop is too slow: increase TI_TUNE_J_COAST_CROSSOVER_FREQ_FACTOR (for example, from 0.2 to 0.4).

  • For noisy systems where G_DC or tau_estimated appear unreliable: increase TI_TUNE_J_COAST_SETTLING_TIME_SEC and reduce the filter cutoff frequencies TI_TUNE_J_COAST_IQ_FILTER_CUTOFF_HZ and TI_TUNE_J_COAST_SPD_FILTER_CUTOFF_HZ.

TiTune_STATE_DONE — Identification Complete

All parameters have been identified. Results are available in TiTune_M1.Results. motorVars_M1.statusVars.flagMotorIdentified is set to true.

Key Tuning Parameters (Section B of ti_tune.h)

The following parameters are in Section B of ti_tune.h and are intended for user adjustment. Do not modify Section C parameters.

Parameter

Default

Description

TI_TUNE_TORQUE_LOOP_BW_RADPS

MATH_TWO_PI * 200.0f

Current loop bandwidth (rad/s) — increase for low-inductance motors

TI_TUNE_RS_TEST_CURRENT1_FRACTION

0.4f

Rs test current 1 (fraction of rated)

TI_TUNE_RS_TEST_CURRENT2_FRACTION

0.5f

Rs test current 2 (fraction of rated)

TI_TUNE_OL_SPEED_TARGET_FRACTION

0.2f

Open-loop target speed (fraction of rated)

TI_TUNE_OL_CURRENT_FRACTION

0.2f

Open-loop Iq current (fraction of rated)

TI_TUNE_OL_ID_FRACTION

0.05f

Open-loop d-axis current injection (fraction of rated)

TI_TUNE_OL_SETTLE_TIME_SEC

4.0f

Open-loop settle time before observer handoff (s)

TI_TUNE_CL_ID_RAMP_TIME_SEC

5.0f

CL Id ramp-down time from OL injection level to zero (s)

TI_TUNE_J_COAST_SETTLING_TIME_SEC

5.0f

Settling time per speed-step test point (s)

TI_TUNE_J_COAST_CROSSOVER_FREQ_FACTOR

0.2f

Speed loop crossover frequency factor (fraction of plant pole)

Watch Window — Monitoring Identification

Expression

Description

motorVars_M1.inputCtrl.flagEnableMotorIdentify

Set true to start identification

motorVars_M1.inputCtrl.motorParamIdentifyMethod

Set to MOTOR_PARAM_IDENTIFY_TITUNE

TiTune_M1.Status.state

Current identification phase (see state list above)

TiTune_M1.RatedCurrent_A

Per-unit current base — verify matches motor nameplate

TiTune_M1.RatedSpeed_Hz

Per-unit speed base — verify matches motor nameplate

motorVars_M1.statusVars.flagMotorIdentified

Goes true when identification is complete

Results — Where to Find Identified Parameters

After TiTune completes, the identified values are in TiTune_M1.Results:

Expression

Description

TiTune_M1.Results.Rs_Ohm

Identified stator resistance (Ω)

TiTune_M1.Results.Ld_H

Identified d-axis inductance (H)

TiTune_M1.Results.Lq_H

Identified q-axis inductance (H)

TiTune_M1.Results.Ke_VpHz

Identified back-EMF constant (V/Hz)

TiTune_M1.Results.J_Kgm2

Identified rotor inertia (kg·m²)

TiTune_M1.Results.Id_Kp

Computed d-axis current loop Kp

TiTune_M1.Results.Id_Ki

Computed d-axis current loop Ki

TiTune_M1.Results.Iq_Kp

Computed q-axis current loop Kp

TiTune_M1.Results.Iq_Ki

Computed q-axis current loop Ki

TiTune_M1.Results.Spd_Kp

Computed speed loop Kp

TiTune_M1.Results.Spd_Ki

Computed speed loop Ki

Copy these values into the macro block in motor_params.h to make them permanent. See Applying Results to motor_params.h.


Applying Results to motor_params.h

After a successful identification run (InstaSPIN or TiTune), copy the identified values back into the motor macro block in motor_params.h:

  1. Read the identified values from the watch window (see Results sections above).

  2. Update the corresponding macros in the MOTOR_MY_MOTOR_* block:

    #define MOTOR_MY_MOTOR_Rs_Ohm          (0.342f)   /* from motorSetVars_M1.Rs_Ohm or TiTune_M1.Results.Rs_Ohm */
    #define MOTOR_MY_MOTOR_Ls_d_H          (0.000178f) /* from motorSetVars_M1.Ls_d_H or TiTune_M1.Results.Ld_H */
    #define MOTOR_MY_MOTOR_Ls_q_H          (0.000208f) /* from motorSetVars_M1.Ls_q_H or TiTune_M1.Results.Lq_H */
    #define MOTOR_MY_MOTOR_RATED_FLUX_VpHz (0.0412f)  /* from motorSetVars_M1.flux_VpHz or TiTune_M1.Results.Ke_VpHz */
    #define MOTOR_MY_MOTOR_INERTIA_Kgm2    (0.0000095f) /* from TiTune_M1.Results.J_Kgm2 (TiTune only) */
    
  3. Rebuild and flash the firmware. The motor will now use the identified parameters on every power-up without requiring re-identification.

Note

After updating motor_params.h, you can disable identification on the next run by leaving motorVars_M1.inputCtrl.flagEnableMotorIdentify at its default false value. The stored parameters will be used directly.


Real-Time Diagnostics — DAC Output and Serial Plot

The AM13E230X includes a CMPSSLITE DAC that can be used to output any floating-point motor variable as an analogue voltage on a physical pin, viewable on an oscilloscope (CRO). The same variable pointers are also used by the Serial Plot feature, which streams two float values over the back-channel UART to a PC serial plotter.

Both features share the same RAM_DAC_CNTRL_T control structures inside SYSTEM_Vars_t and are configured once in initDACOutputs() called from main.c before the ISR starts.


DAC Output — Plotting Variables on an Oscilloscope

How It Works

HAL_updateDACOutputs() reads the variable pointed to by systemVars.dacCtrl1.pDacOutAddr, scales it to a 12-bit integer (0–4095), and writes it to the CMPSSLITE DAC low register via DL_CMPSSLITE_setDACValueLow(). The DAC output appears on the CMPSSLITE output pin and can be probed with an oscilloscope.

The scaling formula depends on the mode field:

mode

Formula

Use case

0 (bipolar)

(value × scalingFactor) + 2048

Signed signals centred at mid-rail (angle, current)

1 (unipolar)

value × scalingFactor

Unsigned signals (speed magnitude, DC bus)

DAC_MAX_VALUE is defined as 4095 in hal_obj.h.

Configuration in initDACOutputs()

Edit motor_common.c inside initDACOutputs() to select which variables to plot:

/* motor_common.c — initDACOutputs() */

/* Enable DAC channel 1 */
sysVarsPtr->dacCtrl1.dacEn = 1U;

/* Example A: Plot FOC angle (bipolar, 0–2π → 0–4095) */
sysVarsPtr->dacCtrl1.pDacOutAddr      = (float32_t *)&obj->outVars.angleFOC_rad;
sysVarsPtr->dacCtrl1.dacScalingFactor = (DAC_MAX_VALUE / MATH_TWO_PI);
sysVarsPtr->dacCtrl1.mode             = 0;   /* bipolar */

/* Example B: Plot phase-A current (bipolar, ±maxCurrent → 0–4095) */
/* sysVarsPtr->dacCtrl1.pDacOutAddr =
 *     (float32_t *)&obj->halInterface->halFOCDataHandle->adcData.I_A.value[0];
 * sysVarsPtr->dacCtrl1.dacScalingFactor = (DAC_MAX_VALUE / objUser->maxCurrent_A);
 * sysVarsPtr->dacCtrl1.mode = 0; */
../../../../_images/DAC_PLOT_ANGLE_CRO.png

DAC output of angleFOC_rad viewed on an oscilloscope — sawtooth waveform at motor electrical frequency.

../../../../_images/DAC_PLOT_PHASE_CURRENT.png

DAC output of phase-A current viewed on an oscilloscope — sinusoidal waveform at motor electrical frequency.

Common Variable Addresses for DAC

Signal

Pointer expression

Scaling

FOC angle

&obj->outVars.angleFOC_rad

DAC_MAX_VALUE / MATH_TWO_PI

Phase-A current

&obj->halInterface->halFOCDataHandle->adcData.I_A.value[0]

DAC_MAX_VALUE / maxCurrent_A

Phase-B current

&obj->halInterface->halFOCDataHandle->adcData.I_A.value[1]

DAC_MAX_VALUE / maxCurrent_A

Speed (Hz)

&obj->outVars.speed_Hz

DAC_MAX_VALUE / maxSpeed_Hz

Iq reference

&obj->outVars.IdqRef_A.value[1]

DAC_MAX_VALUE / maxCurrent_A

ESMO Ealpha

&obj->esmoHandle->Ealpha

DAC_MAX_VALUE / dcBus_nominal_V

Where HAL_updateDACOutputs() Is Called

HAL_updateDACOutputs() is called from runMotorDataLogging() in motor_common.c. To activate it, uncomment the runMotorDataLogging() call in application_run():

/* application.c — application_run() */

/* Section 5: DATA LOGGING — uncomment to enable DAC + serial plot */
runMotorDataLogging();

Note

runMotorDataLogging() executes inside the FOC ISR. For best ISR performance, consider moving it to the low-priority background loop by calling it from FOC_runLowPriorityStateMachine() instead.


Serial Plot — Streaming Variables to a PC

The Serial Plot feature streams two float variables over UART to a PC serial plotter (e.g. the Arduino Serial Plotter, or any tool that accepts the same framing).

Back-Channel UART — Hardware

The AM13E230X LaunchPad routes UC1 / PA0 to the XDS110 back-channel UART, which appears as a virtual COM port on the PC when the LaunchPad USB cable is connected. No additional hardware is required.

SysConfig name

Peripheral

Pin

Baud rate

SERIAL_DATA_PLOT

UC1

PA0 (TX only)

7 812 500

The UART is already configured in the reference .syscfg files (3sh_sen_less_foc_drv8323rh.syscfg, 1sh_sen_less_foc_drv8329a.syscfg).

Packet Format

HAL_updateSerialPlot() sends a 10-byte packet over SERIAL_DATA_PLOT_INST (the generated macro for UC1):

Byte

Content

0

0xAA (header byte 1)

1

0x55 (header byte 2)

2–5

data1 — float32 little-endian (from dacCtrl1.pDacOutAddr)

6–9

data2 — float32 little-endian (from dacCtrl2.pDacOutAddr)

The same pDacOutAddr pointers configured for the DAC are reused for the serial plot, so both outputs always show the same two variables.

Configuring the Serial Plotter

Open a serial terminal or plotter on the XDS110 back-channel COM port at the baud rate configured for SERIAL_DATA_PLOT in the .syscfg file (see the table above). Configure the tool to expect the 0xAA 0x55 header followed by two 4-byte little-endian floats.

../../../../_images/SERIAL_PLOT_CONFIG.png

Serial plotter configuration — set the baud rate to match the .syscfg and header bytes to 0xAA 0x55.

../../../../_images/SERIAL_PLOT_ANGLE.png

Serial plotter showing angleFOC_rad (channel 1) and speed_Hz (channel 2) during motor run.

Enabling Serial Plot

HAL_updateSerialPlot() is called from runMotorDataLogging() alongside HAL_updateDACOutputs(). Uncomment runMotorDataLogging() in application_run() as described in the DAC section above.

To change which variables are plotted, update pDacOutAddr in initDACOutputs():

/* Plot angle on channel 1, speed on channel 2 */
sysVarsPtr->dacCtrl1.pDacOutAddr = (float32_t *)&obj->outVars.angleFOC_rad;
sysVarsPtr->dacCtrl2.pDacOutAddr = (float32_t *)&obj->outVars.speed_Hz;
sysVarsPtr->dacCtrl2.dacEn       = 1U;

Back-Channel UART — Using It for Custom Communication

The same UC1 / PA0 UART can be used for any custom serial communication from the background loop. The SCI_writeBytesNonBlocking() helper writes bytes to the UART TX FIFO without blocking the caller:

/* Custom background task — send a status byte over back-channel UART */
static void myCustomUARTTask(void)
{
    uint8_t  txBuf[6];
    uint16_t idx = 0;

    /* Pack speed as a 4-byte float */
    float32_t speed = motorVars_M1.outVars.speed_Hz;
    memcpy(&txBuf[0], &speed, sizeof(float32_t));
    txBuf[4] = (uint8_t)motorVars_M1.outVars.motorState;
    txBuf[5] = '\n';

    SCI_writeBytesNonBlocking(SERIAL_DATA_PLOT_INST, txBuf, &idx, 6U);
}

Call this from the 1 ms background loop in main.c:

while (systemVars.flagEnableSystem == true)
{
    if (systemVars.timerCntFOCCtrlISR > LOW_PRIORITY_WAIT_TIME_1ms)
    {
        systemVars.timerCntFOCCtrlISR = 0;
        FOC_runLowPriorityStateMachine(&motorVars_M1);
        myCustomUARTTask();   /* custom serial output */
    }
}

Warning

Do not call SCI_writeBytesNonBlocking() from inside the FOC ISR (ADC0_INT1_IRQHandler) or application_run(). UART FIFO writes from the ISR add latency to the FOC loop and can cause ISR overruns at high PWM frequencies. Always place UART communication in the low-priority background loop.