ST AN2291 Application note

AN2291
Application note
Sinusoidal control simulink and software library of a PMSM
Introduction
This application note describes a software library for the electric motor control implementing a (SC) Sinusoidal Control on ST10 Microcontrollers.
March 2007 Rev 1 1/36
www.st.com
Contents
1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2 Sinusoidal control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.1 PMSM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.1.1 Mathematical model of the machine . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2.2 Sinusoidal control structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2.3 The Space vector modulation theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
2.3.1 The 3-phase inverter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
2.3.2 The Space vector pulse width modulation . . . . . . . . . . . . . . . . . . . . . . . 14
3 EMSC simulink library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.1 Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.2 Using the simulink library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.2.1 How to install simulink library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.2.2 Test environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.3 Parameters format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
3.4 PI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
3.4.1 Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
3.4.2 Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
3.4.3 Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
3.4.4 Simulink block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
3.4.5 Test case . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
3.5 Phase advance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
3.5.1 Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
3.5.2 Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
3.5.3 Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
3.5.4 Simulink block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
3.5.5 Test case . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
3.6 Space vector modulation look up table . . . . . . . . . . . . . . . . . . . . . . . . . . 21
3.6.1 Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
3.6.2 Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
3.6.3 Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
3.6.4 Simulink block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
2/36
AN2291 Contents
3.6.5 Test case . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
3.7 Rescaling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
3.7.1 Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
3.7.2 Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
3.7.3 Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
3.7.4 Simulink block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
3.7.5 Test case . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
4 Sinusoidal control software library . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
4.1 Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
4.2 Using the software library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
4.2.1 How to install software library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
4.2.2 Tool chain compatibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
4.2.3 Calling a function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
4.2.4 ST10 MAC configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
4.2.5 Real time aspects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
4.2.6 Naming convention . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
4.2.7 Test environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
4.2.8 Sinusoidal control library benchmark . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
4.3 Library functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
4.3.1 PI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
4.3.2 Description: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
4.3.3 Arguments: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
4.3.4 Algorithm: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
4.3.5 Notes: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
4.3.6 Test: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
4.4 Phase advance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
4.4.1 phase_advance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
4.4.2 Description: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
4.4.3 Arguments: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
4.4.4 Algorithm: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
4.4.5 Notes: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
4.4.6 Test: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
4.5 SVM modulation look up table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
4.5.1 SVM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
4.5.2 Description: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
3/36
4.5.3 Arguments: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
4.5.4 Algorithm: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
4.5.5 Notes: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
4.5.6 Test: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
4.6 Rescaling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
4.6.1 rescaling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
4.6.2 Description: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
4.6.3 Arguments: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
4.6.4 Algorithm: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
4.6.5 Notes: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
4.6.6 Test: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
5 C code auto generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
5.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
5.2 Steps to generate optimized C code . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
5.3 Real-Time Workshop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
5.4 How to generate C code using real time workshop . . . . . . . . . . . . . . . . . 31
5.4.1 Step 1 - Simulink schematic constructor . . . . . . . . . . . . . . . . . . . . . . . . 31
5.4.2 Step 2 - Real Time Workshop options configuration . . . . . . . . . . . . . . . 31
5.5 Automatic configuration of RTW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
6 Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
4/36
AN2291 List of tables
List of tables
Table 1. Time frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Table 2. Data representation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Table 3. Sinusoidal Control library capabilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Table 4. Document revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
5/36
List of figures
Figure 1. Vector diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Figure 2. Cross-section of PMSM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Figure 3. Stator current space vector and its components in (a,b,c) . . . . . . . . . . . . . . . . . . . . . . . . 10
Figure 4. Phase motor with 2 pole pair . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Figure 5. Schema of sinusoidal control for PMSM-motor. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Figure 6. 3-phase power inverter scheme. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Figure 7. Space vector diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Figure 8. SVM in the 1
Figure 9. Example of a switching pattern in Sector 1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Figure 10. Simulink library structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Figure 11. PI block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Figure 12. Phase advance block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Figure 13. SVM block. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Figure 14. Rescaling block. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Figure 15. File structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Figure 16. Flow chart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Figure 17. Configuration parameter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
Figure 18. Hardware implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
Figure 19. RTW system target file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
Figure 20. Generate HTML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Figure 21. Generate code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
st
sector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
6/36
AN2291 Introduction

