UM0324
User manual
STR750
AC induction motor IFOC software library V1.0
Introduction
This user manual describes the AC induction motor IFOC software library, an Indirect Field
Oriented Control (IFOC) Firmware Library for 3-phase induction motors developed for the
STR750 microcontroller.
This 32 bit, ARM cored ST microcontroller, comes with a set of peripherals which make it
suitable for performing both permanent magnet and AC induction motors FOC. In particular,
this manual describes the STR750 software library developed to control AC induction
motors equipped with an encoder or tacho-generator, in both open and closed loop. The
control of a permanent magnet (PM) motor in sinewave mode with encoder is described in
the UM0312 User Manual.
The AC IM IFOC software library is made of several C modules, compatible with the IAR
EWARM toolchain. It will allow you to quickly evaluate both the MCU and the available tools.
In addition, when used together with the STR750 motor control starter kit (STR750-MCKIT)
and an AC induction motor, you will be able to get a motor running in a very short time. It
also eliminates the need for time-consuming development of IFOC and speed regulation
algorithms by providing ready-to-use functions that let you concentrate on the application
layer.
A prerequisite for using this library is basic knowledge of C programming, AC motor drives
and power inverter hardware. In-depth know-how of STR750 functions is only required for
customizing existing modules and for adding new ones for a complete application
development.
The figure below shows the architecture of the firmware. It uses the STR750 Standard
Library extensively but it also acts directly on hardware peripherals when optimizations in
terms of execution speed or code size are required.
February 2007
Rev 1
1/105
www.st.com
UM0324
AC IM IFOC software library V1.0 features (CPU running at
60MHz)
●
Speed feedback:
–
–
Tacho generator
Quadrature incremental encoder
2 isolated current sensors (ICS)
3-shunt resistors placed on the bottom of the three inverter legs
PIDs sampling frequency adjustable up to the PWM frequency.
Open loop operation
Closed loop operation, PID regulation with 0.5ms to 127ms sampling time
PWM frequency can be easily adjusted
Centered PWM pattern type
11 bits resolution at 14.6Khz
●
Current sampling method:
–
–
●
●
Current regulation for torque and flux control:
–
–
–
Speed control:
●
16-bit space vector PWM generation frequencies:
–
–
–
●
●
●
●
Free C source code and spreadsheet for look-up tables
CPU load below 30% (IFOC algorithm refresh frequency 8KHz)
Motor control modules developed in accordance with MISRA C rules
Code size 22.8KB (three shunt resistors for current reading, tacho generator for speed
feedback) + 8.2KB for LCD/joystick management
Note:
These figures are for information only; this software library may be subject to changes
depending on the final application and peripheral resources. Note that it was built using
robustness-oriented structures, thus preventing the speed or code size from being fully
optimized.
Related documents:
Available on
www.st.com:
●
●
●
●
STR750 User Manual,
STR750 Datasheet,
STR750 Standard Library User Manual,
STR7 Flash Programming Manual
Available on
www.arm.com:
ARM7TDMI-S Rev.4 Technical Reference Manual ARM DDI 0234A
2/105
UM0324
Contents
Contents
1
Getting started with tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
1.1
1.2
1.3
Working environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Software tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Library source code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
1.3.1
1.3.2
1.3.3
Download . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
File structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Starting the IAR toolchain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
1.4
Customizing the workspace for your STR750X derivative . . . . . . . . . . . . 13
1.4.1
1.4.2
Inkarm_xxx.xcl
file (internal/external flash or RAM based project) 13
Extended linker file setting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
2
Getting started with the library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
2.1
2.2
Introduction to AC induction motor FOC drive . . . . . . . . . . . . . . . . . . . . . 16
How to customize hardware and software parameters . . . . . . . . . . . . . . 17
2.2.1
2.2.2
Library configuration file:
75x_MCconf.h
. . . . . . . . . . . . . . . . . . . . . . . 18
Drive control parameters:
MC_Control_Param.h
. . . . . . . . . . . . . . . . 19
Power device control parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .19
Flux and torque PID regulators sampling rate . . . . . . . . . . . . . . . . . . . . . . . . . . .19
Speed regulation loop frequency . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .19
Speed controller setpoint and PID constants (initial values) . . . . . . . . . . . . . . . .20
Torque and flux controller setpoints and PID constants . . . . . . . . . . . . . . . . . . . .20
Start-up torque ramp parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .21
Linear variation of PID constants according to mechanical speed. . . . . . . . . . . .21
2.2.3
2.2.4
2.2.5
Incremental encoder parameters:
MC_encoder_param.h
. . . . . . . . . 21
Tachogenerator parameters:
MC_tacho_prm.h
. . . . . . . . . . . . . . . . . . 21
AC induction motor parameters:
MC_ACmotor_param.h
. . . . . . . . . . 23
2.3
How to define and add a c module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
3
Running the demo program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
3.1
3.2
3.3
Open loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Closed loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Setting up the system when using ICS sensors . . . . . . . . . . . . . . . . . . . . 30
3.3.1
3.3.2
Connecting the two ICS sensors to the motor and to STR750 . . . . . . . 31
Selecting PHASE_A_CHANNEL and PHASE_B_CHANNEL . . . . . . . . 31
3/105
Contents
UM0324
3.4
3.5
3.6
How to build the system when using an incremental encoder . . . . . . . . . 32
Fault messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Note on debugging tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
4
Library functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
4.1
4.2
Function description conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
Current reading in three shunt resistor topology and space vector PWM
generation:
75x_svpwm_3shunt
module . . . . . . . . . . . . . . . . . . . . . . . . 35
4.2.1
4.2.2
Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
List of available functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
SVPWM_3ShuntInit
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .36
SVPWM_3ShuntCurrentReadingCalibration
. . . . . . . . . . . . . . . . . . . . . . .37
SVPWM_3ShuntGetPhaseCurrentValues
. . . . . . . . . . . . . . . . . . . . . . . . . . .37
SVPWM_3ShuntCalcDutyCycles
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .38
SVPWM_3ShuntGPADCConfig
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .38
4.2.3
4.2.4
4.2.5
Space vector PWM implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Current sampling in three shunt topology and general purpose A/D
conversions
41
Tuning delay parameters and sampling stator currents in three shunt
resistor topology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Case 1: Duty cycle applied to Phase A low side switch is larger than
DT+TN+ 2TS + TH + TDMA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .44
Case 2: DT+TN+TS < Phase A duty cycle < DT+TN+ 2TS + TH + TDMA. . . . . .46
Case 3: Phase A pulse width < DT+TN+TS . . . . . . . . . . . . . . . . . . . . . . . . . . . . .48
4.3
Isolated current sensor reading and space vector PWM generation:
75x_svpwm_ICS module
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
4.3.1
4.3.2
Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
List of available functions and interrupt service routines . . . . . . . . . . . . 52
SVPWM_IcsInit
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .53
SVPWM_IcsCurrentReadingCalibration
. . . . . . . . . . . . . . . . . . . . . . . . . .53
SVPWM_IcsGetPhaseCurrentValues
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .54
SVPWM_IcsCalcDutyCycles
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .54
4.3.3
Current sampling in isolated current sensor topology and integrating
general purpose A/D conversions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
4.4
Induction motor IFOC vector control:
MC_IFOC_Drive.c
module . . . . . 55
4.4.1
4.4.2
Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
List of available C functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
IFOC_Init . . . . . . . . . . . . . . . . . . . . . . . . 56
IFOC_Model
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .57
IFOC_CalcFluxTorqueRef
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .59
4/105
UM0324
Contents
CalcIm.
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .60
CalcRotFlxSlipFreq.
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .61
4.4.3
4.4.4
Detailed explanation about indirect field oriented control (IFOC) . . . . . 61
Detailed explanation about field weakening operation . . . . . . . . . . . . . . 63
4.5
Reference frame transformations:
MC_Clarke_Park.h
module . . . . . . 65
4.5.1
4.5.2
Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
List of available C functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
Clarke.
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .66
Park
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .67
Rev_Park
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .67
Rev_Park_Circle_Limitation
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .68
4.5.3
4.5.4
Detailed explanation about reference frame transformations . . . . . . . . 68
Circle limitation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
4.6
Encoder feedback processing:
75x_encoder.c module
. . . . . . . . . . . 72
4.6.1
List of available functions and interrupt service routines . . . . . . . . . . . . 72
ENC_Init . . . . . . . . . . . . . . . . . . . . . . . . . 72
ENC_GetPosition . . . . . . . . . . . . . . . . . . . . . 73
ENC_Get_Electrical_Angle . . . . . . . . . . . . . . . . . 73
ENC_Get_Mechanical_Angle . . . . . . . . . . . . . . . . . 73
ENC_ResetEncoder . . . . . . . . . . . . . . . . . . . . . 74
ENC_Clear_Speed_Buffer . . . . . . . . . . . . . . . . . . 74
ENC_Get_Speed . . . . . . . . . . . . . . . . . . . . . . 74
ENC_Get_Average_Speed . . . . . . . . . . . . . . . . . . 75
TIMx_UP_IRQHandler
- interrupt routine . . . . . . . . . . . . . . . . . . . . . . . . . . . . .75
4.7
Tachogenerator feedback processing:
75x_tacho.c
module . . . . . . . . 76
4.7.1
List of available functions and interrupt service routines . . . . . . . . . . . . 76
TAC_TachoTimerInit . . . . . . . . . . . . . . . . . . . . 76
TAC_InitTachoMeasure . . . . . . . . . . . . . . . . . . . 77
TAC_GetRotorFreqInHz . . . . . . . . . . . . . . . . . . . 77
TAC_GetRotorFreq . . . . . . . . . . . . . . . . . . . . . 78
GetLastTachoPeriod . . . . . . . . . . . . . . . . . . . . 78
GetAvrgTachoPeriod . . . . . . . . . . . . . . . . . . . . 78
TAC_IsTimedOut . . . . . . . . . . . . . . . . . . . . . . 79
TAC_ClrTimeOut . . . . . . . . . . . . . . . . . . . . . . 79
TAC_GetCaptCounter . . . . . . . . . . . . . . . . . . . . 79
TAC_ClrCaptCounter . . . . . . . . . . . . . . . . . . . . 80
TAC_StartTachoFiltering . . . . . . . . . . . . . . . . . 80
TAC_ValidSpeedInfo . . . . . . . . . . . . . . . . . . . . 80
TIMx_IC12_IRQHandler . . . . . . . . . . . . . . . . . . . 81
TIMx_UP_IRQHandler . . . . . . . . . . . . . . . . . . . . 81
5/105