ST AN1904 Application note

AN1904

Application note

ST7MC three-phase AC induction motor control software library

Introduction

This Application Note describes a 3-phase induction motor control software library developed for the ST7MC. This 8-bit microcontroller contains a peripheral dedicated to 3- phase brushless motor control, making it suitable for AC induction motors and permanent magnet DC/AC motors (PMDC/PMAC also called BLDC).

The library described here is made of several C modules that contain a set of convenient functions for the scalar control of AC induction motors and is compatible with COSMIC (www.cosmic-software.com) and METROWERKS (www.metrowerks.com) compilers. The control of a Permanent magnet motor in Six-step mode is detailed in application note AN1905. The control of a PMAC motor in Sine wave mode with sensors is detailed in application note AN1947.

This software allows users to quickly evaluate both the MCU and the available tools, and to have a motor running in a very short time when used together with the ST7MC starter kit (ST7MC-KIT/BLDC) and the demonstration AC motor (ST7MC-MOT/IND). It also eliminates the need for time consuming development of sine wave generation and speed regulation algorithms by providing ready-to-use functions that let the user concentrate on his application layer.

The prerequisite for using this library is the basic knowledge of C programming, AC motor drives and power inverter hardware. In-depth know-how of ST7MC functions is only required for customizing existing modules and when adding new ones (grey modules in Figure 1) for a complete application development.

Figure 1. Overall software architecture

 

 

APPLICATION LAYER

 

 

 

SLIP

 

AC MOTOR DRIVE

 

COMMUNICATION

REGULATION

3-PHASE SINE WAVE GENERATION

PROTOCOL

 

PWMART

WWDG

PORTS

MTC

ADC

SCI

16-bit

SPI

Timer

 

 

 

 

 

 

 

 

 

MCO[0..5]

Emergency Stop input

 

 

 

 

PWM outputs

 

 

 

 

Speed feedback

 

 

 

 

 

 

 

 

 

July 2007

Rev 3

1/102

www.st.com

Contents

AN1904

 

 

Contents

1

Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

5

2

Working environment set-up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

6

 

2.1 Development tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

6

2.1.1 Integrated Development Environments (IDE) . . . . . . . . . . . . . . . . . . . . . 6 2.1.2 Emulators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 2.1.3 Programmers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 2.1.4 Starter kit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

2.2 Library source code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

2.2.1 Download . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 2.2.2 File structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

2.3 Utilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

2.3.1 lib.h file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 2.3.2 Sine wave look-up table spreadsheet . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 2.3.3 HyperTerminal file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

2.4 Technical literature . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

3

Getting started with the library using the ST7MC-KIT/BLDC . . . . . . .

10

 

3.1

Running the motor with the ST7MC control panel . . . . . . . . . . . . . . . . . .

10

 

3.2

Library configuration file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

12

 

3.3

Customizing the files for your ST7MC derivative . . . . . . . . . . . . . . . . . . .

13

3.3.1 Memory mapping with COSMIC toolchain . . . . . . . . . . . . . . . . . . . . . . . 13 3.3.2 Memory mapping with METROWERKS toolchain . . . . . . . . . . . . . . . . . 14 3.3.3 Hardware registers description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

 

3.4

How to define and add a C module . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

15

 

 

3.4.1

Using STVD7 release 2.5.x . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

15

 

 

3.4.2

Using STVD7 release 3.x.x . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

16

4

Library functions per software module . . . . . . . . . . . . . . . . . . . . . . . . .

18

4.1 Function description conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 4.2 Sine wave generation and speed feedback (MTC) . . . . . . . . . . . . . . . . . . 18

4.2.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 4.2.2 List of available functions and interrupt service routines . . . . . . . . . . . . 19

2/102

AN1904

 

 

Contents

 

 

 

 

 

4.2.3

Detailed explanations and customization of MTCparam.h . . . . .

. . . . . . 38

4.3

Induction motor scalar control (ACMOTOR) . . . . . . . . . . . . . . . . . . .

. . . . 47

 

4.3.1

Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . 47

 

4.3.2

List of available functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . 47

 

4.3.3

Detailed explanations and customization of ACMparam.h . . . . .

. . . . . 58

4.4

Analog to digital converter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . 71

4.4.1 Module description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71 4.4.2 Synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72 4.4.3 Timing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72 4.4.4 Caution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72 4.4.5 Customizing the ADC module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73

 

4.5

I/O ports

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

73

 

 

4.5.1

Push button reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

73

 

 

4.5.2

LEDs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

73

 

4.6

PWM auto reload timer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

74

 

 

4.6.1

Software timebases working principle . . . . . . . . . . . . . . . . . . . . . . . . . .

74

 

 

4.6.2

Timebase use for the AC motor control library and demo program . . . .

75

 

4.7

Serial communication interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

76

 

 

4.7.1

Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

76

 

 

4.7.2

Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

77

 

 

4.7.3

Changes vs ST7 library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

77

 

 

4.7.4

Customization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

78

 

 

4.7.5

Important notice for hardware implementation . . . . . . . . . . . . . . . . . . .

78

 

4.8

Nested interrupt controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

78

5

Running the demo programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

80

 

5.1

Open loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

81

 

5.2

Closed loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

82

 

5.3

Using the serial communication interface . . . . . . . . . . . . . . . . . . . . . . . . .

83

 

5.4

Mainparam.h file description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

84

5.4.1 Start-up parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84 5.4.2 Brake parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84 5.4.3 Closed-loop slip control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84

6

Designing your application with the library . . . . . . . . . . . . . . . . . . . . .

85

 

6.1

Library maintenance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

85

3/102

Contents

