View detail for ATmega32M1 on MC320

APPLICATION NOTE
BLDC/BLAC Motor Control Using a Sinus Modulated
PWM Algorithm with Atmel ATmega32M1
ATMEGA32M1 ON MC320
Features
● ATAVRMC300 Power Stage Board
● 1 ATAVRMC310 Device Board for the Atmel® ATmega32M1 AVR® Microcontroller
● 12V BLDC Motor Control with Sinus Waveform
● ISP and Emulator Interface
Figure 1.
Demo Kit MC320
9276B-AVR-04/15
1.
Introduction
Equipped with Hall effect sensors, permanent magnet motors are generally powered by currents of 'trapezoidal' shape
(Figure 1-1a). In order to improve the system's performance (less noise, less torque ripple) it can be an advantage to power
these motors using currents that have a ‘sinusoidal’ form (Figure 1-1b). BLDC motors are designed to be supplied with a
trapezoidal shape current and BLAC motors are designed to be supplied with a sinusoidal shape current. This Application
Note proposes implementation using the latter with an MC320 board mounted with an Atmel ATmega32M1.
Figure 1-1. 3 Phases Output Voltages vs. Hall Sensor Inputs
Hall Sensors
3 Phase Voltage
a: 3 Phase Trapezoidal Voltage
2
ATmega32M1 on MC320 [APPLICATION NOTE]
9276B–AVR–04/15
b: 3 Phase Sinusoidal Voltage
2.
Operating Principle
2.1
Introduction
This implementation is based on the use of the Space-Vector Modulation (SVPWM) technique. The different sectors are
determined and synchronized with the Hall sensors.
2.2
Principle of the Space-Vector Modulation
Figure 2-1. Typical Structure of the Application
Sa+
Sb+
Sc+
BLDC Motor
Va
Neutral
Vb
E
Vn
Vc
Hall Sensors
Sa-
Sb-
Sc-
Rotor
Position
Figure 2-1 shows the typical structure of a BLDC/BLAC motor connected to a voltage source inverter. The motor is
considered to have a balanced load with an unconnected neutral as follows:
Vn = (Va + Vb + Vc)/3
Van =Va – Vn = (Vab – Vca)/3
Vbn =Vb – Vn =(Vbc – Vab)/3
Vcn =Vc – Vn = (Vca – Vbc)/3
Because the upper power switches can only be ON or OFF, and because the lower ones are supposed to always be in the
opposed state (the dead times of the inverter legs are neglected), there are only eight possible switching states, as shown in
Table 2-2 on page 5. Six of them lead to non-zero phase voltages, and two interchangeable states lead to zero phase
voltages. When mapped in a 2D frame fixed to the stator using a Concordia transformation [1,2], the six non-zero phase
voltages form the vertices of a hexagon (see Figure 2-3 on page 4).
V
V
=
1 1
1 – --- – --2 2
3
3
0 ------- – ------2
2
V an
= V bn
V cn
ATmega32M1 on MC320 [APPLICATION NOTE]
9276B–AVR–04/15
3
Figure 2-2. Possible Switching Configurations of a 3-phase Inverter
S0 = 000
S1 = 001
S2 = 010
S3 = 011
S4 = 100
S5 = 101
S6 = 110
S7 = 111
As shown in Figure 2-3, the angle between two successive non-zero voltages is always 60°. In complex form, these nonzero phase voltages can be written as
V k = Ee

j   k – 1   --3
, with k = 1 to 6 and V0 = V7 = 0V.
Table 2-1 on page 5 shows the line-to-line and line-to-neutral voltages in each of the eight possible configurations of the
inverter.
Figure 2-3. Representation of Eight Possible Switching Configurations in the Concordia Reference Frame
β
V3
V2
2
1
3
Vβ
d2V2
VS
V1
V4
d1V1
4
Vα
6
5
V5
4
ATmega32M1 on MC320 [APPLICATION NOTE]
9276B–AVR–04/15
V6
α
Table 2-1.
Switching Configurations and Output Voltages of a 3-phase Inverter
Sa+
Sb+
Sc+
Si
Vab
Vbc
Vca
Van
Vbn
Vcn
Vα
Vβ
Vi
0
0
0
S0
0
0
0
0
0
0
0
0
VO
0
0
1
S1
0
–E
E
–E/3
–E/3
+2E/3
–E/2
– E 3/2
V5
0
1
0
S2
–E
E
0
–E/3
+2E/3
–E/3
–E/2
E 3/2
V3
0
1
1
S3
–E
0
E
–2E/3
–E/3
–E/3
–E
0
V4
1
0
0
S4
E
0
–E
+2E/3
–E/3
–E/3
E
0
V1
1
0
1
S5
E
–E
0
E/3
–2E/3
E/3
E/2
– E 3/2
V6
1
1
0
S6
0
E
–E
E/3
E/3
–2E/3
E/2
E 3/2
V2
1
1
1
S7
0
0
0
0
0
0
0
0
V7
Table 2-2.
Expression of the Duty Cycles in Each Sector
Sector Number
θ
dk
dk+1
1

