XE166 Family AP16165 XE166 Sensorless Fieldoriented Control Microcontrollers Application Note V 1.0, 2009-07
XE166 Family
AP16165XE166 Sensorless Fieldor iented Control
Microcontrol lers
Appl icat ion NoteV 1.0, 2009-07
Edition 2009-07Published byInfineon Technologies AG81726 Munich, Germany© 2009 Infineon Technologies AGAll Rights Reserved.
LEGAL DISCLAIMERTHE INFORMATION GIVEN IN THIS APPLICATION NOTE IS GIVEN AS A HINT FOR THE IMPLEMENTATION OF THE INFINEON TECHNOLOGIES COMPONENT ONLY AND SHALL NOT BE REGARDED AS ANY DESCRIPTION OR WARRANTY OF A CERTAIN FUNCTIONALITY, CONDITION OR QUALITY OF THE INFINEON TECHNOLOGIES COMPONENT. THE RECIPIENT OF THIS APPLICATION NOTE MUST VERIFY ANY FUNCTION DESCRIBED HEREIN IN THE REAL APPLICATION. INFINEON TECHNOLOGIES HEREBY DISCLAIMS ANY AND ALL WARRANTIES AND LIABILITIES OF ANY KIND (INCLUDING WITHOUT LIMITATION WARRANTIES OF NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS OF ANY THIRD PARTY) WITH RESPECT TO ANY AND ALL INFORMATION GIVEN IN THIS APPLICATION NOTE.
InformationFor further information on technology, delivery terms and conditions and prices, please contact the nearest Infineon Technologies Office (www.infineon.com).
WarningsDue to technical requirements, components may contain dangerous substances. For information on the types in question, please contact the nearest Infineon Technologies Office.Infineon Technologies components may be used in life-support devices or systems only with the express written approval of Infineon Technologies, if a failure of such components can reasonably be expected to cause the failure of that life-support device or system or to affect the safety or effectiveness of that device or system. Life support devices or systems are intended to be implanted in the human body or to support and/or maintain and sustain and/or protect human life. If they fail, it is reasonable to assume that the health of the user or other persons may be endangered.
AP16165XE166 Sensorless Fieldoriented Control
Application Note 3 V 1.0, 2009-07
Trademarks
XE164Revision History: V 1.0 2009-07Previous Version(s):Page Subjects (major changes since last revision)� This is the first release �
We Listen to Your CommentsIs there any information in this document that you feel is wrong, unclear or missing? Your feedback will help us tocontinuously improve the quality of this document. Please send your proposal (including a reference to this document) to:[email protected]
AP16165XE166 Sensorless Fieldoriented Control
1 Target Market and Motivation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2 Theory of Sensorless Field Oriented Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42.1 DC Motor Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42.1.1 Open Loop Voltage Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42.1.2 Closed Loop Torque Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52.1.3 Closed Loop Speed and Torque Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52.1.4 List of Equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62.2 Space Vector Modulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62.2.1 Reference Vector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82.3 Phase Current Measurement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92.3.1 Limitations of Phase Current Reconstruction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102.4 FOC Calculations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112.4.1 Stationary and Rotating Reference Frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112.4.2 Sensorless FOC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3 Implementation of a Sensorless FOC using the XE164 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153.1 System Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173.2 GPT12 Timer 5 - Oscilloscope Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183.3 GPT12 Timer 6 - Statemachine and Scheduler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183.3.1 IDLE State . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203.3.2 STOP State . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203.3.3 Ramp-down State . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203.3.4 Emergency Stop State . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213.4 CAPCOM2 Timer 7 - Motor Ramp function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213.4.1 Bootstrapping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223.4.2 Motor Ramp-up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223.4.3 Running state . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233.4.4 Motor RAMP-down . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233.5 CAPCOM60 Timer 12 and Timer 13 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233.5.1 CAPCOM60 Timer 12 interrupt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243.6 ADC0 Result Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243.6.1 DC Link Shunt Measurements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243.6.2 VDC and Poti . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253.7 Interrupt Level . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253.8 Variable Definition and Administration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263.9 DAvE Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
4 Communication Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274.1 MultiCAN Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274.1.1 Program Flow XE164 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274.1.2 Command Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 284.1.3 Receiving a CAN Message and Command Execution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 284.1.4 Transmitting a CAN Message . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 284.1.5 Command SET . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 284.1.6 Command GET . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 294.1.7 Button Start, Stop, Ramp Down . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 304.1.8 Scope Buttons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 304.1.9 Oscilloscope and Progress Bar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 304.1.10 Status Flags and Display Fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
5 How to Use the Setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325.1 Excel Sheet and defines.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325.2 Drive Monitor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Application Note 1 V 1.0, 2009-07
AP16165XE166 Sensorless Fieldoriented Control
5.2.1 Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 335.2.2 Monitoring the Startup Behavior . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 335.2.3 Monitoring the Runtime Behavior . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 355.2.4 Special tricks - Field Weakening . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
6 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Application Note 2 V 1.0, 2009-07
AP16165XE166 Sensorless Fieldoriented Control
Target Market and Motivation
Application Note 3 V 1.0, 2009-07
1 Target Market and MotivationThe Field Oriented Control (FOC) method described in this document is aimed at the target market for costsensitive drives, such as fans, pumps, compressors and geared motors.One driving factor for a sensorless FOC on BLDC or PMSM is decreasing the system cost: sensors can generateproblems in manufacturing and reliability, they require special wiring harnesses and connectors which increasethe overall system cost. The other driving factor is the significant improvement of energy efficiency of a motor. With FOC you can bring theefficiency up to 95%. This has a big impact on power consumption, motor dynamics, heat dissipation and noise.As an example fans and pumps in a lot of applications must operate very silently, otherwise the produced solid-borne sound distributes in water or air pipes within the whole building. Usually this leads to concepts with sinusoidal currents in the motor coils. The zero-crossing technique for positiondetecion of BLDC motors does not work, because block-type currents generate audible noise. Therefore the discussed FOC method solves the two obstacles at once:- no need for a hall sensor or any other sensor type- sinusoidal current shape for very efficient and quiet operation.
Figure 1 Target applications for Sensorless FOC
The limitation of the described methods is the single shunt current measurement which cannot guarantee a steadycontrol under all circumstances. Thus the method is not suitable for high dynamic loads and positioning systems.Of course the algorithm can be adapted to 3-phase-shunt measurement which does not have this limitation.
AP16165XE166 Sensorless Fieldoriented Control
Theory of Sensorless Field Oriented Control
2 Theory of Sensorless Field Oriented ControlThis chapter is intended to give an overview about the theory of the sensorless Field Oriented Control (FOC) ofpermanent magnet syncronuous motors (PMSM). The control scheme which has been implemented at XC878 andXE164 is based on this theory. The implementation details are described in Chapter 3. Before describing the FOC theory in detail, we begin some background information on motor control.
2.1 DC Motor ControlThe DC motor consists of a permanent magnet which builds the stator and a coil mounted at the rotor. Amechanical commutator is needed in order to feed the current to the coils. This commutator will cause the currentto be oriented according to the field of the permanent magnets at the stator.
Figure 2 DC Motor
The DC Motor is controlled by the voltage at the rotor coils and the current is proportional to the torque of the motor.The speed of the motor depends on the voltage and the torque.The nominal speed (ωnom) and torque (mnom) are defined in the following equations:
(1)
(2)
The time constants of speed and current control are very different. A control cascade structure for speed andcurrent control can be utilized.
2.1.1 Open Loop Voltage ControlIn an open loop voltage control, there is just a reference voltage which will cause the power inverter to generatea given voltage at the motor. The mechanical load influences the speed and the current of the DC motor.
Figure 3 Open Loop Voltage Control
ωnomv i R⋅�
Kc-------------------=
mnom Kc i⋅=
Vref Power Stage
DC Motor
V
Application Note 4 V 1.0, 2009-07
AP16165XE166 Sensorless Fieldoriented Control
Theory of Sensorless Field Oriented Control
In steady state, the torque can be described as follows:
(3)
2.1.2 Closed Loop Torque ControlThe torque control loop requires the measurement of the motor current with a current sensor; e.g. a shunt resistor. In general, the torque is proportional to the current.
(4)
As a result, a PI controller can be used for current control. The actual current, measured by the current sensor willbe controlled to converge to the reference current. This can be done only by changing the reference Voltage (Vref)of the power stage. Please see following figure for details:
Figure 4 Closed Loop Torque Control
2.1.3 Closed Loop Speed and Torque ControlFor a speed controlled DC motor, a cascaded control structure can be used, because the speed changerequirement is much slower than the one for the current. The speed control requires a speed sensor; e.g. atachometer and the current control requires a current sensor. The output of the speed control is the referencecurrent for the current control. Usually a PI controller is used for speed and current control.
Figure 5 Cascaded Speed and Current Control
mstat Kcv Kcωstat�
R--------------------------⋅=
mm Kc i⋅=
Current Control
Vref
-
Power Stage
mload
I
DC Motor
eI+ V
Current Sensor
Iref
Iact
Current Control
VrefSpeed Control -
+-
ωref Power Stage
mload
ω
I
DC Motor
eI+ Veω
Current Sensor
Speed Sensor
Iref
ωact
Iact
Application Note 5 V 1.0, 2009-07
AP16165XE166 Sensorless Fieldoriented Control
Theory of Sensorless Field Oriented Control
2.1.4 List of EquationsThe mechanical and electrical equations of the DC motor are valid for the Permanent Magnet Synchronous Motor(PMSM) as well. In the following, a set of equations is listed, which will be used later in this application note.
Voltage Equation:
(5)
Induced Voltage:
(6)
Mechanical Friction:
(7)
Mechanical Equation:
(8)
Angle:
(9)
Speed in revolutions per minute (rpm):
(10)
2.2 Space Vector ModulationIn this section, the modulation of a three leg voltage source inverter is described. This type of inverter contains sixMOSFETs or IGBTs which act as switches. The switches connected to the positive supply rail are called high sideswitches (hs) and the switches connected to the negative rail of the power supply are called low side switches (ls).In the following figure, a block diagram of a three leg voltage source inverter can be seen:
Figure 6 Three Leg Voltage Source Inverter
By switching the high side and low side switches on and off, there are eight states possible, which do not causecross currents inside the leg itself, but allow a current flowing to and back from the motor.
Ltd
di R i⋅+⋅ v vbemf�=
vbemf Kc Ψ ω⋅ ⋅=
mFriction rFriction ω⋅=
J tddω⋅ mm mLoad mFriction��=
ϕ ω td∫=
n 60 ω2π------⋅=
-
+
VDC U
W
VU V W
hs
ls
N
Application Note 6 V 1.0, 2009-07
AP16165XE166 Sensorless Fieldoriented Control
Theory of Sensorless Field Oriented Control
The states can be seen as vectors in the space vector diagram of the coordinates U, V and W. There are six activeand two passive vectors. The space vector diagram of a U-V-W system contains six sectors (A, B, C, D, E, F).
Figure 7 Space Vector Diagram of a U-V-W System
The magnetic field (flux) of a three phase PMSM can be represented in a U-V-W space vector diagram. InFigure 7, the flux is simplified by a magnetic dipole. Whereas the stator coils are fixed in their position, the fluxrotates dependent on the sector of the hexagon.In this case, the voltages at the three coils correspond to the values of U, V and W. The resulting vectorcorresponds to the flux of the stator coils.
Figure 8 Space Vectors in Complex Numbers
State Uhs Uls Vhs Vls Whs Wls
000 (passive) OFF ON OFF ON OFF ON100 (active) ON OFF OFF ON OFF ON110 (active) ON OFF ON OFF OFF ON010 (active) OFF ON ON OFF OFF ON011 (active) OFF ON ON OFF ON OFF
001 (active) OFF ON OFF ON ON OFF
101 (active) ON OFF OFF ON ON OFF
111 (passive) ON OFF ON OFF ON OFF
AB
CD
EF
[100][011]
[010 ]
[101]
[110
]
[001
]
N
S
N
SN
S
N
S
N
SN
S
U
V
W
0j
UU evV ⋅=
WVU VVVV ++=
π32j
VV evV ⋅=
π34j
WW evV ⋅=
ππ 34
32
0 j
W
j
V
j
U evevevV ⋅+⋅+⋅=
Scaling:vU = 2/3 VU
vV = 2/3 VV
vW = 2/3 VW
The maximum length of the space vector is:|V|max = VDC
Application Note 7 V 1.0, 2009-07
AP16165XE166 Sensorless Fieldoriented Control
Theory of Sensorless Field Oriented Control
2.2.1 Reference VectorThe reference vector Vref represents the resulting magnetic stator field (flux). It is defined by the following equation:
(11)
It is rotating in space with the speed ω :
(12)
The reference vector can be approximated by two active vectors (e.g. V1 and V2) and one zero vector (V0). Theplane is dissected into six sectors and the angle ϕ is transformed into the relative angle γrel.
Figure 9 Reference Vector Approximation
Taking into account the scaling of the reference vector and expressing the complex numbers in polar coordinates,the following equations are valid for the PWM on-time of a space vector modulation:
(15)
(16)
(17)
The design of the switching sequence depends on the application requirements. Usually the number of switchingsis minimized, in order to reduce switching losses to a minimum.The following figure shows a seven segment switching sequence:
Figure 10 PWM Pattern of a Seven Segment Switching Sequence
Vref Vref ejϕ⋅=
ω 2π f⋅=
AB
CD
EF
[100]
[110
]
γrel
22 VT
T
s⋅
11 VT
T
s⋅
refV
1V
2V
Sampling Period Ts:
(13)
Volt-Second Balancing:
(14)
Ts T1 T2 T0+ +=
Vref Ts⋅ V1 T1 V2 T2 V0 T0⋅+⋅+⋅=
T13 Ts Vref⋅ ⋅
VDC------------------------------- π
3--- γrel� sin=
T23 Ts Vref⋅ ⋅
VDC------------------------------- γrel( )sin=
T0 Ts T1� T2�=
t
TPWM
VU
t
VV
VW
T0/4 T1/2 T2/2 T0/2 T2/2 T1/2 T0/4
[100][000] [110] [100][110] [000][111]
Application Note 8 V 1.0, 2009-07
AP16165XE166 Sensorless Fieldoriented Control
Theory of Sensorless Field Oriented Control
The output voltage of each leg to neutral is shown in Figure 11.
Figure 11 Output Voltage of Space Vector Modulation
The voltages VUV, VUW and VVW at the motor are sinusoidal.
2.3 Phase Current MeasurementFor many motor control schemes, the phase currents are required as input values. A cost efficient method requiresonly one shunt in the DClink. Two phase currents can be reconstructed from the DClink current (IDClink) during onePWM period (TPWM). The third phase current can be calculated by IU + IV + IW = 0, but is redundant for the control.
Figure 12 Phase Current Measurement within the PWM Pattern
In order to realize this method, the ADC trigger points must be adjusted according to the PWM pattern. Twodifferent currents can be measured at PWM time T1 and T2. Depending on the actual sector, the measuredcurrents have a different meaning. The following table shows these combinations and the calculation for phasecurrent IA and IB.
Sector A B C D E FT1 U V V W W U
T2 -W -W -U -U -V -V
IA = IU U (-W) - V -(-U) -(-U) (-V) - W U
IB = IV (-W) - U V V (-U) - W -(-V) -(-V)
A B C D E F
[100] [110] [010] [011] [001] [101] [100]
VU VV VW
t
IDClin
k
T0/4 T1/2 T2/2 T0/2 T2/2 T1/2 T0/4
t
TPWM
VU
t
t
VV
VW
a b c d f ge
IU I-W IUI-W
Application Note 9 V 1.0, 2009-07
AP16165XE166 Sensorless Fieldoriented Control
Theory of Sensorless Field Oriented Control
2.3.1 Limitations of Phase Current ReconstructionWhen T1 or T2 equals 0, only one phase current can be reconstructed. To avoid this situation, the PWM-times T1and T2 have to be limited to a minimum value. This causes a ripple in the phase-phase voltage and the phasecurrent as well. A very fast ADC is required in order to maximize the performance of phase current reconstruction.The following figure shows the output voltage and phase voltage of a T1-T2-limited space vector modulation.
Figure 13 Distortion in Output and Motor Voltage
Although the output signal is slightly distorted, the most cost efficient method of phase current measuring is thereconstruction from the DClink current via a single shunt. A very fast ADC is required to optimize the systemperformance. A direct trigger from the PWM unit to the ADC reduces CPU load significantly.
0
100
200
300
400
500
600
700
800
0 60 120 180 240 300
V_UN
V_VN
V_WN
-800
-600
-400
-200
0
200
400
600
800
0 60 120 180 240 300
V_UN - V_VN
V_VN - V_WN
V_WN - V_UN
Application Note 10 V 1.0, 2009-07
AP16165XE166 Sensorless Fieldoriented Control
Theory of Sensorless Field Oriented Control
2.4 FOC CalculationsFOC is a method to generate a three phase sinusoidal signal, which can easily be controlled in frequency andamplitude in order to minimize the current and therefore maximize the efficiency. The essential idea is thetransform of three phase signals into two rotor-fix signals and vice versa. In the rotor-fix reference frame, thecurrents are stationary and easy to control. The inverse vector rotation causes the contolled voltages to rotate.
2.4.1 Stationary and Rotating Reference Frames
Figure 14 Stationary and Rotating Reference Frames
The transform from the three phase system to the two phase system is called the Clarke transform. The one fromTwo phase system to the rotating system is called the Park transform. These transfroms are expressed in the following equations.
Clarke Transform
(18)
(19)
(20)
Park Transform
(21)
(22)
A B C D E F
Iα Iβ
Iα
Iβ
IV
IW
IU
A B C D E F
IU IV IW
A B C D E FIq
Id
ϕId
Iq
Three phase 120° reference frameTwo phase reference frameRotating reference frame
iα iU=
iβ13
------- iU 2iV+( )⋅=
iU iV iW+ + 0=
id iα ϕcos iβ ϕsin+=
iq i� α ϕsin iβ ϕcos+=
Application Note 11 V 1.0, 2009-07
AP16165XE166 Sensorless Fieldoriented Control
Theory of Sensorless Field Oriented Control
Inverse Park Transform
(23)
(24)
Figure 15 Summary of Transformations
iα id ϕcos iq ϕsin�=
iβ id ϕsin iq ϕcos+=
IV
IW
θIUIα
Iβ
Id
Iq
Summary Transformations� Clarke transformation is used to remove the
redundancy of the 3 phase system� Park transform provides a rotating d-q-reference
frame � The currents Id and Iq are stationary and easy to
control� The inverse Park transform makes the controlled
voltages rotating
Application Note 12 V 1.0, 2009-07
AP16165XE166 Sensorless Fieldoriented Control
Theory of Sensorless Field Oriented Control
2.4.2 Sensorless FOCThe costs for an encoder or other position sensor can be saved, when the exact position of the rotor is not required.The motor�s back EMF is utilized in order to calculate the rotation angle and rotor position. The back EMF iscalculated in the flux estimator, which is based on the voltage model of the system in the two phase referenceframe. A single shunt is enough to reconstruct the phase currents.
Figure 16 Block Diagram of Sensorless Field Oriented Control
Figure 16 shows the block diagram of the sensorless FOC algorithm. The flux estimator�s input signals are takenfrom the orthogonal two phase stator system with the index α and β. The output signal represents the rotor angle.The motor signals in the two phase stator system (α-β-system) are equivalent to the three phase system. As aresult, an ideal two phase motor can be assumed in the α-β-system. Then there are only two equations tocalculate. The following figure shows the voltage equations of the motor in the α-β-system.
Figure 17 Voltage Equations of Ideal 2-phase Motor
The flux of the stator (Equation (25), Equation (26)) contain the mutual inductance and the flux of the rotorwith the permanent magnet . The stator voltage equations (Equation (27), Equation (28)) contains the resistance of the coil and thederivative of the flux of the stator (Faraday�s Law).
IdPI-controller
IqPI-controller
inverse Park
transformModulator
PWM-Unit
with integrated deadtime control
Vd
Vq
Vα
Vβ
U
V
W
Current Calculation
IDClinkParktransform
Id
Iq
Iα
Iβ
+
+speed
PI-controller
0-
-+-
speedcalculation
ϕω
reference speed
Two-level Voltage Source
Inverter(VSI)
cartesian to
polartransform
θ
|V|
Clarketransform
shuntADC
Flux estimator
α
β
N
S
vsα
isα Rs Ls
-ψp ω sin(ϕ)
ω
ϕ
vsβ
isβ Rs Ls
-ψp ω cos(ϕ )
Flux of stator ψs:
(25)
(26)
Stator Voltage Equation:
(27)
(28)
ψsα L isα ψpα+⋅ L isα ψp ϕ( )cos+⋅= =
ψsβ L isβ ψpβ+⋅ L isβ ψp ϕ( )sin+⋅= =
vsα R isα tddψsα+⋅= R isα L+
tddisα ψp td
dϕ ϕ( )sin�⋅ ⋅=
vsβ R isβ tddψsβ+⋅= R isβ L+
tddisβ ψp td
dϕ ϕ( )cos+⋅ ⋅=
L is⋅ψp
R is⋅
Application Note 13 V 1.0, 2009-07
AP16165XE166 Sensorless Fieldoriented Control
Theory of Sensorless Field Oriented Control
Integrating the voltage equations, we calculate the stator flux as follows:
(29)
(30)
The flux of the rotor and hereby the orientation (angle ϕ) of the permanent magnet of the rotor is calculated byinsertion of Equation (29) in Equation (25) and Equation (30) in Equation (26).
(31)
(32)
(33)
Finally the position of the rotor can be calculated by knowing the resistance R and inductance L of the motor. Thestator voltage vs is derived from the algorithm, and the current is needs to be measured in real-time.
ψsα vsα R isα⋅�( ) td∫=
ψsβ vsβ R isβ⋅�( ) td∫=
ψpα ψsα L isα⋅� vsα R isα⋅�( ) td∫ L isα⋅�= =
ψpβ ψsβ L isβ⋅� vsβ R isβ⋅�( ) td∫ L isβ⋅�= =
ϕψpβψpα--------- atan=
Application Note 14 V 1.0, 2009-07
AP16165XE166 Sensorless Fieldoriented Control
Implementation of a Sensorless FOC using the XE164
3 Implementation of a Sensorless FOC using the XE164Field Oriented Control or vector control is a math technique for controlling brushless dc and ac induction motorsthat reduces motor size, cost and power consumption and is a cousin of flux vector control. This Chapter describes the implementation of a sensorless Field Oriented Control using the Infineon XE164microcontroller. The XE164 Series is a new 100-pin device family of the popular C166 microcontroller architecture.Based on the enhanced C166S V2 architecture, it outperforms existing 16-bit solutions. The 3 PWM units, several timer and two very fast and powerful ADC�s make the XE164 a perfect fit for a varietyof motor control applications.
Figure 18 Block Diagram XE164
This application note makes reference to Infineon's FOC Drive Application Kit (ordering code:KIT_AK_FOCDRIVE_V1). This kit comes with the following hardware:� DriveCard XC878� DriveCard XE164� Low Voltage Inverter (23V-55V, 7.5A)� PMSM motor (15W)� DriveMonitor USB stick� Power supply (24V)
Figure 19 FOC Drive Application Kit
Interrupt Bus
XTALOsc / PLL
Clock Generation
RTC WDT
GPT
T2
T3
T4
T5
T6
CC 2
T7
T8
EBC
XBUS ControlExternal Bus
Control
DPRAM2 KB
DSRAM16 KB
PM
U
DM
U
CPU
MULTI CAN
4Channels
Interrupt & PEC
OCDSDebug Support
ADC08/10-Bit
11Channels
GPIO Ports
SCU
VoltageReset
CC 60
T12
T13
CC 61
T12
T13
CC 62
T12
T13
Peripheral Data Bus
USIC2
64 entry buffer
RS 232,SPI
,LIN,
I²C
chan
nel
0
chan
nel
1
Flash256 KB
Flash256 KB
USIC0
64 entry buffer
RS 232,SPI
,LIN,
I²C
chan
nel
0
chan
nel
1
Flash256 KB
PSRAM64 KB
LX Bus
USIC1
64 entry buffer
RS 232,SPI
,LIN,
I²C
chan
nel
0
chan
nel
1
ADC18/10-Bit
5Channels
C 166 SV 2- Core
MAC Unit
Application Note 15 V 1.0, 2009-07
AP16165XE166 Sensorless Fieldoriented Control
Implementation of a Sensorless FOC using the XE164
The sections which follow describe the FOC implementation on the 16-bit device XE164. The project setup isavailable for the Tasking classic toolchains.The project is DAvE compliant; i.e. the peripheral settings can bechanged or added using DAvE code generator and recompiled afterwards. A MicroSoft Excel sheet can be used for scaling and motor parameter adaptation. The Excel sheet generates thecontents for a header file. The DriveMonitor is used for real-time monitorying of those application variables that are of interest. TheDriveMonitor also offers a control interface to the application. Data is exchanged via the CAN bus.Note: The descriptions in the sections which follow are intended for the advanced user; i.e. some basic knowledge
of the Infineon tool-chain is a prerequisite. Several application notes are available to aid understanding (see Chapter 6), and 'hands-on' training is also offered. Less advanced users are recommended to begin with the DaveDrive auto-code generator.
Application Note 16 V 1.0, 2009-07
AP16165XE166 Sensorless Fieldoriented Control
Implementation of a Sensorless FOC using the XE164
3.1 System OverviewThe Field Oriented Control Application Software uses the Drive Card XE164.
Figure 20 System Block
Figure 21 XE166 Sensorless FOC Block Diagram
Inverter+
HS Driver
LS Driver
*G Rshunt
CCU60
ADC0
CH8
CH15: VDC
CH13: POT
t
TPWMT12
t
T13T13PR
T12PR
CC60SR
CC61SR
CC62SR
pm pm
pmpm
CAPCOM2GPT12
MultiCAN
t
T7T7PR
ofof of
t
T6T6PR
of of
t
T5T5PR
ofof ofof of of
Scheduler
CAN Oscilloscope
M0 Ramp
ResReg0
ResReg1
ResReg7
ResReg6
Node0
MO0
MO1
MO2
MO3
MO4
XE164
LV inverterDrive Card
Carthesian to Polar
Transform
+-
Inverter
1
0
PI
+ymax
ymin
ymax
yminIsT1
x y
PK *64
PI
+ymax
ymin
ymax
yminIsT1
x y
PK *64
PI
+ymax
ymin
ymax
yminIsT1
x y
PK *64
PT1
+-
T1
Ts1 xy
+
HS Driver
LS Driver
*G Rshunt
Vd
Vq
Vα
Vβ
Carthesian to Polar Transform
Θ
|V |
Modulator CCU6E
+-
ADC0RESULT0
RESULT1
Clarke TransformIα
Iβ
Park TransformId
Iq
+-
AB
CD
EF
[100][011]
[010]
[1 01]
[ 110
]
[001
]
N
S
N
SN
S
N
S
N
SN
S
Currentcalc.
phaseAII =α
( )phaseAphaseB III +⋅= 23
1β IphaseB
IphaseA
:1[: s2]
:8[: s0]
*4[* s1]
C
RESULT7
CH8
CH15: VDC
Flux Estimation
+-
+-
+-
+-
xyarctan
x
y
ϕ
iα
vα
iβ
vβ
PT1
+-
TsK
PT1
+-
R TLK ⋅
svm.IphaseA
CH13: POT
svm.IphaseBfoc.Ibeta
foc.Ialpha
foc.Iq
foc.Id
foc.Valpha
foc.Vbeta
foc.Vd
svm.Amplitude
svm.Angle
foc.FluxAngle
foc.Fluxbeta
foc.Fluxalpha
foc.IntegratorA
foc.IntegratorB
control.Filter
control.ActualSpeed
control. ReferenceIq
control.ReferenceSpeed
control.Id
control.Iqcontrol.Speed
control.ReferenceId
ymax
0
Startup control
Speed Calculation
foc.AngleStorefoc.Angle
∆ϕ∆tω =
∆ϕ =
status. control
1
0
foc.Vq
∆ϕ ≥ threshold
foc.AngleSpeedT0
foc.AngleSpeed
foc.Angle
1
00
ϕ + ∆ϕ ⇒ ϕ
ϕ∆ϕ
T1
TsK
TLK ⋅
T1 K = Z1/Z2
T = 1/Z2
K = Z1/Z2T = 1/Z2
t
TPWMT12
t
T13T13PR
T12PR
CC60SR
CC61SR
CC62SR
pm pm
pm
pm
RESULT6
handled in the ADC Interrupts (ADC.c)
R 22 yx +x
y
|V|
foc.FluxAmplitude
x
y
1
0
control. ControlSwitch
Speed Ramp
t
n
SpeedUser
Speed
SpeedRampTime =
control.SpeedRampTime
control.ReferenceSpeed
control.ReferenceSpeedUser
3-phase motor
RL
∆n∆t
foc.AngleSpeedThreshold
V/f control
∆ϕ * slew * 256 + offsetfoc.Vf_offset
foc.Vf_slew
t
n
Threshold
SpeedT 0
startup
Inverse Park
Transform
:4[: s3]
x
y 22 yx +x
y
:1[: s4]
xyarctan
x
y
Application Note 17 V 1.0, 2009-07
AP16165XE166 Sensorless Fieldoriented Control
Implementation of a Sensorless FOC using the XE164
3.2 GPT12 Timer 5 - Oscilloscope DataTimer 5 of the GPT module send the Oscilloscope data every 0.5 millisecond via an interrupt. One message objectis used to send the complete data. The structure is shown in Chapter 4.1.9. The Timer 5 interrupt uses the lowestpriority in the system. The transfer rate of the data can be adapted to the application needs.
3.3 GPT12 Timer 6 - Statemachine and SchedulerThe GPT Timer 6 is configured as a Timer and generates a interrupt every millisecond, which executes thescheduler. The scheduler can be divided into a CAN handler and a statemachine part which handles the wholeFOC application Software. For the FOC implementation a statemachines for Motor 0 is integrated. The schedulerhandles the CAN commands and switches or reset's Statemachine states. Some Statemachine states aretriggered from the CAN handler part of the Scheduler, while some are triggered/switched by other events ormechanisms. Figure 22 show the structure of the scheduler. The Figure 23 show the Statemachine for a singleMotor application.After handling a new CAN command, information is sent to the drive monitor, such as the motor states and somecontrol values such as Vdc, the temperature on the inverter.
Figure 22 Scheduler Sensorless FOC
The FOC Software handles 8 different states for the Motor in a seperate global 16 bit word (STATE_M0). Thededicated states are listed for Motor 0 in the register view below.
The bits of the variable are described in a table that follows.
STATE_M0Short Description
Reset value: 0001H
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
- - - - - - - - - - M0 States
- - - - - - - - - - - rw rw rw rw rw
Scheduler Start
New Command?
Handle State M0
Send parameter
Handle Command
Scheduler End
no
yes
Application Note 18 V 1.0, 2009-07
AP16165XE166 Sensorless Fieldoriented Control
Implementation of a Sensorless FOC using the XE164
Figure 23 Statemachine for Single Motor FOC
On power-up the Statemachine normally enters the IDLE state. In IDLE state the Motor is stopped by Softwareand the CCU6 interrupts are disabled. To start the Motor, the BOOTST state is entered. BOOTST can also beentered directly after power-up, instead of IDLE. Whether IDLE or BOOTST mode is entered on power-up isdefined by the DEFAULT_STATE setting in the define.h file.
#define DEFAULT_STATE STATEBOOTST_M0
In the Bootsrap state the low side transistors will be switched on for the dedicated number of the ramp-up timerinterrupts.
Field Bits Type DescriptionM0 States [0:3] rw Statemachine States
0001 STATEIDLE_M0(Default)0010 STATESTARTUP_M00011 STATESTOP_M00100 STATEFOC_M00101 STATERAMPDN_M00101 STATEEMCY_M00111 STATEBOOTST_M01000 STATEPOTI_M0... ...Note: Some states are triggered by the Drive Monitor, while other
states are entered automatically and can not be influenced by the Communication Software.
STARTUPSTOP
FOCRAMPDN
EMCY
reference _speed < threshold
∆ϕ > threshold
CTRAP:low level at pin CTRAP
Start
Stop
StopStop
Ramp Down
Stop
STOP:MotorStop();disable T12_INT disable TRAP_INT
STARTUP:enable T12_INT MotorStart();enable TRAP_INT
EMERGENCY-STOP:MotorStop();
RAMPDOWN:reference_speed_user = threshold;
OnOff
closed_loopTrap
OnOff
closed_loopTrap
OnOff
closed_loopTrap
OnOff
closed_loopTrap
OnOff
closed_loopTrap
IDLE
OnOff
closed_loopTrap
BOOTST
OnOff
closed_loopTrap
Bootstrap:Switch on low sideswait n loops
CPU Trap
Power up
!Main init Power up
POTI
OnOff
closed_loopTrap
Poti:Waits for a Poti value < 10 before start the motor
S chedulerS tateMachine_2009-04-09.emf
Application Note 19 V 1.0, 2009-07
AP16165XE166 Sensorless Fieldoriented Control
Implementation of a Sensorless FOC using the XE164
#define BOOTSTRAP_M0 2
After this the STARTUP state is entered, which means the Motor will start to ramp-up. The FOC state is enteredafter a selected speed of the Motor when the sensor less FOC algorithm starts to handle the Motor. A CTRAP cancause an Emergency Stop as well a CPU TRAP. For more information about the Emergency handling refer toChapter 3.3.4.
3.3.1 IDLE StateIDLE is the default state entered on system power-up. In this state the CPU waits for new commands and for atrigger to start the motor. Status flags will be reset and the values for the CAPCOM2 ramp timer 7 can be changed.To change the timer value, DAvE generated functions are used.
case STATEIDLE_M0:
status0.on = 0;status0.control = 0;status0.off = 1;
CC2_vStopTmr(CC2_TIMER_7);CC2_vLoadTmr(CC2_TIMER_7,control0.SpeedRampSlew);CC2_T7REL = control0.SpeedRampSlew;CC2_vStartTmr(CC2_TIMER_7);break;
3.3.2 STOP StateThe STOP state can be entered with a command from the DriveMonitor, or after the ramp-down state is finished.The STOP function disables the ENABLE signal for the driver IC, and also sets the status flags and FOC variablesto their defaults. The CAPCOM60 Timer 12 is stopped and the interrupt nodes for Timer 12 and the Emergencyinterrup are disabled.
3.3.3 Ramp-down StateThe Ramp-down state can be entered by a command direct from the DriveMonitor. The user reference speed isset to the REFSPEED_STARTUP_M0. Once the reference speed matches the user reference speed, the statemachine automatically enters the STOP state. The following shows a code extract from the scheduler function:
case STATERAMPDN_M0: //This ramps down the Motor 0 -> the switch to idle will be
done on the CCU2 T7 interrupt status0.on = 0;control0.ReferenceSpeedUser = REFSPEED_STARTUP_M0;
break;
Application Note 20 V 1.0, 2009-07
AP16165XE166 Sensorless Fieldoriented Control
Implementation of a Sensorless FOC using the XE164
3.3.4 Emergency Stop StateThe Emergency State can be entered from two different event triggers:
� CCU60/CTRAP - this switches off the power devices if the trap input becomes active.� CPU TRAPS - Trap functions are activated in response to special conditions that occur during the execution
of instructions.
Figure 24 Emergency Stop
There are nine hardware trap functions for the XE164 divided into 2 classes. Class A traps are: � System Request 0 (SR0)� Stack Overflow� Stack Underflow trap� Software Break.
The second Class B traps are: � System Request 1 (SR1)� Undefined Opcode� Memory Access Error� Protection Fault� Illegal Word Operand Access.
All this TRAP call the same Emergency_Stop_M0() function. An Emergency State can only be left with a STOP command from the Drive Monitor.
3.4 CAPCOM2 Timer 7 - Motor Ramp functionThe CAPCOM2 Timer 7 is base for all ramp-up and ramp-down functions of the sensorless FOC software. Thespeed ramp is dependent on three Excel parameters in the define.h file.
REF_RAMPUP_T7_M0 T7_PRESCALERRAMP_STEP_M0
The REF_RAMPUP_T7_M0 defines the Timer ticks and T7_PRESCALER selects a pre scaler for Timer 7. TheRamp Step is also defined. This influences the slope of the ramp behaviour.The Timer 7 interrupt handles the following functions:
� Bootstrapping time� Ramp-up in V/f� Ramp-up in closed loop FOC
Emergency STOP
CPU TRAP CCU60 CTRAP
Motor enable = OFF
Application Note 21 V 1.0, 2009-07
AP16165XE166 Sensorless Fieldoriented Control
Implementation of a Sensorless FOC using the XE164
� Ramp in case of user reference speed changes during run time� Ramp-down in closed loop FOC
3.4.1 BootstrappingA MOSFET/IGBT is a voltage controlled device which, in theory, will not have any gate current. This makes itpossible to utilize the charge inside the capacitor for control purposes. However, eventually the capacitor will loseits charge (due to parasitic gate current), so this scheme is only used where there is a steady pulse present. Thisis because the pulsing action allows for the capacitor to discharge (at least partially if not completely). Most controlschemes that use a bootstrap capacitor force the high side driver (N-MOSFET) off for a minimum time to allow forthe capacitor to refill. This means that the duty cycle will always need to be less than 100% to accommodate forthe parasitic discharge unless the leakage is accommodated for in another manner.The LV inverter in use also needs a re-fill of the bootstrap capacitors. This is achieved in the Bootstrap state byusing the CCU60 to set the compare values for all 3 channels to the Timer 12 period value +1. This will switch onthe low side MOSFET for a dedicated time. The actual time is calculated from the number of Capcom2 Timer 7overruns that is stored in the variable BOOTSTRAP_M0, in the define.h file.
Figure 25 Bootstrap of the LV inverter (D6 Enable Signal; D0,D2,D4 low side; D1,D3,D5 high side)
3.4.2 Motor Ramp-upThe startup mechanism to turn the motor is quite complex and can be divided into two parts. First the Motor willstart to turn by a V/f to a dedicated user defined speed. From this point on the Field Oriented Control will handlethe Motor.
Figure 26 Motor Ramp-Up
A #define in the define.h file is used to switch selection between the V/f control and FOC.
Startup control
∆ϕ =
∆ϕ≥ threshold
foc.AngleSpeedT0
foc.AngleSpeed
ϕ + ∆ϕ ⇒ ϕ
foc.AngleSpeedThreshold
t
n
Threshold
SpeedT 0
t
10
status . control
Motor rpm
Time in CCU2 T7 overruns
V/f FOC
REFSPEEDUSER_STARTUP_M0
Bootstrap
ANGLESPEED_THRESHOLD_M0
Application Note 22 V 1.0, 2009-07
AP16165XE166 Sensorless Fieldoriented Control
Implementation of a Sensorless FOC using the XE164
#define CONTROL_SWITCH_M0 1
If this control switch is set to 0 the motor ramps-up to the angle speed threshold in the V/f control. The motor willrun with that speed without switching to the FOC algorithm. This method can be use to check the calculated angleof the motor with the angle used in the V/f control.
3.4.3 Running stateAfter the motor ramps up to the defined threshold speed, the user can change the User reference speed with theDriveMonitor. In case the define SPEED_POTI is active in the define.h file, the Poti of the DriveCard is used tochange the speed of the Motor.
3.4.4 Motor RAMP-downAfter the scheduler receives the command for ramp-down (Chapter 3.3.3) , the reference speed will be ramped-down to the REFSPEED_STARTUP_M0. Once the speed ramp-down is complete, the scheduler state isautomatically changed to the STOP state.The following shows a code extract from the CAMCOM2 Timer 7 interrupt function:
//********************************************************************************// controlling the speed of the Motor 0 if switched to control mode//********************************************************************************if (STATE_M0 == STATERAMPDN_M0){if(control0.ReferenceSpeedUser > control0.ReferenceSpeed) control0.ReferenceSpeed += RAMP_STEP_M0;if(control0.ReferenceSpeedUser < control0.ReferenceSpeed) control0.ReferenceSpeed -= RAMP_STEP_M0;if(control0.ReferenceSpeedUser == control0.ReferenceSpeed)
{STATE_M0 = STATESTOP_M0;}
}
3.5 CAPCOM60 Timer 12 and Timer 13The PWM is generated with the CCU60 timer unit. Both timers T12 and T13 are used. T12 generates the signalsfor the Space Vector Modulation (SVM). T13 generates the trigger events for the ADC0. T13 runs in single shotmode and starts automatically on one defined compare match of one of the 3 compare channels. The generatedtrigger starts the conversion of the ADC0 channel which generates an interrupt after the channel is converted.Details of the ADC0 handling can be found in Chapter 3.6.1.The passive level selection of the CCU60 compare output signals fits to the Infineon 3 phase gate driver6ED003L06-F. To avoid spikes and dangerous transitions at startup the CCU60 has a special feature which isused for the initialization and for the Start/Stop/Emergency states. Therefore the CCU60�s trap state is forced bysoftware. This is done at the very beginning of CC6_vInit() by setting the flag TRPF (note: DAvE does not set thisflag). By this it is ensured that the output signals always show the defined passive level during initialization untilthe flag TRPF is cleared. There are two application specific constants which have to be defined before compilation in defines.h. They willbe initialized accordingly:
T12PERIODE_M0 DEADTIME_M0
The T12 period needs to be setup according to the PWM frequency. The deadtime counter needs to be setupaccording to the Hardware setup. DAvE settings will be overwritten in this instance.
Application Note 23 V 1.0, 2009-07
AP16165XE166 Sensorless Fieldoriented Control
Implementation of a Sensorless FOC using the XE164
3.5.1 CAPCOM60 Timer 12 interruptThe FOC algorithm can be explained by Figure 21. The shown building blocks are exactly implemented, mainlyin the file FOC_Functions.c and FOC_Functions.h for inline functions. The FOC calculation is divided into twoparts. The first part is located in the ADC0 Result register interrupt and executes the following calculations:
� ADC result register control � current calculation and phase current extraction� clark transformation
The second, larger part is located in the Timer 12 period match of the Interrupt Service Routine, and executes thefollowing calculations:
� flux estimation� park transformation� speed calculation and speed control� current control� inverse park transformation � cartesian to polar transformation� space vector modulation
The Timer 12 one match of the Interrupt Service triggers the shadow transfer for the compare channels.
3.6 ADC0 Result HandlingThe current implementation uses several channels of the ADC0. The ADC1 module is reserved for futureimplementations. Nevertheless a customer specific setup of the free and used ADC channels can be easilycreated within the DAvE project.
Figure 27 ADC0 Structure for Single Motor FOC
3.6.1 DC Link Shunt MeasurementsThe sensorless Field Oriented Control works with a single Shunt measurement. It is possible to economize onecurrent sensor when the current measurement is not performed in the phases but in the dc-link. To effect thisphase current acquisition through the dc link current it is necessary to know the actual switching pattern.In this way, during one PWM, two times, two different phase currents can be measured through a dc-link currentmeasurement. The third phase current can be calculated by the equation iU+iV+iW=0. (see Chapter 2.3 fordetails).In order to get a maximum time between the current conversions with the ADC, the measurement will be startedon the edge of the phase with the middle �on time� (Figure 28).
*G RshuntCH8
CH15: VDC
CH13: POT
ResReg0
ResReg1
ResReg7
ResReg6
ADC0
CAPCOM60
Motor 0
Application Note 24 V 1.0, 2009-07
AP16165XE166 Sensorless Fieldoriented Control
Implementation of a Sensorless FOC using the XE164
Figure 28 ADC Measurement
3.6.2 VDC and PotiThe two additional values are connected to ADC0 CH13 and ADC0 CH15. Both channels will be converted withthe parallel source which is basically a channel scan. The conversion request tigger is set in software in the GPTTimer 6 interrupt. Both results are stored into global variables. If the #define SPEED_POTI is set in the defines.h file, the poti on the XE164 Drive Card will be used to control thespeed of the Motor. The control function is located in the scheduler.
3.7 Interrupt LevelThe XE164 provides 96 separate interrupt nodes assignable to 16 priority levels, with 8 sub-levels (group priority)on each level. The used interrupt level in this project are selected carefully. With the help of DAvE these levels can be adaptedto application needs in case new peripherals like a USIC channel is added into the project.
Calculate new T 13 valuesT13 Shadow transfer enable
TPWMT12
T13
IDClink
T13PR
T12PR
Event (ADC0_INT0):Result Event 0
CC60SR
CC61SR
CC62SR
hardware start
Assign Result Register for DC Link channelT12 count down -> Result Register 1 selected
T13PMT13PM
Calculate new T 13 valuesT13 Shadow transfer enable
Event (ADC0_INT1):Result Event 1
Assign Result Register for DC Link channelResult Register 0 selected
Calculate currents Ialpha and IbetaCalculate currents Id and Iq
hardware start
Application Note 25 V 1.0, 2009-07
AP16165XE166 Sensorless Fieldoriented Control
Implementation of a Sensorless FOC using the XE164
Figure 29 Interrupt Setup
3.8 Variable Definition and AdministrationThe variables used for the FOC algorithm and control of the whole software are separated into 4 structs locatedin the Controls_FOC.h file. These structs are:
� tSVM svm0;� tFOC foc0;� tStatus status0;� tControl control0;
Each struct has associated variables. These structs are preloaded in the Main.c file variable declaration with thedefine values coming from the define.h file. These variables can be changed and monitored as required, via theDriveMonitor.
3.9 DAvE Support The project is based on DAvE with the DIP file for XE16xx_Series V2.0. Setting changes can be made there, suchas the GPT timer values to change the scheduler frequency for example, as well as adding new peripherals suchas a USIC for example.
Application Note 26 V 1.0, 2009-07
AP16165XE166 Sensorless Fieldoriented Control
Communication Interface
4 Communication InterfaceCommunication is via the Drive Monitor Software for the PC and the Drive Monitor USB Stick. Download to theXE164 is via the JTAG connection. Motor communication, such as Start and Stop commands, is via MultiCAN.The XE164 uses the MultiCAN Node 0 running at 500kBaud, together with several Message objects, for thiscommunication.For more information about the Drive Monitor please refer to the AppNote: Drive Monitor, Hardware Description(ap0807120_DriveMonitor.pdf).[1]
4.1 MultiCAN InterfaceIn the current Implementation, five CAN Message objects are used. Message Object 10 is configured as the receive object, forwarding commands from the Drive Monitor Software viaa CAN receive interrupt, to the Scheduler. CAN message objects MO1 through to MO4 are used for data transferfrom the XE164 to the Drive Monitor Software.
4.1.1 Program Flow XE164The program flow of the target microcontroller is an embedded realtime code which runs in several interruptservice routines. There is GPT Timer 6 providing a system tick of 1ms which calls a scheduler. The schedulerstatemachine controls the application and reacts on host commands. The CAN controller is configured to three interrupt vectors for receive, transmit and error handling. The CANMessage Objects have following IDs:
� ID5 - receive object - MO 10: SET/GET command and Buttons� ID55- receive object - MO 2; unused � ID7 - transmit object - MO1; slow data for status flags and display field� ID77- transmit object - MO 3; fast data for oscilloscope and progress bar� ID57- transmit object - MO 4; responds to GET command
Figure 30 Program Flow
RESET
Initialize Application
MAIN
CAN � REC
copy message to buffers
CANRxdBuf0
reti
CAN � TRXID7 / ID 77 / ID57
clear message pending flags of
sent objects
reti
ADC
Handels ADC results
reti
every 1ms
Scheduler
reti
Scheduler
switch states upon command exec.
ret
FOC_Calculation
send CAN messages
CTRAP interrupt
set emergency state
reti
interrupt
CC6 Shadow Transfers
ID5
ADC Poti VDC
CCU60 T12
Speed RampSpeed Control
reti
interruptCCU2 T7
reti
GPT T6
Send Oszi Data
reti
GPT T6
Application Note 27 V 1.0, 2009-07
AP16165XE166 Sensorless Fieldoriented Control
Communication Interface
4.1.2 Command Structure The command structure is as per the document ap0807120_DriveMonitor.pdf.[1]
4.1.3 Receiving a CAN Message and Command ExecutionOn receipt of a CAN message object (M0 10 with ID5) the receive interrupt is vectorized. The interrupt serviceroutine scopes the received data into a global array named CANRxdBuf0. The following shows a code extract of the CAN Receive interrupt service routine:
// The CAN controller has stored a new message into this object. // USER CODE BEGIN (SRN0_OBJ10,4)CANRxdBuf0[0]= CAN_MODATA10LL;CANRxdBuf0[1]= CAN_MODATA10LH;CANRxdBuf0[2]= CAN_MODATA10HL;CANRxdBuf0[3]= CAN_MODATA10HH;// USER CODE END
At every system timer tick the scheduler statemachine is executed. If a new command is received, thecorresponding command is executed and the CANRxdBuf0 is cleared. The CAN receive interrupt and the GPTTimer 6 for scheduler use the same interrupt level. This mechanism ensures that an incoming command has tobe served first before a new command is accepted.
4.1.4 Transmitting a CAN MessageThere are three transmit message objects configured for sending data from the target to the host. The transmitmessages have to be initialized. The transmit buffers CANTrxBuf0/1 are used to load the data to the messageobjects. The load, release and transmit request functions are generated functions from DAvE.The following show a example code of the transmit function for message object 3:
_inline void CAN_Transmit_MO3(void){ // MO3 is shown in Oscilloscope CAN_vLoadData(3, (ubyte*) CANTrxBuf1 );
CAN_vReleaseObj(3);CAN_vTransmit(3);
}
4.1.5 Command SETWith the SET command any variable of the FOC structs can be updated. Therefore it is necessary to have theaddress information of the respective variables. Address and data information are read from the CANRxdBuf0 andthe contents of the address is written with the new value. The following shows a code extract of the scheduler function:
D0 D1 D2 D3 D4 D5 D6 D7 CAN IDcommands from DriveMonitor to targetadrL adrH valL valH 0 0 0 CMD 5
Application Note 28 V 1.0, 2009-07
AP16165XE166 Sensorless Fieldoriented Control
Communication Interface
case CMDSET:// byte # 0 1 2 3 4 5 6 7 // CMD byte adrL adrH valL valH xxxx xxxx cmdL cmdH// CMD int adr val x CMDSET// int # 0 1 2 3
adr = (unsigned int*) CANRxdBuf0[0];value = CANRxdBuf0[1];*adr = value;
// dont change statebreak;
4.1.6 Command GETWith the GET command the host can read the contents of any variable. The host has to send the addressinformation first before the target responds with the data on transmit message object MO 4. The following shows a code extract of the scheduler function:
case CMDGET:// byte # 0 1 2 3 4 5 6 7 // CMD byte adrL adrH xxxx xxxx xxxx xxxx cmdL cmdH// CMD int adr xxx xxx CMDGET// int # 0 1 2 3
adr = (unsigned int*) CANRxdBuf0[0];
// Transmit MO 4 on request tmp[0] = (unsigned int) adr; tmp[1] = *adr; CAN_vLoadData(4, (ubyte*) tmp );
CAN_vReleaseObj(4);CAN_vTransmit(4);// dont change statebreak;
D0 D1 D2 D3 D4 D5 D6 D7 CAN IDcommands from DriveMonitor to targetadrL adrH valL valH 0 0 cmdL cmdH 5
D0 D1 D2 D3 D4 D5 D6 D7 CAN IDfrom DriveMonitor to targetadrL adrH 0 0 0 0 cmdL cmdH 5
Application Note 29 V 1.0, 2009-07
AP16165XE166 Sensorless Fieldoriented Control
Communication Interface
4.1.7 Button Start, Stop, Ramp DownOn pressing the Start, Stop or Ramp Down buttons, the scheduler state variable is updated and will be entered.
4.1.8 Scope ButtonsRealtime monitoring of fast changing data is one of the key features of the DriveMonitor. Therefore the CANmessage object MO 3 - ID 77 is sent with every GPT timer 5 tick to the host. With this message three 16bit valuescan be monitored on the three beams of the virtual scope. With the scope buttons the addresses of the threemonitoring variables can be changed. The following shows a code extract of the scheduler function:
case CMDSETBEAMS://Button Values: SCOPEgreen | SCOPEpink | SCOPEyellow | CMDSETSCOPE:
ScopePointer[0] = CANRxdBuf0[0];ScopePointer[1] = CANRxdBuf0[1];ScopePointer[2] = CANRxdBuf0[2];break;
4.1.9 Oscilloscope and Progress BarWith every GPT Timer 5 over flow the data for the soft oscilloscope and the progress bar are sent to the host.These data have the highest transmit rate. The user has to ensure that the realtime conditions are met. This canbe tuned with the GPT timer 5 overflow rate. The fast data use ID77 with MO 3.
D0 D1 D2 D3 D4 D5 D6 D7 CAN IDfrom DriveMonitor to target0 0 0 0 0 0 cmdL cmdH 5
D0 D1 D2 D3 D4 D5 D6 D7 CAN IDfrom DriveMonitor to targetgreenL greenH pinkL pinkH yellowL yellowH 0 0 5
Application Note 30 V 1.0, 2009-07
AP16165XE166 Sensorless Fieldoriented Control
Communication Interface
Figure 31 Drive Monitor Oscilloscope
4.1.10 Status Flags and Display FieldsFor slower changing data, it is sufficient to send the data over a greater number of timer ticks. Such data wouldbe the status flags and display fields for example. The transmit rate is defined by a variable which counts a definednumber of system timer ticks. The slow data use ID7 with MO 1. The following shows a code extract scheduler function:
//send parameter via CANif (++CANMO1Count == 50){ CANTrxBuf0[0] = (unsigned int)status0.off |
((unsigned int)(status0.on)<<1) | ((unsigned int)(status0.control)<<2) | ((unsigned int)(status0.ramp)<<3) | ((unsigned int)(status0.ctrap)<<4) ;
CANTrxBuf0[1] = svm0.Amplitude;CANTrxBuf0[2] = control0.ActualSpeed;CANTrxBuf0[3] = ADC_VDC; //VDCCAN_Transmit_MO1();
CANMO1Count=0;}
Application Note 31 V 1.0, 2009-07
AP16165XE166 Sensorless Fieldoriented Control
How to Use the Setup
5 How to Use the Setup
5.1 Excel Sheet and defines.hParameterization of the application is via the header file defines.h. For ease of use, an Excel sheet (see Figure 32)is used to generate this files contents. The algorithm itself is left untouched. The Excel sheet has two pages: the input page Input Parameter and the output page defines.h. The Input Parameters can be filled into the yellow marked fields. These are the most relevant parameters. TThestructure is as follows:� Motor Parameter - this is the resistance and inductance of the motor windings. The input value refers to one
phase, i.e. phase-to-neutral and not phase-to-phase. � Startup Parameter - these are the values which are used in the startup block. � Inverter Parameter - in case customized inverter is used, it can be adapted here. � Current Measurement - in case the current amplification or the shunt is changed it has to be changed here. � Speed and Current Controller - here the integral and proportional factor for the PI-controllers can be adjusted.� Flux Integration Scaling - here the PT1 filter for the flux estimator can be adjusted. � Speed Filter - here the PT1 filter for the speed filter can be adjusted� Speed Ramp - here the speed ramp time can be adjusted. In case the Speed Ramp time in the startup
parameters is not fast enough, the incremental steps can be increased. The parameters influence each other, e.g. a very low inductance value L will scale to a very low value L� which isused for the flux estimator. In this case the input parameter K in the Flux Integrator Scaling should be increased. If the Excel sheet shows red marked cells the scaling paramaters have to be changed accordingly.
Figure 32 Excel sheet input page
��������������� ���������������������
�������
������������� ��������������� ������ ������������ ������
� ��� ��
��� ��
��������� � ������!
���������� � ����!� ����" �������� �
������!���������� ���������� ����#����� ������$� ���%
������������&�'� � ���
������������&�'������& ��� ��� �!��"
���������� � ����!� ����" � � ����& �����$$� ���
���������� ����#����� ����(�)$��� ���%
�� ���*+������&�,��� $��� ��� #���$��
����&����� ��� ����� �!&�-" �������� �
�!α�β" ������� �
% ��������������� �!�����������&�" ������(� �
./���*0�����1� $� �
&��&����� � �� �������
�#��+��&���2�!��3" ��( �� 4!&�-" �������) 5
�67� ��-��*+2 ���� �% 4!α�β" �������) 5
8����������+���1������ �� �� 4!����#" �����() 5
9:58 9���*��1�+�������;���1���+����
-�;��#��+����
�
�%��������
5���������*�<�� � ����&�0� �����)�
,������� ������& �
����&�0� ��������
�����������������
�=���*� ���$ �� /����*��0� �����)�
�=4: � 0>�� /����*��0� ��������
�= ��&<�+0 �� 0>��
��3���������1�����5./ �
�!��"��%��������
?� ���� !�@����"
?� �� !�@����"
��������%��������
�+��� !@A����" !@A����"
Application Note 32 V 1.0, 2009-07
AP16165XE166 Sensorless Fieldoriented Control
How to Use the Setup
After changing the Input Parameter, the contents of output page has to be copied to the file defines.h, the C-projecthas to be re-complied and downloaded to the target. The Excel file also creates the scaling factors for theDriveMonitor. For instance the speed scaling changes when the number of pole pairs changes. These values haveto be adapted inside the DriveMonitor configuration (CAN control editor).
5.2 Drive MonitorThe DriveMonitor is a hardware tool which bridges USB to CAN. With this it is possible to monitor some interestingdata of the target on a host PC in real-time. For more information please refer to the DriveMonitor application notein [1].
5.2.1 Configuration The configuration of the DriveMonitor setup can be found in see the DriveMonitor application note in [1].
5.2.2 Monitoring the Startup BehaviorDifferent motors have different startup behavior. The starting up of a synchronous motor is always quite tricky. Thefirst revolutions have to be done in an open loop mode before the FOC algorithm can take over. There are somevalues which mainly influence the startup behaviour. These values can be found in the Excel sheet under StartupParameter and will be discussed below.After setting the correct R and L values, compilation and downloading the DriveMonitor can be started and usedin Setting 1 | Startup. After connecting to the target, the button Scope Start should be pressed and then the buttonStart. The motor should start turning and after a few seconds the Stop button can be pressed. The scope showsin this setting two interesting signals:� pink: Angle from the Startup Control block which is the given angle following the V/f ramp depending on
the slew rate � yellow: FluxAngle from the Carthesian to Polar Transform block, which is the estimated (calculated) angle
based on the current measurement.
Figure 33 Startup Behaviour of a Fan before Optimization
Example Fan:After a few revolutions the estimated angle (yellow) andthe given angle (pink) are quite similar. The FOC takesover at the speed threshold point.DriveMonitor:
Speed refdefines.h:
AngleSpeedThreshold
Application Note 33 V 1.0, 2009-07
AP16165XE166 Sensorless Fieldoriented Control
How to Use the Setup
Figure 34 Startup Behaviour of a Fan after Optimization
The point where the FOC takes over from the V/f control is of special interest. The V/f algorithm increases thespeed continuously until the threshold value is reached (Excel: Startup Speed Threshold, defines.h:AngleSpeedThreshold). At this point the current and speed controllers cannot deliver the correct output as theystart here. The algorithm can only prepare the controllers accordingly. Therefore the current controller�s integral part is preset with current amplitude (Vq) based on the V/f calculationotherwise the amplitude would drop immediately. This is accomplished in CC2.c Timer interrupt function by pre-loading control0.Iq.Yn:
//*****************************************************************************************// ramp up to motor 0
//*****************************************************************************************if (STATE_M0 == STATESTARTUP_M0){if( (control0.ReferenceSpeedUser>0?foc0.AngleSpeed:-foc0.AngleSpeed) < foc0.AngleSpeedThreshold )
foc0.AngleSpeed += (control0.ReferenceSpeedUser>0?RAMP_STEP_M0:-RAMP_STEP_M0);else{ if(control0.ControlSwitch) {
// preload parameterscontrol0.Iq.Yn = ((long)foc0.Vq)<<16;// preload Iq-current controller integral value to last V/f-amplitude value
//*******************status0.on = 0;status0.control = 1;svm0.SVMTMIN = SVMTMIN_M0;STATE_M0 = STATEFOC_M0;
}
}}
The speed controller must adjust at runtime. Therefore it is advisable that the speed controller is started with aninput step, i.e. a difference between the ANGLESPEED_THRESHOLD_M0 and the REFSPEED_STARTUP_M0. InDriveMonitor the value Speed Ramp can be adjusted by Speed_ref, i.e. the user can play with this value.
Example Fan:After optimization ofVf_offset and Vf_slewthe startup behavior ismuch better (less rippleson the estimated angle).
Application Note 34 V 1.0, 2009-07
AP16165XE166 Sensorless Fieldoriented Control
How to Use the Setup
Figure 35 Switching point from V/f to FOC with different Speed_ref settings
In Figure 35 different threshold conditions can be observed:a) REFSPEED_STARTUP_M0= ANGLESPEED_THRESHOLD_M0b) REFSPEED_STARTUP_M0>ANGLESPEED_THRESHOLD_M0c) REFSPEED_STARTUP_M0>>ANGLESPEED_THRESHOLD_M0.
5.2.3 Monitoring the Runtime BehaviorThe Runtime behavior can be influenced by the PI parameter settings of the speed and controllers. Here theDriveMonitor offers the window Setting 2 | Control. Here the ki and kp parameters can be easily adjusted. Formonitoring the Scope Speed or Scope I_uvq can be used.
Figure 36 Speed controller adjustment, reaction on a reference speed step
5.2.4 Special tricks - Field WeakeningThe nominal speed of a motor is reached when the phase amplitude is at its maximum value under zero load. Thisis because the BEMF (Back-Electro-Magnetic-Force) generated voltage increases with the speed and acts againstthe phase voltage. Therefore the speed saturates. In the FOC algorithm there are two components:� the torque building current Iq and � the field building current Id. The latter one Id is controlled to zero because a PMSM motor generates the field by its magnet. This fieldcomponent can be easily controlled to a negative value which weakens the magnetic field. With this trick the motormust turn faster than its nominal rated speed.DriveMonitor allows the field weakening easily in the Setting 2 | Control. The third Group Entry shows Id Ref. Anegative value here will let the motor turn faster.
a) b) c)
reference speed actual speed
Output of speed controller: Iq_reference
small Kp large Kp
Pink: reference speedgreen: actual speedyellow: output of currentregulator
Application Note 35 V 1.0, 2009-07
AP16165XE166 Sensorless Fieldoriented Control
How to Use the Setup
A few more interesting observations can be made in this mode:� the overall current consumption will increase - watch the power supply current,� the torque will decrease in field weakening - this is obvious as the resulting stator flux vector is no more longer
rectangular to the rotor flux vector.
Figure 37 Field Weakening: With negative field building component Id the speed increases above the nominal speed.
Id = -100
Application Note 36 V 1.0, 2009-07
AP16165XE166 Sensorless Fieldoriented Control
References
6 References
[1] Application note - AP0807120_DriveMonitor
[2] Application note - AP0808810_XC878DriveCard
[3] Application note - AP9000110_LVinverter
[4] Application note - AP1616010_DriveCard_XE164
[5] Application note - AP0805910_Sensorless_FOC
[6] Application note - AP08090_XC878_Sensorless_FOC
[7] Link to free toolchain program -- http://www.infineon.com/Freetools
[8] Link to FOC Drive page - www.infineon.com/FOCDRIVE
Note: Please check the Infineon website (www.infineon.com) for the latest Version of these documents.
Application Note 37 V 1.0, 2009-07