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
REGULATION
AC MOTOR DRIVE
3-PHASE SINE WAVE GENERATION
COMMUNICATION
PROTOCOL
PWMART
WWDG
PORTS
MCO[0..5]
PWM outputs
MTC
ADC
SCI
16-bit
Timer
SPI
Emergency Stop input
Speed feedback
July 2007
Rev 3
1/102
www.st.com
Contents
AN1904
Contents
1
2
Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Working environment set-up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.1
Development tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.1.1
2.1.2
2.1.3
2.1.4
Integrated Development Environments (IDE) . . . . . . . . . . . . . . . . . . . . . 6
Emulators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Programmers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Starter kit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.2
Library source code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.2.1
2.2.2
Download . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
File structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.3
Utilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.3.1
2.3.2
2.3.3
lib.h file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Sine wave look-up table spreadsheet . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
HyperTerminal file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.4
Technical literature . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3
Getting started with the library using the ST7MC-KIT/BLDC . . . . . . . 10
3.1
3.2
3.3
Running the motor with the ST7MC control panel . . . . . . . . . . . . . . . . . . 10
Library configuration file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Customizing the files for your ST7MC derivative . . . . . . . . . . . . . . . . . . . 13
3.3.1
3.3.2
3.3.3
Memory mapping with COSMIC toolchain . . . . . . . . . . . . . . . . . . . . . . . 13
Memory mapping with METROWERKS toolchain . . . . . . . . . . . . . . . . . 14
Hardware registers description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
3.4
How to define and add a C module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
3.4.1
3.4.2
Using STVD7 release 2.5.x . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Using STVD7 release 3.x.x . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
4
Library functions per software module . . . . . . . . . . . . . . . . . . . . . . . . . 18
4.1
4.2
Function description conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Sine wave generation and speed feedback (MTC) . . . . . . . . . . . . . . . . . . 18
4.2.1
4.2.2
Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
List of available functions and interrupt service routines . . . . . . . . . . . . 19
2/102
AN1904
4.2.3
Contents
Detailed explanations and customization of MTCparam.h . . . . . . . . . . . 38
4.3
Induction motor scalar control (ACMOTOR) . . . . . . . . . . . . . . . . . . . . . . . 47
4.3.1
4.3.2
4.3.3
Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
List of available functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
Detailed explanations and customization of ACMparam.h . . . . . . . . . . 58
4.4
Analog to digital converter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
4.4.1
4.4.2
4.4.3
4.4.4
4.4.5
Module description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
Synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
Timing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
Caution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
Customizing the ADC module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
4.5
I/O ports . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
4.5.1
4.5.2
Push button reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
LEDs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
4.6
PWM auto reload timer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
4.6.1
4.6.2
Software timebases working principle . . . . . . . . . . . . . . . . . . . . . . . . . . 74
Timebase use for the AC motor control library and demo program . . . . 75
4.7
Serial communication interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
4.7.1
4.7.2
4.7.3
4.7.4
4.7.5
Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
Changes vs ST7 library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
Customization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
Important notice for hardware implementation . . . . . . . . . . . . . . . . . . . 78
4.8
Nested interrupt controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
5
Running the demo programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
5.1
5.2
5.3
5.4
Open loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
Closed loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
Using the serial communication interface . . . . . . . . . . . . . . . . . . . . . . . . . 83
Mainparam.h file description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
5.4.1
5.4.2
5.4.3
Start-up parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
Brake parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
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
6.2.2
6.2.3
6.2.4
6.2.5
Preliminary notice on debugging tools . . . . . . . . . . . . . . . . . . . . . . . . . . 86
Build step1: open loop, low voltage, no motor connected . . . . . . . . . . . 87
Build step2: open loop, rated voltage/power, motor connected . . . . . . . 88
Build step3: open loop, rated power, motor connected with speed
feedback 88
Build step4: closed loop operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
6.3
Motor control related CPU load in the application . . . . . . . . . . . . . . . . . . 89
6.3.1
6.3.2
Estimation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
Adjustment guidelines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
Appendix A Appendix. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
A.1
Flowcharts. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
A.1.1
A.1.2
A.1.3
A.1.4
A.1.5
A.1.6
A.1.7
A.1.8
A.1.9
A.1.10
A.1.11
MTC_U_CL_SO_IT interrupt routine . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
MTC_C_D_IT interrupt routine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
MTC_GetRotorFreq function. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
GetLastTachoPeriod function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
GetAvrgTachoPeriod function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
MTC_StartBraking function. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
MTC_Brake function state diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
MTC_StopBraking function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
ACM_InitSoftStart function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
ACM_SoftStart function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
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)
Cosmic 5.2b
Closed Loop
Open loop
4943
3840
Metrowerks 1.1
5729
4361
RAM (bytes)
Cosmic 5.2b
136
108
Metrowerks 1.1
161
130
5/102