Sensorless PMSM Control on MKV46F256 Using Kinetis SDK

Similar documents
Sensorless PMSM Field-Oriented Control on Kinetis KV and KE

Dual FOC Servo Motor Control on i.mx RT

Automated PMSM Parameter Identification

Low Cost PMSM Sensorless Field-Oriented Control Based on KE02

PMSM Sensorless FOC for a Fan Using the Kinetis KV10

Single Phase Two-Channel Interleaved PFC Operating in CrM Using the MC56F82xxx Family of Digital Signal Controllers

Sensorless BLDC Motor Control Using FRDM-KE02Z Based on Tower Board

KEA128LEDLIGHTRD Quick Start Guide. Lighting Control Module Reference Design using Kinetis KEA128

Dead-Time Compensation Method for Vector-Controlled VSI Drives Based on Qorivva Family

3-in-1 Air Condition Solution

Firmware plugin for STSW-ESC001V1 board with ST Motor Control FOC SDK

Interleaved PFC Average Current Control

Three-Phase BLDC Sensorless Motor Control Using the MKV4x In Quadcopter Application

RX23T inverter ref. kit

STM32 PMSM FOC SDK v3.2. 蒋建国 MCU Application Great China

Motor Control using NXP s LPC2900

Using the High Voltage Physical Layer In the S12ZVM family By: Agustin Diaz

Reference Oscillator Crystal Requirements for MKW40 and MKW30 Device Series

Hello, and welcome to this presentation of the FlexTimer or FTM module for Kinetis K series MCUs. In this session, you ll learn about the FTM, its

Quick Start Guide. TWR-MECH Mechatronics Board TOWER SYSTEM

Electric Bike BLDC Hub Motor Control Using the Z8FMC1600 MCU

AN4269. Diagnostic and protection features in extreme switch family. Document information

How to Use GDU Module in MC9S08SU16

VORAGO Timer (TIM) subsystem application note

RL78 Motor Control. YRMCKITRL78G14 Starter Kit. Renesas Electronics Europe. David Parsons Application Engineering Industrial Business Group.

AP CANmotion. Evaluation Platform with BLDC Motor featuring XC886CM Flash Microcontroller Version 2007/10. Microcontrollers

Migrate PWM from MC56F8013 to MC How to set up the PWM peripheral on the MC56F8247 using the setting of the PWM on the MC56F8013

Control of a DC/DC Converter Using FlexPWM s Force-Out Logic

Parallel Configuration of H-Bridges

Improving feedback current accuracy when using H-Bridges for closed loop motor control

FlexTimer and ADC Synchronization

Using Z8 Encore! XP MCU for RMS Calculation

56F Phase AC Induction Motor V/Hz Control using Processor Expert TM Targeting Document. 56F bit Digital Signal Controllers. freescale.

BLDC Motor Control on Z8FMC16 Series MCUs Using Sensored Sinusoidal PWM Modulation

MB9BF568R Series FM4 PMSM Servo Motor Speed Control User Manual

F²MC-8FX/16LX/16FX/FR FAMILY BLDC DRIVE WITH THE PPG

XGATE Library: PWM Driver Generating flexible PWM signals on GPIO pins

AVR42778: Core Independent Brushless DC Fan Control Using Configurable Custom Logic on ATtiny817. Features. Introduction. AVR 8-bit Microcontroller

Optimizing Magnetic Sensor Power Operations for Low Data Rates

Vybrid ASRC Performance

Overview of the STM32F103xx ACIM and PMSM motor control software libraries release 2.0

Capacitive Sensing Interface of QN908x

The High-Performance Data Acquisition Circuit

AN Industrial Stepper Motor Driver. Application Note Abstract. Introduction. Stepper Motor Control Method

1.2 A 15 V H-Bridge Motor Driver IC

Reference Circuit Design for a SAR ADC in SoC

A COMPARISON STUDY OF THE COMMUTATION METHODS FOR THE THREE-PHASE PERMANENT MAGNET BRUSHLESS DC MOTOR

TUTORIAL Simulation and Code Generation of TI InstaSPIN Using DRV8312 EVM

1.2 A 15 V H-Bridge Motor Driver IC

Generating DTMF Tones Using Z8 Encore! MCU

Temperature Monitoring and Fan Control with Platform Manager 2

Motor Control Solutions

BLDC Sensorless Reference Design Using MC56F8006 Devices Supported: MC56F8006

TMC603EVAL MANUAL Evaluation board for the TMC603 three phase motor driver with BLDC back EMF commutation hallfx

Tarocco Closed Loop Motor Controller

Temperature Monitoring and Fan Control with Platform Manager 2

Hands-on Workshop: Motor Control Part 4 - Brushless DC Motors Made Easy

User Guide IRMCS3041 System Overview/Guide. Aengus Murray. Table of Contents. Introduction

Reaction Module 2 for Peak&Hold Injection Control on the MPC5746R Using REACM2 Utility Functions

MPXM2051G, 0 to 50 kpa, Gauge Compensated Pressure Sensors

MAX11300PMB1 Peripheral Module and Munich (USB2PMB1) Adapter Board Quick Start Guide

