FTF Ind F0010
FTF Ind F0010
Development in MATLAB™/Simulink™
Using the Motor Control Toolbox
FTF-IND-F0010
TM
External Use
Agenda
• Overview: 30 minutes
− Introduction and Objectives
− Motor Control Development Toolbox: Library blocks, FreeMASTER,
and Bootloader
− Model Based Design Steps: Simulation, SIL, PIL and ISO26262
• Hands-on Demo: 20 minutes
− Convert simple model to run on Motor Kit with MCD Toolbox and use
FreeMASTER
• Motor Control: 30 minutes
− Motor Kit (Describe Freescale 3-Phase Motor Kit)
− Trapezoidal control and how to use it to turn a motor
• Motor Control Hands-on Demo: 80 minutes
− Implement Trapezoidal Motor Control on Motor Kit
− Run software from the model and use FreeMASTER to monitor and
tune parameters
• SIL/PIL Demo: 10 minutes
• Summary and Q&A: 10 minutes
TM
External Use 1
Introduction: WHAT DO WE DO?
TM
External Use 2
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 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. Motor Control Development Toolbox allows this stage of the
development to generate 100% of the code from the model.
TM
External Use 3
Introduction: Motor Control Development Toolbox
• The Motor Control Development Toolbox includes an embedded target supporting Freescale
MCUs and 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 Freescale’s renowned Motor Control Center of Excellence. The library provides dozens of
blocks optimized for fast execution on Freescale 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.
TM
External Use 4
Introduction: Reduce Development Time With MBD
and MC Toolbox
Use software-based model Fewer defects found in
System vs. paper-based method, this phase of testing, Functional
Requirements and start testing at very where finding defects is Testing
earliest stage. expensive.
TM
External Use 5
Introduction: Reduce Development Time With MBD
and MC Toolbox
System Functional
Requirements Testing
Modeling/
Simulation
HIL Testing
Rapid Prototype
To This!
Target MCU
Implementation
Time
TM
External Use 6
Objectives
After this Hands-on Workshop, you will be able to:
Use the Motor Control Development Toolbox to auto-
generate and build software for the MCU directly from the
MATLAB™/Simulink™ environment.
Configure the MCU peripherals required to implement
three phase motor control using the MCU and the low-
voltage Three Phase Motor Control Kit.
Implement Trapezoidal Motor Control from a model based
design environment and auto generate the code to run the
brushless DC Motor provided with the Motor Kit.
Know how Motor Control Development Toolbox can help
with your motor control development projects and
Freescale MCUs.
TM
External Use 7
Objectives
TM
External Use 8
Agenda
• Overview: 30 minutes
− Introduction and Objectives
− Motor Control Development Toolbox: Library blocks,
FreeMASTER, and Bootloader
− Model Based Design Steps: Simulation, SIL, PIL and ISO26262
• Hands-on Demo: 20 minutes
− Convert simple model to run on Motor Kit with MCD Toolbox and use
FreeMASTER
• Motor Control: 30 minutes
− Motor Kit (Describe Freescale 3-Phase Motor Kit)
− Trapezoidal control and how to use it to turn a motor
• Motor Control Hands-on Demo: 80 minutes
− Implement Trapezoidal Motor Control on Motor Kit
− Run software from the model and use FreeMASTER to monitor and
tune parameters
• SIL/PIL Demo: 10 minutes
• Summary and Q&A: 10 minutes
TM
External Use 9
MCD Toolbox: Toolbox Library Contents
Peripherals Configuration/Modes Utility
• General • Compiler Options • FreeMASTER Interface
− ADC conversion − CodeWarrior • Data acquisition
− Digital I/O − Wind River DIAB • Calibration
− PIT timer
− Green Hills • Customize GUI
− ISR
− Cosmic
• Communication Interface • Profiler Function
− IAR
− CAN driver • Exec. time measurement
− GCC
− SPI driver • Available in PIL
− RAM/FLASH targets
− I2C • Available in standalone
• Simulation Modes
• Motor Control Interface
− Normal
− Cross triggering unit
− Accelerator
MCUs Supported
− PWM
− eTimer block(s) − Software in the Loop (SIL) • MPC5643L
− Sine wave generation − Processor in the Loop (PIL) • MPC567xK
− ADC Command List • MCU Option • MPC574xP
− GDU (Gate Drive Unit) − Multiple packages • S12ZVM
− PTU (Prog Trigger Unit) − Multiple Crystal frequencies • KV10Z
− TIM Hall Sensor Port • 56F82xx (Coming Soon)
− FTM (Flex Timer Module) • KV31/30 (Coming Soon)
− PDB (Programmable Delay Block)
NOTE: Peripheral Block and compiler availability is dependant on which MCU is use.
TM
External Use 10
MCD Toolbox: Math and Motor Control Library Contents
GFLIB GDFLIB GMCLIB
• Trigonometric Functions • Finite Impulse Filter • Clark Transformation
− GFLIB_Sin − GMCLIB_Clark
− GDFLIB_FilterFIR
− GFLIB_Cos − GMCLIB_ClarkInv
− GFLIB_Tan • Moving Average Filter
− GFLIB_Asin • Park Transformation
− GFLIB_Acos − GDFLIB_FilterMA − GMCLIB_Park
− GFLIB_Atan • 1st Order Infinite Impulse Filter − GMCLIB_ParkInv
− GFLIB_AtanXY
• Limitation Functions − GDFLIB_FilterIIR1init • Duty Cycle Calculation
− GFLIB_Limit − GDFLIB_FilterIIR1 − GMCLIB_SvmStd
− GFLIB_LowerLimit • Elimination of DC Ripples
− GFLIB_UpperLimit • 2nd Order Infinite Impulse Filter
− GFLIB_VectorLimit − GMCLIB_ElimDcBusRip
− GDFLIB_FilterIIR2init
• PI Controller Functions • Decoupling of PMSM Motors
− GFLIB_ControllerPIr − GDFLIB_FilterIIR2 − GMCLIB_DecouplingPMSM
− GFLIB_ControllerPIrAW
− GFLIB_ControllerPIp
− GFLIB_ControllerPIpAW
• Linear Interpolation
− GFLIB_Lut1D
• Hysteresis Function
− GFLIB_Hyst
• Signal Integration Function
− GFLIB_IntegratorTR
• Sign Function
− GFLIB_Sign
• Signal Ramp Function
− GFLIB_Ramp
TM
External Use 11
MCD Toolbox: RAppID Bootloader Utility
The RAppID Bootloader works with the built-in Boot Assist Module (BAM) included in the Freescale
Qorivva and also supports MagniV, Kinetis, and DSCs family of parts. 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, MPC564xL, MPC5604/3P, MPC574xP, S12ZVM, KV10 and 56F82xx.
Graphical User Interface Command
Line
TM
External Use 12
FreeMASTER – Run Time Debugging Tool
TM
External Use 13
MCD Toolbox: Summary of 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
TM
External Use 14
Motor Control Development
Toolbox
Any Questions?
TM
External Use 15
Agenda
• Overview: 30 minutes
− Introduction and Objectives
− Motor Control Development Toolbox: Library blocks, FreeMASTER,
and Bootloader
− Model Based Design Steps: Simulation, SIL, PIL and ISO26262
• Hands-on Demo: 20 minutes
− Convert simple model to run on Motor Kit with MCD Toolbox and use
FreeMASTER
• Motor Control: 30 minutes
− Motor Kit (Describe Freescale 3-Phase Motor Kit)
− Trapezoidal control and how to use it to turn a motor
• Motor Control Hands-on Demo: 80 minutes
− Implement Trapezoidal Motor Control on Motor Kit
− Run software from the model and use FreeMASTER to monitor and
tune parameters
• SIL/PIL Demo: 10 minutes
• Summary and Q&A: 10 minutes
TM
External Use 16
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 ID
Va
Conversion Forward
Park
Forward
Clark
IB
Transform Transform
Vb
IC
IQ
Motor Position
Analog
Analog Device Model
Sensor Model Controller Model
External Use 17
Model Based Design Steps: Step 2 (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
Transform
PWM
Modulation
PWM B
ID PI ID Vb
+ loop Filter cmd cmd PWM C
Zero -
Gate
IA Driver
A/D ID
Va
Conversion Forward
Park
Forward
Clark
IB
Transform Transform
Vb
IC
IQ
Motor Position
Analog
Analog Device Model
Sensor Model Controller Model
External Use 18
Model Based Design Steps: Step 3 (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 ID
Va
Conversion Forward
Park
Forward
Clark
IB
Transform Transform
Vb
IC
IQ
Motor Position
Analog
Analog Device Model
Sensor Model Controller Model
External Use 19
Model Based Design Steps: Step 3 (PIL)
TM
External Use 20
Example IEC 61508 and ISO 26262 Workflow for
Model-Based Design with MathWorks Products*
Model advisor, modeling PIL testing using embedded IDE links
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 Generate production code to run on embedded MCU with real
Embedded Control
Module (ECM)
Electric Motor motor 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.
TM
External Use 22
Model Based Design Steps: Summary
Zero
+
-
loop Filter cmd cmd PWM C
Zero
+
-
loop Filter cmd cmd PWM C
Zero
+
-
loop Filter cmd cmd PWM C
Gate Zero
+
-
ID
loop
PI
Filter
ID
cmd
Vb
cmd PWM C
Gate
Driver
IA IA IA
Va Va Va
Driver
IA
ID ID ID Va
Forward Forward IB Forward Forward IB Forward Forward IB ID
Park Clark Park Clark Park Clark
Forward Forward IB
Transform Transform Transform Transform Transform Transform
Vb Vb Vb Park Clark
IC IC IC Transform Transform
IQ IQ IQ Vb
IC
IQ
Electric Motor Model Electric Motor Model Electric Motor Model Electric Motor
MCU with
PC Environment
PC Environment PC Environment Embedded Control
+ MCU
Module (ECM)
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 using SIL MBD Simulation with ANSI C Code using PIL ANSI C Code Running on Target HW & 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 design See memory/stack usage on MCU Start testing implementation on target ECM
Modeling style guidelines applied Start testing implementation approach Start testing implementation approach Code generate control algorithm +
Algorithm functional partitioning Target testing controls algorithm on MCU I/O drivers. Complete implementation on
Interfaces are defined here Testing of functional components of algorithm ECM. Test system in target environment
Test harness to validate all requirements Refine model for code generation Utilize calibration tools for data logging and
Test coverage of model here Function/File partitioning parameter tuning
Creates functional baseline of model Data typing to target environment done here
Scaling for fixed point simulation and code gen Execute code on target MCU
Testing of functional components of algorithm Functional testing in target environment
Test harness to validate all requirements Ensure execution on target is correct as well
Test coverage of model here as code generation on target is performing as
Creates functional baseline of model desired.
Equivalence testing
TM
External Use 23
Agenda
• Overview: 30 minutes
− Introduction and Objectives
− Motor Control Development Toolbox: Library blocks, FreeMASTER,
and Bootloader
− Model Based Design Steps: Simulation, SIL, PIL and ISO26262
• Hands-on Demo: 20 minutes
− Convert simple model to run on Motor Kit with MCD Toolbox
and use FreeMASTER
• Motor Control: 30 minutes
− Motor Kit (Describe Freescale 3-Phase Motor Kit)
− Trapezoidal control and how to use it to turn a motor
• Motor Control Hands-on Demo: 80 minutes
− Implement Trapezoidal Motor Control on Motor Kit
− Run software from the model and use FreeMASTER to monitor and
tune parameters
• SIL/PIL Demo: 10 minutes
• Summary and Q&A: 10 minutes
TM
External Use 24
Hands-on Demo: Tower Hardware
TWR-MKV10Z32 TWR-MC-LV3PH
Features: Features:
• MKV10Z32VLF7 MCU (48LQFP) • Input voltage 12-24V DC
• OpenSDA debug circuit with Micro USB connector and • Output current 5-10 Amps
virtual serial port • 3-phase MOSFET inverter
• MMA8451Q 3-axis digital accelerometer (i2c interface) • 3-phase pre-driver MC33937
• LEDs with connected buffers to PWM channels for dimming • Analog sensing
• 2 push buttons for user input or interrupts • Motor speed/position sensors interface
• 4 Thermistors for single ended or differential analogue • 2 pole-pair BLDC motor with Hall
inputs, 2 motor control auxiliary connectors sensors (4000 RPM rated speed)
• Compatible with TWR-MC-LV3PH motor driver peripheral • On-board power regulation for Tower
module (NOTE: TWR-MC-LV3PH module and TWR-ELEV System (single power supply via
module must be ordered separately if required. TWR-MC-LV3PH power jack)
TM
External Use 25
Hands-on Demo: Simple Model
Run Simple Model Simulation
1. Open Model “Blinky.slx”
2. You will see a model that toggles outputs
and will change the way it toggles the
outputs based on an input.
3. Run simulation and open the scope. You
should see the following on the scope:
TM
External Use 26
Hands-on Demo: Simple Model
Convert Simple Model and Run
1. Save model as “KV10_Blinky.slx”
2. Select KV10 TLC file to configure model for the MCU
3. Open Simulink library
4. Go to Motor Control Toolbox for Configuration Information Block
5. Drag the block into the model
6. Open block and go to PIL/BAM setup tab
7. Check download code after build
8. Enter the COM port number that you are using from PC
9. Delete Step block and Scope
10. Go back to library under General Purpose Blocks, drag in a Digital Output
block and connect to each mode output a Digital Output Block. Select the
output pins to use which are connected to an LED (See next Slide).
11. Go back to library under Motor Control Blocks and drag in a Digital input
block to read SW1 (PTA4).
12. Go back to the library and under utilities get a Profiler Function block so
that the execution time can be measured.
TM
External Use 27
Hands-on Demo: LED Simple Model
Convert Simple Model and Run
• This is what the model should look like after step 12
TM
External Use 28
Hands-on Demo: Simple Model
TM
External Use 29
Hands-on Demo: Simple Model
TM
External Use 30
Hands-on Demo: Read A/D and Toggle LED Simple Model
Using FreeMASTER with Hands-on Demo
• This is what you should see after step 19
TM
External Use 31
Hands-on Demo: Simple Model
Any Questions?
TM
External Use 32
Agenda
• Overview: 30 minutes
− Introduction and Objectives
− Motor Control Development Toolbox: Library blocks, FreeMASTER,
and Bootloader
− Model Based Design Steps: Simulation, SIL, PIL and ISO26262
• Hands-on Demo: 20 minutes
− Convert simple model to run on Motor Kit with MCD Toolbox and use
FreeMASTER
• Motor Control: 30 minutes
− Motor Kit (Describe Freescale 3-Phase Motor Kit)
− Trapezoidal control and how to use it to turn a motor
• Motor Control Hands-on Demo: 80 minutes
− Implement Trapezoidal Motor Control on Motor Kit
− Run software from the model and use FreeMASTER to monitor and
tune parameters
• SIL/PIL Demo: 10 minutes
• Summary and Q&A: 10 minutes
TM
External Use 33
Tower Motor Kit Overview
Features
• Electrical specifications:
− Input voltage 12-24V DC
− Output current 5-10 Amps
• 3-phase MOSFET inverter
• 3-phase pre-driver MC33937, configurable thru SPI
analog sensing (dcb voltage, dcb current, phase
currents, back-EMF voltage)
• Motor speed/position sensors interface (Encoder, Hall)
• Hardware over-current fault protection
• On-board power regulation for Tower System (single power supply via
TWR-MC-LV3PH power jack)
• Brushless DC (BLDC) Motor Linix 45ZWN24-40
Purpose
• The purpose of the Low Voltage Motor Control Tower module is to be
used by customers to prototype DC, BLDC and PMSM motor control
solutions and to evaluate/demonstrate various algorithms.
TM
External Use 34
Tower Motor Kit: TWR-MC-LV3PH Module
External Use 35
Tower Motor Kit: 3PP Driver Chip (MC33937)
Features
• Fully specified from 8.0V to 40V; covers 12V
and 24V automotive systems
• Extended operating range from 6.0V to 58V
covers 12V and 42V systems
• 1.0A gate drive capability with protection
• Protection against reverse charge injection
• Includes a charge pump to support full FET
drive at low battery voltages
• Dead time is programmable via the SPI
• Simultaneous output capability enabled via
safe SPI command
Purpose
• The IC contains three high-side FET pre-
drivers and three low-side FET pre-drivers.
Three external bootstrap capacitors provide
gate charge to the high side FETs.
The IC interfaces to an MCU via six input control signals, a SPI port for device setup and
asynchronous reset, enable and interrupt signals
TM
External Use 36
Tower Motor Kit: Brushless DC Motor
Features
Model: Linix 45ZWN24-40
Motor Type: Brushless DC
Windings: “Y” Connection Method
Pole Pairs: 2 pairs
Rated Voltage: 24V
Rated Current: 2.3 A
Rated Torque: 990 g.cm
Rated Power: 40 Watts
Rated Speed (Load): 4000 RPM
Speed (Un-Loaded): 4900 RPM
Position Sensing: Hall Type (A, B, C)
Note: Pole pair count for this motor means that every single mechanical
revolution equals two electrical revolutions. State change in Hall sensors
is every 60 degrees electrical.
TM
External Use 37
Introducing Kinetis V Series
Motor Control and Power Conversion MCUs
• Builds on Freescale’s motor and power
control expertise to address NEW mass
market customers.
TM
External Use 38
Kinetis V Series Target Applications
TM
External Use 39
Solutions for Motor Control and Digital Power Conversion
+ Advanced Memory,
Connectivity and Communications
Performance
KVxx
2014 Families
+ High Speed ADC
KV4x Family
High performance
+ High Resolution PWM motors, UPS, solar and Increasing
mid range AC/DC control performance and
2014 feature
integration
KV3x Family + Multi Channel Timers
Mid range PMSM, Optimized
+ Floating Point Unit
UPS power control memory
2014 configurations
KV1x Family + Motor Control Software
BLDC, entry level PMSM
Feature Integration
Freescale IDE, RTOS, Software Libraries and Motor Control Development Tools
TM
External Use 40
Kinetis V Series Enablement
New Kinetis Motor Suite Motor Control Tools
A simple-to-use, motor New Freescale Enablement Software
Kinetis SDK, Kinetis Design Studio, Kinetis Bootloader
control development
suite that allows FreeMASTER: GUI-based run-time debug monitor and
data visualization tool
customers of all
experience levels to MCAT: FreeMASTER plug-in for real-time monitoring,
tuning and updating of control parameters
design applications
quickly, efficiently and Motor Control Toolbox: MATLAB™ modeling
without the need for environment plug-in for automatic code generation
in-depth motor control expertise. Software Libraries for CM0+/M4 & IEC60730:
Motor Parameters & Control
Math, General, Filter and Motor Control libraries.
• Turnkey solutions initially Sensorless algorithms for advanced control
targeting fans, compressors and ADRC
system.
External Use 41
Kinetis V Series Availability
TM
External Use 42
Tower Motor Kit: Kinetis V Series KV1x Overview
Core System Memories Clocks
Key Features:
Core/System ARM Cortex-M0+ Internal and
External
Program Flash SRAM Frequency-
75MHz 32KB 8KB Locked Loop
• 75MHz ARM CM0+ with 4ch DMA Watchdogs
External Use 43
Tower Motor Kit: System Diagram
Vb+
Phase
Voltages
A
Phase A
3PP Phase B
Driver Chip Phase C
(MC33937)
BLDC
Motor
TM
External Use 44
Tower Motor Kit
Any Questions?
TM
External Use 45
Agenda
• Overview: 30 minutes
− Introduction and Objectives
− Motor Control Development Toolbox: Library blocks, FreeMASTER,
and Bootloader
− Model Based Design Steps: Simulation, SIL, PIL and ISO26262
• Hands-on Demo: 20 minutes
− Convert simple model to run on Motor Kit with MCD Toolbox and use
FreeMASTER
• Motor Control: 30 minutes
− Motor Kit (Describe Freescale 3-Phase Motor Kit)
− Trapezoidal control and how to use it to turn a motor
• Motor Control Hands-on Demo: 80 minutes
− Implement Trapezoidal Motor Control on Motor Kit
− Run software from the model and use FreeMASTER to monitor and
tune parameters
• SIL/PIL Demo: 10 minutes
• Summary and Q&A: 10 minutes
TM
External Use 46
Trapezoidal Control: Brushless DC Motor
N
Rotor
S S Phase
Windings
Phase
N
Stator
Windings
TM
External Use 47
Trapezoidal Control: Commutation Method
Phase A Phase C
Phase B
TM
External Use 48
Trapezoidal Control: Commutation Control
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-
TM
External Use 49
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.
Phase Phase Phase
CW
A B C At
0/180○ Vb- NC Vb+ Cb Bb
TM
External Use 50
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.
Phase Phase Phase
CCW At
A B C
Cb Bb
0/180○ Vb+ NC Vb-
30○ Vb+ Vb- NC Bt o Ct
N
60○ NC Vb- Vb+
90○ Vb- NC Vb+ Ab S S Ab
120○ Vb- Vb+ NC
150○ NC Vb+ Vb- N
Ct Bt
Vb+ Vb- NC
Top Bb Cb
Switch On Off Off
At
Bottom
Switch Off On Off
TM
External Use 51
Trapezoidal Control: Motor Position
S S
Hall B N
TM
Hall C
External Use 52
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.
TM
External Use 53
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.
TM
External Use 54
Trapezoidal Control: Bringing It All Together
• With the commutation table and the motor position table, a full
trapezoidal control algorithm can be developed.
External Use 55
Trapezoidal Control: Bringing It All Together
• With the commutation table and the motor position table, a full
trapezoidal control algorithm can be developed.
Trapezoidal Control Algorithm Clockwise Rotation
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 Vb+ Vb- NC
1 1 1 Invalid n/a Top
On Off Off
Switch
Bottom
Switch Off On Off
TM
External Use 56
Trapezoidal Control: Bringing It All Together
• With the commutation table and the motor position table, a full
trapezoidal control algorithm can be developed.
Trapezoidal Control Algorithm Counter Clockwise Rotation
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 Vb+ Vb- NC
1 1 1 Invalid n/a Top
On Off Off
Switch
Bottom
Switch Off On Off
TM
External Use 57
Trapezoidal Control
Any Questions?
TM
External Use 58
Agenda
• Overview: 30 minutes
− Introduction and Objectives
− Motor Control Development Toolbox: Library blocks, FreeMASTER,
and Bootloader
− Model Based Design Steps: Simulation, SIL, PIL and ISO26262
• Hands-on Demo: 20 minutes
− Convert simple model to run on Motor Kit with MCD Toolbox and use
FreeMASTER
• Motor Control: 30 minutes
− Motor Kit (Describe Freescale 3-Phase Motor Kit)
− Trapezoidal control and how to use it to turn a motor
• Motor Control Hands-on Demo: 80 minutes
− Implement Trapezoidal Motor Control on Motor Kit
− Run software from the model and use FreeMASTER to monitor
and tune parameters
• SIL/PIL Demo: 10 minutes
• Summary and Q&A: 10 minutes
TM
External Use 59
Hands-on Demo: Implement Trapezoidal Motor Control on
Motor Kit
Summary Trapezoidal Motor Control on KV10 steps:
1. Open Trap_Ctrl.slx
2. Save model as KV10_Trap_Ctrl.slx
3. Configure KV10 configuration block
4. Configure Input port blocks to read motor hall position state
5. Configure Input Edge Capture Blocks to detect change in motor position
sensors
6. Configure an Input Edge Capture Block to measure one of the Hall sensor pulse
width for RPM calculation
7. Configure Digital Input for use in controlling RPM Request
8. Configure DSPI blocks to interface to Freescale 3PP driver
9. Connect and configure PWM blocks for output to switches
TM
External Use 60
Hands-on Demo: Implement Trapezoidal Motor Control on
Motor Kit
TM
External Use 61
Hands-on Demo: Implement Trapezoidal Motor Control on
Motor Kit
Configure Hall Sensor Input Block using Digital I/O steps:
Set input blocks to correct pins.
TM
External Use 62
Hands-on Demo: Implement Trapezoidal Motor Control on
Motor Kit
The Trapezoidal Control algorithm needs to run on any change of state or event so that we
can change our Commutation State as quickly as possible. Therefore we want to trigger off
of any rising or falling edge of the hall sensors.
TM
External Use 63
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
TM
External Use 64
Hands-on Demo: Implement Trapezoidal Motor Control on
Motor Kit
• Using the Input Edge Capture blocks we can monitor the transitions of the
hall sensors to trigger a function call to set a new commutation state. We
can measure the a hall sensor pulse time to determine RPM.
• We also can capture the number of changes in the hall sensors states and
save that for determining the motor RPM.
TM
External Use 65
Hands-on Demo: Implement Trapezoidal Motor Control on
Motor Kit
TM
External Use 66
Hands-on Demo: Implement Trapezoidal Motor Control on
Motor Kit
TM
External Use 67
Hands-on Demo: Implement Trapezoidal Motor Control on
Motor Kit
MotorSpeedReqInput Block steps:
TM
External Use 68
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.
TM
External Use 69
Hands-on Demo: Implement Trapezoidal Motor Control on
Motor Kit
PWM Block steps:
TM
External Use 70
Hands-on Demo: Implement Trapezoidal Motor Control on
Motor Kit
PWM Block steps:
TM
External Use 71
Hands-on Demo: Implement Trapezoidal Motor Control on
Motor Kit
3PhaseDutyCycleOut Block with Flex PWM Blocks steps:
TM
External Use 72
Hands-on Demo: FreeMASTER to Monitor and Tune
Parameters
Using FreeMASTER with Hands-on Demo
1. Start FreeMASTER and open project KV10_Trap_Ctrl.pmp. Press OK if
a message comes up that the map file has been updated.
2. Go to Project Options pull-down and select “Options”. Verify that COM
settings are the same as what they were set to in your model.
3. Once the COM settings are correct, press the STOP button.
4. Change MotorSpeedReqFreemaster Variable to 1000 RPM.
TM
External Use 73
Hands-on Demo: How can we make the response better
TM
External Use 74
Hands-on Demo: Trapezoidal
Motor Control
Any Questions?
TM
External Use 75
Agenda
• Overview: 30 minutes
− Introduction and Objectives
− Motor Control Development Toolbox: Library blocks, FreeMASTER,
and Bootloader
− Model Based Design Steps: Simulation, SIL, PIL and ISO26262
• Hands-on Demo: 20 minutes
− Convert simple model to run on Motor Kit with MCD Toolbox and use
FreeMASTER
• Motor Control: 30 minutes
− Motor Kit (Describe Freescale 3-Phase Motor Kit)
− Trapezoidal control and how to use it to turn a motor
• Motor Control Hands-on Demo: 80 minutes
− Implement Trapezoidal Motor Control on Motor Kit
− Run software from the model and use FreeMASTER to monitor and
tune parameters
• SIL/PIL Demo: 10 minutes
• Summary and Q&A: 10 minutes
TM
External Use 76
SIL/PIL Demo
TM
External Use 77
SIL/PIL Demo
1. You can switch between SIL and PIL by using the tools menu.
TM
External Use 78
SIL/PIL Demo
Any Questions?
TM
External Use 79
Agenda
• Overview: 30 minutes
− Introduction and Objectives
− Motor Control Development Toolbox: Library blocks, FreeMASTER,
and Bootloader
− Model Based Design Steps: Simulation, SIL, PIL and ISO26262
• Hands-on Demo: 20 minutes
− Convert simple model to run on Motor Kit with MCD Toolbox and use
FreeMASTER
• Motor Control: 30 minutes
− Motor Kit (Describe Freescale 3-Phase Motor Kit)
− Trapezoidal control and how to use it to turn a motor
• Motor Control Hands-on Demo: 80 minutes
− Implement Trapezoidal Motor Control on Motor Kit
− Run software from the model and use FreeMASTER to monitor and
tune parameters
• SIL/PIL Demo: 10 minutes
• Summary and Q&A: 10 minutes
TM
External Use 80
Summary
You now know how to do Trapezoidal Control and auto-generate
software with the Motor Control Development Toolbox directly from
the MATLAB™/Simulink™ for Freescale MCUs.
You now understand how to run SIL and PIL with MCD Toolbox and
how it can accelerate your development, including systems being
developed under IEC 61508 using PIL.
You know how the Freescale MCU covered can fit into your motor
control application.
TM
External Use 81
Summary: Publications
MathWorks Announces Simulink Code Generation Targets in New Freescale Motor Control
Development Toolbox
www.mathworks.com
• Simulink and Embedded Coder enable engineers to generate production code for Freescale
MCUs in IEC 61508 (SIL3) and ISO 26262 (ASIL-D) compliant systems.
TM
External Use 82
Summary
Any Questions?
TM
External Use 83
TM
www.Freescale.com