3-Shunt Hall Sensored 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 Hall sensor-based 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
Hall sensor-based rotor position feedback using GPIO inputs and ECAP speed measurement
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
AM13E230X LaunchPad (LP-AM13E230X)
BOOSTXL-DRV8323RH booster pack
Compatible PMSM/BLDC motor with Hall sensors
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
External Connections
For the complete boosterpack connector pin mapping (LaunchPad header assignments), including Hall sensor wiring, refer to the 3-Shunt Hall FOC Peripheral Configuration page in the Solutions section of the user guide.
Build Instructions
Import the project into your IDE (CCS or IAR)
Build the project using the default configuration
Connect the hardware and flash the device
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 (Ohm)Ls_d_H/Ls_q_H— D/Q-axis stator inductance (H)flux_VpHz/flux_Wb— Motor flux linkagenumPolePairs— Number of pole pairsratedCurrent_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 |
|---|---|
|
Start motor and trigger identification ( |
|
Pulse high to clear active fault register ( |
|
Speed setpoint in Hz ( |
|
Motor direction: 1.0 = forward, -1.0 = reverse ( |
|
Detect spinning rotor before start ( |
|
Startup mode: ALIGN / FREE ( |
|
Enable auto-restart after fault ( |
|
Enable Dead Time Compensation ( |
|
Enable Field Weakening Control ( |
|
Enable Maximum Torque Per Ampere ( |
|
Space vector modulation mode ( |
|
Pulse high to start Hall sensor bidirectional calibration ( |
Output Variables (motorVars.outVars) — FOC Outputs
Variable |
Purpose |
|---|---|
|
Current state machine state ( |
|
Active (raw) fault register ( |
|
Controller speed in Hz ( |
|
Controller speed in rad/s ( |
|
Stator current magnitude (A) ( |
|
Measured d/q currents (A) ( |
|
D/Q current reference (A) ( |
|
D/Q voltage command (V) ( |
|
FOC angle used by controller (rad) — reflects Hall angle ( |
|
Field weakening angle output (rad) ( |
|
MTPA angle output (rad) ( |
|
Estimated torque (N*m) ( |
|
Active power (W) ( |
Status Variables (motorVars.statusVars) — Internal Status
Variable |
Purpose |
|---|---|
|
Motor parameter identification complete ( |
|
Currently running identification and online mode ( |
|
Masked active fault register ( |
|
Previous fault register (fault history) ( |
|
Absolute speed magnitude (Hz) ( |
|
Observer angle — reflects Hall angle output (rad) ( |
|
Angle from Hall sector lookup (rad) ( |
|
Speed from Hall ECAP measurement (Hz) ( |
|
RMS phase currents — 3 phases (A) ( |
|
Restart attempts counter ( |
Set Variables (*motorVars.motorSetsHandle) — Tuning Setpoints
Variable |
Purpose |
|---|---|
|
Speed PI controller gains ( |
|
D-axis current PI gains ( |
|
Q-axis current PI gains ( |
|
Field weakening PI gains ( |
|
Maximum current limit (A) ( |
|
Over voltage fault threshold (V) ( |
|
Under voltage fault threshold (V) ( |
|
Over current threshold (A) ( |
|
Closed-loop max acceleration (Hz/s) ( |
For a detailed description of all motor data structures and runtime setpoints, see the Motor Data Structures page.
AM13E230X Peripheral Configuration
For detailed AM13E230X peripheral configuration including signal routing diagrams, ADC/PWM/CMPSS/Hall sensor/crossbar setup, and complete pin summary, refer to the 3-Shunt Hall FOC Peripheral Configuration page.