AN1904

 

 

6.2

Incremental system build . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

86

 

6.2.1

Preliminary notice on debugging tools . . . . . . . . . . . . . . . . . . . . . . . . . .

86

 

6.2.2

Build step1: open loop, low voltage, no motor connected . . . . . . . . . . .

87

 

6.2.3

Build step2: open loop, rated voltage/power, motor connected . . . . . . .

88

 

6.2.4

Build step3: open loop, rated power, motor connected with speed

 

 

 

feedback 88

 

 

6.2.5

Build step4: closed loop operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

88

6.3 Motor control related CPU load in the application . . . . . . . . . . . . . . . . . . 89

6.3.1 Estimation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89 6.3.2 Adjustment guidelines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89

Appendix A Appendix. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90

 

A.1

Flowcharts. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. 90

 

 

A.1.1

MTC_U_CL_SO_IT interrupt routine . . . . . . . . . . . . . . . . . . . . . . . . . .

. 90

 

 

A.1.2

MTC_C_D_IT interrupt routine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. 91

 

 

A.1.3

MTC_GetRotorFreq function. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. 92

 

 

A.1.4

GetLastTachoPeriod function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. 93

 

 

A.1.5

GetAvrgTachoPeriod function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. 94

 

 

A.1.6

MTC_StartBraking function. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. 95

 

 

A.1.7

MTC_Brake function state diagram . . . . . . . . . . . . . . . . . . . . . . . . . . .

. 96

 

 

A.1.8

MTC_StopBraking function. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. 96

 

 

A.1.9

ACM_InitSoftStart function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. 97

 

 

A.1.10

ACM_SoftStart function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. 98

 

 

A.1.11

Open Loop motor control demo program . . . . . . . . . . . . . . . . . . . . . . .

. 99

 

A.2

Selni motor characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

100

7

Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

101

4/102

AN1904

Features

 

 

1 Features

ST7MC Library Version 1.0.1 Overview (CPU running at 8 MHz):

Stator Frequency Range: From 0.2 Hz up to 680.0 Hz (see Section on page 44) with resolution depending on PWM frequency (typically ~0.1Hz)

Voltage Resolution: 8-bit modulation index

9 to 10-bit PWM generation for sine wave (typical resolution in inaudible PWM range)

PWM Frequency: can be set by default to 1.95, 3.9, 7.8, 12.5 and 15.66 kHz, with centred pattern PWM generation

Brake capabilities (DC current injection)

Speed reversal

Tacho generator Speed acquisition

Speed regulation and control routines for speed profile management

CPU Load (sine wave generation only) around 20%, adjustable (see Section ). Total CPU load (including closed loop control) is typically around 30% for a standard application (see Section 6.3)

Free C source code and spreadsheet for look-up tables

The 12.5 kHz switching frequency is proposed by default, providing a PWM resolution close to 10-bit with a 16-MHz CPU clock. In addition, this frequency is a good compromise between the reduction of switching losses and acoustic noise (rejected in the inaudible range due to centred mode PWM patterns).

Note:

These figures are for information only; this software library may be subject to changes

 

depending on the use of the final application and peripheral resources. It must be noted that

 

it was built using robustness-oriented structures, therefore preventing the speed or code

 

size from being fully optimized.

 

 

 

 

Table 1 below summarizes the memory required by the software library, as it is delivered.

 

These metrics include non motor control related code, implemented for demo purposes

 

(such as ADC management, software timebases, etc.). These must therefore be considered

 

only as indicative figures, which will be lower in the final application.

 

 

Table 1.

Memory size metrics

 

 

 

 

 

 

 

 

 

 

 

 

 

ROM (bytes)

RAM (bytes)

 

 

 

 

 

 

 

 

 

 

Cosmic 5.2b

Metrowerks 1.1

Cosmic 5.2b

Metrowerks 1.1

 

 

 

 

 

 

 

Closed Loop

4943

5729

136

161

 

 

 

 

 

 

 

Open loop

3840

4361

108

130

 

 

 

 

 

 

 

5/102

Working environment set-up

AN1904

 

 

2 Working environment set-up

This section presents the available material that is needed to start working with the ST7MC and the library discussed in this document.

2.1Development tools

2.1.1Integrated Development Environments (IDE)

This library has been compiled using Cosmic & Metrowerks C compilers, launched with STVD7 release 2.5.4 (ST Visual Debugger) and STVD7 release 3.x.x.

A complete software package consists of:

An IDE interface: ST’s proprietary STVD7 (free download available on internet: www.stmcu.com), or third party IDE (e.g. Softec Microsystems’ STVD7 for InDARTSTX).

A third party C-compiler: either Cosmic or Metrowerks (if needed, time limited evaluation versions can be get upon request).

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’ & ‘STVD7 for Indart’) can be directly opened in the root of the library installation folder (AC_Metrowerks.wsp, AC_Cosmic.wsp, acmotor.stw).

2.1.2Emulators

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

In-circuit debugger from Softec (sales type: STXF-INDART/USB).

The inDART-STX from Softec Microsystems is both an emulator 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 the working registers and 2 breakpoint settings. However trace is not available.

ST7MDT50-EMU3 emulator

Full-featured emulator: real-time with trace capability, performance analysis, advanced breakpoints, light logical analyser capabilities, etc. It can also be 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.

2.1.3Programmers

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 dedicated programming interface (stick programmer for example for In-Circuit-Programming). The Visual Programming tool provides an easy way to erase, program and verify the MCU content.

Please note that the inDART-STX from Softec Microsystems is also a programming tool (installation of DataBlaze Programmer software is required).

6/102

AN1904

