1-Shunt Hall Sensored FOC motor control solution using the DRV8329A gate driver

Note

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

Overview

This solution demonstrates single-shunt Hall sensor-based Field Oriented Control (FOC) for PMSM/BLDC motors using the TI DRV8329A gate driver on the AM13E2X LaunchPad.

Key Features

  • Single DC-link current shunt sensing

  • 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

  • Real-time tuning support via TI Tune interface

Hardware Requirements

  • AM13E230X LaunchPad (LP-AM13E230X)

  • DRV8329AEVM 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 1-Shunt Hall 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 (Ohm)

  • 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 / FREE (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.svmMode

Space vector modulation mode (SVM_Mode_e)

motorVars.inputCtrl.flagStartHallCal

Pulse high to start Hall sensor bidirectional calibration (bool)

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) — reflects Hall angle (float32_t)

motorVars.outVars.angleFWC_rad

Field weakening 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.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.angleObs_rad

Observer angle — reflects Hall angle output (rad) (float32_t)

motorVars.statusVars.angleHall_rad

Angle from Hall sector lookup (rad) (float32_t)

motorVars.statusVars.speedHall_Hz

Speed from Hall ECAP measurement (Hz) (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.

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 1-Shunt Hall FOC Peripheral Configuration page.

References