Getting started with the STSW-SPIN3202 firmware package

Implementing PFC Average Current Mode Control using the MC9S12E128 Addendum to Reference Design Manual DRM064

Application Note, V1.0, Oct 2006 AP08019 XC866. Sensorless Brushless DC Motor Control Using Infineon 8-bit XC866 Microcontroller.

Using the HCS08 TPM Module In Motor Control Applications

MiniProg Users Guide and Example Projects

A Practical Primer On Motor Drives (Part 13): Motor Drive Control Architectures And Algorithms

0.7 A 6.8 V Dual H-Bridge Motor Driver

1 Introduction. Freescale Semiconductor Application Note. Document Number: AN4386 Rev. 0, 01/2012

MC34ValveController Processor Expert Component

PMSM Field-Oriented Control on MIMXRT1050 EVK

Use of PWM and ADC on MC56F84789 to Drive Dual PMS Motor FOC

Sensorless Vector Control with RL78G14

LCC-10 Product manual

AN3252 Application note

QWKS Ethernet Accessory Card, User's Guide

CHAPTER-5 DESIGN OF DIRECT TORQUE CONTROLLED INDUCTION MOTOR DRIVE

Using a Linear Transistor Model for RF Amplifier Design

Application Note. 3-Phase Brushless DC Motor Control with Hall Sensors AN-CM-244

User Guide Introduction. IRMCS3043 System Overview/Guide. International Rectifier s imotion Team. Table of Contents

Iowa State University Electrical and Computer Engineering. E E 452. Electric Machines and Power Electronic Drives

RF Power LDMOS Transistor N--Channel Enhancement--Mode Lateral MOSFET

Design of Joint Controller Circuit for PA10 Robot Arm

Software User Manual

RF Power LDMOS Transistor N--Channel Enhancement--Mode Lateral MOSFET

ZKit-51-RD2, 8051 Development Kit

UM DALI getting started guide. Document information

UM DALI getting started guide. Document information

AN4999 Application note

16-Bit Hardware Pulse Width Modulator Data Sheet

Examples of using etimer on Power Architecture devices

TLE9879 EvalKit V1.2 Users Manual

Enhancement Mode phemt

AP08022 C504 / C508. Generating sinusoidal 3-Phase- Currents for Induction Maschines with a time-optimezed algorithm for the Capture Compare Unit

STM32 motor control firmware library. STM32 FOC PMSM SDK v3.0.

Triscend E5 Support. Configurable System-on-Chip (CSoC) Triscend Development Tools Update TM

RAPID CONTROL PROTOTYPING FOR ELECTRIC DRIVES

Using the Break Controller (BC) etpu Function Covers the MCF523x, MPC5500, and all etpu-equipped Devices

AVR443: Sensor-based control of three phase Brushless DC motor. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

KV4x Family Product Brief Supports 150 MHz devices with 64 KB to 256 KB Flash

Transcription:

Freescale Semiconductor, Inc. Application Note Document Number: AN5004 Rev. 1, 03/2015 Sensorless PMSM Control on MKV46F256 Using Kinetis SDK by: Marek Zeman 1 Introduction This application note represents an addendum to DRM148 Sensorless PMSM Field-Oriented Control. It describes the MCU peripherals used in the application, the hardware setup, and results of the measurement, built using the Freescale SDK suite for Kinetis MCUs. The software package attached to the application note contains applications for two Freescale motor-control development platforms. The Tower System boards TWR-KV46F256 and TWR-MC-LV3PH are used for low-voltage motors, and the high-voltage boards HVP-MC3PH and HVP-KV46F150M are used for the application powered from the mains. Contents 1. Introduction................................. 1 2. MCU peripherals............................. 2 3. Interrupts................................... 8 4. Application operation......................... 9 5. SDK implementation........................ 13 6. Project file structure......................... 15 7. Memory usage and CPU load.................. 16 8. Hardware setup............................. 17 9. Conclusion................................ 20 10. References................................. 21 11. Acronyms and abbreviated terms............... 21 12. Revision history............................ 21 2015 Freescale Semiconductor, Inc. All rights reserved.

MCU peripherals 2 MCU peripherals Table 1 summarizes the peripherals of the Kinetis KV46F256 MCU, and their usage in the PMSM sensorless vector-control application. Table 1. Kinetis MKV46F256 peripherals overview Kinetis MKV46F256 peripherals Group Module Number of modules or channels Used in the application Purpose Analog ADC0 ADC1 Comparators Eight channels single-ended or four differential pairs Eight channels single-ended or four differential pairs Four analog comparators, containing a 6-bit DAC and a programmable reference input Three channels Two channels DC-Bus voltage and motor phase currents sensing DAC One 12-bit module SPI One 16-bit module One module MOSFET driver configuration (only for Tower System platform) Communications UART Two modules One module FreeMASTER communication FlexCAN Two modules I 2 C One module eflexpwm One with four submodules Three submodules Generation of a 6-channel PWM for motor control purposes Eight channels Timers FlexTimer PDB One channel Eight channels Two channels for ADC triggering Two channels for DAC triggering PIT Four channels QD One module Other edma 16 channels XBAR Two modules One module Peripheral interconnection 2.1 Enhanced FlexPWM (eflexpwm) configuration The eflexpwm module is a dedicated peripheral enabling the generation of three-phase PWM signals, connected to the MOSFET H-bridge via the the MOSFET pre-driver, depending on the platform used. The configuration of the three PWM submodules used in the application is described in the following subsections. 2 Freescale Semiconductor, Inc.

