AN1113 APPLICATION NOTE Brushless Motor Fuzzy Control by using ST52x301 Authors: G. Grasso, M. Di Guardo INTRODUCTION Brushless DC motors (BLDC) are becoming widely used in the field of control motors. These kind of synchronous motors are used as servo drives in applications such as computer peripherals equipment, robotics, and as adjustable-speed drives in load-proportional capacity-modulated heat pumps, large fans , compressors and so on. Brushless DC motors are referred to by many aliases as brushless permanent magnet, permanent magnet AC motors, permanent magnet synchronous motors, etc. The confusion arises because a brushless motor does not directly operate off a dc voltage source. It is generally driven (supplied) from an inverter which converts a constant voltage to a 3-phase voltage with a frequency corresponding instantaneously to the rotor speed. One of the advantages of BLDC motor is the sparks absence. The brushes of a DC motor have several problems as regards to brushes’ life and dust residues, maximum speed and electrical noise. BLDC motors are potentially cleaner, faster, more efficient, less noisy and more reliable. However, BLDC motors require a more complex electronic control. This application note will show how this complexity can be reduced by using ST52x301 Fuzzy controller. AN OUTLINE OF BRUSHLESS MOTORS The Brushless motor has the physical appearance of a 3-phase permanent magnet synchronous machine. The brushes and commutator have been eliminated and the windings are connected to the control electronics. Electronics replaces the function of the commutator and energizes the proper winding. The energized stator winding leads the rotor magnet and switches just as the rotor aligns with the stator. In synchronous motor drives, the stator is supplied with a set of balanced three-phase currents, whose frequency is f. If p is the number of the poles in the motor, then: f= p ωs (1) 4π where ωs (rad/s) is the flux synchronous speed or, that is the same, the rotor speed. This equation links the rotor speed to the phases switching frequency of the electronic drive. The above currents produce a constant amplitude flux φs in the air gap, which rotates at the synchronous speed ωs. Since the flux amplitude is proportional to the current amplitude, it is enough to manage winding current level to control the rotor torque. From Brushless theory [3-4] it is possible to demonstrate that Tem =Kt Φf Iph sin (δ)(2) where kt is a constant, φf is the field-flux, δ is called torque angle. δ represents the angle between the phase linked flux φfph1 and the relative stator current Iph1. January 1999 1/18 AN1113 - APPLICATION NOTE Now, if the electronic controller is able to supply phase Ph1 in order to maintain δ=90° the equation above (2) can be simplified as Tem = KT Is(3) where KT is called motor torque constant and Is is the amplitude of the stator phase currents. From the previous considerations it is clear the reason why a BLDC motor needs always position sensors to know exactly rotor position. Fig. 1 shows a transversal section of a typical three phase brushless motor. Figure 1 . Three-phase brushless motor H1 H3 H2 In the diagram, three position sensors (Hall sensors) are placed around the rotor in order to detect the shaft position. Fig. 2 reports motor data sheet supplied by the motor builder. Figure 2. Motor Data Sheet Linked Voltage for Counterclockwise direction 2/18 ® Brushless Motor Fuzzy Control by using ST52x301 By observing the motor data sheet, these concepts become clear. In fact, it is possible to see the relation between shaft position, hall sensors response and voltage profile to be supplied. This way to supply the stator phases is very complex because it is necessary to produce a sine wave with a proper period and delay with respect to the sensors information. As we will show later on, a simpler method is possible. INVERTER DRIVER TOPOLOGY The stator of a brushless DC motor is generally supplied by an inverter which converts a DC voltage to a 3-phase AC voltage whose frequency is related to the speed of the rotor. Speed control is achieved by a Pulse Width Modulation (PWM) of the phases voltage accomplished by periodically switching the phase voltage to zero. The widely used driver to perform this switching is the six-step inverter where each phase is driven by means of a couple of transistors. Fig.3 shows the basic operating principle of this drive. The name "six-steps" arises from the finite time-steps in which the whole period can be shared. During each time step, current direction does not change whereas current amplitude can increase or decrease in the coil. To better explain this operating principle, let us consider the action of one leg (phase) of the inverter, such as for example T1 and T4. Transistor T1 is turned on at θ= - 90°and turned off at θ=90° while T4 is turned on at θ=90°. When T1 is Figure 3. Inverter driver operating principle Ph 3 Ph 1 U Ph 2 V W T1 T1 T2 T3 T2 T5 T6 T3 T4 0π/2π3π/2θ=ωt turned off, the current it was carrying is immediately diverted to the diode in parallel with T4. This diode re-circulates the instantaneous current of the winding until it decreases to zero. Once the phase current reverses direction is carried by T4. In term of voltage it is easy to draw the phases voltages by conceiving the transistors as switches. Due to the triangular connection of the phases, each phase voltage depends by the status of two legs of the bridge. Figure 4 shows one real phase star voltage and one phase current. Six voltage steps are evident in the look like sine wave. The same happens in the other legs of the bridge in different times. This topology drives the windings for the whole period, avoiding the phase to be "floating" (Six-Steps Continuous Mode Inverter). FUZZY CONTROLLER ® 3/18 AN1113 - APPLICATION NOTE Figure 4. Phase voltage and current The aim of the control is to maintain the desired Speed regardless of the applied load to the shaft. When a resistance torque is applied to the shaft, a reduction of the speed takes place. This implies an increment in the wave period of the Hall sensors signals and then a decrement of the sine frequency in the phases, to follow sensors information. In this case, the only way to lead the rotor at the previous speed is to increase the winding current in order to balance the load torque. Fuzzy Controller, in fig. 6, performs this task. ST52x301 reads the speed Figure 5. Control topology Speed_Ref Error PWM FUZZY CONTROLLER MOTOR DRIVER Speed 4/18 ® Brushless Motor Fuzzy Control by using ST52x301 "Ref" value from AD Channel0 and the instantaneous Hall signal period by means of a digital port. A software task performs the "error" calculation error = VREF − speed. The variable "Error" also forms the Fuzzy Input for the "Fuzzy Controller" block. A Fuzzy algorithm uses three rules to compute the fuzzy-out, achieving an incremental variable to drive the inverter in real-time mode. This incremental method allows to manage the speed in a closed loop real-time control, since software task time is very short. The first rule is fully activated when "error" value is "neg", i.e. when Vref <<speed. This implies that the actual speed of the shaft is higher than "Ref". Then the action to carry out is to reduce the phase current Figure 6. Fuzzy algorithm I. To achieve this, it is necessary to decrease the PWM duty-cycle. The displayed value "-10" is a good compromise between system stability and step response of the system. This value was assigned after some trials by using only human reasoning. Instead, If the duty step is higher, for example "-20", the system will sooner reach the "Speed_Ref" but the overshoot in a step response could lead to instability. The above explanation is similar for the other rules. The implemented 3-rules fuzzy algorithm is the simplest way to control the speed. A more accurate control could be done by using first derivative of the speed to improve the action strenght by means of other rules. HARDWARE DESCRIPTION ® 5/18 AN1113 - APPLICATION NOTE The real implemented system is shown in the schematic below. ST52x301, the integrated full-bridge dual drive and three AND’s are enough to control the BLDC motor. The basic idea used in this implementation employs the Hall sensors in a direct way. The Hall signals are "AND-ed" directly with a PWM wave produced by ST52x301 in order to supply the proper winding. In Figure 7. Electrical schematic BG Speed REF 15K Torque REF VCC 10K 10K BG Isense 1uF S1 RST RPM VCC 20 21 29 30 33 43 42 41 40 27 25 19 26 2 3 6 31 ST52x301 MAIN2 MAIN1 TRES TCTRL TCLK P0 P1 P2 P3 P4 P5 P6 P7 READY P8 TRIACOUT AIN0 AIN1 AIN2 AIN3 INT TIMEROUT TXD RXD BG OSCIN MODE TEST RESET AVDD AVSS 20MHz VPP OSCOUT 22pF 9 10 11 12 13 14 15 16 17 18 24 28 36 37 U Brushless Motor PWM 5 EnA IN1 7 EnB IN2 10 44 IN3 32 22pF Isense 6 11 10K V IN1 2.2uF W A 1 H3 H1 H2 Vpow 3.9 2W 4 1 2 4 5 9 10 74LS00 74LS00 74LS00 IN2 IN3 8 3 6 8 IN1 IN2 IN3 15 B L298 6/18 ® Brushless Motor Fuzzy Control by using ST52x301 fact, a high frequency PWM wave produces, in a coil, a voltage whose amplitude value is the mean value of the square wave. The motor data sheet displayed in fig. 2, clearly shows that "U-W" phase must be supplied positive when sensor "H1" is high, "W-V" when sensor "H2" is high and so on. This is true because the triangular connection was preferred in the coils arrangement. AND output is, then, a Pulse train whose duration is the same of the Hall signal. This pulses train is used to drive each leg of the bridge L298. L298 is a monolithic dual full-bridge driver designed to accept standard TTL logic levels and drive inductive loads such as relays, solenoids, DC and stepping motors. Enable input signals are available to allow a software protection. Internal circuitry provides the appropriate dead-time in order to avoid a "cross-conduction" along the leg. ST52x301 provides, by means of an internal peripheral, a PWM wave that can be varied by software. ST52x301 PWM frequency is chosen as compromise between acoustic noise in the motor and losses in the power stages of the bridge. A 19 KHz wave frequency was used in the implemented application. SOFTWARE DESCRIPTION Before to discuss about ST52x301 software configuration, it is important to note some HW connections in the schematic. Bit "0" (pin 9) of the parallel port is used to enable the power stage only after power-on reset, then parallel port must be configured in OUT mode. The analog input AIN0 (pin 43) is used to read the voltage reference. A voltage between 0 + 2.5 V present on this pin, is converted in the range 0 + 255. External INTerrupt pin (27) is used to read one Hall sensor signal period in order to calculate the instantaneous speed. This digital input will be configured both in negative or positive edge trigger to produce an internal software interrupt. Fig. 8 displays how to configure A/D peripheral with 3 inputs, TRIAC peripheral in PWM mode at 19 KHz, the used global variables. The following figure reports the main program in term of graphical programming. The appendix at the Figure 8 . Peripheral configuration ® 7/18 AN1113 - APPLICATION NOTE end of this application note contains the whole assembler code generated by the compiler. Let us discuss about the main program. "Int_AD_on" and "init" blocks in fig. 9 are used to initialize global variables and interrupts mask (only AD Int is enabled). The two following blocks start the converter and wait for the results of the conversion. After that, the converter values are stored in the variable called "speed, "torque", "current" and a new Interrupt mask is enabled (only Ext Int). Block "V200_duty" loads the Triac counter with a default value and the block "PWM_start" allows the TriFigure 9 . Main view ac peripheral to run. At this time it is already possible to see a PWM wave on pin 24 of ST52x301. Since pin 27 reads a time period related to the speed it is necessary to perform a mathematical inversion to achieve the frequency. Just to simplify, a complementation of the period byte will be made instead of the inversion. In this way, an error will be introduced in the spin frequency calculation. If a more accurate precision is requested, an alternative method to implement the inversion is to use a fuzzy implementation of the function 1/T. The block "L298_EN_on" enables the bridge driver. The Block "complemnt" performs the above task. Following the loop, a new value of the speed Ref "torque_ref" and "current" are read. The block "max_research" catches the maximum value of the current during a turn of the shaft. This loop is performed until the condition "tmp>=2" is false. Variable tmp is used to create a time inertia in the fuzzy control. "Tmp" is incremented each time the Ext-Interrupt routine is executed (each 1/3 turn of the shaft) and this implies a real time control in about one turn of the shaft. Block "calc_err" performs error calculation as " error = speed - ref - speed ", error variable is sent to the fuzzy input, Fuzzy block "fuzzy controller" produces the incremental value "delta_DC". Next figure shows the content of the 5 mathematics blocks. In the second, "delta_DC" is added (or subtract, if negative) to the current duty-cycle before to refresh Triac counter. The operators If .. then are introduced to avoid overflow or underflow in the counter registers during the control. Key point in the program is the Ext_Int routine (fig. 11). This task performs the period measurement of 8/18 ® Brushless Motor Fuzzy Control by using ST52x301 Figure 10 . Arithmetic blocks the square wave supplied by one Hall sensor. The period is measured by counting the time between a positive edge and the following negative edge of the H2 sensor signal. A flag is used to select the edge. If the coming edge is positive, the Timer peripheral will be started. If negative, the current Timer counter value will be read and the Timer stopped. Before to escape from Ext_Int routine two assembler blocks will set the edge select mask in order to sense the proper next edge. Figure 11. External Interrupt Routine ® 9/18 AN1113 - APPLICATION NOTE CONCLUSIONS AND RESULTS By using ST52x301 Fuzzy Controller it is easy to implement a real time control with few components.The brushless motor control described in this application note represents a good compromise between system costs and motor performances. The graphical programming environment reduces the development time also for not expert programmers. Fig. 12 displays a phase current and the star voltage Vu-o. PWM square wave is filtered by the oscilloscope. From this picture it is possible to observe the six steps on the current wave that yields a distortion of the theoretical sine wave. At higher speed rates the distortion becomes lower, although at low speed, motor performance does not degrade. To evaluate acceleration characteristics and control goodness, some trials were made during the softwa- Figure 12 . Phase current re development. Fig. 13 shows free acceleration characteristics starting from a given speed of the shaft to reach a double speed by changing suddenly the speed_Ref. The dynamic performances of this system were compared, in term of speed and load response, with a traditional controller with six steps drive. No substantial differences were issued in the dynamic performances, but the costs of the traditional system was higher. 10/18 ® Brushless Motor Fuzzy Control by using ST52x301 Figure 13. Dynamical performances Speed_Ref 2ω Motor Speed ω Tr = 150 ms REFERENCES [1] Paul C. Krause "Analysis of Electric Machinery" - McGraw-Hill [2] "Power Products- Application Manual", STMicroelectronics [3] Mohan, Undeland, Robbins "Power Electronics: Converters, Applications and Design" John Wiley & Sons [4] Yasuhiko Dote, Sakan Kinoshita "Brushless Servomotors - Fundamentals and Applications" Oxford Science Publications [5] FUZZYSTUDIO 3.0 - User Manual, STMicroelectronics, 1998 ® 11/18 AN1113 - APPLICATION NOTE APPENDIX: ST52X301 ASSEMBLER CODE ; ; ; ; Source file: C:\TEMP\BLDC_CL.wcl Compile time:Mon Sep 28 11:01:26 1998 Device type: ST52x301 Compiler version: 01.00 (02.06.98) data data data stop irq irq irq irq irq stop @WCLStart@@: ldcf ldcf ldcf ldcf ldcf ldcf ldcf ldcf ldcf ldcf ldcf ldcf ldcf ldcf ldcf ldcf Start: Int_AD_on: ldcf init: ldrc ldrc ldrc ldrc 12/18 0 0 20 147 0 0 1 15 127 15 0 2 0 107 20 3 4 1 2 0 Timer_Interrupt Triac_Interrupt AD_Interrupt SCI_Interrupt External_Interrupt 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 255 4 10 0 59 15 40 8 3 0 4 0 64 0 0 228 14 2 13 14 6 11 128 128 0 0 ® Brushless Motor Fuzzy Control by using ST52x301 ldrc ldrc 15 5 100 0 ldcf 2 11 ldri 12 0 ldri 8 1 ldri 7 2 ldcf 2 10 ldcf 14 1 ldcf 2 11 mdgi ldrc ldpr megi 0 1 200 0 ldcf ldcf 11 10 2 7 mdgi ldrc ldpr megi 0 2 1 0 mdgi ldrc sub megi 9 9 255 15 ldri 12 0 ldri 8 1 ldri 7 2 AD_start: Wait0: waiti Rd_speed: rd_torque: Rd_sense: stopAD: EXT_on: restart_ad: V200_to_duty: PWM_start: L298_EN_on: complemnt: RD_spee: RD_torq: Rd_Isense: ® 13/18 AN1113 - APPLICATION NOTE max_reserch: mdgi ldrr sub megi jps @@00000 ldrr 5 7 0 0 3 6 0 0 7 5 @00001: @00000: @00002: tmp_3: mdgi ldrc sub megi jpz jpns @@00004 @@00003 jp jp calc_err @@00005 jp complemnt @00004: @00003: @00005: calc_err: mdgi ldrc sub megi jps @@00006 ldrc 12 60 0 0 180 12 0 0 60 12 @00007: @00006: @00008: mdgi ldrc sub megi jpz jpns @@00010 @@00009 ldrc 12 @00010: 180 @00009: 14/18 ® Brushless Motor Fuzzy Control by using ST52x301 @00011: ldrc mdgi ldrr subo megi 6 0 10 10 12 9 ldrr stop ldp ldp fzand con ldp ldp fzand con ldp ldp fzand con out stop ldri 0 10 0 0 2 2 117 0 0 1 1 127 0 0 0 0 controller: 137 0 13 9 0 0 5 8 Torque_limit: mdgi ldrr sub megi jps @@00012 ldrc 13 128 ldrc 5 0 0 14 14 128 13 0 @00013: @00012: @00014: incr_duty: mdgi ldrc add add megi mdgi ® 15/18 AN1113 - APPLICATION NOTE ldrc sub megi jpz jpns 0 0 244 14 @@00016 @@00015 ldrc 14 244 0 0 11 14 @00016: @00015: @00017: mdgi ldrc sub megi jps @@00018 ldrc 14 @00019: 11 @00018: @00020: new_duty: ldpr jp External_Interrupt: inv_flag: mdgi ldrc add megi mdgi ldrc sub megi jpz jpns @00022: ldrc @00021: @00023: mdgi ldrc add megi flag_is1: 16/18 1 14 PWM_start 0 11 1 0 0 0 2 11 @@00022 @@00021 11 0 0 6 1 0 ® Brushless Motor Fuzzy Control by using ST52x301 mdgi ldrc sub megi jpz jpns @@00025 @@00024 jp jp set_tim @@00026 jp get_rpm ldri 15 4 ldcf 6 40 rint ldcf rint 0 14 0 1 mdgi ldrc ldpr megi 0 0 255 0 ldcf ldcf 6 6 41 43 rint ldcf rint jp 0 14 0 IRET0 0 0 1 11 @00025: @00024: @00026: get_rpm: stop_tim: on_rise: IRET0: reti set_tim: start_tim: on_fall: 129 AD_Interrupt: IRET2: reti SCI_Interrupt: IRET1: reti Timer_Interrupt: ® 17/18 AN1113 - APPLICATION NOTE IRET4: reti Triac_Interrupt: IRET3: reti stop Information furnished is believed to be accurate and reliable. However, STMicroelectronics assumes no responsibility for the consequences of use of such information nor for any infringement of patents or other rights of third parties which may result from its use. No license is granted by implication or otherwise under any patent or patent rights of STMicroelectronics. Specification mentioned in this publication are subject to change without notice. This publication supersedes and replaces all information previously supplied. STMicroelectronics products are not authorized for use as critical components in life support devices or systems without express written approval of STMicroelectronics. The ST logo is a registered trademark of STMicroelectronics © 1999 STMicroelectronics – Printed in Italy – All Rights Reserved STMicroelectronics GROUP OF COMPANIES http://www.st.com Australia - Brazil - Canada - China - France - Germany - Italy - Japan - Korea - Malaysia - Malta - Mexico - Morocco - The Netherlands Singapore - Spain - Sweden - Switzerland - Taiwan - Thailand - United Kingdom - U.S.A. 18/18 ®