1 Introduction

This document describes a simulink and software library for the electric motor control implementing a (EMSC) Sinusoidal Control targeted to ST10 Microcontrollers.
The library consists of:
Simulink Library;
C optimized Software Library;
ASM optimized Software Library.
The EMSC Simulink Library is a set of Simulink blocks for implementing in Matlab-Simulink environment the functions and the algorithms used in the electric motor control. These blocks can be used either to conceive and to test new electric motor controls and to produce automatic generated code in ANSI C, downloadable on microcontroller.
The Software Library is a set of routines for the electric motor control obtained from the code generated in automatic, by Real Time Workshop Embedded Coder, starting from EMSC Simulink library blocks, and then optimized in C and Assembler.
The SC software library for ST10 is fully compatible with SC simulink library.
This document begins with an introduction on Sinusoidal Control, the permanent magnet synchronous machine (PMSM) and a short description of its mathematical model. Then, it describes the Sinusoidal Control implementation on Simulink and details the space vector modulation (SVM) technique and the used algorithm.
After the technical introduction, the EMSC Simulink Library is described, followed by the Software Library.
7/36

2 Sinusoidal control

The Sinusoidal Control is a control strategy, characterized by sinusoidal waveforms so as to drive the three motor windings with currents that vary smoothly and sinusoidally, obtaining a negligible torque ripple and improved high-torque characteristics at both low and high speeds compared with other control strategies.
In order to generate a smooth sinusoidal modulation as the motor works, it is necessary an accurate rotor position feedback from a sensor, as encoder or similar devices.
The position information is used to synthesize three modulation signals shifted by 120° degrees each other then multiplied by the command signal provided as output of a PI controller. These signals are used to feed the motor windings with the three voltages, proportional to desired command signal and appropriately phased, through a voltage source inverter (VSI).
There are three basic methods to control the voltage vector direction, each with different advantages and requests of measurement:
1. Vector of stator voltage is placed 90° relative to the vector of rotor permanent magnet flux;
2. Vector of stator current is placed 90° relative to the vector of rotor permanent magnet flux;
3. Voltage vector is kept in the direction of the current vector.garte06
Figure 1 shows the vector diagram of each control strategy:

Figure 1. Vector diagram

1)
Us space vector of stator voltage Is space vector of stator current
Ys space vector of stator flux Yr space vector of rotor flux Y space vector of magnetic flux E space vector of back emf Rs stator resistance w angular rotor speed
2)
8/36
AN2291 Sinusoidal control
In Figure 5, the control of the motor speed forces the amplitude of the voltage vector obtained in output from the PI controller starting from the speed error while an offset is added to the actual rotor position in order to keep the voltage space vector in a desired position respect to the rotor flux space vector.

2.1 PMSM

The necessity of reducing the charge of the combustion engine and of eliminating the weight due to the mechanical connections in several applications, like in automotive field, induces to use more and more electric motors, that assure a wide range in speed and torque control satisfying the load demand.
The DC machine fulfils these requirements but needs periodic maintenance.
The AC machine, like induction motor and brushless permanent magnet motor, hasn’t brushes, and its rotor is more robust because there aren’t commutator and/or rings. That means a very low maintenance, other than increases the power-to-weight ratio and efficiency.
In particular, in the automotive field the Permanent Magnet Synchronous Machine (PMSM) seems to be the best solution.
The brushless permanent magnet motors (PMSMs) have the same electromagnetic structure of a synchronous machine, without the brushes. As shown in the cross-section in the below Figure 2, they have a wound stator, similar to an induction machine, and a rotor with some permanent magnets instead of a wound rotor fed with DC current like the one that is used in the classical synchronous machines. Besides, they need of an internal or external device for sensing of the rotor position, like Hall sensors, encoder or resolver.

