Motor Control — Frequently Asked Questions
This page is a navigation guide for engineers new to the AM13E230X motor control solution. Each question links directly to the relevant section of the documentation.
Getting Started
Which example should I start with?
Start with the example that matches your current sensing topology:
3-shunt (per-phase current sensing, DRV8323RH gate driver) → 3-Shunt FOC README
1-shunt (DC-link current sensing, DRV8329A gate driver) → 1-Shunt FOC README
What files do I actually need to edit to get the motor spinning?
Only three files need changes for a first bring-up on the reference hardware:
user_mtr1.h— set PWM frequency, current/voltage scale factors, and over-current limit to match your board schematicmotor_params.c— add your motor’s nameplate data (Rs, Ld, Lq, flux, pole pairs)The
.syscfgfile — reassign ADC, PWM, and GPIO pins if your board differs from the reference EVM
See the full Migration Checklist for a step-by-step list.
What hardware is required to run the reference examples?
See the Hardware Requirements section in each example README:
What is SysConfig and why does the motor control solution use it?
SysConfig is a graphical peripheral configuration tool. The motor control solution uses
it to configure all hardware peripherals (ADC, MCPWM, CMPSS, GPIO, UART) and
auto-generate ti_sdk_dl_config.h / ti_sdk_dl_config.c. This means pin assignments
and peripheral settings can be changed without editing C source code.
See SysConfig Integration for details on what SysConfig configures and how the generated macros are used in the HAL.
How are the peripherals configured in SysConfig for the motor control application?
SysConfig configures all hardware peripherals (MCPWM, ADC, CMPSS, crossbar, GPIO, UART)
and auto-generates ti_sdk_dl_config.h / ti_sdk_dl_config.c.
The peripheral configuration differs between the 1-shunt and 3-shunt topologies:
Peripheral |
3-Shunt (DRV8323RH) |
1-Shunt (DRV8329A) |
|---|---|---|
MCPWM |
MCPWM4 only — three-phase centre-aligned PWM |
MCPWM4 (motor PWM) + MCPWM0 (ADC trigger timing) |
ADC |
ADC0, ADC1, ADC2 — one per phase current + phase/DC voltages |
ADC0 only — DC-link current + phase/DC voltages; four triggers per cycle for current reconstruction |
CMPSS |
CMPSS0/1/2 — per-phase hardware OC trip |
CMPSS0 — single DC-link OC trip |
Crossbar |
INPUTXBAR, PWMXBAR, OUTPUTXBAR for fault routing |
Same crossbar structure |
UART |
|
Same |
For the complete pin mapping, ADC SOC sequencing, CMPSS DAC thresholds, crossbar routing, and software handle assignments, see the dedicated peripheral configuration pages:
Understanding the Software Architecture
What is the overall file structure of the motor control solution?
See File Structure and Software Layers. The key directories are:
Directory |
Contents |
|---|---|
|
Example entry point: |
|
FOC algorithm, state machines, data structures |
|
Hardware abstraction: FOC interface, gate driver interface |
|
Board constants ( |
|
Motor parameter tables ( |
How does the FOC algorithm execute? What calls what?
The FOC runs inside the ADC ISR, triggered every PWM cycle:
MCPWM → ADC SOC trigger → ADC0_INT1_IRQHandler (isr.c)
└─ application_run()
├─ FOC_runFeedback() — read ADC, compute currents/voltages
├─ FOC_runObservers() — FAST or ESMO angle/speed estimation
├─ FOC_runStateMachine() — state transitions
├─ FOC_runFeedforward() — Park transform, SVPWM output
└─ data logging
See Execution Architecture for the full diagram including the background loop.
How fast does the ISR run? Can I change the ISR frequency?
The ISR runs at the same frequency as the PWM switching frequency. The default is
15 kHz (66 µs per tick). It can be scaled up to 100 kHz by changing
USER_M1_PWM_FREQ_kHz in
user_mtr1.h and matching the MCPWM
period in SysConfig.
See Execution Architecture for the PWM→ADC trigger chain explanation.
What are the motor control state machines and how do they interact?
There are three state machines:
State Machine |
Runs In |
Frequency |
Purpose |
|---|---|---|---|
High-priority SM |
ADC ISR |
Every PWM cycle |
FOC angle/current control, state transitions |
Low-priority SM |
Background loop |
~1 ms |
Fault checking, trajectory, monitoring |
TiTune SM |
ADC ISR (during IDENT) |
Every PWM cycle |
Automated motor parameter identification |
See State Machines for diagrams of all three.
What happens during startup before the motor runs?
Two calibration phases must complete before the motor can be commanded:
Comparator DAC offset calibration — blocking, runs before ISR starts, calibrates CMPSS hardware over-current trip points
ADC IIR offset calibration — ISR-driven, runs with PWM active at 0% duty, calibrates ADC current/voltage channel offsets
See Startup and Calibration Sequence for the full sequence diagram and explanation of why two phases are needed.
What motor states exist and what do they mean?
See High-Priority State Machine for the full state diagram. Key states:
State |
Meaning |
|---|---|
|
Motor stopped, waiting for command |
|
ADC calibration running |
|
Rotor forced to known angle |
|
Open-loop speed ramp |
|
Closed-loop FOC active |
|
Fault active, PWM disabled |
What data structures control the motor at runtime?
See Motor Data Structures. The key structures are:
Structure |
Purpose |
|---|---|
|
Runtime setpoints — speed reference, current limits, enable flags |
|
User commands — start/stop, mode selection |
|
FOC outputs — Id, Iq, Vd, Vq, angle, speed |
|
Internal status — observer state, PI integrators |
|
Master object — contains all of the above |
|
Motor nameplate — Rs, Ld, Lq, flux, pole pairs |
What is HAL_FOC_Data_Obj and what does it carry at the hardware/FOC boundary?
HAL_FOC_Data_Obj
is the mutable runtime data object that sits at the boundary between the hardware abstraction
layer (HAL) and the FOC algorithm. It is updated every PWM cycle inside the ADC ISR and
carries all the live data the FOC algorithm needs to read from hardware and write back to it.
Field |
Type |
Direction |
Purpose |
|---|---|---|---|
|
|
HAL → FOC |
Phase currents ( |
|
|
FOC → HAL |
Duty-cycle commands ( |
|
|
HAL → FOC (read-only) |
Gate driver scaling constants and fault thresholds; FOC reads these to scale currents and voltages correctly |
|
|
HAL → FOC |
Comparator DAC trip-point offsets for hardware over-current protection |
ADC data and offset calibration:
adcData.offset_I_ad[] holds the IIR-filtered ADC zero-current offset for each phase.
These are computed during the MOTOR_OFFSET_CALIB state and must be near mid-scale
(≈ 2048 for 3-shunt, ≈ 511 for 1-shunt) before the motor can run.
PWM data flow:
The FOC algorithm writes normalised duty cycles to pwmData.Vabc_pu[]. The HAL converts
these to compare register values (cmpValue[]) and writes them to the MCPWM hardware.
flagEnablePwm gates the output — the HAL only updates the compare registers when this
flag is set.
Gate driver fault communication:
gdDataHandle points to the gate driver’s read-only data object. The FOC layer reads
gdDataHandle->overCurrentFaultThreshold_A and the voltage scaling constants from this
handle. The gate driver ISR sets fault bits in the same object, which the low-priority
state machine polls to trigger MOTOR_FAULT_STOP.
See HAL FOC Data Object for the complete field reference, sub-structure descriptions, and data-flow diagrams.
How do I command the motor to start/stop and set speed?
Use the MOTOR_InputCtrl_t fields in the watch window or via your application code:
/* Set speed reference and direction */
motorVars_M1.inputCtrl.speedRef_Hz = 50.0f;
motorVars_M1.inputCtrl.direction = 1.0f;
/* Select estimator (FAST or ESMO) */
motorVars_M1.inputCtrl.estimatorMode = ESTIMATOR_MODE_ESMO;
/* Enable run */
motorVars_M1.inputCtrl.flagEnableRunAndIdentify = true;
To stop the motor, clear flagEnableRunAndIdentify:
motorVars_M1.inputCtrl.flagEnableRunAndIdentify = false;
See MOTOR_InputCtrl_t — User Commands for all available fields.
Motor Parameter Identification
How do I identify my motor’s Rs, Ld, Lq, and flux linkage parameters?
Use TiTune — the automated parameter identification tool built into the solution.
Set motorParamIdentifyMethod = MOTOR_PARAM_IDENTIFY_TITUNE and enable
flagEnableRunAndIdentify. TiTune runs a sequence of HF injection, DC injection,
open-loop ramp, and closed-loop flux estimation to identify all parameters automatically.
See TiTune State Machine for the identification sequence and Motor Parameter Tuning for step-by-step instructions.
What does TiTune identify and what does it output?
Parameter |
Identification Method |
Output Field |
|---|---|---|
|
HF voltage injection at standstill |
|
|
DC current injection |
|
|
Closed-loop flux estimation |
|
|
Coast-down frequency sweep |
|
Speed PI gains |
Computed from J/Kt |
|
Motor Startup Sequence
How does the motor start from standstill — Motor Align or IPD?
Before a sensorless FOC drive can enter closed-loop control, the rotor’s initial angular position must be established. Two methods are available:
Method |
How It Works |
When to Use |
|---|---|---|
Motor Align |
Applies a fixed DC voltage vector for a configurable hold time, forcing the rotor to a known angle |
SPM motors, or when brief rotor movement at startup is acceptable |
IPD (Initial Position Detection) |
Injects high-frequency voltage pulses in six sectors and measures the current response to detect the d-axis angle without moving the rotor |
IPM motors, or when rotor movement at startup is not acceptable |
Select the method in mtr1_init.c:
/* Motor Align (default) */
obj->inputCtrl.flagEnableAlignment = true;
obj->inputCtrl.startupMode = STARTUP_ALIGN;
/* IPD */
obj->inputCtrl.startupMode = STARTUP_IPD;
Key parameters in motor_params.h:
Parameter |
Method |
Description |
|---|---|---|
|
Motor Align |
DC hold current (A) — must be enough to move the rotor |
|
Motor Align |
Hold duration (s) — allow 5 s for the rotor to fully settle |
|
IPD |
Peak current limit for each injection pulse (A) |
|
IPD |
Number of injection cycles per sector |
See Motor Startup for the full configuration guide, watch window expressions, and troubleshooting tips.
How do I tune the open-loop ramp and closed-loop transition?
After initial position detection, the motor accelerates in open-loop (forced angle) until
the sensorless observer locks on, then transitions to closed-loop FOC. The key parameters
are in motor_params.h:
Parameter |
Description |
Tuning Guidance |
|---|---|---|
|
Torque current applied during the open-loop ramp |
Start at 50–70% of rated current |
|
Open-loop speed ramp rate (Hz/s) |
Too high → rotor loses sync; too low → slow startup |
|
Electrical speed at which OL→CL handover is triggered |
Must be high enough for the observer to lock on (≥10–20% of rated speed for ESMO) |
|
Angle blending step rate at the OL→CL transition |
Smaller value = smoother handover; 360 deg/s is a good starting point |
|
Closed-loop speed ramp rate after CL entry |
Too high → current saturation; too low → slow ramp to target speed |
To hold the motor in open-loop for debugging, set
motorVars_M1.inputCtrl.flagEnableOpenLoopDebug = true in the watch window.
See Open-Loop Ramp and Closed-Loop Transition for the full parameter reference and watch window expressions.
How do I enable Flying Start for a motor that may already be spinning?
Flying Start (ISD — Initial Speed Detection) allows the drive to detect a spinning rotor and transition directly to closed-loop without a full restart sequence. It is designed for fan, blower, and high-inertia loads that coast after a stop command or power interruption.
Enable it in mtr1_init.c:
obj->inputCtrl.flagEnableFlyingStart = true;
When enabled, the state machine enters MOTOR_SEEK_POS at startup. The sensorless observer
runs passively for FlyingStartDelay_sec seconds. If the estimated speed exceeds
FlyingStartMinSpeed_Hz, the drive transitions directly to closed-loop. Otherwise it falls
through to the normal Motor Align → Open-Loop Ramp sequence.
Key parameters in motor_params.h:
Parameter |
Description |
Example |
|---|---|---|
|
Minimum electrical speed to consider the rotor spinning |
|
|
Detection window — how long to observe before deciding |
|
Note
Flying Start does not require DC bus voltage sensing. Speed detection relies entirely on the sensorless observer (FAST or ESMO) using only phase current measurements.
See Flying Start (ISD) for the full configuration guide and watch window expressions.
Porting to a New Board
My PCB uses the same gate driver but has different pin assignments. What needs to change?
Only SysConfig and user_mtr1.h:
Open the
.syscfgfile and reassign ADC channels, PWM pins, CMPSS inputs, and GPIO to match your board’s pin connectionsUpdate
USER_M1_CURRENT_SF,USER_M1_VOLTAGE_SF, andUSER_M1_MAX_CURRENT_Ainuser_mtr1.hto match your shunt resistor value, op-amp gain, and voltage divider
See Step 2 — Update SysConfig and Step 3 — Update user_mtr1.h.
My design uses a different gate driver IC. How do I add support for it?
Create a new gate driver interface header following the pattern of the existing ones
(drv8329a_interface.h / drv8323rh_interface.h), implement the HAL_GD_vTable_t
virtual function table, and add the header directory to the CCS project include paths.
See Adding a New Gate Driver Interface for the complete step-by-step guide with code templates.
What is the board guard macro (DRV8329AEVM_REVA, BSXL8323RH_REVB) and where is it defined?
Each gate driver interface header is wrapped in an #ifdef BOARD_GUARD_MACRO guard.
The correct macro must be defined as a compile-time preprocessor symbol in the CCS
project settings (Project Properties → Build → Arm Compiler → Predefined Symbols).
See Existing Gate Driver Interfaces for the macro names and Step 4 — Define the board guard macro for how to set it in CCS.
What is the difference between 1-shunt and 3-shunt current sensing?
Aspect |
1-Shunt (DRV8329A) |
3-Shunt (DRV8323RH) |
|---|---|---|
Shunt location |
DC link (single resistor) |
Per phase (three resistors) |
ADC channels |
1 current channel |
3 current channels |
Current reconstruction |
Required (sample timing critical) |
Not needed |
ADC offset |
~4096/8 (unipolar) |
4096/2 (bipolar) |
Sample timing macros |
|
Not needed |
See 1-Shunt vs 3-Shunt Topology and Key Differences: 1-Shunt vs 3-Shunt.
Is there a migration checklist I can follow when porting to a new board?
Yes. The Migration Checklist in the board migration guide provides a step-by-step list covering all required changes:
Step |
What to Do |
|---|---|
1 |
Copy the reference project for your topology (1-shunt or 3-shunt) |
2 |
Update SysConfig ( |
3 |
Update |
4 |
Define the board guard macro in the project preprocessor settings |
5 |
Update or create the gate driver interface header |
6 |
Update the hardware wiring file ( |
7 |
Enter motor nameplate parameters in |
8 |
Run motor parameter identification (TiTune or InstaSPIN) |
See Board Migration Guide for the complete step-by-step instructions with code examples for each step.
How do I validate the signal path after porting to a new board?
Use the four-step Signal Path Diagnostics procedure in the Board Migration Guide. It walks through each layer of the signal chain in order, so you can isolate problems before attempting closed-loop motor operation:
Step |
What It Validates |
Key Variables |
|---|---|---|
1 — ADC & CMP Offsets |
ADC offset calibration completed correctly; CMPSS DAC trip-points are non-zero |
|
2 — Align Debug (voltage mode) |
ADC channel-to-phase mapping, current scaling, and sign convention |
|
3 — Continuous Align (closed-loop current) |
Current loop gains ( |
|
4 — Open-Loop Debug (observer lock) |
Speed observer converges before closing the speed loop |
|
Enable flags (set in the CCS Watch Window):
/* Step 2 — voltage-mode align */
motorVars_M1.motorCtrl.flagEnableAlignDebug = 1
motorVars_M1.motorCtrl.flagEnableContAlign = 1
/* Step 3 — closed-loop current, clear align-debug */
motorVars_M1.motorCtrl.flagEnableAlignDebug = 0
motorVars_M1.motorCtrl.flagEnableContAlign = 1
/* Step 4 — open-loop observer validation */
motorVars_M1.motorCtrl.flagEnableOpenLoopDebug = 1
See Signal Path Diagnostics for the complete procedure with pass/fail criteria and troubleshooting guidance for each step.
Adding Custom Code
How do I add a new interrupt-driven peripheral (e.g., a custom UART or timer ISR)?
Add the peripheral in SysConfig to get the generated init code and IRQ number
Write the ISR handler in
isr.cSet the NVIC priority lower than the ADC ISR (higher numeric value) so it cannot preempt the FOC execution
How do I add code that runs synchronously with the FOC ISR at the same rate?
Add your code inside application_run() in
application.c,
after the five FOC sections. Keep execution time within the ISR budget
(1000 / USER_M1_PWM_FREQ_kHz µs — e.g. 66 µs at 15 kHz, 10 µs at 100 kHz).
Place time-critical code in RAM using the MOTOR_CTRL_RAMFUNC attribute.
How do I add a slow background task (e.g., a status report or outer-loop controller)?
Add it to the background loop in main.c or inside
FOC_runLowPriorityStateMachine(). The background loop runs approximately every 1 ms.
Use the timerCntFOCCtrlISR counter to create sub-multiples of the 1 ms tick if needed.
How much ISR execution time is available for custom code?
At 15 kHz the ISR budget is 66 µs. At 100 kHz it is 10 µs. Use the
CPU_TIME_Obj (cpuTime) in main.h to measure actual ISR execution time.
Custom code added to application_run() must be RAM-resident (MOTOR_CTRL_RAMFUNC)
to avoid flash wait-state latency.
See ISR Execution Budget.
Control Algorithms
Which observer should I use — FAST or ESMO?
Observer |
Best For |
|---|---|
FAST (InstaSPIN) |
Wide speed range, robust startup, handles parameter variation |
ESMO |
Simpler tuning, lower CPU load, good for steady-state operation |
See FAST Observer and ESMO Observer for configuration details and a comparison table.
How do I enable Field Weakening (FWC) to run above base speed?
Set flagEnableFWC = TRUE in MOTOR_SetVars_t and configure the FWC voltage limit
(VsRef) and maximum negative d-axis current (IdMin_A).
See Field Weakening.
What is MTPA and when should I use it?
MTPA (Maximum Torque Per Ampere) minimizes copper losses by finding the optimal d/q
current split for a given torque. It is most beneficial for interior permanent magnet
(IPM) motors where Ld ≠ Lq. Enable with flagEnableMTPA = TRUE.
See MTPA.
What is dead-time compensation and when should I enable it?
Dead-time compensation (DTC) corrects the voltage distortion introduced by the mandatory dead-time inserted between complementary switch transitions in each inverter leg. Without compensation, dead-time causes harmonic distortion in the output voltage, leading to torque ripple and reduced control accuracy — especially at low speeds and low modulation indices.
DTC is disabled by default. Enable it in mtr1_init.c
or at runtime via the watch window:
/* In mtr1_init.c — enable DTC during initialisation */
DTC_InitParams_t dtcParams;
DTC_setDefaultParams(&dtcParams);
dtcParams.speedEnableLimit_Hz = 10.0f; /* Enable DTC above 10 Hz electrical speed */
dtcParams.speedDisableLimit_Hz = 5.0f; /* Disable DTC below 5 Hz (hysteresis) */
dtcParams.enableDTC = true;
DTC_initParams(obj->deadTimeCompHandle, &dtcParams);
Or toggle at runtime:
/* Watch window expression */
motorVars_M1.inputCtrl.flagEnableDTC = true;
Parameter |
Default |
Description |
|---|---|---|
|
|
Minimum electrical speed to activate DTC |
|
|
Speed at which DTC deactivates when decelerating |
|
|
Maximum compensation voltage as a fraction of DC bus voltage |
DTC is most effective when:
The motor runs at low speed or low modulation index
The ESMO observer is used (DTC improves voltage accuracy for the back-EMF estimator)
Torque ripple or current THD at low speed is unacceptable
See Dead-Time Compensation for the full configuration guide and effect on performance.
What should I tune if the motor vibrates or makes noise at low speed?
Common causes and tuning targets:
Symptom |
Likely Cause |
Where to Tune |
|---|---|---|
Vibration at low speed |
Current loop bandwidth too high or Rs mismatch |
|
Noise during open-loop ramp |
|
|
Oscillation after OL→CL transition |
Observer not locked, |
|
Dead-time distortion at low speed |
Dead-time compensation not enabled |
How do I monitor and debug motor variables on an oscilloscope or serial plotter?
The solution provides two real-time diagnostic output paths that share the same variable pointer configuration:
Method |
Output |
Hardware Required |
|---|---|---|
DAC output |
Analogue voltage on CMPSSLITE pin, viewable on a CRO |
Oscilloscope probe on the DAC output pin |
Serial Plot |
Two float values streamed over back-channel UART ( |
PC serial plotter at the baud rate configured in the |
To select which variables to plot, edit initDACOutputs() in
motor_common.c
and point pDacOutAddr at any float32_t field in motorVars_M1:
/* Plot FOC angle on channel 1 (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; /* 0 = bipolar, 1 = unipolar */
sysVarsPtr->dacCtrl1.dacEn = 1U;
/* Plot speed on channel 2 */
sysVarsPtr->dacCtrl2.pDacOutAddr = (float32_t *)&obj->outVars.speed_Hz;
sysVarsPtr->dacCtrl2.dacEn = 1U;
To activate both outputs, uncomment runMotorDataLogging() in application_run():
/* application.c — Section 5: DATA LOGGING */
runMotorDataLogging();
Common variable addresses for the DAC pointer:
Signal |
Pointer expression |
|---|---|
FOC angle |
|
Phase-A current |
|
Speed (Hz) |
|
Iq reference |
|
ESMO Ealpha |
|
See Real-Time Diagnostics — DAC Output and Serial Plot for the full configuration guide, scaling formulas, packet format, and oscilloscope screenshots.
Where are all the tunable parameters and what do they control?
See Motor Data Structures for a complete map of all runtime parameters and their locations. Key tuning parameters:
Parameter |
Location |
Controls |
|---|---|---|
|
|
Speed setpoint |
|
|
Current limit |
|
|
Speed PI gains |
|
|
D-axis current PI gains |
|
|
Q-axis current PI gains |
|
|
Open-loop ramp rate |
|
|
Alignment current |