MBDT General Presentation
MBDT General Presentation
EXTERNAL USE
Agenda
• Overview:
− Introduction and Objectives
− Model-Based Design Toolbox: Library blocks, FreeMASTER, and Bootloader
• Hands-On Demo:
− Motor Kit (Describe Freescale 3-Phase Motor Kit)
− Convert simple model to run on Motor Kit with MCD Toolbox and use FreeMASTER
• Model-Based Design:
− Model-Based Design Steps: Simulation, SIL, PIL and ISO 26262
− SIL/PIL Hands-On Demo Step 2 & 3 of MBD
1 EXTERNAL USE
Introduction: Model-Based Design (MBD)
• Model-Based Design is becoming more common during the normal course of software development to
explain and implement the desired behavior of a complex system. The challenge is to take advantage of
this approach and get an executable that can be simulated and implemented directly from the model to help
you get the product to market in less time and with higher quality. This is especially true for electric motor
controls development in this age of hybrid/electric vehicles and the industrial motor control application
space.
• Many companies model their controller algorithm and the target motor or plant so they can use a simulation
environment to accelerate their algorithm development.
• The final stage of this type of development is the integration of the control algorithm software with target
MCU hardware. This is often done using hand code or a mix of hand code and model-generated code.
Model-Based Design Toolbox allows this stage of the development to generate 100% of the code from the
model.
2 EXTERNAL USE
Introduction: Model-Based Design Toolbox
• The Model-Based Design Toolbox includes an embedded target supporting NXP MCUs, Simulink™ plug-in
libraries which provide engineers with an integrated environment and 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 includes an extensive Math and Motor Control Function Library developed by NXP’s
renowned 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.
• The toolbox provides built-in support for Software and Processor-in-the-Loop (SIL and PIL), which enables
direct comparison and plotting of numerical results.
4 EXTERNAL USE
Objectives
Model-Based Design
Driver configuration
Assignment to pins
Initialization setup
Signal Visualization
and Data Acquisition Tool
5 EXTERNAL USE
Agenda
• Overview: 20 minutes
− Introduction and Objectives
− Model-Based Design Toolbox: Library blocks, FreeMASTER, and Bootloader
6 EXTERNAL USE
MBD Toolbox: Library Contents
Simulink
Libraries
MBD Toolbox
Peripheral block
library
MBD Toolbox
Library for
S12ZVM
7 EXTERNAL USE
Model-Based Design Toolbox: Toolbox Contents
8 EXTERNAL USE NOTE: Peripheral Blocks and compiler support is dependent on MCU use.
Automotive Math and Motor Control Library Set - Architecture
General Motor Advanced Motor
Control Library Control Library
General Digital
General Function
Filters Library
Library
• Absolute Value, Negative Value • Trigonometric Functions • Finite Impulse Filter • Clark Transformation • BEMF Observer DQ
• MLIB_Abs, MLIB_AbsSat • GFLIB_Sin, GFLIB_Cos, • GDFLIB_FilterFIR • GMCLIB_Clark • AMCLIB_BemfObsrvDQ
• MLIB_Neg, MLIB_NegSat GFLIB_SinCos, GFLIB_Tan • Moving Average Filter • GMCLIB_ClarkInv • Tracking Observer
• Add/Subtract Functions • GFLIB_Asin, GFLIB_Acos, • GDFLIB_FilterMA • Park Transformation • AMCLIB_TrackObsrv
• MLIB_Add, MLIB_AddSat GFLIB_Atan, GFLIB_AtanYX • 1st Order Infinite Impulse • GMCLIB_Park
• MLIB_Sub, MLIB_SubSat • GFLIB_AtanYXShifted • GMCLIB_ParkInv
Filter
• Multiply/Divide/Add-multiply • Limitation Functions • Duty Cycle Calculation
• GDFLIB_FilterIIR1init
• GFLIB_Limit, GFLIB_VectorLimit • GMCLIB_SvmStd
Functions • GDFLIB_FilterIIR1
• GFLIB_LowerLimit, • Elimination of DC Ripples
• MLIB_Mul, MLIB_MulSat
GFLIB_UpperLimit
• 2nd Order Infinite Impulse
• MLIB_Div, MLIB_DivSat • GMCLIB_ElimDcBusRip
• PI Controller Functions Filter
• MLIB_Mac, MLIB_MacSat
• GDFLIB_FilterIIR2init • Decoupling of PMSM Motors
• MLIB_Mnac, MLIB_Msu • GFLIB_ControllerPIr,
• GDFLIB_FilterIIR2 • GMCLIB_DecouplingPMSM
• MLIB_VMac GFLIB_ControllerPIrAW
• GFLIB_ControllerPIp,
• Shifting
GFLIB_ControllerPIpAW
• MLIB_ShL, MLIB_ShLSat
• MLIB_ShR • Interpolation
• MLIB_ShBi, MLIB_ShBiSat • GFLIB_Lut1D, GFLIB_Lut2D
• Normalisation, Round Functions • Hysteresis Function
• MLIB_Norm, MLIB_Round • GFLIB_Hyst
• Conversion Functions • Signal Integration Function
• GFLIB_IntegratorTR
• MLIB_ConvertPU, MLIB_Convert
• Sign Function Delivery Content
• GFLIB_Sign
• Signal Ramp Function Matlab/Simulink Bit Accurate Models
• GFLIB_Ramp User Manuals
• Square Root Function Header files
• GFLIB_Sqrt
Compiled Library File
License File (to be accepted at install time)
S32K14x Available Not supported1 N/A2 Not supported1 Available Available N/A2
1) Not supported: The compiler contains the support of selected device, however the AMMCLib does not support this compiler.
2) N/A: The compiler (or the compiler version) does not support selected device.
12 EXTERNAL USE
MBD Toolbox: RAppID Bootloader Utility
The RAppID Bootloader works with the built-in Boot Assist Module (BAM) included in Freescale Qorivva MCUs or can be
resident in FLASH. The Bootloader provides a streamlined method for programming code into FLASH or RAM on either
target EVBs or custom boards. Once programming is complete, the application code automatically starts.
Modes of Operation
The Bootloader has two modes of operation: for use as a stand-alone PC desktop GUI utility, or for integration with different user required
tools chains through a command line interface (i.e. Eclipse Plug-in, MATLAB/Simulink, …)
MCUs Supported
MPC5534, MPC5601/2D, MPC5602/3/4BC, MPC5605/6/7B, MPC564xB/C, MPC567xF, MPC567xK, MPC564xA, MPC5605/6/7BK,
MPC564xL, MPC5604/3P, MPC574xP, MPC5746R, MPC5746C, MPC5748G, MPC5777C, MPC5775K, S12ZVC, S12ZVL, S12ZVM,
S12VR, KEAZN16/32/64, KEAZ64/128, S32K144, 56F82xx, KV10Z, and KV3x/KV4x/KV5x.
13 EXTERNAL USE
What is FreeMASTER?
14 EXTERNAL USE
FreeMASTER Topology and Platforms Support
FreeMASTER
FreeMASTER
• ARM Cortex-M (Kinetis/S32)
• S12/S12X/S12Z(MagniV),
• MPC56xx, MPC57xx
• ColdFire V1/V2
UART/SCI UART/SCI
15 EXTERNAL USE
MBD Toolbox: Summary of Customer Application Support
SYSTEM APPLICATION
User Application
Software Application SW
API
Target Platform
GDFLIB Algorithm
GMCLIB
Motor Control
Digital filtering
Libraries
Documentation
GFLIB API
General functions
Drivers
MC library set
On-Chip
Drivers Peripherals
Efficient
Reflecting the chip features PINS
16 EXTERNAL USE
Agenda
• Overview:
− Introduction and Objectives
− Model-Based Design Toolbox: Library blocks, FreeMASTER, and Bootloader
• Hands-On Demo:
− Motor Kit (Describe Freescale 3-Phase Motor Kit)
− Convert simple model to run on Motor Kit with MCD Toolbox and use FreeMASTER
• Model-Based Design:
− Model-Based Design Steps: Simulation, SIL, PIL and ISO 26262
− SIL/PIL Hands-On Demo Step 2 & 3 of MBD
17 EXTERNAL USE
Hands-On Demo: Motor Kit
MTRCKTSBNZVM128
Features:
• MC9S12ZVML/C12MKH
• BDM interface
• On-board OSBDM
• Hall Sensor
• Resolver interface
• SINCOS interface
• LIN/CAN BLDC Motor
• USB-to-SCI serial port
Control Dev Kit
• Phase and DC-bus current sensing circuits
• FAULT indicator
• Over-voltage and over-current FAULT indicator with Motor and Drive Features:
potentiometer adjustments
• Input voltage 12–24 V DC
• 2 User LEDs
• Output current 5–10 Amps
• 2 push buttons
• 3-phase MOSFET inverter using 6 N-
• 1 switch
channel Power MOSFETs
• 4 MHz oscillator
• 4 pole-pair BLDC motor with Hall
• 1 Potentiometer
sensors (9450 RPM rated speed at
24 V)
18 EXTERNAL USE
Hands-On Demo: Read A/D and Toggle LED Simple Model
19 EXTERNAL USE
Hands-On Demo: Read A/D and Toggle LED Simple Model
20 EXTERNAL USE
Hands-On Demo: Read A/D and Toggle LED Simple Model
22 EXTERNAL USE
Hands-On Demo: Read A/D and Toggle LED Simple Model
23 EXTERNAL USE
Hands-On Demo: Read A/D and Toggle LED Simple Model
24 EXTERNAL USE
Hands-On Demo: Read A/D and Toggle LED Simple Model
25 EXTERNAL USE
Hands-On Demo: Read A/D and Toggle LED Simple Model
26 EXTERNAL USE
Hands-On Demo: Read A/D and Toggle LED Simple Model
27 EXTERNAL USE
Hands-On Demo: Read A/D and Toggle LED Simple Model
Convert Simple Model and Run
• This is what the model should look like after step 24
28 EXTERNAL USE
Hands-On Demo: Read A/D and Toggle LED Simple Model
29 EXTERNAL USE
Hands-On Demo: Read A/D and Toggle LED Simple Model
Note: You should be able to change the threshold value to something other than 2000. Try
changing it and see if the LED_State changes state.
30 EXTERNAL USE
Hands-On Demo: Read A/D and Toggle LED Simple Model
31 EXTERNAL USE
Hands-On Demo: Read A/D and Toggle LED Simple Model
32 EXTERNAL USE
Hands-On Demo: Read A/D and Toggle LED Simple Model
33 EXTERNAL USE
Agenda
• Overview:
− Introduction and Objectives
− Model-Based Design Toolbox: Library blocks, FreeMASTER, and Bootloader
• Hands-On Demo:
− Motor Kit (Describe Freescale 3-Phase Motor Kit)
− Convert simple model to run on Motor Kit with MCD Toolbox and use FreeMASTER
• Model-Based Design:
− Model-Based Design Steps: Simulation, SIL, PIL and ISO 26262
− SIL/PIL Hands-On Demo Step 2 & 3 of MBD
34 EXTERNAL USE
Model-Based Design Steps: Step 1 (Simulation)
Simulation in PC environment
PWM A
Torque IQ PI IQ Va
Control + loop Filter cmd cmd
ADC - Reverse
Park
Transform
PWM
Modulation
PWM B
ID PI ID Vb
+ loop Filter cmd cmd PWM C
Zero -
Gate
IA Driver
A/D Va
ID
Conversion Forward Forward IB
Park Clark
Transform Transform
Vb
IC
IQ
Motor Position
Analog
Analog Device Model
Sensor Model Controller Model
Electric Motor Model Idealized simulation of the controller and the motor to refine the
PC Environment
control technique. Done on host PC without regard for embedded
controller. Can optionally add analog device models for fault
detection and signal control.
35 EXTERNAL USE
Model-Based Design Steps: Step 2 – Software in the Loop (SIL)
(SIL) Generated code executes as atomic unit on PC
PWM A
Torque IQ PI IQ Va
Control + loop Filter cmd cmd
ADC - Reverse
Park
PWM
Modulation
PWM B
Transform
ID PI ID Vb
+ loop Filter cmd cmd PWM C
Zero -
Gate
IA
Driver
A/D Va
ID
Conversion Forward Forward IB
Park Clark
Transform Transform
Vb
IC
IQ
Motor Position
Analog
Analog Device Model
Sensor Model Controller Model
PC Environment Electric Motor Model 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.
36 EXTERNAL USE
Model-Based Design Steps: Step 3 – Processor in the Loop (PIL)
(PIL) Executes generated code on the target MCU
PWM A
Torque IQ PI IQ Va
Control + loop Filter cmd cmd
ADC - Reverse
Park
Transform
PWM
Modulation
PWM B
ID PI ID Vb
+ loop Filter cmd cmd PWM C
Zero -
Gate
IA Driver
A/D Va
ID
Conversion Forward Forward IB
Park Clark
Transform Transform
Vb
IC
IQ
Motor Position
Analog
Analog Device Model
Sensor Model Controller Model
Electric Motor Model Execute the model on the target MCU and perform numeric
PC Environment + MCU
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.
37 EXTERNAL USE
Model-Based Design Steps: Step 3 (PIL)
38 EXTERNAL USE
Example IEC 61508 and ISO 26262 Workflow for Model-Based Design
with MathWorks Products*
Model advisor, modeling PIL testing using MBD Toolbox PIL Mode Support**
standards checking
Simulation (model testing), Real-Time Workshop Embedded
model coverage, RMI Coder traceability report or
model vs. code coverage
comparison
Torque
Control +
IQ
loop
PI
Filter
IQ
cmd
Va
cmd
PWM A
* I/O peripheral driver blocks
ADC - Reverse
Park
Transform
PWM
Modulation
PWM B
can be included in the model,
ID PI ID Vb
Zero
+
-
loop Filter cmd cmd PWM C
providing the analog driver
Gate
A/D Va
IA Driver
interfaces needed to directly
ID
Conversion Forward
Park
Transform
Forward
Clark
Transform
IB
interface to devices external
Vb
IQ
IC
from the MCU.
Motor Position
Output
Input Drivers*
Drivers* Controller Model
Execute on Target MCU on ECM/EVB
MCU with
Embedded Control Electric Motor Generate production code to run on embedded MCU with real motor
Module (ECM)
while collecting execution metrics on the embedded controller of control
algorithm. Validate performance on MCU and use FreeMASTER to tune
control parameters and perform data logging.
40 EXTERNAL USE
Model-Based Design Approach
Idea incubation ANSI C code Experiments Final Product
PWM A
PWM A Torque IQ PI IQ Va
Torque
+
IQ PI IQ Va
PWM A Control + loop Filter cmd cmd PWM A
Control loop Filter cmd cmd Torque IQ PI IQ Va Torque IQ PI IQ Va
- + - Reverse PWM B Control + loop Filter cmd cmd
Reverse Control loop Filter cmd cmd PWM
PWM PWM B Park
Park
Modulation - Reverse Transform
Modulation - Reverse PWM B
Transform PWM PWM B PWM
Park Park
Modulation ID PI ID Vb Modulation
Vb Transform Transform
+
ID PI ID
PWM C
+ loop Filter cmd cmd PWM C
loop Filter cmd cmd Vb Vb
ID PI ID ID PI ID
Zero - + cmd PWM C Zero - + loop Filter cmd cmd PWM C
loop Filter cmd
Zero - Zero -
IA
IA Va
Va IA
IA ID
ID Va Va
Forward Forward IB
Forward Forward IB ID ID
Park Clark
Park Clark Forward Forward Forward Forward
IB Transform Transform IB
Transform Transform Park Clark Vb Park Clark
Vb IC
To SIL
IC Transform Transform IQ Transform Transform
To PIL To MCU
IQ Vb Vb
IC IC
IQ IQ
Motor Position
Motor Position
Motor Position Motor Position
Electric Motor Model Electric Motor Model Electric Motor Model Real Electric Motor
Step 1 – System Requirements: Step 2 – Modeling/Simulation: Step 3 – Rapid Prototype: Step 4 – Target MCU Implementation
MBD Simulation Only MBD Simulation with ANSI C Code MBD Simulation with ANSI C Code ANSI C Code Running on Target HW
using SIL using PIL & MCU
• Software requirements • Control algorithm design • Controller code generation • Validation/verification phase
• Control system requirements • Code generation preparation • Determine execution time on MCU • Controller code generation
• Overall application control strategy • Control system design • Verify algorithm on MCU • Determine execution time on MCU
• Overall application control strategy • See memory/stack usage on MCU • Start testing implementation on target ECM
design • Start testing implementation approach • Code generate control algorithm
• Start testing implementation approach • Target testing controls algorithm on MCU • Test system in target environment Utilize
calibration tools for data logging and
parameter tuning
• Modeling style guidelines applied • Testing of functional components of • Refine model for code generation • Execute code on target MCU
• Algorithm functional partitioning algorithm • Function/File partitioning • Functional testing in target environment
• Interfaces are defined here • Test harness to validate all requirements • Data typing to target environment done here • Ensure execution on target is correct as well
• Test coverage of model here • Scaling for fixed point simulation and code gen as code generation on target is performing
• Creates functional baseline of model Testing of functional components of algorithm as desired.
• Test harness to validate all requirements
• Test coverage of model here
41 EXTERNAL USE • Creates functional baseline of model
• Equivalence testing
Demo: SIL/PIL Step 2 & 3 of MBD
1. Open Model “FOC_Sensorless_SIL_PIL.slx
2. You will see a motor simulation of an FOC control algorithm
3. Will Run model and view the results.
42 EXTERNAL USE
Demo: SIL/PIL Step 2 & 3 of MBD
4. You can switch between SIL and PIL thru using the tools menu.
43 EXTERNAL USE
Demo: SIL/PIL Step 2 & 3 of MBD
5. Open “Configuration Parameters” in the reference model.
6. Go to PIL/BAM Setup tab.
7. Enter the COM port number that you are using from PC.
44 EXTERNAL USE
Demo: SIL/PIL Step 2 & 3 of MBD
8. - Will Run model and view the results.
45 EXTERNAL USE
Demo: SIL/PIL Step 2 & 3 of MBD
9. Let us try improving the execution time by changing the compiler options
10. Change the optimization level from 0 to 2.
46 EXTERNAL USE
Demo: SIL/PIL Step 2 & 3 of MBD
11. Run model and view the results.
47 EXTERNAL USE
Agenda
• Overview:
− Introduction and Objectives
− Model-Based Design Toolbox: Library blocks, FreeMASTER, and Bootloader
• Hands-On Demo:
− Motor Kit (Describe Freescale 3-Phase Motor Kit)
− Convert simple model to run on Motor Kit with MCD Toolbox and use FreeMASTER
• Model-Based Design:
− Model-Based Design Steps: Simulation, SIL, PIL and ISO 26262
− SIL/PIL Hands-On Demo Step 2 & 3 of MBD
48 EXTERNAL USE
Motor Kit: MTRCKTSBNZVM128 BLDC Motor Control Kit
• The kit includes a 4 pole-pair count motor, which means that every single mechanical revolution equals four
electrical revolutions. State changes in Hall sensors is every 60 degrees electrical.
49 EXTERNAL USE
Motor Kit: XS12ZVMx12EVB Power indicator
LEDs OSBDM
User Switches
CAN option
Hall
interface
LIN interface
USB-to-SCI
interface
GDU / 3-phase
bridge access
Reset
BDM interface
12 V
supply
User LEDs
Vb+
A
Phase A
Phase B
S12ZVM
Analog Phase C
Gate
Drive Current BLDC
Unit Feedback Motor
Pot
Switches Hall Sensors
Vb-
PWM
TIM
PMF GPIO ADC
S12ZVM Hall Sensor Port
SCI Digital DO
51 EXTERNAL USE
Motor Kit: S12ZVM for BLDC Motor Control
Discrete Solution
VREG 3+
MCU
(8pin) 20+ Gate
or
Driver
2+
DSC (48pin)
LIN phy (48pin)
(8pin)
Op-amps
4 cm
~1 ½ in.
S12ZVM Solution:
• ~ 50 fewer solder joints
• - 4 to 6 cm2 PCB space
64 pin
52 EXTERNAL USE
10 Billion Electric Motors Shipped Globally in 2013
2.5 Billion in Automobiles, 30 Per Car Average
Convertible roof Circular pump for stationary
Motor for Heating fan
Sliding roof heating system • source: IMS Research, 2013
stationary heating system
Idle position
Cooling fan for air adjustment system
conditioning system
Tailgate closing
Heating and air
conditioning system Rear windscreen
wiper
Wipers
Ergonomic backrest, Fuel pump
headrest adjustment
Belt system
Circular pump for heating Seat control
and cooling water circuit
Headrest adjustment
Engine cooling fan
Backrest adjustment
Starter
Rear seat adjustment
Alternator,
generator Active suspension
Mirror
Steering wheel, adjustment
adjustment
Window winder
Motor Control
53 EXTERNAL USE
Motor Kit: S12ZVM Family
Digital 5 V Analog
BLDC/PMSM/SR motor control Components Components
Key Features:
• S12Z CPU @ 50 MHz bus speed
Pierce Temp 2 x 12-Bit
• 6 ch. Gate Drive Unit (GDU) with 50-150 nC total Gate Charge CAN/LIN-PHY
Osc. Sense LADC
drive capability, incl charge pump for High-Side, Bootstrap diodes SCI 1 SCI 0
RCosc.
PLL
Bootstrap
+/-1.3% Diodes
for charging external bootstrap capacitors
3x Phase
SPI MSCAN S12Z 50MHz Bus
• Embedded Vreg with switchable 5V/20 mA sensor supply Comparators
G BDM KWU Win 16-256 KB GDU 6ch
• LIN PHY, LIN2.1 / 2.2 / J2602 compliant P BDC Wdog Flash (ECC) MOS-FET-Predriver
I TIM 16b
• Dual 12-bit list-based ADC (LADC), synch with PWM through O 128B-1kB 2-32kB Charge Pump
4ch
Programmable Trigger Unit (PTU) 6ch PMF 2ch
EEPROM RAM
VSUP
(ECC) (ECC) VREG
(PWM) PTU sense
• 2x Op-amp for current sensing
Current Sense
EVDD
(2 x Op-Amp)
Target applications:
• Sensorless BLDC or PMSM motor control Options:
• Package: 64-LQFP-EP, 48 LQFP-EP, 80-LQFP-EP
• Switched Reluctance Motor
• Memory: 16 kB / 32 kB / 64 kB / 128 kB / 256 kB Flash
• Bidirectional DC motors (H-Bridge) • Spec-Options:
• Various pumps (oil, fuel, water, vacuum) • L with LIN phy
• Cooling fan, HVAC blower, Turbocharger • C with CAN-PHY (256 kB only)
• C with 2nd Vreg for external CAN phy (128/64 kB)
• “ “ with High Voltage PWM-communication interface
54 EXTERNAL USE • Temperature: V / M / W (up to 150 °C Ta per AEC-Q100
Grade 0)
Digital 5V Analog
Components Components
2x UARTs LIN Physical S12Z CPU On-chip RC 2 x 12-bit list based ADC
One linked to LIN Phy, 2nd Layer 16-bit, 32-bit MAC, OSC Simultaneous measurement
as independant Test Intf. LIN2.2 and SAE linear addressing factory- 5+4 ch. external. Plus 8 ch. int
J2602 compliant Harvard architech trimmed to +/- (temp sence, GDU phase, Ref
+/- 8 kV ESD compatible within 1.3%, meets voltages) with DMA
SPI
As alternative test Interf or capability S12 MagniV family LIN -needs
for peripherals (sensors)
Product Name VMC256 VML128 VMC128 VML64 VMC64 VML32 VML31 VML31 VM32 VM16
80LQFP- 64LQFP- 64LQFP- 64LQFP- 64LQFP- 64LQFP- 64LQFP- 48LQFP- 64LQFP- 48LQFP- 64LQFP- 48LQFP-
Package
EP EP EP EP EP EP EP EP EP EP EP EP
EEPROM (bytes) 1K 512 512 512 512 512 128 128 128 128 128 128
PHY CAN LIN 0 LIN 0 LIN LIN LIN HV HV HV HV
Separate VREG 1+1 0 1 0 1 0 0 0 0 0 0 0
GDU (HS / LS) 3/3 3/3 3/3 3/3 3/3 3/3 3/3 3/3 3/3 3/3 3/3 3/3
Bootstrap Diodes 0 0 0 0 0 0 3 3 3 3 3 3
Op Amp 2 2 2 2 2 2 2 1 2 1 2 1
ADC (ext. channels) 8+8 4+5 4+5 4+5 4+5 4+5 4+5 1+3 4+5 1+3 4+5 1+3
MSCAN 1 1 1 1 1 1 0 0 0 0 0 0
SCI 2 2 2 2 2 2 2 1 2 1 2 1
SPI 1 1 1 1 1 1 1 0 1 0 1 0
TIM (IC/OC
4 4 4 4 4 4 4 3 4 3 4 3
channels)
PWM channels 6+4 6 6 6 6 6 6 6 6 6 6 6
Internal timers RTI+API RTI+API RTI+API RTI+API RTI+API RTI+API RTI+API RTI+API RTI+API RTI+API RTI+API RTI+API
External FET
Nominal Total Gate 100-150 100-150 100-150 100-150 100-150 100-150 50-80 50-80 50-80 50-80 50-80 50-80
Charge (nC)
12 mm x 10 mm x 10 mm x 10 mm x 10 mm x 10 mm x 10 mm x 10 7 mm x 7 10 mm x 7 mm x 7 10 mm x 7 mm x 7
Package Size
12 mm 10 mm 10 mm 10 mm 10 mm 10 mm mm mm 10 mm mm 10 mm mm
Samples availability H2 2015 Now Now Now Now Now Now Q2 2015 Now Q2 2015 Now Q2 2015
Production release H2 2016 Q1 2014 Q1 2014 Q1 2014 Q1 2014 Q1 2014 Q1 2016 Q3 2016 Q1 2016 Q3 2016 Q1 2016 Q3 2016
56 EXTERNAL USE
Motor Kit: S12ZVM Ecosystem — The Complete Solution
CAN/LIN Stack
FreeMASTER:
NVM Drivers
MC ToolBox: MCAT
LIN Drivers
MC Dev Kit
-Graphical User
Rapid prototyping with Tuning Reference
Interface
Matlab Simulink Tool Software
-Instrumentation
57 EXTERNAL USE
Motor Control: Motion Force Generation
current
I B
Direction of force
causing wire motion
F1= I.Bo.l.sin
r
Current flowing
α away from you
F2 = I.Bo.l.sin
Current flowing
towards you
59 EXTERNAL USE
Motor Types
• DC Motors
− Two or more permanent magnets in stator
− Rotor windings connected to mechanical commutator
• BLDC Motors
− PM in rotor, 3-phase conductors in stator
− Trapezoidal back-EMF
60 EXTERNAL USE
BLDC Motor = Trapezoidal Back-EMF
A B C
0V
C B
61 EXTERNAL USE
PM Machines – Trapezoidal vs. Sinusoidal
• The characteristic “Trapezoidal” or “Sinusoidal” is linked with the shape of the Back-EMF of the Permanent
Magnet motor.
− “Sinusoidal” means Synchronous (PMSM) motors
− “Trapezoidal” means Brushless DC (BLDC) motors
62 EXTERNAL USE
Trapezoidal vs. Sinusoidal PM Machine
• Sinusoidal” or “Sinewave” machine means Synchronous (PMSM)
• Trapezoidal means brushless DC (BLDC) motors
• Differences in flux distribution
• Six-Step control vs. Field-Oriented Control
• Both requires position information
• BLDC motor control
− 2 of the 3 stator phases are excited at any time
− 1 unexcited phase used as sensor (BLDC Sensorless)
• Synchronous motor
− All 3 phases persistently excited at any time
− Sensorless algorithm becomes complicated
63 EXTERNAL USE
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 Permanent
Magnets
N
Rotor
S S Phase
Windings
Phase
N
Stator
Windings
64 EXTERNAL USE
Trapezoidal Control: BLDC Commutation Method
65 EXTERNAL USE
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.
Circuit Representation
of BLDC Stator Windings
Phase A Phase C
Phase B
66 EXTERNAL USE
Trapezoidal Control: Commutation Control
By adding switches, the current flow can be controlled by a MCU to perform trapezoidal
control.
Vb+
Vb+
OFF
ON At Ct OFF
ON
Vb-
N.C.
Vb+ Vb-
N.C.
Vb+
ON Ab
OFF Cb ON
OFF
Vb- Phase A Phase C
Vb-
Vb+
Phase B
ON Bt
OFF
Vb-
N.C.
Vb+
ON Bb
OFF
Vb-
67 EXTERNAL USE
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.
At
Cb Bb
Phase Phase Phase
CW
A B C
Bt o Ct
0/180○ Vb- NC Vb+ N
30○ Vb- Vb+ NC
Ab S S Ab
60○ NC Vb+ Vb-
90○ Vb+ NC Vb-
Ct
N Bt
120○ Vb+ Vb- NC
150○ NC Vb- Vb+
Bb Cb
Vb+ Vb- NC At
Top
Switch On Off Off
Bottom
Switch Off On Off
68 EXTERNAL USE
Trapezoidal Control: Turning the Motor CCW
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.
At
Cb Bb
Phase Phase Phase
CCW
A B C
Bt o Ct
0/180○ Vb+ NC Vb- N
30○ Vb+ Vb- NC
Ab S S Ab
60○ NC Vb- Vb+
90○ Vb- NC Vb+
Ct
N Bt
120○ Vb- Vb+ NC
150○ NC Vb+ Vb-
Bb Cb
Vb+ Vb- NC At
Top
Switch On Off Off
Bottom
Switch Off On Off
69 EXTERNAL USE
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”.
Hall A
A
o
N
S S
Hall B N
Hall C
70 EXTERNAL USE
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.
71 EXTERNAL USE
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.
72 EXTERNAL USE
Trapezoidal Control: Bringing It All Together
With the commutation table and the motor position table, a full trapezoidal control algorithm can be
developed.
73 EXTERNAL USE
Trapezoidal Control: Bringing It All Together
With the commutation table and the motor position table, a full trapezoidal control algorithm can be developed.
74 EXTERNAL USE
Trapezoidal Control: Bringing It All Together
With the commutation table and the motor position table, a full trapezoidal control algorithm can be
developed.
75 EXTERNAL USE
Sensor-based Commutation
Rotor Electrical Position (Degrees)
0 60 120 180 240 300 360
DC BUS voltage
Hall a Commutation
events
Hall b Bt Ct
At
Hall c Ab Bb Cb
1 2 3 4 5 6
PWM At
B
PWM Bt
A C
PWM Ct
76 EXTERNAL USE
Trapezoidal Work-Shop Control Block diagram
MC9S12ZVM Board 3-phase Inverter
Hall A
Hall B
TIM GPIO GDU
Hall C
Duty
Cycle
• Hands-On Demo:
− Motor Kit (Describe Freescale 3-Phase Motor Kit)
− Convert simple model to run on Motor Kit with MCD Toolbox and use FreeMASTER
• Model-Based Design:
− Model-Based Design Steps: Simulation, SIL, PIL and ISO 26262
− SIL/PIL Hands-On Demo Step 2 & 3 of MBD
78 EXTERNAL USE
Hands-on Demo: Implement Trapezoidal Motor Control on Motor Kit
79 EXTERNAL USE
Hands-on Demo: Implement Trapezoidal Motor Control on Motor Kit
80 EXTERNAL USE
Hands-on Demo: Implement Trapezoidal Motor Control on Motor Kit
Configure Hall Sensor Input Block using Digital I/O steps:
Remove termination blocks and pull 3 output blocks to replace them and then set them to the
correct MCU pins. Set input blocks to correct pins.
81 EXTERNAL USE
Hands-on Demo: Implement Trapezoidal Motor Control on Motor Kit
82 EXTERNAL USE
Hands-on Demo: Implement Trapezoidal Motor Control on Motor Kit
Measure the pulse width of a hall sensor so that motor speed can be calculated
83 EXTERNAL USE
Hands-on Demo: Implement Trapezoidal Motor Control on Motor Kit
84 EXTERNAL USE
Hands-on Demo: Implement Trapezoidal Motor Control on Motor Kit
3PhaseDutyCycleOut Block with Flex PWM Blocks steps:
Pull Simple PWM phase block from library, connect to phase A and configure.
85 EXTERNAL USE
Hands-on Demo: Implement Trapezoidal Motor Control on Motor Kit
PMF Block steps:
86 EXTERNAL USE
Hands-on Demo: Implement Trapezoidal Motor Control on Motor Kit
87 EXTERNAL USE
Hands-on Demo: Implement Trapezoidal Motor Control on Motor Kit
88 EXTERNAL USE
Hands-on Demo: FreeMASTER to Monitor and Tune Parameters
89 EXTERNAL USE
Agenda
• Overview:
− Introduction and Objectives
− Model-Based Design Toolbox: Library blocks, FreeMASTER, and Bootloader
• Hands-On Demo:
− Motor Kit (Describe Freescale 3-Phase Motor Kit)
− Convert simple model to run on Motor Kit with MCD Toolbox and use FreeMASTER
• Model-Based Design:
− Model-Based Design Steps: Simulation, SIL, PIL and ISO 26262
− SIL/PIL Hands-On Demo Step 2 & 3 of MBD
90 EXTERNAL USE
Motor Control: Why FOC over Trapezoidal
• FOC inherently better at aligning rotor and stator flux which results in a more efficient way of
generating motor torque.
• Since FOC continuously pulls the rotor to a new position torque ripple is reduced making it
ideal for application like electric steering where low speeds are required.
• FOC uses sinusoidal commutation therefore reducing EMC noise that trapezoidal control can
create.
• Finally, FOC can enable a motor to go above its rated speed at the expense of torque. This
is called Field Weakening where the stator windings are energized at an angle where the
rotor’s magnetic field weaker therefore increasing the magnetic field vector.
91 EXTERNAL USE
Motor Control: Creation of Rotating Magnetic Field
• The space-vectors can be defined for all motor quantities
j120 j 240
B is iAe iB e
j0
iC e
3ph currents
A B C
1
A
0
is
-1
p 2p
92 EXTERNAL USE
Motor Control: Transformation to 2-ph Stationary Frame
Is_a_comp Forward Clark Is_beta 3ph currents / MMF
Is_b_comp Transformation
Is_c_comp Is_alpha
a,b,c->alpha,beta A B C
1
b 3ph quantities
-1
p 2p
b
1.5
is
Stationary
2ph quantities
0
-1.5
p 2p
93 EXTERNAL USE
Motor Control: Transformation to 2-ph Synchronous Frame
• Position and amplitude of the stator flux/current vector is fully controlled by two DC values
b
1
b Stationary
2ph quantities
0
-1
p 2p
d q
1
is
Rotating
2ph quantities
0
beta Transformation –
q p 2p
, b > d, q
94 EXTERNAL USE
Motor Control: FOC Transformation Summary
Phase A d d Phase A
Control
3-Phase Stationary Rotating
Action
Phase B Phase B
Phase C
to
2-Phase
b to
Rotating
q q to b SVM
Stationary Phase C
95 EXTERNAL USE
Motor Control: FOC Transformation Summary
Control Action
PWM A
Torque IQ PI IQ Va
IQ +
Control loop Controller cmd cmd
- Space
Inverse PWM B
Vector
Park PWM
Modulation
Transform
(SVM)
ID PI ID Vb
+ loop Controller cmd cmd PWM C
Zero -
IA
Va
ID
Park Clark IB
A/D
Transform Transform
Vb
IC
IQ
Motor Position
I/O
96 EXTERNAL USE
Motor Control: Field Oriented Control in Steps
1. Measure obtain state variables quantities
(e.g. phase currents, voltages, rotor position, rotor speed …).
2. Transform quantities from 3-phase system to 2-phase system (Forward Clark Transform) to simplify the
math - lower number of equations
97 EXTERNAL USE
Motor Control: Commutation Control Methods
• All three inverter legs (6 transistors) are managed at any time – transistors are either switched on or off
OFF
ON
OFF
PWM period
32 1 2 3
98 EXTERNAL USE
Motor Control: Commutation Control Methods
• All three inverter legs (6 transistors) are managed at any time – transistors are either switched on or off
OFF
ON
OFF
PWM period
32 1 2 3
99 EXTERNAL USE
Motor Control: Commutation Control Methods
• All three inverter legs (6 transistors) are managed at any time – transistors are either switched on or off
ON
OFF
PWM period
32 1 2 3
100 EXTERNAL USE
Motor Control: Current Sensing with Shunt Resistors
DC Bus
+U/2
• Shunt resistors voltage drop measured
PWM At PWM Bt PWM Ct
• SW calculation of all 3 phase currents
Phase A Phase B Phase C
needed
PWM Ab PWM Bb PWM Cb
iSA n iSC
Sampled Current
Synchronized
Sampling
PWM 0
Scanning Principle
0.5
resolver pole-pairs (usually 1-3 cycles) 0
-0.5
-1
0 0.001 0.002 0.003 0.004 0.005 0.006 0.007 0.008 0.009 0.01
Uref
1 Reference Voltage
Ucos
Rotor shaft 0.5
0
-0.5
-1
0 0.001 0.002 0.003 0.004 0.005 0.006 0.007 0.008 0.009 0.01
PWM Reload
Time base Event
Control
Counter
Async Com-
mutation Event
Bus Clock
108 EXTERNAL USE
Motor Control: Autonomous PMSM Application Timing
Two shunts current sensing
PMFMOD
VAL0
Hardware Events
PWM counter 100 us
SW Serviced
0
Preset
Phase current A ADC list
sampling
DMA0
UDCBus
sampling
ADC0 conversion
Phase current B
ADC1 sampling
DMA1 Temp sampling
EOC EOC
ADC1 conversion interrupt interrupt
SW
FOC
CPU ISR service
routine
FOC calculations application
Calculations
Free for application use
• Force Mode – Use the requested speed and position as the estimated speed and position for the back-EMF
observer and FOC control. FOC always uses phase currents from the shunt resisters. Speed control uses
requested speed and position to close the loop on speed.
• Tracking Mode – The back-EMF observer closes the loop and uses it own estimated position and speed
vs. the requested position and speed for feedback. Speed control uses requested speed and position to
close the loop on speed.
• Sensorless Mode – Speed control uses back-EMF observer speed and position to close the loop on speed.
• Basically each mode transition happens at a different requested speed value to eventually have the motor
spin fast enough to generated enough back-EMF to accurately estimate the motor position and speed.
• Hands-On Demo:
− Motor Kit (Describe Freescale 3-Phase Motor Kit)
− Convert simple model to run on Motor Kit with MCD Toolbox and use FreeMASTER
• Model-Based Design:
− Model-Based Design Steps: Simulation, SIL, PIL and ISO 26262
− SIL/PIL Hands-On Demo Step 2 & 3 of MBD
FastLoopInput Block
FastLoopInput