Three-Phase BLDC Sensorless Motor Control Using the MKV4x ...

Post on 10-Dec-2021

5 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

Transcript

© 2015 Freescale Semiconductor, Inc. All rights reserved.

Three-Phase BLDC Sensorless Motor Control Using the MKV4x In Quadcopter Application By: Zbynek Mynar

1. IntroductionThis application note describes the implementation of a sensorless control of four three-phase brushless DC (BLDC) motors using a single Freescale 32-bit Kinetis MKV46F256 device as Electronic Speed Controller (ESC) in a quadcopter application. The sensorless control software for a single motor and the BLDC control theory in general are described in Three-Phase BLDC Sensorless Motor Control Application (document DRM144). The hardware-dependent part of code of this general BLDC motor-control software is separated, which enables simple porting to new devices and easy scalability for multi-motor applications. This application note focuses on implementing this software on the MKV46F256 device and on the multi-motor aspects of BLDC sensorless control. It describes the modifications of a single-motor control software that enables running multiple BLDC motors on one device, bare-metal setup of all used peripherals, special features needed for the quadcopter drone application, and a basic overview of the MKV46F256 device.

Freescale Semiconductor, Inc. Document Number: AN5169

Application Note Rev. 0 , 07/2015

Contents 1. Introduction ....................................................................... 1

1.1. Advantages and features of MKV4x ........................ 2 2. ESC for quadcopter with MKV4x ..................................... 33. Implemented software concept .......................................... 4

3.1. Hardware-independent part of code ......................... 5 3.2. Input / output variables of the motor-control software ................................................................................. 7 3.3. Peripheral drivers and initialization ......................... 7

4. Hardware ......................................................................... 155. CPU load and memory usage ........................................... 166. Conclusion ....................................................................... 167. Acronyms and abbreviations ............................................ 168. References ....................................................................... 179. Revision history ............................................................... 17

This datasheet has been downloaded from http://www.digchip.com at this page

Introduction

Three-Phase BLDC Sensorless Motor Control Using the MKV4x In Quadcopter Application, Rev. 0, 07/2015 2 Freescale Semiconductor, Inc.

1.1. Advantages and features of MKV4x The Kinetis KV4x family of MCUs is a high-performance solution based on the ARM® Cortex®-M4 core running at 150 MHz with floating-point unit, and up to 256 KB of flash and 32 KB of RAM, which is suitable mainly for motor-control applications. Advanced peripherals, such as high-resolution pulse-width modulation (PWM) modules with a total of 30 PWM channels, and high-speed dual 12-bit analog-to-digital converters (ADCs), make these devices ideal for multi-motor systems. The basic block diagram of the MKV4x MCUs is shown in Figure 1. Other features of the MKV4x MCUs are: • System peripherals 16-channel DMA controller Low-leakage wakeup unit SWD interface and Micro Trace buffer Advanced, independently-clocked watchdog

• Analog modules Two 12-bit cyclic ADCs Four analog comparators (CMP) containing a

6-bit DAC and a programmable reference input One 12-bit DAC

• Timers One eFlexPWM with four submodules, providing

12 PWM outputs Two 8-channel FlexTimers (FTM0 and FTM3) One 2-channel FlexTimers (FTM1) Four Periodic Interrupt Timers (PIT) Two Programmable Delay Blocks (PDB) Quadrature encoder / decoder (ENC)

Figure 1. KV4x block diagram

ARM Cortex-M432-bit CPU150 MHz

JTAG / SWD

SPFPU

MCM

16-chDMA

MCG32 kHz

RC8 MHz

RC

PLL10 - 240 MHz

OscLow range: 32 kHz

High range: 4 - 20 MHz

Crossbar switch (AXBS Lite)

FMC GPIOup to 70

32 RCM SIM PMC

Peripheral bridge

P-flashup to 256 KB

SRAMup to 32 KB

eFlexPWM8 ch + 4 ch

