ST AN1905 Application note

AN1905

APPLICATION NOTE

ST7MC THREE-PHASE BLDC MOTOR CONTROL SOFTWARE LIBRARY

INTRODUCTION

This application note describes one of the software libraries available for the ST7MC MCU. The ST7MC microcontroller comes with a dedicated motor control cell (MTC) and can drive both permanent magnet DC/AC motors (PMDC/PMAC also called BLDC) and induction AC motors. This application note describes the ST7MC software library required to control a BLDC motor with a trapezoidal 6-step drive in sensor or sensorless mode, open or closed loop, and in current or voltage mode. The control of a PMAC motor in Sinewave mode with sensors is detailed in application note AN1947. The control of an AC induction motor in Sinewave mode is detailed in application note AN1904.

The library is made of different C modules, compatible with both COSMIC (www.cosmic-software.com) and METROWERKS (www.metrowerks.com) toolchains. The functions are grouped into several families, making this library an easy way to go through any BLDC project development. Used in conjunction with the ST7MC starter kit (ST7MC-BLDC-KIT), evaluation can be achieved in a very short time, as the library eliminates the need to study the MCU in detail.

A basic knowledge of C Language, PMDC motor drives and power inverter hardware is required.

AN1905

Rev 2

1/77

1

Table of Contents

INTRODUCTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 OVERALL SOFTWARE ARCHITECTURE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 1 GETTING STARTED WITH TOOLS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 1.1 WORKING ENVIRONMENT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 1.2 SOFTWARE TOOLS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

1.2.1 PROGRAMMERS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

1.2.2 Emulators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

1.3 LIBRARY SOURCE CODE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

1.3.1 Download . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 1.3.2 File structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

1.4 UTILITIES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

1.4.1 lib.h file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

2 CUSTOMIZING THE WORKSPACE FOR YOUR ST7MC DERIVATIVE . . . . . . . . . 11 2.1 USING STVD7 RELEASE 2.5.X . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

2.1.1 Memory mapping with the COSMIC toolchain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 2.1.2 Memory mapping with the METROWERKS toolchain . . . . . . . . . . . . . . . . . . . . . . . 12

2.2 USING STVD7 RELEASE 3.X.X . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 2.3 "VERSION.H" FILE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 2.4 ADDITIONAL OR UP-TO-DATE TECHNICAL LITERATURE . . . . . . . . . . . . . . 15 3 GETTING STARTED WITH THE LIBRARY USING THE ST7MC-KIT/BLDC . . . . . . 16 3.1 INTRODUCTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 3.2 RUNNING THE MOTOR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 3.3 STANDALONE MODE AND CLOSED LOOP OPERATION . . . . . . . . . . . . . . . 18 3.4 NOTE ON DEBUGGING TOOLS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

3.4.1 Low voltage applications (below 30V) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 3.4.2 Medium-high voltage application (above 30V) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

3.5 USING YOUR OWN POWER STAGE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 3.6 CHECKING THE CURRENT SENSOR RESISTOR VALUE . . . . . . . . . . . . . . . 21

3.6.1

Maximum current . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

22

3.6.2

Interpreting the current feedback/settings in the GUI . . . . . . . . . . . . . . . . . . . . . . .

23

2/77

1

Table of Contents

4 MODULES PRESENTATION, LIBRARY ROUTINES . . . . . . . . . . . . . . . . . . . . . . . . 25 4.1 LIBRARY REFERENCES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 4.2 MTC SOFTWARE LAYER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

4.2.1

List of available routines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

26

4.2.2

List of MTC interrupt routines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

36

4.3 APPLICATION LAYER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45

4.3.1 regul.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 4.3.2 adc.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 4.3.3 it_ST7MC.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 4.3.4 ports.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 4.3.4.1 Push button reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 4.3.4.2 LEDs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47

4.3.5 spi.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 4.3.6 LinSCI.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48

5 HOW TO DEFINE AND ADD A MODULE (STVD7 2.5.X) . . . . . . . . . . . . . . . . . . . . . 49 5.1 COSMIC TOOLCHAIN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 5.2 METROWERKS TOOLCHAIN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 6 CODE EXAMPLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51

7 PMDC (PMAC) MOTOR CONSIDERATIONS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 7.1 PHYSICAL CONSIDERATIONS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53

