AN1291 APPLICATION NOTE SLIP CONTROL OF AN ASYNCHRONOUS THREE-PHASE MOTOR WITH ST52X420 Author: M. Di Guardo, V. Marino 1. INTRODUCTION Induction motors with squirrel-cage rotors are the workhorse of industry because of their low cost and rugged construction. The aim of this Application Note is to show how to perform the slip control of an AC threephase induction motor with ST52x420, in order to obtain minimum input power and maximum efficiency operations. This type of control can be achieved by adjusting the amplitude of the applied stator voltage versus torque requirement. Efficiency improvement by voltage control is obtained by reducing the applied voltage whenever the torque requirement of the load can be met with less flux. The reduced motor flux results in a reduction of core and stator copper losses since the magnetization component of the stator current is reduced as well. However, it is to note that the minimization of the air gap flux requires a larger slip to produce the torque required if compared with operations at full rated flux. This application note shows the implementation of the slip control of an aynchronous motor in order to have energy saving of the global power system, representing a convenient solution to reduce the rotor and stator copper losses. 1.1 Torque Characteristics of Asynchronous Three-Phase Motors Typical torque and current characteristics are represented in figure 1 where the torque Tem is plotted as function of rotor speed and fsl (slip frequency is the difference between stator frequency f and rotor frequency). At low values of fsl, Tem varies linearly with fsl ,see the line plotted in bold in the stable zone (fig.1). The maximum torque that the motor can produce is represented by the pull-out point shown below. Figure 1. Torque versus rotor speed at f and Vs constant. Tem/Trated Pull-out Torque Flux decreases Maximum torque Stable zone 1.5 T, rated 1.0 Flux =rated Unstable points Rotor speed rated July 2000 0 0.2 1.0f 1.0 0.8f 0.4 0.6f 0.6 0.4f 0.8 0.2f 0.8 0.6 0.4 0.2 fsl s r 1.0 s 0 slip 0 frequency ( f-fr) slip 1/33 AN1291 - APPLICATION NOTE If an induction motor is started directly from the power supply and the load torque is lower than the startup torque, at maximum slip (slip=1), the motor is able to run and enter in the stable zone. Then the intersection of the motor torque characteristic with load torque determines the steady-state point of operation. If the load torque reaches the maximum torque, the motor enters in the break down domain until the complete stop of the motor. 1.2 Speed Control Speed can be controlled by varying stator frequency f with power electronic inverter, in order to control synchronous speed and, hence, the motor speed, if the slip is kept small, keeping the flux constant in the air gap, varying stator voltage in linear proportion to stator frequency f (Fig. 2). Figure 2. Speed control by varying stator frequency Tem, T rated 1 .5 T , r a te d 1 .0 f1 f2 f3 f4 r ra te d 1 .0 0 fs l1 1 .0 fs l2 s 1 .0 fs l3 fs l4 R o to r s p e e d in c re a s e s a t th e i n c re a s in g o f the Sta to r F re q u e n c y The torque speed characteristics shift horizontally in parallel, as shown in figure 2 for four different values of fsl. Note that, at a constant load-torque, the slip frequency (which is the frequency of the induced voltage and currents in the rotor circuit in hertz) is constant. 1.3 V/F = constant speed control The simplest method of control is to maintain constant the flux (V/F) with power converters varying the motor speed. This regulation is called torque constant control. If we change the frequency also the voltage applied must vary in a linear way in order to maintain V/F constant. This ratio is dimensionally a flux (fig.3). Figure 3. Voltage vs Frequency relation Vs Vmax =constant Vmin minimum frequency 2/33 rated frequency f (Stator frequency) AN1291 - APPLICATION NOTE V/F characteristics are listed below: * * * * It operates at constant flux and Torque Motor always supplies the maximum Torque Efficiency is not optimized Motor is oversized In this application note, the flux minimization control has been implemented instead of the V/F constant method. In this way, it is possible to reach good efficiency and torque regulation. 1.4 Motor Efficiency Optimization with Slip Control The motor efficiency can be improved by controlling the stator voltage to maintain the slip constant at minimum flux (flux minimization). Adapting the flux in the air gap to have a large slip, but not large enough to reach the pull out torque otherwise the motor would stop, the required torque is generated so as to be compared with operation at full rated flux. Power loss can be minimized maintaining large and constant the slip adjusting the available torque (Fig.4). This voltage varying method of the phase motor offers limited possibilities of speed regulation. However, combining both voltage control (minimum flux) and frequency control, the motor is well controlled in a wide range of speed. Figure 4. Motor characteristics fixing the stator voltage Tem Trated 1.5 rated curve WORKING ZONE f=constant Flux =rated T,rated 1.0 T6 T5 T4 T3 T2 T1 ADJUSTING STATOR VOLTAGE 0 r 0 0.2 0.4 0.6 0.8 1.0f 0.8f 0.6f 0.4f 0.2f fsl 0 slip frequency f-fr 1.0 0.8 0.6 0.4 0.2 s 0 slip 1.0 s slip=constant 3/33 AN1291 - APPLICATION NOTE 2. Control Structure The aim of the control is to bring the speed of the motor axis to the reference speed maintaining the slip within a certain range fixed by the measures carried out during the modellization phase of the motor. Two fuzzy loops are implemented (Fig.5 and 6): Figure 5. Control structure ENCODER External interrupt (rotor period calcolation) Rotor frequency PWM0 Pulse generation Stator Frequency Voltage PWM1 PWM2 Reference A/D FUZZY 1 FUZZY 2 ST52x420 The first fuzzy loop (FUZZY1) is of the incremental type. The input of this Fuzzy block is the speed error given by the difference between the reference speed read through the A/D Converter and the motor speed "Frotor" calculated using the external interrupt input where the encoder signal is connected. The output of the block f is summed algebraically to the stator frequency Fstator to reach the motor speed to the reference set up. The second fuzzy loop (FUZZY2) receives in input the difference between "Fstator" and "Frotor" (slip), and adjusts the voltage level (voltage) to optimize the flux and prevent overcurrents in the motor (Fig. 5 and 6). According to the stator frequency and the desired voltage level, the "Pulse generator" block generates three PWM signals to drive the inverter (refer to "Pulse Construction" for further information). Figure 6. Fuzzy Control Diagram Speed setpoint Speed Error Fuzzy algorithm +- f Rotor speed Slip Stator speed Rotor speed 4/33 Fuzzy algorithm Vs Stator frequency increment Stator Voltage AN1291 - APPLICATION NOTE 2.1 Fuzzy Controller Algorithm Stator Voltage Loop The ST52x420 microcontroller thanks to its Fuzzy Logic dedicated architecture, allows the implementation of complex systems such as three-phase motors. Thanks to the three Timers and to the multiplication and division functions it is possible to obtain the three PWM sinusoidal modulation signals to be supplied to the inverter driver varying, in an independent way, the Frequency and the modulation index. From a set of preliminary measurements performed on the motor it is possible to build a table that describes the complete functionment of the motor at low and full load in every condition: rotor frequency [rpm] accuracy [%] stator frequency [Hz] max slip frequency (f-fr) [Hz] minimum stator voltage [Vs] max stator voltage [V] max slip [s%] More precisely, using the electronic system: Stator period [msec] tacho period [msec] tacho timer value obtained [byte] max stator timer value [byte] min stator timer value [byte] max slip frequency [byte] Once the tables have been completed with all the working points we know exactly how to change the stator voltage. Implementing a fuzzy logic interpolation we can modify the voltage by using two Membership Functions inputs that are respectively stator frequency f and slip frequency, using a set of rules of the kind: IF Frequency is Low and slip is Very High then output is High More precisely, the output of this function, i.e. a function of two variables: Vs=Vs(f,s) that is the required voltage for the motor. Now, if the loading conditions of the motor are such that the voltage controller is not able to set the motor at the established slip and speed set points, for example under a great increase of the torque in the axis of the motor, then the second controller is activated for the frequency adjustment. Figure 7. Fuzzy logic voltage control surface Fuzzy Output (stator voltage) F1 S1 Slip frequency (f-fr) Stator Frequency 5/33 AN1291 - APPLICATION NOTE 2.2 Fuzzy Controller Algorithm Stator Frequency Loop Analogously, to build the fuzzy rule for the stator frequency adjustment, we can take into account the speed error to obtain the right increment or decrement for the frequency adjustment. These rules will be of the kind: IF Speed Error is Negative Big and then output is Negative Big More in details, the stator frequency f is equal to: f(k)=f(K-1) f where f is the increment or the decrement provided to the output of the fuzzy controller in order to adjust the rotor speed (Fig.8). Figure 8. Fuzzy Logic frequency adjustment Stator Frequency Adjustment Speed error Fuzzy rules 2.3 Sinewaves PWM Modulation For pulse construction, a 24-byte table, representing the unit sinusoid sampling, is allocated in the internal memory of the MCU. The three sinewaves are drawn by the same table using three 120o-shifted pointers (Fig.9). Figure 9. Pulses construction vk 255 127 0 0 The three pointers with 1200 phase shift give the values to be loaded in the PWMs PWM 0 PWM 1 PWM 2 vaK=1/128*Voltage*sin(tk) vbK=1/128*Voltage*sin(tk-2/3) vcK=1/128*Voltage*sin(tk-2/3) VOLTAGE 6/33 23 k Stator speed by varying reading patterns tK+1-tK=T*16s 40 T 240 F=1/[24*(tK+1-tK)] 10.8Hz F 65.1Hz FREQUENCY AN1291 - APPLICATION NOTE The PWM sinusoidal modulation is obtained scanning the 24 samples with a variable period related to the frequency to be assigned to the motor phases. Each sample is multiplied by the modulation index to change the sinewave amplitude. This is obtained loading this value on the PWM counter thus obtaining a duty-cycle variable that allows to build a sinusoid with an amplitude dependent on the modulation index (Fig.10). Figure 10. PWM Pulses Construction 255 vk 127 0 k t0 t1 x 23 modulation index 1 PWM t0 2 t1 t T 7/33 AN1291 - APPLICATION NOTE 3. HARDWARE IMPLEMENTATION This application consists of four functional blocks (Fig.11): * A three-phase asynchronous motor * A three-phase power inverter * The closed loop Fuzzy motor control with ST52x420 * An AC-DC converted supplied by the mains Figure 11. Three-Phase Inverter AC/DC converter ST52x420 Microcontroller THREE PHASE INVERTER Feedback 8/33 Encoder LI1 HI1 6 4 3 2 1 7 C12 R9 100k C1 220pF +15V 270 R11 L6386 CIN VCC HIN SD LIN SGND U1 .1uF 1 68K C9 14 13 12 9 8 5 22uF 100 VBOOT HVG OUT LVG PGND DIAG R10 PHASE1 + J1 R6 J4 R2 +15V 100 R1 Q4 R12 * bus- 6 4 3 2 1 7 .1uF C2 bus- L6386 CIN VCC HIN SD LIN SGND U2 1 VBOOT HVG OUT LVG PGND DIAG J2 PHASE2 PRINTED RESISTOR SEE PCB GP7NB60HDFP LI2 HI2 8.2K +15V GP7NB60HDFP Q1 14 13 12 9 8 5 C10 22uF Q5 R7 100 100 R3 Q2 1 GP7NB60HDFP + 1 J5 LI3 HI3 HI1 LI1 HI2 LI2 HI3 LI3 +15V GP7NB60HDFP bus+ 6 4 3 2 1 7 L6386 CIN VCC HIN SD LIN SGND U3 +15V .1uF C3 1 2 3 4 5 6 7 8 J6 14 13 12 9 8 5 C11 22uF 1 Q6 GP7NB60HDFP R8 100 R4 100 Q3 GP7NB60HDFP EXT.INTERFACE VBOOT HVG OUT LVG PGND DIAG PHASE3 J3 + bus+ C7 R5 220k AN1291 - APPLICATION NOTE 3.1 Motor Interface The motor interface consists of three inverter legs with IGBT or Power Mos, which are driven by the ST L6386 drive (Fig.12). Figure 12. DC-AC Inverter schematic 3.3nF-1KV This structure needs DC link voltage +HV, typical value is 325V rectifying AC line voltage. The three-phase motor is connected In the points named R, S, T. Note: * The PCB can be found on the ST52 Microcontrollers pages at www.st.com/stonline/prodpres/ 9/33 2 1 220Vac J3 12 HEADER 2 TRANSFORMER 1:2 T2 VCC VCC - - IN U4 TS831 + V1 ~ ~ 2A500V + V2 ~ 0.5A 50V ~ 1 0.1uF C1 OUT R2 10k C23 0.1uF GND 3 12 11 10 9 8 7 6 5 4 3 2 1 220K R8 + C13 0.1uF +15 C6 100pF 0.1uF C22 ST52X420 TEST RESET OSCOUT PB0/AIN0 PB1/AIN1 PB2/AIN2 PB3/AIN3 PB4/AIN4 PB5/AIN5 PB6/AIN6 PA0/T0RES PA1/T0OUTN PA2/T1OUTN PA3/T2OUTN PA4/T0STRT PA5/T0CLK PA6 PA7/AIN7 1A F1 C19 1000uF25V VIN U7 LM78L05ACZ C7 22pF C21 68uF450V + 3 4 1 2 9 10 11 12 15 16 17 25 24 23 22 21 20 19 18 U1 GND 10/33 2 J1 1 J6 1 J5 BUS- BUS+ VOUT 20Mhz Y1 1 C20 3 5 6 7 8 26 28 13 27 14 470uF16V + OSCIN PC0/INT PC1/T0OUT PC2/T1OUT PC3/T2OUT VPP VDD VDDA VSS GNDA 0.1uF C2 C14 0.1uF C8 22pF VCC VCC 3.3k R7 1N4148 D6 3.3k 1N4148 R6 D5 3.3k 1N4148 R5 D4 3.3k 1N4148 R4 D3 3.3k 1N4148 R3 D2 3.3k 1N4148 R1 D1 5 C16 1nF 13 C15 1nF 11 C10 1nF C9 1nF C5 1nF 3 C4 1nF 1 1 74HC14 U2F 1 U2E 1 6 8 12 10 74HC14 U2D 74HC14 9 1 4 2 74HC14 U2C 74HC14 1 U2B 74HC14 1 U2A 9 3 1 7404 1 U3D 1 7404 U3B 1 7404 U3A 8 4 2 +15 C3 0.1uF 13 11 5 7404 1 U3F 7404 1 U3E 1 7404 U3C CON8 1 2 3 4 5 6 7 8 J2 12 10 6 AN1291 - APPLICATION NOTE 3.2 Closed Loop Fuzzy Control In the following figure is shown the complete schematic of the digital control with ST52x420. To generate the six signals to be sent to the inverter section, ST52x420 uses the three-PWM peripheral. Figure 13. Scheme Diagram for signal generation with ST52x420 These three signals are used from the dead time net in order to obtain all the six signals for the inverter stage to avoid cross conduction in the power switch of each leg. AN1291 - APPLICATION NOTE Figure 14. Components layout of the three-phase inverter Figure 15. Three-phase inverter board (Power section) 11/33 AN1291 - APPLICATION NOTE Figure 16. Control board with ST52x420 AB420_4 ST52x420 12/33 AN1291 - APPLICATION NOTE Figure 17. Control board (ST52X420) 13/33 AN1291 - APPLICATION NOTE 4. SOFTWARE DESCRIPTION Before to analyze the structure of the software project, it is necessary to notice some connections on the schematic. The pins 6, 7 and 8 of ST52x420, (outputs of the three PWM peripherals), are used to drive the three legs of the bridge. The three-phase voltage is obtained by indexing 3 pointers on the same look-up-table containing the desired PWM pattern at modulation index equal to 1, to reconstruct a sinusoidal signal. This pattern is recomputed every time for each modulation index, in order to obtain three PWM signals. One single pointer is shifted on this table, synchronously with one PWM pointer, in order to obtain three phases supplied with 120o phase shift. Sine period is instead defined by the number N of ADC interrupts: Statoric period = AD_int_counter*AD_int_period*number_of_samples=N*16 s*24. In fact, the AD peripheral of ST52x420, besides reading from the pin 9 (Ain0/PB0) the value of reference for the motor speed, is used as time measurer, exploiting the fact that the peripheral requires an interrupt every time that a conversion has been completed (see also paragraph 4). Finally pin 5, configured as external interrupt, is used to measure the instantaneous motor speed by means of a tachometer. 4.1 Main program The main program is shown in the following flowchart: Figure 18. Flowchart START MAIN A/D INTERRUPT ROUTIN E VARIABLES AND PERIPHERALS INITIALISATION SET STATOR FREQUENCY ROTATION PERIOD IS COMPLETED NO WAIT FOR INTERR UPT RETI YES R EAD LOOK_UP_TABLE AND C ALCULATE DUTY_CYCLE EXTERNAL INTERRUPT ROUTIN E CALCU LATE ERROR FREQUENCY START/STOP ROTOR FREQUENCY C ALCULATION FREQUENC Y FUZZY C ONTROL RETI CALCU LATE SLIP PWM_0 INTERRUPT ROUTINE ROTOR FREQUENCY CALCU LATION SLIP FUZZY C ONTROL RETI : 14/33 AN1291 - APPLICATION NOTE In the following figure is shown the main program in FUZZYSTUDIOTM4 environment. The appendix at the end of this application note contains the whole assembler code generated by the compiler. Figure 19. Main Program window 4.2 'Initialize' folder The folder 'initialize' contains the blocks used to initialize the global variables and the interrupts mask, and to start the peripherals ADC, PWM0, PWM1 and PWM2. Figure 20. Variables and Peripherals Initialization 15/33 AN1291 - APPLICATION NOTE 4. 3 'AD interrupt' routine The AD interrupt is used as counter; in fact, each 16 s an interrupt is generated and the counter 'AD_int_counter' is incremented. The period between two interrupts is given by the formula: Tconv=number_of_channels*[78*SCK+4]*TCKM when 'SCK' is 2 or 1 if AD frequency is divided by 2 or not, and TCKM is the period of the clock master. In the case described, when the number of channels converted are 2 (0 and 1) and the AD frequency is the clock master frequency (20 Mhz) divided by 2, Tconv=2*[78*2+4]*50 ns= 16 s. Figure 21. A/D Interrupt routine When the counter 'AD_int_counter' reaches the value 'Fstator', the pointers are incremented in order to read on the look-up-table the new sample value of the sine wave (see Read_table folder paragraph), and 'AD_int_counter' is first put to 255, so that, when increased, it is reset. 4.4 'External interrupt' and 'PWM0 interrupt' routines The external interrupt is used to measure the rotor period; in fact it is measured by counting the time between two positive edges of the square wave supplied by a tachometer system, that is connected to the INT pin; a variable named 'flag' is used to select the edge. If the variable value is 0, the PWM0_int is enabled, in order to start the calculation of a period, and the variable 'flag' is set to 1. At the next external interrupt the PWM0_int is disabled and the value reached from the variable 'Fr_measure' is a measure of the rotor period. Moreover, the variable 'flag' is set to 0, in order to restart the calculation at the following edge and the variable 'flag_fuzzy' is set to 1, in order to perform the fuzzy control (see Fig. 23). 16/33 AN1291 - APPLICATION NOTE Figure 22. External interrupt routine Of course the variable 'Fr_measure' is incremented in the 'PWM0_int' routine, and the value obtained between two external interrupt edges must be compared with the value of the stator frequency. In fact the stator period is: Tstator=Fstator*16 s*24=(384*Fstator) s, instead the rotor period measured with a tacho that gets a period 1/8 of the rotor period is: Trotor=Fr_measure*102 s*8=(816*Fr_measure) s. You have to notice that the value 102 ls is the period of PWM0, corresponding at a frequency value of 9.8 KHz, as you can see in figure 5 in the 'working frequency' box. In order to make consistent the measure of rotor frequency with that of the stator, you have to use another variable 'Frotor' so that: Frotor=(816/384)*Fr_measure=(17/8)*Fr_measure 17/33 AN1291 - APPLICATION NOTE Figure 23. PWM 4.5 'Read_table' folder The block "read_table" is used to obtain three PWM signals; each of the three instantaneous duty-cycle values are generated addressing three pointers, (called 'sina_phase, sinb_phase, sinc_phase") in the look-up-table where unitary and sampled sinewave are stored. The voltage amplitude of the sinewave is obtained by using the multiplication and division capabilities of ST52x420, as you can see in the figures 24 and 25. In the block "read_table0" the instruction "table_value=sinus[sina_phase]" allows to access the look-uptable 'sinus' and store the value addressed from the index "sina_phase" in the variable "table_value". Then the subroutine 'voltage' is called, in order to calculate the duty-cycle in accordance with the modulation index; this procedure is performed three times, for each duty-cycle value, that will be charged in the respective PWM_COUNT with the block "PWM_COUNT_set". In the block "duty_cycle_calculator" the module of the value read from the look-up-table is multiplied by the value "voltage_level", (obtained from fuzzy block "slip_control ") and divided by "level_number", in order to obtain the instantaneous duty-cycle. Moreover, the block "reset_cursor" is used to control if the values of the indexes reached the maximum, in order to reset them if that happened. 18/33 AN1291 - APPLICATION NOTE Figure 24. Read Table folder Figure 25. Voltage 4.6 Fuzzy Controls Two fuzzy blocks are present in this program: the first is used to control the frequency, the second to control the slip. The block "error_calculator " performs the instruction 'error=reference-Frotor'; "reference" is the value desired for the motor speed, that can be varied with a trimmer, in the range '1/(16e-6*24*240)= 10.8Hz -- 1/ (16e-6*24*40)=65.1Hz', instead "Frotor" is the frequency measured with the tachometer. 19/33 AN1291 - APPLICATION NOTE Before sending the "error" value to the fuzzy input, a control to avoid an overflow or underflow is performed. In according with the input value, the fuzzy block "frequency_control" produces the incremental value "dFstator", that is added (with sign), in the block "frequency_calculator", to the current value of the variable "Fstator". In this way, the speed motor is adjusted to reach the reference value. Figure 26. Frequency control The block "slip_calculator" is used to calculate the slip, as 'slip=Fstator-Frotor', with a control to avoid an overflow or underflow. According with the "slip" value and the statoric frequency, the fuzzy block "slip_control" calculates the value of the modulation index "voltage_level", that allows to adjust the voltage level of the sinusoidal phases. The memberships and the fuzzy rules of this block represent the mathematical model of the motor and were obtained through experiments with different points of operation. Figure 27. Slip calculation 20/33 AN1291 - APPLICATION NOTE APPENDIX A - Assembler code ; Interrupt Vector Configuration irq 4 External irq 0 AD_Converter irq 1 PwmTimer0 irq 2 PwmTimer1 irq 3 PwmTimer2 ; Global MBF mbf 0 mbf 1 mbf 2 mbf 3 mbf 4 mbf 5 mbf 6 mbf 7 mbf 8 mbf 9 mbf 10 mbf 11 mbf 12 mbf 13 mbf 14 Definition 45 195 45 6 128 8 45 240 0 0 98 24 45 105 45 17 113 13 24 122 6 0 96 17 5 140 0 17 160 0 15 128 15 0 60 45 7 135 5 45 150 45 13 143 17 ; Tables Allocation ; "BYTE sinus[24]" use 24 eprom locations from 63(Page:0 Offset:63) to 86(Page:0 Offset:86) data 0 63 0 ; sinus[0] = 0 data 0 64 33 ; sinus[1] = 33 data 0 65 63 ; sinus[2] = 63 data 0 66 90 ; sinus[3] = 90 data 0 67 110 ; sinus[4] = 110 data 0 68 123 ; sinus[5] = 123 data 0 69 127 ; sinus[6] = 127 data 0 70 123 ; sinus[7] = 123 data 0 71 110 ; sinus[8] = 110 data 0 72 90 ; sinus[9] = 90 data 0 73 63 ; sinus[10] = 63 data 0 74 33 ; sinus[11] = 33 data 0 75 128 ; sinus[12] = 128 data 0 76 161 ; sinus[13] = 161 data 0 77 191 ; sinus[14] = 191 data 0 78 218 ; sinus[15] = 218 data 0 79 238 ; sinus[16] = 238 data 0 80 251 ; sinus[17] = 251 data 0 81 255 ; sinus[18] = 255 data 0 82 251 ; sinus[19] = 251 data 0 83 238 ; sinus[20] = 238 data 0 84 218 ; sinus[21] = 218 data 0 85 191 ; sinus[22] = 191 data 0 86 161 ; sinus[23] = 161 ; ; ; ; Tables Allocation Report: byte used : 24 from : 63(Page:0 Offset:63) to : 86(Page:0 Offset:86) setmem 0 87 21/33 AN1291 - APPLICATION NOTE ; Store Device Configuration Parameters into Eprom ; Default Interrupt Priority data 0 87 228 ; Port Configuration data 0 90 0 data 0 98 248 data 0 99 243 data 0 100 3 data 0 101 241 data 0 102 0 ; A/D Converter Configuration data 0 89 58 ; WatchDog Configuration data 0 88 12 ; Pwm-Timer data 0 data 0 data 0 0 Configuration 91 208 92 35 93 0 ; Pwm-Timer 1 Configuration data 0 94 208 data 0 95 35 ; Pwm-Timer 2 Configuration data 0 96 208 data 0 97 35 setmem 0 103 ; End ************************************ ; Set Device Configuration Parameters pgset 0 ldce 1 87 ldce 2 88 ldce 3 89 ldce 4 90 ldce 5 91 ldce 6 92 ldce 7 93 ldce 8 94 ldce 9 95 ldce 10 96 ldce 11 97 ldce 12 98 ldce 13 99 ldce 14 100 ldce 15 101 ldce 16 102 ldrc 0 0 ldpr 4 0 ldpr 6 0 ldpr 8 0 ; ** User Defined Variables ** ; NAME -> REG 22/33 AN1291 - APPLICATION NOTE ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; -----------------------------------------AD_int_counter -> 10 Fr_measure -> 11 Frotor -> 12 Fstator -> 13 dFstator -> 14 duty -> 15 duty0 -> 16 duty1 -> 17 duty2 -> 18 error -> 19 flag -> 20 flag_fuzzy -> 21 level_number -> 22 reference -> 23 sina_phase -> 24 sinb_phase -> 25 sinc_phase -> 26 slip -> 27 table_value -> 28 temp -> 29 voltage_level -> 30 word1 -> 31 32 word_value -> 33 34 ********************************** main: ; ********** Start procedures "main" Start: initialize: init_var: ldrc 20 0 ldrc 21 0 ldrc 24 0 ldrc 25 8 ldrc 26 16 ldrc 22 128 ldrc 30 64 ldrc 23 200 ldrc 13 200 ldrc 27 248 ldrc 10 0 enable_int: ; IrqEnableMask mdgi ldrc 0 3 ldcr 0 0 megi ADC_start: ; ADC Setting mdgi ldrc 0 63 ldcr 3 0 megi three_PWM_start: ; ALL_PWM Setting 23/33 AN1291 - APPLICATION NOTE mdgi ldrc ldcr ldrc ldcr ldrc ldcr ldrc ldcr ldrc ldcr megi Exit0: jp 0 7 0 5 0 8 0 10 0 7 224 0 213 0 213 0 213 0 0 0 initialize_Exit initialize_Exit: flag_fuzzy: mdgi ldrc 0 1 sub 0 21 megi jpnz End_If_6 jp read_table End_If_6: no_operation: jp flag_fuzzy read_table: read_table0: mdgi ldrr 0 24 ldrc 28 63 add 28 0 pgset 0 Read: ldrc 0 28 ldre (0) (28) megi Call3: call voltage duty0: ldrr 16 15 read_table1: mdgi ldrr 0 25 ldrc 28 63 add 28 0 pgset 0 Read_1: ldrc 0 28 ldre (0) (28) megi 24/33 AN1291 - APPLICATION NOTE Call4: call voltage duty1: ldrr 17 15 read_table2: mdgi ldrr 0 26 ldrc 28 63 add 28 0 pgset 0 Read_2: ldrc 0 28 ldre (0) (28) megi Call5: call voltage duty2: ldrr 18 15 PWM_COUNT_set: ldpr 3 16 ldpr 5 17 ldpr 7 18 reset_cursor: mdgi ldrc 0 24 sub 0 24 megi jpnz No_If_9 ldrc 24 0 jp End_If_9 No_If_9: mdgi ldrc sub megi jpnz ldrc jp No_If_8: mdgi ldrc sub megi jpnz ldrc 0 0 24 25 No_If_8 25 0 End_If_8 0 0 24 26 End_If_7 26 0 End_If_7: End_If_8: End_If_9: Exit6: jp read_table_Exit 25/33 AN1291 - APPLICATION NOTE read_table_Exit: error_calculator: ldri 23 1 mdgi ldrc 0 240 sub 0 23 megi jpns No_If_11 ldrc 23 240 jp End_If_11 No_If_11: mdgi ldrc 0 40 ldrr 1 23 sub 1 0 megi jpns End_If_10 ldrc 23 40 End_If_10: End_If_11: mdgi ldrr 19 23 subo 19 12 megi jpnc No_If_13 ldrc 19 255 jp End_If_13 No_If_13: jpns End_If_12 ldrc 19 0 End_If_12: End_If_13: frequency_control: ; Fuzzy System : frequency_control mdgi ; Init error ldfr 0 19 ; Output fuzzy ldp ldp fzand con ldp ldp fzand con ldp ldp fzand con ldp 26/33 Variable : dFstaror 0 0 7 7 118 0 5 0 5 124 0 10 0 10 128 0 14 AN1291 - APPLICATION NOTE ldp fzand con ldp ldp fzand con out megi 0 14 132 0 9 0 9 138 14 ; ; End Fuzzy System : frequency_control frequency_calculator: mdgi addo 13 14 megi mdgi ldrc 0 240 sub 0 13 megi jpns No_If_15 ldrc 13 240 jp End_If_15 No_If_15: mdgi ldrc 0 40 ldrr 1 13 sub 1 0 megi jpns End_If_14 ldrc 13 40 End_If_14: End_If_15: slip_calculator: mdgi ldrr 27 13 subo 27 12 megi jpnc No_If_17 ldrc 27 255 jp End_If_17 No_If_17: jpns End_If_16 ldrc 27 0 End_If_16: End_If_17: ldrc 21 0 slip_control: ; Fuzzy System : slip_control mdgi ; Init slip ldfr 0 27 ; Init Fstator 27/33 AN1291 - APPLICATION NOTE ldfr 1 ; Output fuzzy ldp ldp fzand con ldp ldp fzand con ldp ldp fzand con ldp ldp fzand con ldp ldp fzand con ldp ldp fzand con ldp ldp fzand con ldp ldp fzand con ldp ldp fzand con ldp ldp fzand con ldp ldp fzand con ldp ldp fzand con ldp ldp fzand con ldp ldp fzand con ldp ldp fzand 28/33 13 Variable : voltage_level 1 0 11 3 124 1 11 0 6 116 1 11 0 1 108 1 11 0 12 100 1 11 0 8 92 1 0 4 3 108 1 4 0 6 100 1 4 0 1 92 1 0 4 12 84 1 0 4 8 76 1 0 13 3 92 1 0 13 6 84 1 0 13 1 76 1 0 13 12 68 1 0 13 8 AN1291 - APPLICATION NOTE con ldp ldp fzand con ldp ldp fzand con ldp ldp fzand con ldp ldp fzand con ldp ldp fzand con ldp ldp fzand con ldp ldp fzand con ldp ldp fzand con ldp ldp fzand con ldp ldp fzand con out megi 60 1 0 0 3 76 1 0 0 6 68 1 0 0 1 60 1 0 0 12 52 1 0 0 8 44 1 0 2 3 60 1 0 2 6 52 1 0 2 1 44 1 0 2 12 36 1 0 2 8 28 30 ; ; End Fuzzy System : slip_control jp no_operation ; ; End procedures "main" ***** AD_Converter: ; ** Start procedures "AD_Converter" set_sinus_frequency: mdgi ldrr 0 10 sub 0 13 megi jpnz End_If mdgi inc 24 megi mdgi 29/33 AN1291 - APPLICATION NOTE inc 25 megi mdgi inc 26 megi ldrc 10 255 End_If: mdgi inc 10 megi RetI2: reti ; ; End procedures "AD_Converter" ***** PwmTimer0: ; ****** Start procedures "PwmTimer0" inc_Fr_measure: mdgi inc 11 megi RetI1: reti ; ; End procedures "PwmTimer0" ****** PwmTimer1: ;****** Start procedures "PwmTimer1" reti ; ; End procedures "PwmTimer1"******* PwmTimer2: ;****** Start procedures "PwmTimer2" reti ; ; End procedures "PwmTimer2"******** External: ; ******* Start procedures "External" WatchDog_0: ; WDT Setting wdtrfr Jump0: mdgi ldrc sub megi jpnz jp 0 0 End_If_1 enable_Tim0_int End_If_1: 30/33 0 20 AN1291 - APPLICATION NOTE disable_Tim0_int: ; IrqEnableMask mdgi ldrc 0 3 ldcr 0 0 megi Fr_calculator: ldrc 20 0 ldrc 21 1 mdgi ldrc 0 120 sub 0 11 megi jpns End_If_2 ldrc 11 120 End_If_2: ldrc 29 8 mdgi ldrc 31 17 mult 31 11 megi mdgi ldrr 0 31 ldrr 1 32 div 0 29 ldrr 12 1 megi RetI0: reti enable_Tim0_int: ; IrqEnableMask mdgi ldrc 0 7 ldcr 0 0 megi reset_Fr_measure: ldrc 11 0 ldrc 20 1 jp RetI0 ; ; End procedures "External" ********* voltage: ; ******* Start procedures "voltage" duty_cycle_calculator: mdgi ldrc 0 128 ldrr 1 28 sub 1 0 megi jps No_If_5 mdgi ldrc 0 127 and 28 0 megi mdgi ldrr 33 28 31/33 AN1291 - APPLICATION NOTE mult megi mdgi ldrr ldrr div ldrr megi mdgi ldrc ldrr sub megi jpns mdgi ldrc sub ldrr megi jp 33 30 0 1 0 15 33 34 22 1 0 1 1 127 15 0 No_If_3 0 0 15 127 15 0 End_If_3 No_If_3: ldrc 15 0 End_If_3: jp End_If_5 No_If_5: mdgi ldrr mult megi mdgi ldrr ldrr div ldrr megi mdgi ldrc ldrr sub megi jpns mdgi ldrc add megi jp 33 33 28 30 0 1 0 15 33 34 22 1 0 1 1 128 15 0 No_If_4 0 15 128 0 End_If_4 No_If_4: ldrc 15 255 End_If_4: End_If_5: Return0: ret ; ; End procedures "voltage" ************ 32/33 AN1291 - APPLICATION NOTE 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 trademark of STMicroelectronics 2000 STMicroelectronics - All Rights Reserved FUZZYSTUDIOTM is a registered trademark of STMicroelectronics STMicroelectronics GROUP OF COMPANIES http://www.st.com Australia - Brazil - China - Finland - France - Germany - Hong Kong - India - Italy - Japan - Malaysia - Malta - MoroccoSingapore - Spain - Sweden - Switzerland - United Kingdom - U.S.A. 33/33