File Structure and Software Layers
This section describes the directory layout of the motor control solution, the role of each source file, and how SysConfig generates peripheral initialization code that ties the hardware to the application.
Software Layer Overview
The motor control software is organized into four layers. Each layer has a well-defined responsibility and communicates only with the layer directly above or below it.
Layer |
Files |
Responsibility |
|---|---|---|
Application Entry |
|
System init, ISR registration, background loop |
Application Library |
|
FOC algorithm, state machines, observers |
Motor Control HAL |
|
Hardware abstraction for ADC, PWM, gate driver |
SDK Driverlib + SysConfig |
|
Register-level peripheral access, generated init |
Directory Structure
solutions/motor_control/
├── ufoc_lp_bxl/
│ ├── 3sh_sen_less_foc_drv8323rh/ ← 3-shunt example (DRV8323RH gate driver)
│ │ ├── main.c ← System init, background loop
│ │ ├── isr.c ← ADC ISR → application_run()
│ │ ├── main.h ← System-level defines (LED, relay timing)
│ │ ├── README_<DEVICE>.md ← e.g. README_AM13E230X.md, README_AM13E232X.md
│ │ └── <device>_lp/m33_nortos/ ← e.g. am13e230x_lp, am13e232x_lp
│ │ ├── 3sh_sen_less_foc_drv8323rh*.syscfg ← SysConfig: ADC, PWM, CMPSS, UART
│ │ ├── ti_arm_clang/ ← CCS project files
│ │ └── iar_arm/ ← IAR project files
│ │
│ └── 1sh_sen_less_foc_drv8329a/ ← 1-shunt example (DRV8329A gate driver)
│ ├── main.c
│ ├── isr.c
│ ├── main.h
│ └── am13e230x_lp/m33_nortos/ ← AM13E230X only
│ └── 1sh_sen_less_foc_drv8329a.syscfg
│
└── common_files/ ← Shared across all motor control examples
├── app_lib/
│ ├── include/
│ │ ├── application.h ← ISR state machine, inline FOC helpers
│ │ ├── foc.h ← FOC feedback, observers, feedforward
│ │ ├── motor_common.h ← All motor structs, enums, fault flags
│ │ └── ti_tune.h ← TiTune parameter identification API
│ └── source/
│ ├── application.c ← application_run(), FOC_runLowPriorityStateMachine()
│ ├── motor_common.c ← Motor monitor, fault handling
│ └── ti_tune.c ← TiTune state machine implementation
│
├── hal/
│ ├── controller_interface/
│ │ ├── include/
│ │ │ ├── hal.h ← HAL public API (init, setParams, interrupts)
│ │ │ ├── hal_obj.h ← HAL object structure
│ │ │ └── hal_data.h ← ADC data, PWM data structures
│ │ └── source/
│ │ └── hal.c ← HAL_init(), HAL_setParams()
│ ├── foc_interface/
│ │ ├── include/
│ │ │ ├── hal_foc_interface.h ← HAL_FOC_Interface_t, ADC/PWM config
│ │ │ ├── hal_1sh_foc_interface.h ← 1-shunt current reconstruction
│ │ │ └── hal_3sh_foc_interface.h ← 3-shunt direct current reading
│ │ └── source/
│ │ ├── hal_1sh_foc_interface.c
│ │ └── hal_3sh_foc_interface.c
│ ├── gate_driver_interface/
│ │ ├── include/
│ │ │ └── hal_gate_driver.h ← HAL_GD_vTable_t vtable interface
│ │ ├── drv8323rh/
│ │ │ ├── drv8323rh_interface.h
│ │ │ └── drv8323rh_interface.c
│ │ └── drv8329a/
│ │ ├── drv8329a_interface.h
│ │ └── drv8329a_interface.c
│ └── communication_interface/
│ └── include/
│ └── hal_communication.h ← Serial plot (UART), DAC debug output
│
├── app_lib/
│ ├── include/
│ │ └── motor_params.h ← Motor_ParamsType: Rs, Ls, flux, poles
│ └── source/
│ └── motor_params.c ← Motor parameter tables (Teknic, Panasonic, ...)
│
ufoc_lp_bxl/<solution>/
├── system_config/
│ ├── user_mtr1.h ← Board constants: PWM freq, sense gains, limits
│ ├── mtr_config.h ← Aggregates user_mtr1.h + mtr1_init.h
│ ├── mtr1_init.h ← Global variable declarations, init prototypes
│ ├── mtr1_init.c ← initMotor1Handles(), initMotor1CtrlParameters()
│ ├── system_config.c ← HAL_FOC_Config_t, gate driver obj, interface instantiation
│ └── system_config.h ← extern declarations for all objects above
│
Key Source Files
Application Entry Point
File |
Purpose |
|---|---|
Calls |
|
Defines |
|
System timing constants: |
Application Library
File |
Purpose |
|---|---|
All state machine handlers as |
|
FOC algorithm sections: |
|
|
|
All motor data structures, enums ( |
|
TiTune API: |
Motor Configuration
File |
Purpose |
|---|---|
|
Board-level constants — PWM frequency, ISR tick ratios, current/voltage sense scale factors, over-current limits |
|
|
Motor parameter tables for supported motors; |
|
|
Global variable declarations ( |
|
Aggregation header — includes |
|
Hardware wiring file (3-shunt) — instantiates |
|
extern declarations for all objects in |
|
Hardware wiring file (1-shunt) — equivalent of the 3-shunt |
|
extern declarations for all objects in |
SysConfig Integration
SysConfig (.syscfg) is the graphical peripheral configuration tool. It generates
ti_sdk_dl_config.h and ti_sdk_dl_config.c which contain all peripheral initialization
code and symbolic macro names used throughout the motor control software.
What SysConfig Configures
Peripheral |
SysConfig Module |
Generated Macro Example |
|---|---|---|
ADC channels |
|
|
PWM (MCPWM) |
|
|
Comparator (CMPSS) |
|
|
ADC trigger |
|
|
UART (serial plot) |
|
|
GPIO (timing pin) |
|
|
ECAP (IPD) |
|
|
Startup Sequence
int main(void)
{
Device_Init(); // Clock, power domain init
SYSCFG_DL_init(); // All peripherals configured by SysConfig
HAL_disableGlobalInts();
halHandle = HAL_init(&hal, sizeof(hal)); // HAL wraps SysConfig handles
HAL_setParams(halHandle); // Apply motor-specific settings
// ...
}
SYSCFG_DL_init() is the single call that initializes every peripheral. The HAL layer
then wraps these peripheral handles with motor-control-specific logic.
1-Shunt vs 3-Shunt Topology
The two examples differ in how phase currents are measured. This affects the SysConfig configuration, the HAL FOC interface, and the gate driver.
Aspect |
3-Shunt |
1-Shunt |
|---|---|---|
ADC channels |
3 (Ia, Ib, Ic) |
1 (DC-link) |
CMPSS instances |
3 |
1 |
Current reconstruction |
Not needed |
Required (sample timing critical) |
HAL interface |
|
|
Gate driver |
DRV8323RH |
DRV8329A |
Include path |
|
|
The correct gate driver interface header directory must be added to the project’s include paths in CCS project settings (Project Properties → Build → Arm Compiler → Include Options).
The application code in motor_common.h uses CURRENTSEN_Type_e to select the
correct current reading path at runtime, while the HAL FOC interface files provide
the topology-specific HAL_ReadPhaseCurrents() implementation.