0, --3
VS
2- -----
----- -  sin  --- – 
3
3 E
VS
2- ---------- -  sin   
3 E
2

--- , 2
-----3 3
VS
2- -----
----- -  sin  --- + 
3
3 E
VS
2- -----5
----- -  sin  ------ + 
3
3 E
3
2
------ ,
3
VS
2- ---------- -  sin   
3 E
VS
2- -----4
----- -  sin  ------ + 
3
3 E
4
4
, -----3
VS
2- -----5
----- -  sin  ------ + 
3
E
3
VS
2- ---------- -  sin  2 –  
3 E
5
4
------ , 5
-----3 3
VS
2- -----4
----- -  sin  ------ + 
3
3 E
VS
2- -----
----- -  sin  --- – 
3
3 E
6
5
------ ,2
3
VS
2- ---------- -  sin  2 –  
3 E
VS
2- -----
----- -  sin  --- + 
3
3 E
In the Concordia frame, any stator voltage VS = Vα + jVβ = Vsm cos(θ) + jVsm sin(θ) located inside this hexagon belongs to
one of the six sectors and can be expressed as a linear combination of the two non-zero phase voltages which delimit this
sector: VS = dkVk + dk+1Vk+1. Equating dkVk + dk+1Vk+1 to Vsm cos(θ) + jVsm sin(θ) in each sector leads to the expressions of
the duty cycles shown in Table 2-2. Because the inverter cannot generate instantaneously the space vector PWM principle
consists in producing a TS-periodic voltage whose average value equals VS, by generating Vk during Tk = dkTs and Vk+1
during Tk+1 = dk+1Ts. Because dk + dk+ ≤ 1, these voltages must be completed over the switching period Ts by V0 and/or V7.
Several solutions are possible, and the one which minimizes the total harmonic distortion of the stator current consists in
applying V0 and V7 during the same duration
1 – d k – d k+1
T 0 = T 7 = -------------------------------  T s
2
V0 is also applied at the beginning and at the end of the switching period, whereas V7 is applied at the midpoint. As an
illustration, the upper side of Figure 2-4 on page 6 shows the waveforms obtained in sector 1.
ATmega32M1 on MC320 [APPLICATION NOTE]
9276B–AVR–04/15
5
2.3
Efficient Implementation of the SV-PWM
Table 2-2 on page 5 indicates that the duty cycles have different expressions in each sector. A thorough study of these
expressions show that because sin(x) = sin(π – x) all these duty cycles can be written in a unified way as
2V sm
2V sm


