AVR448: Control of High Voltage 3-Phase BLDC Motor Features • • • • ½ horsepower 3-phase BLDC motor Integrated Power Module controls motor currents Motor control via potentiometer wired to an ATmega48 AC Line powered as found in White Goods and appliance applications 8-bit Microcontrollers Application Note 1 Introduction Three Phase AC motors have been in operation worldwide for decades. They offer relative simplicity of construction, low maintenance, and high efficiencies. Many of these motors require the minimum of control electronics; typically only a 3-pole single throw switch. However, one disadvantage is that their running speed varies with the mechanical load, and is not easily controlled. With the addition of a microcontroller as a control device, 3-phase motors can be used for a far wider range of applications. Motor sizes below one horsepower are efficiently controlled in speed, acceleration and power levels. This is the ideal situation for consumer appliances and white goods such as washing machines. Additional applications include battery-operated tools, air conditioners, vacuum cleaners, and toys. Figure 1-1. 3-Phase Motor Examples Rev. 2592C-AVR-05/06 2 Theory of Operation 2.1 Hall Sensors Detect Rotor Position One very important detail in MCU motor control is rotor position. The control application must know the angular position of the rotor so that the proper voltages and currents are applied to the motor terminals. Hall magnetic sensors are typically installed within the motor. When 5 VDC is applied to them, they provide a digital output signal that changes when the rotor turns. Three phase motors use three Hall sensors. This type of position detection is well suited for many 3-phase motors and in particular, those with high starting loads. Figure 2-1. Hall Sensor Outputs as Related to Rotor position Hall 1 Hall 2 Hall 3 0 30 60 90 120 150 180 210 240 270 300 330 360 390 Shaft Position in degrees Figure 2-2. Motor winding schematic 2.2 Electrical Requirements of a 3-Phase BLDC Motor The motor used in this application note is a 120V 4A 3-phase design wired in a “star” configuration. It has a permanent magnet rotor and the 3 phases are wound in the stator. Hence, it has 3 wire connections to the windings, as is the case with many industrial 3-phase motors. In addition, it has 5 additional connections for the 3 Hall sensors: 5 VDC In, GND, and the 3 Hall sensor outputs. See schematic. 2 AVR448 2592C-AVR-05/06 AVR448 2.3 ATmega48 Firmware The ATmega48 is running a C-program that reads an analog voltage from a potentiometer used as a speed control knob. This is done using pin ADC0 and 8 bits of the A-to-D converter (ADC). The outputs of the ATmega48 are connected to an Integrated Power Module (IPM) from International Rectifier. This device accepts logic levels from the ATmega48, as well as 180 VDC at up to 4A and applies this voltage to the motor windings. Figure 2-3. Integrated Power Module There are numerous methods for control of 3 phase motors using a MCU. Three common methods are Trapezoidal, Sine Wave, and direct Torque control. In this application note, Trapezoidal control has been implemented because it simple but yet effective at controlling motor speed and power. The Trapezoidal method simply applies On-Off digital signals to the IPM. These signals are Pulse Width Modulated from 0% to 100% at a frequency of 20kHz. The 20kHz frequency is constant, and chosen to be out of the range of human hearing. The Hall sensor outputs are used by the program to determine which IPM inputs to set high and low. The signals to the IPM are pulse width modulated, which effectively varies the average voltages and currents to the windings. To clarify, consider the case where power is first applied to the motor with the rotor stopped. Only one H input and one L input will be active; the remaining 4 IPM inputs will be high (inactive). Look at the schematic to see the 6 IPM inputs. For the first millisecond, the rotor may rotate a very small amount. Most likely, the Hall outputs will remain unchanged, which tells the program to continue with the same H and L inputs. However, these inputs are pulse-width modulated, otherwise full power would result, and this would likely blow the fuse or circuit breaker. The duty cycle of these signals would be 20-30%, (at 20 kHz frequency) which limits the starting current. As the rotor begins to turn, the Hall sensors change their outputs, and the program reacts by choosing a different pair of H and L inputs to the IPM. From 0 to 10,000 RPM, this motor exhibited good starting torque, smooth acceleration and abundant torque. The variable speed and high speeds are achieved by varying the frequency of field excitation, under program control, in response to Hall Sensor position feedback. This is a demonstration program that reads the voltage on a potentiometer and adjusts the power to the 3-phase motor. This resultant motor speed is running open 3 2592C-AVR-05/06 loop, in the sense that there is no provision to measure the RPM in this program. Open loop speeds range from 0 to >>5000 RPM and one must use caution to not damage the motor with excessive speed or current. 2.3.1 Main Loop After the MCU is reset, the I/O ports, ADC and Timers are initialized. Next, the Top of Main Loop is reached. The Main Loop is a very short fast loop that essentially reads the PWM Output on Port C bit 3, and sets a variable IPM_B4_PWM to all 1’s or to a value assigned in the Pin Change Interrupt Service. Figure 2-4. Flowchart for Main Loop START Initialize I/O Port B Initialize ADC Initialize Timer 2 in Phase Correct PWM Mode Initialize Port C Pin Change Interrupts Set all IPM signals to high (inactive) N Is pin PD3 (PWM Output) high ? Y Set IPM signals to IPM_BW_PWM value 2.3.2 Pin Change Interrupt Handler This routine is initialized by forcing a pin change at the beginning of the main program. This first execution of the Pin Change Interrupt Routine reads the ATmega48 input pins connected to the Hall sensors, and determines what is the initial rotor position. Earlier in the program the variable Clockwise (CW) is defined, which determines direction of rotation. This direction decision and the Hall signals are used to look up the proper signals to output to the IPM via PORTB. This is, in effect, a Look Up Table of values that apply signals to the IPM that turn the motor 60 degrees. This routine is entered 12 times per revolution of the motor. If the motor is running at 6000 RPM, that is 100 Rev/Sec, or 1 revolution in 10 msec, or 10,000 usec. So, 10,000 usec/12 = an interrupt every 833 usec. 4 AVR448 2592C-AVR-05/06 AVR448 Figure 2-5. Flowchart for Main Loop Pin Change Interrupt Read Hall sensor signals from Port C Select current winding state from CW sequence Y Clockwise rotation? N Select current winding state from CCW sequence N PWM value = ADC value Read ADC value from potentiometer PWM value = 200 Y ADC value > 200? RETURN 2.3.3 Analog-to-Digital Converter The ADC converts the POT voltage to a digital number used by the Pin Change Interrupt Routine. This 10-bit value is converted to 8 bits, and limited under software control to 200. It is then sent to the PWM Output Compare register, where it sets the PWM duty cycle. If 0 is written to the OCR2B register, this will result in 0% PWM or no voltage applied to the motor. Conversely, if 200d = 0xC8 is written to OCR2B, this will result in 200/255 = 78.4% PWM or 78.4% of full voltage. 3 Schematic The schematic contains circuitry for a demo board, and includes the necessary power supplies, ATmega48, IPM and the 3-phase motor. 3.1 4.1 Safety Precautions with Line Operated Power Supply This power supply was designed to run from 120 VAC, 50-60 Hz. Notice that the negative side of the two bridge rectifiers is connected to a common ground. This IS NEITHER chassis ground NOR Earth Ground. DO NOT connect this ground to your oscilloscope ground wires! An Isolation transformer must be used. An example is shown here, along with a voltage variable transformer; the voltage variable transformer is highly recommended while developing code, because programming bugs could apply maximum voltage to the motor and damage some components. 5 2592C-AVR-05/06 Figure 3-1. BK Precision Variable AC supply Figure 3-2. BK Precision Isolation Transformer These are two of many available devices to aid in development and increase the level of safety. The above equipment is for 120 VAC operations. For 220-240 VAC operation, similar equipment rated for 220-240 VAC must be used. If it is desired to run this demo on 220-240 VAC, the power supply must be modified with higher voltage components, not shown here. The IPM shown is rated up to 600 VDC. It is the responsibility of the reader to use safe development procedures to prevent electric shock and equipment damage. Note that there is a transformer on the schematic. This reduces the incoming AC to approximately 15 VAC, which is then rectified and filtered for use by the 15 VDC and 5 VDC regulators. The ATmega48 is shown connected for demonstration purposes. It has many additional I/O and ADC inputs, as well as additional features that are beyond the scope of this application note. The IPM is wired sufficiently to operate the motor from 0-5000+ RPM. The IPM has built in protection circuits that protect itself and the motor. However, a bug in programming can cause full voltage to be applied to the motor, and may damage the motor and/or the IPM. This is why the Variable AC Supply is HIGHLY RECOMMENDED. Start your program development at much lower voltages, and apply 25-50 VDC to the IPM at first. Also, the transformer shown in the schematic may have to be connected to 120 VAC (not through the variable AC supply) so that the 5 and 15 VDC voltages will be present while the Variable AC Supply controls the high DC voltage. The Hall sensors operate on 5 VDC. Their 3 digital outputs are connected directly to the ATmega48 Port C. 6 AVR448 2592C-AVR-05/06 AVR448 Atmel offers the debugging/programming tool JTAGICE mk II. It is an ideal tool for program development and debugging. When used with the ATmega48/88/168, the debugger uses only one pin: the Reset pin. This tool is designed to work with Atmel’s AVR Studio® 4. 4 Alternative Solutions The application described above enters an eternal loop, polling the PWM output and setting the IPM signals. This leaves no CPU time for other tasks, such as external communication or safety functions (thermal shutdown etc). For such applications, two alternative solutions are given in the following. 4.1 External OR gates The raw PWM signal is already present on the OC2B pin (PC3). Instead of polling this bit in software, it could be wired to an array of external OR gates. The gates use the PWN output as an inverted ENABLE signal for passing through the IPM signal or not. If the PWM output is low, the IPM signal is passed unchanged through the gate. When the PWM output is high, the gate output is always high, meaning ‘inactive’ to the IPM input. This solution requires the OC2 output to be inverted by setting the appropriate bits in the Timer/Counter Control Register. Figure 4-1. Using external OR gates IPM ATmega48 ~PWM 4.2 Utilizing more PWM channels The two 8-bit Timer/Counters in ATmega48 provide three PWM channels each. However, when limiting the PWM base frequency to 20kHz, the register controlling channel A is used to set the timer TOP value. This leaves two PWM channels on each timer. The IPM is always used with one High-side and one Low-side input activated. By choosing to only Pulse-Width-Modulate the Low-side inputs, three PWM channels are enough and can be used to drive the Low-side inputs directly, thereby eliminating the eternal loop in software. 7 2592C-AVR-05/06 5 Literature • The datasheet for the IPM is available at: http://www.irf.com/product-info/datasheets/data/irams10up60a.pdf • The datasheet for the motor used is available at: http://www.newmotech.com/dws.html • More information on motor technology: http://www.freescale.com/webapp/sps/site/overview.jsp?nodeId=02nQXGrrlP 8 AVR448 2592C-AVR-05/06 AVR448 Figure 5-1. Schematic diagram AC IN +180 VDC + 680 uf 200 VDC +15 VDC + 470 uf 25 VCC AC Transformer 15VAC out 3 Terminal Pos. Reg. 5VDC out 3 Terminal Pos. Reg. 15VDC out + +5VDC + 47 uf 25 VDC 47 uf 25 VDC Shock Hazard! Dangerous voltages connected to GROUND on this schematic. +180 VDC VCC +15 VDC +5VDC An ISOLATION TRANSFORMER MUST BE USED during DEVELOPMENT and TESTING V+ VDD AREF VRU +5VDC VRW SPEED ADJUST ADC5 ADC0 5K OHM Mega 48 PB5 PB4 PB3 PB2 PB1 PB0 IMS10UP60ARA VRV !HIN3 !HIN2 !HIN1 !LIN3 !LIN2 !LIN1 VB1 VS1 VB2 VS2 VB3 VS3 VSS 23 7 8 4 5 1 2 + 10uf + 10uf + 10uf 5VDC Hall Supply PC2 PC1 PC0 Hall GND GND 7, 22 9 2592C-AVR-05/06 Disclaimer Atmel Corporation 2325 Orchard Parkway San Jose, CA 95131, USA Tel: 1(408) 441-0311 Fax: 1(408) 487-2600 Regional Headquarters Europe Atmel Sarl Route des Arsenaux 41 Case Postale 80 CH-1705 Fribourg Switzerland Tel: (41) 26-426-5555 Fax: (41) 26-426-5500 Asia Room 1219 Chinachem Golden Plaza 77 Mody Road Tsimshatsui East Kowloon Hong Kong Tel: (852) 2721-9778 Fax: (852) 2722-1369 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 Atmel Operations Memory 2325 Orchard Parkway San Jose, CA 95131, USA Tel: 1(408) 441-0311 Fax: 1(408) 436-4314 Microcontrollers 2325 Orchard Parkway San Jose, CA 95131, USA Tel: 1(408) 441-0311 Fax: 1(408) 436-4314 La Chantrerie BP 70602 44306 Nantes Cedex 3, France Tel: (33) 2-40-18-18-18 Fax: (33) 2-40-18-19-60 ASIC/ASSP/Smart Cards Zone Industrielle 13106 Rousset Cedex, France Tel: (33) 4-42-53-60-00 Fax: (33) 4-42-53-60-01 RF/Automotive Theresienstrasse 2 Postfach 3535 74025 Heilbronn, Germany Tel: (49) 71-31-67-0 Fax: (49) 71-31-67-2340 1150 East Cheyenne Mtn. Blvd. Colorado Springs, CO 80906, USA Tel: 1(719) 576-3300 Fax: 1(719) 540-1759 Biometrics/Imaging/Hi-Rel MPU/ High Speed Converters/RF Datacom Avenue de Rochepleine BP 123 38521 Saint-Egreve Cedex, France Tel: (33) 4-76-58-30-00 Fax: (33) 4-76-58-34-80 1150 East Cheyenne Mtn. Blvd. Colorado Springs, CO 80906, USA Tel: 1(719) 576-3300 Fax: 1(719) 540-1759 Scottish Enterprise Technology Park Maxwell Building East Kilbride G75 0QR, Scotland Tel: (44) 1355-803-000 Fax: (44) 1355-242-743 Literature Requests 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 ATMEL’S TERMS AND CONDITIONS OF SALE LOCATED ON ATMEL’S 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. Atmel’s products are not intended, authorized, or warranted for use as components in applications intended to support or sustain life. © 2006 Atmel Corporation. All rights reserved. ATMEL®, logo and combinations thereof, Everywhere You Are®, AVR®, and others, are the registered trademarks or trademarks of Atmel Corporation or its subsidiaries. Other terms and product names may be trademarks of others. 2592C-AVR-05/06