7.1.1 Checking the number of pair poles of the motor . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 7.1.2 Connecting the sensor outputs to the board . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54

7.2 CONTROL STRATEGY CONSIDERATIONS . . . . . . . . . . . . . . . . . . . . . . . . . .

55

7.2.1 Voltage versus current mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

55

7.2.2 Choosing a demagnetization type (Sensorless mode only) . . . . . . . . . . . . . . . . . . .

56

7.2.3 The 4 Z event sampling methods (Sensorless) . . . . . . . . . . . . . . . . . . . . . . . . . . . .

57

7.2.3.1 At the end of the PWM low state . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

57

7.2.3.2 At PWM On, with delay once . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

58

7.2.3.3 At PWM On, with delay, at fSCF frequency . . . . . . . . . . . . . . . . . . . . . . .

58

7.2.3.4

At fSCF frequency . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

58

7.2.3.5

Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

59

7.2.4 Setting the PWM distribution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

59

7.3 SOFTWARE SETTING CONSIDERATIONS . . . . . . . . . . . . . . . . . . . . . . . . . . . 67

7.3.1 PI regulator implementation and tuning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 7.3.2 Adjusting falling/rising Bemf settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74 7.3.3 Completion of Fine Tuning and Other Software Considerations . . . . . . . . . . . . . . . 75

3/77

Table of Contents

8 REVISION HISTORY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76

4/77

1

ST7MC THREE-PHASE BLDC MOTOR CONTROL SOFTWARE LIBRARY

OVERALL SOFTWARE ARCHITECTURE

APPLICATION LAYER

PI

 

PMDC MOTOR DRIVE

 

COMMUNICATION

REGULATION

 

 

PROTOCOL

 

 

 

 

 

 

 

 

 

 

 

 

 

 

I/Os

 

 

 

 

 

 

ADC

 

LIN

 

 

 

16-bit

WDG

 

 

 

MTC

 

 

 

 

 

 

 

 

 

 

 

 

 

SCI

 

SPI

 

Timer

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

PWM outputs

 

 

MCES

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

MCO[0..5]

 

MCIx (Optional hall effect sensors)

 

 

 

 

 

 

 

 

 

 

ST7MC Library Version 1.0 Characteristics (CPU running at 16 MHz)

-BLDC (trapezoidal 6 step method) modes available:

1.Sensorless : Back EMF voltage on the non-energized phase is monitored and used to trigger the commutation events

Sensor : Hall effect sensors trigger the commutation events. 2.Voltage : PWM duty cycle is set directly via 12-Bit PWM Generator.

Current : Internal current loop and external voltage reference are used conjointly to set the maximum current in motor windings. PWM duty is automatically set according to current feedback loop output.

3.Open loop operation.

Closed loop operation : PI regulation, 1 to 255 ms sampling time.

- 12-bit PWM generation frequencies:

Current mode, Voltage mode: fixed 390Hz, 625Hz, 961Hz, 1.25Khz, 1.56Khz, 3.13Khz, 6.25Khz, 10Khz, 12.5Khz, 15.4Khz, 18.1Khz, 20Khz, 25Khz, 33.33Khz, 40Khz, 50Khz. (Voltage mode PWM frequency can be manually adjusted up to 50Khz in the library)

5/77

ST7MC THREE-PHASE BLDC MOTOR CONTROL SOFTWARE LIBRARY

- Required ROM/RAM:

 

ROM (bytes)

RAM (bytes)

 

Cosmic 4.5A

Metrowerks 1.1

Cosmic 4.5A

Metrowerks 1.1

 

 

 

 

 

Sensorless open loop

3400

4500

100

115

 

 

 

 

 

Sensorless closed loop

4700

6000

130

150

 

 

 

 

 

Sensor open loop

2370

3200

85

90

 

 

 

 

 

Sensor closed loop

3500

4600

120

125

 

 

 

 

 

These metrics include non motor control related code, implemented for demo purposes (such as ADC management, software time bases, etc.). Depending on the chosen memory model, the code size produced can be smaller or larger. This must therefore be considered only as indicative figures.

6/77

ST7MC THREE-PHASE BLDC MOTOR CONTROL SOFTWARE LIBRARY

1 GETTING STARTED WITH TOOLS