d k = ------------- sin    and d k+1 = ------------- sin    , with  = --- –  and  =  –  k – 1  ---- .
3
3
E 3
E 3
Because these expressions no longer depend on the sector number, they can be denoted as da and db. Because θ’ is always
between 0 and π/3, computing da and db requires a sine table for angles inside this interval only. This greatly reduces the
amount of memory required to store this sine table.
The Atmel ATmega32M1 provides the 3 Power Stage Controllers (PSC) needed to generate the switching waveforms
computed from the space vector algorithms.
The counters will count from zero to a value corresponding to one-half of the switching period (as shown on the lower side of
Figure 2-4), and then count down to zero. The values that must be stored in the three compare registers are given in Table 23 on page 7.
Figure 2-4. Inverter Switch Waveforms and Corresponding Compare Register Values
TS
T0/2
T1/2
T2/2
V0
V1
V2
T7/2
T7/2
V7
T2/2
T1/2
T0/2
V2
V1
V0
Sa+
Sb+
Sc+
TS/2
Cc
Cb
Ca
t
TS
6
ATmega32M1 on MC320 [APPLICATION NOTE]
9276B–AVR–04/15
Table 2-3.
2.4
Compare Register Values vs. Sector Number
Sector Number
4/Ts Ca – 1
4/Ts Cb – 1
4/Ts Cc – 1
1
–da – db
da – db
da + db
2
–da + db
–da – db
da + db
3
da + db
–da – db
da – db
4
da + db
–da + db
–da – db
5
da – db
da + db
–da – db
6
–da – db
da + db
–da + db
Sector Determination Algorithm
The sector determination is based on readings from the three Hall sensors. All along one electrical revolution, the three Hall
sensors generates six steps. These six steps divide the circle into six sectors which are used in the SVPWM (see Figure 25).
Figure 2-5. Sector Determination
Hall Event
Hall Value
a
b
d
n
m
Counter CU
c
p
e
q
f
r
s
0
0
0
0
0
0
m
n
p
q
r
s
Counter CD
Sector 6
Sector 1
Sector 2
Sector 3
Sector 4
Sector 5
Sector 6
Inside one sector the counter CU is incremented at a rate given by a high frequency reference clock. At the end of the sector
the counter CU is copied into the counter CD. Then this counter CD is decremented by the same reference rate. This
counter CD reflects the value of the angle ϑ of Vs vector inside a sector (see Figure 2-6 on page 8). For example, during
sector 1 counter CU is incremented from 0 to n. At Hall event counter CU is copied into counter CD. Then during sector 2
counter CU is incremented and counter CD is decremented. Counter CD drives the rotation of the vector Vs (see Figure 2-6
on page 8).
ATmega32M1 on MC320 [APPLICATION NOTE]
9276B–AVR–04/15
7
Figure 2-6. Rotation of Vs Vector
n
UC
p
p
0
V3
2
0
n
V2
CU
CU
CD
Vs
3
1
ϑ
q
0
V4
V1
0
m
m
6
CU
4
CU
q
5
r V5
0
CU
V6
s 0
s
r
Figure 2-7 shows the data flow of the implementation of this SVPWM core. The Hall sensors indicate the sector number and
the two angles ϑ' and ϑ''. These angles point to a sine table. The sine value is multiplied by the voltage to calculate da and db.
Then da and db are used to determine the compare values sent to the PSC (see Figure 2-4 on page 6).
Figure 2-7. Space Vector PWM Data Flow Diagram
2V sm
Voltage
E
Demux
3
da
Hall
Sensors
Ɵ‘
Sector
and
angle
Ɵ”
determination
X
Sine
Table
Direction
8
ATmega32M1 on MC320 [APPLICATION NOTE]
9276B–AVR–04/15
Ca
db
Compare
register
values
determination
Cb
Cc
The resulting dataflow diagram, shown on Figure 2-7 on page 8, can be used to build a speed control loop (Figure 2-8 on
page 9) in which the difference between the desired speed and the measured speed feeds a PI controller that determines
the stator voltage frequency.
Figure 2-8. Block Diagram of the Complete System
Reference
Voltage
PI
SVPWM
Sector
Determination
PSC
Inverter
Motor
Hall Sensors
Speed
ATmega32M1 on MC320 [APPLICATION NOTE]
9276B–AVR–04/15
9
3.
Hardware Description
This application is available on the MC320 evaluation kit equipped with an Atmel ATmega32M1. This board provides a way
to start and experiment with BLDC and BLAC motor control. The main features of the MC320 are:
● Atmel ATmega32M1 microcontroller
●
●
12VDC motor drive
ISP and emulator interface
Figure 3-1. Connecting the BLDC Motor
Table 3-1.
10
Signals
J7 Signals
Motor Wires
U
Thin yellow
V
Thin red
W
Thin black
X
Not connected
Vn
Not connected
H1
Thin blue
H2
Thin green
H3
Thin white
VHa
Thin red
GND
Thin black
ATmega32M1 on MC320 [APPLICATION NOTE]
9276B–AVR–04/15
4.
Software Description
All algorithms have been written in the C language using IAR Embedded Workbench® and AVR Studio® as development
tools. For the space vector PWM algorithm, a table of the rounded values of
2k
127sin  ----------
 480 