MCU peripherals 2.1.1 TWR-KV46F256 board PWM_0 IPBus clock source (150 MHz) Running frequency of 10 khz with a period of 100 μs INIT register 7500, VAL1 7499 13-bit resolution Complementary mode with a dead time of 1 μs PWM reload and synchronization signals are generated from this module on every opportunity Trigger 4 is enabled to provide synchronization with the ADC module via XBAR High-side switch PWM_A output is in a negative active-low polarity Low-side switch PWM_B output is in a positive active-high polarity PWM_1 and PWM_2 PWM_0 clock source Running frequency of 10 khz with a period of 100 μs INIT register 7500, VAL1 7499 13-bit resolution Complementary mode with a dead time of 1 μs PWM reload and synchronization signals are generated using the PWM_0 submodule signal on every opportunity High-side switch PWM_A output is in a negative active-low polarity Low-side switch PWM_B output is in a positive active-high polarity PWM_1 and PWM_2 Fault 0 signal with high-level detection, connected via the XBAR input from the over-current MC33937 driver output Automatic fault clearing PWM_A, PWM1_A, and PWM2_A channels are disabled and the output pins are set to a high-level when a fault is detected PWM0_B, PWM1_B, and PWM2_B channels are disabled and the output pins are set to a low-level when a fault is detected Fault input filter is enabled 2.1.2 HVP-KV46F150M board PWM_0 IPBus clock source (150 MHz) Running frequency of 10 khz with a period of 100 μs INIT register 7500, VAL1 7499 13-bit resolution Complementary mode with a dead time of 1 μs PWM reload and synchronization signals are generated from this module on every opportunity Trigger 4 is enabled to provide synchronization with the ADC module via XBAR High-side switch PWM_A output is in a positive active-high polarity Freescale Semiconductor, Inc. 3

MCU peripherals Low-side switch PWM_B output is in a positive active-high polarity PWM_1 and PWM_2 PWM_0 clock source Running frequency of 10 khz with a period of 100 μs INIT register 7500, VAL1 7499 13-bit resolution Complementary mode with a dead time of 1 μs PWM reload and synchronization signals are generated using the PWM_0 submodule signal on every opportunity High-side switch PWM_A output is in a negative active-high polarity Low-side switch PWM_B output is in a positive active-high polarity PWM_1 and PWM_2 Fault 0 signal with a low-level detection is connected via the XBAR input from the over-current HVP-MC3PH driver output Automatic fault clearing PWM_A, PWM1_A, and PWM2_A channels are disabled, and the output pins are set to a low level when a fault is detected PWM0_B, PWM1_B, and PWM2_B channels are disabled, and the output pins are set to a low level when a fault is detected Fault input filter is enabled 2.2 ADC module configuration The on-chip ADC module is used to sample the feedback signals (motor phase currents and DC-Bus voltage) that are necessary to successfully perform the vector-control algorithm. The eflexpwm serves the Trigger 4 signal via the XBAR for the hardware triggering of both ADCs, set in a parallel mode. 2.3 ADC conversion timing, currents and voltage sampling The eflexpwm submodule 0 generates the Trigger 4 signal, as the submodule counter is reset to the initialization value after overflow. This signal, connected via the XBAR channel 12, triggers the AD conversion of voltage and current. Only three conversions must be triggered without CPU intervention (two out of three motor phase currents and the DC-Bus voltage). Figure 1 shows the module interconnections and the ADC interrupt generation. For more information about the eflexpwm and the ADC synchronization, see the KV4x Sub-Family Reference Manual [Section 10, References ]. 4 Freescale Semiconductor, Inc.

MCU peripherals 2.4 Current measurement Figure 1. ADC conversion timing The assignment of the ADC channels to the measured analog signals is closely related to the ADC conversion trigger timing. It is necessary to know the values of all three motor phase currents to compute the fast (current) control loop of the FOC. Since there are only two ADC modules, it is possible to sample only two analog quantities in one instance. Assuming that the motor represents a symmetrical three-phase system, the sum of all three instantaneous phase currents is zero. 0 = i A + i B + i C Eqn. 1 Since the phase currents are measured when the bottom transistors are conducting, in the case of high-duty cycle ratios (current value is in the area of the maximum of the sine curve), the time when the current can be measured is too short. The bottom transistor must be switched on for at least a critical pulse width to get a stabilized current shunt resistor voltage drop. The selection of the channels is done according to the section where the space vector of the stator current is generated. This assignment is performed at the end of the ADC1 interrupt service routine. It is sufficient to sample only two phase currents, while the third is easily calculated according to Equation 2, Equation 3, and Equation 4. Sector 1,6: i A = i B i C Eqn. 2 Sector 2,3: i B = i A i C Eqn. 3 Sector 4,5: i C = i B i A Eqn. 4 Figure 2 explains the reason, why in some time instances the third current cannot be measured directly. Case I shows the phase currents at 30 and case II at 60. Freescale Semiconductor, Inc. 5

