Documente Academic
Documente Profesional
Documente Cultură
32-bit
Microcontrollers
Application Note
1 Introduction
This application note delivers an implementation of Sensor Field Oriented Control
algorithm for brushless DC motor on Atmel AVR32 UC3B microcontrollers.
This software includes standalone libraries for all mathematical transformations
required by the algorithm.
For more information about the AVR32 architecture, please refer to the appropriate
documents available from http://www.atmel.com/avr32.
2 Requirements
The software provided with this application note requires several components:
Rev. 32126A-AVR32-06/09
3 Theory of Operation
3.1 Overview
As continuity in the energy efficiency process, the increase of capability of
microcontrollers allows to implement complex algorithm as Field Oriented Control
methodology which allows to:
Provide smoother and more accurate motor control than sinusoidal command
with hall feedback.
Optimize motor choice (torque): find the best alternative between dimension
and power.
But this algorithm requires more complex computation and requires more CPU
bandwidth than standard algorithms.
Moreover, this command strategy fits with some brushless DC motors with dynamical
load changes due to reduction of response time. It allows regulating torque and speed
at the same time.
2 encapsulated regulation loops: one for the current (torque and power loss)
and another for the speed.
3-phases current
Regulation loop
(Ia,Ib,Ic)
Speed Target
Vectorial
Command
Speed
Regulation loop
Speed
and Position
AVR32723
32126A-AVR32-06/09
AVR32723
3.3 System Overview
As shown Figure 3-2, the 3-phases current are measured and one Hall Effect
feedback is used to compute field oriented control algorithm.
Figure 3-2. System Overview
PWM
3-phases Inverter
PWM_XH
PWM_XL
PWM_YH
3-phases
BLDC
PWM_YL
PWM_ZH
Sensor
FieldOriented
Ccontrol
Process
PWM_ZL
Current
IA
IB
IC
Speed
Hall Effect A
USB-CDC
USB Task
PC
32126A-AVR32-06/09
The USB connection is used through a PC application for real time motor remote
control and display of regulated variables. This data monitor displays feedback control
remotely. This GUI provides:
- 3 graphs and 1 cursor display.
-
4 inputs control.
The purpose is to be able to connect to the application without disturbing the behavior
of the application. The application offers the following features:
With a 100 sec control loop, the CPU is used at 35% by the Sensor Field
Oriented Control Process at 42MHz.
AVR32723
32126A-AVR32-06/09
AVR32723
4 Motor Control Theory
4.1 General Model.
The mathematical model in a constant domain linked to the stator is linked to
differential equation with constant coefficients defining the motor behavior.
Applying the Lenz-Faraday model, we have:
va
[Vabc ] = vb ,
vc
ia
a
Ls
[ abc ] = M
M
M
Ls
M
M i a sf cos( )
2
M i b + sf cos(
3
Ls i c
2
sf cos( +
3
sf
cos(
)
Ls M M ia
ia
va
d
d
2
vb = R ib + M Ls M ib +
sf cos(
)
dt
dt
3
M M Ls ic
ic
vc
sf cos( + 2 )
3
In order to simplify the mathematical resolution of this system, some mathematical
transformations are used.
Using the Park P1(), the instantaneous power is kept and it allows to have a
mathematical expression of the torque still acceptable for the real motor.
32126A-AVR32-06/09
Using the Park inverse transformation, it is possible to return to the values space from
regulated values and generate commands.
4.1.1 Park Transformation (P1()) and Clarke Transformation (inv P-1()) 2.
The Park transformation is defined from the matrix P1(), it defines the link between
the real vectors Vabc , Iabc et abc , the new vectors V 0 dq , I 0 dq et 0 dq .
[ ] [ ] [
P1( ) =
2
3
1
2
1
2
1
2
][
] [
2
2
cos(
) sin(
)
3
3
2
2
cos(
) sin(
)
3
3
cos( )
sin( )
vb
Vd
va
[P1()]
-1
[xabc]=P1()[X0dq]
va
V0
vc
With V0 =0V, I0 =0A and 0 =0Wb, the normalized Park transformation is the addition
the Concordia Transformation T32 and the rotating matrix p() :
1
T 32 =
2
2
2
2
2
3
+
2
3
cos sin
p( ) =
sin cos
x
t
32
Xd
P(-)
Xq
AVR32723
32126A-AVR32-06/09
AVR32723
4.2 Power Bridge Command.
The power bridge stage is here to power the BLDC motor with alternatives voltages
from a continuous source. This bridge allows modulating frequency and amplitude.
Figure 4-3. Power Bridge Stage
I
Ta
Tb
Tc
ia
a
a
ib
n
c
Ta
Tb
Ca Ca
m
Cb
ic
Tc
Cb
Cc
Cc
The logical signals Ca, Ca, Cb, Cb, Cc and Cc are command signals for the power
bridge.
The output voltages are given from the ground m of source generator and from the
virtual neutral point n of BLDC motor.
Ca
Vam
Vbm = E Cb
Cc
Vcm
(II-1)
1
(Vam + Vbm + Vcm ) .
3
Van
2 1 1 Vam
2 1 1 Ca
Vbn = 1 1 2 1 Vbm = E 1 2 1 Cb
3
3
Vcn
1 1 2 Vcm
1 1 2 Cc
32126A-AVR32-06/09
Or :
2 1 1
Van
V
1
t
t
T 32 . 1 2 1 = T 32 . and = T 32 Vbn
3
V
1 1 2
Vcn
Ca
V
t
t
We conclude so: = T 32 .E Cb , ( T 32 is the translation of T 32 )
V
Cc
t
The following table gives the voltage values in the spaces ( , ) and (a, b, c).
Ca
Cb
Cc
Van
Vbn
Vcn
V0
V1
-1
-1
1
V2
3
2
-2
-1
-1
-2
V3
1
E
V4
V5
0
0
3
2
-1
3
2
-1
-1
2
1
E
3
V6
3
2
-2
V7
We show that all vectors components (V , V ) are with modules 2 3 E and are
located in the regular hexagon.
Figure 4-4. Space Vector values in the regular hexagon.
(0, 1, 0)
V
2
V3
(0, 1, 1)
V4
3
4
V5
(1, 1, 0)
V2
1V
(0, 0,
(1, 1,
5V
(0, 0, 1)
(1, 0, 0)
6
(1, 0, 1)
AVR32723
32126A-AVR32-06/09
AVR32723
4.2.1 Space Vector PWM. 3
The vectorial modulation uses directly the signal for the Concordia transformation. It
supposes that a regulation loop is ever implemented for the generation of V and V
components.
As stated below, at a instantaneous point, the power bridge is able to generate only 8
voltages (Vi, i = 0,,7) in the space of transformation Concordia (V , V) with two
components equal to 0 and 6 with the module equal to E 2 3 and the angle
to ( 3) (i 1) . Two successive vectors, called Vi and Vi+1 defined a sector i (Figure
4-4) with I from the interval [I, VI].
V
Vi =
V i
cos 3 (i 1)
2
2
1
=E
p (i 1)
=E
3
3 3
0
sin (i 1)
(V ) = i Vi + i + 1 Vi + 1
Where
Vi and Vi+1 ;
i + 1 are the duration for relative values are the relatives voltages when
iVi and i + 1Vi + 1 are the projection of vector (V ).
and
32126A-AVR32-06/09
V and V
Yes
No
V 0
i=1 or 2 or 3
i=4 or 5 or 6
Yes
No
Yes
V 0
V 0
i=1 or 2
i=2 or 3
No
Yes
No
i=5 or 6
Yes
V-3 V 0
V+3 V 0
No
n
i=4 or 5
No
Yes
Yes
V+3 V 0
No
V-3 V 0
Yes
i=1
i=2
i=3
i=2
i=5
i=6
i=5
i=4
i +1
V
V
V
V = i V + i + 1V
i+1
i
And so
V
1
2
1
V = E 3 i p 3 (i 1) 0 + i + 1 p ( 3 i ) 0
10
AVR32723
32126A-AVR32-06/09
AVR32723
Table 4-2. Sector expressions
Sector
1
T1= 1+ 2+ 0
T2= 2+ 0
T3= 0
T1= 2+ 0
T2= 3+ 2+ 0
T3= 0
T1= 0
T2= 3+ 4+ 0
T3= 4+ 0
T1= 0
T2= 4+ 0
T3= 5+ 4+ 0
T1= 0+ 6
T2= 0
T3= 0+ 5+ 6
32126A-AVR32-06/09
T1= 0+ 1+ 6
T2= 0
T3= 0+ 6
R
R
Shun
R
VA
ia
ADC
V1
V2
V1
V
V2
Offset
For example:
Vs = Offset +
R2
(V 2 V 1)
R1
When measuring the three currents Ia,Ib and Ic, only two measures are required,
indeed Ia + Ib + Ic = 0.
Figure 4-7. ADC and PWM synchronization
T
T1
PWM
ADC
tm
t
tm
tm
The ADC measures are done every period of the PWM. The first ADC measure
should be done in the time range named tm. This time is the minimum time where
none of the 3-phases are driven.
For example:
In case of sector 1, T1 is the longest time so it means that T1 > T-tm, in that case it is
not possible to measure Ia. So Ib and Ic are measured and Ia is derived from the two
others measures with the equation Ia = Ib Ic.
12
AVR32723
32126A-AVR32-06/09
AVR32723
4.4 Current regulation and speed Regulation 4
In order to reduce time consuming effect of regulator, we have used the Integrator
Proportional (IP) regulator.
4.4.1 Current Regulation
In a continuous domain, the closed loop has the mathematical expression:
Id =
Ki
Idref
L c s + ( R + Kd ) s + K i
2
a
s + 2 n s + n
2
With Ki =
Lc n
and Kd = 2 n Lc R
These correctors have been chosen to have a depreciation rate =2 and a response
time of 5 (TrWn).
Response Time
Depreciation rate
For that
n = 2 R L c with
Ki = 4 R 2 Lc and Kd = 7. R
Ki
a
=
= 2
2
ref J s + Kdv s + Kiv s + 2 n s + n 2
With
n2 =
Kiv
Kdv
et 2 n =
J
J
32126A-AVR32-06/09
R2
R
J et Kdv = 0.4 J
2
Lc
Lc
Mul
Div
Shift
17
62
62
Regulation
124
Decoupling 5
62
SVPWM
27
354
Concordia
abc-to-
Clark
-to-dq
Clark Inv
dq-to-
The decoupling stage is the stage to separate torque and power loss regulations
after the current measurement stage. The idea is to be sure to only regulate torque
(without disturbing the power loss loop).
14
AVR32723
32126A-AVR32-06/09
AVR32723
4.6 General Algorithm
As shown in Figure 4-9, the regulation_loop_task() process is sequenced on tick
reference (every 100s). This task synchronizes current measurement and computes
all mathematical transformations to execute the Field Oriented Control algorithm.
Inside this task, there are two regulation loops interlinked:
- Current regulation loop.
- Speed regulation loop.
Figure 4-9. Regulation Loop Task Step Machine
regulation_loop_task()
Hall Interrupt
No
MC_current_measurement()
Current measurement of
the 3-phases
hall_estimator_update()
Clarke()
Wait
Yes
Compute new Teta and
Speed
park()
Speed
Regulation?
No
Yes
Proceed Speed
Regulation
Execute Speed
Regulation
park_inv()
Current Regulation
Execute Current
Regulation
svpwm()
Compute new
vectorial command
Message Ready?
Sleep()
32126A-AVR32-06/09
CDC communication
task
HMI
Motor Control
regulation_loop_task() mc_control.c
usb_task() device_cdc_task.c
device_cdc_task()
Motor Driver
mc_driver.c
PARK
SERVICES/MOTOR//PI
SERVICES/MOTOR/PARK
HALL ESTIMATOR
SERVICES/MOTOR/HALL
SERVICES/MOTOR/SVPWM
CLARKE
SERVICES/MOTOR/CLARKE
DRIVERS
usb.c adc.c pwm.c flashc.c pm.c gpio.c
This application does not require any operating system to run. The main() function is
in charge of calling the software tasks (using a scheduler) realizing FOC algorithm
computation and USB communication with the Communication Device Class (CDC)
for HMI management. There are 2 tasks:
16
AVR32723
32126A-AVR32-06/09
AVR32723
5.2 Package
The EVK1101-SENSOR-FIELD-ORIENTED-CONTROL-X.Y.Z.zip contains projects
for AT32UC3B0256 RevF or later:
EVK1101-SENSOR-FIELD-ORIENTED-CONTROL-X.Y.Z
5.3 Documentation
For full source code documentation, please refer to the auto-generated Doxygen
source code documentation found in:
AVR32723/APPLICATIONS/EVK110x-MOTOR-CONTROL/BLDCFOC/EXAMPLE/readme.html
src/ APPLICATIONS/EVK110x-MOTOR-CONTROL/BLDC-FOC/EXAMPLE/IAR/
src/ APPLICATIONS/EVK110x-MOTOR-CONTROL/BLDC-FOC/EXAMPLE/GCC/
src/APPLICATIONS/EVK110x-MOTOR-CONTROL/BLDC-FOC/EXAMPLE/main.c
src/SERVICES/MOTOR_CONTROL/
The Park and Clarke transformations explained in section 4.1.1 are delivered in
the folder src/SERVICES/MOTOR_CONTROL/PARK_CLARKE/
The Space Vector Modulation explained in section 4.2.1 is delivered in the folder
src/SERVICES/MOTOR_CONTROL/SVPWM/
32126A-AVR32-06/09
src/APPLICATIONS/EVK110x-MOTOR-CONTROL/BLDCFOC/EXAMPLE/device_cdc_task.c
This task receives and sends messages through the USB communication.
With:
src/UTILS/LIBS/DRIVERS/AT32UC3B/
can
be
found
in the
src/APPLICATIONS/EVK110x-MOTOR-CONTROL/BLDC-FOC/LABVIEW/FOC_Gui.msi
18
src/APPLICATIONS/EVK110x-MOTOR-CONTROL/BLDC-FOC/LABVIEW/usb_cdc.inf
AVR32723
32126A-AVR32-06/09
AVR32723
5.8 CPU Cost and Memory Usage for Sensor Field Oriented Control algorithm.
All results are given using IAR Workbench 5.3 compiler revision 3.10A with speed
optimization level and Hmatrix optimization.
Criteria
Result
CPU Occupation
Code Size
17Kb
Data
13Kb
Const
3.5Kb
32126A-AVR32-06/09
Launch avr32Studio
Create a new AVR32 C project (File -> new -> AVR32 C Project).
Fill-in the dialogue box with project name, set target MCU to UC3B0256 and
press finish.
Choose Import archive file (File -> import), press the next button.
Load the Code: Please refer to the application note AVR32723: AVR32 Studio
getting started
5.10.2 If you are using GCC with the AVR32 GNU Toolchain
Open IAR and load the associated IAR project of this application (located in the
directorysrc/APPLICATIONS/EVK110x-MOTOR-CONTROL/BLDCFOC/EXAMPLE/IAR)
20
Press the Debug button at the top right of the IAR interface.
The project should compile. Then the generated binary file is downloaded to the
microcontroller to finally switch to the debug mode.
AVR32723
32126A-AVR32-06/09
AVR32723
5.11 Start the PC application
The USB enumeration should start; a new serial port appeared in Windows.
Iq
Speed
Id
Serial port
Iq
32126A-AVR32-06/09
Speed
Iq
22
AVR32723
32126A-AVR32-06/09
AVR32723
6 Reference
[1] Commande vectorielle sans capteur de position d'une machine synchrone
aimants permanents Atmel Nantes & IREENA[2] NI LabWindows/CVI http://www.ni.com/lwcvi/
32126A-AVR32-06/09
7 Appendix
Figure 14. Hardware Schematic.
24
AVR32723
32126A-AVR32-06/09
AVR32723
32126A-AVR32-06/09
Disclaimer
Headquarters
International
Atmel Corporation
2325 Orchard Parkway
San Jose, CA 95131
USA
Tel: 1(408) 441-0311
Fax: 1(408) 487-2600
Atmel Asia
Unit 1-5 & 16, 19/F
BEA Tower, Millennium City 5
418 Kwun Tong Road
Kwun Tong, Kowloon
Hong Kong
Tel: (852) 2245-6100
Fax: (852) 2722-1369
Atmel Europe
Le Krebs
8, Rue Jean-Pierre Timbaud
BP 309
78054 Saint-Quentin-enYvelines Cedex
France
Tel: (33) 1-30-60-70-00
Fax: (33) 1-30-60-71-11
Atmel Japan
9F, Tonetsu Shinkawa Bldg.
1-24-8 Shinkawa
Chuo-ku, Tokyo 104-0033
Japan
Tel: (81) 3-3523-3551
Fax: (81) 3-3523-7581
Technical Support
Avr32@atmel.com
Sales Contact
www.atmel.com/contacts
Product Contact
Web Site
www.atmel.com
Literature Request
www.atmel.com/literature
Disclaimer: The information in this document is provided in connection with Atmel products. No license, express or implied, by estoppel or otherwise, to any
intellectual property right is granted by this document or in connection with the sale of Atmel products. EXCEPT AS SET FORTH IN ATMELS TERMS AND
CONDITIONS OF SALE LOCATED ON ATMELS WEB SITE, ATMEL ASSUMES NO LIABILITY WHATSOEVER AND DISCLAIMS ANY EXPRESS, IMPLIED
OR STATUTORY WARRANTY RELATING TO ITS PRODUCTS INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTY OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
CONSEQUENTIAL, PUNITIVE, SPECIAL OR INCIDENTAL DAMAGES (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF PROFITS,
BUSINESS INTERRUPTION, OR LOSS OF INFORMATION) ARISING OUT OF THE USE OR INABILITY TO USE THIS DOCUMENT, EVEN IF ATMEL HAS
BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. Atmel makes no representations or warranties with respect to the accuracy or completeness of the
contents of this document and reserves the right to make changes to specifications and product descriptions at any time without notice. Atmel does not make any
commitment to update the information contained herein. Unless specifically provided otherwise, Atmel products are not suitable for, and shall not be used in,
automotive applications. Atmels products are not intended, authorized, or warranted for use as components in applications intended to support or sustain life.
2009 Atmel Corporation. All rights reserved. Atmel , Atmel logo and combinations thereof, AVR, AVR Studio and others, are the
registered trademarks or trademarks of Atmel Corporation or its subsidiaries. Windows and others are registered trademarks or trademarks of
Microsoft Corporation in the U.S. and or other countries. Other terms and product names may be trademarks of others.
32126A-AVR32-06/09