Figure 2. Cross-section of PMSM

The PMSMs are not self-commuting motors and to produce useful torque, the currents and the voltages applied to stator phases must be controlled as a function of rotor position. Therefore it is generally required to count the rotor position with a sensor so that the inverter phases which feed it, acting at any time, are commuted depending on the rotor position.
That explains the necessity of a closed-loop speed/position feedback.
9/36
There are two kinds of brushless permanent magnet machines classifiable in account of the shape of the BEMF (back-electromagnetic force):
DC brushless machine having trapezoidal flux distribution and a trapezoidal BEMF fed
by quasi-square wave currents;
AC brushless machine having approximately sinusoidal air-gap flux density and a
quasi-sinusoidal BEMF fed by sinusoidal stator currents.
Generally the DC brushless machines have a simpler control strategy than AC brushless machines.
For trapezoidal flux distributions, to impose quasi-square wave currents on stator windings, it is only needed a six position sensor, with a resolution of at least 60 electrical degrees.
On the contrary, for the sinusoidal current type, the angular position needs to be known with a very accurate precision in order to control each of the three phases currents.
For each kind, the high reliability control makes this type of machine a powerful system for electric vehicle application.

2.1.1 Mathematical model of the machine

In order to model the fields produced by the stator windings in terms of windings current, “current space vectors” are used. The current space vector for a given winding has the direction of the field produced by that winding and a magnitude proportional to the current through the winding. This allows us to represent the total stator field as a current space vector that is the vector sum of three space vector components, one for each of the stator windings.
The three-phase voltage, currents and fluxes of AC motors can be analyzed in terms of complex space vectors.
For instance, with regard to the currents in the stator windings, the current space vector can be defined as follows.
Figure 3. Stator current space vector and its components in (a,b,c)
Assuming tha complex stator current vector
Equation 1 i
t is1,is2,is3 are the instantaneous currents in the stator phases, then the
i
is defined by:
s
2
-- -
3
i
s1is2
s
α is3α2⋅++()=
10/36
AN2291 Sinusoidal control
where α = e
j(2π/3)
and
α
2
= e
j(4π/3)
represent spatial operators. The Figure 3 shows the
stator current complex space vector.
In terms of space vectors it is possible to write the mathematical model of an AC brushless machine in a stator frame, as follows:
Equation 2
u
s
RsisL
di
d
s
---- -
++=
-------
s
dt
dt
jpθ
⎛⎞
ψ
⎝⎠
r
e
f
where:
ψ
f
R
s
L
s
ω
r
p Number of pole pairs
θ
r
and the space vectors:
2
Equation 3
-- -
u
s
3
Modulus of the magnetizing flux-linkage vector
Stator resistance
Total three phase stator inductance
Rotor angular speed
Mechanical position
2π
------ -
⎛⎞
=
t() u2t() e
++
u
⎜⎟
1
⎝⎠
j
3
u3t() e
4π
------ -
j
3
Equation 3 space vector of the stator voltage
Equation 4
2π
------ -
2
t() e
j
3
i
s
3
⎛⎞
2
-- -
i
=
t() i
i
s
⎜⎟
s1
3
⎝⎠
s
t() e
++
4π
------ -
j
3
Equation 4 shows space vector of the stator current
Note: The mechanical position of the electric motors is related to the rotation of the shaft while the
electrical position is relate to the rotation of the rotor magnetic field.
So being the motor with p pole pairs, its rotor needs only to move 360/p mechanical degrees to obtain an identical magnetic configuration as when it started.
Figure 4. Phase motor with 2 pole pair
11/36
Loading...
+ 25 hidden pages