1.1 WORKING ENVIRONMENT

The present software library was fully validated using the main hardware board (a complete inverter and control board) included in ST7MC-KIT/BLDC starter kit. The ST7MC-KIT/BLDC starter kit also includes a low-cost INDART hardware debugger, making this tool an ideal set for starting a project and evaluating/using the library.

Therefore, for rapid implementation and evaluation of the software discussed in this application note, it is recommended to acquire the ST7MC-KIT/BLDC starter kit and one of the two compatible C-toolchains.

1.2 SOFTWARE TOOLS

This library has been compiled using COSMIC and Metrowerks C-toolchains, running under STVD7 release 2.5.4 (ST Visual Debugger) and STVD7 release 3.x.x. Free IDE and demo versions of third party toolchains can be found at http://www.st.com/mcu/ (then select Downloads). A complete software package consists of:

-An IDE interface: STVD7 (free download available on internet), or third party IDE (e.g. SOFTEC Indart STX for ST7).

-A third party C-compiler: either Cosmic or Metrowerks (if needed, time-limited evaluation versions can be obtained upon request. A free 4K COSMIC version can compile all stand alone firmware configurations).

The choice of the C Toolchain is left to the appreciation of the user. Both COSMIC and METROWERKS are fully supported, and the dedicated workspace (compatible with ‘STVD7’ and ‘STVD7 for Indart’) can be directly opened in the root of the library installation folder (BLDC_Sensorless_Metrowerks_STVD2_5_4.wsp,BLDC_Sensorless_Cosmic_STVD2_5_4. wsp,BLDC_Sensor_Metrowerks_STVD3_x.wsp, BLDC_Sensor_Cosmic_STVD3_x.wsp).

In addition, the GUI included in the ST7MC-KIT/BLDC starter-kit allows customization of these libraries with variables prepared for your own motor. This makes the first implementation of this library significantly easier. See Section 3 of this document.

1.2.1 PROGRAMMERS

In order to program an MCU with the generated S19 file, you should also install the ST Visual Programmer software (please visit our internet web-site) and use a programming interface (STICK programmer for example for In-Circuit-Programming). The Visual Programmer tool provides an easy way to erase, program and verify the MCU content.

Please note that the INDART STX kit from SOFTEC (see next chapter) is also a programming tool (installation of DataBlaze Programmer is required).

7/77

ST AN1905 Application note

ST7MC THREE-PHASE BLDC MOTOR CONTROL SOFTWARE LIBRARY

Figure 1. STVisual Programmer software

1.2.2 Emulators

Two types of real-time development tools are available for debugging applications using ST7MC:

- In-circuit debugger from Softec (salestype : STXF-INDART/USB)

The INDART from SOFTEC features an emulation and a programming tool. This is achieved using the In-circuit debug module embedded on the MCU. The real-time features of the Indart include access to real-time registers and 2 break-point settings. However, trace is not available.

- ST7MDT50-EMU3 emulator

Fully-featured emulator: real-time with trace capability, performance analysis, advanced breakpoints, light logical analyser capabilities, etc. It can also function as a programming tool when used with the delivered ICC ADDON module (select STMC-ICC as hardware target in STVP7). This ICC-ADDON module allows In-Circuit-Debugging with STVD7.

8/77

ST7MC THREE-PHASE BLDC MOTOR CONTROL SOFTWARE LIBRARY

1.3 LIBRARY SOURCE CODE

1.3.1 Download

