PUBLIC USE
EDUARDO VIRAMONTES
MOTOR CONTROL SYSTEM ENGINEER
SESSION #FTF-SMI-N2008
18, MAY, 2016
MOTOR CONTROL
HANDS-ON WORKSHOP
PUBLIC USE1 #NXPFTF PUBLIC USE1 #NXPFTF
AGENDA
• Intro to KV series
• What is FOC?
• How is FOC implemented?
• Enablement and reference designs
• Using MCAT to tune and spin a motor
• Model-based design with Mathworks Simulink and the
Motor Control Toolbox
PUBLIC USE2 #NXPFTF
Kinetis V series MCUs Based on ARM® Cortex® Cores For Motor Control & Digital Power Conversion
• NXP’s extensive motor and power control expertise and the latest ARM Cortex-M0+, M4 and M7 cores bring secure, connected, high efficiency motor control and power conversion to the mass market
• Efficient, next generation BLDC, PMSM and ACIM designs are enabled by optimized MCU performance and high speed/resolution analog and timing peripherals. High resolution eFlexPWMs support digital power conversion
• Performance and feature scalable MCU families from entry-level 75MHz MCUs, to advanced 240MHz MCUs, maximize hardware & software reuse and end product flexibility
• Enablement including NXP Tower and Freedom development boards, Embedded Software Libraries and Kinetis motor suite reduce motor control learning curve and speed time to market
PUBLIC USE3 #NXPFTF
New Levels of Performance, Reliability and Power Efficiency
for Motor Control and Digital Power Conversion
NXP IDE, RTOS, Software Libraries and Motor Control Development Tools
2016
2014
KV1x MCU FamilyBLDC, entry-level PMSM
ARM® Cortex® -M0+
Feature Integration
+ Motor Control Software
+ Multi Channel Timers
+ Floating Point Unit
+ High Speed ADC
+ High Resolution PWM
+ Advanced Memory,
Connectivity and CommunicationsKV5x MCU Family
High-performance single/multi motor
systems with connectivity & security.
Advanced digital power conversion
ARM Cortex-M7
Pe
rfo
rma
nce
2014
KV3x MCU FamilyMid-range PMSM, UPS power control
ARM Cortex-M4
2015
KV4x MCU FamilyHigh-performance motors, UPS, solar
and mid-range AC/DC control
ARM Cortex-M4
PUBLIC USE4 #NXPFTF
Kinetis V Series: Performance and Feature Scalability
Core
168MHz
CM4
DSP + FPU
100/120MHz
CM4
DSP + FPU
75MHz
CM0+
H/W DIV & SQRT
Memory
64-256kB Flash
64-512kB Flash
16-128kB
Flash
Flextimer
2 x 8ch
1x 2ch
FlexTimer
2x 8ch
2x 2ch
FlexTimer
2x 6ch
2x 2ch
FlexTimer
eFlexPWM
12ch eFlexPWM
+ Nano-Edge
-
-
ADC
2x 12bit
4.1Msps
2x 16-bit
1.2Msps
2x 16-bit
1.2Msps
DAC
2x 12-bit
2x 12-bit
1x 12-bit
ACMP
4x ACMP
with
6-bit DAC
2x ACMP
with
6-bit DAC
2x ACMP
with
6-bit DAC
Packages
100 pin 64 pin 48 pin
100 pin 64 pin 48 pin 32 pin
64 pin 48 pin 32 pin
KV4x
KV3x
Scalable performance, timing and analog functionality
based on application need
Key Peripherals for Motor and Power Control Applications
KV1x
MCU
Family
240MHz
CM7
DSP + FPU
512kB-1MB Flash
2 x 8ch
1x 2ch
FlexTimer
2 x 12ch eFlexPWM
+ Nano-Edge
4 x 12bit
5Msps,
1 x 16bit
1x 12-bit
4x ACMP
with
6-bit DAC
144 pin 100 pinKV5x
Comms.
Ethernet,
3 x CAN
-
1 x CAN
2 x CAN
Motor Control Timers
PUBLIC USE5 #NXPFTF
Perf
orm
an
ce
Q1 Q2
75
MHz
100
MHz
120
MHz
160
MHz
240
MHz
Kinetis V Series Availability Roadmap
Beyond
Q3 Q1 Q2Q4
2014 2015
KV10
Cortex M0+
32KB
KV3x
Cortex M4
64/128kB
KV3x
Cortex M4
256/512kB
Q4
2016
KV11
Cortex-M0+
64/128kB, CAN
KV10
Cortex-M0+,
64/128kB
KV4x
Cortex M4
64/128/256kB, CAN
KV3x KMS
Cortex M4
256/512kB
KV3x KMS
Cortex M4
64/128kB
KV5x
Cortex M7
512kB/1MB, CAN, E’net
PUBLIC USE6 #NXPFTF
Kinetis V – Target Applications
KV1x KV3x KV5xKV4x
Industrial Real Time Control
BLDC Motors – FOC; Sensorless & Sensor’d
Low Dynamic PMSM FOC High Dynamic PMSM FOC
1 or 2 BLDC Motors Up to 4 x BLDC Motors
1 PMSM Motor
FOC ACIM
Power Control:
UPS, SMPS, Photo Voltaic
Up to 8 x BLDC Motors
Up to 2 x PMSM Motors Up to 4 x PMSM Motors
Up to 2 x FOC ACIM
PUBLIC USE7 #NXPFTF
Kinetis V Series KV1x: Block Diagram
Core/System
• 75MHz Cortex-M0+ with
• Hardware Divide & Square
Root
• 4ch DMA
Memory
• 16/32/64/128KB Flash
• 8/16KB SRAM
• Option with FAC
• Communications
• Multiple serial ports
+ 1 FlexCAN*
Analog
• 2 x 8ch 16-bit ADC
• 1.2Msps in 12-bit mode
(835ns)
• 1 x12-bit DAC
• 2 x ACMP with 6-bit DAC
Timers
• Up to 2x6ch FlexTimer (PWM)*
• Up to 4x2ch FlexTimer
(PWM/Quad Dec.)
• Low Power Timer
Other
• 32-bit CRC
• Up to 54 GPIO
• 1.71V-3.6V; -40 to 105C
Packages
• 32QFN, *32LQFP,
48LQFP, 64LQFP
• * Package Your Way
Debug
Interfaces
H/W Divide
& Square
Root
Interrupt
Controller
ARM Cortex-M0+
75 MHz
Internal and
External
Watchdogs
4ch-DMA Flash
Up to 128KB
SRAM
Up to 16KB
Frequency-
Locked
Loop
Low/High
Frequency
Oscillators
Internal
Reference
Clocks
Cyclic
Redundanc
y
Check
(CRC)
2 x16-bit
ADC
2 x ACMP
w/ 6b DAC
1 x12-bit
DAC
FlexTimers
Programmabl
e
Delay Block
Low-
Power
Timer
1xI2C
1xSPI
2xUARTs
GPIO
Core System Memories Clocks
Security
and Integrity
Analog Timers Communication Interfaces HMI
Flash
Access
Controller*
MTB
BMELow
Leakage
Wake-up
Unit
1x
FlexCAN
*Optional
V Ref
FlexTimer
s
Unique ID
From $0.90 to $1.56 @ 10k units
PUBLIC USE8 #NXPFTF
Kinetis V Series KV3x: Block Diagram
Core/System
• Cortex-M4 @ 100/120MHz with FPU
• 4 or 16ch DMA
Memory
• 64/128/256/512KB Flash,
• 16/24/48/96KB SRAM
• FlexBus (512KB version only)
Bootloader
• Communications
• Multiple serial ports
Analog
• 2 x16-bit ADC: 1.2Msps in 12-bit mode
• Up to 2 x12-bit DAC
• 2 x ACMP with 6-bit DAC
Timers
• Up to 2x8ch FTM (PWM)
• 2x2ch FTM (PWM/Quad Dec.)
• Programmable Delay Block
• Low Power Timer
Other
• Up to 70 I/Os
• 6 high-drive I/Os (20mA) –SPI/I2C
• 1.71V-3.6V; -40 to 105C
Packages
• 32QFN, *48LQFP, 64/100LQFP
• *Alternative, non committed package
Debug
InterfacesDSP
Interrupt
Controller
ARM Cortex-M4
100/120MHz
Internal &
External
Watchdogs
4/16ch-
DMA
Low-Leakage
Wake-Up Unit
Program Flash
Up to 512K
SRAM
up to 96KB
Serial
Programming
Interface
(Export)
Phase-Locked
Loop
Frequency-
Locked Loop
Low/High
Frequency
Oscillators
Internal
Reference
Clocks
Cyclic
Redundancy
Check
2 x 16-bit
ADC
2 x ACMP
w/ 6b DAC
Up to 2 x
12-bit DAC
FlexTimers
Programmable
Delay Block
Periodic
Interrupt
Timer
Low Power
Timer
2 x I2C
2 x DSPI
4 x UARTs
GPIO
Core System Memories Clocks
Security
and Integrity
Analog Timers Communication Interfaces HMI
FlexBus
External
Bus
Interface
FPUBOOT Flash
Flash Access
Controller V Ref
SRAM
Retention
Optional
Unique ID
From $1.19 to $2.76 @ 10k units
PUBLIC USE9 #NXPFTF
Kinetis V Series KV4x: Block Diagram
Core/System
• 168MHz Cortex-M4, FPU
Memory
• 64/128/256KB Flash @ 128bits
wide w/ 128Byte cache
• 16/24/32KB SRAM
• Bootloader
Communications
• Multiple serial ports
• Up to 2 x CAN
Analog
• 2 x 8ch 12-bit ADC
˗ Sampling at up to
4.1MS/s
˗ PGA x1, x2, x4
• 12-bit DAC
• 4 x ACMP with 6-bit DAC
Timers
• Up to 12ch eFlexPWM
˗ Up to 312ps PWM and PFM
Resolution
• 2x8ch + 1x2ch FlexTimer
(PWM)
• Quadrature Encoder
•2 x Programmable Delay Blocks
Other
• 32-bit CRC
• Inter-Peripheral Crossbar with
AND/OR interface
• Up to 56 I/Os
• 1.71V-3.6V; -40 to 105oC
Packages
• *48LQFP, 64 LQFP &
100LQFP
• *Alternative, non committed
package
Debug
InterfacesDSP
Interrupt
Controller
ARM Cortex-M4
168MHz
Internal &
External
Watchdogs
16ch-DMA
Inter-
Peripheral
Crossbar
Program
Flash
Up to 256KB
SRAM
Up to 32KB
Phase &
Frequency-
Locked Loop
Low/High
Frequency
Oscillators
Internal
Reference
Clocks
Cyclic
Redundancy
Check
2 x 12-bit
ADC
w//PGA
4 x ACMP
1 x 12-bit
DAC
FlexTimers
Programmab
le
Delay Block
Periodic
Interrupt
Timers
1xI2C
1xSPI
2xUARTs
GPIO
Core System Memories Clocks
Security
and Integrity
Analog Timers Communication Interfaces HMI
2x CAN12ch
eFlexPWM
Quad
Encoder/
Decoder
Flash Access
Controller
BOOT Flash
FPU
SRAM
Retention
Low-Leakage
Wake-Up Unit
Unique ID
Low-Power
Timer
V Ref
From $2.19 to $3.41 @ 10k units
PUBLIC USE10 #NXPFTF
Kinetis KV5x MCU Family
Key Features:
• Core/System
• 240MHz Cortex-M7 with FPU and 32ch DMA
• 16KB Instruction Cache / 8KB Data Cache
Memory
• 512KB/1MB Flash, 256bits wide, 128 Bytes cache
• 128/256KB SRAM
Boot Flash
• Communications
• Multiple serial ports
• 3 x FlexCAN
Analog
• 4 x 8ch 12-bit ADC
− 5Msps Sample Time
• 1 x 16-bit SAR ADC
• 1 x12-bit DAC
• 4 x ACMP w/ 6b DAC
Timers
• 1 x 12ch eFlexPWM
− 312ps PWM and PFM Resolution
• 1 x 12ch eFlexPWM
• 2x8ch FlexTimer (PWM)
• 2x2ch FlexTimer (PWM)
• Quadrature Encoder
• 2 x Programmable Delay Blocks
• Low-Power Timer
Others
• MMCAU & RNG
• 32-bit CRC
• Inter-module Crossbar Switch with AOI
• Memory Protection Unit
• 1.71V-3.6V; -40 to 105oC
Packages
• 100LQFP, 144LQFP, 144MAPBGA
• V Temp (105C) : 240MHz Optional
Debug /
InterruptsDSP
MPU
ARM Cortex-M7
240MHz
Internal and
External
Watchdogs
32ch-DMA
Inter-Module
Crossbar
Program Flash
1MB
SRAM
256KB
Phase &
Frequency-
Locked Loop
Low/High
Frequency
Oscillators
Internal
Reference
Clocks
Cyclic
Redundancy
Check (CRC)
4 x12-bit
SAR ADC
4 x ACMP
1 x12-bit
DAC
2x8ch
FlexTimer
2x PDB
PIT
2xI2C
3xSPI
6xUARTs
GPIO
Core System Memories Clocks
Security
and Integrity
Analog Timers Communication Interfaces HMI
2x2ch
FlexTimer
3x CAN2x12ch
eFlexPWM
Quad
Encoder
BOOT Flash
FPU
External Bus
Interface
(FlexBus)
8KB D Cache
16KB I Cache System MPU
IEEE 1588
Ethernet MACMMCAU
RNG 1 x16-bit
SAR ADC
From $4.49 to $6.70 @ 10k units
Qualified now and in production now. Launching June.
PUBLIC USE11 #NXPFTF
Kinetis V Series Package Scalability
Fla
sh
Me
mo
ry
32LQFP 48LQFP32QFN 64 LQFP 100 LQFP
KV4x
KV3x
KV1xKV1x KV1x
KV3x KV3x
KV3x
KV3x KV3x KV3x
KV4x KV4x
KV3x KV3x
KV4x KV4x
KV3x KV3x
Package
128KB
64KB
16/32KB
256KB
512KB
KV4x
KV4x
144
QFP/MAPBGA
KV5xKV5x
KV1x
1MBKV5xKV5x
KV1x
KV1x KV1x KV1x
KV1x KV1x
PUBLIC USE13 #NXPFTF
Kinetis V Series Enablement
• AIM: Simply to enable our customers to get their product to market quicker
• The right MCU for your application;
• The right DEVELOPMENT SYSTEM for your budget;
• The right SOFTWARE for your level of experience or background
PUBLIC USE14 #NXPFTF
Low Cost Reference Platforms: Hardware + SoftwareBLDC & PMSM
FRDM-KV31F: $20
FRDM-KV10Z: $20
FRDM-MC-LVPMSM: $50
− PMSM (Sinusoidal) control
− 24V, 5Amp, 120W
FRDM-MC-LVBLDC: $30
− BLDC (Trapezoidal) control
− 12V, 5Amp, 60W
FRDM-MC-LVMTR: $35
− 4000RPM, 90W
Or Your Motor
Complete
Reference
Design From $85 ?
Kinetis Motor
Suite
Kinetis
Reference
Design
Motor Control
Toolbox
Software Platform’s Supported
PUBLIC USE15 #NXPFTF
Tower Reference Platform: Hardware + SoftwareBLDC & PMSM
TWR
Reference
Design From $485
TWR-KV11Z75M
TWR-KV31F120M
TWR-KV46F150M
TWR-KV58F220M
TWR-MC-LV3PH
− PMSM (Sinusoidal) &
− BLDC (Trapezoidal) control
− Includes Motor
TWR-ELEV
Kinetis Motor
Suite
Kinetis
Reference
Design
Motor Control
Toolbox
Software Platform’s Supported
PUBLIC USE16 #NXPFTF
High Voltage Reference Platform: Hardware + SoftwareACIM, BLDC & PMSM
HVP-MC3PH
includes HVP-KV46F150M card
85/230 volt,
1KW 3-ph motor control inverter
inc PFC circuitry
Your motor
High Voltage
Reference
Design
From $600?
Controller CardHVP-KV10Z32
HVP-KV11Z75M
HVP-KV31F120M
HVP-KV58F220M
Kinetis Motor
Suite
Kinetis
Reference
Design
Motor Control
Toolbox
Software Platform’s Supported
PUBLIC USE17 #NXPFTF
Motor Control Software Enablement
Most Efficient Design
• For customers who have
− limited experience of motor control or
− a limited time to market.
− budget constraints
• Focuses on delivering
− ease of use
− IP that can quickly improve efficiency
• Simple Graphical Interface for ALL
configuration, tuning and initial application
development.
• System manages as much of the
development as possible
• Tight integration with toolchain simplifying
development
• www.nxp.com/kinetismotorsuite
• For customer who have:
− Expert level of knowledge
− Ability and time to tune motor efficiently
• Focuses on delivering
− best in class motor control efficiency
− highest rated motor performance
− Integration with NXP’s IEC60730 safety
software
• Graphical Interface for motor parameter
reading
• Leverages experience and IP developed
working with OEMs to provide high
efficiency
• System solution not just library functions of
motor functions.
• www.nxp.com/kinetisdesigns
Easy & Fast Design Model Based Design
• For customer who have:
− Demand to use model based design
− Limited time to market
• Focuses on delivering
− Model to MCU code development efficiency.
− Excellent rate motor perfromance
− Integration with NXP’s Embedded Software
Librariy and FreeMASTER tool.
• Model based development environment that
automatically generates MCU Targets
software.
• Leverage the industry standard in Model
Based design - MATLAB
• Integration with NXP’s Motor Control
toolchain;
• www.nxp.com/motorcontroltoolbox
PUBLIC USE18 #NXPFTF
Motor Control Software Enablement
Kinetis Reference
Software
• Intuitive development solution that enables
the design of sensored and sensorless
BLDC & PMSM motor control applications
quickly and efficiently via a simple graphical
user interface.
• Automated motor and system inertia
identification.
• Single Parameter to tune motor response.
• Disturbance rejection control algorithm
ensures high performance even in highly
dynamic operating conditions
• Cost: Starts at $1.60 inc. MCU & SW
• KV3x supported today, others in 2016
• www.nxp.com/kms
• Sensorless FOC BLDC, PMSM & ACIM
Supported today
• Complete Software Solutions built on NXP
Embedded Software Libraries.
• Libraries of software algorithms for Math,
Motor Control, Power Conversion, Filters
and Advanced functions. ~200 algorithms
available
• Cost: free of charge
• All Kinetis V MCU’s are supported today
• www.nxp.com/kinetisdesigns
Kinetis Motor Suite
• MCU Targets for MATLAB™/Simulink™
modelling environment
• Motor control plug-in tool for automatic code
generation.
• Supports multiple compilers. FreeMASTER
compatible.
• Incorporates NXP ESL
• Cost: $8K license
• All Kinetis V MCU’s are supported today
• www.nxp.com/motorcontroltoolbox
Motor Control Toolbox
Easy & Fast Design Most Efficient Design Model Based Design
PUBLIC USE19 #NXPFTF
S/w Enablement Guide
FreeMASTER
• GUI based FreeMASTER plug-in tool that provides real-time monitoring, tuning and updating of motor control system parameters
• Provided as a plug-in for the FreeMASTER tool. Designed to work with FSL Ref. Design s/w
• http://www.youtube.com/watch?v=ZsLQzSTnhgo
• Cost: free of charge
• Supported devices
− KV1x, KV3x, KV4x, KV5x
• Complimentary GUI based run-time debug monitor and data visualization tool
• Replaces debugger in situations when the core can not be simply stopped, ideal for motor control and power conversion application development
• http://www.youtube.com/watch?v=vKVlxu8ecdg
• Cost: free of charge
• Supported devices
− KV1x, KV3x, KV4x, KV5x
MCAT
(Motor Control
Application Tuner)
• SDK – a complete software
framework for developing
applications across all Kinetis
MCUs. h/w abstraction, peripheral
drivers, stacks, RTOS’s, utilities,
and usage examples; delivered in C
source
• Processor Expert – GUI Eclipse
plug-in tool for creating and
configuring software and peripheral
drivers quickly & easily
• Cost: free of charge
• Supported devices
− KV1x, KV3x & KV4, KV5x
Kinetis SDK &
Processor Expert
Code Generator
MQX RTOS /
FreeRTOS
• Commercial-grade MCU
software platform at no cost
with optional support packages
• RTOS Kernel, Real Time
TCP/IP Communication Suite,
File System, USB Host/Device
Stack and Board Support
Packages
• Cost: free of charge
• Supported devices
− KV1x, KV3x , KV4x & KV5x
PUBLIC USE20 #NXPFTF
WHAT ARE NXP’S MOTOR
CONTROL REFERENCE
DESIGNS?NXP.COM/KINETISDESIGNS
PUBLIC USE21 #NXPFTF
Motor Control Reference SolutionsBuilding on FSL Embedded Software Libraries
Motor
Topology
Product
Supported
HW
Platform
Target Applications Availability
PMSM Sensorless
FOC
KV1x, KV3x, KV4x, TWR
HVP
FRDM
General drives, Pumps Now
BLDC Sensorless
Trapezoidal
KV1x TWR
FRDM
HVP
Fan, Pumps Now
ACIM Sensorless
FOC
KV3x, KV4x, KV5x HVP Pumps, Fan Now
Dual BLDC
Trapezoidal
Control
KV11 TWR Appliances Now
Dual PMSM
Sensorless FOC
KV5x TWR
HVP
Iot Motor Control Now
PUBLIC USE22 #NXPFTF
Development tools
Hardware KitsFreeMASTER
Watch & Update
variables
Scope & Recorder
Direct Flash Write
Real time debug
IAR
Keil
Coding Applic. Config/DebugEmbedded
Math, Filters, Motor Control Algo library
Custo
me
r co
de
Motor Start-up
Motor Ctrl. Ref. FrameworkPMSM, BLDC, ACIM, SRM
Motor Parameters
Identification
Motor Control Reference Solution
KDS
MCAT
Tuning Control
Parameters
Application Config
& Set-up
Easy-to-Use & Expert
modes
60730 Safety
Applic. Specific Code
(washer, fan…)
Connectivity
Kinetis SDK 2.0
Fault Protection Data
ClockTool
PinMux Tool
PUBLIC USE23 #NXPFTF
NXP Embedded Software Libraries• Libraries of s/w algorithms for Math, Motor Control, Power Conversion, Filters and Advanced functions
• Supports Kinetis MCUs, DSCs and key compilers (CW, KDS, IAR, Keil)
• Algorithms tested extensively through MATLAB Simulink reference models
• Version 4.0 includes optimized M0+ libraries for Motor Control, and the new Power Conversion Library
• Version 4.1 added H/W Sqr & Div capability for KV10 & KV11
• Version 4.2 added support for the CM7 core – available now
• Version 4.3 added support for the ACIM and SDK 2.0 integration – available Q3 2016
• Free of charge : Binary code released through FSL website
www.nxp.com/fslesl
PUBLIC USE24 #NXPFTF
Math Library (MLIB)
•Simple math functions (addition, subtraction, multiplication, division, shifts...) with
and without saturation. Efficient, fast mathematics built on the MCU’s instructions.
General Function Library (GFLIB)
•Basic building blocks of a real-time control application. Functions for basic
mathematical calculations, trigonometric functions, simple look-up table and control
functions such as PI and PID controllers.
General Motor Control Library (GMCLIB)
•Fundamental functional blocks of a motor control application including vector
modulation, Park and Clarke transformations and specific functions to build digitally
controlled motor drives.
General Digital Filter Library (GDFLIB)
•Includes filter functions for signal conditioning.
Advanced Motor Control Library (AMCLIB)
•Functions that enable the construction of a variable speed, AC motor drive system
that implements FOC techniques without position or speed sensors to provide the
lowest cost solution.
Power Control Library (PCLIB)
•Control loop algorithms required in Power Control applications.
Library Structure
-2
-1
0
1
2
-1.5 -1 -0.5 0 0.5 1 1.5
y=sin(x), z=cos(x)
PUBLIC USE25 #NXPFTF
IEC/UL 60730 & 60335 Appliance Safety
Features Supported Tests Devices Supported
(certified at VDE and UL)
“After-Reset operation”
Registers, PC,
RAM, Flash,
Clock, Stack, I/O
KV1x, KV3x, 4x, 5x, KL, KE
DSC
“Run-Time” operation
Self-diagnostics
I/O peripheral tests
• Libraries of core self-test routines per IEC/UL 60730 & 60335 (Class B)
• Supports DSC and Kinetis KV1x/4x/7x cores and key compilers
• Core self tests certified at VDE and UL
PUBLIC USE26 #NXPFTF
Motor Control Reference Framework
• Open Source Reference Frameworks for key motor control topologies for Kinetis KV & KE
• Include easy-to-use tuning tools for parameters identification, configuration and tuning
• Allow seamless integration of customer code
• RTCESL (Embedded Control Libraries) based control algorithms
• SDK 2.0 example integration
• Supported sensorless motor control algorithms for PMSM, ACIM, BLDC
• Supported IDEs: IAR, KDS, Keil
• Supported HW boards: Freedom, Tower, High voltage board
• MCAT tool for motor parameter tuning and setting
• FreeMASTER online monitor and debugging tool
• Reference FreeRTOS based solution – see demo in FTF Tech lab
Hardware Kits
Math, Filters, Motor Control Algo library
Custo
me
r co
de
Motor Start-up
Motor Ctrl. Ref. FrameworkPMSM, BLDC, ACIM, SRM
Motor Parameters
Identification
60730 Safety
Applic. Specific Code
(washer, fan…)
Connectivity
Kinetis SDK 2.0
Fault Protection
PUBLIC USE27 #NXPFTF
Motor control solutions: sensorless trapezoidal control
• 6 step control is ideal for lower-cost brushless DC motors designed to have
trapezoidal back EMF
• Basic application includes speed control
and current limiting
• MCAT tool allows simple identification
of critical parameter and tuning
PUBLIC USE28 #NXPFTF
Motor control solutions: sensorless trapezoidal control
• The simplest 3-phase control technique.
• Ideal for speed control applications using simple brushless DC motors where
torque ripple or slightly increased acoustic noise is not an issue.
• Example applications:
− Consumer-level quadcopters
− Blowers
− Low-cost blenders
30º 60º 90º 120º 150º 180º 210º 240º 270º 300º 330º Electricalangle
Voltage
Phase A
Phase B
Phase C
+UDCB
-UDCB
+UDCB
-UDCB
+UDCB
-UDCB
PUBLIC USE29 #NXPFTF
BLDC Motor Control Reference Framework
• Six-step communication process
• Close-loop speed control
• Dynamic motor current limitation
• Commutation event calculation using integration method
• FreeMASTER control page
• MCAT for motor parameter setting and tuning
PUBLIC USE30 #NXPFTF
BLDC Motor Control Reference Enablement
• Desing reference manual DRM144
• Application note AN5263 – Sensorless BLDC Control on Kinetis KV
• Application software package MCRSP-BLDC
• Supported development boards:
o FRDM-KV10Z + FRDM-MC-LVBLDC
o FRDM-KV31F + FRDM-MC-LVBLDC
o TWR-KV10Z + TWR-MC-LV3PH
o TWR-KV11Z + TWR-MC-LV3PH
o TWR-KV31F + TWR-MC-LV3PH
o TWR-KV46F + TWR-MC-LV3PH
o TWR-KV58F + TWR-MC-LV3PH
o HVP-KV10Z + HVP-MC3PH
o HVP-KV31F + HVP-MC3PH
o HVP-KV46F + HVP-MC3PH
o HVP-KV58F + HVP-MC3PH
For more information go to:
nxp.com/motorcontrol_bldc
PUBLIC USE31 #NXPFTF
Sensorless FOC for permanent magnet motors
• Field oriented control (FOC) provides an increased amount of torque and speed control
• Ideal for applications that require smooth torque operation, varying levels of torque control
and limiting
• Example applications:
− Washing machines and other advanced appliances
− Medical instrumentation
− Variable speed cordless drills
− High-inertia fans
− Electric vehicles
PUBLIC USE32 #NXPFTF
Sensorless FOC for permanent magnet motors
• FOC is an extremely complicated control
technique.
• Current is the main control variable.
• Current sine waveforms are
mathematically transformed from a 3-
phase system to a 2 signal direct system.
• The 2 signals are called d and q and
represent magnetic flux and torque,
allowing for unprecedented control.
• Speed of the motor is an additional control
loop that controls the required d and q
values.
The “d” axis refersto the “direct” axisof the rotor flux
The “q” axis is the axismotor torque along
which the stator fieldmust be developed
Axis of phase c
+a
+b
-b
+c
-c
Axis of phase a
Axis of phase b
Stator windingsRotor made from
permanent magnets
-a
Rotation
N
S
PUBLIC USE33 #NXPFTF
Permanent Magnet Synchronous Motor (PMSM) Control
Reference Framework• Field oriented control (FOC)
• Close-loop speed control
• Extended Back-EMF Observer estimating motor speed
and position
• FreeMASTER control page
• MCAT for motor parameter setting and tuning
• Two application types: Demo & Full featured reference
code
• Electrical motor parameters estimation
• Control modes enabling advanced motor tuning:
o Scalar
o Voltage FOC
o Current FOC
o Speed FOC
PUBLIC USE34 #NXPFTF
PMSM Control Reference Enablement
• Desing reference manual DRM148
• Application note AN5237– Sensorless BLDC Control on Kinetis KV
• Application software package MCRSP-PMSM
• MC FreeRTOS demo application based on FRDM-KV31
• Visit Tech lab to see the demo
• Supported development boards:
o FRDM-KV10Z + FRDM-MC-LVBLDC
o FRDM-KV31F + FRDM-MC-LVBLDC
o TWR-KV10Z + TWR-MC-LV3PH
o TWR-KV11Z + TWR-MC-LV3PH
o TWR-KV31F + TWR-MC-LV3PH
o TWR-KV46F + TWR-MC-LV3PH
o TWR-KV58F + TWR-MC-LV3PH
o HVP-KV10Z + HVP-MC3PH
o HVP-KV31F + HVP-MC3PH
o HVP-KV46F + HVP-MC3PH
o HVP-KV58F + HVP-MC3PH
For more information go to:
nxp.com/motorcontrol_pmsm
PUBLIC USE35 #NXPFTF
Sensorless FOC for AC induction motors
• Field oriented control (FOC) provides an increased amount of torque and speed control
• Induction motors have an added layer of complexity as their electric field is asynchronous to the rotor
• Example applications:
− Driers
− Furnace blowers
− Industrial mixers
− Industrial AC
PUBLIC USE36 #NXPFTF
AC Induction Motor Slip
rotating Field (s)
Torquer
Induced current
Basic Principle: The stator is a classic three-phase
stator with the winding displaced by 120°
The rotor is a squirrel cage rotor in which bars are shorted together at both ends of the rotor by cast aluminum end rings
The rotor currents are induced by stator magnetic field.
The motor torque is generated by an interaction between the
stator magnetic field and induced rotor magnetic field
NO BRUSHES, NO PERMANENT MAGNETS, LOWER COST
PUBLIC USE37 #NXPFTF
AC Induction Motor (ACIM) Control Reference Framework
• Field oriented control (FOC)
• Close-loop speed control
• ACIM rotor flux observer
• Model reference adaptive system (MRAS)
• FreeMASTER control page
• MCAT for motor parameter setting and tuning
• Two application types: Demo & Full featured reference
code
• Full motor parameters estimation (electrical &
mechanical)
• Control modes enabling advanced motor tuning:
o Scalar
o Voltage FOC
o Current FOC
o Speed FOC
PUBLIC USE38 #NXPFTF
ACIM Control Reference Enablement
• Desing reference manual DRM150
• Application note AN5051– Sensorless ACIM Control on Kinetis KV
• Application software package MCRSP-ACIM
• Visit Tech lab to see the HVP-KV31F based demo
• Supported development boards:
o HVP-KV31F + HVP-MC3PH
o HVP-KV46F + HVP-MC3PH
o HVP-KV58F + HVP-MC3PH
For more information go to:
nxp.com/motorcontrol_acim
• Desing reference manual DRM150
• Application software package MCRSP-ACIM
• Visit Tech lab to see the HVP-KV31F based demo
• Supported development boards:
o HVP-KV31F + HVP-MC3PH
o HVP-KV46F + HVP-MC3PH
o HVP-KV58F + HVP-MC3PH
PUBLIC USE39 #NXPFTF
MCAT Tool key features:
• user-friendly and intuitive graphical plug-in
tool for FreeMASTER (not standalone tool)
• intended for tuning and configuration of the
motor control applications (PMSM, ACIM,
BLDC) with potential to other application
fields (digital power, metering…)
• supports real-time tuning & updating of
control parameters
• MCU independent (Kinetis, MPC, DSC, S12
MagniV 16/32 bit, Fix/Float)
MCAT mission:
Enable customers to configure and tune complex real-time embedded applications
in easy-to-use & effective way
Modular Application Tuning (MCAT) Tool
Embedded software
FreeMASTER
MCAT
PUBLIC USE40 #NXPFTF
FreeMASTER
• What is FreeMASTER?
− Configuration & Tuning Tool for Embedded Software Libraries and Applications
− Graphical Control Panel for embedded applications
− Data Capture tool, interface to custom processing in Matlab, Excel etc.
• Supported Communication Interfaces
− RS232 (UART, SCI, LPUART)
− CAN (msCAN, FlexCAN) – PC side supports IXXAT, Vector, NI, GLinker, ZLG
− JTAG (DSC568xxx)
− BDM non intrusive (P&E Multilink and OpenSDA, Segger J-LINK, ARM CMSIS-DAP, Open Source OSBDM, winIDEA)
− All of the above remotely over Internet
• Tool-chains Support (executable file format parsing)
− CodeWarrior, GCC, KDS, IAR, Keil
− Integration to Kinetis SDK since version 1.1
• Primary Applications, success stories
− Motor Control design wins: Indesit, Electrolux, Diehl AKO
− Wireless Charging: diagnostic and setup tool
− Touch Sensing: diagnostic and setup tool
− future targets: Sensor enablement, SDK applications tuning and control
Project on hold
PUBLIC USE42 #NXPFTFPUBLIC USE42
FIELD-ORIENTED CONTROL• Motor control technique which uses measured current flowing
into the motor to obtain torque and magnetic flux information
• Outputs sinusoidal voltage modulated through PWM
• Creates a smooth torque profile, giving better mechanical
robustness, higher efficiency and reduced acoustic noise
• Allows to control speed, magnetic flux and torque of the motor
independently
PUBLIC USE43 #NXPFTF43
C
M
Motorola
Dave’sControlCenter
A
B
C
Controllerwith A/D
i a
i b
i c
Measure and . From Kirkoff’s current law, calculate .
i a i b i c
A, B, and C axes are “fixed” with respect to the motor housing. This reference frame is also called the “stationary frame” or “stator frame”.
net current vector
A
B
i b
i c
i a
(implied)
FOC implementation1. Measure currents flowing in the motor
PUBLIC USE44 #NXPFTF44
Simplify the math by converting the 3-phase motor to a 2-phase motor before jumping up on the rotor
Perform a “3-phase to 2-phase transform” on the current measurements
aii23
cb iii2
3
2
3
i b
i c
i aA
B
C
sii
i
Clarke Transformation
FOC implementation2. Transform from Three Phases to Two Phases
PUBLIC USE45 #NXPFTF45
ddq
ddd
iii
iii
cossin
sincos
4 trig calulations7 multiplications3 additions
Total
Jump up on the rotor by performing a “Stationary to Rotating Frame Transform”.
A
B
C
d
i q
i d
sii
i
Park Transformation
FOC implementation3. Transform from Stationary to Rotating Frame
PUBLIC USE46 #NXPFTF46
Summary of FOC Transformations
Phase A
Phase B
Phase C
Phase A
Phase B
Phase C
d
q
d
q
3-Phaseto
2-Phase
Stationaryto
Rotating
Modulation
3-PhaseSystem
3-PhaseSystem
2-PhaseSystem
AC
Rotatingto
Stationary
ACDC
Co
ntr
ol p
roce
ss
Stationary Reference Frame
Stationary Reference Frame
Rotating Reference Frame
PUBLIC USE47 #NXPFTF47
Once d and q currents are obtained, they represent magnetic flux (d) and torque (q), they can now be controlled
i d
I
P+
+
+-
error(t)
(commanded)
i d (measured)
vd
I
P+
+
+-
error(t)
i q
i q
(commanded)
(measured)
vq
controls rotor flux magnitude
controls amount of torque generated by motor
i d
i q
d and q current control
50 EXTERNAL USE
HW / SW Setup
1. In the desktop folder “Motor control hands on stuff” browse to:
1. \Motor control hands on stuff\PMSM Code\build_ref_solutions\frdm-kv31f\iar
2. Double click on pmsm_ref_sol.eww (this opens IAR)
3. Plug in all your boards:
1. Shield to FRDM board
2. 24 volt power source
3. Check that motor phases are wired
4. USB cable to computer
4. On IAR click on debug icon
1. Wait for flashing to happen and then click on run once the debug view is open
51 EXTERNAL USE
FreeMASTER Communication Setup - Step 1
• RS232 interface is used for the communication (OpenSDA virtual serial port via USB)
• Open FreeMASTER 2.0 from Windows menu
• Click on File – Open project and look for:
\Motor control hands on stuff\
PMSM Code\
build_ref_solutions\
frdm-kv31f\iar\
pmsm_ref_sol_iar.pmp
52 EXTERNAL USE
• It is necessary to assign correct number of COM port:
−Open menu item “Project / Option … “ (Ctrl+T)
−From the drop down list of COM port numbers select the one which is assigned to
“OpenSDA-CDC Serial Port”:
−Click OK button to confirm changes and close “Options” window.
FreeMASTER Communication Setup - Step 2
53 EXTERNAL USE
FreeMASTER Communication Setup - Step 3
• Start the communication (Ctrl+K or click button)
• If the communication with embedded side is working you will see numbers instead of “?” in the variables watch
grid area:
54 EXTERNAL USE
FreeMASTER Error Messages and Errors Fix - 1
• Source: Error in the OpenSDA communication interface:
− Wrong number of communication port entered
− Target side has no power
− Power was interrupted to the target side (power supply over current shut down) then
consequently USB connection was interrupted (terminated)
• How to fix:
1. Disconnect USB cable
2. Disconnect -> connect power to the Tower kit
3. Connect USB cable
4. If still not working , check the communication COM number
55 EXTERNAL USE
FreeMASTER Error Messages and Errors Fix - 2
• Source: Embedded MCU does not respond
− Wrong number of SCI channel on the MCU selected (not our case)
− MCU not powered
− MCU is stopped (breakpoint reached, after starting debugger session, the debugger stops at “void
main(void)” line:
• How to fix:
1. Check IAR debugger (click “Go” button)
2. Disconnect USB cable.
3. Disconnect -> connect power to the Tower kit.
4. Connect back the USB cable.
5. If still not working, check the COM port number.
, if application stops
57 EXTERNAL USE
MCAT for PMSM – Motor El. Parameters Measurement
• Used for Rs measurement. The supply voltage
should be 24V
• Used for ke measurement, if too low the motor
will not spin and result will be NGAmplitude of the AC current
used in Ls measurement
Frequency decrement of AC
voltage used for Ls measurement
Increment of voltage in Ls measurement. Ud is increased until
Id ampl is reached.
If voltage is incremented up to Udcb/2, the frequency is decrased
Default frequency of Ud voltage
used for Ls measurement
After two step alignment the motor
performs one electrical revolution then
stops for a second. User has to
calculate # of el. revolutions until one
mechanical revolution is made.
Stops the pp measurement
(stops the motor)
Enter manually
58 EXTERNAL USE
MCAT for PMSM – Parameters Summary Tab
Reloads previously
stored values
Values are updated
directly into running
application
Stores modified
value
Basic / Expert
Represent max
16 bit number in
MCU
59 EXTERNAL USE
MCAT for PMSM – Current Control Loop Tab
Loop parameters pre-
set in basic mode, do
not drastically modify
61 EXTERNAL USE
MCAT for PMSM - Sensorless Tab
To successfully tune observer, it is
necessary to perfectly identify
motor electrical parameters. Only
analytical approach leads to
success.
62 EXTERNAL USE
MCAT for PMSM – Output File Tab
• Click the button
• pmsm_appconfig.h file generated
• Open the IAR, compile the project,
flash the code
63 EXTERNAL USE
MCAT – Application Control Structure
• Problem >>> What to touch in the application, when after parameters
setting, the drive does not work at all, speed oscillates, or over current
fault is generated after turn-on.
− Is the speed regulator too aggressive?
− Is the Tracking Observer bandwidth too low?
• Solution >>> MCAT Application Control Structure
Allows to decompose the whole
PMSM sensorless FOC application
into fundamental control blocks so the
number of unknown independent
variables in each step is reduced
64 EXTERNAL USE
Control Structure – Scalar Control (Position Open Loop)
Advantage
•the functionality of HW
can be double-checked
• position evaluation
algorithms (TO) tuning
No need for feedback.
65 EXTERNAL USE
Control Structure - Scalar control in PMSM sensless
FOC
d,q
α,β
SVM PWM
Requiredspeed
PI controller
+
++
-
-
-
Phase Currents
Iq_req
UqIq
Id PWM
ADC
DC-Bus Voltage Udcb
PWM Output
slow control loop fast control loop
0
α,β
a,b,c
Iα
Iβ
Ia
Ib
Ic
Clarke Trans
Park Trans
Inv Park Trans
Back-EMF Observer d,q
PI controller
Elim DC Bus
Ripple
Inverter
Tracking Observer
Open loop start up
Ramp
PI controller
Merge 1IntegratorMerge 2
Id_req
d,q
α,β
Uβ
PMSM3
Udcb
sin cos
d,q
α,β
Uα
Iβ
Iα
Blocks supported by Libraries Peripherals
Park Trans
Lim
MERGED
MERGED
Position Estimation
MA filter
Park Trans
d,q
α,β
sin cos
ϑ
66 EXTERNAL USE
Control Structure – Voltage FOC
Advantage
• direction of rotation
tweaked ( positive uq turns
the motor positive
direction)
• current measurement
tuning (phase order,
polarity…)
Only position feedback required.
67 EXTERNAL USE
Control Structure – Voltage FOC in PMSM sensless
FOC
d,q
α,β
SVM PWM
Requiredspeed
PI controller
+
++
-
-
-
Phase Currents
Iq_req
UqIq
Id PWM
ADC
DC-Bus Voltage Udcb
PWM Output
slow control loopfast control loop
0
α,β
a,b,c
Iα
Iβ
Ia
Ib
Ic
Clarke Trans
Park Trans
Inv Park Trans
Back-EMF Observer d,q
PI controller
Elim DC Bus
Ripple
Inverter
Tracking Observer
Open loop start up
Ramp
PI controller
Merge 1IntegratorMerge 2
Id_req
d,q
α,β
Uβ
PMSM3
Udcb
sin cos
d,q
α,β
Uα
Iβ
Iα
Blocks supported by Libraries Peripherals
Park Trans
Lim
MERGED
MERGED
Position Estimation
MA filter
Park Trans
d,q
α,β
sin cos
Ud
68 EXTERNAL USE
Control Structure – Current FOC
Advantage
• direction of rotation
tweaked ( positive iq turns
the motor positive direction)
• speed TO tuning
Required feedbacks:
• position sensor
• phase currents
69 EXTERNAL USE
Control Structure – Current FOC in PMSM sensless
FOC
d,q
α,β
SVM PWM
Requiredspeed
PI controller
+
++
-
-
-
Phase Currents
Iq_req
Iq
Id PWM
ADC
DC-Bus Voltage Udcb
PWM Output
slow control loopfast control loop
α,β
a,b,c
Iα
Iβ
Ia
Ib
Ic
Clarke Trans
Park Trans
Inv Park Trans
Back-EMF Observer d,q
PI controller
Elim DC Bus
Ripple
Inverter
Tracking Observer
Open loop start up
Ramp
PI controller
Merge 1IntegratorMerge 2
d,q
α,β
Uβ
PMSM3
Udcb
sin cos
d,q
α,β
Uα
Iβ
Iα
Blocks supported by Libraries Peripherals
Park Trans
Lim
MERGED
MERGED
Position Estimation
MA filter
Park Trans
d,q
α,β
sin cos
Id_req
70 EXTERNAL USE
Control Structure – Speed FOC Control
Required feedbacks:
• position sensor
• phase currents
• rotor speed
71 EXTERNAL USE
1. Assuming the communication with embedded side is working (see “HW / SW
Setup” slides )
2. In the project tree click “PMSM FOC Sensorless” Block name:
3. Navigate to “Motor Identif” tab:
4. Click the “Measure” button:
5. You can try motor pole pairs counting assistant:
Lab 1 – MCAT MID
72 EXTERNAL USE
Lab 2 – Voltage FOC
1. In the project tree click “Speed” scope in the “1. Scalar & Voltage Control” group:
2. In the variable watch grid window do:
a) Set “Application Switch” to “On” (from the drop down menu)
b) Set “MCAT Control” variable to “VOLTAGE_FOC” , or write “1”
c) Set some positive value to “MCAT Uq Required” ( 1; 2; 3; 4 .. Up to 10)
3. The speed of the motor will change in steps, as the Uq Required value will be modified
7
2
73 EXTERNAL USE
Lab 2 – Voltage FOC
Alignment
(Ud applied)
The motor is running, but not in optimal mode. The voltage vector is generated “somewhere” not perpendicular to the actual rotor position.
74 EXTERNAL USE
Lab 3 – Current FOC
1. In the project tree click “Current Controller” scope in the
“2. Current Control” group:
2. In the variable watch grid window do following:a) Set “Application Switch” to “On” (from the drop down menu)
b) Set “MCAT Control” variable to “CURRENT_FOC” , or write “2”
c) Set 0.5 to “MCAT Iq Required” variable
d) The motor will rump up to maximal speed.
e) Decrease the Iq Required value-> 0.4; 0.3; 0.2 Current value
0.2 A is still enough for running the motor, but too low to start
the motor from zero (it needs to help with a hand when starting
form zero )
75 EXTERNAL USE
Lab 3 – Current FOC
Uq req is the output of
the Q-current
controller. For default
setting quite
satisfactory course (no
oscillations)
The speed of the motor is exponentially changed, when the value of Iq current is changed. The speed of the motor can be easily influenced with light touch of the plastic ring
76 EXTERNAL USE
Lab 3.1 – Current FOC – experience torque
1. Set iq current to 0.3
2. Carefully grab the motor shaft with your finger, observe the measured current to 0.3 and then
motor stop (because of torque limiting)
3. Set iq current to 0.75
4. Carefully grab motor shaft again and observe how it is much more difficult to stop the motor and
the current goes up to the new limit.
Iq goes up to Iq
required and
doesn’t go over
that
Voltage drops (and
thus speed) to reduce
or limit current
77 EXTERNAL USE
Lab 4 – Speed FOC
1. In the project tree click “Speed Controller” scope in the “3.
Current Control” group:
2. In the variable watch grid window do following:a) Set “Application Switch” to “On” (from the drop down menu)
b) Set “MCAT Control” variable to “SPEED_FOC” , or write “3”
c) Set “Speed Required” variable to 3000 after speed stabilizes then
to 1000, to 4000 and then to 0
d) Check the drive response on the change of the required speed,
what do you see?
78 EXTERNAL USE
Lab 4 - Speed FOC
The speed controller parameters are obviously set not correctly.
The controller is too weak. The response on the changes are slow with overshoot.
79 EXTERNAL USE
1. In the Control page navigate to “Speed Loop” tab:
2. Now change the Kp constant of the speed controller to 0.001
3. Click “Update Target” button:
4. Try again the same sequence of Speed Required” variable: 3000 … 1000 … 4000 … 0
5. Check the drive response on the change of the required speed
Lab 4 - Speed FOC – Controller Tuning
80 EXTERNAL USE
Lab 4 - Speed FOC – Controller Tuning
Already better, but still space for improvement
81 EXTERNAL USE
Lab 4 - Speed FOC – Controller Tuning
We will try to set the controller even harder:
1. Change the Kp constant of the speed controller to 0.004 and Ki constant to 0.009
2. Click “Update Target” button
3. Try again the same sequence of Speed Required” variable: 3000 … 1000 … 4000 … 0
4. Check the drive response on the change of the required speed
82 EXTERNAL USE
Lab 4 - Speed FOC – Controller Tuning
• If you are now satisfied with the drive response, you can store the controller constants.
• Click “Store Data” button:
• Navigate to “Output File” tab and click “ Generate Configuration File” button:
• Now you can open the IAR workspace, compile the project with new “pmsm_appconfig.h” file, compile the program and flash the code:
1. Go back to IAR
2. You can open “pmsm_appconfig.h” file to confirm changes
3. Compile the project – press “F5”
4. Download the application and start debugging – press “Ctrl+D” or click
5. Click “Go” button, to run the code:
83 EXTERNAL USE
Lab 4 - Speed FOC – Speed Controller
• Speed controller sets (regulates) the torque (Iq current) in such a way that the constant speed
will be kept, regardless of the load variation.
• You may try to brake the disk on the motor (with caution).
• Speed controller will increase the Iq current on order to maintain required speed:
Load
applied
Load
released
84 EXTERNAL USE
Speed Controller
• Try to visualize other application variables using “Recorder”:
− Phase currents and estimated position
− Duty cycles (SVM output – PWMs shape)
85 EXTERNAL USE
INTRODUCING MOTOR CONTROL
DEVELOPMENT TOOLBOX AND
MATLABNXP.COM/MOTORCONTROLTOOLBOX
86 EXTERNAL USE
Model-Based Design with Production Code Generation
Design
with
Simulation
Executable
Specifications
Continuous
Test and
Verification
Production
Code Generation
Models
Design
with
Simulation
Executable
Specifications
Continuous
Test and
Verification
Production
Code Generation
ModelsTest with Design- detect errors earlier
Simulation-rapid iterations/prototypes
-convert float- to fixed point
Production code generation-minimize coding errors
Executable models-“one truth”
87 EXTERNAL USE
Production Code Generation – User Stories
Lear
Automotive ECUsHoneywell Aerospace USA
Flight Control Systems
Weinmann Medical Germany
Transport ventilator
Alstom France
Propulsion Control Systems
Elementary Schools
Project Based Learning
Alstom Grid UK
HDVC Power Systems
60%
50%
75%
50%
40%
0%
Development Time Savings
88 EXTERNAL USE
Matlab
• Environment for technical computing
• High-level textual numeric language
• Data analysis and visualization
• Toolboxes for signal and image
processing, statistics, optimization,
symbolic math, and other areas
• Foundation of MathWorks products
89 EXTERNAL USE
Simulink
• Environment for modeling and
simulating
• dynamic systems
• Block diagrams and state machines
(Stateflow)
• Linear, nonlinear, discrete-time,
continuous-time, and multicore systems
• Blocksets for controls, signal
processing,
communications, physical modeling,
and other system engineering areas
• Foundation for Model-Based Design
90 EXTERNAL USE
C/C++ Coders
• MATLAB Coder - Code from MATLAB
−Portable code for numerical algorithms
−Desktop applications (standalone, library)
• Simulink Coder - Code from Simulink
−Portable code for algorithms plus real-time framework
−Real-time machines for RP/HIL (e.g., Simulink Real-Time)
• Embedded Coder – Production code
−Extends ML Coder and SL Coder for embedded processors
−MCUs and DSPs (from 8-bit devices to multicore SoCs) Code optimization (portable code and processor-specific)
Code verification (software- and processor-in-the-loop, trace)
Code profiling (tasks and functions)
Code customization (data, functions, files)
Embedded targets (board initialization, I/O blocks, scheduler)
Certification (ISO-26262, IEC 61508, etc.)
All coders generate portable code (ANSI/ISO C) by default.
C/C++
Gen
era
te
MATLAB and SimulinkAlgorithm and System Design
Verify
91 EXTERNAL USE
Embedded Coder Metrics
SAE Technical Paper 2004-01-0269, March 2004
www.mathworks.com/mason/tag/proxy.html?dataid=4361&fileid=20307
Generated code is smaller
than hand code.
93 EXTERNAL USE
Executable Specifications
Design
with
Simulation
Continuous
Test and
Verification
Automatic
Code Generation
Executable
Specifications
Models
95 EXTERNAL USE
Rapid Prototyping – Simulink Coder
HarnessReal-Time or
Embedded
Simulink Real-Time
Is my algorithm feasible?
Code
Generation
96 EXTERNAL USE
Harness
On-Target Rapid Prototyping – Embedded Coder
Embedded Processor or ECU
Is my algorithm practical?
Code
Generation
97 EXTERNAL USE
Design with Simulation
Design
with
Simulation
Continuous
Test and
Verification
Automatic
Code Generation
Executable
Specifications
Models
98 EXTERNAL USE
Float- to Fixed-Point Conversion
• Overflow/underflow
• Code optimizations
• Simulation ranges
• Derived ranges
−Design-range scaling
>>fxpdemo_fpa
99 EXTERNAL USE
Function Interface Specification
• Function Name
• Argument Name
• Pass by value
• Pass by reference
• Qualifier
101 EXTERNAL USE
Production Code Generation
Design
with
Simulation
Continuous
Test and
Verification
Automatic
Code Generation
Executable
Specifications
Models
102 EXTERNAL USE
Algorithm Code (ANSI-C)
A B C
M
I N P U T
B L U E G R E E N R E D
P O W E R
RGBSplit-4BLACK BOX
V R C S
Input
Drivers
Output
Drivers
Special
Device
Drivers
Comm
Drivers
Scheduler/Operating System
and Support Utilities
Communication
Interfaces
Sensors
Actuators
Special
Interfaces
Tuning
Generated
Algorithm
Code
Algorithm
Model
103 EXTERNAL USE
A B C
M
I N P U T
B L U E G R E E N R E D
P O W E R
RGBSplit-4BLACK BOX
V R C S
Generated
Algorithm
Code
Input
Drivers
Output
Drivers
Special
Device
Drivers
Comm
Drivers
Scheduler/Operating System
and Support Utilities
Communication
Interfaces
Sensors
Actuators
Special
Interfaces
Tuning
Processor
Optimized
Code
Algorithm
Model
Algorithm Code (Processor-Optimized)
104 EXTERNAL USE
A B C
M
I N P U T
B L U E G R E E N R E D
P O W E R
RGBSplit-4BLACK BOX
V R C S
Generated
Algorithm
Code
Input
Drivers
Output
Drivers
Special
Device
Drivers
Comm
Drivers
Scheduler/Operating System
and Support Utilities
Communication
Interfaces
Sensors
Actuators
Special
Interfaces
Tuning
System Model
Processor
Optimized
Code
System Executable (Algorithm + I/O)
106 EXTERNAL USE
Continuous Test and
Verification (PIL)
Design
with
Simulation
Continuous
Test and
Verification
Automatic
Code Generation
Executable
Specifications
Models
107 EXTERNAL USE
Non-Real-Time
Synchronization
with Host at Each Time Step
Execution History
• Results comparison (sim vs. tgt)
• Code coverage
• Execution timing
Communication
Gateway
Processor-in-the-Loop (PIL)Verify Algorithms
109 EXTERNAL USE
MOTOR CONTROL
DEVELOPMENT
TOOLBOXWWW.NXP.COM/MOTORCONTROLTOOLBOX
110 EXTERNAL USE
Introduction: Motor Control Development Toolbox
• The Motor Control Development Toolbox is a MATLAB plugin to enable complete motor control application simulation within the MATLAB environment, enabling Software and Processor-in-the-Loop (SIL and PIL) simulation.
• Motor control tool box Includes:
−an embedded target supporting NXP MCUs,
−Simulink™ plug-in libraries which provide engineers with an integrated environment
−tool chain for configuring and generating the necessary software, including initialization routines, device drivers, and a real-time
scheduler to execute algorithms specifically for controlling motors.
• The toolbox also integrate the Embedded Software Libraries developed by NXP’s Motor Control Center of Excellence. The library provides dozens of blocks optimized for fast execution on NXP MCUs with bit-accurate results compared to Simulink™ simulation using single-precision math.
111 EXTERNAL USE
MCD Toolbox: Summary of Customer Application
Support
External HardwareSystem Infrastructure
On-Chip
Peripherals
PINS
External
Connections
Application SW
Drivers
DriversEfficient
Reflecting the chip features
FreeMasterSupport
Do
cu
me
nta
tio
n
SYSTEM APPLICATION
Targ
et
Pla
tfo
rm
API
MC library set
Algorithm
Libraries
GFLIBGeneral functions
GDFLIBDigital filtering
GM
CL
IBM
oto
r C
ontr
ol
API
Boot Loader Support
User Application
Software
112 EXTERNAL USE
MCD Toolbox: Toolbox Library Contents
Peripherals
• General
• ADC conversion
• Digital I/O
• PIT timer
• ISR
• Communication Interface
• CAN driver
• SPI driver
• LIN driver
• Motor Control Interface
• Cross triggering unit
• PWM
• eTimer block(s)
• ADC Command List
• GDU (Gate Drive Unit)
• PTU (Prog Trigger Unit)
• TIM Hall Sensor Port
Configuration/Modes
• Compiler Options
• CodeWarrior
• Wind River DIAB
• Green Hills
• Cosmic
• RAM/FLASH targets
• Simulation Modes
• Normal
• Accelerator
• Software in the Loop (SIL)
• Processor in the Loop (PIL)
• MCU Option
• Multiple packages
• Multiple Crystal
frequencies
Utility
• FreeMASTER Interface
• Data acquisition
• Calibration
• Customize GUI
• Profiler Function
• Exec. time measurement
• Available in PIL
• Available in standalone
• KV1x
• KV3x
• KV4x
• KV5x
MCUs Supported
113 EXTERNAL USE
Idealized simulation of the controller and
the motor to refine the control technique.
Done on host PC without regard for
embedded controller. Can optionally add
analog device models for fault detection
and signal control.
Controller Model
Electric Motor Model
Analog
Device ModelAnalog
Sensor Model
PI
Filter
PI
Filter
Reverse
Park
Transform
PWM
Modulation
PWM A
PWM B
PWM C
Zero
+
-
+
-
Torque
Control
IQ
loop
ID
loop
IQ
cmd
ID
cmd
ID
Va
cmd
Vb
cmd
Forward
Park
Transform
Forward
Clark
Transform
IA
IB
IC
Va
Vb
Motor Position
IQ
Gate
Driver
With
Isolation
ADC
A/D
Conversion
Simulation in PC environment
PC Environment
Model Based Design Steps: Step 1 (Simulation)
114 EXTERNAL USE
Model Based Design Steps: Step 2 (SIL)
Still done on host PC without regard for
embedded controller. Instead using
generated C code that is compiled using
a PC-based compiler. Run same test
vectors as in simulation for C Code
Coverage analysis and verify functionality.
(SIL) Generated code executes as atomic unit on PC(SIL) Generated code executes as atomic unit on PC
Controller Model
Electric Motor Model
Analog
Device ModelAnalog
Sensor Model
PI
Filter
PI
Filter
Reverse
Park
Transform
PWM
Modulation
PWM A
PWM B
PWM C
Zero
+
-
+
-
Torque
Control
IQ
loop
ID
loop
IQ
cmd
ID
cmd
ID
Va
cmd
Vb
cmd
Forward
Park
Transform
Forward
Clark
Transform
IA
IB
IC
Va
Vb
Motor Position
IQ
Gate
Driver
ADC
A/D
Conversion
PC Environment
115 EXTERNAL USE
Model Based Design Steps: Step 3 (PIL)
Execute the model on the target MCU and
perform numeric equivalence testing. Co-
execution with MCU and Model Based Design
working together while collecting execution
metrics on the embedded controller of control
algorithm. Validate performance on MCU.
(PIL) Executes generated code on the target MCU
Controller Model
Electric Motor Model
Analog
Device ModelAnalog
Sensor Model
PI
Filter
PI
Filter
Reverse
Park
Transform
PWM
Modulation
PWM A
PWM B
PWM C
Zero
+
-
+
-
Torque
Control
IQ
loop
ID
loop
IQ
cmd
ID
cmd
ID
Va
cmd
Vb
cmd
Forward
Park
Transform
Forward
Clark
Transform
IA
IB
IC
Va
Vb
Motor Position
IQ
Gate
Driver
ADC
A/D
Conversion
PC Environment + MCU
PUBLIC USE117 #NXPFTF
Trapezoidal Control: Brushless DC Motor
A BLDC motor consists of a rotor with permanent magnets and a stator
with phase windings. A BLDC motor needs electronic commutation for
the control of current through its three phase windings.
Stator
Stator
N
N
S S
Permanent
Magnets
RotorPhase
Windings
Phase
Windings
PUBLIC USE118 #NXPFTF
Trapezoidal Control: Commutation Method
Trapezoidal control is one type of commutation method used to turn a
motor where only two phase windings will conduct current at any one
time. With direction also to consider, that leaves six possible
patterns.
Phase B
Phase CPhase A
Circuit Representation
of BLDC Stator Windings
PUBLIC USE119 #NXPFTF
Trapezoidal Control: Commutation Control
By adding switches, the current flow can be controlled by a MCU to
perform trapezoidal control.
Phase B
Phase CPhase A
Vb+
Vb-
At
Ab
Bt
Bb
Vb+
Vb-
Ct
Cb
Vb+
Vb-
OFF
OFF
N.C.
OFF
ON
Vb+
ON
OFF
Vb-
OFF
OFF
N.C.
OFF
ON
Vb+
ON
OFF
Vb-
OFF
OFF
N.C.
OFF
ON
Vb+
ON
OFF
Vb-
OFF
OFF
N.C.
OFF
ON
Vb+
ON
OFF
Vb-
OFF
OFF
N.C.
OFF
ON
Vb+
ON
OFF
Vb-
OFF
OFF
N.C.
OFF
ON
Vb+
ON
OFF
Vb-
PUBLIC USE120 #NXPFTF
AtBb
Ct
Ab
Bt
Cb
AtBb
Ct
Ab
Bt
Cb
CWPhase
A
Phase
B
Phase
C
0/180○
30○
60○
90○
120○
150○
Trapezoidal Control: Turning the Motor CW
With the switches, the stator can be used to turn the motor to the desired direction and location by creating a magnetic field that affects
the magnets on the rotor.
N
N
S S
o
NC Vb+Vb-
NC Vb-Vb+
NCVb-Vb+
Vb- NC Vb+
Vb- Vb+ NC
Vb+NC Vb-
Vb+ Vb- NC
Top
Switch On Off Off
Bottom
Switch Off On Off
PUBLIC USE121 #NXPFTF
AtBb
Ct
Ab
Bt
Cb
AtBb
Ct
Ab
Bt
Cb
CCWPhase
A
Phase
B
Phase
C
0/180○
30○
60○
90○
120○
150○
Trapezoidal Control: Turning the Motor
CCWWith the switches, the stator can be used to turn the motor to the
desired direction and location by creating a magnetic field that affects
the magnets on the rotor.
N
N
S S
o
NC Vb-Vb+
NC Vb+Vb-
NCVb+Vb-
Vb+ NC Vb-
Vb+ Vb- NC
Vb-NC Vb+
Vb+ Vb- NC
Top
Switch On Off Off
Bottom
Switch Off On Off
PUBLIC USE122 #NXPFTF
Trapezoidal Control: Motor Position
In order to commutate correctly for trapezoidal control, motor position
information is required for proper motor rotation. The motor position
information enables the MOSFETs or IGBTs in the inverter to properly be
switched ON and OFF to ensure proper direction of current flow through
the phase windings. Therefore, Hall sensors are used as position
sensors for trapezoidal control. Each Hall sensor is placed 120 degrees
apart and delivers a “high” state when facing a “north pole” and a “low”
state when facing a “south pole”.
N
N
S S
o
Hall A
Hall B
Hall C
A
PUBLIC USE123 #NXPFTF
Trapezoidal Control: Motor Position CW
With three Hall sensors, it is possible to have eight states with two
invalid states. That leaves six valid states that can be used to determine
which two phase coils to drive the current through and in which direction.
The six states are generated due to rotation of the motor.
N
N
S S
o
Hall A
Hall B
Hall C
Hall A Hall B Hall C State CW
0/180○
30○
60○
90○
120○
150○
0 0 0 Invalid n/a
1 1 1 Invalid n/a
51 10
31 10
1100
41 0 0
61 1 0
210 0
A
PUBLIC USE124 #NXPFTF
Trapezoidal Control: Motor Position CCW
With three Hall sensors, it is possible to have eight states with two
invalid states. That leaves six valid states that can be used to determine
which two phase coils to drive the current through and in which direction.
The six states are generated due to rotation of the motor.
N
N
S S
o
Hall A
Hall B
Hall C
Hall A Hall B Hall C State CCW
0/180○
30○
60○
90○
120○
150○
0 0 0 Invalid n/a
1 1 1 Invalid n/a
51 10
31 10
1100
41 0 0
61 1 0
210 0
A
PUBLIC USE125 #NXPFTF
Trapezoidal Control: Bringing It All Together
With the commutation table and the motor position table, a full
trapezoidal control algorithm can be developed.
Hall A Hall B Hall C State CW
1 0 0 4 0/180○
1 1 0 6 30○
0 1 0 2 60○
0 1 1 3 90○
0 0 1 1 120○
1 0 1 5 150○
0 0 0 Invalid n/a
1 1 1 Invalid n/a
CW Phase A Phase B Phase C
0/180○ Vb+ NC Vb-
30○ Vb+ Vb- NC
60○ NC Vb- Vb+
90○ Vb- NC Vb+
120○ Vb- Vb+ NC
150○ NC Vb+ Vb-
Motor Position Table Input Commutation Table Output
Vb+ Vb- NC
Top
Switch On Off Off
Bottom
Switch Off On Off
PUBLIC USE126 #NXPFTF
Trapezoidal Control: Bringing It All Together
With the commutation table and the motor position table, a full
trapezoidal control algorithm can be developed.
Hall A Hall B Hall C State CW Phase A Phase B Phase C
1 0 0 4 0/180○ Vb+ NC Vb-
1 1 0 6 30○ Vb+ Vb- NC
0 1 0 2 60○ NC Vb- Vb+
0 1 1 3 90○ Vb- NC Vb+
0 0 1 1 120○ Vb- Vb+ NC
1 0 1 5 150○ NC Vb+ Vb-
0 0 0 Invalid n/a
1 1 1 Invalid n/a
Trapezoidal Control Algorithm Clockwise Rotation
Vb+ Vb- NC
Top
Switch On Off Off
Bottom
Switch Off On Off
PUBLIC USE127 #NXPFTF
Trapezoidal Control: Bringing It All Together
With the commutation table and the motor position table, a full
trapezoidal control algorithm can be developed.
Hall A Hall B Hall C State CW Phase A Phase B Phase C
1 0 0 4 0/180○ Vb- NC Vb+
1 0 1 5 30○ Vb- Vb+ NC
0 0 1 1 60○ NC Vb+ Vb-
0 1 1 3 90○ Vb+ NC Vb-
0 1 0 2 120○ Vb+ Vb- NC
1 1 0 6 150○ NC Vb- Vb+
0 0 0 Invalid n/a
1 1 1 Invalid n/a
Trapezoidal Control Algorithm Counter Clockwise Rotation
Vb+ Vb- NC
Top
Switch On Off Off
Bottom
Switch Off On Off