MCU peripherals 2.5 Over-current level Figure 2. Current sensing The over-current signal is connected to the eflexpwm FAULT0 signal via the XBAR peripheral. The details of the connection for both boards are described in the following subsections. 2.5.1 TWR-KV46F256 board The MC33937 predriver contains an over-current comparator, whose output is connected via the Freescale Tower system elevator IRQ_A (B62) pin to the GPIO_C7 pin of the MKV40F256 device. This pin is internally connected via the XBAR input channel 4 to the PWM FAULT0 signal that handles the fault using the PWM hardware. For a detailed description, see Figure 3. 6 Freescale Semiconductor, Inc.

MCU peripherals Figure 3. TWR-MC-LV3PH over-current level The over-current level can be set in the range of 0 ~ 8 A using the trimmer R37 on the TWR-MC-LV3PH board. The maximal current level can be set by turning the trimmer counterclockwise. You can find the level by turning the trimmer counterclockwise while the motor is running, until the red LED is lit. It is recommended to set the trimmer to a somewhat higher level, so the motor can operate at the maximal speed. 2.5.2 HVP-KV46F150M board The power module FNB41560 contains an over-current comparator, whose output is connected via the PCI Express FAULT_1 pin to the GPIO_E1 pin of the MKV40F256 device. This pin is connected internally via the XBAR input channel 7 to the PWM FAULT0 signal that handles the fault using the PWM hardware. For a detailed description, see Figure 4. The maximal over-current level is set to 10.5 A, and the active output fault level is low. For more details about the HVP-MC3PH, refer to the High-Voltage Motor Control Platform User's Guide (Document number HVPMC3PHUG), and for details about the HVP-KV46F150M, refer to the HVPKV46F150MUG User's Guide (Document number HVPKV46F150MUG). Figure 4. HVP-MC3PH over-current level Freescale Semiconductor, Inc. 7

Interrupts 2.6 SPI configuration (only for Tower System platform) The SPI interface is used only in the Freescale Tower System; in the application, it is used for communication between the intelligent MOSFET gate driver MC33937 available on the TWR-MC-LV3PH board, and the MKV46F256 MCU. The MC33937 gate driver is placed on the TWR-MC-LV3PH module and drives the high-side and low-side MOSFET transistors of the three-phase inverter. In the application, the initialization of the MC33937 must be performed. When the motor runs, the driver fault pin is checked for the latched faults. If a fault is detected, the status register is read. The MC33937 driver requires a precise timing of the SPI signals. The default setting of the SPI module on the MCU cannot be used. The exact timing of the SPI signals is listed in the Three-Phase Field Effect Transistor Pre-driver Data Sheet (Document number MC33937). 2.7 SCI (UART) configuration The SCI is used in the application for communication between a master system and the embedded application. The master system is the notebook or PC where the FreeMASTER software was installed to control the application and visualize its state. On Kinetis MKV46F256, there are two UART modules implemented. UART1 is used on the Tower System modules and on the HVP platform. The communication speed is set to 19200 Bd. 3 Interrupts The application requires minimal number of interrupts, because the MCU can hardware-trigger the AD conversion. There are two interrupts in the application. The ADC interrupt serves to execute fast-loop (Current FOC) algorithms, and the ports interrupt handles user buttons. 3.1 ADC interrupt This interrupt request is triggered when the channel conversion is completed. It has the highest priority. During the interrupt generation, the sampled values of physical quantities are available in: Result register 0 (motor phase current 1) Result register 8 (motor phase current 2) Result register 9 (DC-Bus voltage) The Application State Machine function is called in the beginning of the ADC ISR execution. If the application is in the RUN state, then the execution of the fast (current) control loop of the PMSM vector control algorithm (including the position and speed estimation) occurs next. The execution of the slow (speed) control loop is performed according to the value of the software counter, which is decremented each time the fast control loop is passed. Figure 4 gives an overview of the program flow during the execution of the ADC interrupt service routine, when the application is in the Run state and Spin substate. 8 Freescale Semiconductor, Inc.

Application operation Figure 5. ADC ISR flowchart 3.2 Ports interrupt (only for Tower system platform) The handling of user buttons is available only on the TWR-MKV46F256 board, performed in the ISR associated with the Ports interrupt, generated whenever one of the buttons is pressed. At the beginning of the ISR, a simple logic is executed to evaluate which button was pressed, and the interrupt flag is cleared. Pressing the SW1 button causes the speed to increase in 10 % steps. Pressing the SW2 button causes the speed to decrease in 10% steps, and also the transition back to the STOP state. For more information about the application control using the user buttons, see Tuning Three-Phase PMSM Sensorless Control Application Using MCAT Tool (Document number AN4912), where the usage of the FreeMASTER control interface for enhanced control and diagnostics is described. 4 Application operation The application can be operated either using the user button on the TWR-KV46F256 MCU board (as mentioned in Section 3.2, Ports interrupt (only for Tower system platform) ), or using the FreeMASTER software, which enables visualization of the application variables. The FreeMASTER application consists of two parts: the PC application used for variable visualization, and the set of software drivers running in the embedded application. The data is transferred between the PC and the embedded application using the RS232 interface. Freescale Semiconductor, Inc. 9