The complete source files are available for free on the ST website (http://www.st.com/mcu), in the Downloads section, as a zip file. This library is also copied by default on the hard-disk when installing the ST7MC Control Panel from Softec micro systems, or available in the Downloads section of www.softecmicro.com, software part (AK-ST7FMC System Software).

Important Note: It is highly recommended to check for the latest releases of the library before starting any new development, and then verify from time to time all release notes to be aware of any new features that might be of interest for the project. Registration mechanisms are also available on the web sites of ST and Softec Microsystems to automatically obtain update information.

1.3.2 File structure

Once the files are unzipped, the following library structure appears, depending on the toolchain.

Library release 1.0

This library contains the workspace for both the STVD7 2.5.4 and STVD7 3.x IDEs. Four separate folders are provided (see Figure 2).

9/77

ST7MC THREE-PHASE BLDC MOTOR CONTROL SOFTWARE LIBRARY

Figure 2. Library structure for release 1.0

BLDCmotor_1.0 \ BLDC sensor \ config \ cosmic

\ metrowerks \ object \ cosmic

\ metrowerks \ source

\ debug \ release

\BLDC sensorless\ config\ cosmic

\metrowerks

\object \ cosmic

\metrowerks

\source

\debug

\release

\Pair poles chk\ config \ cosmic

\metrowerks

\object \ cosmic

\metrowerks

\source

\debug

\release

\ sci

1.4 UTILITIES 1.4.1 lib.h file

The purpose of this header file is to provide useful macros and type re-definitions which will be used throughout the entire library:

Re-definition of data types using the following convention: a first letter indicating if a variable is signed (s) or unsigned (u), plus a number indicating the number of available bits (for instance: u8, s16, etc.),

Defines for assembly mnemonics used in C source code: Nop(), Trap(), etc.

Common macros used for bit-level access (SetBit, ClrBit, etc.), to get the dimension of an array (DIM[x]), etc.

10/77

ST7MC THREE-PHASE BLDC MOTOR CONTROL SOFTWARE LIBRARY

2 CUSTOMIZING THE WORKSPACE FOR YOUR ST7MC DERIVATIVE

2.1 USING STVD7 RELEASE 2.5.X

Figure 3. Memory Map

0000h

HW Registers

0080h

Short Addressing

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

007Fh

 

00FFh

RAM (zero page)

 

 

 

 

 

 

0080h

 

 

 

 

 

 

 

 

 

RAM

0100h

256 Bytes Stack

1000h

 

 

 

 

 

 

 

 

 

 

 

 

 

 

60 KBytes

 

(1536/1024

 

 

 

 

 

 

01FFh

 

 

 

 

 

 

 

 

768/384 Bytes)

 

 

 

 

 

 

 

067Fh

0200h

16-bit Addressing

4000h

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

0680h

Reserved

 

RAM

 

48 KBytes

 

 

01FFh

 

 

 

 

 

 

0FFFh

 

8000h

 

 

 

 

 

 

 

 

 

 

 

 

1000h

 

or 037Fh

 

32 KBytes

 

 

 

Program Memory

or 047Fh

A000h

 

 

 

 

 

 

(60K, 48K, 32K, 24K, 8K)

or 067Fh

24 KBytes

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

FFDFh

 

 

 

E000h

 

 

 

 

 

FFE0h

Interrupt & Reset Vectors

 

 

 

 

 

 

 

 

 

 

 

8 KBytes

 

 

 

 

 

 

 

 

 

 

 

 

 

FFFFh

 

 

 

FFFFh

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

The ST7MC memory is shown on Figure 3. The memory arrangement may vary depending on the type of the MCU. Please refer to the datasheet in order to get more information.

The library is dedicated by default to the ST7FMC2N6B6 MCU (SDIP56, 32KB Flash, 1K RAM). In order to target another ST7MC MCU, you may need to modify the C-toolchain configuration files. Here’s a basic example of what has to be done prior to any other modifications.

This example is based onto the ST7FMC2S4 MCU (TQFP 44, 16K Flash, 768 Bytes RAM)

2.1.1 Memory mapping with the COSMIC toolchain

Go into the ..\BLDC sensorless\config\Cosmic\ folder ( ..\BLDC sensor\config\Cosmic\ for sensor driving mode).

Edit the "BLDC_Cosmic.lkf" file and check the following lines, in ‘SEGMENT DEFINITION’:

# SEGMENT DEFINITION (.text, .const, .data, .bss, .bsct, .ubsct, .eeprom are c compiler

predefined sections)

 

+seg .text -b0x8000 -m0x7f00 -nCODE -sROM

# executable code

+seg .const -aCODE -it -sROM

# constants and strings

+seg .bsct -b0x0080 -m0x007F -nZPAGE -sRAM

# initialized variables in SHORT range

+seg .ubsct -aZPAGE -nUZPAGE -sRAM

# uninitialized variables in SHORT range

+seg .share -aUZPAGE -is -sRAM

# shared segment

+seg .bss -b0x0200 -m0x0280 -nUDATA -sRAM

# uninitialized variables

+seg .data -aUDATA -nIDATA -sRAM