Working environment set-up

 

 

Figure 2. STVisual Programmer software (STVP7)

2.1.4Starter kit

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, and the demonstration AC motor from SELNI (Sales type ST7MC-MOT/IND). See Section A.2 on page 100 for electrical specifications of this motor. The ST7MC-KIT/BLDC starter kit also includes a lowcost inDART hardware emulator, making this tool an ideal set for starting a project and evaluating/using the library. Finally, the graphical user interface included in the starter kit (ST7MC Control Panel) is primarily intended to run motors from a PC for testing and demo purposes, and is also able to generate library configuration files, with defines corresponding to your own motor. This makes the first implementation of this library significantly easier. See Section 4 of this document for details.

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-toolchain (or at least time limited evaluation versions).

2.2Library source code

2.2.1Download

The complete source files are available for free on ST website (www.stmcu.com), in the Technical Literature and Support Files 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 on www.softecmicro.com, in the Downloads section, software part (AK-ST7FMC System Software).

7/102

Working environment set-up

AN1904

 

 

Caution: It is highly recommended to check for the latest releases of the library before starting a new development, and then verify the release notes from time to time to be aware of 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 get automatically update information.

2.2.2File structure

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

Library release 1.0.0

This release only supports STVD7 2.5.x workspace; this IDE does not provide C builder capabilities. All build information is provided in makefiles and linker command files, in dedicated folders: config\Cosmic and config\Metrowerks (see Figure 3). Object files are also provided in dedicated folders.

Figure 3. Library structure for release 1.0.0

ACmotor \ config \ cosmic

\ metrowerks \ object \ cosmic

\ metrowerks \ source

Library release 1.0.1

This library contains the workspace for both the STVD7 2.5.x and STVD7 3.x IDEs. Two separate sets of folders are provided to differentiate object and configuration files, with a common set of source files (see Figure 4).

This is to ensure the compatibility with STVD7 for inDART-STX, based on STVD7 2.5.3.

Figure 4. Library structure for release 1.0.1

ACmotor_1.0.1 \ config \ cosmic

\ metrowerks

For STVD7_2.5.x

\ object \ cosmic

\ metrowerks

\ Debug

For STVD7_3.x

\Release

\Source

\Utilities

8/102

AN1904

Working environment set-up

 

 

2.3Utilities

2.3.1lib.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(),...

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

2.3.2Sine wave look-up table spreadsheet

A sine3.xls Excel file is provided with the library, in the \utilities folder. It contains the data and calculations necessary to re-generate the sine wave reference look-up table. This lookup table includes 3rd harmonics and is therefore not suitable as it is for bi-phase motor control. PWM frequency set-up on page 39.

2.3.3HyperTerminal file

An AC Library.ht file is also provided in the \utilities folder to set-up the HyperTerminal software when the RS232 communication is enabled. Serial communication interface on page 76.

2.4Technical literature

More information can be found on the ST website (www.st.com).

9/102

Getting started with the library using the ST7MC-KIT/BLDC

AN1904

 

 

3Getting started with the library using the ST7MCKIT/BLDC

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

The first method is to edit (with your motor specific features) and compile the modules described in Section 4 of this application note. Then program ST7MC and run your motor using the ST7MC-KIT/BLDC Starter-kit hardware or your own design.

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

run and fine tune motor parameters with the ST7MC Control Panel,

generate *.h files and select/save manually key parameters,

edit some of the .h files with run-time parameters collected with the GUI (see

Section 4.2.3 and Section 4.3.3 for details),

compile, link and program the ST7MC,

run the motor.

This second method is highly recommended and is described below.

3.1Running the motor with the ST7MC control panel

As a starting point, the open loop mode can be used for the first trials. Low voltage values can be used for safety and then increased smoothly step by step. Incremental system build on page 86 for details.

Once the motor settings have been finely adjusted (whatever the driving mode, open or closed loop), the parameters have to be imported into the stand-alone library. Simply click on ‘Generate *.h Files’ and select the source directory of the stand-alone library: see

Figure 5

10/102

ST AN1904 Application note

AN1904

Getting started with the library using the ST7MC-KIT/BLDC

 

 

Figure 5. . ST7MC Control Panel: library header files generation

This interface generates 3 header files containing the motor and application parameters plus a file with conditional compilation keys for library re-build (see Section 3.2):

MTCparam.h contains parameters of routines directly related to the motor controller peripheral, mainly PWM, sine wave generation and speed feedback processing (see

Section 4.2.3 on page 38),

ACMparam.h contains parameters related to the motor and the load, such as V/f curve and speed regulation (see Section 4.3.3 on page 58),

Mainparam.h contains some application/demo specific features (see Section 5.4 on page 84).

Once the above files have been generated, the whole library must be re-built. The library and its demo program will then include the new settings automatically.

To launch the compilation, click on the ’rebuild all’ icon of STVD7: see Figure 6

Figure 6. Rebuilding the whole application with STVD7

Rebuild

11/102

Getting started with the library using the ST7MC-KIT/BLDC

AN1904

 

 

3.2Library configuration file

The purpose of this file is to declare the compiler conditional compilation keys which will be used throughout the entire library compilation process, to:

define the AC motor driving mode: open / closed loop (see Section 5 and Section 5.3),

define the PWM resolution (needed to define the PWM frequency range, see Section ),

enable or disable the RS232 communication (see Using the serial communication interface on page 83),

enable or disable the PI parameters tuning (see Regulation tuning procedure on page 62).

Below are the compilation key definitions in config.h:

// Define here the desired control type

//0 -> Open loop

//1 -> Closed loop #define CONTROL1

//-------------------------------------------------------------------------

