3-Shunt Sensorless FOC motor control solution using the DRV8323RH gate driver

Note

Common source files are linked from their original SDK locations for easier maintenance during development.

Overview

This solution demonstrates three-shunt sensorless Field Oriented Control (FOC) for PMSM/BLDC motors using the TI DRV8323RH gate driver on the AM13E2X LaunchPad.

Key Features

  • Three-phase current sensing with individual shunt resistors

  • Sensorless rotor position estimation using eSMO (enhanced Sliding Mode Observer)

  • FAST observer library support for motor parameter identification

  • Field Oriented Control (FOC) with Space Vector PWM

  • Flux weakening capability for extended speed range

  • Maximum Torque Per Ampere (MTPA) control

  • Real-time tuning support via TI Tune interface

Hardware Requirements

  • AM13E232X LaunchPad (LP-AM13E232X)

  • BOOSTXL-DRV8323RH booster pack

  • Compatible PMSM/BLDC motor

  • DC power supply (appropriate voltage for motor)

Software Dependencies

  • TI ARM Clang Compiler or IAR Embedded Workbench

  • SysConfig tool for peripheral configuration

  • Code Composer Studio (CCS) or IAR EWARM IDE

  • FAST observer library (pre-built, included)

External Connections

For the complete boosterpack connector pin mapping (LaunchPad header assignments), refer to the 3-Shunt FOC Peripheral Configuration page in the Solutions section of the user guide.

Build Instructions

  1. Import the project into your IDE (CCS or IAR)

  2. Build the project using the default configuration

  3. Connect the hardware and flash the device

  4. Use the debugger or TI Tune to control motor operation

Motor Configuration

Motor parameters are configured in the motor_params.c file:

Common motor control data structures and types are defined in motor_common.h:

Update the following fields in the motorParams structure to match your motor specifications:

  • Rs_Ohm — Stator resistance (Ω)

  • Ls_d_H / Ls_q_H — D/Q-axis stator inductance (H)

  • flux_VpHz / flux_Wb — Motor flux linkage

  • numPolePairs — Number of pole pairs

  • ratedCurrent_A — Rated phase current (A)

Watch Window Variables

For the quickest setup, import the pre-configured watch variables file into the CCS Watch Window. In CCS, open the Debug:watch view, Right click - Import button (or use View - Debug - Watch Expressions), and select

This will automatically add all key variables for controlling and monitoring the motor controller at runtime.

Alternatively, you can selectively add the following expressions to the CCS Watch Window to monitor and tune the motor controller at runtime:

Input Control (motorVars.inputCtrl) — User Commands

Variable

Purpose

motorVars.inputCtrl.flagEnableRunAndIdentify

Start motor and trigger identification (bool)

motorVars.inputCtrl.flagClearFaults

Pulse high to clear active fault register (bool)

motorVars.inputCtrl.speedRef_Hz

Speed setpoint in Hz (float32_t)

motorVars.inputCtrl.direction

Motor direction: 1.0 = forward, -1.0 = reverse (float32_t)

motorVars.inputCtrl.flagEnableFlyingStart

Detect spinning rotor before start (bool)

motorVars.inputCtrl.startupMode

Startup mode: ALIGN / IPD / FREE / HFI (STARTUP_Mode_e)

motorVars.inputCtrl.flagEnableRestart

Enable auto-restart after fault (bool)

motorVars.inputCtrl.flagEnableDTC

Enable Dead Time Compensation (bool)

motorVars.inputCtrl.flagEnableFWC

Enable Field Weakening Control (bool)

motorVars.inputCtrl.flagEnableMTPA

Enable Maximum Torque Per Ampere (bool)

motorVars.inputCtrl.estimatorMode

FAST or ESMO estimator selection (ESTIMATOR_Mode_e)

motorVars.inputCtrl.svmMode

Space vector modulation mode (SVM_Mode_e)

Output Variables (motorVars.outVars) — FOC Outputs

Variable

Purpose

motorVars.outVars.motorState

Current state machine state (MOTOR_Status_e)