for k between 0 and 80 is used. The length of this table (81 bytes) is a better trade off between the size of the available
internal memory and the quantification of the rotor shaft speed. For bi-directional speed control, the values stored in two of
the comparators are interchanged when the output of the PI regulator is a negative number (see Figure 2-8 on page 9).
4.1
Project Description
In Figure 4-1 the flow chart of the main routine is described. In the main() all the necessary modules are initialized and in the
while(1) endless circle the value of the potentiometer is updated based on the Timer0 compare interrupt. The value of the
potentiometer is used to control the motor, including the running direction and the speed.
Figure 4-1. Flow Chart of Main()
Main()
Init()
// Initialize the ports of ATmega32M1
// Initialize the ADC and read the value
of POTI to control the speed
ADC_init_POT()
// Initialize the PSC module
PSC_init()
// Initialize the motor driver parameters
to be prepared for the timer interrupt and
the generation of the sinus waveform
mci_forward()
mci-run()
no
no
Main_Tick = 1?
// Controlled by TIMER 0_COMPA_vect
Main_Tick = 0
Start_ADC()
// In the ADC_vect the variable Flag_IT_ADC
is set
Flag_IT_ADC = 1?
yes
a = read_acquisition()
a >0x210
mci_backward()
store_new amplitude(a)
mci_run()
(a >0x190) &&
(a <0x210)
mci_stop()
// Get the poti value from the ADC register
a <0x190
mci_forward()
a = 0x400-a
store_new amplitude(a)
mci_run()
// According to the a
value control the motor
running direction and
the amplitude of the
PWM
ATmega32M1 on MC320 [APPLICATION NOTE]
9276B–AVR–04/15
11
While the motor is running the comparator interrupts ANA_COMPn_vect and the timer0 A compare interrupts
TIMER0_COMPA_vect play the most important role. The comparator interrupts are triggered by the Hall sensor signals to
indicate the commutation time point. The timer0 A compare interrupts calculate the two variables tau1 and tau2 through the
variables Sensor_Counter_Down, in order to select the corresponding values from the sinusoidal table. The following Figure
4-2 shows how the algorithm works.
Figure 4-2. Motor State Commutation
ANA_COMPn_vect
ANA_COMPn_vect
TIMER0_COMPA_vect
TIMER0_COMPA_vect
TIMER0_COMPA_vect
.......
Do_Sensor_Interrupt () is called
to prepare for the new motor state.
If the variable Delay_For_Change
does not equal to 0, that means the
motor state should be forced to the
next state, with some variables
initialized. At the same time the
variable Mem_Top_Counter should
be filtered here and
Sensor_Counter_Up is reset for
the coming motor state. The
corresponding Hall signals are read
and Delay_For_Change is updated
for the next state.
4.2
If the variable Delay_For_Change
does not equal to 0, the variable is
decreased by 1. If Delay _For_ Change
equals to 0, one sinus cycle is over
before the hall signals are updated,
which means the sinus cycle should
begin again by resetting the corresponding
variables. The variables
Sensor_Counter_Up increases
and Sensor_Counter_Down decreases step
by step according to the Figure 2-8. The
Sensor_Counter_Down is used to calculate
the ta1 and the ta2, which are useful to determine
the PWM values tau1 and tau2 with the help of
the sinus table. Referring to the running direction
and the actual motor state, the PWM1,2,3 are
calculated and applied.
Resources
The values include all the application resources (main, serial communication,...)
2 472 bytes of CODE memory
1 684 bytes of DATA memory
Timer 0 is used for speed measurement/main tick/svpwm
Timer 1 is not used
PSC0, 1, and 2 are used to generate PWM
ADC is used for current measurement. It is synchronized by PSC on the PWM waveform.
12
ATmega32M1 on MC320 [APPLICATION NOTE]
9276B–AVR–04/15
4.3
Experimentation
Figure 4-3 shows the voltage and the sinusoidal current on the U motor phase. With the SV-PWM algorithm presented
above the sinus waveform BLDC motor control can be realized flawlessly on the MC320 with the Atmel ATmega32M1.
Figure 4-3. Voltage and Current on the U Motor Phase
ATmega32M1 on MC320 [APPLICATION NOTE]
9276B–AVR–04/15
13
5.
Revision History
Please note that the following page numbers referred to in this section refer to the specific revision mentioned, not to this
document.
14
Revision No.
History
9276B-AVR-04/15
Put document in the latest template
ATmega32M1 on MC320 [APPLICATION NOTE]
9276B–AVR–04/15
XXXXXX
Atmel Corporation
1600 Technology Drive, San Jose, CA 95110 USA
T: (+1)(408) 441.0311
F: (+1)(408) 436.4200
|
www.atmel.com
© 2015 Atmel Corporation. / Rev.: 9276B–AVR–04/15
Atmel®, Atmel logo and combinations thereof, Enabling Unlimited Possibilities®, AVR®, and others are registered trademarks or trademarks of Atmel Corporation in U.S.
and other countries. Other terms and product names may be trademarks of others.
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 THE ATMEL TERMS AND CONDITIONS OF SALES LOCATED ON THE
ATMEL WEBSITE, 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 AND 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 products 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. Atmel products are not intended,
authorized, or warranted for use as components in applications intended to support or sustain life.
SAFETY-CRITICAL, MILITARY, AND AUTOMOTIVE APPLICATIONS DISCLAIMER: Atmel products are not designed for and will not be used in connection with any applications where
the failure of such products would reasonably be expected to result in significant personal injury or death (“Safety-Critical Applications”) without an Atmel officer's specific written
consent. Safety-Critical Applications include, without limitation, life support devices and systems, equipment or systems for the operation of nuclear facilities and weapons systems.
Atmel products are not designed nor intended for use in military or aerospace applications or environments unless specifically designated by Atmel as military-grade. Atmel products are
not designed nor intended for use in automotive applications unless specifically designated by Atmel as automotive-grade.