//Define here the chosen PWM resolution (linked to PWM switching frequency)

//0 -> 9-bit: 1.95kHz, 3.9kHz, 7.8kHz, 15.66kHz: cf. "MTCparam.h"

//1 -> 10-bit: 12.5 kHz

#define PWM_RESOLUTION 1

//-------------------------------------------------------------------------

//Define here the way the closed loop parameters (Kp, Ki) are set

//if this label is commented, Kp and Ki are set according to a look-up table

//defined in ACMparam.h.

//#define PI_PARAM_TUNING

//-------------------------------------------------------------------------

//Define here if you want to use the SCI interface to monitor some internal

//variables during run time

//IMPORTANT NOTE: As communication is done by polling, this will decrease

//the sampling rate of the PI Speed controller

#define ENABLE_RS232

12/102

AN1904

Getting started with the library using the ST7MC-KIT/BLDC

 

 

3.3Customizing the files for your ST7MC derivative

Figure 7.

Memory map

 

 

 

 

 

 

 

 

 

0000h

 

 

0080h

 

 

 

 

 

 

 

 

 

HW Registers

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

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

or 037Fh

 

 

 

 

 

 

1000h

 

 

 

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 7. The memory arrangement may vary depending on the type of the MCU. Please refer to the ST7MC datasheet for 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.

The above example is based on the ST7FMC2S4 MCU (TQFP 44, 16K Flash, 768 Bytes RAM).

3.3.1Memory mapping with COSMIC toolchain

Go to \config\Cosmic, edit 32K.lkf and check the following lines, in ‘SEGMENT

DEFINITION’:

# SEGMENT DEFINITION (.text, .const,.data,.bss,.bsct,.ubsct are c compiler predefined sections)

+seg .text

-b0x8000 -m0x8000 -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 (defined when using compact

or

memory models

only)

 

 

 

+seg .data

-b0x0200 -m0x27F -nIDATA

-sRAM # NO initialized variables

 

+seg .bss

-aIDATA -nUDATA -sRAM

 

# uninitialized variables

 

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

In order to enter the memory mapping of the ST7FMC2S4, the size of ROM and RAM memory have to be changed (32K -> 16K Flash, 1K RAM -> 768 Bytes RAM). For ROM:

13/102

Getting started with the library using the ST7MC-KIT/BLDC

AN1904

 

 

 

+seg .text

-b0xc000 -m0x3fe0 -nCODE -sROM

# executable code

(where 0xc000 is the new starting address of the program memory and 0x3fe0 the size in bytes). For RAM:

+seg .bss

-b0x0200 -m0x0180 -nUDATA -sRAM

# uninitialized variables

(where 0x0180 is the new size of the 16 bit addressing RAM memory).

3.3.2Memory mapping with METROWERKS toolchain

Go to \config\Metrowerks, edit acmotor.prm and check the following lines:

SECTIONS

ZRAM = READ_WRITE 0x0080 TO 0x00FF;

RAM = READ_WRITE 0x0200 TO 0x047F;

ROM = READ_ONLY 0x8000 TO 0xFFDF;

This part of the prm file contains the memory locations of pages declared at the end of the file.

To modify the memory size for the ST7FMC2S4, ROM and RAM memory settings have to be changed (32K -> 16K Flash, 1K RAM -> 768 Bytes RAM):

ROM = READ_ONLY 0xC000 TO 0xDFFF;

(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 end address of the 16 bit addressing RAM memory).

Caution: The application layer has been written for the STMFC2NB6. Using a different ST7MC sales type can imply the need to do 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 datasheet for details.

3.3.3Hardware registers description

The library is based on the ST7FMC2N6.h file, which contains the hardware registers declarations and memory mapping for the ST7FMC2N6. It also contains most of the bit masks for the peripherals, at the exception of some Motor Controller bits and bitfields described in mtc_bits.h.

The ST7FMC2N6.h is provided by default with the STVD7 release 3.x.x toolchain, usually in:

C:\Program Files\STMicroelectronics\st7toolset\include

All other ST7MC derivative descriptions can be found in this folder, from the ST7FMC1K2 to the ST7FMC2M9. The name of the corresponding header file will have to be changed in the config.h file.

14/102

AN1904

Getting started with the library using the ST7MC-KIT/BLDC

 

 

3.4How to define and add a C module

This chapter describes how to define and declare a new module in a project based on the library. The example is based on the addition of 2 files: ‘my_file.c’ and the corresponding header file ‘my_file.h’.

The first step is the creation of these files. Existing files can be copied, pasted and renamed, or created by clicking on the ‘new files’ icon and then saving them with the right extension (*.c or *.h).

Three files (two source and one object) have to be declared in the toolchain configuration files.

3.4.1Using STVD7 release 2.5.x

COSMIC compiler

COSMIC compiler is launched using a makefile (acmotor.mak) and the linker gets information from the linker command file 32K.lkf file. These two files need to be modified.

In 32.lkf, the new object file has to be added in the common object file list, or apart from this object list with correct settings (for instance for interrupt vectors or constants that need to be at fixed location, see documentation of C compiler for details).

# OBJECT FILES

..\..\object\cosmic\main.o

...

..\..\object\cosmic\my_file.o

...

# OBJECT FILES END

In acmotor.mak, ‘my_file.c’ has to be added in the C source file list:

C_SRC = \

main.c \

acmotor.c \

... \

my_file.c \

... \

vector.c

and the list of dependencies has to be updated accordingly:

# RULES FOR MAKING THE OBJECT FILES:

main.o: main.c lib.h ports.h adc.h pwmart.h Sci.h mtc.h acmotor.h config.h Mainparam.h ST7FMC2N6.h

