Spinning Brushless Motors with Simulink
Nukul Sehgal
Vamshi Kumbham
We will spin a brushless motor using Simulink and Model-Based
Design
2
Brushless motors are everywhere
3
Developing embedded motor control software has its challenges
Developing embedded motor control software has its challenges
▪ Design work needed to be started before
motor hardware was available and needed
extensive testing to comply with standards
▪ Team needed to rapidly implement control
software on embedded processor once more
hardware became available
▪ Complex algorithms running at high sample
rates were difficult to implement in short
amount of time
Why Simulink for motor control?
▪ Verify control algorithm with desktop
simulation
Customers routinely
▪ Generate compact and fast code from models report 50% faster
time to market
▪ Minimize development time using reference
examples
6
Motor Control Blockset simplifies the workflow
▪ Control blocks optimized for code
generation
▪ Sensor decoders and observers
▪ Motor parameter estimation
▪ Controller autotuning
▪ Reference examples
7
Brushless motors require complex algorithms – field-oriented
control Voltage
Supply
Control algorithm
𝑣𝐷𝐶
Physical system Inverse Park Transform
𝑖𝑑_𝑟𝑒𝑓 𝑣𝑑_𝑟𝑒𝑓 𝑣𝛼_𝑟𝑒𝑓
Current d,q Space
𝜔𝑟𝑒𝑓 Speed 𝑇𝑟𝑒𝑓 Current 𝑑𝑢𝑡𝑦 Power
Reference Vector 𝑐𝑦𝑐𝑙𝑒𝑠
Controller 𝑖𝑞_𝑟𝑒𝑓 Controller 𝑣𝑞_𝑟𝑒𝑓 Inverter
Generator 𝑣𝛽_𝑟𝑒𝑓 Generator
α,β
𝑖𝑑 𝑖𝑎
d,q
𝜔 𝜃𝑒 𝑖𝑏
𝑖𝑞
a,b
Sensor
Park, Clarke Transforms
decoders or PMSM
observers
8
Workflow for implementing field-oriented control
Model Design
Calibrate Estimate Deploy &
Motor & Control
Sensors Motor Validate
Inverter Algorithm
Parameters
We will use Texas Instruments motor control kit
Teknic 2310P
surface-mount PMSM
DRV8305 3-phase
inverter
TMS320F28379D
MCU
10
Sensor calibration
▪ Calibrate ADC offsets
11
Sensor calibration
▪ Calibrate ADC offsets
▪ Calibrate position sensor
offset
13
Parameter estimation
▪ Instrumented tests running
on the target
▪ Host model to start and
control parameter estimation
14
Bonus: you can use other techniques to parameterize motor models
From datasheet From ANSYS Maxwell, From dyno data
JMAG, Motor-CAD FEA tools
Simscape Electrical Simscape Electrical Powertrain Blockset
15
Modeling motor and inverter
▪ Use linear lumped-parameter
motor model
▪ Model inverter as an
average-value inverter or
model switching with
Simscape Electrical
16
Bonus: you can model at needed level of fidelity
Motor Control Blockset Simscape Electrical Simscape Electrical
Simscape Electrical
17
Control algorithm design
▪ Model field-oriented control
algorithm
▪ Model sensor decoders or
sensorless observers
▪ Tune loop gains
▪ Verify in closed-loop
simulation
18
Control algorithm design
▪ Model field-oriented control
algorithm
▪ Model sensor decoders or
sensorless observers
▪ Tune loop gains
▪ Verify in closed-loop
simulation
Control System Toolbox
19
Bonus: you can use several techniques to tune loop gains
Empirical Computation FOC Autotuner Classic Control Theory
Motor Control Blockset Motor Control Blockset and Simulink Control Design
Simulink Control Design
21
Control algorithm design
▪ Model field-oriented control
algorithm
▪ Model sensor decoders or
sensorless observers
▪ Tune loop gains
▪ Verify in closed-loop
simulation
22
Deployment
▪ Target any processor with
ANSI C code
▪ Use provided example to
partition the model into
algorithmic and
hardware-specific parts
▪ Generate algorithmic
code for integration into
embedded application
Algorithmic Code
23
Deployment
▪ Generate code (floating and
fixed-point)
▪ Use host model to control and
debug
▪ Validate on hardware
24
MathWorks Training Services:
Exploit the full potential of MathWorks products
Production Code Generation
Control
System
Design
Simulation Based Testing
Load tests Run test Results
You can verify and profile code using Processor-In-the-Loop testing
26
Bonus: you can target FPGAs as well
HDL Code Generation
27
Workflow for implementing field-oriented control
Model Design
Calibrate Estimate Deploy &
Motor & Control
Sensors Motor Validate
Inverter Algorithm
Parameters
ATB Technologies cuts electric motor controller development time
by 50% using code generation for TI’s C2000 MCU
Challenge
Develop control software to maximize the efficiency
and performance of a permanent magnet
synchronous motor
Solution
Use MathWorks tools for Model-Based Design to
model, simulate, and implement the control system
ATB Technologies permanent magnet
on a target processor synchronous motor.
Results
“MathWorks tools enabled us to verify the quality of our design at
▪ Development time cut in half
multiple stages of development, and to produce a high-quality
▪ Design reviews simplified component within a short time frame.”
▪ Target verification and deployment accelerated - Markus Schertler, ATB Technologies
Link to user story
Use Model-Based Design for your next motor control project!
▪ Verify control algorithm with desktop
simulation
▪ Generate compact and fast code from models
▪ Minimize development time using reference
examples, built-in algorithmic blocks,
automated parameter estimation, and gain-
tuning
30
Learn More
▪ Visit mathworks.com/products/motor-control
and mathworks.com/solutions/power-
electronics-control
▪ Get power electronics control design trial
package with necessary tools for desktop
modeling, simulation, control design, and
production code generation of your next
motor control project
As a follow up, in which area would you like to talk to us?
▪ Buy/Try the product
▪ Speak with our technical expert
▪ Training (Paid)
▪ Consulting (Paid)
▪ I am not ready for any of the above
32