Migration to a New Board
This section describes how to adapt the motor control solution to a new hardware board — whether that means a different PCB layout (new pin assignments), a different gate driver IC, or a different motor. The changes are localized to a small set of files.
What Needs to Change
Step-by-Step Migration Guide
Step 1 — Copy an Existing Example
Start from the example that most closely matches your topology:
# For 3-shunt topology
solutions/motor_control/ufoc_lp_bxl/3sh_sen_less_foc_drv8323rh/
# For 1-shunt topology
solutions/motor_control/ufoc_lp_bxl/1sh_sen_less_foc_drv8329a/
Copy the entire example folder and rename it for your board. The main.c, isr.c, and
main.h files require minimal changes — most customization is in the files described below.
Step 2 — Update SysConfig (.syscfg)
Open the .syscfg file in SysConfig GUI (or edit as text) and reassign peripherals to
match your board’s pin connections.
Key peripherals to configure:
Peripheral |
What to Configure |
Impact |
|---|---|---|
ADC |
Channel assignments for phase currents and bus voltage |
|
MCPWM |
PWM output pins for U/V/W phases |
|
CMPSS |
Comparator inputs for over-current protection |
|
PWM XBAR |
ADC trigger source (must be PWM-synchronous) |
|
GPIO |
Gate driver enable, nFAULT, ISR timing pin |
|
UART |
Serial plot output |
|
ECAP |
IPD pulse capture (if using IPD startup) |
|
After saving the .syscfg file, SysConfig regenerates ti_sdk_dl_config.h and
ti_sdk_dl_config.c with the new peripheral macros. The HAL and application code
use these macros — no other source changes are needed for pin reassignment.
Note
Run SysConfig → Generate after any .syscfg change to
ensure ti_sdk_dl_config.h is up to date before building.
Step 3 — Update user_mtr1.h
user_mtr1.h contains board-level constants that must match your hardware. These are not generated
by SysConfig — they must be set manually.
Critical parameters to review:
/* PWM frequency — must match MCPWM configuration in SysConfig */
#define USER_M1_PWM_FREQ_kHz (15)
/* Current sense scale factor — depends on shunt resistor and op-amp gain */
/* Formula: I_A = ADC_count × USER_M1_CURRENT_SF */
/* For DRV8323RH: use DRV8323_CURRENT_SF from drv8323rh_interface.h */
/* For DRV8329A: use DRV8329_CURRENT_SF from drv8329a_interface.h */
#define USER_M1_CURRENT_SF (float32_t)(DRV8323_CURRENT_SF)
/* DC bus voltage scale factor — depends on voltage divider ratio */
/* For DRV8323RH: use DRV8323_VOLTAGE_SF from drv8323rh_interface.h */
/* For DRV8329A: use DRV8329_VOLTAGE_SF from drv8329a_interface.h */
#define USER_M1_VOLTAGE_SF (float32_t)(DRV8323_VOLTAGE_SF)
/* Hardware over-current trip threshold — set to match CMPSS DAC level */
#define USER_M1_MAX_CURRENT_A (float32_t)(10.0f)
/* ADC offset calibration time — increase if offsets are noisy */
#define USER_M1_OFFSET_CALIB_TIME_SEC (float32_t)(0.5f)
Warning
Incorrect USER_M1_CURRENT_SF or USER_M1_VOLTAGE_SF will cause wrong current/voltage
readings, leading to incorrect PI gains and potential over-current faults. Verify these
values against your board schematic before running the motor.
Step 4 — Update the Motor Parameters
If connecting a different motor, add its parameters to
motor_params.c
and update the active motor pointer:
/* motor_params.c — add new motor entry */
const Motor_ParamsType Motor_myMotor = {
.NumPolePairs = 4,
.Rs_Ohm = 0.85f,
.Ls_d_H = 0.00135f,
.Ls_q_H = 0.00135f,
.RatedFlux_VpHz = 0.0415f,
.RatedCurrent_A = 5.0f,
.Inertia_Kgm2 = 0.0001f,
.RatedSpeed_Hz = 100.0f,
.OlSpeedThr_Hz = 20.0f,
.OlTorqueCurrent_A = 1.5f,
.AlignCurrent_A = 1.0f,
/* ESMO gains — tune after first run */
.EsmoKslideMax = 0.5f,
.EsmoKslideMin = 0.05f,
.EsmoPllKpMax = 10.0f,
.EsmoPllKpMin = 1.0f,
.EsmoPllKi = 0.001f,
};
/* Select active motor */
const Motor_ParamsType *motorParams_M1 = &Motor_myMotor;
If motor parameters are unknown, use TiTune to identify them automatically. See the Motor Parameter Tuning guide.
Step 5 — Update the Gate Driver Interface
Each gate driver has a dedicated interface header that defines the hardware-specific scale factors, offset calibration values, and GPIO object. When migrating to a new board or gate driver, these macros must be updated to match your hardware.
Existing Gate Driver Interfaces
The two supported gate drivers are located at:
common_files/hal/gate_driver_interface/
├── drv8329a/
│ └── drv8329a_interface.h ← 1-shunt (DRV8329A EVM RevA)
└── drv8323rh/
└── drv8323rh_interface.h ← 3-shunt (BSXL8323RH RevB)
Each file is guarded by a board-identification #ifdef that must be defined in
the project’s compile-time defines (CCS project settings or SysConfig):
Gate Driver |
Guard Macro |
Topology |
|---|---|---|
DRV8329A |
|
1-shunt (DC-link) |
DRV8323RH |
|
3-shunt (per-phase) |
DRV8329A Interface Macros (1-Shunt)
File: drv8329a_interface.h
Macro |
Value |
Description |
|---|---|---|
|
|
Full-scale DC bus voltage at ADC input (set by voltage divider: 110kΩ/4.99kΩ) |
|
|
Analog voltage filter pole frequency (110kΩ/4.99kΩ/100nF) |
|
|
Full-scale DC-link current at ADC input (Rs=10mΩ, CSA gain=10V/V) |
|
|
Voltage scale factor: ADC count → Volts |
|
|
Current scale factor: ADC count → Amps |
|
|
Inverse current scale factor |
|
|
Current polarity: |
|
|
DC-link current ADC offset (≈ 4096/8, mid-scale for unipolar sensing) |
|
|
CMPSS DAC offset for hardware over-current trip |
|
|
Acceptable offset calibration range |
|
|
Phase voltage ADC offset scale factors (≈ 0.5 = mid-scale) |
|
|
DC bus over-voltage fault threshold |
|
|
DC bus over-voltage recovery threshold |
|
|
DC bus under-voltage fault threshold |
|
|
Minimum ADC sampling window (clock cycles): Tdt+Tpd+Tr+Ts+Ts&h |
|
|
ADC sample delay (clock cycles): Tdt+Tpd+Tr+Ts |
GPIO object (HAL_DRV8329_Obj):
Field |
Description |
|---|---|
|
GPIO port/pin for DRV8329A nSLEEP pin |
|
GPIO port/pin for driver off control |
DRV8323RH Interface Macros (3-Shunt)
File: drv8323rh_interface.h
Macro |
Value |
Description |
|---|---|---|
|
|
Nominal DC bus voltage |
|
|
Full-scale DC bus voltage at ADC input |
|
|
Analog voltage filter pole frequency |
|
|
Full-scale phase current at ADC input |
|
|
Voltage scale factor: ADC count → Volts |
|
|
Current scale factor: ADC count → Amps |
|
|
Inverse current scale factor |
|
|
Current polarity sign |
|
|
Phase current ADC offset (mid-scale: 4096/2, bipolar sensing) |
|
|
CMPSS DAC offset for hardware over-current trip |
|
|
Phase voltage ADC offset scale factors |
|
|
Acceptable per-phase offset calibration range |
|
|
DC bus over-voltage fault threshold |
|
|
DC bus under-voltage fault threshold |
|
|
Number of current sensors (one per phase) |
|
|
Number of voltage sensors (3 phase + 1 DC bus) |
GPIO object (HAL_DRV8323_Obj):
Field |
Description |
|---|---|
|
GPIO port/pin for DRV8323RH calibration pin |
|
GPIO port/pin for gate driver enable |
Key Differences: 1-Shunt vs 3-Shunt Current Sensing
Parameter |
DRV8329A (1-Shunt) |
DRV8323RH (3-Shunt) |
|---|---|---|
Current offset |
|
|
Sensing type |
Unipolar (DC-link, always positive) |
Bipolar (per-phase, positive and negative) |
CMPSS offset |
Same as ADC offset |
Same as ADC offset |
Sample timing |
|
Not needed (direct sampling) |
Current sensors |
1 |
3 |
The 1-shunt offset is near 4096/8 because the DC-link current is always positive (unipolar), so the ADC input is biased to a low value. The 3-shunt offset is at 4096/2 (mid-scale) because phase currents are bipolar (positive and negative).
Adding a New Gate Driver Interface
If your board uses a gate driver not already supported, implement the
HAL_GD_vTable_t virtual function table interface defined in
hal_gate_driver.h.
1. Create the interface header with the same macro pattern:
/* my_new_driver_interface.h */
#ifdef MY_NEW_DRIVER_BOARD_REV
/* --- Scale factors (compute from your schematic) --- */
#define MY_DRV_ADC_FULL_SCALE_VOLTAGE_V (48.0f) /* Vbus divider ratio × 3.3V */
#define MY_DRV_ADC_FULL_SCALE_CURRENT_A (20.0f) /* Ishunt_max = Vref / (Rs × gain) */
#define MY_DRV_VOLTAGE_SF (MY_DRV_ADC_FULL_SCALE_VOLTAGE_V / 4096.0f)
#define MY_DRV_CURRENT_SF (MY_DRV_ADC_FULL_SCALE_CURRENT_A / 4096.0f)
#define MY_DRV_CURRENT_INV_SF (4096.0f / MY_DRV_ADC_FULL_SCALE_CURRENT_A)
#define MY_DRV_SIGN_CURRENT_SF (1.0f) /* 1.0f = inverting, -1.0f = non-inverting */
/* --- ADC offsets (measure after calibration or compute from circuit) --- */
#define MY_DRV_IDC_OFFSET_AD (2048.0f) /* 4096/2 for bipolar, 4096/8 for unipolar */
#define MY_DRV_IDC_OFFSET_CMPSS (uint16_t)(MY_DRV_IDC_OFFSET_AD)
/* --- Fault thresholds --- */
#define MY_DRV_OVER_VOLTAGE_FAULT_V (54.5f)
#define MY_DRV_UNDER_VOLTAGE_FAULT_V (8.0f)
/* --- GPIO object --- */
typedef struct _HAL_MY_DRV_Obj_
{
uint32_t gateEnableGPIO;
uint32_t gateEnableGPIONum;
} HAL_MY_DRV_Obj;
#endif /* MY_NEW_DRIVER_BOARD_REV */
2. Create the vtable implementation:
/* my_new_driver_interface.c */
#include "hal_gate_driver.h"
#include "my_new_driver_interface.h"
static void MyDriver_init(const HAL_GD_DATA_Obj *gdData)
{
/* Configure SPI registers, set CSA gain, etc. */
}
static void MyDriver_enable(const HAL_GD_DATA_Obj *gdData)
{
HAL_setGPIOHigh(MY_DRV_EN_PORT, MY_DRV_EN_PIN);
}
const HAL_GD_vTable_t MyDriver_vTable = {
.init = MyDriver_init,
.enable = MyDriver_enable,
};
3. Add the gate driver header to the project include path in CCS project settings:
Open Project Properties → Build → Arm Compiler → Include Options and add:
hal/gate_driver_interface/my_new_driver
4. Define the board guard macro in CCS project settings:
Open Project Properties → Build → Arm Compiler → Predefined Symbols and add:
MY_NEW_DRIVER_BOARD_REV
Step 6 — Update the Motor Config Wiring File
The file system_config.c (3-shunt)
(and its header system_config.h)
is the primary hardware wiring file for the 3-shunt example. It instantiates and
links together all hardware-specific objects that the application layer uses at runtime.
When migrating to a new board or gate driver, copy this file pair into your new example folder and update the following objects:
HAL_FOC_Config_t halFOCConfig_M1
Maps SysConfig-generated macros to the HAL FOC configuration. After updating SysConfig
(Step 2), verify that the ADC, PWM, CMPSS, and ECAP macro names used here match the
names generated in ti_sdk_dl_config.h:
const HAL_FOC_Config_t halFOCConfig_M1 = {
/* ADC current channels — update if ADC pin assignments changed */
.adcCurrentCfg[0].adcResultBase = (uint32_t)MTR1_IU_SEN_ADC_RESULT_BASE,
.adcCurrentCfg[1].adcResultBase = (uint32_t)MTR1_IV_SEN_ADC_RESULT_BASE,
.adcCurrentCfg[2].adcResultBase = (uint32_t)MTR1_IW_SEN_ADC_RESULT_BASE,
/* ADC voltage channels */
.adcVoltageCfg[0].adcResultBase = (uint32_t)MTR1_VU_SEN_ADC_RESULT_BASE,
/* ... */
/* PWM peripheral */
.pwmCfg.pwmHandle = (uint32_t)MTR1_MCPWM_BASE_BASE,
/* CMPSS overcurrent comparators */
.cmpCfg.cmpssHandle[0] = (uint32_t)MTR1_CMPSS_U_BASE_BASE,
/* ECAP for IPD */
.ecapIPDConfig.base = (uint32_t)IPD_CAPTURE_BASE,
/* ... */
};
HAL_DRV8323_Obj drv8323Inst_M1
Holds the GPIO port/pin assignments for the gate driver control signals. Update these to match your board’s GPIO connections for the gate driver enable and calibration pins:
const HAL_DRV8323_Obj drv8323Inst_M1 = {
.gateCalGPIO = (uint32_t)MTR1_DRV_CAL_PORT,
.gateCalGPIONum = (uint32_t)MTR1_DRV_CAL_PIN,
.gateEnableGPIO = (uint32_t)MTR1_DRV_EN_PORT,
.gateEnableGPIONum = (uint32_t)MTR1_DRV_EN_PIN,
};
HAL_GD_Interface_t halGDInst and HAL_FOC_Interface_t halFOCInterface
These link the vtable, instance data, and configuration together. If you are using the same gate driver (DRV8323RH) on a new board, these do not need to change — only the GPIO macros above need updating. If switching to a different gate driver IC, update the vtable pointer to point to the new driver’s vtable:
const HAL_GD_Interface_t halGDInst = {
.vTable = &halDRV8323FnTable, /* ← change for new gate driver */
.instance = &drv8323Inst_M1,
.data = &drv8323Data_M1,
};
MOTOR_Vars_t motorVars_M1
Links the gate driver and FOC interfaces into the top-level motor object. This typically does not need to change when migrating boards:
MOTOR_Vars_t motorVars_M1 = {
.halInterface = &halFOCInterface,
};
Note
For the 1-shunt topology, the equivalent file is system_config.c (1-shunt).
The same update procedure applies.
Migration Checklist
Note
Use this checklist when migrating to a new board:
SysConfig: ADC channels reassigned to new pin names
SysConfig: PWM outputs assigned to correct phase pins
SysConfig: CMPSS inputs connected to correct current sense signals
SysConfig: GPIO pins for gate driver EN, nFAULT, timing pin updated
user_mtr1.h:USER_M1_CURRENT_SFverified against schematicuser_mtr1.h:USER_M1_VOLTAGE_SFverified against schematicuser_mtr1.h:USER_M1_MAX_CURRENT_Aset to hardware OC limituser_mtr1.h:USER_M1_PWM_FREQ_kHzmatches SysConfig MCPWM settingmotor_params.c: New motor entry added,motorParams_M1pointer updatedGate driver header:
ADC_FULL_SCALE_VOLTAGE_Vcomputed from voltage divider schematicGate driver header:
ADC_FULL_SCALE_CURRENT_Acomputed from shunt resistor value and CSA gainGate driver header:
IDC_OFFSET_ADset correctly (≈4096/8 for unipolar 1-shunt, ≈4096/2 for bipolar 3-shunt)Gate driver header:
OVER_VOLTAGE_FAULT_V/UNDER_VOLTAGE_FAULT_Vset to system limitsGate driver header:
DCLINKSS_MIN_DURATION/DCLINKSS_SAMPLE_DELAYset (1-shunt only)Gate driver header: Board guard macro defined in project compile-time defines (
DRV8329AEVM_REVA,BSXL8323RH_REVB, or custom)Gate driver vtable: New driver vtable implemented (if using a new gate driver IC)
drv8323_3sh_config.c(ordrv8329_1sh_config.c): ADC macro names verified againstti_sdk_dl_config.hdrv8323_3sh_config.c: GPIO macros for gate driver EN and CAL pins updated to new board pin namesdrv8323_3sh_config.c:halGDInst.vTableupdated if switching to a different gate driver ICBuild succeeds
First run: verify current and voltage readings in watch window before enabling motor
Signal Path Diagnostics
After migrating to a new board, use this four-step procedure to validate the complete signal path — from raw ADC counts through current feedback, current control, and finally the speed observer — before attempting closed-loop motor operation.
Note
All variables referenced below are accessible in the CCS Watch Window.
halFOCData is the HAL_FOC_Data_Obj instance for motor 1.
motorVars_M1 is the MOTOR_Vars_t master object.
Step 1 — Verify ADC and Comparator Offsets
Before enabling the motor, confirm that the ADC offset calibration has produced values in the
expected range. Offsets are stored in HAL_FOC_Data_Obj.adcData
after HAL_RunOffsetCalStep() completes.
Topology |
Field to inspect |
Expected value |
|---|---|---|
3-shunt |
|
≈ 2048 (mid-scale of 12-bit ADC) |
1-shunt (DRV8329A) |
|
≈ 511 (quarter-scale, unipolar sensing) |
Comparator DAC offsets are stored in halFOCData.compOffsetData[0..2]. These represent
the hardware over-current trip-point calibration. Verify they are non-zero and within the
range defined by OVER_CURRENT_FAULT_A in the gate driver header.
Watch window variables:
halFOCData.adcData.offset_I_ad[0] /* Phase A (or DC-link for 1-shunt) */
halFOCData.adcData.offset_I_ad[1] /* Phase B (3-shunt only) */
halFOCData.adcData.offset_I_ad[2] /* Phase C (3-shunt only) */
halFOCData.compOffsetData[0] /* CMPSS comparator DAC offset, phase A */
halFOCData.compOffsetData[1] /* CMPSS comparator DAC offset, phase B */
halFOCData.compOffsetData[2] /* CMPSS comparator DAC offset, phase C */
Pass criteria: Offset values within ±10 % of the expected mid-scale value. Values near 0
or near full-scale (4095) indicate a wiring or SysConfig error — recheck ADC channel
assignments and the IDC_OFFSET_AD macro in the gate driver header.
Step 2 — Align Debug: Validate ADC Current Feedback (Voltage Mode)
Enable align-debug mode to inject a known DC voltage vector and observe the resulting phase currents. This validates ADC channel assignment, current scaling, and sign convention without running the current controller.
Enable flags (set in MOTOR_InputCtrl_t):
motorVars_M1.motorCtrl.flagEnableAlignDebug = 1
motorVars_M1.motorCtrl.flagEnableContAlign = 1
With both flags set the motor is held continuously in the align state. The applied voltage
is V_q = I_align × Rs (voltage-mode, open-loop — no current feedback used).
Procedure:
Set
flagEnableAlignDebug = 1andflagEnableContAlign = 1.Enable the motor (
flagEnableRunAndIdentify = 1). The rotor will lock to the align angle.Vary the align angle via
motorVars_M1.motorSetVars.alignAngle_radacross 0 → 2π.Monitor the phase currents and the d/q projections:
motorVars_M1.motorOutVars.Iabc_A.value[0] /* Phase A current, amperes */
motorVars_M1.motorOutVars.Iabc_A.value[1] /* Phase B current, amperes */
motorVars_M1.motorOutVars.Iabc_A.value[2] /* Phase C current, amperes */
motorVars_M1.motorOutVars.Id_A /* d-axis current */
motorVars_M1.motorOutVars.Iq_A /* q-axis current */
Pass criteria:
Iabc_Avalues are smooth and symmetric as the align angle rotates.Id_Atracks the commanded align current;Iq_Astays near zero.No phase reads a constant zero (would indicate an open ADC channel or wrong pin mapping).
If the feedback looks wrong: Recheck ADC channel-to-phase mapping in SysConfig and
verify USER_M1_CURRENT_SF in user_mtr1.h. Adjust current loop gains (Kp, Ki) in
motorVars_M1.motorSetVars or re-run TiTune / InstaSPIN parameter identification.
Step 3 — Continuous Align: Validate Closed-Loop Current Control
Disable align-debug mode while keeping continuous align active. The current controller is
now closed and regulates Id to the align current setpoint. This step validates current
loop tuning independently of the speed observer.
Enable flags:
motorVars_M1.motorCtrl.flagEnableAlignDebug = 0 /* disable voltage-mode align */
motorVars_M1.motorCtrl.flagEnableContAlign = 1 /* keep continuous align active */
Procedure:
Clear
flagEnableAlignDebug(leaveflagEnableContAlign = 1).Step through several align angles and observe
Id_AandIq_A.Id_Ashould tightly track the commanded align current with minimal overshoot.Iq_Ashould remain near zero at all angles.
Watch window variables:
motorVars_M1.motorOutVars.Id_A /* should equal alignCurrent_A setpoint */
motorVars_M1.motorOutVars.Iq_A /* should be ≈ 0 */
motorVars_M1.motorSetVars.alignCurrent_A /* commanded align current */
motorVars_M1.motorSetVars.Kp_Id /* d-axis proportional gain */
motorVars_M1.motorSetVars.Ki_Id /* d-axis integral gain */
Pass criteria: Id_A settles to within 5 % of alignCurrent_A within a few PWM cycles.
Oscillation or steady-state error indicates incorrect Kp/Ki — re-run parameter
identification or manually tune the current loop gains.
Step 4 — Open-Loop Debug: Validate the Speed Observer
Enable open-loop debug mode to run the motor under closed-loop current control with an open-loop speed ramp. The speed observer runs in parallel but does not yet close the speed loop. This lets you verify that the observer locks to the rotor before switching to full sensorless closed-loop operation.
Enable flag:
motorVars_M1.motorCtrl.flagEnableOpenLoopDebug = 1
Procedure:
Clear
flagEnableContAlignand setflagEnableOpenLoopDebug = 1.Enable the motor. The firmware ramps speed open-loop to
motorSetVars.speedStart_Hz.Monitor the observer output speed and angle:
motorVars_M1.motorStatusVars.speedObs_Hz /* observer estimated speed */
motorVars_M1.motorStatusVars.angleObs_rad /* observer estimated angle */
motorVars_M1.motorSetVars.speedStart_Hz /* open-loop ramp target speed */
Pass criteria:
speedObs_Hzconverges to and tracksspeedStart_Hz(the open-loop ramp target).angleObs_radadvances smoothly without large jumps.Observer lock is confirmed when
speedObs_Hzis within ±5 % of the commanded speed.
If the observer does not lock:
Verify motor parameters (
Rs,Ld,Lq,flux) inmotor_params.c.Check that
USER_M1_MOTOR_NUM_POLE_PAIRSis correct.Reduce
speedStart_Hzto a lower value and retry.Re-run InstaSPIN or TiTune identification to obtain accurate motor parameters.
Transition to Closed-Loop:
Once the observer locks reliably in open-loop debug mode, clear
flagEnableOpenLoopDebug and proceed with normal closed-loop sensorless FOC operation.