$(CC) ..\..\source\main.c

15/102

Getting started with the library using the ST7MC-KIT/BLDC

AN1904

 

 

...

my_file.o: my_file.c my_file.h lib.h ST7FMC2N6.h ...

$(CC) ..\..\source\my_file.c

METROWERKS compiler

For METROWERKS users, modifications have to be done in acmotor.prm and acmotor.mak files. In the makefile, the new object file my_file.o has to be added in the ‘Object file list’ section and the corresponding dependencies have to be set in the ‘Application files’ section:

# -----------------------------

OBJECT

FILES LIST -----------------------------

OBJ_LIST = main.o mtc.o ...

my_file.o

 

...

 

 

# ---------------------------

APPLICATION FILES ------------------------------

main.o : $(ENV) main.c lib.h ports.h adc.h pwmart.h sci.h mtc.h acmotor.h \ config.h MainParam.h ST7FMC2N6.h

$(CC) main.c

my_file.o : $(ENV) my_file.c my_file.h lib.h ST7FMC2N6.h ...

$(CC) my_file.c

In acmotor.prm the new object file has to be added in the ‘Project module list’ section:

/*** PROJECT MODULE LIST ***/

NAMES main.o mtc.o

...

my_file.o

...

start07.o

ansi.lib END

3.4.2Using 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 source file.

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

16/102

AN1904

Getting started with the library using the ST7MC-KIT/BLDC

 

 

Figure 8. Adding a source file using STVD7 3.x.x

17/102

Library functions per software module

AN1904

 

 

4 Library functions per software module

4.1Function description conventions

The functions are described in the format given below:

Synopsis

This section lists the required include files and prototype declarations.

Description

The functions are described with a brief explanation on how they are

 

executed.

Input

In few lines, the format and units are given.

Returns

Gives the value or error code returned by the function.

Caution

Indicates the limits of the function or specific requirements that must be

 

taken into account during library integration.

Warning

Indicates important points that must be taken into account to prevent

 

hardware failures.

Functions called Allows to prevent conflicts due to the simultaneous use of resources.

Duration

The approximate duration of the routine. This is performed using the

 

maximum CPU clock frequency (8 MHz) without interrupts if not notified.

 

Slight variations may be expected when changing compiler, options,

 

memory models,...

Code example

Indicates the proper way to use the function if there are certain

 

prerequisites (interrupt enabled, etc.).

Some of these sections may not be included if not applicable (no parameters, obvious use, etc.).

4.2Sine wave generation and speed feedback (MTC)

4.2.1Overview

The “mtc.c” module is intended to handle all motor control functionalities directly linked to the motor control peripheral hardware (initialization or run-time accessed registers, interrupt service routine).

It can be seen as an interface between the AC motor control specific module and the low level control routines having direct influence on the hardware (PWM outputs, speed sensor, Emergency Shutdown pin).

It contains, among other functions:

basic setup / control functions for the Motor Controller Peripheral (MTC),

Sine wave generation (through PWM interrupt processing),

DC current braking,

Direction reversal,

speed acquisition related interrupts and functions.

The prototype functions are located in the “mtc.h” header file.

18/102

AN1904

Library functions per software module

 

 

4.2.2List of available functions and interrupt service routines

The following is a list of available functions as listed in the mtc.h header file.

MTC_ResetPeripheral . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . on page 20

MTC_InitPeripheral . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . on page 20

MTC_InitSineGen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . on page 20

MTC_EnableMCOutputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . on page 21

MTC_DisableMCOutputs. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . on page 21

MTC_CheckEmergencyStop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . on page 22

MTC_ClearEmergencyStop. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . on page 22

MTC_StartBraking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . on page 23

MTC_Brake . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . on page 24

MTC_StopBraking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . on page 25

MTC_Toggle_Direction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . on page 26

MTC_Set_ClockWise_Direction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . on page 26

MTC_Set_CounterClockWise_Direction . . . . . . . . . . . . . . . . . . . . . . . . . . on page 26

MTC_GetRotationDirection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . on page 26

MTC_GetVoltage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . on page 27

MTC_GetStatorFreq . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . on page 27

MTC_GetSlip . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . on page 27

MTC_InitTachoMeasure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . on page 28

MTC_StartTachoFiltering. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . on page 28

MTC_ValidSpeedInfo. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . on page 29

MTC_GetRotorFreq . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . on page 30

MTC_UpdateSine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . on page 31

GetLastTachoPeriod . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . on page 32

GetAvrgTachoPeriod . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . on page 32

MTC_U_CL_SO_IT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . on page 33

MTC_C_D_IT. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . on page 34

MTC_R_Z_IT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . on page 35

MCES_SE_IT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . on page 36

SET_MTC_PAGE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . on page 37

ToCMPxL. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . on page 37

ToCMPxH . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . on page 37

MTC_EnableClock. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . on page 37

MTC_DisableClock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . on page 37

19/102

Library functions per software module

AN1904

 

 

MTC_ResetPeripheral

MTC_InitPeripheral

MTC_InitSineGen

 

Synopsis

#include "mtc.h"

 

 

void MTC_ResetPeripheral(void);

 

 

void MTC_InitPeripheral(void);

 

 

void MTC_InitSineGen(void);

 

Description

The purpose of these three functions is to set-up the Motor Controller

 

 

peripheral and to initialize the software variables needed for sine wave

 

 

generation.

 

 

MTC_ResetPeripheral

 

 

Resets the whole circuitry of the Motor Controller peripheral of the ST7MC,

 

 

as it is found after a microcontroller RESET, with the sole exception of the

 

 