motorVars.outVars.faultMtrNow

Active (raw) fault register (FAULT_MTR_REG_t)

motorVars.outVars.speed_Hz

Controller speed in Hz (float32_t)

motorVars.outVars.speed_rps

Controller speed in rad/s (float32_t)

motorVars.outVars.Is_A

Stator current magnitude (A) (float32_t)

motorVars.outVars.Idq_in_A

Measured d/q currents (A) (MATH_Vec2)

motorVars.outVars.IdqRef_A

D/Q current reference (A) (MATH_Vec2)

motorVars.outVars.Vdq_out_V

D/Q voltage command (V) (MATH_Vec2)

motorVars.outVars.angleFOC_rad

FOC angle used by controller (rad) (float32_t)

motorVars.outVars.angleFWC_rad

Field weakening angle output (rad) (float32_t)

motorVars.outVars.angleMTPA_rad

MTPA angle output (rad) (float32_t)

motorVars.outVars.torque_Nm

Estimated torque (N·m) (float32_t)

motorVars.outVars.powerActive_W

Active power (W) (float32_t)

Status Variables (motorVars.statusVars) — Internal Status

Variable

Purpose

motorVars.statusVars.flagMotorIdentified

Motor parameter identification complete (bool)

motorVars.statusVars.flagRunIdentAndOnLine

Currently running identification and online mode (bool)

motorVars.statusVars.estState

Estimator state (EST_State_e)

motorVars.statusVars.faultMtrUse

Masked active fault register (FAULT_MTR_REG_t)

motorVars.statusVars.faultMtrPrev

Previous fault register (fault history) (FAULT_MTR_REG_t)

motorVars.statusVars.speedAbs_Hz

Absolute speed magnitude (Hz) (float32_t)

motorVars.statusVars.speedEST_Hz

Speed from FAST estimator (Hz) (float32_t)

motorVars.statusVars.speedPLL_Hz

Speed from PLL/eSMO (Hz) (float32_t)

motorVars.statusVars.angleObs_rad

Observer angle — primary observer output (rad) (float32_t)

motorVars.statusVars.angleEST_rad

Angle from FAST estimator (rad) (float32_t)

motorVars.statusVars.angleSMO_rad

Angle from SMO (rad) (float32_t)

motorVars.statusVars.anglePLL_rad

Angle from PLL (rad) (float32_t)

motorVars.statusVars.Irms_A

RMS phase currents — 3 phases (A) (float32_t[3])

motorVars.statusVars.restartTimesCnt

Restart attempts counter (uint16_t)

Set Variables (*motorVars.motorSetsHandle) — Tuning Setpoints

Variable

Purpose

motorVars.motorSetsHandle->Kp_spd / Ki_spd

Speed PI controller gains (float32_t)

motorVars.motorSetsHandle->Kp_Id / Ki_Id

D-axis current PI gains (float32_t)

motorVars.motorSetsHandle->Kp_Iq / Ki_Iq

Q-axis current PI gains (float32_t)

motorVars.motorSetsHandle->Kp_fwc / Ki_fwc

Field weakening PI gains (float32_t)

motorVars.motorSetsHandle->maxCurrent_A

Maximum current limit (A) (float32_t)

motorVars.motorSetsHandle->overVoltageFault_V

Over voltage fault threshold (V) (float32_t)

motorVars.motorSetsHandle->underVoltageFault_V

Under voltage fault threshold (V) (float32_t)

motorVars.motorSetsHandle->overCurrent_A

Over current threshold (A) (float32_t)

motorVars.motorSetsHandle->accelerationMax_Hzps

Closed-loop max acceleration (Hz/s) (float32_t)

For a detailed description of all motor data structures and runtime setpoints, see the Motor Data Structures page.

AM13E232X Peripheral Configuration

For detailed AM13E232X peripheral configuration including signal routing diagrams, ADC/PWM/CMPSS/crossbar setup, and complete pin summary, refer to the 3-Shunt FOC Peripheral Configuration page.

References