Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
THE SIMULATION OF THE DIRECT TORQUE CONTROL OF PERMANENT MAGNET SYNCHRONOUS MOTOR.
A project report submitted in partial fulfillment of the requirements of the award of the degree of Master of Engineering (Electrical Power)
MAY, 2007
ii
iv
I declare that this thesis The Simulation Of The Direct Torque Control Of Permanent Magnet Synchronous Motor is the result of my own research except for the works that have been cited in the reference. The thesis has not been accepted any degree and not concurrently submitted in candidature of any other degree.
____ ___________
To my beloved husband, mother and family, for their encouragement, blessing and inspiration..
vi
ACKNOWLEDGEMENTS
Alhamdulillah, I am grateful to Allah SWT on HIS blessing and mercy for making this project successful.
I would like to extend my deepest gratitude to my supervisor, PM Dr Nik Rumzi bin Nik Idris for his invaluable, committed and continuous supervision, guidance and patience throughout this project.
I would like to thank all the people involved in the preparation of this thesis especially to all the lecturers who have taught me, thank you for the lessons that has been delivered. A special thank to my husband for his endless support and encouragement.
vii
ABSTRACT
The direct torque control theory has achieved great success in the control of induction motor. Many attempts have been made to implement the idea of DTC of induction motor to PMSM since 1990s. The DTC is implemented by selecting the proper voltage vector according to the switching status of inverter which was determined by the error signals of reference flux linkage and torque with their measured real value acquired by calculating in the stationary reference frame by means of simply detecting the motor voltage or currents. Aiming at the DTC in PMSM Drives, this project explained the theoretical basis of the direct torque control (DTC) for PMSM firstly. Then explained the difference between the application of DTC to PMSM and to IM. Finally the Matlab/Simulink models were developed to examine the DTC for PMSM and IM. The simulation results is presented and explained in detail.
viii
ABSTRAK
Direct Torque Control berjaya digunakan bagi mengawal Motor Aruhan . Oleh
yang demikian berbagai usaha dilakukan oleh para penyelidik bagi menggunakan DTC mengawal Motor Segerak Magnet Kekal (PMSM) sejak tahun 1990. DTC mempunyai banyak kelebihan berbanding cara kawalan yang lain terutamanya FOC. Cara DTC ialah pada mulanya tork and fluks motor dianggarkan melalui voltan dan arus motor yang diukur. Tork dan fluks ini dibandingkan dengan tork dan fluks rujukan. Hasil perbezaannya dibandingkan dalam pembanding hysteresis dan seterusnya vektor voltan yang sesuai dipilih untuk dibekalkan kepada motor berdasarkan jadual penyuisan bagi penyongsang. Projek ini menggunakan cara kawalan DTC dalam mengawal PMSM. Pada mulanya teori PMSM dan DTC dibincang dan diterangkan dengan jelas. Kemudian model-model simulink dibina bagi tujuan simulasi. Simulasi dilakukan dengan menggunakan applikasi Matlab Simulink. Simulasi dilaksanakan dan hasil simulasi dibentang dan dibincangjan.
ix
TABLE OF CONTENTS
TITLE
ACKNOWLEDGEMENTS ABSTRACT ABSTRAK TABLE OF CONTENTS LIST OF TABLES LIST OF FIGURES LIST OF SYMBOLS LIST OF ABBREVIATIONS
INTRODUCTION Introduction Objectives Scope of project Research Methodology Literature Review Structure and Layout of Thesis 1 2 2 2 3 5
x 2.2 Model of the Permanent Magnet Synchronous Motor. 2.2.1 Motor Equation 2.2.2 Parks Transformation 2.3 2.4 2.5 2.6 The Torque Equation In xy Reference Frame The Flux Linkage Equations In The xy Reference Frame PMSMs With Pole Saliency Summary 6 9 12 14 10 11 12
CONTROL SCHEMES FOR PERMANENT MAGNET SYNCHRONOUS MOTOR 3.1 3.2 3.3 Introduction Scalar Control (Volts/Hertz Control) Vector Control 3.3.1 Field Oriented Control 3.3.2 Direct Torque Control 3.4 Summary 15 16 17 17 18 19
DIRECT TORQUE CONTROL 4.1 4.2 4.3 4.4 4.5 Introduction Torque Control principle of DTC for PMSM Amplitude Control Of Stator Flux Linkage The control of the rotation of stator flux linkage (s ). The implementation 0f the Direct Torque Control System 4.5.1 Flux and Torque Estimator 4.5.2 Torque and Flux Hysteresis Comparator 4.5.3 Switching Table 4.5.4 Voltage Source Inverter 4.6 Summary 26 28 29 30 32 20 21 21 23 25
xi 5.1 5.2 Introduction Simulink Block of DTC for PMSM 5.2.1 Torque and Flux Hysteresis Block 5.2.2 Subsystem Block 5.2.3 PMSM Model 5.2.4 Stator Flux Voltage Model 5.3 5.4 Simulink Block of the DTC for IM Results 5.4.1 The DTC performance of PMSM. 5.4.2 The DTC performance of IM 5.4.3 5.5 Comparison of DTC performance in PMSM and IM Summary 60 33 37 36 37 38 39 40 43 44 49 53
CONCLUSION & FUTURE WORKS 6.1 6.2 Conclusion Suggestion for future work. 61 62
63 65 69 73
xii
LIST OF TABLES
TITLE The switching table for Inverter The switching table for Inverter Parameter Values of PMSM used in Simulation Parameter Values of PMSM used in Simulation
PAGE 25 33 34 41
xiii
LIST OF FIGURES
FIGURE NO. 2.1 2.2 3.1 4.1 4.2 4.3 4.4 4.5 4.6 5.1 5.2 5.3 5.4 5.5 5.6 5.7
TITLE The stator and rotor flux linkages in different frames Equivalent Circuit of PMSM Some Common Control Techniques Used For PMSM The movement of the end of stator flux linkage. The control of the stator flux linkage Block Diagram Of the basic DTC For PMSM 2-level torque hysteresis comparator 2-level flux hysteresis comparator VSI and connection to PMSM Simulink Block of DTC for PMSM Model of the torque and Flux hysteresis comparator The actual torque, reference torque and the output of the hysteresis The actual flux linkage, reference flux and the output of the hysteresis comparator Simulik model of Subsytem block. Simulink Block of PMSM Stator flux voltage model
PAGE 9 13 19 26 26 28 32 32 34 35 35 36 37 38 39 40
xiv 5.8 5.9 5.10 5.11 5.12 5.13 5.14 5.15 5.16 5.17 5.18 5.19 5.20 5.21 5.22 5.23 5.24 5.25 5.26 5.27 The Simulink Block of DTC for IM Simulink Block of IM The Torque hysteresis comparator block for IM The waveform of the stator flux linkage, the developed torque and speed of the PMSM The actual and reference torque The torque response The stator flux linkage and reference flux Flux and Torque ripple of PMSM Actual Torque, torque error and hysteresis comparator The actual and error of the stator Linkage flux and the hysteresis comparator The waveform of the stator flux linkage, the developed torque and speed The actual and reference torque of IM The waveform of the actual stator flux linkage and the reference. The actual flux linkage , the error and the flux hysteresis comparator output. The actual torque , the torque error and the torque hysteresis comparator output. The flux and torque ripple of IM The waveforms of flux, torque and speed (a) PMSM (b) IM Torque response of PMSM and IM Torque ripples of PMSM and IM Actual and reference flux linkage of PMSM and IM 42 42 43 44 45 45 46 47 47 48 49 50 51 53 54 55 56 57 58 59
xv
LIST OF SYMBOLS
Ld Lq id Vd iq Vq J B L s f Va,Vb,Vc Rs P Te r m dc Sa,Sb,Sc
d-axis self inductance q- axis self inductance d-axis current d-axis voltage q- axis current q- axis voltage inertia friction Self inductance Stator flux linkage Field flux linkage output Torque hysteresis output flux hysteresis load angle Three Phase Voltage rotor resistance pairs of pole develop torque rotor electrical speed rotor mechanical speed. DC Voltage switching states
xvi
LIST OF ABBREVIATIONS
Direct Torque Control Permanent magnet Synchronous Motor Induction Motor Voltage Source Inverter Field Oriented Control Voltage Space Vector
CHAPTER 1
INTRODUCTION
1.1 Introduction Permanent magnet synchronous motors (PMSM) are widely used in low and mid power applications such as computer peripheral equipments, robotics, adjustable speed drives and electric vehicles.
The growth in the market of PMSM motor drives has demanded the need of simulation tool capable of handling motor drive simulations. Simulations have helped the process of developing new systems including motor drives, by reducing cost and time. Simulation tools have the capabilities of performing dynamic simulations of motor drives in a visual environment so as to facilitate the development of new systems. In this work, the simulation of a direct torque control of PMSM is developed using Simulink. The Direct Torque Control is one of the high performance control strategies for AC machine. The DTC scheme has been realized successfully in the Induction Motor drives. The aim of the project is to study the implementation of the Direct Torque Control (DTC) in Permanent Magnet Synchronous Motor (PMSM).
1.2 Objectives
The objectives of the project are: i) To stimulate the Direct Torque Control (DTC) of Permanent Magnet Synchronous Motor (PMSM) and Induction Motor (IM). ii) To compare the performance of the DTC of Permanent Magnet
The scope of work for this project: i) ii) iii) PMSM with saliency is considered. Simulation is performed using MATLAB Simulink. The performance of DTC in PMSM and IM are discussed based on the simulation results. 1.4 Research Methodology
The research work is undertaken in the following stages: i) ii) Studied the application of MATLAB simulink. Studied the theoretical basis of the direct torque control (DTC) for Permanent Magnet Synchronous Motor (PMSM) drives and Induction Motors.
3 iii) iv) Simulation of DTC of PMSM and IM is performed using Simulink. Analyzed the simulation results.
The original concept of DTC was proposed by Takahashi and Noguchi in 1986 for application in Induction Motors. Their idea was to control the stator flux linkage and the torque directly , not via controlling the stator current. This was accomplished by controlling the power switches directly using the outputs of hysteresis comparators for the torque and the modulus of the stator flux linkage and selecting an appropriate voltage vector from a predefined switching table. The table was called the optimum switching table. The measurement of the rotor angle was not used.
A same kind
At first,
Takahashi and Noguchi did not give any name to their new control principle. In a later paper by Takahasi and Ohmori (1987) the control system was named the direct torque control, DTC. Depenbrock called his control method Direct Self Control, DSC.
Tiitenen et al discussed the first industrial application of the DTC. After that , the number of papers on the DTC has grown tremendously on different aspects of the DTC for asynchronous motors. In recent years there has been interest to apply the DTC to permanent magnet synchronous motors.
4 L.Zhong et al discussed the implementation of DTC in PMSM Drives. In 1998, Rahman et al proposed a DTC scheme for a wide speed range operation of an interior PMSM drive. The proposed scheme possess some attractive features compared to the conventional current-controlled drives like field oriented control (FOC). Later on, Tang et al proposed a DTC control schemes for the IPM featuring almost fixed switching frequency.
In 2002, Rahman et al, proposed a completely sensorless DTC control for an IPM drive, which uses a new speed estimator from the stator flux linkage vector and the torque angle. To reduce the torque ripples, Sun et al proposed a fuzzy logic algorithm to refine the selection of the voltage vectors. Today, the DTC has become an accepted control method beside the field oriented control.
The purpose of this thesis is to present a simulation of a direct torque controlled of permanent magnet synchronous motor and compared the performance with IM. The simulation is carried out by using Matlab Simulink. The thesis is organized into six chapter:
Chapter 1 gives the introduction to project, stating its objectives, scope of work, research methodology and overview.
5 Chapter 2 introduces to permanent magnet synchronous motor and the equation related to PMSM such as the voltage, stator flux linkage and torque.
Chapter 3 presents some common control techniques used for control of Permanent Magnet Synchronous Motors (PMSM).
Chapter 4 present and analyzed the implementation of the Direct Torque Control in PMSM drives.
Chapter 5 explain the simulink block of DTC of PMSM and Induction motor and also discuss the results obtained from the simulation
Chapter 6 gives the summary of this project and present the recommendation for future work to improve the performance of the DTC of PMSM.
CHAPTER 2
2.1 Introduction
Two types of permanent magnet ac motor drives are available in the drive industry. There are Permanent Magnet Synchronous distribution. Motor (PMSM) drive with a sinusoidal flux distribution and the brushless dc motor drive with a trapezoidal flux
The Permanent Magnet Synchronous Motor (PMSM) has numerous advantages over other machines that are conventionally used for ac servo drives. The stator current of the induction motor (IM) contains magnetizing as well as torque-producing components. The use of the permanent magnet in the rotor of the PMSM makes it unnecessary to supply magnetizing current through the stator for constant air-gap flux; the stator current need only be torque producing. Hence for the same output, the PMSM will operate at a higher power factor (because of the absent of magnetizing current).and will be more efficient than Induction Motor. The development of the PMSM was to remove the foregoing disadvantages of the Synchronous Motor by replacing its field coil, DC power supply and slip rings with a permanent magnet [7]
2.2
The two axes PMSM stator windings can be considered to have equal turn per phase. The rotor flux can be assumed to be concentrated along the d axis while there is zero flux along the q axis, an assumption similarly made in the derivation of indirect vector controlled induction motor drives. Also, rotor flux is assumed to be constant at a given operating point.
8 There is no need to include the rotor voltage equation as in the induction motor since there is no external source connected to the rotor magnet and variation in the rotor flux with respect to time is negligible.
The stator equations of the induction machine in the rotor reference frames using flux linkages are taken to derive the model of the PMSM. The rotor reference frame is chosen because the position of the rotor magnets determine independently of the stator voltages and currents, the instantaneous induced emfs and subsequently the stator currents and torque of the machine. In Induction motor , the rotor fluxes are not independent variables, they are influenced by the stator voltage and currents and that is why any frame of reference is suitable for the dynamic modeling of the induction machine.
2.2.1
Motor Equation
The stator flux linkage vector s and rotor flux linkage f of PMSM can be drawn in the rotor flux (dq), stator flux (xy), and stationary (DQ) frames as shown in figure 1.
Vs
is
ix id
f r
D
Figure 2.1
When rotor references frame are considered, it means the equivalent q and d axis stator windings are transformed to the reference frames that are revolving at rotor speed. The consequences is that there is zero speed differential between the rotor and stator magnetic fields and the stator q and d axis windings have a fixed phase relationship with the rotor magnet axis which is the d axis in the modeling.
The angle between the stator and rotor flux linkage is the load angle when the stator resistance is neglected. In the steady state , is constant corresponding to a load torque and both stator and rotor flux rotate at synchronous speed. In transient operation varies and the stator and rotor flux rotate at different speeds. Since the electrical time constant is normally much smaller than the mechanical time constant , the rotating speed
10 of the stator flux with respect to the rotor flux can be easily changed. It will be shown in this chapter that the increase of torque can be controlled by controlling the change of or the rotating speed of the stator flux.
The well-known voltage equations in the rotor reference frame are as follows: d = Rd id + d d - rq dt q= Rq iq + d q + rd dt (1) (2)
where Rd and Rq are the quadrature and direct-axis winding resistances which are equal and be refered to as Rs is the stator resistance.
To compute the stator flux linkage in the q and d axes, the current in the stator and rotor are required. The permanent magnet excitation can be modeled as a constant current source, if. The rotor flux along d axis , so the d axis rotor current is if. The q axis current in the rotor is zero , because there is no flux along this axis in the rotor, by assumption.
= =
where Lm is the mutual inductance between the stator winding and rotor magnets. Substituting these flux linkages into the stator voltage equations gives the stator equations:
11
q = d =
(5) (6)
q d
=
Rq + Lq -rLq
rLd Rd + Ld
iq id
+
rLm if
f
(7)
which upon substitution of the flux linkages in terms of the inductances and current yields Te = 3 P ( f iq + (Ld - Ld ) iq id ) 2 (9)
f is the flux through the stator windings due to the permanent magnet. f L m if ( 10 )
Solving for the rotor mechanical speed from the above equation : m = (Te + TL + B)dt
( 12 )
12 J And m = r (2/P) ( 13 )
In the above equation r is the rotor electrical speed where as m is the rotor mechanical speed.
Converting the phase voltages variables Vabc to Vdqo variables in rotor reference frame the following equations are obtained: Vq Vd = 2/3 V0 Va Vb = 2/3 Vc cos r sin r cos r cos (r -120) cos ( r +120) cos (r -120) cos ( r +120) sin (r -120) sin ( r +120) sin r sin (r -120) sin ( r +120) Va Vb Vc Vq Vd V0 ( 15 ) ( 14 )
From the d-q modeling of the motor using the stator voltage equations the equivalent circuit of the motor can be derived. Assuming rotor d axis flux from the
13 permanent magnet is represented by a constant current source as described in the following equation f
=
Rs + +
rq +
rd - +
id
Vd Lm If Vq
iq
Lm
2.3
With the transformation below, equation (6) can be transformed to stator flux reference frame.
Fx Fy
Fd Fq
(16)
14
Fd Fq
Fx Fy
(17)
From figure 1, it can be found that sin = q |s| cos = d |s| (18)
where | s| represents the amplitude of the stator flux linkage. Substituting (16) and (17) for current into (8) gives : T = 3 P [ d (ix sin + iy cos ) - q (ix cos + iy sin ) ] 2 = 3 P [ ix dq + iy d 2 - ix dq + iy d 2 (19)
| s|
| s|
| s|
| s|
Equation (19) means that the torque is directly proportional to the y axis component of the stator current if the amplitude of the stator flux linkage is constant.
d q
Ld 0 0 Lq
id iq
f 0
(20)
x y
Ld 0 0 Lq
f 0
(21)
2.5
16 For a PMSMs with pole saliency, Ld Lq, the torque equation in terms of stator flux linkage and angle can be obtained by solving ix with y= 0:
(22)
Equation (23) consists of two terms, the first is the excitation torque, which is produced by the permanent magnet flux. The second term is the reluctance torque. For PMSM with pole saliency, the amplitude of the stator flux should be changed with the change of actual torque even for constant torque operation. Under the condition of constant amplitude of s , by differentiating (23) with respect to time, the rate of increasing of torque at t = 0 can be obtained in (24).
(24)
From (23) and (24) can be seen that electromagnetic torque in PMSM is determined by the angle; quick dynamic response can be achieved by changing as quickly as possible. And according to (25) , fast dynamic response can be achieved if the amplitude of the stator flux linkage is chosen as ( 25) [5 ] s < Lq f (25)
17 Lq Ld
2.6
Summary
In this chapter the motor model was derived. The equations expressed in the rotor reference frame is used in simulations. The electromagnetic torque for PMSM with pole saliency was derived. From the toque equation can be seen that that electromagnetic torque in PMSM is determined by the angle; quick dynamic response can be achieved by changing as quickly as possible and fast dynamic response can be achieved if the amplitude of the stator flux linkage is chosen according to equation (25).
CHAPTER 3
18
3.1 Introduction
PMSM control techniques can be divided into scalar and vector control. Scalar control is based on relationships valid in steady-state. Amplitude and frequency of the controlled variables are considered. In vector control amplitude and position of a controlled space vector is considered. These relationships are valid even during transients which is essential for precise torque and speed control.
Scalar Based
Vector Based
Voltz/Hertz
19
Scalar control is based on relationships valid in steady state. Only magnitude and frequency of voltage, current, etc. are controlled. Scalar control is used e.g. where several motors are driven in parallel by the same inverter.
Volts/Hertz control is among the simplest control schemes for motor control. The control is an open-loop scheme and does not use any feedback loops. The idea is to keep stator flux constant at rated value so that the motor develops rated torque/ampere ratio over its entire speed range.
The problem with scalar control is that motor flux and torque in general are coupled. This inherent coupling affects the response and makes the system prone to instability if it is not considered. In vector control, not only the magnitude of the stator and rotor flux is considered but also their mutual angle.
Field Oriented Control was invented in the beginning of 1970s and it demonstrates that an induction motor or synchronous motor could be controlled like a separately excited dc motor by the orientation of the stator mmf or current vector in relation to the rotor flux to achieve a desired objective.
20
The vector control of currents and voltages in control of the spatial orientation of the electromagnetic fields in the machine and has led to the name field orientation. Field Oriented Control usually refer to controllers which maintain a 90 electrical angle between rotor and stator field components. System which depart from the 90 orientation are referred to as field angle control or angle control.
The performance of FOC is comparable to DC Machine. It produce less ripples but the system is more complex and less robust compare to DTC.
The Direct Torque Control was introduced in the 1980s for Induction Machine for torque and flux control. It was developed for PMSM in 1990s. The DTC is gaining popularity due to its simple control structure and easy implementation .
The
principle
of Direct and
Torque flux
Control are
(DTC) is compared
voltage vectors according to the difference between reference and actual value of torque and flux linkage. Torque errors comparators. Depending on the comparators a voltage vector is selected from a table. Advantages of the DTC are low complexity and that it only need to use of one motor parameter, the stator resistance. No pulse width modulation is needed; instead one of the six VSI voltage vectors is applied during the whole sample period. All calculations are done in a stationary reference frame which does not involve the explicit knowledge of rotor position. Still, for a synchronous motor, rotor position must be known at startup.
21
The DTC hence require low computational power when implemented digitally. The system possess good dynamic performance but shows quite poor performance in steady-state since the crude voltage selection criteria give rise to high ripple levels in stator current, flux linkage and torque. Its simplicity makes it possible to execute every computational cycle in a short time period and use a high sample frequency. For every doubling in sample frequency, the ripple will approximately halve. The problem is that the power switches used in the inverter impose a limit for the maximum sample frequency.
3.4 Summary
This chapter presents some of the control techniques used for permanent magnet motor control. A scalar control technique called Volts/hertz control being among the simplest control methods. It is used where exact torque and flux control is not essential but where speed control is desirable, like when several motors are driven in parallel by a single inverter.
Vector control is used where high performance torque and flux control is needed. Vector control can be implement by using FOC or DTC technique. DTC technique is simple, robust and offer good dynamic performance. FOC technique gives the best performance in terms of ripples level but requires more processor power and are more complicated to implement.
22
CHAPTER 4
4.1 Introduction
23 This chapter discussed the three signal which affect the control action in a DTC system and also presents the block diagram of the basic DTC system. Each block is described in detail and the functions of all system blocks are explained.
There are 3 signals which affect the control action in a DTC system; 1. Torque - Te 2. The amplitude of the Stator Flux linkage - |s| 3. The angle of the resultant flux linkage vector -
In the chapter 2, it has been proven that the change of torque can be controlled by keeping the amplitude of the stator flux linkage constant and increasing the rotating speed of the stator flux linkage as fast as possible. The amplitude and rotating speed of the stator flux linkage can be controlled by selecting the proper stator voltage vectors.
The stator flux linkage of a PMSM expressed in the stationary reference frame is s = (s - Ris ) dt (26)
24
Each voltage vector is constant during the switching interval and (26) is then rewritten as in (27).
s = st - R is dt +
s|t =0
(27)
Neglecting the stator resistance , the stator flux linkage can be directly defined by the integration of the voltage vector. s = st + s|t =0 (28)
Equation (28) explains that the movement of the end of the stator flux linkage has the same direction with the given voltage vector, as shown in Figure 4.1. Therefore, it is possible to control the amplitude, moving direction and moving speed of the stator flux linkage by selecting proper voltage vector. s|t =0 at the instant switching. is the initial stator flux linkage
25
V0 & V8
V4
V3
2 s 1
V3 V4
V2 V1
V3 is applied
4 V5 5 V6
V2
s|t=0
V5 V6
6 V1
Hysteresis band
= section
V = voltage vector
For the convenience of selecting voltage vector, it is desired to divide the space vector plane into six-region as shown in figure 4.1 In each region , two adjacent voltage vectors, which give the minimum switching frequency , are selected to increase or decrease the amplitude of stator flux linkage. ,respectively. For example, in figure 4.1, vectors V2 and V3 are selected to increase and decrease the amplitude of stator flux linkage when s in region one and rotating in counter clockwise. In this way , s can be controlled at the required value by selecting the proper voltage vectors. Figure 4.2
26 shows how the voltage vectors are selected for keeping s within a hysteresis band when s is rotating in the counter clockwise direction.
V4 V5 3 V5 4 V6 V5 V4 V5 V6 V1 V6 V1 V6 V3 2 V2
V3 V4 V3 V2 1 V1 V3
V4
V2 V2
V1
It is seen from (28) that s will stay at its original position when zero voltage vectors are applied. This is true for an induction motor. In an Induction Motor, the stator flux linkage is uniquely determined by the stator voltage, and when the zero voltage
27 vectors are selected the stator flux linkage vector will be standstill in the position where it was and the electromagnetic torque will decrease rapidly. In a PMSM, however , the stator flux linkage is jointly determined by both the stator voltage and the rotor magnet flux. Since the permanent magnets rotate all the time, the stator flux linkage still exists even if the zero voltage vectors are used, and as a result, the zero voltage vectors will only cause the torque decrease slightly. An inverse voltage vector is normally selected to reduce the torque rapidly. The zero voltage vectors are not used for controlling the stator flux linkage. Thus s should always be in motion with respect to rotor flux linkage.
In the previous chapter, it is seen that , the electromagnetic torque can be controlled effectively by controlling the amplitude and rotational speed of the stator flux linkage. For counter-clockwise operation, if the actual torque is smaller than the reference, the voltage vectors that keeps s rotating in the same direction are selected. The angle increases as fast as it can, and the actual torque increases as well. Once the actual torque is greater than the reference, the voltage vectors that keep s rotating in the reverse direction are selected instead of the zero voltage vectors. The angle decreases, and the torque decreases also.
By selecting the voltage vectors in this way, the stator flux linkage (s) is rotated all the time and its rotational direction is determined by the output of the hysteresis controller for the torque.
28 The switching table for controlling the amplitude and rotating direction of s is as below and is used for both direction of operations. In Table 4.1, and are the outputs of the hysteresis controllers for the flux linkage and torque, 1 - 6 denote the section of the space vector plane where the present flux linkage vector is located, V1 V6 are the voltage vectors to be selected. This table formed the control strategy for DTC of PMSM. If the = 1, then the actual flux linkage is smaller than the reference value. The same is true for the torque.
Table 4.1: The switching table for Inverter -Section (stator flux linkage position) 1 2 3 4 5 6 V2(110) V3(010) V4(011) V5(001) V6(101) V1(100) V6(101) V1(100) V2(110) V3(010) V4(011) V5(001) V3(010) V4(011) V5(001) V6(101) V1(100) V2(110) V5(001) V6(101) V1(100) V2(110) V3(010) V4(011)
Flux = 1
Torque
=1 =0
= 0
=1 = 0
The basic DTC scheme is indicated in figure 4.3, torque and flux signals are obtained from the estimator. These are regulated by using two hysteresis controllers. The
29 hysteresis controllers outputs in turn switch the three inverter legs, applying a set of voltage vectors across the motor.
Va
Tref
Terr
Hysteresis Controller
Switching table
Sa Sb Sc
Te
VSI/PWM Inverter
Vb
PMSM
Vc
ref s
err
Hysteresis controller
Vdc
In the DTC there are no extra sensors needed compared to FOC except the dcbus voltage sensors. The continuous rotor position which is essential for torque control in the FOC is not required if the initial rotor position is known.
4.5.1
30 Flux and torque estimator are used to determine the actual value of the torque and flux linkage. Into this block enters the VSI voltage vector transformed to the qdstationary reference frame.
The three-phase variables are transformed into dq axes variables with the following transformation:
d q
2 3 0
-1 3 -1 3
-1 3 1 3
a b c
(29)
The stator flux linkage is estimated by taking the integral of diffrerence between the input voltage and the voltage drop across the stator resistance as,
s = (d 2 + q2 )
(31)
In this block , the location of stator flux linkage () is determined by the load angle () i.e the angle between the stator and rotor flux linkage. The load angle must be
31 known so that the DTC can choose an appropriate set of vectors depending on the flux location. The load angle can be determined by : = tan-1 d q The electromagnetic torque can be estimated with; Te = 3 P ( d iq - q id ) 2 (32)
4.5.2
The estimated torque and stator flux linkage are compared with the reference torque and stator flux linkage . The difference between reference and estimated value is compared in this block. If the actual torque is smaller than the reference value, the comparator output at state 1 or otherwise.
state 1
32 e -1
state 1
e 0
33 The hysteresis comparator states, and , together with the section number , are now used by the switching table block to chose an appropriate volatge vector. The switching table used in this project is shown in Table 4.2. A high hysteresis state increases the corresponding quantity and vice versa. The selected voltage vector is sent to the Voltage Source Inverter then synthesized.
Table 4.2: The switching table for Inverter Flux = 1 Torque -Section (stator flux linkage position) 1 V2 11-1 V7 111 V4 -111 V1 1-1-1 V0 -1-1-1 V5 -1-11 2 V3 -11-1 V0 -1-1-1 V5 -1-11 V2 11-1 V7 111 V6 1-11 3 V4 -111 4 V5 -1-11 5 V6 1-11 6 V1 1-1-1
=1 =0
= -1
= 0
=1 =0
= -1
V7 V0 111 -1-1-1 V6 V1 1-11 1-1-1 V3 V4 -11-1 -111 V0 V7 -1-1-1 111 V1 V2 1-1-1 11-1
V7 V0 111 -1-1-1 V2 V3 11-1 -11-1 V5 V6 -1-11 1-11 V0 V7 -1-1-1 111 V4 V3 -11-1 -111
34
The VSI synthesizes the voltage vectors commanded by the switching table. In DTC, this task is quite simple since no pulse width modulation is used, the output devices stay in the same state during the entire sample period.
Vdc
1 Va
1 Vb
Sa 0
Sb 0
Sc 0
Vc
The connection of power switchers in a VSI with three-phase windings of a PMSM is shown in Figure 4.6 , where the power switches of this voltage source inverter are 180 conducting mode [ SD] , which means only three switching signal Sa, Sb and Sc are needed to uniquely determined the status of six switchers. If the switcher in upper leg of certain phase is on, the switching signal for this phase is defined as S = 1, otherwise S=0 represents the switcher in lower leg of this phase is on. In this way there
35 are six effective VSVs and two zero VSVs existing in the ordinary operation for a inverter. Assuming that the VSV is located in the a-axis of the a, b, c reference frame with phase a voltage Va applied alone, then the inverter output VSVs under different switching states can be expressed as
(33)
where s is the primary voltage vector, Sa, Sb , Sc represent three-phase switching states and 2/3 is a transformation coefficient. According to above equation, the inverter output VSV represent in terms of switching statue where six effective VSVs V1 V6 are apart from each other in space by 60 electric degrees and the two zero VSVs , V0, V7 are located in the centre of the space-vector plane.
The inverter keeps the same state until the output of the hysteresis controllers changes their outputs at the sampling period. Therefore, the switching frequency is usually is not fixed; it is changes with the rotor speed, load and bandwidth of the flux and torque controllers.
4.6 Summary
36
This chapter discussed the three signal which affect the control action in a DTC system and also presents the block diagram of the hysteresis based DTC system. Each block is described in detail and the functions of the blocks are explained.
In DTC technique , the actual flux and torque values are firstly calculated by the estimator. The calculated torque/flux are compared with the torque/flux reference in the hysteresis comparator. The output of the hysteresis comparators and the section number () are used to select the proper stator voltage vector based on the optimal voltage vector switching logic so as to minimize the errors between the actual and reference value of torque/flux. The selected voltage vector is sent to VSI. The VSI synthesizes the voltage vectors commanded by the switching table. The inverter keeps the same state until the output of the hysteresis controllers changes their outputs at the sampling period. Therefore, the switching frequency is usually is not fixed; it is changes with the rotor speed, load and bandwidth of the flux and torque controllers.
37
CHAPTER 5
5.1 Introduction
In Chapter 3 and 4, the PMSM and DTC systems were explained in detail. In this chapter the simulation models of DTC of PMSM and IM are programmed in Matlab Simulink. The simulation models are presented and the results are discussed. The PMSM parameter used in this project are given in Table 5.1. These parameters were taken from reference [13 ]
38 Resistance R (ohm) Inductance [Ld,]H Inductance [Lq,]H Flux Induced by magnets [wb] 0.57 8.72 x10-3 H 22.8 x10-3H 0.108
39
5.2.1
40
. The torque
reference value of -2 Nm to 2Nm at 0.067sec was produced by the signal generator. The flux linkage reference was produced by step response with 0.808Wb.
41
The actual torque, reference torque and the output of the hysteresis
Figure 5.4 : The actual flux linkage, reference flux and the output of the hysteresis comparator 5.2.2 Subsystem Block
42 The subsystem is used to provide three-phase voltage, Va, Vb and Vc to the PMSM . The hysteresis comparator states, and , together with the load angle, are now used by the switching table block (select 2) to choose an appropriate voltage vector. The switching table used in this project is shown in Table 4.2.
43
In this block, the three-phase voltage and current ( Vabc and iabc) are transformed to dq voltage and current by using park transformation. Vabc is 100V. The developed torque is sent to the comparator.
44 The stator flux-voltage model was developed based on the equations below, d = Rd id + d d - rq dt q= Rq iq + d q + rd dt The stator flux-voltage model is used to determine the amplitude of stator flux linkage and the load angle in order to select the proper voltage vector for VSI.
45
The difference between the simulink block of the DTC for IM and PMSM are the torque hysteresis block and motor properties. The torque reference is 15Nm at 15 Hz. The Induction motor parameter is given in Table 5.2 . The simulink block of DTC in IM is given in figure 5.8 and 5.9.
Table 5.2 : Parameter Values of IM used in Simulation Stator Resistance R (ohm) Rotor Resistance R (ohm) Inductance [Ls,]H Inductance [Lr,]H Inductance [Lm,]H Inertia[Jkgm^2] Load torque No of pole 5.5 4.51 306.5 x 10-3 306.5 x 10-3 291.9 x 10-3 0.03 1Nm 4
46
47
The torque hysteresis of the IM is a three level hysteresis comparator. The zero voltage vectors are used in IM because when the zero voltage vectors are selected the stator flux linkage vector will be standstill in the position where it was and the electromagnetic torque will decrease rapidly.
48
5.4 Results
Matlab/Simulink models were developed to examine the basic Direct Torque Control for Permanent Magnet Synchronous Motor and Induction Motor. The simulation results is divided into three section. Section 5.4.1 presents the steady-state
performance of DTC systems in PMSM. The waveforms are flux linkage, torque and speed respectively. The reference torque given is 2Nm to -2Nm and the reference stator flux linkage is set at the rated value 0.808Wb
15Nm to 15Nm. Section 5.4.3 presents the comparison of PMSM and IM performance at the same reference torque and flux.
The PMSM parameter used for this simulation is given in table 5.1. The torque and flux linkage reference is set at -2Nm to 2 Nm and 0.808Wb respectively. The waveforms of torque, speed, flux, hysteresis comparator are presented to show the performance of DTC in PMSM.
Wb
Flux
rpm
Nm
Torque
Speed
Time (s) Figure 5.11 : The waveform of the stator flux linkage, the developed torque and speed of the PMSM. Tref at -2Nm to 2 Nm and 0.808Wb flux reference.
50 Figure 5.11 shows that the motor speed is 1500rpm, the actual flux and torque is about the reference values. There are ripples exist in both waveforms. Figure 5.12 and 5.13 show the torque response of DTC in PMSM. The actual torque response of the Permanent Magnet Synchronous Motor is delayed by 0.6ms compared to the reference torque.
Nm
Nm
Time (s)
Figure 5.12: The actual and reference torque ( Tref =-2Nm to 2 Nm)
51
Figure
5.14 shows that the actual stator flux linkage ripples is varied from
0.797Wb to 0.817Wb at t = 0.01s. The reference flux is set at 0.808Wb. While Figure 5.15 present the flux linkage and torque ripples. The flux linkage ripples of PMSM is about 0.02Wb and torque ripples is about 0.4 Nm
52
Wb
Wb
Time (s) Figure 5.14 : The stator flux linkage and reference flux (Flux ref at 0.808Wb)
Flux ripples
Wb
Nm
Torque ripples
53
Nm
Nm
Terr
Time (s)
The torque hysteresis band for PMSM is set at 0.2Wb. Figure 5.16 shows that the status of the hysteresis comparator (): 1 when err = 0.2 Wb -1 when err = -0.2Wb
54
Wb
Wb
err
Time (s)
Figure 5.17 : The actual and error of the stator Linkage flux and the hysteresis comparator.
Figure 5.17 shows that the status of the hysteresis comparator (): 1 when err = 0.01Nm 0 when err = -0.01Nm The flux hysteresis band is set at 0.01Nm
Wb
Flux
Nm
Torque
pu
Speed
Time (s)
Figure 5.18: The waveform of the stator flux linkage, the developed torque and speed of the IM , torque reference is 15Nm to -15Nm, flux linkage is 1.2 Wb
56
Nm
Actual Torque
Nm
Reference Torque
Time (s)
Figure 5.19: The actual and reference torque of IM (Tref = -15Nm to15Nm)
Figure 5.19 shows that the actual torque response of the Induction Motor is delayed by 0.8ms compared to the reference torque
57
Wb
Actual Flux
Reference Flux Wb
Time (s) Figure 5.20 : The waveform of the actual stator flux linkage and the reference .
The reference flux linkage is 1.2 Wb but the actual stator flux linkage shows in figure 5.20 is varied from 1.1Wb to 1.22Wb. The flux ripple is about 0.12Wb.
58
s Wb
err Wb
Time (s)
Figure 5.21 : The actual flux linkage , the error and the flux hysteresis comparator output.
From the above figure shows that the status of the hysteresis comparator (): 0 when err = -0.1 1 when err = 0.1
59
Nm
Nm
Terr
Time (s) Figure 5.22 : The actual torque , the torque error and the torque hysteresis comparator output.
From the above figure shows that the status of the hysteresis comparator (): 1 when err > 0 -1 when err < 0
60
Nm
Wb
Time (s)
Figure 5.23 the flux ripples of IM is about 0.12 Wb while the torque ripples is about 1Nm.
The reference torque for both motors are set at -2 Nm to 2 Nm, 15Hz and flux linkage at 0.808Wb. The motors parameter used as in Table 5.1 and 5.2.
Wb
Flux
Nm
Torque
rpm
Speed
62
Wb
Flux
Nm
Torque
Speed
Time (s) (b) Induction Motor Figure 5.24 : The waveforms of flux, torque and speed (a) PMSM (b) IM when Tref is -2Nm to 2Nm and the flux reference is 0.808Wb.
PMSM
performance is better than IM because the ripples exist in both waveforms is less than IM.
63
Nm
Nm
Reference Torque
Actual Torque
Nm
Nm
Figure 5.25: Torque response of PMSM and IM when Tref is -2Nm to 2Nm
64
Nm
Nm
65
produced by the PMSM and IM. The torque produced by IM has large ripples compare to PMSM. The torque ripples of PMSM and IM is about 0.4Nm and 1Nm respectively.
Wb
Actual Flux
Wb
Reference Flux
66
Wb
Actual Flux
Wb
Reference Flux
Time (s) (b) Induction Motor Figure 5.27 : Actual and reference flux linkage of PMSM and IM
Figure 5.27 shows that the flux ripples of IM is larger than PMSM. The flux ripples of PMSM is 0.02Wb while the flux of IM varies from 0.41Wb to 0.57Wb.
67 5.5 Summary
In this chapter the simulink models and results of DTC of PMSM and IM are presented. The above simulation results show the DTC implemented in PMSM having less torque and flux ripple and good torque response compare to IM.
68
CHAPTER 6
6.1 Conclusion
DTC was introduced in the 1980s for the application of Induction motor. In 1990s , DTC was applied to PMSM . Direct Torque Control has a good dynamic torque response when compared with other control method. The basic principle of the DTC is quite the same for the implementation in PMSM and IM.
Since the introduction of DTC a lot of research has been done to improve the performance of DTC drives while maintaining the good properties such as low complexity, good dynamic response, high robustness.
69 This thesis explained the mathematical equations related to the application of DTC in PMSM. The equations show that the change of torque can be controlled by keeping the amplitude of the stator flux linkage constant and increasing the rotating speed of the stator flux linkage as fast as possible. The amplitude and rotating speed of the stator flux linkage can be controlled by selecting the proper stator voltage vectors. The differences in the DTC technique for PMSM and IM are presented. The simulink block of DTC in PMSM and IM are presented. The simulation results examined the implementation of the direct torque control in permanent magnet synchronous motor and compared its performance with induction motor. The torque and flux linkage reference are kept constant at the same level..
A detailed Simulink model for DTC of PMSM and IM has being developed. Simulink has been chosen from several simulation tools because its flexibility. Mathematical models can be easily incorporated in the simulation and the present numerous toolboxes and support guides simplified the simulation of large system compared to other software. Simulink is capable of showing real time results with reduced simulation time and debugging.
It is shown in the simulation results of DTC in PMSM and IM that the DTC implemented in PMSM having less level of torque and flux ripples and at the same time maintaining good torque response.
70
DTC technique is simple, robust and offer good dynamic performance. The main drawback of the DTC is its relatively high torque and flux ripples and also variable switching frequency. Therefore, the performance of the Direct Torque Control of PMSM can be improved by reduced the high torque and flux ripples and maintaining a constant switching frequency.
The source to the variable switching frequency problem is the use of hysteresis comparators, in particular, the torque hysteresis comparator. The variable switching frequency in a hysteresis-based DTC due to the variation of the time taken for the torque error to touch the upper and lower hysteresis bands, which is caused by the variation of the torque slopes with operating conditions. The torque ripples is directly related to the width of the torque hysteresis comparator. Therefore, a constant switching frequency torque controller should be designed to replace the conventional hysteresis-based controller in order to minimize the torque .
REFERENCES
71 1. I.Takahashi, T. Noguchi (1986). A New quick-response and high efficiency control strategy of an induction machine, IEEE Transactions on Industry Application, Vol 22, 2. Bimal K. Bose(1988), A High-Performance Inverter-Fed Drive System of an Interior Permanent Magnet Synchronous Machine. IEEE Transactions on Industry Application, Vol 24, No.6. 3. Pragasen Pillay(1999) Modelling,Simulation and Analysis of Permanent Magnet Motor Drives. IEEE Transaction On Industry Application, Vol 25. 4. N. R. N. Idris, A.H. M. Yatim.(2004). Direct Torque Control of induction Machines with constant switching frequency and Reduced Torque Ripple. IEEE Transaction On Industry Application, Vol 51, No 4. 5. L.Tang, L.Zhong, M.F. Rahman.(2003). A Novel Direct Torque Control for Interior Permanent-Magnet Synchronous Machine drive with low ripple in torque and flux A speed-sensorless Approach. IEEE Transaction On Industry Application, Vol 39, No. 6. 6. D. Casadie, G.Serra and A.Tani (2000) : Implementation Of A Direct Torque Control Algorithm for Induction Motors Based On Discrete Space Vector Modulation. Power Electronics IEEE Transaction On Power Electronics, Vol 15 No 4. 7. Isao Takashi, Toshishiko Noguchi (1997. Take a look back upon the past decade of direct torque control . IECON 97 8. C.G.Mei, S.K. Panda, J.X.Xu And K.W.Lim.(1999).Direct Torque Control of induction Motor-Variable switching sectors. Proc.IEEE PEDS.
72 9. Z.Tan , Y.Li and M.Li. (2001). A direct Torque Control of induction motor based on three level-inverter in Proc.IEEE PESC, Vol12. 10. C. Martins,X.Roboam, T.A Meynard and A.S. Caryalh.(2002). Switching Frequency Imposition And Ripple Reduction In Dtc Drives By Multilevel Converter. IEEE Transaction On Power Electronics, Vol 17 11. G.Escobar.(2003): A Family of switching Control Strategies for the reduction of Torque Ripple in DTC. IEEE Transaction On Control System, Vol 11, No 6. 12. L.Tang, M.F.Rahman. (2001). A Matlab/Simulink Modul Based on Power System Blocked A New Direct Torque Control Strategy for Interior PMSM Drives System.University of New South Wales, Australia. 13. L.Zhong, M.F.Rahman. (1997). Analysis of Direct Torque Control in Permanent Magnet Synchronous Drives. IEEE Transaction On Power Electronics, Vol 12, No 3. 14. Bimal K. Bose. (2002). Modern Power Electronics and AC Drives. Prentice Hall. 15. S.Dan, F.Weizhong,H.Yikang.(2000). Study on the Direct Torque Control of Permanent Magnet Synchronous motor Drives. Zhejiang university, Hangzhoa, China. 16. S.Dan, J.G. Zhu,H.Yikang.(2003). Continuous Direct Torque Control of Permanent Magnet Synchronous motor Based on SVM. Zhejiang university, Hangzhoa, China 17. Y.Yan, J.Zhu, H.Lu . Direct Torque Control of a Surface-Mounted Permanent Magnet Synchronous motor Based on Accurate Modelling. University of Technology, Sydney, Australia.
73
APPENDIX A :
IMCH.C
74
* sfuntmpl.c: Template C S-function source file. * * ------------------------------------------------------------------------* | See matlabroot/simulink/src/sfuntmpl.doc for a more detailed template | * ------------------------------------------------------------------------* * Copyright (c) 1990-97, by The MathWorks, Inc. * All Rights Reserved * $Revision 1.1 $ * You must specify the S_FUNCTION_NAME as the name of your S-function. */ #define S_FUNCTION_NAME imch /* Input Arguments */ /* * Need to include simstruc.h for the definition of the SimStruct and * its associated macro definitions. */ /* #include "tmwtypes.h" */ #include "tmwtypes.h" #include "simstruc.h" #define Rs ssGetArg(S,0) #define Rr ssGetArg(S,1) #define Ls ssGetArg(S,2) #define Lr ssGetArg(S,3) #define Lm ssGetArg(S,4) #define pole ssGetArg(S,5) /*====================* * S-function methods * *====================*/ /* Function: mdlInitializeSizes =============================================== * Abstract: * The sizes information is used by SIMULINK to determine the S-function * block's characteristics (number of inputs, outputs, states, etc.). */ static void mdlInitializeSizes(SimStruct *S) { ssSetNumContStates( S, 4); /* number of continuous states */ ssSetNumDiscStates( S, 0); /* number of discrete states */ ssSetNumInputs( S, 3); /* number of inputs */ ssSetNumOutputs( S, 5); /* number of outputs */ ssSetDirectFeedThrough(S, 0); /* direct feedthrough flag */ ssSetNumSampleTimes( S, 1); /* number of sample times */
75 ssSetNumInputArgs( S, 6); ssSetNumRWork( S, 0); /* number of real work vector elements */ ssSetNumIWork( S, 0); /* number of integer work vector elements*/ ssSetNumPWork( S, 0); /* number of pointer work vector elements*/ ssSetNumModes( S, 0); /* number of mode work vector elements */ ssSetNumNonsampledZCs( S, 0); /* number of nonsampled zero crossings */ ssSetOptions( S, 0); /* general options (SS_OPTION_xx) */ } /* Function: mdlInitializeSampleTimes ========================================= */ static void mdlInitializeSampleTimes(SimStruct *S) { ssSetSampleTime(S, 0, CONTINUOUS_SAMPLE_TIME); ssSetOffsetTime(S, 0, 0.0); } /* Function: mdlInitializeConditions ========================================== * Abstract: * * In this function, you should initialize the continuous and discrete * states for your S-function block. The initial states are placed * in the x0 variable. You can also perform any other initialization * activities that your S-function may require. */ static void mdlInitializeConditions(real_T *x0, SimStruct *S) { int i; for (i=0; i<4; i++){ *x0++ = 0.0; } } /* Function: mdlOutputs ======================================================= * Abstract: * * In this function, you compute the outputs of your S-function * block. The outputs are placed in the y variable. */ static void mdlOutputs(real_T *y, const real_T *x, const real_T *u, SimStruct *S, int_T tid) { double lm; double pl; lm = mxGetPr(Lm)[0]; pl = mxGetPr(pole)[0];
76 y[0]=x[0]; y[1]=x[1]; y[2]=x[2]; y[3]=x[3]; y[4]=1.5*(pl/2)*lm*((x[0]*x[3])-(x[1]*x[2])); } static void mdlUpdate(real_T *x, const real_T *u, SimStruct *S, int_T tid) { } /* Function: mdlDerivatives =================================================== * Abstract: * * In this function, you compute the S-function block's derivatives. * The derivatives are placed in the dx variable. */ static void mdlDerivatives(real_T *dx, const real_T *x, const real_T *u, SimStruct *S, int_T tid) /* x0=iq x1=id x2= iqr x3= idr u0=vq u1=vd u2=w */ { double lr,ls,rr,rs,lm,a; lm = mxGetPr(Lm)[0]; lr = mxGetPr(Lr)[0]; ls = mxGetPr(Ls)[0]; rr = mxGetPr(Rr)[0]; rs = mxGetPr(Rs)[0]; a=1/(lm*lm-lr*ls); dx[0]=(u[2]*lm*lm*x[1]+rs*lr*x[0]+u[2]*lr*lm*x[3]-rr*lm*x[2]-lr*u[0])*a; dx[1]=(rs*lr*x[1]-u[2]*lm*lm*x[0]-rr*lm*x[3]-u[2]*lr*lm*x[2]-lr*u[1])*a; dx[2]=-(u[2]*lm*ls*x[1]+rs*lm*x[0]+u[2]*lr*ls*x[3]-rr*ls*x[2]-lm*u[0])*a; dx[3]=-(rs*lm*x[1]-u[2]*lm*ls*x[0]-rr*ls*x[3]-u[2]*lr*ls*x[2]-lm*u[1])*a; } /* Function: mdlTerminate ===================================================== * Abstract: * * In this function, you should perform any actions that are necessary
77 * at the termination of a simulation. For example, if memory was allocated * in mdlInitializeConditions, this is the place to free it. */ static void mdlTerminate(SimStruct *S) { /* * YOUR CODE GOES HERE */ } /*======================================================* * See sfuntmpl.doc for the optional S-function methods * *======================================================*/ /*=============================* * Required S-function trailer * *=============================*/ #ifdef MATLAB_MEX_FILE /* Is this file being compiled as a MEX-file? */ #include "simulink.c" /* MEX-file interface mechanism */ #else #include "cg_sfun.h" /* Code generation registration function */ #endif
APPENDIX B:
FLXP2.C
78 /* * sfuntmpl.c: Template C S-function source file. * ------------------------------------------------------------------------* | See matlabroot/simulink/src/sfuntmpl.doc for a more detailed template | * ------------------------------------------------------------------------* Copyright (c) 1990-97, by The MathWorks, Inc. * All Rights Reserved * $Revision 1.1 $ */ /* * You must specify the S_FUNCTION_NAME as the name of your S-function. */ #define S_FUNCTION_NAME flxp2 /* Input Arguments */
/* * Need to include simstruc.h for the definition of the SimStruct and * its associated macro definitions. */ /* #include "tmwtypes.h" */ #include "tmwtypes.h" #include "simstruc.h" /*====================* * S-function methods * *====================*/ /* Function: mdlInitializeSizes =============================================== * Abstract: * * The sizes information is used by SIMULINK to determine the S-function * block's characteristics (number of inputs, outputs, states, etc.). * */ static void mdlInitializeSizes(SimStruct *S) { ssSetNumContStates( S, 0); /* number of continuous states */ ssSetNumDiscStates( S, 0); /* number of discrete states */ ssSetNumInputs( S, 1); /* number of inputs */ ssSetNumOutputs( S, 1); /* number of outputs */ ssSetDirectFeedThrough(S, 1); /* direct feedthrough flag */ ssSetNumSampleTimes( S, 1); /* number of sample times */ ssSetNumInputArgs( S, 0); ssSetNumRWork( S, 0); /* number of real work vector elements */
79 ssSetNumIWork( S, 0); /* number of integer work vector elements*/ ssSetNumPWork( S, 0); /* number of pointer work vector elements*/ ssSetNumModes( S, 0); /* number of mode work vector elements */ ssSetNumNonsampledZCs( S, 0); /* number of nonsampled zero crossings */ ssSetOptions( S, 0); /* general options (SS_OPTION_xx) */ } /* Function: mdlInitializeSampleTimes ========================================= */ static void mdlInitializeSampleTimes(SimStruct *S) { ssSetSampleTime(S, 0, INHERITED_SAMPLE_TIME); ssSetOffsetTime(S, 0, 0.0); } /* Function: mdlInitializeConditions ========================================== * Abstract: * * In this function, you should initialize the continuous and discrete * states for your S-function block. The initial states are placed * in the x0 variable. You can also perform any other initialization * activities that your S-function may require. */ static void mdlInitializeConditions(real_T *x0, SimStruct *S) { } /* Function: mdlOutputs ======================================================= * Abstract: * * In this function, you compute the outputs of your S-function * block. The outputs are placed in the y variable. */ static void mdlOutputs(real_T *y, const real_T *x, const real_T *u, SimStruct *S, int_T tid) { if(u[0] > -1.5708 & u[0] <= -0.5236) y[0] = 1; else if(u[0] > -0.5236 & u[0]<= 0.5236) y[0] = 2; else if(u[0] >0.5236 & u[0] <=1.5708) y[0] = 3; else if(u[0] > 1.57 & u[0] <=2.618)
80 y[0] = 4.0; else if(u[0] > 2.61 & u[0] <= 3.1416) y[0] = 5; else if(u[0] > -3.1416 & u[0] <= -2.618) y[0] = 5; else if(u[0]> -2.618 & u[0] <= -1.5708) y[0] = 6; } static void mdlUpdate(real_T *x, const real_T *u, SimStruct *S, int_T tid) { }
/* Function: mdlDerivatives =================================================== * Abstract: * * In this function, you compute the S-function block's derivatives. * The derivatives are placed in the dx variable. */ static void mdlDerivatives(real_T *dx, const real_T *x, const real_T *u, SimStruct *S, int_T tid) { } /* Function: mdlTerminate ===================================================== * Abstract: * * In this function, you should perform any actions that are necessary * at the termination of a simulation. For example, if memory was allocated * in mdlInitializeConditions, this is the place to free it. */ static void mdlTerminate(SimStruct *S) { } /*======================================================* * See sfuntmpl.doc for the optional S-function methods * *======================================================*/ /*=============================* * Required S-function trailer * *=============================*/ #ifdef MATLAB_MEX_FILE /* Is this file being compiled as a MEX-file? */ #include "simulink.c" /* MEX-file interface mechanism */ #else
APPENDIX C:
SELECT2.C
82 * * ------------------------------------------------------------------------* | See matlabroot/simulink/src/sfuntmpl.doc for a more detailed template | * ------------------------------------------------------------------------* * Copyright (c) 1990-97, by The MathWorks, Inc. * All Rights Reserved * $Revision 1.1 $ */ * You must specify the S_FUNCTION_NAME as the name of your S-function. */ #define S_FUNCTION_NAME select2 /* Input Arguments */ * Need to include simstruc.h for the definition of the SimStruct and * its associated macro definitions. */ /* #include "tmwtypes.h" */ #include "tmwtypes.h" #include "simstruc.h" /*====================* * S-function methods * *====================*/ /* Function: mdlInitializeSizes =============================================== * Abstract: * * The sizes information is used by SIMULINK to determine the S-function * block's characteristics (number of inputs, outputs, states, etc.). * */ static void mdlInitializeSizes(SimStruct *S) { ssSetNumContStates( S, 0); /* number of continuous states */ ssSetNumDiscStates( S, 0); /* number of discrete states */ ssSetNumInputs( S, 3); /* number of inputs */ ssSetNumOutputs( S, 3); /* number of outputs */ ssSetDirectFeedThrough(S, 1); /* direct feedthrough flag */ ssSetNumSampleTimes( S, 1); /* number of sample times */ ssSetNumInputArgs( S, 0); ssSetNumRWork( S, 0); /* number of real work vector elements */ ssSetNumIWork( S, 0); /* number of integer work vector elements*/ ssSetNumPWork( S, 0); /* number of pointer work vector elements*/ ssSetNumModes( S, 0); /* number of mode work vector elements */ ssSetNumNonsampledZCs( S, 0); /* number of nonsampled zero crossings */ ssSetOptions( S, 0); /* general options (SS_OPTION_xx) */ }
83 /* Function: mdlInitializeSampleTimes ========================================= */ static void mdlInitializeSampleTimes(SimStruct *S) { ssSetSampleTime(S, 0, INHERITED_SAMPLE_TIME); ssSetOffsetTime(S, 0, 0.0); } /* Function: mdlInitializeConditions ========================================== * Abstract: * * In this function, you should initialize the continuous and discrete * states for your S-function block. The initial states are placed * in the x0 variable. You can also perform any other initialization * activities that your S-function may require. */ static void mdlInitializeConditions(real_T *x0, SimStruct *S) { } /* Function: mdlOutputs ======================================================= * Abstract: * * In this function, you compute the outputs of your S-function * block. The outputs are placed in the y variable. */ static void mdlOutputs(real_T *y, const real_T *x, const real_T *u, SimStruct *S, int_T tid) { /* inputs: torque u[0], flux u[1] and angle u[2] * For torque =1 */ if(u[0] == 1 & u[2] == 1 & u[1] == 1){ y[0] = 1; y[1] = 1; y[2] = -1;} else if(u[0] == 1 & u[2] == 1 & u[1] == 0){ y[0] = 1; y[1] = -1; y[2] = -1;} else if(u[0] == 1 & u[2] == 2 & u[1] == 1){ y[0] = -1; y[1] = 1; y[2] = -1;} else if(u[0] == 1 & u[2] == 2 & u[1] == 0){ y[0] = 1; y[1] = 1; y[2] = -1;} else if(u[0] == 1 & u[2] == 3 & u[1] == 1){ y[0] = -1; y[1] = 1; y[2] = 1;} else if(u[0] == 1 & u[2] == 3 & u[1] == 0){
84 y[0] = -1; y[1] = 1; y[2] = -1;} else if(u[0] == 1 & u[2] == 4 & u[1] == 1){ y[0] = -1; y[1] = -1; y[2] = 1;} else if(u[0] == 1 & u[2] == 4 & u[1] == 0){ y[0] = -1; y[1] = 1; y[2] = 1;} else if(u[0] == 1 & u[2] == 5 & u[1] == 1){ y[0] = 1; y[1] = -1; y[2] = 1;} else if(u[0] == 1 & u[2] == 5 & u[1] == 0){ y[0] = -1; y[1] = -1; y[2] = 1;} else if(u[0] == 1 & u[2] == 6 & u[1] == 1){ y[0] = 1; y[1] = -1; y[2] = -1;} else if(u[0] == 1 & u[2] == 6 & u[1] == 0){ y[0] = 1; y[1] = -1; y[2] = 1;} /* for torque = 0 */ else if(u[0] == 0 & u[2] == 1 & u[1] == 1){ y[0] = 1; y[1] = 1; y[2] = 1;} else if(u[0] == 0 & u[2] == 1 & u[1] == 0){ y[0] = -1; y[1] = -1; y[2] = -1;} else if(u[0] == 0 & u[2] == 2 & u[1] == 1){ y[0] = -1; y[1] = -1; y[2] = -1;} else if(u[0] == 0 & u[2] == 2 & u[1] == 0){ y[0] = 1; y[1] = 1; y[2] = 1;} else if(u[0] == 0 & u[2] == 3 & u[1] == 1){ y[0] = 1; y[1] = 1; y[2] = 1;} else if(u[0] == 0 & u[2] == 3 & u[1] == 0){ y[0] = -1; y[1] = -1; y[2] = -1;} else if(u[0] == 0 & u[2] == 4 & u[1] == 1){ y[0] = -1; y[1] = -1; y[2] = -1;} else if(u[0] == 0 & u[2] == 4 & u[1] == 0){ y[0] = 1; y[1] = 1; y[2] = 1;} else if(u[0] == 0 & u[2] == 5 & u[1] == 1){ y[0] = 1; y[1] = 1; y[2] = 1;} else if(u[0] == 0 & u[2] == 5 & u[1] == 0){ y[0] = -1; y[1] = -1; y[2] = -1;} else if(u[0] == 0 & u[2] == 6 & u[1] == 1){ y[0] = -1; y[1] = -1; y[2] = -1;} else if(u[0] == 0 & u[2] == 6 & u[1] == 0){ y[0] = 1; y[1] = 1; y[2] = 1;}
/* for torque = -1 */ else if(u[0] == -1 & u[2] == 1 & u[1] == 1){ y[0] = -1; y[1] = 1; y[2] = 1;} else if(u[0] == -1 & u[2] == 1 & u[1] == 0){ y[0] = -1; y[1] = -1; y[2] = 1;}
85 else if(u[0] == -1 & u[2] == 2 & u[1] == 1){ y[0] = -1; y[1] = -1; y[2] = 1;} else if(u[0] == -1 & u[2] == 2 & u[1] == 0){ y[0] = 1; y[1] = -1; y[2] = 1;} else if(u[0] == -1 & u[2] == 3 & u[1] == 1){ y[0] = 1; y[1] = -1; y[2] = 1;} else if(u[0] == -1 & u[2] == 3 & u[1] == 0){ y[0] = 1; y[1] = -1; y[2] = -1;} else if(u[0] == -1 & u[2] == 4 & u[1] == 1){ y[0] = 1; y[1] = -1; y[2] = -1;} else if(u[0] == -1 & u[2] == 4 & u[1] == 0){ y[0] = 1; y[1] = 1; y[2] = -1;} else if(u[0] == -1 & u[2] == 5 & u[1] == 1){ y[0] = 1; y[1] = 1; y[2] = -1;} else if(u[0] == -1 & u[2] == 5 & u[1] == 0){ y[0] = -1; y[1] = 1; y[2] = -1;} else if(u[0] == -1 & u[2] == 6 & u[1] == 1){ y[0] = -1; y[1] = 1; y[2] = -1;} else if(u[0] == -1 & u[2] == 6 & u[1] == 0){ y[0] = -1; y[1] = 1; y[2] = 1;} } static void mdlUpdate(real_T *x, const real_T *u, SimStruct *S, int_T tid) { } /* Function: mdlDerivatives =================================================== * Abstract: * * In this function, you compute the S-function block's derivatives. * The derivatives are placed in the dx variable. */ static void mdlDerivatives(real_T *dx, const real_T *x, const real_T *u, SimStruct *S, int_T tid) { } /* Function: mdlTerminate ===================================================== * Abstract: * * In this function, you should perform any actions that are necessary * at the termination of a simulation. For example, if memory was allocated * in mdlInitializeConditions, this is the place to free it. */ static void mdlTerminate(SimStruct *S)
86 { } /*======================================================* * See sfuntmpl.doc for the optional S-function methods * *======================================================*/ /*=============================* * Required S-function trailer * *=============================*/ #ifdef MATLAB_MEX_FILE /* Is this file being compiled as a MEX-file? */ #include "simulink.c" /* MEX-file interface mechanism */ #else #include "cg_sfun.h" /* Code generation registration function */ #endif