MDTG and MPOL write-once registers (see datasheet for details).

 

 

MTC_InitPeripheral

 

 

Performs the initialization of the Motor Controller peripheral hardware

 

 

registers, for the sine wave general parameters (such as PWM frequency,

 

 

output polarity, deadtime, interrupts,...) and speed feedback processing

 

 

(tacho input selection, edge sensitivity,...). It also starts the 12-bit PWM

 

 

timer and the tacho dedicated timer (MTIM:MTIML). All required motor

 

 

control related interrupts are unmasked upon completion of this routine.

 

 

MTC_InitSineGen

 

 

Initialization of software variables needed for sine wave generation and

 

 

used in the PWM update interrupt routine. Ensures that once the PWM

 

 

update interrupts will have been enabled, the sine wave generated will

 

 

have a null voltage and that stator frequency change will be taken into

 

 

account.

 

Duration

2.75µs for MTC_ResetPeripheral, 26µs for MTC_InitPeripheral and 392µs

 

 

for MTC_InitSineGen.

Note:

These three functions do not need to be called by the user application, as they are managed

 

by the ACM_Init function.

20/102

AN1904

Library functions per software module

 

 

MTC_EnableMCOutputs

MTC_DisableMCOutputs

Synopsis

#include "mtc.h"

 

void MTC_EnableMCOutputs(void);

 

void MTC_DisableMCOutputs (void);

Description

The purpose of these two functions is to configure the MCOx outputs of the

 

ST7MC.

 

MTC_EnableMCOutputs

 

Enables the MCOx pins to output the PWM signals of the Motor Controller

 

Peripheral. This function must be called to re-start PWM generation after

 

an emergency shutdown (low state on MCES pin).

 

MTC_DisableMCOutputs

 

This function immediately disconnects the MCOx PWM outputs pins from

 

the Motor Controller peripheral. It resets the MOE bit in the MCRA register,

 

thus causing the MCOx pins to be in their reset configuration, as defined in

 

the options bytes (high impedance or low impedance high/low state).

Duration

2.15 µs

See also

ST7MC Datasheet: MTC chapter.

21/102

Library functions per software module

AN1904

 

 

MTC_CheckEmergencyStop

MTC_ClearEmergencyStop

Synopsis

#include "mtc.h"

 

BOOL MTC_CheckEmergencyStop(void);

 

void MTC_ClearEmergencyStop(void);

Description

The purpose of these two functions is to provide to the higher level control

 

modules information regarding an Emergency Stop of the PWM operation.

 

This information is returned by a function call once the related interrupt

 

routine has been serviced. For users requiring immediate action taken as

 

soon as the NMCES event occurs, the interrupt routine needs to be used

 

directly (see MCES_SE_IT on page 36).

 

MTC_CheckEmergencyStop

 

Indicates if PWM outputs are enabled or not, and therefore if MOE bit

 

(Main Output Enable) has been cleared by hardware, upon Emergency

 

Stop event.

 

MTC_ClearEmergencyStop

 

Resets the boolean where the emergency Stop interrupt routine execution

 

was recorded, regardless of the MOE bit state.

Returns

MTC_CheckEmergencyStop returns a boolean parameter, TRUE if an

 

emergency Stop interrupt has been serviced, causing the PWM outputs to

 

be disabled.

Duration

2.5 µs

See also

ST7MC Datasheet: Motor Controller section, Emergency feature section.

 

MCES_SE_IT on page 36.

22/102

AN1904

Library functions per software module

 

 

MTC_StartBraking

Synopsis

#include "mtc.h"

 

void MTC_StartBraking(u16 DutyCycle);

Description

The purpose of this function is to start the braking sequence by initializing

 

the brake related flags, stopping the PWM interrupts generation, disabling

 

the PWM outputs and starting the timebase needed for stator

 

demagnetization. It also set the sine wave voltage to zero in case the

 

braking sequence is interrupted and sine wave generation is re-started.

 

Braking is obtained by sinking DC current in one motor winding. The

 

braking torque is also defined in this function, in direct relation with the duty

 

cycle applied to one of the motor winding, the other two phases being

 

grounded (low side switches continuously ON).

Input

Duty cycle value is entered as a u16 variable without unit: to get the

 

applied duty cycle, the value has to be compared to the CMP0 register

 

value, defining the PWM frequency.

 

For instance, for a PWM frequency of 12.5kHz, CMP0 = 639 (refer to the

 

Section for details). If the DutyCycle variable is set to 32, this will lead to

 

an applied duty cycle of 32/(639+1) = 10% (with center-aligned patterns).

 

As the AC motor is driven in voltage mode, there’s no way to define a

 

relationship between this duty cycle, the braking torque and the current

 

feed in the motor. This duty cycle will therefore have to be defined

 

empirically.

Functions called MTC_UpdateSine, MTC_DisableMCOutputs, ART_SetSequenceDuration.

Duration

70 µs

See also

MTC_Brake, MTC_StopBraking, flowchart on A.1.6 on page 95,

 

Section 5.4 on page 84 and Section on page 45 for timings set-up.

23/102

Library functions per software module

AN1904

 

 

MTC_Brake

Synopsis

#include "mtc.h"

 

void MTC_Brake(void);

Description

The purpose of this function is to handle the three phases of the braking

 

sequence, as represented below in Figure 9

1.A waiting time for the Stator current to decrease down to zero (demagnetization), all PWM being OFF.

2.A smooth DC current increase up to expected value to avoid inrush current in the stator.

3.The sustaining of this current permanently up to the MTC_StopBraking function call.

Figure 9. . Current waveform during brake sequence

Current

 

 

 