12-bit ADC(4.1 MSPS

12-bit ADC(4.1 MSPS)

FlexTimer8ch + 8 ch + 2 ch 2 x PDB XBARA

nano-edge 1 x 12-bitDAC

4 x HSCMPwith 6-bit DAC ENC EWM WDOG 4-ch PIT XBARB

FlexSCI FlexSCI LPTMR SPI I2CSMBUS

128

FlexCANx 2

CRC IRQ AOI

• Communication interfaces Two Universal Asynchronous Receiver /

Transmitter (UART) / FlexSCI modules with a programmable 8-bit or 9-bit data format

One 16-bit SPI module One I2C module Two FlexCAN modules

• Operating characteristics Voltage range: 1.71 V to 3.6 V Temperature range: –40°C to 105°C

• Clocks 32 kHz to 40 kHz or 3 MHz to 32 MHz

crystal oscillator Multipurpose Clock Generator (MCG)

with frequency-locked loop and phase-locked loop, referencing either internal or external reference clock

ESC for quadcopter with MKV4x

Three-Phase BLDC Sensorless Motor Control Using the MKV4x In Quadcopter Application, Rev. 0, 07/2015 Freescale Semiconductor, Inc. 3

2. ESC for quadcopter with MKV4x The quadcopter is a very popular design of Unmanned Aerial Vehicle (UAV). In the simplest form, which is shown in Figure 2, it consists of a flight controller and four ESCs, one for each motor. The flight controller is usually equipped with a radio to receive flight commands provided by the pilot and the Inertial Measurement Unit (IMU). The IMU provides information (such as velocity and orientation) that are necessary for autonomous stabilization of the vehicle, using the internal accelerometer, gyroscope, and sometimes also the magnetometer and GPS receiver. Based on this information, it determines the necessary pull (speed) of each rotor, which is then provided to the ESC of a given motor. Each ESC contains a three-phase inverter driven by the MCU with a specialized motor-control software.

Figure 2. Quadcopter block diagram with a common arrangement

The solution described in this application note combines four separate ESC boards into one ESC with a single 32-bit Kinetis MKV46F MCU capable of driving four BLDC motors, as shown in Figure 3. This arrangement enables collecting information from all four inverters into a single MCU, which can be used for easier debugging (FreeMASTER run-time debugging tool is used in this case), diagnostics, logging, and higher safety, or for implementation of new features, such as estimation of the remaining flight time based on current consumption. Each inverter in this solution is also enhanced with an MC34GD3000 pre-driver. This IC is capable of driving only N-channel MOSFETs for better efficiency, it can operate with a supply voltage of up to 58 V, 100% duty cycle, and it offers many diagnostics options and improved external FET protection. To find out more about the GD3000 pre-driver features, refer to www.freescale.com.

Figure 3. Quadcopter block diagram with MKV46F as a single ESC MCU

Radio GPS

FlightController

BLDC

ESCM4

Dis

cret

e pr

e-dr

iver

MC

U

BLDCESC

M1

Dis

cret

e pr

e-dr

iver

MC

U

BLDC

ESCM2

Dis

cret

e pr

e-dr

iver

MC

UBLDC

ESC

M3

Dis

cret

e pr

e-dr

iver

MC

U

Radio GPS

FlightController

PWM

MCUMKV4x

PWMADC

PWMADC

PWMADC

PWMADC

LEDs

Electronic Speed Controller (ESC)

UART(FreeMASTER)

BLDC

GD3

000

BLDC

GD3

000

BLDC

GD3

000

BLDC

GD3

000

M1 M2

M3 M4

Implemented software concept

Three-Phase BLDC Sensorless Motor Control Using the MKV4x In Quadcopter Application, Rev. 0, 07/2015 4 Freescale Semiconductor, Inc.

For further integrated solution combining both ESC and flight controller functionalities into a single MCU, the powerful 32-bit MKV5x family based on ARM Cortex-M7 core can be used. This high-performance MCU can run with core frequency of up to 240 MHz, contains single and double-precision floating-point unit, and up to 1 MB of flash and 256 KB of RAM. Since all KV46F peripherals used by the ESC software described in this document are present in the MKV5x MCUs as well, the software can be easily ported to the MKV5x family (this was tested with MKV58F1M0 device). For more details about the MKV5x MCU family, see www.freescale.com.

The software for the MKV46F ESC MCU in this solution meets the following requirements: • High-performance six-step sensorless control of four high-speed BLDC motors, including

overload protection safety feature • Measurement of pulse length (duty cycle) of a standard PWM-encoded signal, containing

required speed information from the flight controller • Serial communication for debugging purposes using the FreeMASTER protocol • SPI communication for communication with the GD3000 pre-driver • Other user-defined features (LED control)

The implemented software is described in the following section.

3. Implemented software concept The basic requirements for the ESC MCU software were introduced in the previous section. To implement the computation-demanding task of controlling four BLDC motors in a simple, easy-to-orient manner, the final software is divided, as shown in Figure 4. The ESC software can be divided into three basic parts:

• The hardware-dependent part of code (dependent on the hardware board and peripheral modules of the selected MCU device), which includes the initialization of the CPU and peripheral modules, I/O control drivers, and Interrupt Service Routines (ISR) handling.

• The hardware-independent part of code, which contains the BLDC motor-control software and FreeMASTER run-time debugger communication module.

• The communication layer between the hardware-dependent and hardware-independent parts (I/O variables and flags).

Each part is described in detail in the following sections.

Implemented software concept

Three-Phase BLDC Sensorless Motor Control Using the MKV4x In Quadcopter Application, Rev. 0, 07/2015 Freescale Semiconductor, Inc. 5

Figure 4. Four-motor control system concept

3.1. Hardware-independent part of code This part of software contains six-step BLDC motor-control algorithms and the embedded side of the FreeMASTER communication interface. The motor-control software (referred to as original motor-control software in the following text) and the BLDC motor-control theory are described in detail in Three-Phase BLDC Sensorless Motor Control Application (document DRM144). Only a few changes (which are described in the following text) were made to the original motor control software. A block diagram of the sensorless six-step BLDC motor-control algorithm is shown in Figure 5 (note that the voltage and current measurement belongs to the hardware-dependent portion of the software).

We can divide the code also according to the algorithm sampling frequency point of view. The voltage measurement, current measurement, and position-detection tasks must be conducted at a high sampling

M4M3

M2M1

First motorsensorless BLDC control algorithm

values duty cycle

GPIO, ¼

values duty cycle

GPIO, ¼

values duty cycle

GPIO, ¼

Measurements vectorvalues duty cycle

GPIO, SPI, Timer, T

Driver SW

Analog-to-Digital Converters

Driver SW

PWM Modules

Driver SW

First motor I/O Variables & Control FlagsGPIO, ...

PWMCommutation Analog Timer

SW

HW

Device specific SW

MCU device

Device independent SW

BLDC

GD

3000

BLDC

GD

3000

BLDC

GD

3000

BLDC

GD

3000

Inverters

M1

M4

M2

M3

SW interface layer

Implemented software concept

Three-Phase BLDC Sensorless Motor Control Using the MKV4x In Quadcopter Application, Rev. 0, 07/2015 6 Freescale Semiconductor, Inc.

frequency (tens of kHz). These tasks are therefore executed in the fast control loop. The required speed measurement, speed, and current PI controllers are called in the slow control loop at a much lower frequency. The commutation is a completely asynchronous event, and depends on the current rotor speed.

Figure 5. BLDC speed-control algorithm block diagram

The modifications that were done to the original motor-control software to meet the requirements of the quadcopter application are:

• The Back-EMF integration sensorless position-detection method used in the original motor-control software is not suited for high rotor speeds. Due to a small number of ADC samples of phase voltage per commutation time at a high rotor speed, the precision of this method declines with speed. Zero-crossing sensorless method was implemented because it provides a better performance at higher rotor speeds. This document does not explain the principles and implementation of this method, but you can find a detailed description in 3-Phase Sensorless BLDC Motor Control Using MC9S08MP16 (document DRM117). The sensorless method is selected automatically, based on the number of PWM periods that passed since the last commutation, which depends on the actual rotor speed. The threshold between these two methods is selected using these macros:

— “MX_SELECT_SENSORLESS_METHOD_INT_THR” – specifies the number of PWM periods per commutation period to go from the zero-crossing to the integration sensorless method. The recommended value is 16.

— “MX_SELECT_SENSORLESS_METHOD_ZC_THR” – specifies the number of PWM periods per commutation period to go from the integration to the zero-crossing sensorless method. The value of this macro must be smaller than the “MX_SELECT_SENSORLESS_METHOD_INT_THR” value to introduce the switching hysteresis. The recommended value is 10.

Both macros are located in the “mX_bldc_appconfig.h” file, where “X” stands for the motor number. The zero-crossing sensorless method has only one setup parameter called the advance angle, which enables forcing earlier commutation, and thus enabling the field-weakening operation. This value is defined as a percentage of the full time until the next commutation in a 16-bit fractional macro “MX_ZC_ADVANCE_ANGLE”, located in the same file.

Current & voltage measurement

Position detection1/T

Dutycycle

BLDCLimitation

CommutationMaximal duty

cycle

BEMF voltage

DC-bus current

MaximalDC-bus current

SectorSpeed

Ramp

rpm

%

Required speed

PWM-encodedrequired speed

Duty cyclemeasurement

Inverter

Implemented software concept

Three-Phase BLDC Sensorless Motor Control Using the MKV4x In Quadcopter Application, Rev. 0, 07/2015 Freescale Semiconductor, Inc. 7

• The common functions, such as “ReadSwFaults()”, “TimeEvent()”, ”FastControlLoop()”, and “SlowControlLoop()” are moved from the “mX_state_machine.c” and “mX_state_machine.h” files to the “bldc_control.h” and “bldc_control.c” files to prevent repetition of identical code.

• Freescale’s Embedded Software Libraries (FSLESL) version 4.01 for ARM Cortex-M4 core are used, which results in a different data-type and variable-naming convention. For details on the FSLESL 4.01 library, refer to www.freescale.com.

3.2. Input / output variables of the motor-control software This part of the software forms a communication bridge between the hardware-independent and hardware-dependent parts of code using flags and several I/O variables, including measured values of the Back-EMF voltage, DC-bus current of each motor, and DC-bus voltage. This portion of code is similar to the software in Three-Phase BLDC Sensorless Motor Control Application (document DRM144). The changes made to this part are:

• A new unsigned integer variable called “ui16MotorID” is added to the main motor-control structure data type called “MCSTRUC_BLDC_SNLS_T”. The value of this variable is used to identify the correct motor within the hardware peripheral drivers. Each motor-control module must be assigned a unique identification number ranging from 0 to 3 in this variable.

• The output application flag “UPDATE_BRAKE_RESISTOR_ON_REQ” is removed, because this functionality is not used.

3.3. Peripheral drivers and initialization This section describes the implementation of the hardware-dependent code to the MKV46F MCU. The application contains both synchronous (slow control loop and fast control loop) and asynchronous (commutation) events. These tasks are handled using interrupt service routines, as shown in the application timing example (Figure 6).

Figure 6. Application timing example

The tasks can be divided according to the priority of their execution as follows:

Commutation

ADC & Fast loop

Slow loop &pulse length

measurement

FreeMASTERcommunication

taskpriority

time

M3&4M1&2 M1&2 M3&4

TPWM

Tsample Tsample

M3&4

TPWMM4 M1

ADC EOS (triggered by FTM0)FTM1 trigger

eFlexPWM.ch3 trigger eFlexPWM.ch0 trigger

FTM1_Isr()

FMSTR_Poll()

ADCA_Isr()

PWMACmpCH0_Isr(),PWMACmpCH1_Isr(),PWMACmpCH2_Isr(),PWMACmpCH3_Isr()

ADC EOS (triggered by FTM3)

Implemented software concept

Three-Phase BLDC Sensorless Motor Control Using the MKV4x In Quadcopter Application, Rev. 0, 07/2015 8 Freescale Semiconductor, Inc.

• Main loop: The flowchart of the “main()” function is shown in Figure 7. The peripherals, FreeMASTER embedded driver, and motor-control variables are initialized first. The variable “bFtmSwtch” is used to determine which pair of motors is to be controlled in the next execution of the fast control loop. The FreeMASTER communication task is poll-driven with a low-priority task, and it is executed in the main program loop.

Figure 7. Main loop flowchart

• Slow control loop: The slow loop containing speed control and required speed (pulse length) measurement is periodically executed in the “FTM1_Isr()” interrupt service routine with a level 1 priority. This routine is triggered by the FlexTimer FTM1 periphery output-compare event (vector 59) each millisecond. The flowchart of this routine is shown in Figure 8. The required speed measurement is executed only in case none of the motors are in the fault state, otherwise all motors stop. The duty cycle of the PWM-encoded signal containing the required speed information from the flight controller is measured using the eFlexPWM periphery in the input-capture mode. The slow control loop itself (remains the same as in Three-Phase BLDC Sensorless Motor Control Application (document DRM144)) and the duty cycle updates are then executed.

Figure 8. FTM1_Isr() slow loop interrupt routine flowchart

START

Initialize peripherals

InitializeFreeMASTER

Initialize motorcontrol variables

FreeMASTERpolling

bFtmSwtch=false

START

Measure Required Speed

Required Speed=0

Slow control loop

Update dutycycle

Return

M1...4 in fault?

-

+

Implemented software concept

Three-Phase BLDC Sensorless Motor Control Using the MKV4x In Quadcopter Application, Rev. 0, 07/2015 Freescale Semiconductor, Inc. 9

For debugging purposes, it is possible to disable the speed control loop and set the duty cycle directly, when the “SPD_CLOSED_LOOP” macro is reset to 0. The macro is located in the “hwconfig.h” file.

Fast control loop: The fast loop control is executed in “ADC_Isr()” interrupt service routine with priority level 2. Its flowchart is shown in Figure 10. Only two motors (either motors 1 and 2 or motors 3 and 4) are controlled during a single execution. The flag variable called “bFtmSwtch” is used to determine which pair of motors is controlled. The routine is triggered with the ADC end-of-scan event (vector 55) every Tsample = 16.6 µs. All measured data are already converted and ready when the routine execution begins. The ADC runs in a parallel mode, and it is triggered by initialization event triggers of either the FTM0 or FTM3 peripheries. These triggers occur with a period of TPWM = 33.3 µs, and they are delayed by Tsample = TPWM / 2 time from each other. The Inter-Peripheral Crossbar Switch A (XBARA) is used to switch between triggers from the FTM0 and FTM3 peripheries, based on the value of the “bFtmSwtch” variable (to ensure proper synchronization). The complete trigger chain is shown in Figure 9.

Figure 9. The complete ADC trigger chain

The analog data are measured in this order: phase voltage, DC-bus current, and DC-bus voltage (for each motor). The fast control loop, state machine, fault reading function, and hardware update function remain the same as in Three-Phase BLDC Sensorless Motor Control Application (document DRM144).

Figure 10. ADC_Isr() fast loop interrupt service routine

FTM0_INIT

FTM3_INIT

XBARA SIM

SYNC0 (ADC trigger)

bFtmSw tch

START

bFtmSwtch+-

bFtmSwtch=falsebFtmSwtch=true

Load M3&M4 analog meas.

Load M1&M2analog meas.

M1&M2 fastcontrol loop

M3&M4 fastcontrol loop

Prepare M3&M4analog meas.

Prepare M1&M2analog meas.

Read M1&M2faults

Read M3&M4faults

M1&M2state machine

M3&M4state machine

Update M1&M2HW modules

Update M3&M4HW modules

Return

Implemented software concept

Three-Phase BLDC Sensorless Motor Control Using the MKV4x In Quadcopter Application, Rev. 0, 07/2015 10 Freescale Semiconductor, Inc.

• Commutation: The commutation of each motor is executed in a dedicated interrupt routine with the highest priority level 3, called “PWMACmpCh0_Isr()”, “PWMACmpCh1_Isr()”, “PWMACmpCh2_Isr()”, and “PWMACmpCh3_Isr()”. These routines are triggered by the output-compare event in the eFlexPWM periphery, channel 0 (vector 97), channel 1 (vector 99), channel 2 (vector 101), and channel 3 (vector 103).

3.3.1. Peripheral initialization This section provides basic information about the peripheral setup. For more information and a detailed function description see KV4x Reference Manual (document KV4XP100M150RM). The application uses the following peripheral and external modules for sensorless BLDC motor control:

• Multipurpose Clock Generator and System Integration Module (MCG, SIM) • 12-bit cyclic Analog-to-Digital Converter (ADC) • FlexTimer Modules (FTM0, FTM1, and FTM3) • Inter-Peripheral Crossbar Switch A (XBARA) • GD3000 external MOSFET pre-driver • Serial Peripheral Interface (SPI) • Universal Asynchronous Receiver / Transmitter (UART0) • Pulse Width Modulator (PWMA / eFlexPWM) • General-Purpose Input / Output (GPIO)

3.3.1.1. Multipurpose Clock Generator and System Integration Module (MCG, SIM) The MKV4x MCU uses the MCG and SIM modules to configure and distribute the clock across the peripheral modules. The MCG (Multipurpose Clock Generator) module provides several clock source choices for the MCU. The SIM (System Integration Module) provides system control and chip configuration. The MCG module configuration is as follows:

• 8 MHz crystal is used as an external reference clock source • PLL is used to generate the 144 MHz MCG output clock (PRDIV = 1 and VDIV = 36)

The SIM module configuration is as follows: • Clock is enabled for all peripheral modules • System clock is set to 144 MHz (divider OUTDIV1 = 0) • Fast peripheral clock is set to 72 MHz (divider OUTDIV2 = 1) • Bus / flash clock is set to 24 MHz (divider OUTDIV4 = 5) • ADC trigger source is set to XBARA output 12

3.3.1.2. Analog-to-Digital Converter (ADC) The ADC module is used for measurement of DC-bus voltage, DC-bus currents, and phase voltages. The configuration is as follows:

Implemented software concept

Three-Phase BLDC Sensorless Motor Control Using the MKV4x In Quadcopter Application, Rev. 0, 07/2015 Freescale Semiconductor, Inc. 11

• Input clock (conversion clock frequency) is set to 24 MHz • Triggered parallel mode is selected (the source is selected in the SIM module,

see Section 3.3.1.1, “Multipurpose Clock Generator and System Integration Module (MCG, SIM)”), and converters A and B run scans simultaneously

• Three consequential samples are taken on each converter (phase voltage, DC-bus current, and DC-bus voltage samples)

• End of scan ISR, priority level 2 is enabled

3.3.1.3. FlexTimer modules (FTM0, FTM1, and FTM3) FlexTimer modules FTM0 and FTM3 are used for the output PWM generation. FTM0 is used for controlling motors M1 and M2, and FTM3 is used for controlling motors M3 and M4. FTM1 is used for the slow control loop timing. The FTM0 and FTM3 modules have the following configuration:

• Input clock is set to 72 MHz fast peripheral clock • Output PWM frequency is set to 30 kHz • Center-aligned PWM is selected • Duty-cycle is updated using the LDOK feature • Output mask and software control registers are updated using the software synchronization

feature (commutation) • Reset FTM counter on commutation • Inverted PWM polarity for upper MOSFETs (GD3000 feature) • FTM0 and FTM3 internal counters are delayed by one counter modulo

The FTM1 peripheral module is configured as: • Free-running timer • Input clock is set to 36 MHz (one half of the fast peripheral clock) • Output compare mode • ISR on output compare, priority level 3 (low priority)

3.3.1.4. Pulse Width Modulator (PWMA / eFlexPWM) The PWMA / eFlexPWM module A is used for both the commutation control and the required speed pulse length measurement. Each submodule performs these functions for one motor. Each submodule is configured as:

• Free-running timer

• PWM output is disabled

• Input clock is set to 562.5 kHz (fast peripheral clock divided by 128)

• ISR with high priority (level 3) is triggered with output compare value 2 event

• Enhanced capture is enabled on the PWM_X (one-shot mode, captures one rising and one falling edge).

Implemented software concept

Three-Phase BLDC Sensorless Motor Control Using the MKV4x In Quadcopter Application, Rev. 0, 07/2015 12 Freescale Semiconductor, Inc.

3.3.1.5. Inter-Peripheral Crossbar Switches A (XBARA) Inter-Peripheral Crossbar Switch A module is used to switch between FTM0 and FTM3 trigger for ADC triggering. Initial configuration of this module is:

• XBARA input IN17 (FTM0_INIT trigger) is connected to output OUT12

3.3.1.6. Serial Peripheral Interface (SPI) SPI is a four-wire interface used for GD3000 three-phase pre-driver configuration and status reading. This module configuration is as follows:

• Baud rate is set to 1.28 MHz

• Falling-edge SCLK polarity

• Master SPI mode

• Software chip select control

3.3.1.7. Universal Asynchronous Receiver / Transmitter (UART0) UART0 is used for FreeMASTER communication between the MCU board and the PC. The module configuration is as follows:

• Baud rate is set to 38400 bps

• Receiver and transmitter are enabled

• Other settings are default

3.3.1.8. GD3000 external MOSFET pre-driver (over SPI) The GD3000 three-phase MOSFET driver is used for output control. The SPI communication channel is used to configure and read the status of the driver. The configuration of the driver is as follows:

• Desaturation protection is disabled

• Interrupts are disabled

• No dead-time is generated

3.3.2. Commutation and duty cycle control A six-step control with independent unipolar PWM switching is implemented in this application. This method has the benefits of better EMC compatibility, half the voltage ripple in comparison with bipolar switching, and lower switching losses, which prolongs the flight time. The principle of this method is shown in Figure 11. Only the upper transistors are controlled using the PWM, which, in this case, is generated using the FTM0 and FTM3 peripheral modules, while the bottom transistors remains in the defined state based on the given sector during the whole time of commutation. The bottom transistors can be controlled using the GPIO pins. You don’t need to generate dead time in this case.

Implemented software concept

Three-Phase BLDC Sensorless Motor Control Using the MKV4x In Quadcopter Application, Rev. 0, 07/2015 Freescale Semiconductor, Inc. 13

Figure 11. Six-step control with independent unipolar switching

The even channels (channel Ch0, Ch2, and Ch4) of FTM0 and FTM3 are assigned to motors M1 and M3, while the odd channels (channel Ch1, Ch3, and Ch5) of FTM0 and FTM3 are assigned to motors M2 and M4. The required duty cycle can be asserted to a given motor with the ID stored in the “iMotorID” parameter using the “FTM_SetDutyCycle()” function.

The time of the commutation event depends on the actual position of the rotor. Therefore, the commutation period depends on the actual motor speed. During the commutation, the PWM output configuration must be updated simultaneously. The FlexTimer periphery supports simultaneous update of the output control registers and the FTM counter initialization at the same time. The output mask register (OUTMASK) is used to determine which PWM channel output is active. The application software uses an array of structure variables “Pwm_sChannelControl bldcCommutationTableComp[9]”, where each element of the array contains the “i16Mask” and “i16Port” variables, as shown in Table 1. The “i16Mask” variable contains the mask that is asserted to the OUTMASK register. For motors that are controlled from the odd FTM0 and FTM 3 channels, the “i16Mask” is shifted to the left by one. The i16Port variable contains the mask whose bottom transistor is active. Connecting the bottom transistors for a given motor to the neighboring GPIO pins simplifies the bottom transistor control, because the “i16Port” can be assigned directly to the GPIO output control registers. The required sector can be asserted to a given motor with ID “iMotorID” using the “FTM_SetPwmOutput()” function.

Three-phaseBLDC

SAb SBb SCb

SCtSBtSAt

commutation commutation commutation commutationcommutation commutation commutation

SAt

SAb

SBt

SBb

SCt

SCb

A-off

B-off

C-off

A-off

B-off B-off

C-off C-off

Sector 1 20 3 4 5 0 1 time

transistor state

Implemented software concept

Three-Phase BLDC Sensorless Motor Control Using the MKV4x In Quadcopter Application, Rev. 0, 07/2015 14 Freescale Semiconductor, Inc.

Table 1. Commutation table

Vector i16Mask i16Port Transistor control

SAt SAb SBt SBb SCt SCb

Sector 0 0x14 0x02 PWM OFF OFF ON OFF OFF Sector 1 0x14 0x04 PWM OFF OFF OFF OFF ON Sector 2 0x11 0x04 OFF OFF PWM OFF OFF ON Sector 3 0x11 0x01 OFF ON PWM OFF OFF OFF Sector 4 0x05 0x01 OFF ON OFF OFF PWM OFF Sector 5 0x05 0x02 OFF OFF OFF ON PWM OFF

Align (1 + 2) 0x10 0x04 PWM OFF PWM OFF OFF ON OFF 0x15 0x00 OFF OFF OFF OFF OFF OFF

Bottom ON 0x15 0x07 OFF ON OFF ON OFF ON

3.3.3. Required speed command measurement The required speed is sent from the flight controller to the ESC using the 400 Hz PWM protocol, which corresponds to a period of 2.5 ms. The required speed Nreq is obtained from the measured high-pulse length Tpulse, as indicated in Figure 12. In our case, the Tpulse,min time is 1 ms (corresponds to motor start speed Nreq,min), and Tpulse,max time is 1.8 ms (corresponds to the maximal motor speed Nreq,max). The correct signal parameters can be set using “PULSE_MEAS_LNGTH”, “PULSE_MEAS_MAX”, and “PULSE_MEAS_MIN” defines located in the “hwconfig.h” file. As mentioned in Section 3.3.1.4, “Pulse Width Modulator (PWMA / eFlexPWM),” the eFlexPWM periphery in the input capture mode is being used for pulse length measurement.

Figure 12. Relation between the required speed and the measured pulse length

Hardware

Three-Phase BLDC Sensorless Motor Control Using the MKV4x In Quadcopter Application, Rev. 0, 07/2015 Freescale Semiconductor, Inc. 15

4. Hardware The application was tested on the KV46F256VLL15 MCU and (after porting) on the MKV58F1M0VLL22 ESC demo board. The MKV58F version is shown in Figure 13. The ESC boards are nearly identical for both MCUs, and have the following features:

• Power supply voltage input of 12 V DC (can be up to 58 V) • DC-bus current scaled to 29 A for each motor • 5 V and 12 V sources for the flight controller • Four three-phase bridge inverters (4x6-N-type MOSFETs) • Four three-phase MC34GD3000 MOSFET gate pre-drivers with over-current and under-voltage

protection • Four three-phase voltage, DC-bus current, and voltage sensors • SWD debugging interface • Four user LED connectors

Figure 13. ESC hardware board

Acronyms and abbreviations

Three-Phase BLDC Sensorless Motor Control Using the MKV4x In Quadcopter Application, Rev. 0, 07/2015 16 Freescale Semiconductor, Inc.

5. CPU load and memory usage The total memory usage and CPU load of the MKV46F256 MCU is listed in Table 2.

Table 2. Total MCU memory usage and CPU load

Total flash usage 24 756 B 256 KB

Total RAM usage* 7 468 B 32 KB

CPU load** 54.25 %

* Value includes the 1024 B FreeMASTER recorder buffer ** Only the ADC and commutation ISRs are measured

6. Conclusion The software for the quadcopter ESC board based on the MKV46F256 MCU is described in this application note. The integrated solution of a single ESC for four BLDC motors brings many advantages, as described in Section 2, “ESC for quadcopter with MKV4x.” Section 3, “Implemented software concept” focuses on a detailed description of the implemented software, which is based on the original motor-control software described in Three-Phase BLDC Sensorless Motor Control Application (document DRM144). Section 5, “CPU load and memory usage” shows that the high-priority tasks (fast loop and motor commutations) consume only about 55% of the CPU time, leaving space for other user-defined low-priority tasks. However, to implement both the ESC and flight controller functionality into a single MCU, the powerful 32-bit Kinetis KV5x ARM Cortex-M7 device is recommended. For more details refer to www.freescale.com.

7. Acronyms and abbreviations Table 3. Acronyms and abbreviations

Term Meaning ADC Analog-to-Digital Converter

BEMF Back-Electromotive Force

BLDC Brushless DC Motor

CPU Central Processing Unit

DC Direct Current

DRM Design Reference Manual

FTM FlexTimer module

GPIO General-Purpose Input / Output

I/O Input / Output interfaces between a computer system and the external environment – the CPU reads an input to sense the level of an external signal, and writes to an output to change the level of the external signal.

MCU Microcontroller

PWM Pulse-Width Modulation

UART Universal Asynchronous Receiver / Transmitter

SPI Serial Peripheral Interface module

Revision history

Three-Phase BLDC Sensorless Motor Control Using the MKV4x In Quadcopter Application, Rev. 0, 07/2015 Freescale Semiconductor, Inc. 17

8. References The following references are available on freescale.com:

• KV4x Reference Manual (document KV4XP100M150RM) • Three Phase Field Effect Transistor Pre-driver (document MC34GD3000) • 3-Phase BLDC Motor Sensorless Control using MC9S08AW60, (document DRM086) • 3-Phase BLDC Motor Sensorless Control using MC9S08MP16, (document DRM117) • Three-Phase BLDC Sensorless Motor Control Application (document DRM144) • Three-Phase BLDC Sensorless Control Using the MKV10x, (document AN4862)

9. Revision history Table 4. Revision history

Revision number Date Substantive changes

0 07/2015 Initial release

Document Number: AN5169 Rev. 0

07/2015

How to Reach Us:

Home Page: freescale.com

Web Support: www.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: www.freescale.com/SalesTermsandConditions.

Freescale, the Freescale logo, and Kinetis are trademarks of Freescale Semiconductor, Inc., Reg. U.S. Pat. & Tm. Off.

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.

top related