Application operation 4.1 Installing FreeMASTER on the PC or notebook The FreeMASTER application for PC can be downloaded from the Freescale website at freescale.com/freemaster; from the Download tab, select FreeMASTER 1.4 Application Installation. Since downloading the FreeMASTER application requires registration, you must create an account before you can log in. After logging into the system, the license agreement appears. You should read the license agreement and then accept the agreement by clicking the I Accept button. When using Internet Explorer, a bar asking to authorize the file download appears at the top of the web page. Click on the bar and select Download File. A dialog box appears where you can choose either Run or Save. In both cases, the installation archive will be stored on your PC. After selecting Save, you have the option to select the preferred location for saving of the installation archive; otherwise, it will be saved to a temporary folder in your system. The library installation archive will now be downloaded to your computer. To run the installation, click the Run button. Follow the instructions on the screen to complete the installation process. 4.2 Establishing a connection between the PC and the embedded application FreeMASTER allows using multiple communication interfaces between the embedded applications and the PC (UART (RS232), CAN, Ethernet, USB, BDM, and other). For this application, the RS232 was used, because the software overhead for the data transfer represents the lowest additional load on the CPU. Nowadays, the notebooks are not equipped with the COM port, so for this purpose, the TWR-KV46F256 and HVP-KV46F150M modules have a USB-to-RS232 interface in place (CDC Serial Port). By connecting the TWR KV46F256 or HVP-KV46F150M modules to a notebook via an USB cable, a virtual serial port will be established in the Windows system. To run the FreeMASTER application, double-click the pmsm_foc_kv4x.pmp file located in the \freemaster\pmsm_sensorless_foc folder. The FreeMASTER application starts and the environment will be created automatically, as defined in the *.pmp file. 4.3 Setting up the communication When the notebook is connected to the TWR-KV46F256 or HVP-KV46 board via a USB cable, the operating system assigns the number of the COM port to the OpenSDA CDC serial port interface. This number is assigned randomly, therefore it is necessary to set the right communication port when the connection is established (re-plugging the USB cable might cause a different port number assignment). To set the port number, click the Project \ Options menu item. It is necessary to assign a correct port number and/or value. Add the OpenSDA value to the Port list box and FreeMASTER automatically assigns a correct communication channel, or select COM port from the dropdown listbox menu. The correct port number selection is confirmed by the text OpenSDA CDC Serial Port next to the list box with the available serial port numbers. The communication speed of the interface is 19200 Bd. 10 Freescale Semiconductor, Inc.

Application operation Figure 6. FreeMASTER communication settings 4.4 Starting / stopping the communication and the application When the communication settings are performed, the communication between the PC and the embedded application can be initiated. Click the Stop button in the FreeMASTER toolbar, as shown in Figure 7. Figure 7. Initiating the communication with the embedded side The next step is switching the application to the RUN state. Click on the drop-down list next to the Application Switch variable name in the Variable Watch grid in the FreeMASTER window, and select ON, as shown in Figure 8. When the application is switched to the RUN state, the required speed can be changed to a non-zero value. The procedure is similar to the previous step; in the Variable Watch grid, enter a positive or negative value next to the Speed required variable name. Freescale Semiconductor, Inc. 11

Application operation 4.5 MCAT tool control Figure 8. Starting the application To run the FreeMASTER application including the MCAT tool, double-click on the mcat_pmsm_foc_kv4x.pmp file located in the \freemaster\pmsm_sensorless_foc folder. The FreeMASTER application starts and the environment will be created automatically, as defined in the *.pmp file. The application enables tuning of the PMSM sensorless application for any motor. For this purpose, the field-oriented control can be divided into four modes, as follows: Scalar Voltage FOC Current FOC Speed FOC This enables tuning of the application in several steps, with each step containing a limited number of unknown parameters that can be adjusted. To switch between these modes, the MCAT tab Control Struc is used. For more information on tuning of the application for any motor, see Tuning Three-Phase PMSM Sensorless Control Application Using MCAT Tool (Document number AN4912). The application code contains routines for a PM synchronous motor parameters identification. The algorithm simplifies and speeds up the controller constant calculations and settings. The identification process is disabled in the application by default, and can be enabled from the MCAT control tab Motor Identif. For more information on user motor identification, see Automated PMSM Parameters Identification (Document number AN4986). 12 Freescale Semiconductor, Inc.

