You are on page 1of 22

Freescale Semiconductor, Inc.

Application Note

Document Number: AN5004


Rev. 1, 03/2015

Sensorless PMSM Control on


MKV46F256 Using Kinetis SDK
by: Marek Zeman

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.

2015 Freescale Semiconductor, Inc. All rights reserved.

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.

Contents
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
MCU peripherals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Application operation . . . . . . . . . . . . . . . . . . . . . . . . . 9
SDK implementation . . . . . . . . . . . . . . . . . . . . . . . . 13
Project file structure . . . . . . . . . . . . . . . . . . . . . . . . . 15
Memory usage and CPU load . . . . . . . . . . . . . . . . . . 16
Hardware setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Acronyms and abbreviated terms . . . . . . . . . . . . . . . 21
Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21

MCU peripherals

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

Used in the
application

Purpose

Module

Number of modules or channels

ADC0

Eight channels single-ended or


four differential pairs

Three channels

ADC1

Eight channels single-ended or


four differential pairs

Two channels

Comparators

Four analog comparators,


containing a 6-bit DAC and a
programmable reference input

DAC

One 12-bit module

SPI

One 16-bit module

One module

MOSFET driver configuration


(only for Tower System platform)

UART

Two modules

One module

FreeMASTER communication

FlexCAN

Two modules

2C

One module

eFlexPWM

One with four submodules

Three
submodules

Generation of a 6-channel PWM


for motor control purposes

Eight channels

One channel

Eight channels

Two channels for ADC triggering

Two channels for DAC triggering

PIT

Four channels

QD

One module

eDMA

16 channels

XBAR

Two modules

One module

Peripheral interconnection

DC-Bus voltage and motor phase


currents sensing

Analog

Communications

FlexTimer
Timers
PDB

Other

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.

Sensorless PMSM Control on MKV46F256 Using Kinetis SDK, Application Note, Rev. 1, 03/2015
2

Freescale Semiconductor, Inc.

MCU peripherals

2.1.1

2.1.2

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

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
Sensorless PMSM Control on MKV46F256 Using Kinetis SDK, Application Note, Rev. 1, 03/2015

Freescale Semiconductor, Inc.

MCU peripherals

2.2

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

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].

Sensorless PMSM Control on MKV46F256 Using Kinetis SDK, Application Note, Rev. 1, 03/2015
4

Freescale Semiconductor, Inc.

MCU peripherals

Figure 1. ADC conversion timing

2.4

Current measurement

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 = iA + iB + iC

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:

iA = iB iC

Eqn. 2

Sector 2,3:

iB = iA iC

Eqn. 3

Sector 4,5:

iC = iB iA

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.

Sensorless PMSM Control on MKV46F256 Using Kinetis SDK, Application Note, Rev. 1, 03/2015
Freescale Semiconductor, Inc.

MCU peripherals

Figure 2. Current sensing

2.5

Over-current level

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.

Sensorless PMSM Control on MKV46F256 Using Kinetis SDK, Application Note, Rev. 1, 03/2015
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

Sensorless PMSM Control on MKV46F256 Using Kinetis SDK, Application Note, Rev. 1, 03/2015
Freescale Semiconductor, Inc.

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.

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.

Sensorless PMSM Control on MKV46F256 Using Kinetis SDK, Application Note, Rev. 1, 03/2015
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.

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.

Sensorless PMSM Control on MKV46F256 Using Kinetis SDK, Application Note, Rev. 1, 03/2015
Freescale Semiconductor, Inc.

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.

Sensorless PMSM Control on MKV46F256 Using Kinetis SDK, Application Note, Rev. 1, 03/2015
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.

Sensorless PMSM Control on MKV46F256 Using Kinetis SDK, Application Note, Rev. 1, 03/2015
Freescale Semiconductor, Inc.

11

Application operation

Figure 8. Starting the application

4.5

MCAT tool control

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).

Sensorless PMSM Control on MKV46F256 Using Kinetis SDK, Application Note, Rev. 1, 03/2015
12

Freescale Semiconductor, Inc.

SDK implementation

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

Sensorless PMSM Control on MKV46F256 Using Kinetis SDK, Application Note, Rev. 1, 03/2015
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.

Sensorless PMSM Control on MKV46F256 Using Kinetis SDK, Application Note, Rev. 1, 03/2015
14

Freescale Semiconductor, Inc.

Project file structure

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 compilers 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).
Sensorless PMSM Control on MKV46F256 Using Kinetis SDK, Application Note, Rev. 1, 03/2015
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.

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)

25 048 B

22 730 B

588 B

504 B

6 623 B (*)

6 576 B

Program Flash (application code)


512 KB
Data Flash (application constants)
Data RAM (application variables)

96 KB

(*) 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

3B

3B

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.
Sensorless PMSM Control on MKV46F256 Using Kinetis SDK, Application Note, Rev. 1, 03/2015
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

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).

Sensorless PMSM Control on MKV46F256 Using Kinetis SDK, Application Note, Rev. 1, 03/2015
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 Users 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

Sensorless PMSM Control on MKV46F256 Using Kinetis SDK, Application Note, Rev. 1, 03/2015
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

Linix

Type

45ZWN24-40

Nominal voltage (line-to-line)

24 V DC

Nominal speed

4000 RPM

Rated power

40 W

Stator winding resistance

Stator winding inductance q axis

367 H

Stator winding inductance d axis

413 H

Number of pole-pairs

Back-EMF constant ke

0.0136 V.s.rad-1

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

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 users 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.

Sensorless PMSM Control on MKV46F256 Using Kinetis SDK, Application Note, Rev. 1, 03/2015
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

MIGE

Type

60CST-MO1330

Nominal voltage (line-to-line)

220V

Nominal speed

3,000 RPM

Rated power

400 W

Stator winding resistance

1.25

Stator winding inductance q axis

4.85 mH

Stator winding inductance d axis

4.79 mH

Number of pole-pairs

Back-EMF constant ke

0.0618 V.s.rad-1

Conclusion

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.
Sensorless PMSM Control on MKV46F256 Using Kinetis SDK, Application Note, Rev. 1, 03/2015
20

Freescale Semiconductor, Inc.

References

10 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 Users 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

Analog-to-digital converter

Back-EMF
FOC

Back-electromotive force: the voltage generated by a rotating motor


Field-oriented control

PMSM

Permanent magnet synchronous motor

PWM

Pulse-width modulation

SVM

Space vector modulation: the algorithm used to generate the signals for the PWM output

SDK

Software development kit

12 Revision history
Table 10. Revision history
Rev. number

Date

Substantial changes

04/2014

Initial release.

03/2015

SDK compatibility added.

Sensorless PMSM Control on MKV46F256 Using Kinetis SDK, Application Note, Rev. 1, 03/2015
Freescale Semiconductor, Inc.

21

How to Reach Us:

Information in this document is provided solely to enable system and software

Home Page:
freescale.com

implementers to use Freescale products. There are no express or implied copyright

Web Support:
freescale.com/support

information in this document.

licenses granted hereunder to design or fabricate any integrated circuits based on the

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 customers 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

You might also like