Application Note: Atmel AVR1636: Configurable PMSM Sensorless Field Oriented Control Using The XMEGA
Application Note: Atmel AVR1636: Configurable PMSM Sensorless Field Oriented Control Using The XMEGA
Application Note: Atmel AVR1636: Configurable PMSM Sensorless Field Oriented Control Using The XMEGA
Features
Introduction
This application note describes the implementation and use of a configurable 3-phase
permanent magnet synchronous motor (PMSM) kit using the ATxmega16D4
microcontroller implementing sensorless field oriented control (FOC). The complete
kit includes a 12V 3-phase PMSM, an ATxmega16D4 processor board, and a low
voltage motor control board, a USB-to-UART bridge cable, a 12V universal power
adapter, the firmware running on the ATxmega16D4, and a PC based configuration
utility.
42061A−AVR−01/2013
Table of Contents
Atmel AVR1636: Configurable PMSM Sensorless Field Oriented Control using the XMEGA
[APPLICATION NOTE] 2
42061A−AVR−01/2013
1. Theory of operation
1.1 Overview
This application note covers the description and use of a complete 3-phase PMSM sensorless FOC system.
After reading this document the reader should have an understanding of the system hardware, firmware, and
configuration utility.
1.2 Hardware
The hardware consists of a complete motor control system. The system is composed of a 3-phase PMSM, an Atmel
ATxmega16D4 processor board, an Atmel low voltage motor control board, a USB-to-UART bridge cable and a 12V
universal power adapter.
1.3 Firmware
The firmware running on the ATxmega16D4 provides the control structure for PMSM sensorless FOC. The sensorless
control technique uses back EMF calculation to form a back EMF phase locked loop (PLL). Speed control is provided by
a proportional integral (PI) controller. The back EMF sensing PLL, the current regulators, and the speed control loop
require configuration and tuning. This is covered in Chapter 3.
2. System details
2.1 Hardware
The hardware consists of the 3-phase PMSM, the ATxmega16D4 processor board, the low voltage motor control board,
the USB-to-UART bridge cable, and the 12V universal power adapter as shown if Figure 2-1.
USB
PC to ATxmega16D4
UART processor 3
bridge board 3-phase
PMSM
AC Atmel
Universal 12V 2.5A
low voltage motor control
power
outlet board
adapter
Atmel AVR1636: Configurable PMSM Sensorless Field Oriented Control using the XMEGA
[APPLICATION NOTE] 3
42061A−AVR−01/2013
2.1.1 3-phase PMSM
The 3-phase PMSM consists of a 3-phase 8-pole permanent magnet synchronous motor. The three motor leads,
consisting of one red, one black and one yellow 20 AWG wire, are brought out for connection to the low voltage motor
control board. The motor includes three Hall sensors leads plus a common sensor power and ground. These five 28
AWG wires can be left disconnected since they are not used in the sensorless algorithm.
The motor shown in Figure 2-2 is rated for 4,000 rpm at 12VDC input, the full motor specification can be found
in Appendix C.
Atmel AVR1636: Configurable PMSM Sensorless Field Oriented Control using the XMEGA
[APPLICATION NOTE] 4
42061A−AVR−01/2013
The low voltage motor control board can be configured for up to 48V nominal input voltage and 12A rms output per
phase depending on component selection. The configuration shown in Figure 2-3 and the schematics shown
in Appendix B are for the board configured for 11 to 15VDC input range and a peak output current of 6A rms.
Figure 2-3. Low voltage motor control board and an Atmel ATxmega16D4 processor board.
Atmel AVR1636: Configurable PMSM Sensorless Field Oriented Control using the XMEGA
[APPLICATION NOTE] 5
42061A−AVR−01/2013
2.1.5 Universal power adapter
The universal power adapter provides 12V for powering the demo board. The adapter is rated for 2.5A at 12V. The AC
power adapter uses a removable AC power connector for international use.
2.2 Firmware
The firmware was designed to run on the Atmel ATxmega16D4 to demonstrate a configurable motor control application
driving 3-phase PMSM with sensorless FOC.
The sensorless control algorithm updates at a rate of 128µs (7812.5Hz) this can provide sinusoidal current regulation
above 500Hz. The back EMF PLL is always enabled for robust operation that provides automatic motor starting or
recovery of the motor speed after a stall condition.
Atmel AVR1636: Configurable PMSM Sensorless Field Oriented Control using the XMEGA
[APPLICATION NOTE] 6
42061A−AVR−01/2013
Figure 2-6. Control structure.
d,q α,β
i_d_ref + i_d v_d v_a
0
Regulator v_b
PWMs
- v_c
PWM
i_q_ref
3 6
Speed Speed + i_q v_q
command Regulator Regulator
α,β a,b,c
-
Event
System
theta Back EMF
Calculation v_bus DC
speed and Bus
PLL ADC
Current
Shunt
USB
to i_sample_1
d,q α,β i_a
UART i_d i_sample_2
Bridge i_b
Serial i_c 3 phase
Communication current
2 reconstruction
3
i_q
α,β a,b,c
The field orientation to the air gap flux linkage is established by coordinate transformation (Clark transform) and vector
rotation (Park transformation) using the correct angle (theta) between a fixed reference point on the motor’s stator and
the actual air gap flux represented as a vector. This can be visualized by Figure 2-7.
Atmel AVR1636: Configurable PMSM Sensorless Field Oriented Control using the XMEGA
[APPLICATION NOTE] 7
42061A−AVR−01/2013
Figure 2-7. Air-gap flux linkage angle, theta.
The sensorless field oriented control is based on calculating the back EMF from stator currents and voltages, then
transforming the back EMF into the d-q reference frame that is reference by the air gap flux linkage, Figure 2-8. The
back EMF phase locked loop uses d-axis back EMF as the phase error detector, since perfect lock should produce zero
d-axis back EMF. This is based on the fact that back EMF is perpendicular to the flux linkage that generates it.
Atmel AVR1636: Configurable PMSM Sensorless Field Oriented Control using the XMEGA
[APPLICATION NOTE] 8
42061A−AVR−01/2013
Figure 2-8. Back EMF calculation and PLL.
Atmel AVR1636: Configurable PMSM Sensorless Field Oriented Control using the XMEGA
[APPLICATION NOTE] 9
42061A−AVR−01/2013
2.2.3 ISR routine
There is one main interrupt service routine (ISR) based off the PWM port C timer 0, triggered every 32µs. The timer
interrupt triggers an analog to digital (ADC) conversion used for single shunt current reconstruction and the ISR. The
ISR updates PWM, serial communication, and the FOC routines. Each ISR executes one fourth of the FOC routines,
giving a 128µs update rate for the complete FOC control loop. Figure 2-10, shows the PWM ISR flow.
The field oriented control routines are further broken down into three functions:
1. The back EMF phase locked loop.
2. The vector control and regulator blocks.
3. The PWM control and current reconstruction.
Each function is split between the four ISRs as shown in Figure 2-11.
Atmel AVR1636: Configurable PMSM Sensorless Field Oriented Control using the XMEGA
[APPLICATION NOTE] 10
42061A−AVR−01/2013
Figure 2-11. Field oriented control routines.
Atmel AVR1636: Configurable PMSM Sensorless Field Oriented Control using the XMEGA
[APPLICATION NOTE] 11
42061A−AVR−01/2013
2.2.4 Communication
Serial communication to the firmware allows configuration of motor control parameters stored in the EEPROM and to
allow data collection during tuning and configuring of the firmware.
A USB-to-UART bridge is used to communicate with a PC running the configuration utility.
Atmel AVR1636: Configurable PMSM Sensorless Field Oriented Control using the XMEGA
[APPLICATION NOTE] 12
42061A−AVR−01/2013
2.3.3 Variables
Variables from the firmware are sent to the configuration utility at the rate of approximately once per 123ms. The list of
variables was chosen as the most useful for configuration and tuning of the motor.
2.3.5 Parameters
The parameter list of values are also updated once every 123ms along with the variable list. During the configuration
and tuning process, new values can be sent to the microprocessor and the new values will be reflected in the 123ms
update. Updated parameters are stored in RAM so they are reset back to the EEPROM values after cycling power. To
store updated values the EEPROM the program button must be pressed.
3.1 Hardware
The system is connected as shown in Figure 3-1. Initially the Atmel ATxmega16D4 processor board can be powered
directly from the USB port, this powers up the ATxmega16D4 allowing communication with the configuration utility
without running the motor.
Atmel AVR1636: Configurable PMSM Sensorless Field Oriented Control using the XMEGA
[APPLICATION NOTE] 13
42061A−AVR−01/2013
Figure 3-1. Configurable 3-phase PMSM with a USB-to-UART bridge and universal power adapter connected.
Note: gold
contacts
facing up.
The PMSM phase leads are connected to the 3-pin connector J2. The motor phase leads are the 20 AWG black, red,
and yellow wires from the motor. The five 28 AWG wires are Hall sensors connections not used in this application, so
they should be left unconnected. Connecting the motor phase leads in the order shown in Figure 3-2 provides clockwise
rotation for a positive command and counter clockwise rotation for a negative command. Swapping any two phases
reverses the rotation direction for positive and negative commands.
Figure 3-2. PMSM phase leads phases a, b and c from top to bottom.
a
b
c
Atmel AVR1636: Configurable PMSM Sensorless Field Oriented Control using the XMEGA
[APPLICATION NOTE] 14
42061A−AVR−01/2013
DC input voltage is connected to J3 shown in Figure 3-3. The DC input range is from 0 to 15V. The gate drive ICs (U1
to U3 from Appendix B) provide an under voltage lockout below approximately 10.1V so a supply of at least 12V
nominal is recommended to run the motor. 12V power can be supplied from the universal power adapter or a variable
lab supply can be used that is capable of supplying 12V and 2.5A.
Figure 3-3. DC bus voltage input leads +Vbus and –Vbus from top to bottom.
+Vbus
-Vbus
3.2 Firmware
The following instructions are for the Atmel ATxmega16D4 processor boards that do not have firmware preinstalled or
are going to be upgraded from a previous version of firmware. This section can be skipped if firmware is already
installed. Firmware needs to be installed on the ATxmega16D4 before using the configuration utility and parameters
need to be stored in the EEPROM for the motor to run properly. There are provisions for downloads of firmware and
fuse settings through the standard six pin header, J3 using many of the common programming tools and the latest
version of Atmel Studio. Firmware can be installed using the following steps:
1. Download the AVR1636 - Firmware project.
2. Plug in USB-to-UART cable to provide 5V power to the ATxmega16D4 processor board while noting the
polarity of the connector from Figure 3-1 since this connector is not keyed.
Warning: It is good practice to not supply power to the DC bus on the low voltage motor control board while updating
firmware.
3. Connect the programmer to PC through USB connector and connect programmer ribbon cable to P1, match up
pin 1 PCB, marked by a square pad, with pin 1 on ribbon connector since the connector is not keyed.
4. Bring up latest version of Atmel Studio, example is shown with Atmel Studio 6 at the time of this writing. If you
are using a newer version of Atmel Studio, start a new C project using the GCC compiler option and select the
ATxmega16D4. Add the downloaded version of AVR1636 - Firmware.c to the project and remove the project
generated .c source file. This project is written for the GCC compiler as a single file: AVR1636 - Firmware.c
so it is easily added into a newer project.
5. Select the GCC Compiler optimization to –O2.
6. Build the solution by pressing CTRL+SHIFT+B and check for compiling errors.
9. Download the firmware by pressing the start without debugging button.
The firmware should now be running. The EEPROM parameters can be set using the configuration utility.
Atmel AVR1636: Configurable PMSM Sensorless Field Oriented Control using the XMEGA
[APPLICATION NOTE] 15
42061A−AVR−01/2013
3.3.1 Running the configuration utility
The configuration utility comes as a compressed zip file. The zip file should be extracted at the root directory (C:\). The
folder contains the executable file Atmel Motor Control Configuration Utility ver1_4_0.exe along with support files. There
is no Windows® installation, just run the .exe file.
A message in the variable plot window appears requesting that a COM port should be selected as shown in Figure 3-4.
Use the drop down box to select the COM port.
Select COM
port.
Select
Application
configuration.
Figure 3-5 shows an example of COM port four selected. If the COM port is unknown it can be found in the Windows
start menu under Settings → Control Panel → System → Hardware → Device Manager → Ports (COM & LPT) you
should see a USB serial port (COMx), where x is the port number. After selecting the COM port, the application
configuration should be selected for AVR1636. This presents the proper variable and parameter list labels in the
configuration utility.
Atmel AVR1636: Configurable PMSM Sensorless Field Oriented Control using the XMEGA
[APPLICATION NOTE] 16
42061A−AVR−01/2013
Figure 3-5. COM port and application configuration boxes after selection.
If the variable plot is not displaying counter, then the counter function is selected to the variable plot screen by
pressing the counter button, Figure 3-8.
Atmel AVR1636: Configurable PMSM Sensorless Field Oriented Control using the XMEGA
[APPLICATION NOTE] 17
42061A−AVR−01/2013
The variable plot and updates of variables and parameters can be stopped using the radio buttons shown in Figure 3-9.
This can be used to freeze data on the plot area, to read variables, and for capturing data to be saved to a file.
When selecting a variable for plotting the selected variable location in the list, name and description are displayed in the
variable information window, Figure 3-10.
The complete list of 16 variables is shown in Figure 3-11. The configuration utility just displays raw 8-bit values and
does not differentiate between signed and unsigned values. The first 11 variables are signed values in the firmware, but
are transmitted to the utility with the zero point offset by 128, so that positive values are greater than 128 and negative
values are less than 128.
Atmel AVR1636: Configurable PMSM Sensorless Field Oriented Control using the XMEGA
[APPLICATION NOTE] 18
42061A−AVR−01/2013
Figure 3-11. The variable list.
Atmel AVR1636: Configurable PMSM Sensorless Field Oriented Control using the XMEGA
[APPLICATION NOTE] 19
42061A−AVR−01/2013
Variable Description Use
i_q q-axis current perpendicular with air gap Used to verify current regulator is controlling torque producing
flux. component of current.
e_d d-axis component of Back EMF. Value driven to zero (=128) by back EMF PLL.
v_bus DC input voltage. Raw ADC sample of DC bus voltage. Using in calculation of
u_a.
speed Motor speed. Used to watch motor speed especially useful in back EMF PLL
tuning. speed is a signed number so 128 = zero speed.
Positive values are above 128, negative numbers are below
128.
theta Rotor angle Integral of speed. Determines angle of air gap flux.
osc_error Oscillator error Used for testing oscillator calibration against USB-to-UART
cable oscillator. osc_error is a signed number so 128 = zero
error. Positive values are above 128, negative numbers are
below 128. An invalid value = 0 is displayed before an
oscillator test has been performed. The test button must be
pressed to display a valid result.
counter Up/down counter. Used to indicate connection between configuration utility and
firmware.
Atmel AVR1636: Configurable PMSM Sensorless Field Oriented Control using the XMEGA
[APPLICATION NOTE] 20
42061A−AVR−01/2013
Figure 3-12. The parameter list.
Atmel AVR1636: Configurable PMSM Sensorless Field Oriented Control using the XMEGA
[APPLICATION NOTE] 21
42061A−AVR−01/2013
Table 3-2. Parameter list description and use.
Atmel AVR1636: Configurable PMSM Sensorless Field Oriented Control using the XMEGA
[APPLICATION NOTE] 22
42061A−AVR−01/2013
Parameter Description Use
p_gravity Back EMF PLL regulator gravity term. Amount of negative error added into the back EMF PLL.
Used to force the speed down to speed_min when the PLL
is not locked onto the back EMF. This is used at startup or
during a stall condition.
u_scaling Phase voltage scaling parameter. Used to set scaling of phase voltage in back EMF
calculator. See section on back EMF Calculator.
r_scaling Phase resistance scaling parameter. Used to set scaling of phase resistance in back EMF
calculator.
r_phase Phase resistance. Phase resistance, ohms per count determined by u_scaling
and r_scaling.
l_scaling Phase inductance scaling parameter. Used to set scaling of phase inductance in back EMF
calculator.
l_phase Phase inductance. Phase inductance, henries per count determined by
u_scaling and l_scaling.
The copy all buttons shown in Figure 3-13 provides a quick method to transfer all the variables between the
configuration utility and the Atmel ATxmega16D4.
The white boxes on the far right column of Figure 3-12 are for editing and transferring data between the configuration
utility and files. The file transfer is a simple file saves or file load (Figure 3-14) to a text file EEPROM.txt that is stored in
the same directory that the configuration utility is launched. Backups of this file must be copied and renamed to prevent
overwriting from the utility. The default EEPROM.txt from the download should contain the parameters values
from Figure 3-12, this can be used to load the correct values.
To transfer the parameters stored in RAM back to the EEPROM the program button is pressed, this will ensure that the
values are preserved and are used as the default values next time the application is powered up, Figure 3-15.
Atmel AVR1636: Configurable PMSM Sensorless Field Oriented Control using the XMEGA
[APPLICATION NOTE] 23
42061A−AVR−01/2013
Figure 3-15. Program parameters in EEPROM.
The parameter input_cmd is used for directly sending a voltage, current, or speed command. The input_cmd
parameter is shown in Figure 3-16. The command can be directly modified using the input box on the right and then
pressing the arrow key in the middle.
Note: This only transfers the value to the RAM of the Atmel ATxmega16D4 and the program button still needs to be
pressed to commit the RAM values to EEPROM.
When the arrow key is pressed a description of the parameter shows up in the parameter information box, Figure 3-17.
Atmel AVR1636: Configurable PMSM Sensorless Field Oriented Control using the XMEGA
[APPLICATION NOTE] 24
42061A−AVR−01/2013
3.3.5 Oscillator calibration
The oscillator calibration can be checked by pressing the test button as shown is in Figure 3-18. The internal oscillator
is compared with the USB-to-UART cable oscillator which has an oscillator accuracy of better than 0.2%. See the Atmel
ATxmega16D4 datasheet for further details about oscillator calibration.
Once the calibration button is pressed the osc_error, Figure 3-19, variable is updated. The error is centered around 128.
This means a value of 128 = zero error. A number above 128 means the oscillator is running slower than the reference
value and a number below 128 means the oscillator is running faster than the reference value. When first launching the
configuration utility, the osc_error value starts out with an invalid value of 0 so a test must be performed to get a valid
reading.
The oscillator calibration can be adjusted by updating the osc_cal_adj parameter, Figure 3-20, and programming the
EEPROM. osc_cal_adj is a correction factor to the original factory calibration. The range of values is from 0 to 64,
where 32 correspond to 0 correction. If the osc_error indicate that the oscillator is running too fast you want to adjust it
down, by specifying an osc_cal_adj that is less than 32. Values from any value above 64 are ignored and only the
factory calibration is used.
The equation for Oscillator cal adjustment for osc_cal_adj < 65:
Equation 3-1
_ _ _ _ – 32
Figure 3-20. Oscillator calibration adjustment parameter, example for -15, adjustment to factory calibration.
Atmel AVR1636: Configurable PMSM Sensorless Field Oriented Control using the XMEGA
[APPLICATION NOTE] 25
42061A−AVR−01/2013
Table 3-3. Mode options.
For mode = 0, voltage mode, the control blocks used are shown in Figure 3-22. Voltage mode directly maps into the
input_cmd into the v_q variable. This mode is useful for initial tuning of the back EMF calculator and the back EMF PLL,
by eliminating any interaction with sensing and the speed and current regulators.
For mode = 1, current control mode, the control blocks used are shown in Figure 3-23. Current control mode set the
current reference i_q_ref to the input command and sets i_d_ref to 0. The setting of i_q_ref produces a torque
proportional to current, by regulation the torque producing component of stator current. The current regulators are
proportional integral (PI) controllers that can be tuned after the back EMF calculator and back EMF PLL are tuned.
Atmel AVR1636: Configurable PMSM Sensorless Field Oriented Control using the XMEGA
[APPLICATION NOTE] 26
42061A−AVR−01/2013
Figure 3-23. Mode = 1, current control mode (torque control).
For mode = 2, speed control mode, the control blocks used are shown in Figure 3-24. Speed control mode sets the
speed reference to the input command. The output of the speed regulator sets the motor toque by changing the i_q_ref
based on speed error. The speed regulator is a proportional integral (PI) controller that can be tuned after the current
regulators are tuned.
Atmel AVR1636: Configurable PMSM Sensorless Field Oriented Control using the XMEGA
[APPLICATION NOTE] 27
42061A−AVR−01/2013
3.3.7 Minimum bus voltage
The v_bus_min sets a threshold for the DC input voltage (v_bus) above which the control loops are enabled. This
prevents the speed and current regulators from winding up when the voltage is too low to properly control the motor
(due to lack of back EMF feedback signal). The scaling for v_bus and v_bus min is based on the v_bus divider and
the ADC scaling:
_ Equation 3-2
Where:
VDC = DC input voltage [volt]
Kbus = Scaling constant for variable v_bus [count/volt]
Equation 3-3
Where:
Dividerbus = Resistive divider on low voltage motor control board, Appendix B, R9 and R27.
ResolutionADC = ADC resolution used for calculation [count]
Vref = Voltage reference used for ADC [volt]
Using the values on the low voltage motor control board in Appendix B:
1
256 Equation 3-4
1 33.2
1
Equation 3-5
7.48
Atmel AVR1636: Configurable PMSM Sensorless Field Oriented Control using the XMEGA
[APPLICATION NOTE] 28
42061A−AVR−01/2013
The variables i_a and i_b, Figure 3-27, represent the measure phase current from single shunt current reconstruction
for phase a and phase b. The scaling for current is based on the current shunt value, external divider, and ADC
settings.
_ Equation 3-7
Where:
Ia = Phase a current [ampere]
Kcurrent = Scaling constant for variable i_a, i_b and i_c [counts/ampere]
Equation 3-8
Where:
Rshunt = Current sensing resistor on low voltage motor control board, Appendix B, R1 [Ω]
Dividercurrent = Resistive divider used for biasing ground referenced Rshunt voltage above ground on low voltage motor
control board, Appendix B, R29 and R14
ResolutionADC = ADC resolution used for calculation [count]
– – Equation 3-12
Where:
Ea = Phase a back emf [volt]
Ua = Phase a voltage [volt]
Ia = Phase a current [ampere]
Rphase = Phase resistance [ohm]
Lphase = Phase inductance [Henry]
The back EMF calculator for one of three phases with parameters is shown in Figure 3-28.
Atmel AVR1636: Configurable PMSM Sensorless Field Oriented Control using the XMEGA
[APPLICATION NOTE] 29
42061A−AVR−01/2013
Figure 3-28. Back EMF calculator one of three phases with parameters.
v_a
u_a
X ÷
v_bus
u_scaling
2
+
ir_a - e_a
X ÷
-
+
-1
i_a_last l_didt_a
z X ÷
-
l_phase l_scaling
2
The parameters in the back EMF calculator are shown in 0. These values need proper adjustment and scaling for
calculating the back EMF.
The scaled phase voltage, u_a, is determined by the following equation:
_ _
_ Equation 3-13
2 _
_ Equation 3-14
Where:
Ku = Scaling constant for variable u_a [count/volt]
Ua = Phase a voltage [volt]
_
Equation 3-15
2
Where:
Kbus = Scaling constant for variable v_bus [count/volts]
PWMmax = Maximum count for PWM timer [count]
2u_scaling = Scaling factor for voltage u_a, u_b, and u_c [count]
Atmel AVR1636: Configurable PMSM Sensorless Field Oriented Control using the XMEGA
[APPLICATION NOTE] 30
42061A−AVR−01/2013
The scaled resistive drop, ir_a, is determined by the following equation:
_ _
_ Equation 3-18
2 _
_ Equation 3-19
_
2
Equation 3-21
ohm
Where:
2r_scaling = Scaling factor for r_phase [count]
_ 36 Equation 3-26
_ _ Equation 3-28
Atmel AVR1636: Configurable PMSM Sensorless Field Oriented Control using the XMEGA
[APPLICATION NOTE] 31
42061A−AVR−01/2013
2_
Equation 3-30
Henry
Where:
2r_scaling = Scaling factor for r_phase [count]
freqloop = Frequency of FOC control loop [hertz]
Using the example values:
14.96 2 7812.5
Equation 3-31
11.6 Henry
_ 41 Equation 3-35
Phase a back EMF values are brought out as display variables to aid in tuning the parameters, Figure 3-30. These
values are signed numbers, so they are centered on the value 128 for display on the configuration utility.
The three phase back EMF goes through a Clarke and Park transform, Figure 3-31, for feedback to the back EMF
phase locked loop.
Atmel AVR1636: Configurable PMSM Sensorless Field Oriented Control using the XMEGA
[APPLICATION NOTE] 32
42061A−AVR−01/2013
Figure 3-31. Back EMF Clarke and Park transforms.
The d-axis component of back EMF, e_d is driven to zero by the back EMF PLL; this aligns the air gap flux with the d-
axis and all the back EMF is generated on the q-axis. Since e_d is a signed value it is centered on 128 for displaying on
the configuration utility. Figure 3-32 shows e_d centered at 128.
Atmel AVR1636: Configurable PMSM Sensorless Field Oriented Control using the XMEGA
[APPLICATION NOTE] 33
42061A−AVR−01/2013
Figure 3-33. Back EMF PLL block diagram with parameters.
p_error_limit
X ÷
+ + p_k_scaling + speed
p_kp 2
0 ÷
- - +
p_gravity + p_reg_scaling
X ÷ 2
+
p_k_scaling
-p_error_limit p_ki 2 Z-1
speed_min X
p_reg_scaling
2
speed_max X
e_d
The parameters from the block diagram are listed in Figure 3-34. The parameters for the PLL are as follows:
1. speed_min and speed_max – speed range of the back EMF PLL.
2. p_reg_scaling – sets the number of fractional bits used in calculation, this can range from 0 to 7, where 5 is a
good starting point.
3. p_error_limit – clamps the amount of error that goes into the PI controller. Typical range is 8 to 32.
4. p_k_scaling – sets the number of fractional bits used in calculation of the PI gains.
5. p_kp – the proportional gain.
6. p_ki – the integral gain.
7. p_gravity – allows a small offset to force the PLL frequency to speed_min if PLL is not locked onto the back
EMF. This helps with startup of the motor. Typical values are 0 to 2.
Atmel AVR1636: Configurable PMSM Sensorless Field Oriented Control using the XMEGA
[APPLICATION NOTE] 34
42061A−AVR−01/2013
Tuning a PLL regulator typically is done in mode = 0, Voltage mode, with an input_cmd fairly low so that excessive
current does not flow in the motor at stall. The input_cmd value used on this motor is set to 158 (30 above the zero
point of 128). Also the back EMF calculator must first have its values calculated and entered. Tuning the PLL is finding
the p_kp and p_ki values that give the motor quick startup and smooth steady state performance. This is done by
watching the speed variable in the Variable plot window and changing the gain values. It is best to start with setting
typical values for scaling and limits and setting the integral gain i_ki to a low value such as 1 or 2. Then increase the
i_kp gain so that the PLL tracks the motor speed.
The result of the accumulation is scaled by the parameter speed_scale Figure 3-36. This scaling sets the frequency
range of the sine wave output voltages v_a, v_b, and v_c and as a result sets the speed range of the motor.
2 . . . Equation 3-37
_
60
2
Where:
Speed = speed_min or speed_max [unitless] (between 1 and 255)
freqloop = Frequency of FOC control loop [hertz]
thetamax = Maximum count for theta equal to 360 degrees [count]
speed_scale
2 = Scaling factor for speed [counts]
Npoles = Number of motor poles from motor datasheet, Appendix C
Atmel AVR1636: Configurable PMSM Sensorless Field Oriented Control using the XMEGA
[APPLICATION NOTE] 35
42061A−AVR−01/2013
7812.5 2 . . . Equation 3-38
60
256 2 8
. . . Equation 3-39
28.6
The minimum and maximum speed can be calculated replacing in speed_min and speed_max:
Equation 3-40
_ . . .
Equation 3-41
28.6 . . .
Equation 3-42
_ . . .
Equation 3-43
7293 . . .
It is important to choose a speed_scale value that ensures that the maximum speed of the motor can be reached.
For the motor included with the kit, the range is well within the no-load speed of the motor rated at 4000 [R.P.M]
from the motor datasheet in Appendix C.
Atmel AVR1636: Configurable PMSM Sensorless Field Oriented Control using the XMEGA
[APPLICATION NOTE] 36
42061A−AVR−01/2013
Figure 3-37. i_d current regulator with parameters.
The q-axis is perpendicular to the air gap flux produced by the rotor magnets. Current along this axis produces
torque. Figure 3-38 shows the current regulator for the q-axis current, i_q and the reference set to input_cmd for mode
= 1. For mode = 2 the i_q_ref is set by the output of the speed regulator.
Atmel AVR1636: Configurable PMSM Sensorless Field Oriented Control using the XMEGA
[APPLICATION NOTE] 37
42061A−AVR−01/2013
Figure 3-38. i_q current regulator with parameters.
The two current regulators share the same gain settings. The parameters from the block diagrams are listed in Figure 3-
39. The parameters for the current regulators are as follows:
1. i_reg_scaling – sets the number of fractional bits used in calculation, this can range from 0 to 7, where 5 is a
good starting point.
2. i_error_limit – clamps the amount of error that goes into the PI controller. Typical range is 8 to 32.
3. i_k_scaling – sets the number of fractional bits used in calculation of the PI gains.
4. i_kp – the proportional gain.
5. i_ki – the integral gain.
6. v_limit – set the maximum value for v_d and v_q, the outputs of the regulators.
Tuning a current regulator typically starts with setting typical values for scaling and limits and setting the i_ki = 0 to turn
off the integral gain. Then increasing the i_kp gain so that the current tracks the reference, but with a DC offset. Then a
small amount of integral gains is added in until the DC offset is eliminated.
Atmel AVR1636: Configurable PMSM Sensorless Field Oriented Control using the XMEGA
[APPLICATION NOTE] 38
42061A−AVR−01/2013
3.3.13 Speed regulator
The speed regulator is used to modulate the torque command until the speed error is reduced to zero. The speed
regulator is a PI regulator using the same structure as the back EMF PLL and the current regulators. When mode =2
the input_cmd sets the speed reference as shown in Figure 3-40.
The speed regulator parameters from the block diagrams are listed in Figure 3-41. The parameters for the speed
regulator are as follows:
1. s_reg_rate – sets the number of current control loop updates before the speed regulator is updated, this is
due to the much lower bandwidth of the speed loop vs. the current loop. A good rule of thumb is that they
should be an order of magnitude apart. Choosing a value in the range from 10 to 50 is a good starting point.
2. s_reg_scaling – sets the number of fractional bits used in calculation, this can range from 0 to 7, where 5 is a
good starting point.
3. s_error_limit – clamps the amount of error that goes into the PI controller. Typical range is 8 to 32.
4. s_k_scaling – sets the number of fractional bits used in calculation of the PI gains.
5. s_kp – the proportional gain.
6. s_ki – the integral gain.
7. i_limit – set the maximum value i_q_ref, the outputs of the regulator.
Atmel AVR1636: Configurable PMSM Sensorless Field Oriented Control using the XMEGA
[APPLICATION NOTE] 39
42061A−AVR−01/2013
Figure 3-41. Speed control parameters.
Tuning a speed regulator typically starts with setting typical values for scaling and limits and setting the i_ki = 0 to turn
off the integral gain. Then increasing the i_kp gain so that the speed tracks the reference, but with a DC offset. Then a
small amount of integral gains is added in until the DC offset is eliminated.
4. Conclusion
This application note described the implementation and use of a configurable 3-phase permanent magnet synchronous
motor (PMSM) under sensorless field oriented control using the Atmel ATxmega16D4 microcontroller. The complete
hardware system includes a 12V 3-phase PMSM, an ATxmega16D4 processor board, a low voltage motor control
board, a USB-to-UART bridge cable, an AC power adapter, the firmware running on the ATxmega16D4, and a PC
based configuration utility for customizing the sensorless FOC for the motor.
Atmel AVR1636: Configurable PMSM Sensorless Field Oriented Control using the XMEGA
[APPLICATION NOTE] 40
42061A−AVR−01/2013
Appendix A. Atmel ATmega16D4 Processor Board Schematics
Atmel AVR1636: Configurable PMSM Sensorless Field Oriented Control using the XMEGA
[APPLICATION NOTE] 41
42061A−AVR−01/2013
Appendix B. Low Voltage Motor Control Board Schematics
Atmel AVR1636: Configurable PMSM Sensorless Field Oriented Control using the XMEGA
[APPLICATION NOTE] 42
42061A−AVR−01/2013
Appendix C. 42BLS01-001 Motor Datasheet
Atmel AVR1636: Configurable PMSM Sensorless Field Oriented Control using the XMEGA
[APPLICATION NOTE] 43
42061A−AVR−01/2013
Appendix D. Kit Parts List
Description Manufacturer Part number
Low Voltage Motor Control Board Atmel Corporation
ATxmega16D4 Processor Board Atmel Corporation
12V 4000RPM Tecmotion 42BLS01-001
USB-to-UART Bridge Cable FTDI, Future Technology Devices International Ltd TTL-232R-5V
Atmel AVR1636: Configurable PMSM Sensorless Field Oriented Control using the XMEGA
[APPLICATION NOTE]
42061A−AVR−01/2013
44
Appendix E. Revision History
Doc. Rev. Date Comments
42061A 01/2013 Initial document release
Atmel AVR1636: Configurable PMSM Sensorless Field Oriented Control using the XMEGA
[APPLICATION NOTE] 45
42061A−AVR−01/2013
Atmel Corporation Atmel Asia Limited Atmel Munich GmbH Atmel Japan G.K.
1600 Technology Drive Unit 01-5 & 16, 19F Business Campus 16F Shin-Osaki Kangyo Building
San Jose, CA 95110 BEA Tower, Millennium City 5 Parkring 4 1-6-4 Osaki
USA 418 Kwun Tong Road D-85748 Garching b. Munich Shinagawa-ku, Tokyo 141-0032
Tel: (+1)(408) 441-0311 Kwun Tong, Kowloon GERMANY JAPAN
Fax: (+1)(408) 487-2600 HONG KONG Tel: (+49) 89-31970-0 Tel: (+81)(3) 6417-0300
www.atmel.com Tel: (+852) 2245-6100 Fax: (+49) 89-3194621 Fax: (+81)(3) 6417-0370
Fax: (+852) 2722-1369
Atmel®, Atmel logo and combinations thereof, AVR®, Enabling Unlimited Possibilities®, XMEGA®, and others are registered trademarks or trademarks of Atmel
Corporation or its subsidiaries. Windows® is a registered trademark of Microsoft Corporation in U.S. and or 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.