Motor running

Rotor

Current

Active brake

 

demag.

settle

 

This function must be called as often as possible (typically from the main loop) to respect the required timings. Once the steady state current is attained, the brake continues permanently, until the MTC_StopBraking function is called.

Caution 1 Independently from software timebase jitter (+/-1ms), the programmed duration may vary depending on the interval between two MTC_Brake function call (the lower the interval, the better the resolution).

Caution 2 If the user stops calling this function, the current will be maintained to its last value (either null during rotor demagnetization or below the final expected value).

Duration

14 µs average

Functions called ART_IsSequenceCompleted, ART_SetSequenceDuration,

 

MTC_EnableMCOutputs, MTC_DisableMCOutputs

See also

MTC_StartBraking, MTC_StopBraking, Section 5.4 on page 84 and Brake

 

on page 45 for timings set-up, flowchart on A.1.7 on page 96.

24/102

AN1904

Library functions per software module

 

 

MTC_StopBraking

Synopsis

#include "mtc.h"

 

void MTC_StopBraking(void);

Description

This function stops the active braking, whatever the current sequence

 

(stator demagnetization, current settle, steady state).

 

It disables the PWM outputs and re-starts the PWM Update interrupts

 

generation.

Duration

41.5 µs

Functions called MTC_DisableMCOutputs

Caution: The PWM outputs are disabled when exiting this function. In order to resume motor operations, it is mandatory to call a start function (ACM_InitSoftStart, ACM_InitSoftStart_OL) or MTC_EnableMCOutputs.

See also

MTC_StartBraking, MTC_Brake, flowchart on A.1.8 on page 96

25/102

Library functions per software module

AN1904

 

 

MTC_Toggle_Direction

MTC_Set_ClockWise_Direction

MTC_Set_CounterClockWise_Direction

MTC_GetRotationDirection

Synopsis

#include "mtc.h"

 

void MTC_Toggle_Direction(void)

 

void MTC_Set_ClockWise_Direction(void)

 

void MTC_Set_CounterClockWise_Direction(void)

 

Direction_t MTC_GetRotationDirection(void)

Description

These functions are used to set, modify or get indication of the rotating

 

direction. Rotation direction change is achieved by modifying the sign of

 

the variable holding the phase shift between the three phases (either 120°

 

or -120°).

 

The clockwise direction is defined randomly. The real direction will only

 

depend on the physical connection of the motor.

Duration

2.25 µs for MTC_Set_ClockWise_Direction and

 

MTC_Set_CounterClockWise_Direction, 3.5µs for the other two functions.

Returns

The Direction_t type is a public enumerated typedef defined in the mtc.h

 

file: {CLOCKWISE, COUNTERCLOCKWISE}.

Caution: No tests are performed on motor status (running or stopped) inside these functions. You must therefore be sure that motor is stopped before calling any of the three routines

able to modify the rotation direction. On the contrary, if direction is changed while motor is running, it can immediately become generator, thus injecting reactive energy in the high voltage DC bus capacitor, causing the voltage to go above capacitor’s maximum voltage rating.

26/102

AN1904

Library functions per software module

 

 

MTC_GetVoltage

MTC_GetStatorFreq

MTC_GetSlip

 

Synopsis

#include "mtc.h"

 

 

u8 MTC_GetVoltage(void);

 

 

u16 MTC_GetStatorFreq(void);

 

 

u16 MTC_GetSlip(void);

 

Description

MTC_GetVoltage

 

 

This function returns the current modulation index, corresponding to the

 

 

voltage applied on the motor winding.

 

 

MTC_GetStatorFreq

 

 

This function returns the current Stator frequency; if a stator frequency

 

 

update (done in PWM Update interrupt) is on-going after a call to the

 

 

MTC_UpdateSine function and it has not been completed, the previous

 

 

value is returned.

 

 

MTC_GetSlip

 

 

This function returns the difference between the stator and rotor

 

 

frequencies. This value will always be positive (unsigned variable)

 

 

assuming that this software library is not designed to handle negative slip

 

 

operations (i.e. motor used as a generator). However, if the slip is negative,

 

 

the returned value will be zero.

 

Returns

Stator and slip frequencies are given in [0.1Hz] unit using 16-bit format: a

 

 

returned value of 357 corresponds to 35.7Hz.

 

 

The voltage is an 8-bit value; 0 to 100% modulation index is described

 

 

within the 0 to 255 range; 255 corresponds to full voltage.

 

Duration

MTC_GetVoltage: 1.85 µs

 

 

MTC_GetStatorFreq: 3.5 µs

 

 

MTC_GetSlip: 620 µs (including ~20% of CPU time spent in interrupt for

 

 

sine wave generation)

 

See also

MTC_GetRotorFreq, MTC_UpdateSine.

Note:

MTC_GetSlip duration mainly comes from the Rotor speed calculation, done in

 

MTC_GetRotorFreq; if MTC_GetRotorFreq and MTC_GetSlip have to be used in the same

function of your own, it may be interesting to compute the slip directly from the Stator and rotor speed information to spare CPU processing time.

27/102

Library functions per software module

AN1904

 

 

MTC_InitTachoMeasure

MTC_StartTachoFiltering

Synopsis

#include "mtc.h"

 

void MTC_InitTachoMeasure(void);

 

void MTC_StartTachoFiltering(void);

Description

MTC_InitTachoMeasure

 

The purpose of this function is to initialize the flags and variables

 

associated with speed acquisition: the software FIFO stack where the last

 

4 speed acquisitions are stored, the tacho timer clock prescaler and the

 

flag disabling rolling average. Upon completion of this routine,

 