SDK implementation 5 SDK implementation Kinetis SDK (KSDK) provides a comprehensive software support for Freescale Kinetis devices, such as the KV46F256 MCU. The KSDK includes all necessary source and header files required by the application, such as startup code, clock configuration, and peripherals configuration, provided by Hardware Abstraction Layer (HAL) as low-level configuration routines and high-level peripherals drivers, based on HAL routines. This suite provides easy portable basics of applications for the Kinetis family of MCUs with no or little code modifications, depending on the MCU and its peripherals, and core equipments used. For more information about the KSDK, see Kinetis SDK Demo Applications User's Guide (Document KSDKDEMOUG) and freescale.com/ksdk. The next steps explain how to run a demo application under the KSDK with the IAR Workbench, and how to prebuild the platform driver library in the IAR Workbench, which is necessary to run the example application. 5.1 Building the platform driver library in the IAR Workbench In the first step, it is required to generate the platform library file, before building and debugging the demo application. This library contains all the HAL and peripheral driver functions that are device-specific. Therefore, each device has its own library (platform.a). It should not be necessary to build the library after initially downloading the KSDK, because the platform library is already prebuilt. However, if this is necessary, see the following directions to rebuild the platform library. Open the workspace file by double clicking the pmsm_sensorless_foc.eww file in IAR, located in build\iar\kv46\pmsm_sensorless_foc\ folder. The IAR workspace launches and contains two projects: ksdk_platform_lib and pmsm_sensorless_foc. You must build the platform library before the PMSM sensorless project can be used. As shown in Figure 9, the workspace contains two projects. Right-click on ksdk_platform_lib and a drop-down menu appears. Click on Set as Active, and then click on the Make button (highlighted in a red rectangle in Figure 9). When the build is complete, the library (ksdk_platform_lib.a) is generated in the output directory according to the build target, and can be located depending on the build target: Debug <ksdk_install_dir>/lib/ksdk_platform_lib<toolchain>/<device_name>/output/debug Release <ksdk_install_dir>/lib/ksdk_platform_lib/<toolchain>/<device_name>/output/release Freescale Semiconductor, Inc. 13

SDK implementation Figure 9. Platform driver library build 5.2 Building the PMSM project in IAR Workbench After the platform library build is complete, the PMSM sensorless project can be generated. As mentioned in Section 5.1, Building the platform driver library in the IAR Workbench, and as shown in Figure 9, the workspace contains two projects. You must activate the pmsm_sensorless_foc project by right-clicking the project name, and then selecting Set as Active. The PMSM project is activated and can be built by clicking the Make button. After the output file pmsm_sensorless_foc.out is generated in the output directory, it can be loaded into the KV46F256 MCU with the debugger, or linked to the FreeMASTER communication tool. 14 Freescale Semiconductor, Inc.

Project file structure 6 Project file structure The total number of source (*.c) and header files (*.h) in the project exceeds one hundred. Therefore, only the key project files will be described in detail, and the rest will be described in groups. The main project folder is divided into three subfolders: build\iar\kv46\ pmsm_sensorless_foc contains configuration files for the IAR compiler, as well as the compiler s output executable and object files. If the IAR Embedded Workbench for ARM is installed on your computer, double-click the workspace file pmsm_sensorless_foc.eww to launch the IAR IDE. freemaster\ pmsm_sensorless_foc contains the FreeMASTER configuration file (mcat_pmsm_foc_kv4x.pmp) and supporting files (control page in HTML format and the binary file with addresses of the variables). src contains the project source and header files, and its contents will be described in the following text. Files in the src\projects\kv46\ pmsm_sensorless_foc folder: main.c, main.h contain basic application initialization (enabling interrupts), subroutines accessing the MCU peripherals, and interrupt service routines. The FreeMASTER communication is performed in the background infinite loop. m1_state_machine.c and m1_state_machine.h contain the software routines that are executed when the application is in a particular state or state transition. freemaster_cfg.h the configuration file for the FreeMASTER interface. pmsm_appconfig.h contains constants definitions for the application control processes (parameters of the motor and regulators, and the constants for other vector-control related algorithms). When the application is tailored for another motor using the Motor Control Application Tuning Tool, this file is generated by the tool at the end of the tuning process. \peripherals\ folder contains important files for static configuration of the peripherals used in the application (eflexpwm, ADC, SPI, UART). Subfolders in the src\ folder: \state_machine contains the application state machine structure definition that handles the switching between the application states and application state transitions. \control_algorithms contains the structures definitions and subroutines dedicated for performing the motor-control algorithm (vector-control algorithm, position and speed estimation algorithm, speed control loop). Files in the src\cm4_mmclib_r1.0\ folder: CM4_MMCLIB_IAR.a software library containing motor-control, general math, and filter algorithms. The other files in the folder and subfolders are associated header files, each one for a particular function of the library. ACLIB\ CM4_ACLIB_F16.a contains the advanced control algorithms for rotor position and speed estimation (Back-EMF observer and Tracking observer). Freescale Semiconductor, Inc. 15