# initialized variables

This section contains the memory placement for the object files, listed just after this declaration.

In order to target the memory size of the ST7MC2S4, the sizes of ROM and RAM memory have to be changed (32K -> 16K Flash, 1K RAM -> 768 Bytes RAM)

11/77

ST7MC THREE-PHASE BLDC MOTOR CONTROL SOFTWARE LIBRARY

+seg .text -b0xc000 -m0x3f00 -nCODE -sROM # executable code

where 0xc000 is the new starting address of the program memory and 0x3fe0 the size in bytes.

+seg .bss -b0x0200 -m0x0180 -nUDATA -sRAM # uninitialized variables

where 0x0180 is the new 16-bit addressing RAM memory in bytes.

2.1.2 Memory mapping with the METROWERKS toolchain

Go into ..\BLDC sensorless\config\Metrowerks ( ..\BLDC sensor\config\Metrowerks\ for sensor driving mode).

Edit the "BLDC_Metrowerks.prm" file

SECTIONS

ZRAM = READ_WRITE 0x0080 TO 0x00FF;

// zeropage

RAM = READ_WRITE 0x0200

TO 0x047F; // 16 bit adressing RAM

ROM_SEC_2

= READ_ONLY

0x8000

TO 0xDFFF; // sector 2

ROM_SEC_1

= READ_ONLY

0xE000 TO 0xEFFF; // sector 1

ROM_SEC_0

= READ_ONLY

0xF000 TO 0xFEFF; // sector 0 - 0xFF00 to 0xFFDF reserved for ICC

This Section contains the memory locations of pages declared at the end of this file.

To target the memory size of the ST7MC2S4, ROM and RAM memory settings have to be changed (32K -> 16K Flash, 1K RAM -> 768 Bytes RAM).

ROM_SEC_2 = READ_ONLY 0xC000 TO 0xDFFF; // sector 2

where 0xc000 is the new starting address of the program memory

RAM = READ_WRITE 0x0200 TO 0x027F; // 16-bit addressing RAM

where 0x027F is the ending address of the 16-bit addressing RAM memory

Important Note: The application layer has been written for the STMFC2NB6. Using a different ST7MC sales type can imply the need for some modifications to the library, according to the available features (some of the I/O ports are not present on low-pin count packages). Please refer to the data sheet for details.

2.2 USING STVD7 RELEASE 3.X.X

The procedure is far easier with STVD7 3.x.x, as the makefile and linking command files are automatically generated.

In the workspace window, just right click on the selected project (either cosmic or metrowerks) and select “Add Files to Project”. You’ll be asked to select the source file.

12/77

ST7MC THREE-PHASE BLDC MOTOR CONTROL SOFTWARE LIBRARY

When rebuilding the library, the configuration files will be updated accordingly.

13/77

ST7MC THREE-PHASE BLDC MOTOR CONTROL SOFTWARE LIBRARY

2.3 "VERSION.H" FILE

The purpose of this file is to declare the compiler options which will be used throughout the entire library compilation process.

Define the PMDC driving mode: voltage/current, open/closed loop

In sensorless mode, 3 more options are added for the demagnetization type: hardware, hardware with software backup, software.

Special care has to be taken for the demagnetization type, since the value range is 1, 2 and 3, corresponding respectively to hardware, hardware with software backup, software demagnetization type (HW, HSW, SW).

Other compiler options can be disabled/enabled by writing 0 or 1 in front of each declaration (0 for disable, 1 for enable). Figure 4 gives an example when setting the current/closed loop/alternate hard soft demagnetization in sensorless mode.

Figure 4. Settings for current/closed loop/alternate hard soft demagnetization (sensorless)

.....

/* Demagnetization type parameters */

#define HW

1

 

// 1 -> Hard demag only

#define HSW

2

 

// 2 -> Hard with soft backup

#define SW

3

 

// 3 -> Soft Demag only

/* Driving mode parameters */

 

 

#define CURRENT_MODE

0

// 0 -> Current mode

#define VOLTAGE_MODE

1

// 1

-> Voltage mode

/* Regulation type parameters */

 

#define OPEN_LOOP

0

// 0

-> Open loop

#define CLOSED_LOOP

1

// 1

-> Closed loop

....

 

 

 

 

