SPEED CONTROL OF A PERMANENT MAGNET DC MOTOR

advertisement
UNIVERSITY OF NAIROBI
SCHOOL OF ENGINEERING
DEPT. OF ELECTRICAL AND INFORMATION
ENGINEERING
PROJECT REPORT
SPEED CONTROL OF A PERMANENT MAGNET
DC MOTOR USING A DSP
NAME: WANYAMA EVANS AKUNGWI
ADM NO: F17/1394/2010
PROJECT SUPERVISOR: MR. AHMED SAYYID
EXAMINER: PROF. ELIJAH MWANGI
DUE DATE: Thursday, April 23, 2015
Project leading to the award of Bachelor of Science in Electrical and Information Engineering
1
DEDICATION
I dedicate this project to my sister Brigit Wanyama and my parents Peter and Everlyne for their
continuous support during my course.
2
ACKNOWLEDGEMENT
I would like to take this opportunity to express my sincere gratitude to my project supervisor Mr.
Ahmed Sayyid for the guidance and support he has provided during the entire period I have been
working on the project. I am grateful for the patience and zeal he has shown. I am highly
indebted to him for giving me a better understanding of the subject and valuable inputs.
I am grateful to Prof. A. H. Ouma the Chairman Department of Electrical and Information
Engineering, University of Nairobi for allowing me access to the department’s equipment and for
enabling me get the necessary components for the completion of this project.
I would like to thank my friends for their support and criticism during my project period. They
have been my consistent anchors during this project.
Lastly, I would like to thank my parents and family members for their support and
encouragement as I carried out the project. They have been there for me and have always been
proud of me.
3
TABLE OF CONTENTS
DEDICATION.................................................................................................................................................. 2
ACKNOWLEDGEMENT .................................................................................................................................. 3
LIST OF FIGURES ........................................................................................................................................... 6
LIST OF TABLES .............................................................................................................................................. 7
LIST OF ABBREVIATIONS .................................................................................................................... 8
ABSTRACT ................................................................................................................................................. 9
CHAPTER ONE: INTRODUCTION ..................................................................................................... 10
CHAPTER TWO: LITERATURE REVIEW ........................................................................................ 11
2.1 DC MOTORS ...................................................................................................................................... 11
PRINCIPLE OF OPERATION OF A PERMANENT MAGNET DC MOTOR ................................................. 11
SPEED OF A DC MOTOR ...................................................................................................................... 12
SPEED CONTROL OF A DC MOTOR ...................................................................................................... 13
EQUIVALENT CIRCUIT OF A DC MOTOR .............................................................................................. 13
FOUR QUADRANT OPERATION OF A DC MOTOR ............................................................................... 14
ADJUSTABLE SPEED DRIVES ................................................................................................................ 16
THE TRANSFER FUNCTION OF A PERMANENT MAGNET DC MOTOR ................................................. 17
2.2 DC – DC BUCK CONVERTERS ............................................................................................................. 19
2.2.1 THE BUCK CONVERTER ............................................................................................................... 20
2.3 PULSE WIDTH MODULATION (PWM) ................................................................................................ 27
APPLICATIONS OF THE PWM .............................................................................................................. 28
2.4 DIGITAL SIGNAL PROCESSOR (DSP) ................................................................................................... 28
CHAPTER THREE: DESIGN ............................................................................................................................ 30
3.1 SPEED DRIVE REQUIREMENTS .......................................................................................................... 30
3.2 DIGITAL SIGNAL PROCESSOR ............................................................................................................ 31
3.3 BUCK CONVERTER ............................................................................................................................. 33
3.4 PERMANENT MAGNET DC MOTOR ................................................................................................... 34
3.5 TACHOGENERATOR ........................................................................................................................... 35
3.6 MOSFET SWITCH ............................................................................................................................... 35
3.7 GATE DRIVE DESIGN .......................................................................................................................... 36
3.8 COMPENSATOR DESIGN .................................................................................................................... 37
CHAPTER FOUR: SIMULATION ........................................................................................................ 45
4.1 OPEN LOOP SIMULATION.................................................................................................................. 45
4
4.2 CLOSED LOOP SIMULATION .............................................................................................................. 45
CHAPTER FIVE: RESULTS AND ANALYSIS ................................................................................... 47
5.1 RESULTS FOR THE DC MOTOR PRACTICAL EXPERIMENT .................................................................. 47
5.2 OPEN LOOP SIMULATION RESULTS ................................................................................................... 48
5.3 CLOSED LOOP SIMULATION .............................................................................................................. 49
5.4 GATE DRIVE SIMULATION RESULTS .................................................................................................. 49
CHAPTER SIX: CONCLUSION AND RECOMMENDATIONS....................................................... 51
6.1 CONCLUSIONS ................................................................................................................................. 51
6.2 DIFFICULTIES ENCOUNTERED............................................................................................................ 51
6.3 RECOMMENDATIONS........................................................................................................................ 51
REFERENCES .......................................................................................................................................... 52
APPENDIX ................................................................................................................................................ 53
5
LIST OF FIGURES
Figure 2. 1. Basic circuit for a dc motor operation principle ........................................................ 11
Figure 2. 2. Equivalent Circuit of Permanent Magnet dc Motor .................................................. 14
Figure 2. 3. Four Quadrant Operation ........................................................................................... 15
Figure 2. 4 Two Quadrant Converter ............................................................................................ 16
Figure 2. 5 Single Quadrant Converter ......................................................................................... 16
Figure 2. 6 Block Diagram of a dc Motor speed controller in a closed loop system .................... 17
Figure 2. 7 Block diagram representation of Motor-Load Combination ...................................... 18
Figure 2. 8 DC-DC Voltage regulator........................................................................................... 20
Figure 2. 9 A Basic dc-dc Converter ............................................................................................ 21
Figure 2. 10. Average output voltage of a buck converter, Vo ..................................................... 21
Figure 2. 11. A buck converter circuit .......................................................................................... 22
Figure 2. 12. Continuous mode operation of a buck converter when the switch is; (a) on, and (b)
off. ................................................................................................................................................. 23
Figure 2. 13. Schematic diagram of a buck converter .................................................................. 24
Figure 2. 14. The circuit averaged model of a buck converter ..................................................... 25
Figure 2. 15. DC equivalent model of a buck convereter ............................................................. 26
Figure 2. 16. Small signal equivalent model of a buck converter................................................. 26
Figure 2. 17. A PWM signal ......................................................................................................... 27
Figure 2. 18. A PWM signal with 0.25 duty cycle ....................................................................... 27
Figure 3.1. A flow chart showing different components used in the project ................................ 30
Figure 3.2. C2000 Piccolo Launchpad .......................................................................................... 33
Figure 3.3. Permanent magnet dc motor ....................................................................................... 34
Figure 3. 4 A small dc motor inside a Frame, used as a tachogenerator ...................................... 35
Figure 3. 5 A MOSFET switch ..................................................................................................... 36
Figure 3. 6 Gate drive circuit ........................................................................................................ 37
Figure 3. 7 Bode plot diagram for the motor-converter transfer function .................................... 40
Figure 3. 8 Bode diagram of the compensated system ................................................................. 42
Figure 3. 9 Step response of the compensated system .................................................................. 44
Figure 4. 1 Open Loop Simulation ............................................................................................... 45
Figure 4 2 Closed Loop Simulation .............................................................................................. 46
Figure 5 1 Graph of Va/Vo against Va ........................................................................................... 47
Figure 5 2 Graph of Output Voltage against Speed in RPM ........................................................ 48
Figure 5 3 Gate Drive Practical waveforms .................................................................................. 49
6
LIST OF TABLES
Table 1. Results for the dc motor practical experiment ............................................................................. 47
Table 2. Open loop simulation results ........................................................................................................ 48
Table 3. Closed loop simulation .................................................................................................................. 49
Table 4. Practical Results……………………………………………………………………………………………………………………… 50
7
LIST OF ABBREVIATIONS
DSP
Digital Signal Processor
DC
Direct Current
PWM
Pulse Width Modulation
EME
Electromagnetic Field
KVL
Kirchhoff’s Voltage Law
KCL
Kirchhoff’s Current Law
HDTV High Definition Television
GSM
General Service Mobile
GPS
Global Position
RPM
Revolutions Per Minute
8
ABSTRACT
Speed control of a dc motor is a very important part of the industry today. Many industrial
applications require the rotation of dc motors at different speeds.
This project is about controlling the speed of a permanent magnet dc motor. A DSP is used as the
digital controller in this case. A closed loop system is to be built by obtaining the output speed as
the feedback. A closed loop transfer function is also obtained for the system.
Simulation is done in both the open loop and closed loop system. Results of the simulations and
the practical results are obtained and compared.
9
CHAPTER ONE: INTRODUCTION
DC motors are widely used in industry today because of their low cost, higher efficiency
compared to ac machines, less complex control structure and wide range of speed and torque.
Permanent magnet dc motors do not need field excitation arrangement and less input power is
consumed. Because of these advantages, permanent magnet dc motors have a wide range of
applications where constant speed is to be maintained at varying loads or where different speeds
are to be obtained at constant load. They are commonly used as starter motors in automobiles,
windshield wipers, washer, conveyor belts, elevators, cranes, sewing machines, for blowers used
in heaters and air conditioners, among others. Thus, speed control of dc motors is a useful part of
study of the dc motors.
The speed of permanent magnet dc motors can be controlled by varying the armature voltage of
the motor. This can be done using several methods. In this project, a power electronic dc-dc
converter is used to regulate the armature voltage. The buck converter was chosen here and it is
switched on and off using a MOSFET controlled by a PWM signals from a DSP. The DSP is the
controller of the speed control system and a feedback system is designed for the system. The
closed loop transfer function of the system is also determined and used in the design process.
The simulation of the system is done using PowerSim software. Both the open loop simulations
and the closed loop simulations are done.
10
CHAPTER TWO: LITERATURE REVIEW
2.1 DC MOTORS
DC motors are devices that convert electrical energy (dc) to mechanical energy. A motor works
on the principle that a current-carrying conductor placed in a magnetic field experiences a
force. This force is due to the interaction between magnetic field due to the current carrying
conductor and the magnetic field that existed.
A motor can derive its electrical energy from either a dc source or from an ac source. They can
therefore be referred to as either dc motors or ac motors.
The magnetic field of the motors can be derived from either a permanent magnet or from an
electromagnet.
PRINCIPLE OF OPERATION OF A PERMANENT MAGNET DC MOTOR
A rectangular coil free to rotate about a fixed axis is placed inside a magnetic field produced by a
permanent magnet as shown in figure 2.1.
Figure 2. 1. Basic circuit for a dc motor operation principle
A dc current is fed into the coil through carbon brushes bearing on a commutator, which consists
of a metal ring split into two halves separated by insulation. As current flows through the coil a
11
magnetic field is set up around the coil which interacts with the magnetic field due to the
permanent magnet. This causes a force F to be exerted on the conductor, whose direction can be
determined by the Fleming’s Left hand rule. This causes a torque and the coil rotates. When the
coil has rotated through 900 the negative and positive terminals if the supply interchange the
commutator halves thus, reversing the current direction. This prevents the coil from rotating in
the opposite direction, thus it rotates continuously in one direction.
SPEED OF A DC MOTOR
BACK EMF, Eb
When the armature of a dc motor rotates under the influence of the driving torque, the armature
conductors move through the magnetic field due to the permanent magnet, thus an emf is
induced in them as in a generator. The induced emf acts in opposite direction to the direction of
the applied voltage, Vt (Lenz’s Law). The induced emf is known as back emf or counter emf, Eb.
The back emf is given by;
P∅ZN
Eb= 60A
Where, P= Number of poles of the permanent magnet,
∅= Flux per pole in Wb,
Z= total number of armature conductors,
N= speed of the motor in RPM
A= number of parallel paths
The back emf is always smaller than the applied voltage, although the difference is small when
the motor is running under normal conditions.
The net voltage across the armature circuit is, Va=Vt-Eb.
If Ra is the armature resistance, then, Ia=
Vt −Eb
Ra
Since Vt and Ra are usually fixed, the value of Eb determines the current Ia drawn by the motor. If
P∅ZN
the speed of the motor is high, then Eb= 60A , is large hence the motor draws less armature
current and vice versa.
Vt=Eb + IaRa (Motor voltage equation)
Eb= Vt - IaRa
Thus,
P∅ZN
60A
= Vt - IaRa
12
Or N=
(Vt − Ia Ra )60A
∅PZ
Or N= K
(Vt – Ia Ra )
∅
πœ‹
Where K=
60A
PZ
Armature torque =
𝑍∅Ia P
2πœ‹π΄
=
Ia Eb
πœ”π‘Ž
SPEED CONTROL OF A DC MOTOR
There are three main methods of controlling the speed of a dc motor, namely:
i.
ii.
iii.
By varying the flux per pole (∅). This is called flux control method.
By varying the resistance in the armature circuit. This is called armature control method.
By varying the applied voltage. This is called voltage control method.
EQUIVALENT CIRCUIT OF A DC MOTOR
In a dc motor, the field flux ∅f is established by the stator, either by means of a permanent
magnet where the field flux ∅f remains constant or by means of a field winding where the field
current If controls the flux ∅f.
The rotor carries in its slots the armature winding, which handles the electrical power.
The interaction of the field flux ∅f and the armature current ia produces the electromagnetic
torque;
Tem=kt∅fia
Where kt is the torque constant of the motor.
A back emf is produced in the armature circuit by the rotation of the armature conductors of a
speed πœ”m in the presence of a field flux ∅f:
ea =ke∅f πœ”m
where ke is the voltage constant of the dc motor.
The interaction between Tem with the load torque determines how the motor speed builds up.
π‘‡π‘’π‘š = 𝐽
𝑑ωm
+ 𝐡ωm + Tωl (t)
𝑑𝑑
13
Where J and B are the total equivalent inertia and the damping respectively, of the motor-load
combination and T πœ”L is the equivalent working torque of the load.
Figure 2. 2. Equivalent Circuit of Permanent Magnet dc Motor
A controllable voltage source Vt is applied to the armature terminals to establish ia. Thus the
armature current is determined by Vt, the induced emf ea, the armature resistance Ra, and the
armature winding inductance La.
𝑑i
Vt=ea+Raia+La π‘‘π‘‘π‘Ž
FOUR QUADRANT OPERATION OF A DC MOTOR
DC machines act as generators while braking. To consider braking, it’s assumed that the flux ∅f
is kept constant and the motor is initially driving a load at speed πœ”m. to reduce speed, the
armature voltage Vt is reduced below ea so that the armature current ia reverses in direction. The
electromagnetic torque Tem reverses in direction and the kinetic energy associated with the motor
load inertia is converted into electrical energy by the dc machine.t this energy must somehow be
absorbed by the source Vt or be dissipated by a resistor.
During braking operation, the polarity of ea does not change since the direction of rotation has
not changed. As the rotor slows down, ea decreases in magnitude. The generation stops when the
rotor comes to a standstill and all the inertial energy has been exhausted.
14
The direction of rotation of the motor is reversed by reversing the polarity of the terminal voltage
Vt. A dc motor can therefore operate in either direction and its electromagnetic torque can be
reversed for braking, as shown by the four quadrants of the torque-speed plane in figure 2.3.
Figure 2. 3. Four Quadrant Operation
In permanent magnet dc motors, permanent magnets on the stator produce a constant field flux
∅f and thus we have;
Tem=kTIa
Ea=kEπœ”m
Vt=Ea + RaIa
The steady state speed can thus be obtained as a function of Tem for a given value of Vt.
1
𝑅
πœ”m = π‘˜ (𝑉𝑑 − π‘˜π‘Ž π‘‡π‘’π‘š )
𝐸
𝑇
The speed of a load with an arbitrary torque-speed characteristics can hence be controlled by
controlling Vt in a permanent magnet dc motor.
15
ADJUSTABLE SPEED DRIVES
A switch mode dc-dc converter can be used to control the speed of a dc motor. Figure 2.4 is a
two quadrant converter which can be used when reversing the direction of the motor rotation is
not needed but braking is required.
Figure 2. 4 Two Quadrant Converter
For a single quadrant operation where speed is to remain unidirectional and there is no need for
braking, the step down converter of figure 2.5 can be used.
Figure 2. 5 Single Quadrant Converter
CONTROL OF ADJUSTABLE SPEED DRIVES
Figure 2.6 shows a block diagram of a dc motor operating in closed loop to deliver controlled
speed.
The speed transducer converts the mechanical energy (speed) into an electrical signal. The
electrical signal is fed to the controller as a feedback. The controller compares the feedback
16
signal to the reference signal (speed) and produces a PWM signal of appropriate duty cycle. The
PWM signal is used to control the switch of the power electronics converter. This controls the
terminal voltage Vt and hence, the speed.
Figure 2. 6 Block Diagram of a dc Motor speed controller in a closed loop system
THE TRANSFER FUNCTION OF A PERMANENT MAGNET DC MOTOR
The following equations written in terms of small deviations around their steady state values are
used for analysing small signal performance of the motor-load combination around a steady state
operating point.
𝑑
Δvt = Δea + RaΔia + La𝑑𝑑 (Δia)
Δea = kE Δπœ”m
ΔTem = kT Δia
ΔTem = ΔTWL + B Δπœ”m + J
𝑑( Δωm )
𝑑𝑑
Taking the laplace transforms of these equations;
Vt(s) = Ea(s) + (Ra + sLa)Ia(s)
Ea(s) = kEπœ”m(s)
Tem(s) = kTIa(s)
Tem(s) = TWL(S) + (B + sJ) πœ”m(s)
17
πœ”m(s) = sθm(s)
These equations for the motor-load combination can be represented by the transfer function
blocks as shown in figure 2.7.
Figure 2. 7 Block diagram representation of Motor-Load Combination
The inputs to the motor-load combination in the figure are the armature voltage Vt(s) and the
load torque TWL(s). Applying one input at a time and setting the other input to zero, the
superposition principle yields;
𝐀𝑇
𝑉𝑑 (𝑠)
π‘Ž +π‘ πΏπ‘Ž )(𝑠𝐽+𝐡)+𝐀 𝑇 𝐀 𝐸
πœ”m(s) = (𝑅
π‘…π‘Ž +π‘ πΏπ‘Ž
− (𝑅
π‘Ž +𝑠𝐽)(𝑠𝐽+𝐡)+π’Œπ‘‡ π’Œπ‘¬
This equation results in two closed loop transfer functios:
G1(s) =
πœ”π‘š (𝑠)
𝑉𝑑 (𝑠)
= (𝑅
π‘˜π‘‡
π‘Ž +π‘ πΏπ‘Ž )(𝑠𝐽+𝐡)+π‘˜π‘‡ π‘˜πΈ
TWL(s) = 0
And;
ω (s)
G2(s) = 𝑇 m (𝑠)
π‘ŠπΏ
= (𝑅
π‘…π‘Ž +π‘ πΏπ‘Ž
π‘Ž +π‘ πΏπ‘Ž )(𝑠𝐽+𝐡)+π‘˜π‘‡ π‘˜πΈ
Vt(s) = 0
18
π‘‡π‘ŠπΏ (𝑠)
The friction term is usually small and can be neglected by setting B=0 in the equation for G1(s).
Considering just the motor without the load, J in the equation is then the motor inertia Jm. thus;
π‘˜π‘‡
(𝑅
+𝑠𝐿
π‘š π‘Ž
π‘Ž )+π‘˜π‘‡ π‘˜πΈ
G1(s) = 𝑠𝐽
=
1
𝐿 𝐽
𝑅 𝐽
π‘˜πΈ (𝑠2 π‘Ž π‘š +𝑠 π‘Ž π‘š +1)
π‘˜πΈ π‘˜π‘‡
π‘˜πΈ π‘˜π‘‡
But;
ΙΎm=
π‘…π‘Ž π½π‘š
π‘˜π‘‡ π‘˜πΈ
= mechanical time constant.
𝐿
ΙΎe= π‘…π‘Ž = Electrical time constant.
π‘Ž
Using ΙΎm and ΙΎe in the expression for G1(s);
G1(s)= π‘˜
1
2
𝐸 (𝑠 ΙΎπ’Ž ɾ𝒆 +π‘ π½π‘š +1)
In general, ΙΎm>> ΙΎe, it is thus reasonable approximation to replace sΙΎm by s(ΙΎm + ΙΎe). Therefore;
G1(s) =
πœ”π‘š (𝑠)
𝑉𝑑 (𝑠)
=π‘˜
1
𝐸 (π‘ ΙΎπ‘š +1)(𝑠ɾ𝑒 +1)
2.2 DC – DC BUCK CONVERTERS
DC-DC converters are used to convert unregulated dc input voltage to a controlled dc output
voltage at a desired level.
The unregulated dc input voltage can be obtained by rectifying the line voltage or from a dc
source such as a battery, as shown in figure 2.8.
19
Figure 2. 8 DC-DC Voltage regulator.
AC line voltage
1-phase or 3-phase
There are several types of dc-dc converters. The following are some of the types of dc-dc
converters that exist:
i.
ii.
iii.
iv.
v.
Step-down (buck) converter
Step-up (boost) converter
Step-down/step-up converter (buck-boost) converter
Cuk converter
Full bridge converter
In this project the buck converter was discussed and used.
2.2.1 THE BUCK CONVERTER
The average dc output voltage of a dc-dc converter is controlled to equal a desired level even
though the input dc voltage and the output load may fluctuate. The average output voltage is
controlled by controlling the switch “on” and “off” durations (ton and toff). Figure 2.9 illustrates a
basic dc-dc converter.
20
Figure 2. 9 A Basic dc-dc Converter
The average value Vo of the output voltage vo depends on ton and toff as shown in figure 2.10
below.
Figure 2. 10. Average output voltage of a buck converter, Vo
The output voltage is controlled by switching at a constant frequency (and hence a constant
switching time period Ts=ton+toff). The duty ratio, D is defined as the ratio of the on duration to
the switching time period. Adjusting the on duration therefore, varies the duty ratio, D.
D=
π‘‘π‘œπ‘›
𝑇𝑠
The basic circuit of figure 9 constitutes a buck converter for purely resistive load. Assuming an
ideal switch, a constant instantaneous input voltage Vd and a purely resistive load, the
instantaneous output voltage waveform is shown in figure 10 as a function of the switch position.
The average output voltage can be calculated in terms of the switch duty ratio, D:
π‘‰π‘œ =
π‘‘π‘œπ‘›
𝑇𝑠
1 𝑇𝑠
1
∫ π‘£π‘œ (𝑑)𝑑𝑑 = (∫ 𝑉𝑑 𝑑𝑑 + ∫ 0𝑑𝑑)
𝑇𝑠 0
𝑇𝑠 0
π‘‘π‘œπ‘›
21
=
π‘‘π‘œπ‘›
𝑇𝑠
𝑉𝑑
= 𝐷𝑉𝑑
Varying the duty ratio, D thus, controls the output voltage Vo.
The circuit of figure 8 above has two drawbacks:
i.
ii.
In practice, the load would be inductive and even with resistive loads there would always
be stray inductance. The switch will thus absorb (or dissipate) the inductive energy and
may be destroyed.
The output voltage fluctuates between Vd and zero, which is not acceptable for most
applications.
The circuit of figure 2.11 below is used to overcome these drawbacks.
Figure 2. 11. A buck converter circuit
The problem of stored inductive energy is overcome by using a diode as shown in the figure
above.
A low pass filter consisting of an inductor and a capacitor is used to diminish the output voltage
fluctuations. The corner frequency of the low pass filter is chosen to much lower than the
switching frequency fs, thus eliminating the switching ripple in the output voltage.
When the switch is on, the diode becomes reversed biased and input provides energy to the load
and the inductor. When the switch is off the inductor current flows through the diode,
transferring some of its stored energy to the load.
22
The average inductor current is equal to the average output current Io, since the average capacitor
current in steady state is zero.
CONTINUOUS CONDUCTION MODE
In continuous conduction of operation, the inductor current flows continuously and does not fall
to zero. The figure below shows the waveforms of continuous conduction mode.
Figure 2. 12. Continuous mode operation of a buck converter when the switch is; (a) on, and (b)
off.
When the switch is on, it conducts the inductor current and the diode becomes reverse biased.
This results in a positive voltage VL = Vd + Vo, across the inductor. This voltage causes linear
increase in inductor current iL. When the switch is turned off, the inductive energy causes iL to
continue flowing. The current now flows through the diode and Vo = -VL. Since in steady state
operation the waveform must repeat from one time period to the next;
23
𝑇𝑠
π‘‘π‘œπ‘›
∫ 𝑉𝐿 𝑑𝑑 = ∫
0
𝑇𝑠
𝑉𝐿 𝑑𝑑 + ∫ 𝑉𝐿 𝑑𝑑 = 0
0
π‘‘π‘œπ‘›
Therefore;
(𝑉𝑑 − π‘‰π‘œ )π‘‘π‘œπ‘› = π‘‰π‘œ (𝑇𝑠 − π‘‘π‘œπ‘› )
Or,
π‘‰π‘œ π‘‘π‘œπ‘›
=
=𝐷
𝑉𝑑
𝑇𝑠
The output voltage is thus proportional to the value of the duty cycle, D as shown in the equation
above.
In discontinuous conduction mode the inductor current goes to zero during the period when the
switch is off and it does not flow until when the switch is turned on again.
THE TRANSFER FUNCTION OF A BUCK CONVERTER
Figure 2.13 shows the schematic diagram of the open loop Buck converter.
Figure 2. 13. Schematic diagram of a buck converter
The expressions below show the relationship between the inductor voltage vL and current iL, in
time and frequency domain:
𝑣𝐿 = L
𝑑𝑖𝐿
𝑑𝑑
𝑣𝐿 (𝑠) = 𝑠𝐿 𝑖𝐿 (𝑠)
The expressions about the relationship between the capacitor voltage, vo and its current, ic are:
𝑖𝑐 = C
π‘‘π‘£π‘œ
𝑑𝑑
𝑖𝑐 (𝑠) = 𝑠𝐢 π‘£π‘œ (𝑠)
24
Switch S can be modelled as a current-controlled current source and the diode D can be modelled
as voltage controlled voltage source in continuous conduction mode, that is;
⟨𝑖𝑠 ⟩ = 𝑑⟨𝑖𝐿 ⟩
⟨𝑣𝐷 ⟩ = 𝑑⟨𝑣𝑖𝑛 ⟩
Where ⟨𝑣𝐷 ⟩, ⟨𝑣𝑖𝑛 ⟩, ⟨𝑖𝑠 ⟩, ⟨𝑖𝐿 ⟩ and ⟨π‘£π‘œ ⟩ are the averaged values of VD, Vin, is, iL and Vo respectively.
The circuit averaged model of the buck converter can thus be obtained as shown in figure 2.14
below:
Figure 2. 14. The circuit averaged model of a buck converter
Assuming that IL, Vo, Vin and D are the dc values of ⟨𝑖𝐿 ⟩, ⟨π‘£π‘œ ⟩, ⟨𝑣𝑖𝑛 ⟩ and 𝑑 respectively, and iLΜ‚,
voΜ‚, vinΜ‚ and dΜ‚ are the small signal variations of ⟨𝑖𝐿 ⟩, ⟨π‘£π‘œ ⟩, ⟨𝑣𝑖𝑛 ⟩ and 𝑑 respectively, we have;
⟨𝑖𝐿 ⟩ = IL + 𝑖̂𝐿
⟨π‘£π‘œ ⟩ = Vo + 𝑣
Μ‚π‘œ
} − − − −(4) and,
⟨𝑣𝑖𝑛 ⟩ = Vin + 𝑣𝑖𝑛 Μ‚
𝑑 = D + 𝑑̂
iLΜ‚<< IL
vo<< Vo
vinΜ‚<< Vin
dΜ‚<< D
Taking equation (4) into (3) and omitting high order small signal terms, that is, iLΜ‚dΜ‚ = voΜ‚dΜ‚ ≈ 0, we
have,
⟨𝑖𝑠 ⟩ = DIL + 𝑑̂ IL + D𝑖̂𝐿
} ------- (5)
⟨VD ⟩ = DVin + 𝑑̂ Vin + D𝑣𝑖𝑛 Μ‚
25
We can use equations (4) and (5) to obtain the dc equivalent circuit model and the small signal
equivalent circuit model, as shown in figures 2.15 and 2.16 below;
Figure 2. 15. DC equivalent model of a buck convereter
Figure 2. 16. Small signal equivalent model of a buck converter
DUTY CYCLE TO OUTPUT VOLTAGE TRANSFER FUNCTION (Gvod)
The perturbation of the input voltage, vinΜ‚(s) is taken to zero.
From KVL and KCL;
Ls𝑖𝐿 (𝑠) = 𝑑̂(𝑠)Vin + 𝑣
Μ‚(𝑠)
π‘œ
Cs𝑣
Μ‚(𝑠)
= 𝑖̂𝐿 (𝑠) −
π‘œ
𝑣̂(𝑠)
π‘œ
} -------- (6)
R
Therefore,
26
πΊπ‘£π‘œπ‘‘(𝑠) =
𝑣
Μ‚(𝑠)
π‘œ
|
Μ‚
𝑑 (𝑠)
=
𝑣̂
𝑖𝑛 = 0
Vin
Ls
1 + LCs 2 + R
2.3 PULSE WIDTH MODULATION (PWM)
Pulse Width Modulation (PWM) is a way of delivering energy through a succession of pulses
rather than a continuously varying analog signal. Consider the waveform shown in figure 2.17
below:
Figure 2. 17. A PWM signal
The signal is a voltage switching between 12V and 0V. A device connected to use the signal
will see the average voltage. Since the time the signal is 12V is equal to the time the signal is 0V
in the figure shown above, an average voltage of 6V will be seen by the device.
In figure 2.18 below the positive pulse lasts only 25% of the total time;
Figure 2. 18. A PWM signal with 0.25 duty cycle
27
The average voltage seen by the device in this case is 3V, that is, less than in the first case. The
voltage is equivalent to the product of the positive pulse value and 25%.
Varying the time of the positive pulse thus varies the average output voltage. The percentage of
the time of positive pulse compared to the period of the signal is called the duty cycle, D of the
signal. In the figures above the duty cycle, D was therefore, 50% and 25% respectively.
PWM signals have the advantage of high efficiency compared to other signals. They however,
cannot be used by some devices due to their abrupt and periodic changes in magnitude.
Several circuits can be used to generate PWM signals. A digital signal processor (DSP) is
normally programmed to produce PWM signals.
APPLICATIONS OF THE PWM
A suitable device has to be used to see the average output voltage, since some devices don’t
work properly with abrupt changing voltages.
Pulse width modulated signals are used to control the speed of a motor, as control voltages for
switches, hence greatly used in power electronics converters among others.
2.4 DIGITAL SIGNAL PROCESSOR (DSP)
A digital signal processor (DSP) is a specialized microprocessor, with its architecture optimized
for the operational needs of digital signal processing.
The goal of DSPs is usually to measure, filter and/or compress continuous real-world analog
signals. Most general-purpose microprocessors can also execute digital signal processing
algorithms successfully, but dedicated DSPs usually have better power efficiency. Thus, they are
more suitable in portable devices such as mobile phones because of power consumption
constraints. DSPs often use special memory architectures that are able to fetch multiple data
and/or instructions at the same time.
Digital Signal Processing both provides a mathematical description of the systems to be designed
and also implements them (either by software programming or by hardware embedding) without
much dependency on hardware issues, which explains the importance and success of DSP
engineering.
DSP processor ICs are found in every type of modern electronic systems and products including,
SDTV | HDTV sets, radios and mobile communication devices, Hi-Fi audio equipment, Dolby
noise reduction algorithms, GSM mobile phones, mp3 multimedia players, camcorders and
digital cameras, automobile control systems, noise cancelling headphones, digital spectrum
analyzers, intelligent missile guidance, radar, GPS based cruise control systems and all kinds of
image processing, video processing, audio processing and speech processing systems.
28
The DSPs have the following advantages when used as controllers over the other controllers:
1.
2.
3.
4.
5.
Low cost
High performance
Flexibility of quick design modifications
Implementation of more control schemes
Less susceptible to aging, environmental variations & have better noise immunity.
29
CHAPTER THREE: DESIGN
This project requires that the speed of a permanent magnet dc motor is digitally controlled using
a digital signal processor.
A feedback system for the speed control system is to be provided. This was achieved using a
device that converts the speed to a voltage signal.
3.1 SPEED DRIVE REQUIREMENTS
Different components were use in the design of the speed control system. These include a
permanent magnet dc motor, a tachogenerator, DSP, MOSFET switch and its gate drive; and a
buck converter. The flow chart of figure 3.1 below shows how the different components interoperated to complete the project:
Figure 3.1. A flow chart showing different components used in the project
30
3.2 DIGITAL SIGNAL PROCESSOR
A DSP is used as the digital controller in this project. The controller was designed in analog
using MATLAB and implemented using a DSP.
The DSP used is a TMS320F28027 from Texas Instruments. This is a member of the F2802x
Piccolo family of microcontrollers. This family of microcontrollers provides the power of the
C28x core coupled with highly integrated control peripherals in low pin-count devices.
Features of the TMS320F28027
οƒ˜
οƒ˜
οƒ˜
οƒ˜
οƒ˜
οƒ˜
οƒ˜
οƒ˜
οƒ˜
οƒ˜
οƒ˜
οƒ˜
High-Efficiency 32-Bit CPU (TMS320C28x)
o 60 MHz (16.67-ns Cycle Time)
o 50 MHz (20-ns Cycle Time)
o 40 MHz (25-ns Cycle Time)
o 16 x 16 and 32 x 32 MAC Operations
o 16 x 16 Dual MAC
o Harvard Bus Architecture
o Atomic Operations
o Fast Interrupt Response and Processing
o Unified Memory Programming Model
o Code-Efficient (in C/C++ and Assembly)
Endianness: Little Endian
Low Cost for Both Device and System:
o Single 3.3-V Supply
o No Power Sequencing Requirement
o Integrated Power-on and Brown-out Resets
o Small Packaging, as Low as 38-Pin Available
o Low Power
o No Analog Support Pins
Clocking:
o Two Internal Zero-pin Oscillators
o On-Chip Crystal Oscillator/External Clock Input
o Dynamic PLL Ratio Changes Supported
o Watchdog Timer Module
o Missing Clock Detection Circuitry
Up to 22 Individually Programmable, Multiplexed GPIO Pins With Input Filtering
Peripheral Interrupt Expansion (PIE) Block That Supports All Peripheral Interrupts
Three 32-Bit CPU Timers
Independent 16-Bit Timer in Each ePWM Module
On-Chip Memory
o Flash, SARAM, OTP, Boot ROM Available
Code-Security Module
128-Bit Security Key/Lock
o Protects Secure Memory Blocks
o Prevents Firmware Reverse Engineering
Serial Port Peripherals
31
o
o
o
One SCI (UART) Module
One SPI Module
One Inter-Integrated-Circuit (I2C) Bus
οƒ˜ Enhanced Control Peripherals
o Enhanced Pulse Width Modulator (ePWM)
o High-Resolution PWM (HRPWM) Module
o Enhanced Capture (eCAP) Module
o Analog-to-Digital Converter (ADC)
o On-Chip Temperature Sensor
o Comparator
οƒ˜ Advanced Emulation Features
o Analysis and Breakpoint Functions
o Real-Time Debug via Hardware
οƒ˜ 2802x, 2802xx Packages
o 38-Pin DA Thin Shrink Small-Outline Package (TSSOP)
o 48-Pin PT Low-Profile Quad Flatpack (LQFP)
The program used was designed on Code Composer Studio IDE and Control Suit both from the
Texas Instruments, which are compatible with the DSP. The figure 3.2 below shows a photo of
the TMS320F28027 C2000 Launchpad.
32
Figure 3.2. C2000 Piccolo Launchpad
3.3 BUCK CONVERTER
A buck converter was designed to control the armature voltage of the dc motor.
The inductance of the dc motor was used as the inductor in the design of the buck converter. The
switching frequency of the gate was thus chosen as 50 kHz by considering the inductance of the
dc motor.
33
3.4 PERMANENT MAGNET DC MOTOR
The motor used has the following properties:
La = 6.6mH
Ra = 12Ω
A maximum dc voltage of 30V was applied to the armature.
The value of the armature inductance was measured in the lab.
The armature resistance was calculated as the gradient of the graph of armature voltage against
armature current. Different values of armature current were recorded at different armature
voltages as shown in table 1. A graph of Armature voltage against Armature current was then
drawn.
The figure 3.3 below shows a photo of the motor used.
Figure 3.3. Permanent magnet dc motor
34
3.5 TACHOGENERATOR
A tachogenerator was used to design the feedback system. It converts the output (speed) to a
voltage signal of magnitude proportional to the speed.
A smaller permanent magnet dc motor was used as the tachogenerator. The dc motor is rated 3V.
The figure 3.4 below is a photo taken of the tachogenerator system fabricated in a frame to hold
it more stable and at an appropriate height.
Figure 3. 4 A small dc motor inside a Frame, used as a tachogenerator
The motor was connected in the machines lab as a generator and different values of the output
voltage were recorded at different values of speed of rotation of the motor shaft. These values
were recorded in table 1.
3.6 MOSFET SWITCH
A mosfet was used as the switch to the buck converter. The mosfet used is to be controlled by the
PWM signals from the digital controller-the DSP. The mosfet does not see the average voltage of
the PWM signal, but it sees HIGH voltages followed by LOW voltages repeatedly just like the
PWM signal appears, and at the same frequency as the frequency of the signal.
The mosfet switches ON when a HIGH voltage is applied to its gate and OFF when a LOW
voltage is applied to gate. It therefore, switches ON and OFF at the frequency of the PWM
signal.
The mosfet used had the following properties:
100V
10A
35
High switching frequency.
The figure 3.5 below shows a photo of the mosfet used.
Figure 3. 5 A MOSFET switch
3.7 GATE DRIVE DESIGN
The switching time of a transistor needs to be kept as short as possible, to minimize power
losses. However, the switching time is inversely proportional to the amount of current used to
charge the gate. Switching currents are therefore required in terms of several hundreds of
milliamperes or even amperes.
The switching signal, which is a PWM signal, for the transistor is generated by a DSP. The DSP
provides an output signal that is limited to a few milliamperes of current. Consequently, if the
transistor is directly driven by such a signal, it would switch very slowly, with correspondingly
high power loss. The gate capacitor of the transistor will draw current so quickly, during
switching, that it causes a current overdraw in the DSP, causing overheating which may lead to
permanent damage or even completely destroy DSP. A gate driver is thus provided between the
DSP output signal and the power transistor to prevent this from happening.
The figure 3.6 below shows the gate drive designed for this particular function:
36
Figure 3. 6 Gate drive circuit
3.8 COMPENSATOR DESIGN
The compensator is designed in frequency domain as follows:
The motor transfer function is given by:
G1(s) =
KE =
πœ”π‘š (𝑠)
𝑉𝑑 (𝑠)
=π‘˜
1
(𝑠ɾ
+1)(𝑠ɾ
𝐸
π‘š
𝑒 +1)
π΄π‘Ÿπ‘šπ‘Žπ‘‘π‘’π‘Ÿπ‘’ π‘£π‘œπ‘™π‘‘π‘Žπ‘”π‘’ π‘‰π‘Ž
𝑆𝑝𝑒𝑒𝑑 𝑖𝑛 𝑅𝑃𝑀
A graph of Armature voltage against speed in RPM was drawn from the values of table 1 and its
gradient calculated. This value is equal to KE.
Thus, KE = 0.038533
37
Torque was calculated from the values in table 1 at different values of speed as;
T=
π‘‰π‘Ž πΌπ‘Ž
πœ”π‘š
𝑇
Kt = 𝐼 = 0.3681
π‘Ž
0.3681 is the average value calculated from the table.
The motor inertial moment is given as;
Jm =
π‘Šπ‘… 2
2𝑔
Where W is the weight of the motor in Newton,
R is the radius of the rotor in meters,
And
g is the gravitational acceleration.
The following were values were measured for the motor:
R = 0.05 metres
W = 49 N
Thus, Jm =
49∗0.052
9.8
= 0.0125 kg_m2
𝐿
ɾ𝑒 = π‘…π‘Ž =
6.6∗10−3
π‘Ž
ΙΎπ‘š
12
= 0.00055 = 5.5 ∗ 10−4
π‘…π‘Ž π½π‘š 12𝛺 ∗ 0.0125π‘˜π‘”π‘š2
=
=
= 10.5753
𝐾𝑑 𝐾𝐸
0.3681 ∗ 0.038533
1
Thus G1(s) = 0.038533(𝑠∗10.58+1)(5.5∗10−4 𝑠+1)
1
= 0.038533(0.005819𝑠2 +10.58𝑠+1)
1
= 0.0002242𝑠2 +0.4077𝑠+0.038533
4460.3
= 𝑠2 +1818.5𝑠+171.87
The buck converter transfer function is given by;
38
πΊπ‘£π‘œπ‘‘(𝑠) =
𝑣
Μ‚(𝑠)
π‘œ
|
Μ‚
𝑑 (𝑠)
=
𝑣̂
𝑖𝑛 = 0
Vin
Ls
1 + LCs 2 + R
Vin is chosen as 40V.
Thus, πΊπ‘£π‘œπ‘‘(𝑠) =
40
72727.3
6.6∗10−3 𝑠
1+
12
= 𝑠+1818.2
4460.3
72727.3
The motor_converter (plant) transfer function G(s) = 𝑠2 +1818.5𝑠+171.87 ∗ 𝑠+1818.2
324385454.5
= 𝑠3 +3636.7𝑠2 +3306568.52𝑠+312403.124
𝐻(𝑠) =
𝑠3
+
3636.7𝑠 2
324385454.5
+ 3306568𝑠 + 324697857.624
The plant transfer function was used to design the compensator using MATLAB as follows:
A new m-file was created and the following code typed on it:
K = 324385454.5;
a=1
b = 3636.7;
c = 3306568.52;
d = 312403.124;
s = tf('s');
G = K/as3+bs2+cs+d;
The code below was added to the m-file and run to obtain the bode plot:
bode(P_motor)
grid
title('Bode Plot of the Original Plant')
The plot of figure 3.7 below was obtained:
39
Figure 3. 7 Bode plot diagram for the motor-converter transfer function
A phase margin of around 60 degrees is generally sufficient for stability margin. From the above
Bode plot, this phase margin is achieved for a crossover frequency of approximately 500 rad/sec.
The bode command below was added to the m-file to get the exact phase and gain at 500rad/sec.
[mag,phase,w] = bode(P_motor,10)
The values below were obtained on the MATLAB window:
mag =
40
0.1824
phase =
-120.7397
w=
500
The exact phase margin is, 180 – 120.7397 = 59.260
The exact gain at this frequency is 20log 0.1824 =
A proportional gain of
1
0.1824
= 5.4825 = 5.5 dB is required to achieve an open loop gain of 1 at
500rad/sec
The following command was added to the m-file to observe the effect of the proportional
controller on the system:
C = 5.5;
margin(C*G);
41
Figure 3. 8 Bode diagram of the compensated system
To plot the system response a % was added to the front of the margin and bode commands to
comment them out and the following code added to the m-file:
sys_cl = feedback(C*G,1);
t = 0:0.01:10;
step(sys_cl,t), grid
title('Step Response with Proportional Gain = 72')
The figure 3.9 was obtained:
42
43
Figure 3. 9 Step response of the compensated system
44
CHAPTER FOUR: SIMULATION
Simulation of the various circuits was done using the PowerSim software as shown below.
4.1 OPEN LOOP SIMULATION
The aim of this simulation was to obtain different values of speed at different duty cycles hence
armature voltages.
The circuit was connected to match the speed of the practical motor used at different armature
voltages.
The circuit for the open loop simulation was as shown below:
Figure 4. 1 Open Loop Simulation
4.2 CLOSED LOOP SIMULATION
A feedback system was incorporated with the proportional compensator designed to form a
closed loop system. The compensator replaced the PWM producer in the open loop circuit.
The aim of this simulation was to get different values of speed using different values of the
reference voltage. A voltage of 2.4V was used as the maximum reference voltage and it was
reduced using a voltage divider to give different values for the reference voltage.
The figure below shows the circuit of the closed loop simulation:
45
Figure 4 2 Closed Loop Simulation
The results of the open loop simulation and the closed loop simulation are recorded in chapter 5.
46
CHAPTER FIVE: RESULTS AND ANALYSIS
5.1 RESULTS FOR THE DC MOTOR PRACTICAL EXPERIMENT
Table 1. Results for the dc motor practical experiment
The values in bold are the average values for Ra, Kt and Kv respectively.
A graph of Va/Vo against Vo was plotted as shown below:
Figure 5 1 Graph of Va/Vo against Va
The values of the armature voltage divided by the output voltage, that is, Va/Vo, were relatively
constant as seen in the graph; they ranged from 38 to 40.
A graph of Vo against speed in RPM was plotted as shown below:
47
Figure 5 2 Graph of Output Voltage against Speed in RPM
A straight line of best fit was drawn. The gradient of the graph is 0.001 as seen in the graph.
Therefore, for every 1 rpm increase in speed there is 0.001 increase in the output voltage.
5.2 OPEN LOOP SIMULATION RESULTS
Table 2. Open loop simulation results
48
5.3 CLOSED LOOP SIMULATION
Table 3. Closed loop simulation
5.4 GATE DRIVE SIMULATION RESULTS
Figure 5 3 Gate Drive Practical waveforms
49
PRACTICAL RESULTS
The open loop practical results were as follows:
Table 4. Practical Results
DUTY CYCLE
0.1
0.5
0.9
ARMATURE VOLTAGE
2.32
13.67
27.00
50
SPEED IN RPM
22
370
740
CHAPTER SIX: CONCLUSION AND RECOMMENDATIONS
6.1 CONCLUSIONS
The importance of permanent magnet dc motor speed control cannot be overstated. This project
has shown that cheaper and simpler methods can be used to control the speed of a permanent
magnet dc motor efficiently and accurately.
The dc motor was controlled using a DSP as the controller. The transfer function of the closed
loop system of the speed drive was also determined in the process.
6.2 DIFFICULTIES ENCOUNTERED
The speed measurement instruments in the lab were in a poor condition and could not accurately
give the desired results
6.3 RECOMMENDATIONS
The recommendations for future works are:
Designing and implementing the dc motor speed drive in all the four quadrants. This will be able
to give rotation in either direction and provide braking for the dc motor.
Using the microprocessor to detect and display the speed of the dc motor on a screen.
51
REFERENCES
A. E. Fitzgerald, C. K. (2003). Electric Machinery. New York: McGraw-Hill.
Bishop, R. H. (n.d.). Mordern Control Systems Analysis. ADDISON WESLEY.
Ned Mohan, T. M. (2003). POWER ELECTRONICS. Jolm Wiley & Sons.
Nice N. S. (1996). Control Systems Engineering. John Wiley & Sons Inc.
John Bird. (2003). Electrical and Electronic Principles and Technology. Newnes.
Robert W. Erickson. (2001). Fundanentals of Power Electronics. Kluwer Academic Publishers.
www.ti.com
http://www.Analogdevices.com
www.mathworks.com/controltutorials
52
APPENDIX
//---------------------------------------------------------------------------------//
FILE:
ProjectName-Main.C
//
//
Description:
Sample Template file to edit
//
The file drives duty on PWM1A using C28x
//
These can be deleted and modified by the user
//
C28x ISR is triggered by the PWM 1 interrupt
//
//
Version:
2.0
//
// Target:
TMS320F2802x(PiccoloA),
//
//---------------------------------------------------------------------------------// Copyright Texas Instruments © 2004-2010
//---------------------------------------------------------------------------------// Revision History:
//---------------------------------------------------------------------------------// Date | Description / Status
//---------------------------------------------------------------------------------// October 2010 - Sample template project with DPLib v3 (MB)
//---------------------------------------------------------------------------------//
// PLEASE READ - Useful notes about this Project
// Although this project is made up of several files, the most important ones are:
//
"{ProjectName}-Main.C"
- this file
//
- Application Initialization, Peripheral config,
//
- Application management
//
- Slower background code loops and Task scheduling
53
//
"{ProjectName}-DevInit_F28xxx.C
//
- Device Initialization, e.g. Clock, PLL, WD, GPIO mapping
//
- Peripheral clock enables
//
- DevInit file will differ per each F28xxx device series, e.g. F280x, F2833x,
//
//
//
"{ProjectName}-DPL-ISR.asm
- Assembly level library Macros and any cycle critical functions are found here
"{ProjectName}-DPL-CLA.asm"
//
- Init code for DPlib CLA Macros run by C28x
//
- CLA Task code
//
"{ProjectName}-Settings.h"
//
- Global defines (settings) project selections are found here
//
- This file is referenced by both C and ASM files.
//
//
"{ProjectName}-CLAShared.h.h"
- Variable defines and header includes that are shared b/w CLA and C28x
//
// Code is made up of sections, e.g. "FUNCTION PROTOTYPES", "VARIABLE DECLARATIONS" ,..etc
//
each section has FRAMEWORK and USER areas.
// FRAMEWORK areas provide useful ready made "infrastructure" code which for the most part
//
does not need modification, e.g. Task scheduling, ISR call, GUI interface support,...etc
// USER areas have functional example code which can be modified by USER to fit their appl.
//
// Code can be compiled with various build options (Incremental Builds IBx), these
// options are selected in file "{ProjectName}-Settings.h". Note: "Rebuild All" compile
// tool bar button must be used if this file is modified.
//---------------------------------------------------------------------------------#include "ProjectName-Settings.h"
#include "PeripheralHeaderIncludes.h"
#include "DSP2802x_EPWM_defines.h"
54
#include "DPlib.h"
#include "IQmathLib.h"
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%
// FUNCTION PROTOTYPES
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%
// Add prototypes of functions being used in the project here
void DeviceInit(void);
#ifdef FLASH
void InitFlash();
#endif
void MemCopy();
//-------------------------------- DPLIB -------------------------------------------void PWM_1ch_CNF(int16 n, int16 period, int16 mode, int16 phase);
void ADC_SOC_CNF(int ChSel[], int Trigsel[], int ACQPS[], int IntChSel, int mode);
// -------------------------------- FRAMEWORK -------------------------------------// State Machine function prototypes
//---------------------------------------------------------------------------------// Alpha states
void A0(void); //state A0
void B0(void); //state B0
void C0(void); //state C0
// A branch states
void A1(void); //state A1
void A2(void); //state A2
void A3(void); //state A3
void A4(void); //state A4
55
// B branch states
void B1(void); //state B1
void B2(void); //state B2
void B3(void); //state B3
void B4(void); //state B4
// C branch states
void C1(void); //state C1
void C2(void); //state C2
void C3(void); //state C3
void C4(void); //state C4
// Variable declarations
void (*Alpha_State_Ptr)(void); // Base States pointer
void (*A_Task_Ptr)(void);
// State pointer A branch
void (*B_Task_Ptr)(void);
// State pointer B branch
void (*C_Task_Ptr)(void);
// State pointer C branch
//----------------------------------------------------------------------------------
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%
// VARIABLE DECLARATIONS - GENERAL
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%
// -------------------------------- FRAMEWORK --------------------------------------
int16
VTimer0[4];
// Virtual Timers slaved off CPU Timer 0
56
int16
VTimer1[4];
// Virtual Timers slaved off CPU Timer 1
int16
VTimer2[4];
// Virtual Timers slaved off CPU Timer 2
// Used for running BackGround in flash, and ISR in RAM
extern Uint16 *RamfuncsLoadStart, *RamfuncsLoadEnd, *RamfuncsRunStart;
// Used for copying CLA code from load location to RUN location
extern Uint16 Cla1funcsLoadStart, Cla1funcsLoadEnd, Cla1funcsRunStart;
// Used for ADC Configuration
int
ChSel[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int
int
TrigSel[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
ACQPS[16] = {7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7};
// Used to indirectly access all EPWM modules
volatile struct EPWM_REGS *ePWM[] =
{ &EPwm1Regs,
//intentional: (ePWM[0] not
used)
&EPwm1Regs,
&EPwm2Regs,
&EPwm3Regs,
&EPwm4Regs,
};
// Used to indirectly access all Comparator modules
volatile struct COMP_REGS *Comp[] =
{ &Comp1Regs,
//intentional: (Comp[0] not
used)
&Comp1Regs,
&Comp2Regs,
57
};
// ---------------------------------- USER ----------------------------------------// ---------------------------- DPLIB Net Pointers --------------------------------// Declare net pointers that are used to connect the DP Lib Macros here
//ADCDRV_1ch - instance #1
extern volatile long *ADCDRV_1ch_Rlt0; //instance 0
// CONTROL_2P2Z - instance #1
extern volatile long *CNTL_2P2Z_Ref1;
extern volatile long *CNTL_2P2Z_Out1;
extern volatile long *CNTL_2P2Z_Fdbk1;
extern volatile long *CNTL_2P2Z_Coef1;
// PWMDRV_1ch
extern volatile long *PWMDRV_1ch_Duty1;
// instance #1, EPWM1
// ---------------------------- DPLIB Variables --------------------------------// Declare the net variables being used by the DP Lib Macro here
volatile long ADCOut, Filter_Out , Ref_Value;
#pragma DATA_SECTION(CNTL_2P2Z_CoefStruct1, "CNTL_2P2Z_Coef");
struct CNTL_2P2Z_CoefStruct CNTL_2P2Z_CoefStruct1;
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%
// VARIABLE DECLARATIONS - CCS WatchWindow / GUI support
58
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%
// -------------------------------- FRAMEWORK --------------------------------------
//GUI support variables
// sets a limit on the amount of external GUI controls - increase as necessary
int16
*varSetTxtList[16];
//16 textbox controlled variables
int16
*varSetBtnList[16];
//16 button controlled variables
int16
*varSetSldrList[16];
//16 slider controlled variables
int16
*varGetList[16];
//16 variables sendable to GUI
int16
*arrayGetList[16];
//16 arrays sendable to GUI
int16 LedBlinkCnt;
// ---------------------------------- USER -----------------------------------------
// Monitor ("Get")
// Display as:
// Configure ("Set")
// History arrays are used for Running Average calculation (boxcar filter)
// Used for CCS display and GUI only, not part of control loop processing
//Scaling Constants (values found via spreadsheet; exact value calibrated per board)
// Variables for background support only (no need to access)
int16
i;
Uint32 HistPtr, temp_Scratch;
// common use incrementer
// Temp here means Temporary
59
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%
// MAIN CODE - starts here
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%
void main(void)
{
//=================================================================================
//
INITIALISATION - General
//=================================================================================
// The DeviceInit() configures the clocks and pin mux registers
// The function is declared in {ProjectName}-DevInit_F2803/2x.c,
// Please ensure/edit that all the desired components pin muxes
// are configured properly that clocks for the peripherals used
// are enabled, for example the individual PWM clock must be enabled
// along with the Time Base Clock
DeviceInit();
// Device Life support & GPIO
//-------------------------------- FRAMEWORK --------------------------------------
// Only used if running from FLASH
// Note that the variable FLASH is defined by the compiler with -d FLASH
#ifdef FLASH
// Copy time critical code and Flash setup code to RAM
// The RamfuncsLoadStart, RamfuncsLoadEnd, and RamfuncsRunStart
// symbols are created by the linker. Refer to the linker files.
60
MemCopy(&RamfuncsLoadStart, &RamfuncsLoadEnd, &RamfuncsRunStart);
// Call Flash Initialization to setup flash waitstates
// This function must reside in RAM
InitFlash();
// Call the flash wrapper init function
#endif //(FLASH)
// Timing sync for background loops
// Timer period definitions found in PeripheralHeaderIncludes.h
CpuTimer0Regs.PRD.all = mSec1;
// A tasks
CpuTimer1Regs.PRD.all = mSec10;
// B tasks
CpuTimer2Regs.PRD.all = mSec100;
// C tasks
// Tasks State-machine init
Alpha_State_Ptr = &A0;
A_Task_Ptr = &A1;
B_Task_Ptr = &B1;
C_Task_Ptr = &C1;
VTimer0[0] = 0;
VTimer1[0] = 0;
VTimer2[0] = 0;
LedBlinkCnt = 5;
// ---------------------------------- USER ----------------------------------------// put common initialization/variable definitions here
61
//===============================================================================
//
INITIALISATION - GUI connections
//=================================================================================
// Use this section only if you plan to "Instrument" your application using the
// Microsoft C# freeware GUI Template provided by TI
/*
//"Set" variables
//--------------------------------------// assign GUI variable Textboxes to desired "setable" parameter addresses
varSetTxtList[0] = &Gui_TxtListVar;
varSetTxtList[1] = &Gui_TxtListVar;
varSetTxtList[2] = &Gui_TxtListVar;
varSetTxtList[3] = &Gui_TxtListVar;
varSetTxtList[4] = &Gui_TxtListVar;
varSetTxtList[5] = &Gui_TxtListVar;
varSetTxtList[6] = &Gui_TxtListVar;
varSetTxtList[7] = &Gui_TxtListVar;
varSetTxtList[8] = &Gui_TxtListVar;
varSetTxtList[9] = &Gui_TxtListVar;
varSetTxtList[10] = &Gui_TxtListVar;
varSetTxtList[11] = &Gui_TxtListVar;
// assign GUI Buttons to desired flag addresses
varSetBtnList[0] = &Gui_BtnListVar;
varSetBtnList[1] = &Gui_BtnListVar;
varSetBtnList[2] = &Gui_BtnListVar;
varSetBtnList[3] = &Gui_BtnListVar;
varSetBtnList[4] = &Gui_BtnListVar;
62
// assign GUI Sliders to desired "setable" parameter addresses
varSetSldrList[0] = &Gui_SldrListVar;
varSetSldrList[1] = &Gui_SldrListVar;
varSetSldrList[2] = &Gui_SldrListVar;
varSetSldrList[3] = &Gui_SldrListVar;
varSetSldrList[4] = &Gui_SldrListVar;
//"Get" variables
//--------------------------------------// assign a GUI "getable" parameter address
varGetList[0] = &Gui_GetListVar;
varGetList[1] = &Gui_GetListVar;
varGetList[2] = &Gui_GetListVar;
varGetList[3] = &Gui_GetListVar;
varGetList[4] = &Gui_GetListVar;
varGetList[5] = &Gui_GetListVar;
varGetList[6] = &Gui_GetListVar;
varGetList[7] = &Gui_GetListVar;
varGetList[8] = &Gui_GetListVar;
varGetList[9] = &Gui_GetListVar;
varGetList[10] = &Gui_GetListVar;
varGetList[11] = &Gui_GetListVar;
varGetList[12] = &Gui_GetListVar;
varGetList[13] = &Gui_GetListVar;
varGetList[14] = &Gui_GetListVar;
varGetList[15] = &Gui_GetListVar;
// assign a GUI "getable" parameter array address
arrayGetList[0] = &DBUFF1;
//only need to set initial position of array,
63
arrayGetList[1] = &DBUFF2;
// program will run through it accordingly
arrayGetList[2] = &DBUFF3;
arrayGetList[3] = &DBUFF4;
*/
//==================================================================================
//
INCREMENTAL BUILD OPTIONS - NOTE: selected via {ProjectName-Settings.h
//==================================================================================
// ---------------------------------- USER -----------------------------------------
//---------------------------------------------------------------------// Open Loop Two Phase Interleaved PFC PWM Driver
//----------------------------------------------------------------------
// Configure PWM1 for 50Khz (Period Count= 60Mhz/50Khz = 1200)
PWM_1ch_CNF(1, 1200, 1, 0);
// Configure ADC to be triggered from EPWM1 Period event
//Map channel to ADC Pin
ChSel[0]=14;
//Map channel 0 to pin ADC-B6
// for additional ADC conversions modify below
/*ChSel[1]=n;
//An
ChSel[2]=n;
//An
ChSel[3]=n;
//An
ChSel[4]=n;
//An
ChSel[5]=n;
//An
ChSel[6]=n;
//An
ChSel[7]=n;
//An
ChSel[8]=n;
//An
64
ChSel[9]=n;
//An
ChSel[10]=n;
//An
ChSel[11]=n;
//An
ChSel[12]=n;
//An
ChSel[13]=n;
//An
ChSel[14]=n;
//An
ChSel[15]=n;
//An
*/
// Select Trigger Event for ADC conversion
TrigSel[0]= ADCTRIG_EPWM1_SOCA;
// associate the appropriate peripheral trigger to the ADC channel
/*TrigSel[1]= ADCTRIG_EPWMn_SOCA;
TrigSel[2]= ADCTRIG_EPWMn_SOCA;
TrigSel[3]= ADCTRIG_EPWMn_SOCA;
TrigSel[4]= ADCTRIG_EPWMn_SOCA;
TrigSel[5]= ADCTRIG_EPWMn_SOCA;
TrigSel[6]= ADCTRIG_EPWMn_SOCA;
TrigSel[7]= ADCTRIG_EPWMn_SOCA;
TrigSel[8]= ADCTRIG_EPWMn_SOCA;
TrigSel[9]= ADCTRIG_EPWMn_SOCA;
TrigSel[10]= ADCTRIG_EPWMn_SOCA;
TrigSel[11]= ADCTRIG_EPWMn_SOCA;
TrigSel[12]= ADCTRIG_EPWMn_SOCA;
TrigSel[13]= ADCTRIG_EPWMn_SOCA;
TrigSel[14]= ADCTRIG_EPWMn_SOCA;
TrigSel[15]= ADCTRIG_EPWMn_SOCA;*/
// Configure the ADC with auto interrupt clear mode
65
// ADC interrupt after EOC of channel 0
ADC_SOC_CNF(ChSel,TrigSel,ACQPS,0,2);
// Configure the EPWM1 to issue the SOC
EPwm1Regs.ETSEL.bit.SOCAEN = 1;
EPwm1Regs.ETSEL.bit.SOCASEL = ET_CTR_PRD; // Use PRD event as trigger for ADC SOC
EPwm1Regs.ETPS.bit.SOCAPRD
= ET_1ST;
// Generate pulse on every event
// Digital Power CLA(DP) library initialisation
DPL_Init();
// Lib Module connection to "nets"
//---------------------------------------//----------------------------------------
// ADCDRV_1ch block connections
// Initialize the net variables
// Initialize the net variables
// Connect the ADC Output to the Net Variable
ADCDRV_1ch_Rlt0 = &ADCOut;
// Connect the CNTL_2P2Z block to the variables
CNTL_2P2Z_Fdbk1 = &ADCOut;
CNTL_2P2Z_Out1 = &Filter_Out;
66
CNTL_2P2Z_Ref1 = &Ref_Value;
CNTL_2P2Z_Coef1 = &CNTL_2P2Z_CoefStruct1.b2;
// Connect the PWM Driver input to the output of the controller 2P2Z
PWMDRV_1ch_Duty1 = &Filter_Out;
// Initialize the Controller Coefficients
CNTL_2P2Z_CoefStruct1.b2 = _IQ26(0);
CNTL_2P2Z_CoefStruct1.b1 = _IQ26(0);
CNTL_2P2Z_CoefStruct1.b0 = _IQ26(0);
CNTL_2P2Z_CoefStruct1.a2 = _IQ26(5.5);
CNTL_2P2Z_CoefStruct1.a1 = _IQ26(0);
CNTL_2P2Z_CoefStruct1.max =_IQ24(0);
CNTL_2P2Z_CoefStruct1.min =_IQ24(0);
//Initialize the net Variables/nodes
Ref_Value=_IQ24(0.82);
Filter_Out=_IQ24(0.0)
// (INCR_BUILD == 1)
//===================================================================================
=
// INTERRUPTS & ISR INITIALIZATION (best to run this section after other initialization)
//===================================================================================
=
// Set up C28x Interrupt
67
//Also Set the appropriate # define's in the {ProjectName}-Settings.h
//to enable interrupt management in the ISR
;EALLOW;
PieVectTable.EPWM1_INT = &DPL_ISR;
PieCtrlRegs.PIEIER3.bit.INTx1 = 1;
// Map Interrupt
// PIE level enable, Grp3 / Int1
EPwm1Regs.ETSEL.bit.INTSEL = ET_CTR_PRD;
EPwm1Regs.ETSEL.bit.INTEN = 1;
EPwm1Regs.ETPS.bit.INTPRD = ET_1ST;
// INT on PRD event
// Enable INT
// Generate INT on every event
IER |= M_INT3;
// Enable CPU INT3 connected to EPWM1-6 INTs:
EINT;
// Enable Global interrupt INTM
ERTM;
// Enable Global realtime interrupt DBGM
EDIS;
//=================================================================================
//
BACKGROUND (BG) LOOP
//=================================================================================
//--------------------------------- FRAMEWORK ------------------------------------for(;;) //infinite loop
{
// State machine entry & exit point
//===========================================================
(*Alpha_State_Ptr)();
// jump to an Alpha state (A0,B0,...)
//===========================================================
}
} //END MAIN CODE
68
//=================================================================================
//
STATE-MACHINE SEQUENCING AND SYNCRONIZATION
//=================================================================================
//--------------------------------- FRAMEWORK ------------------------------------void A0(void)
{
// loop rate synchronizer for A-tasks
if(CpuTimer0Regs.TCR.bit.TIF == 1)
{
CpuTimer0Regs.TCR.bit.TIF = 1; // clear flag
//----------------------------------------------------------(*A_Task_Ptr)();
// jump to an A Task (A1,A2,A3,...)
//-----------------------------------------------------------
VTimer0[0]++;
// virtual timer 0, instance 0 (spare)
}
Alpha_State_Ptr = &B0;
// Comment out to allow only A tasks
}
void B0(void)
{
// loop rate synchronizer for B-tasks
if(CpuTimer1Regs.TCR.bit.TIF == 1)
{
CpuTimer1Regs.TCR.bit.TIF = 1;
// clear flag
69
//----------------------------------------------------------(*B_Task_Ptr)();
// jump to a B Task (B1,B2,B3,...)
//----------------------------------------------------------VTimer1[0]++;
// virtual timer 1, instance 0 (spare)
}
Alpha_State_Ptr = &C0;
// Allow C state tasks
}
void C0(void)
{
// loop rate synchronizer for C-tasks
if(CpuTimer2Regs.TCR.bit.TIF == 1)
{
CpuTimer2Regs.TCR.bit.TIF = 1;
// clear flag
//----------------------------------------------------------(*C_Task_Ptr)();
// jump to a C Task (C1,C2,C3,...)
//----------------------------------------------------------VTimer2[0]++;
//virtual timer 2, instance 0 (spare)
}
Alpha_State_Ptr = &A0; // Back to State A0
}
//=================================================================================
//
A - TASKS
//=================================================================================
70
//-------------------------------------------------------void A1(void)
//-------------------------------------------------------{
//------------------//the next time CpuTimer0 'counter' reaches Period value go to A2
A_Task_Ptr = &A2;
//------------------}
//----------------------------------------------------------------void A2(void)
//----------------------------------------------------------------{
//------------------//the next time CpuTimer0 'counter' reaches Period value go to A1
A_Task_Ptr = &A3;
//------------------}
//----------------------------------------void A3(void)
//----------------------------------------{
//----------------//the next time CpuTimer0 'counter' reaches Period value go to A1
A_Task_Ptr = &A4;
71
//----------------}
//---------------------------------------------------------void A4(void)
//--------------------------------------------------------{
//----------------//the next time CpuTimer0 'counter' reaches Period value go to A1
A_Task_Ptr = &A1;
//----------------}
//=================================================================================
//
B - TASKS
//=================================================================================
//----------------------------------- USER ----------------------------------------
//---------------------------------------void B1(void)
//---------------------------------------{
//----------------//the next time CpuTimer1 'counter' reaches Period value go to B2
B_Task_Ptr = &B2;
//----------------}
72
//---------------------------------------void B2(void) // Blink LED on the control CArd
//---------------------------------------{
if(LedBlinkCnt==0)
{
GpioDataRegs.GPBTOGGLE.bit.GPIO34 = 1;
//turn on/off LD3 on the
controlCARD
LedBlinkCnt=5;
}
else
LedBlinkCnt--;
//----------------//the next time CpuTimer1 'counter' reaches Period value go to B3
B_Task_Ptr = &B3;
//----------------}
//---------------------------------------void B3(void)
//---------------------------------------{
//----------------//the next time CpuTimer1 'counter' reaches Period value go to B4
B_Task_Ptr = &B4;
//----------------}
73
//---------------------------------------void B4(void) // SPARE
//---------------------------------------{
//----------------//the next time CpuTimer1 'counter' reaches Period value go to B1
B_Task_Ptr = &B1;
//----------------}
//=================================================================================
//
C - TASKS
//=================================================================================
//--------------------------------- USER ------------------------------------------
//-----------------------------------------------------void C1(void)
//-----------------------------------------------------{
//----------------//the next time CpuTimer2 'counter' reaches Period value go to C2
C_Task_Ptr = &C2;
//-----------------
}
74
//---------------------------------------void C2(void)
//---------------------------------------{
//----------------//the next time CpuTimer2 'counter' reaches Period value go to C3
C_Task_Ptr = &C3;
//----------------}
//----------------------------------------void C3(void)
//----------------------------------------{
//----------------//the next time CpuTimer2 'counter' reaches Period value go to C4
C_Task_Ptr = &C4;
//----------------}
//----------------------------------------void C4(void) // SPARE
//----------------------------------------{
75
//----------------//the next time CpuTimer2 'counter' reaches Period value go to C1
C_Task_Ptr = &C1;
//----------------}
76
Download