Memory usage and CPU load Other subfolders in the src\ folder: \freemaster contains all source files of the FreeMASTER application, it is not necessary to access it or change anything inside. The interface to the programmer is handled via the freemaster_cfg.h file located in src\projects\kv46\ pmsm_sensorless_foc folder. \sac (Sensor and Actuator Components) contains routines for accessing peripherals used by the motor-control algorithm to sense input feedback physical quantities (currents, voltage, speed, position) and to set the actuators based on calculated output variables (eflexpwm, MOSFET predriver). \sdk\startup contains startup routines with clock settings possibilities and system_kv46f15.h predefined header for clock setup. 7 Memory usage and CPU load The following tables show the memory usage of the MKV46F256 chip, total available data and RAM memory, size of the used memory, and the memory used by the individual algorithm blocks. Table 2. Memory usage, values in bytes Memory Total available on the Kinetis MKV46F256 Used by the application (TWR) Used by the application (HVP) Program Flash (application code) 25 048 B 22 730 B 512 KB Data Flash (application constants) 588 B 504 B Data RAM (application variables) 96 KB 6 623 B (*) 6 576 B (*) including 4096 B FreeMASTER recorder buffer Table 3. Memory usage, values in bytes Algorithm block Program memory (code + constants) Data memory TWR HVP TWR HVP FOC (fast + slow loops) 4 472 B 4 406 B FreeMASTER 2 942 B 2 942 B 4365 B 4 365 B SAC (Sensor and actuator components) 2 124 B 1 428 B 3 B 3 B MID (Motor identification) 2 545 B 3 406 B 590 B 590 B Application state machine 4 326 B 4 680 B 616 B 572 B The CPU load is influenced mainly by the execution of the ADC1 ISR, in which the execution of the application state machine and calculation of the fast (current) and slow (speed) control loops of the PMSM vector control is performed. In the worst case, the complete ADC1 ISR consumes some machine cycles (state machine and fast / slow control loop), and the consume time per interrupt is shown in Table 4, depends on the platform used. The ADC1 interrupt is generated periodically with the same frequency as the PWM reload event, when the values of the duty cycles are updated. The Kinetis KV46F256 MCU clock is running at 150 MHz. 16 Freescale Semiconductor, Inc.

Hardware setup Table 4. CPU load Board Machine cycles [-] CPU load [%] TWR-KV46F256M 5001 33,34 HVP-KV46F150M 5118 34,12 8 Hardware setup The applications support both hardware platforms; the Tower System (modular development system) and the high-voltage three-phase board. All modules of the Tower and HVP systems are available for order via the Freescale web page or from distributors, so you can easily build the hardware platform for which the application is targeted. Following sections describe the required configuration for both platforms. 8.1 Tower system hardware setup and jumpers configuration The PMSM sensorless control for low-voltage motors is based on the Tower system platform. It consists of the following modules: Tower elevator modules (TWR-ELEV) Kinetis MKV46F256 tower module (TWR-KV46F256) Three-phase low-voltage power module (TWR-MC-LV3PH) with included motor Building a system using the modules of the Tower system is not difficult. The peripheral modules and the MCU module are plugged into the elevator connectors, while the white stripe on the side of the module boards determines the orientation to the functional elevator (the elevator with mini USB connector, power supplies, and switch). Freescale Semiconductor, Inc. 17

Hardware setup Table 5. Jumper settings of the TWR-MKV46F256 board Jumper # Settings Jumper # Settings J1 Open J21 Open J2 Open J23 Open J4 2-3 J505 3-4 J5 1-2 J506 3-4 J13 1-2 3-4 J512 1-2 J15 1-2 J514 2-3 J16 Open J517 2-3 J19 Open J519 3-4 J20 1-2 J520 1-2 The jumper settings for the TWR-MC-LV3PH board are listed and highlighted in Table 6. See TWR-MC-LV3PH User s Manual (Document number TWRMCLV3PHUG) for more details about the TWR-MC-LV3PH stage (for example, the hardware over-current threshold setting). Table 6. Jumper settings of the TWR-MC-LV3PH board Jumper # Settings J2 1-2 J3 1-2 J10 1-2 J11 1-2 J12 1-2 J13 1-2 J14 1-2 18 Freescale Semiconductor, Inc.

Hardware setup The motor used in the reference design is part of the TWR-MC-LV3PH kit. It is a BLDC motor with a trapezoidal shape of the back-emf voltage with salient poles on the stator. This is different from a PM synchronous motor, which has distributed winding on the stator, forming a sinusoidal shape of the magnetic field. The rotor construction is the same for both types of motors (salient poles on the shaft). Even the vector-control algorithm was originally developed for PM synchronous motors, assuming a sinusoidal shape of the magnetic field. Therefore, it is possible to employ the same control strategy for a BLDC motor. Of course, the performance will not be optimal, but the drive will possess less audible noise than a traditional six-step commutation control. The main benefit is that the customer can learn and adopt sensorless vector control on a cost-effective hardware solution. Motor specifications are listed in Table 7. Table 7. Low-voltage motor specifications Motor specification Motor model parameters Manufacturer name Type Nominal voltage (line-to-line) Nominal speed Rated power Stator winding resistance Stator winding inductance q axis Stator winding inductance d axis Linix 45ZWN24-40 24 V DC 4000 RPM 40 W 1 367 H 413 H NOTE The application parameters (speed PI controller and value of the startup current) are set for a motor that has a plastic circle (part of the kit) mounted on the shaft. Without the circle mounted, speed oscillation might occur. 8.2 HVP hardware setup Number of pole-pairs 2 Back-EMF constant k e 0.0136 V.s.rad -1 The PMSM sensorless control is based on the following modules: HVP-MC3PH: High-Voltage Development Platform HVP-KV46F150M: High-Voltage Development Platform Controller Card The boards work with the default configuration and no jumper setting is required to run the attached application. It is highly recommended to read the board user s guides High-Voltage Motor Control Platform User's Guide (Document number HVPMC3PHUG) and HVPKV46F150MUG User's Guide (Document number HVPKV46F150MUG) prior to the first use. Freescale Semiconductor, Inc. 19

