Professional Documents
Culture Documents
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
DEDICATION
I dedicate this project to my sister Brigit Wanyama and my parents Peter and Everlyne for their
continuous support during my course.
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 departments 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.
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
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
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
LIST OF ABBREVIATIONS
DSP
DC
Direct Current
PWM
EME
Electromagnetic Field
KVL
KCL
GPS
Global Position
RPM
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.
10
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 Flemings 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 (Lenzs Law). The induced emf is known as back emf or counter emf, Eb.
The back emf is given by;
PZN
Eb= 60A
Vt Eb
Ra
Since Vt and Ra are usually fixed, the value of Eb determines the current Ia drawn by the motor. If
PZN
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,
PZN
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
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.
m
+ m + Tl (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.
Vt=ea+Raia+La
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.
In permanent magnet dc motors, permanent magnets on the stator produce a constant field flux
f and thus we have;
Tem=kTIa
Ea=kEm
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
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.
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.
vt = ea + Raia + La (ia)
ea = kE m
Tem = kT ia
Tem = TWL + B m + J
( m )
m(s) = sm(s)
These equations for the motor-load combination can be represented by the transfer function
blocks as shown in figure 2.7.
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) = (
+)(+)+
()
()
= (
+ )(+)+
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=
G1(s)=
1
2
( + +1)
G1(s) =
()
()
1
( +1)( +1)
19
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.
20
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.
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
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.
() = ()
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:
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, iLd = vod 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;
Cs
()
= ()
()
} -------- (6)
Therefore,
26
() =
()
()
= 0
Vin
Ls
1 + LCs 2 + R
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.
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
Figure 3.1. A flow chart showing different components used in the project
30
o
o
o
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
33
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.
36
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
2
2
490.052
9.8
= 0.0125 kg_m2
= =
6.6103
12
12 0.01252
=
=
= 10.5753
0.3681 0.038533
1
= 0.038533(0.0058192 +10.58+1)
1
= 0.00022422 +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
40
72727.3
6.6103
1+
12
= +1818.2
4460.3
72727.3
= 3 +3636.72 +3306568.52+312403.124
() =
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
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)
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
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
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')
43
44
45
The results of the open loop simulation and the closed loop simulation are recorded in chapter 5.
46
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:
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.
48
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
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:
//
//
//
//
//
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 management
//
//
"{ProjectName}-DevInit_F28xxx.C
//
//
//
- 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"
//
//
//
"{ProjectName}-Settings.h"
//
//
//
//
"{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
//
// 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);
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);
void (*B_Task_Ptr)(void);
void (*C_Task_Ptr)(void);
//----------------------------------------------------------------------------------
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%
// VARIABLE DECLARATIONS - GENERAL
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%
int16
VTimer0[4];
56
int16
VTimer1[4];
int16
VTimer2[4];
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)
&EPwm1Regs,
&EPwm2Regs,
&EPwm3Regs,
&EPwm4Regs,
};
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;
// ---------------------------- DPLIB Variables --------------------------------// Declare the net variables being used by the DP Lib Macro here
volatile long ADCOut, Filter_Out , Ref_Value;
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%
// VARIABLE DECLARATIONS - CCS WatchWindow / GUI support
58
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%
*varSetTxtList[16];
int16
*varSetBtnList[16];
int16
*varSetSldrList[16];
int16
*varGetList[16];
int16
*arrayGetList[16];
int16 LedBlinkCnt;
// 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)
i;
59
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%
// MAIN CODE - starts here
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%
void main(void)
{
//=================================================================================
//
INITIALISATION - General
//=================================================================================
DeviceInit();
#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
#endif //(FLASH)
// A tasks
CpuTimer1Regs.PRD.all = mSec10;
// B tasks
CpuTimer2Regs.PRD.all = mSec100;
// C tasks
VTimer0[0] = 0;
VTimer1[0] = 0;
VTimer2[0] = 0;
LedBlinkCnt = 5;
61
//===============================================================================
//
//=================================================================================
// 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;
62
//"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;
arrayGetList[1] = &DBUFF2;
arrayGetList[2] = &DBUFF3;
arrayGetList[3] = &DBUFF4;
*/
//==================================================================================
//
//==================================================================================
// ---------------------------------- USER -----------------------------------------
//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
*/
= ET_1ST;
ADCDRV_1ch_Rlt0 = &ADCOut;
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;
// (INCR_BUILD == 1)
//===================================================================================
=
// INTERRUPTS & ISR INITIALIZATION (best to run this section after other initialization)
//===================================================================================
=
67
// 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;
// Enable INT
// Generate INT on every event
IER |= M_INT3;
EINT;
ERTM;
EDIS;
//=================================================================================
//
//=================================================================================
//===========================================================
}
} //END MAIN CODE
68
//=================================================================================
//
//=================================================================================
//----------------------------------------------------------(*A_Task_Ptr)();
//-----------------------------------------------------------
VTimer0[0]++;
Alpha_State_Ptr = &B0;
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)();
//----------------------------------------------------------VTimer1[0]++;
Alpha_State_Ptr = &C0;
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)();
//----------------------------------------------------------VTimer2[0]++;
//=================================================================================
//
A - TASKS
//=================================================================================
70
//-------------------------------------------------------void A1(void)
//-------------------------------------------------------{
//----------------------------------------------------------------void A2(void)
//----------------------------------------------------------------{
//------------------//the next time CpuTimer0 'counter' reaches Period value go to A1
A_Task_Ptr = &A3;
//------------------}
//----------------------------------------void A3(void)
//----------------------------------------{
//----------------}
//---------------------------------------------------------void A4(void)
//--------------------------------------------------------{
//----------------//the next time CpuTimer0 'counter' reaches Period value go to A1
A_Task_Ptr = &A1;
//----------------}
//=================================================================================
//
B - TASKS
//=================================================================================
//---------------------------------------void B1(void)
//---------------------------------------{
//----------------//the next time CpuTimer1 'counter' reaches Period value go to B2
B_Task_Ptr = &B2;
//----------------}
72
controlCARD
LedBlinkCnt=5;
}
else
LedBlinkCnt--;
//---------------------------------------void B3(void)
//---------------------------------------{
//----------------//the next time CpuTimer1 'counter' reaches Period value go to B4
B_Task_Ptr = &B4;
//----------------}
73
//=================================================================================
//
C - TASKS
//=================================================================================
//-----------------------------------------------------void C1(void)
//-----------------------------------------------------{
}
74
//---------------------------------------void C2(void)
//---------------------------------------{
//----------------------------------------void C3(void)
//----------------------------------------{
76