/******************************************************************************/ /* Option settings used throughout the compilation process */

#define SENSOR_TYPE

0

// no use in sensorless mode

#define DEMAG_TYPE

2

// no use in sensor mode

#define DRIVING_MODE

1

 

#define FEEDBACK_TYPE

1

 

After choosing the desired compiler options, the whole library has to be rebuilt. To launch the compilation, click on the ’rebuild all’ icon.

14/77

ST7MC THREE-PHASE BLDC MOTOR CONTROL SOFTWARE LIBRARY

2.4 ADDITIONAL OR UP-TO-DATE TECHNICAL LITERATURE

More information can be found on the ST website (http://www.st.com/mcu).

More specifically, the latest documents and software can be found directly at: http://www.st.com/mcu in the Downloads section

In addition, FAQ and Forums can be found directly at :

http://www.st.com/stonline/products/support/micro/st7/st7mc.htm

15/77

ST7MC THREE-PHASE BLDC MOTOR CONTROL SOFTWARE LIBRARY

3 GETTING STARTED WITH THE LIBRARY USING THE ST7MC-KIT/BLDC

3.1 INTRODUCTION

There are two ways to get started with this software library.

The first way is to edit (with your motor specific features), compile and assemble the modules described in Section 5 and Section 6 of this application note. Then, program ST7MC and run your motor on hardware like the one provided in the ST7MC-KIT/BLDC Starter-kit.

The second way is to use the ST7MC-KIT/BLDC Starter-kit and follow this process:

-run and fine-tune the motor parameters with the GUI

-generate the *.H files and manually select/save the key parameters

-edit mtc.h file with key parameters

-compile, link, program ST7MC

-run the motor

If you are new to the BLDC environment or to the ST7MC product, the second method is highly recommended and is described below.

3.2 RUNNING THE MOTOR

As a starting point, the open loop mode shall be used for the first trials. Low-duty cycle values should be used also (alignment, ramp and real time settings) and then increased smoothly step by step.

Once the motor settings have been finely adjusted (whatever the driving mode, sensor/sensorless), the parameters have to be ‘injected’ into the stand-alone library. Simply click on ‘Generate *.h Files’ and select the source directory of the stand-alone library.

16/77

ST7MC THREE-PHASE BLDC MOTOR CONTROL SOFTWARE LIBRARY

The GUI will generate 1 dedicated header file containing the settings of the motor (mainly the MTC peripheral settings) and another one containing the compiler options (see Figure 5).

Figure 5. Files generated in sensorless and sensor mode

SENSORLESS MODE

SENSOR MODE

“MTC_Settings_Sensorless.h” “MTC_Settings_Sensor.h”

“Version.h” “Version.h”

Once previous files have been generated, launch a new compilation. Firmware will then be compiled according to the new settings/compiler options automatically.

17/77

ST7MC THREE-PHASE BLDC MOTOR CONTROL SOFTWARE LIBRARY

3.3 STANDALONE MODE AND CLOSED LOOP OPERATION

To run a BLDC motor in standalone closed loop, the approach should be, for a given target mechanical speed, to fine tune all the realtime parameters most adequate for this speed. For each target speed, these values should be recorded in the form of a table, which will be used by the ST7MC standalone firmware. You should collect data for 4 speeds: the min and max speeds specified in the GUI advanced screen, and 2 intermediate speeds of your choice. The ST7MC standalone firmware will then make a linear extrapolation of realtime parameters in between the 4 specified speeds to ensure smooth operation.

Once the data is collected, edit the ‘mtc.h’ file and fill in the field dedicated to the Rising/Falling Bemf, Ki, Kp coefficient calculation (see Figure 6).

Figure 6. ‘mtc.h’ field for coefficient computation

// See 'Mtc_Settings_Sensorless.h' for Freq_Min & Freq_Max values //Fmin

#define Rising_Fmin

20

// Frequency min coefficient settings

#define Falling_Fmin

30

 

#define Ki_Fmin

10

 

#define Kp_Fmin

30

 

//F_1

 

 

#define F_1

1000

// 100 Hz

#define Rising_F_1

50

// Intermediate frequency 1 coefficient settings

#define Falling_F_1

40

 

#define Ki_F_1

20

 

#define Kp_F_1

10

 

//F_2

 

 

#define F_2

2000

// 200 Hz

#define Rising_F_2

30

// Intermediate frequency 2 coefficient settings

#define Falling_F_2

10

 

#define Ki_F_2

50

 

#define Kp_F_2

40

 

//Fmax

 

 

#define Rising_Fmax

10

// Frequency max coefficient settings

#define Falling_Fmax

16

 

#define Ki_Fmax

13

 

#define Kp_Fmax

18

 

Once the motor runs, rising/falling Back-EMF and proportional/integer coefficients are computed following a linear curve between F_min and F_1, F_1 and F_2, F_2 and F_max (see Figure 7). Note that F_min, F_1, F_2, F_max are electrical frequencies, with 0.1 Hz resolution (for example F_1 = 1234 means F_1 = 123.4Hz).

18/77

ST7MC THREE-PHASE BLDC MOTOR CONTROL SOFTWARE LIBRARY

Figure 7. Linear curve for coefficient computation

Rising/Falling Bemf

 

 

 

 

Ki, Kp

 

 

 

 

Rising_F_2, Falling_F_2

 

 

 

 

Ki_F_2, Kp_F_2

 

 

 

 

Rising_Fmax, Falling_Fmax

 

 

 

 

Ki_Fmax, Kp_Fmax

 

 

 

 

Rising_F_1, Falling_F_1

 

 

 

 

Ki_F_1, Kp_F_1

 

 

 

 

Rising_Fmin, Falling_Fmin

 

 

 

 

Ki_Fmin, Kp_Fmin

 

 

 

 

F_min

F_1

F_2

F_max

Target rotor

 

 

 

 

electrical

 

 

 

 

frequency

3.4 NOTE ON DEBUGGING TOOLS

3.4.1 Low voltage applications (below 30V)

For these voltage levels, the real-time emulator can be connected to the application, taking care to connect the protective boards provided with the MDT50 emulator (refer to the emulator datasheet for details). It offers trace and advanced breakpoint capabilities, as well as the possibility to automatically disable the PWM outputs on a breakpoint to avoid any DC current injection in the motor (see Figure 8).

This emulator is delivered with a set of three boards to protect some of the motor control dedicated I/Os from voltages greater than 5V. It is highly recommended to have them connected during the development. A neutral board is also provided in case the protection networks impedance (1K series resistor plus 5V3 zener diode) is an issue for the application. Refer to the ST7MDT50-EMU3 Probe user guide Section 3.1 for details.

An In-Circuit Debugging tool can also be directly connected, as long as an ICC connector is available on the application.

Important Note: When using ICD, during a breakpoint, the clock circuitry is not disabled: a permanent DC current may flow in the motor as the PWM outputs are enabled. It is thus recommended to use a power supply with fast current limitation capabilities or if possible to disable the PWM outputs (by inserting MTC_DisableMCOutputs function) before the breakpoint.

19/77

ST7MC THREE-PHASE BLDC MOTOR CONTROL SOFTWARE LIBRARY

Figure 8. Configuring the Motor Controller clock state on breakpoint with MDT50

3.4.2 Medium-high voltage application (above 30V)

Here the real-time emulator use is not recommended, even if protective boards are inserted.

Important Note: In the event of high voltage applications connected to the mains, the application ground may be at a dangerous voltage; so too then would be the MDT50 emulator (the protective boards do not provide galvanic isolation).

For voltages above 30V, it is highly recommended to use only programmed devices. ICD debugging can be used in conjunction with an ICC isolation board, as the one provided with the ST7MC-KIT/BLDC starter kit, but the limitations mentioned in Section 3.4.1 nevertheless apply, and are even emphasized by the high voltage levels.

Good practice for real-time application debugging is to use “diagnostic tools” such as:

RS232 communication which can be easily isolated,

Standalone DAC (serial SPI-based model for instance) to be able to monitor signals on an oscilloscope,

Debug outputs of the ST7MC itself (MCDEM and MCZEM pins), to monitor the D, Z and C events (refer to datasheet for details).

Refer to the application note AN438 (Safety Precautions for Development Tool Triac + Microcontroller) for further details when working with the mains supply.

20/77

ST7MC THREE-PHASE BLDC MOTOR CONTROL SOFTWARE LIBRARY

3.5 USING YOUR OWN POWER STAGE

In order to configure the standalone library to match any kind of power stage, care should be taken to observe the logic input diagrams of the drivers. The starter kit uses three L6386 highvoltage high and low side drivers; other devices may require adjustments, depending on whether their logical inputs are active low or high. The ‘MPOL’ register has then to be set manually in the firmware. Modifications can be done in the ‘MTC_InitPeripheral’ routine (see Figure 9). It has to be noted also that the option byte has to be updated accordingly (MCO output states during reset).

Figure 9. MPOL register configuration

void MTC_InitPeripheral(void)

{

MTC_ResetPeripheral();

// Initialize registers in page 1 first SET_MTC_PAGE(1);

MCONF = mem_MCONF;

MPWME = (u8)(mem_MPWME | DG_MSK); //Force output of debug signal

MPOL = ALL_ACTIVE_HIGH;

// (L6386D) <-- to be updated according to your own

device characteristics

// ZVD bit=0; Z and D have opposite edge

The starter kit can also be connected directly to an external power stage using the socket J6 (26 pins).

3.6 CHECKING THE CURRENT SENSOR RESISTOR VALUE

The starter kit comes with a current sensor resistor of 0.047 Ohm (R21 on the schematic, see Figure 10). The current limiter of the MTC cell relies on a comparator that turns off the PWM when the voltage on this resistor has reached a limit (see Section 7.2.1 Voltage versus current mode for more details). This voltage is amplified by a factor of 11 by the internal OPAMP configured as a non-inverter amplifier (see R66 and R67 values).

21/77

ST7MC THREE-PHASE BLDC MOTOR CONTROL SOFTWARE LIBRARY

Figure 10. Starter kit: zoom on the power stage

‘R21’ 47 milli-ohm resistor acting as a current sensor

3.6.1 Maximum current

The saturation voltage of the internal comparator is 5 Volts. Figure 11 summarizes the hardware configurations when the winding current is set to maximum.

22/77

ST7MC THREE-PHASE BLDC MOTOR CONTROL SOFTWARE LIBRARY

Figure 11. Configuration at max. current

 

 

clock

 

 

 

 

PWM freq.

HV

 

 

 

 

 

 

comparator

 

 

MCCREF

-

Set

 

 

 

T1

 

OAZ/MCCFI1

+

R

5 Volts

 

 

 

 

 

 

 

 

 

A

 

 

 

 

T4

 

Uout

OPAMP

Usense

 

 

 

 

 

 

 

 

X11

 

 

 

 

 

47 milli-Ohm

Therefore, the maximum current can be calculated:

Imax = Vsaturation / (OPAMPgain x Rsense)

Previous formula applied to the starter kit leads to:

Imax = 5 / (11 x 0.047) = 9.67 amperes

The current sense resistor value has to be adjusted when a different working range is needed. It is then necessary to decrease it when the current requirement is higher, or to increase it when the current requirement is lower. It is also possible to adjust the OPAMP gain, but it has to be remembered that:

A High-gain OPAMP configuration may decrease EMC performance.

A low-gain OPAMP combined with a high current sense resistor value will induce higher power loss (into the resistor).

The power stage of the starter kit has been designed to handle power up to 1KW. For higher power, a bigger heat sink and current capability IGBTs or MOSFETs may be required.

3.6.2 Interpreting the current feedback/settings in the GUI

Settings related to current values on the GUI are treated as if the current sensor value were a 47 milli-Ohm type (with OPAMP gain equal to 11). When using a different resistor value, settings concerning current can’t be read/written directly but have to be calculated manually using a proportional coefficient equal to:

K = 47 milli-Ohm / new value

The actual current information is the one shown on the GUI multiplied by the proportional coefficient ‘K’ (See Figure 12 & Figure 13).

23/77

ST7MC THREE-PHASE BLDC MOTOR CONTROL SOFTWARE LIBRARY

Figure 12. Using a 20 milli-Ohm resistor, K = 2.35 (47/20)

Actual value:

3x2.35 = 7.05 A

1x2.35 = 2.35 A

8.7x2.35 = 20.45 A

Figure 13. Using a 100 milli-Ohm resistor, K = 0.47 (47/100)

Actual value: 1.97x0.47 = 0.93 A

24/77

Loading...
+ 53 hidden pages