model-based design for motor control development
DESCRIPTION
Developing motor control applications using model-based design and automatic code generation. By Paul Crook, Analog Devices, Inc.TRANSCRIPT
The World Leader in High Performance Signal Processing Solutions
Model-Based Design For Motor Control Development
Paul Crook – Analog Devices
2
Topics
Developing motor control applications using model-based design and automatic code generation
Hardware platform Model-Based Design overview Modeling of motor control systems Simulation and automatic code generation Running generic C-code on embedded platformWhen to use MBD and when to use “traditional” design
methods
3
ADI Demo Platforms
Motor Drive hardware 3 phase PM motor PC with MATLAB®, Simulink®, and IAR Embedded Workbench
4
HW Platform
100V-250V AC input with PFC, 5A Isolated current, position, voltage and diagnostic feedback 3-phase, 0.55kW, permanent magnet synchronous motor
5
ADSP-CM40x Embedded Target
Key PointsARM CORTEX M4F240MHzTwo 16-bit ADCs
380ns conversion time
SINC filter384kB SRAM2MB Flash20 DMA channelsPeripherals for
motor controlCommunication
interfaces
6
MODEL-BASED DESIGN
7
Why Model-Based Design?
• Requirements Development• System Simulation• Automatic Code Generation• Continuous Verification
8
The Traditional Design Process
Requirements Phase
Design Phase
Realization Phase
Testing Phase
9
Traditional Design of a Multi-Domain System
Integration, Test & Certification
Research & Requirements
Software
Requirements
Design
Realization
Testing
Hardware
Requirements
Design
Realization
Testing
Mechanical
Requirements
Design
Realization
Testing
10
The Cost of a Traditional Design Process
Source: ROI for IV&V, NASA
11
Model-Based Design
• Automate regression testing
• Detect design errors
• Parameter tuning
• Support certification and standards
• Generate efficient code
• Explore and optimize implementation tradeoffs
• Model multi-domain systems
• Explore and optimize system behavior in floating point and fixed point
• Collaborate across teams and continents
INTEGRATION
IMPLEMENTATION
DESIGN
TE
ST
& V
ER
IFIC
AT
ION
RESEARCH REQUIREMENTS
ARM
C, C++
Environment Models
Physical Components
Algorithms
12
Model-Based Design for Embedded System Development
Designwith
Simulation
ExecutableSpecifications
ContinuousTest and
Verification
AutomaticCode Generation
Models
Designwith
Simulation
ExecutableSpecifications
ContinuousTest and
Verification
AutomaticCode Generation
ModelsTest with Design- Detects errors earlier
Simulation- Reduces “real” prototypes- Iterative “what-if” analysis
Automatic code generation- Minimizes coding errors
Executable models- Unambiguous- “One Truth”
13
Steps in MBD approach
1. Plant modeling- Motor, load, power electronics etc.
2. Interface modeling- Sensors, device drivers
3. Controller modeling- Field oriented control of 3 phase PM motor
4. Analysis and synthesis- The models created in step 1-3 are used to identify dynamic
characteristics of the plant model.- Tuning and configuration of system
5. Validation and test- Offline simulation and/or real-time simulation- Time response of the dynamic system is investigated
6. Deployment to embedded target- Automatic code generation- Test and verification
14
Steps in MBD approach
Simulation of Controller and Plant model Off-line development of algorithms without access to HW Code generation and deployment to embedded controller Comparison between simulation and actual implementation
PC
Target
Controller Model
Motor/inverterModel
System Model
TestSignals Verify
CodeGeneration
Motor Drive System
System
Embedded Controller
Motor/inverter
HW
15
Model complexity
What is a good model?Represent the states of interestSupports automatic code generationExecute fastUse existing (trusted) librariesReusable across platforms
Too little Too much
?
Right balance
5
16
Model complexity
Understanding strengths and weaknesses of tools is critical when defining model scope
Strength
Weakness
- Solving differential equation- Time domain modeling- Visualization- Target specific setup- Managing system resources- Time scheduling
- Register setup and control- Managing System resources- Time scheduling- Real time control systems- Debugging and test- Visualization
17
Interfacing to Embedded Target
SW architectureGeneric C-code needs to be tied to embedded platformUtilizing strength of multiple environmentsGraphical environment for application code development“Classic” C-code for target specific control
Control Algorithm
Embedded Platform
HW interface layerPl
atfor
m
inde
pend
ent
Platf
orm
de
pend
ent
18
Interfacing Embedded Target
Two platforms – one implementationCommon control algorithm for Simulation and Embedded systemPlatform specific device drivers or behavioral models
Debug algorithm using simulation and test on embedded platform
19
Drive system feedback and control
Feedback
20
Motor Control Application Program
Power Inverter and Motor
Sensors, interfaces and Device Drivers
MC Algorithm
MC ‘C’ codeDevice driversApplication code
CC & LinkMC ApplicationFirmware
Device Driver
Aut
oco
de
21
AC Motor Algorithm (Field Oriented Control)
Shaft position sensor measures rotor magnet (flux) position – velocity is calculated. Two/three motor currents measured (two is enough). Clarke-Park transfer calculate Torque (Iq) and Flux (Id) components of current. Speed loop generates Iq reference; Id reference set to zero for PMSM. Current loops and Field alignment generates a,b,c voltage commands.
22
Field oriented control
23
Simulation
0 1000 2000 3000 4000 5000-250
-200
-150
-100
-50
0
Frequency [kHz]
Mag
nitu
de
[dB
]
0 1000 2000 3000 4000 5000-3000
-2000
-1000
0
Frequency [kHz]
Pha
se [
Deg
rees
]
Simulink scopes Code debugging
Data analysis in MATLAB
24
Generating C-code
25
Building and Linking – IAR EWB
26
Building and Linking
Workbench
Matlab/Simulink
Motor Control- FOC functions
ARM Library- M3/M4 support
Executable
C-code
Device drivers- SW enablement package
Application code- State machines
Scheduling- IRQs/RTOS
C-code C-code
Device Drivers- Functional model
System resources- Allocation & setup
Legacy code- Existing code
CM40x
27
Running target
MATLAB GUI + embedded engineStreaming data back to MATLAB
0 20 40 60 80 100 120 140 160 180 200-1000
-500
0
500
1000
Dut
y-cy
cle
Captured runtime data
0 20 40 60 80 100 120 140 160 180 2002.5
3
3.5
4x 10
4
Pha
se c
urr
en
t
0 20 40 60 80 100 120 140 160 180 2000
2
4
6
8R
oto
r a
ng
le
Sample number
28
Sampling domains
10 kHz
1 kHz
29
Summary
Model-Based DesignSystem modeling and simulationAutomatic code generation
Modeling of motor control systemsElectronics/mechanicalInterfacesControl algorithm
Interfacing generic C-code to embedded targetUse of different environmentsDevice drivers
Debugging and testOff-lineIn real-time
30
Questions