MTC_GetRotorFreq function call will return a speed calculated from the

 

very last tacho capture only.

 

MTC_StartTachoFiltering

 

Once called, this function enables the MTC_GetRotorFreq to return a

 

speed corresponding to the average of the last four captured values. On

 

the tacho event following this function call, the whole software FIFO stack

 

is filled with the latest captured value to start the rolling average with

 

values up to date.

Duration

MTC_InitTachoMeasure: 26 µs

 

MTC_StartTachoFiltering: 2.75 µs

Code example

 

 

...

...

IMC_InitTachoMeasure();/*Must be called before motor start*/

...

/* Start routine */

if (MTC_ValidSpeedInfo(MinRotorFreq))

{

MTC_StartTachoFiltering (); /* Must be called once we

}are sure that we have reliable speed information */

See also

MTC_GetRotorFreq, MTC_ValidSpeedInfo.

28/102

AN1904

Library functions per software module

 

 

MTC_ValidSpeedInfo

Synopsis

#include "mtc.h"

 

BOOL MTC_ValidSpeedInfo (u16 MinRotorFreq);

Description

The purpose of this function is to determine if the motor has actually

 

started and if the rotor speed exceeds a given threshold above which the

 

tachometer can be considered has providing reliable information.

 

Two conditions are evaluated:

 

- If the actual speed is higher than the defined threshold,

 

- If the acceleration is positive: the very last speed captured is higher than

 

the average of the four previous values. This is necessary to discard the

 

parasitic information appearing at the beginning of motor rotation. This

 

spurious tacho events are usually due to the tachogenerator technology,

 

made of winding and magnet; at very low speed, the tacho output signal is

 

in the range of hundreds of mV, with relatively low signal vs noise ratio.

Input

The input parameter is the minimum rotor speed at which the motor is

 

considered as really being started, in tenth of Hz. For instance,

 

MinRotorFreq=105 corresponds to 10.5Hz. The minimum Rotor speed has

 

to be set inside the intrinsically stable tile of the motor’s torque versus

 

frequency characteristic (typically 10-20Hz), keeping in mind that it must

 

not be too high: the higher this value, the bigger will be the stator

 

voltage/current inrush current at start-up.

 

Furthermore it is recommended to set a value as close as possible to the

 

target speed to be reached when exiting the start-up routine to ease the

 

transition to the closed loop speed regulation. If the target frequency is too

 

high, then a ramp function has to be implemented.

Returns

Boolean parameter, TRUE if both the above conditions are verified, FALSE

 

otherwise. The function will also return FALSE if called with the

 

MinRotorPeriod parameter set to 0 (incorrect value).

Duration

88 µs maximum

Caution: There is no way to differentiate rotation directions using a tachogenerator. Take note that this routine may return TRUE in certain conditions, even if the motor is not started in the right direction. In this case, you should manage a minimum amount of time before restarting (for instance with high inertia load). Obviously, this function may be ineffective if the start-up duration is far shorter than time needed to have at least few consecutive speed values.

Functions called MTC_GetRotorFreq, GetAvrgTachoPeriod, GetLastTachoPeriod.

29/102

Library functions per software module

AN1904

 

 

MTC_GetRotorFreq

Synopsis

#include "mtc.h"

 

u16 MTC_GetRotorFreq (void);

Description

The purpose of this function is to provide the rotor rotational frequency. The

 

frequency is calculated using the period between two edges of the sensor

 

signal (typically a tachometer), the [MTIM:MTIML] counter and the MPRSR

 

prescaler.

 

If the MTC_StartTachoFiltering function has been called previously to this

 

function, the rotor frequency is computed as the average of the last four

 

values and the speed value is up-to date whatever the motor speed and

 

the tacho information rate (rolling average). On the contrary, the very last

 

tacho period is used to do the computation; this is of interest during the

 

start-up phase of the motor, when the tachogenerator signal is very weak.

Returns

Rotor frequency with [0.1Hz] unit; for instance a returned value of 357

 

corresponds to rotor mechanical frequency of 35.7Hz

 

If the calculated speed is less than a minimum speed the returned value

 

will be 0. This minimum speed is checked using the MPRSR prescaler

 

value, which is automatically updated (refer to the ST7FMC datasheet for

 

details): if its value is >= MAX_RATIO constant, the returned speed is zero.

 

MAX_RATIO is defined in MTCparam.h; it is set by default to 7: if no tacho

 

edges are detected within a period of 500 ms to 1 second, the motor is

 

considered to be stopped. This time out period depends on the previous

 

value of the MPRSR prescaler: see the equations below.

Figure 10. Time Out duration before having Freq=0, depending on MPRSR value

 

Timeout =

0xFFFF × 27

 

MPRSR=7

 

---------------------------------- = 524ms

 

 

 

16MHz

 

 

Timeout =

0xFFFF ×

25

0xFFFF × 26

0xFFFF × 27

MPRSR=5

--------16MHz----------------------

---- +

---------------------------------- +

---------------------------------- = 917ms

 

 

16MHz

16MHz

 

Note on accuracyWith the 16-bit timer range and its automatically updated prescaler, the accuracy is better than 0.1Hz up to tacho input frequency of 1265Hz. This limit is lowered when having Fmtc below 16MHz.

Duration

560 µs (inc. ~20% CPU time spent in U interrupt for sine generation)

Functions called GetAvrgTachoPeriod, GetLastTachoPeriod.

See also MTC_StartTachoFiltering on page 28, MTC_C_D_IT on page 34, Customization hints in Rotor frequency computation on page 38, flowchart on A.1.3 on page 92

30/102

Loading...
+ 72 hidden pages