Conclusion Target reset / bootloader enable USB mini for communication, debugging, and power supply Isolated power supply Target controller 8 MHz crystal OpenSDA OpenSDA JTAG Isolated target SWD connector SWD isolator Main board interface Figure 10. Platform driver library build For the application software loading and FreeMASTER communication, use preferably the USB mini connector J2 (red circle mark in Figure 10). No additional communication driver installation is required, and the application will run in a short time. See HVP-KV46F150M Freescale High-Voltage Development Platform Quick Start Guide (Document number HVPKV46F150MQSG) for more details. The motor used in the reference application is MIGE AC servomotor, see Table 8 for its specifications. Table 8. Motor used in the application Motor specification Motor model parameters Manufacturer name Type Nominal voltage (line-to-line) Nominal speed Rated power Stator winding resistance Stator winding inductance q axis Stator winding inductance d axis MIGE 60CST-MO1330 220V 3,000 RPM 400 W 1.25 4.85 mh 4.79 mh 9 Conclusion Number of pole-pairs 4 Back-EMF constant k e 0.0618 V.s.rad -1 The results of the execution time measurement show that the Kinetis MKV46F256 MCU can be used to drive the PMSM sensorless vector control algorithm for highly dynamic applications. The CPU load at the PWM frequency of 10 khz represents only 33 ~ 34 %, so there is much room to either increase the frequency of the fast control loop or to perform additional tasks. 20 Freescale Semiconductor, Inc.

10 References References The following references are available on freescale.com: [1] Sensorless PMSM Field-Oriented Control (Document DRM 148). [2] KV4x Sub-Family Reference Manual [3] Three Phase Field Effect Transistor Pre-driver Data Sheet (Document number MC33937) [4] Tuning Three-Phase PMSM Sensorless Control Application Using MCAT Tool (Document number AN4912) [5] Automated PMSM Parameters Identification (Document number AN4986) [6] Kinetis SDK Demo Applications User's Guide (Document KSDKDEMOUG) [7] TWR-MC-LV3PH User s Manual (Document number TWRMCLV3PHUG) [8] Kinetis SDK KV46 User's Guide [9] High-Voltage Motor Control Platform User's Guide (Document number HVPMC3PHUG) [10] HVPKV46F150MUG User's Guide (Document number HVPKV46F150MUG) [11] HVP-KV46F150M Freescale High-Voltage Development Platform Quick Start Guide (Document number HVPKV46F150MQSG) 11 Acronyms and abbreviated terms The following table contains the abbreviated terms used in this document. Table 9. Acronyms and abbreviated terms Term Meaning ADC Back-EMF FOC PMSM PWM SVM SDK Analog-to-digital converter Back-electromotive force: the voltage generated by a rotating motor Field-oriented control Permanent magnet synchronous motor Pulse-width modulation Space vector modulation: the algorithm used to generate the signals for the PWM output Software development kit 12 Revision history Table 10. Revision history Rev. number Date Substantial changes 0 04/2014 Initial release. 1 03/2015 SDK compatibility added. Freescale Semiconductor, Inc. 21

How to Reach Us: Home Page: freescale.com Web Support: freescale.com/support Information in this document is provided solely to enable system and software implementers to use Freescale products. There are no express or implied copyright licenses granted hereunder to design or fabricate any integrated circuits based on the information in this document. Freescale reserves the right to make changes without further notice to any products herein. Freescale makes no warranty, representation, or guarantee regarding the suitability of its products for any particular purpose, nor does Freescale assume any liability arising out of the application or use of any product or circuit, and specifically disclaims any and all liability, including without limitation consequential or incidental damages. Typical parameters that may be provided in Freescale data sheets and/or specifications can and do vary in different applications, and actual performance may vary over time. All operating parameters, including typicals, must be validated for each customer application by customer s technical experts. Freescale does not convey any license under its patent rights nor the rights of others. Freescale sells products pursuant to standard terms and conditions of sale, which can be found at the following address: freescale.com/salestermsandconditions. Freescale, the Freescale logo, and Kinetis are trademarks of Freescale Semiconductor, Inc., Reg. U.S. Pat. & Tm. Off. Tower is a trademark of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. ARM and Cortex are registered trademarks of ARM Limited (or its subsidiaries) in the EU and/or elsewhere. All rights reserved. 2015 Freescale Semiconductor, Inc. Document Number: AN5004 Rev. 1 03/2015