Speed Control of a Permanent Magnet Dc Motor Using a Dsp

Embed Size (px)

Citation preview

  • 8/16/2019 Speed Control of a Permanent Magnet Dc Motor Using a Dsp

    1/76

    1

    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 AKUNGWIADM 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

  • 8/16/2019 Speed Control of a Permanent Magnet Dc Motor Using a Dsp

    2/76

    2

    DEDIC TION

    I dedicate this project to my sister Brigit Wanyama and my parents Peter and Everlyne for their

    continuous support during my course.

  • 8/16/2019 Speed Control of a Permanent Magnet Dc Motor Using a Dsp

    3/76

    3

    CKNOWLEDGEMENT

    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.

  • 8/16/2019 Speed Control of a Permanent Magnet Dc Motor Using a Dsp

    4/76

    4

    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

  • 8/16/2019 Speed Control of a Permanent Magnet Dc Motor Using a Dsp

    5/76

    5

    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

  • 8/16/2019 Speed Control of a Permanent Magnet Dc Motor Using a Dsp

    6/76

    6

    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 ..................................................... 25Figure 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 ........................................................................................................ 37Figure 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

    http://e/project/omwaka/WANYAMA/PROJECT.docx%23_Toc417639958http://e/project/omwaka/WANYAMA/PROJECT.docx%23_Toc417639958

  • 8/16/2019 Speed Control of a Permanent Magnet Dc Motor Using a Dsp

    7/76

    7

    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 

  • 8/16/2019 Speed Control of a Permanent Magnet Dc Motor Using a Dsp

    8/76

    8

    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/16/2019 Speed Control of a Permanent Magnet Dc Motor Using a Dsp

    9/76

    9

    ABSTRACTSpeed 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 asthe 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. 

  • 8/16/2019 Speed Control of a Permanent Magnet Dc Motor Using a Dsp

    10/76

    10

    CHAPTER ONE: INTRODUCTIONDC 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. Theclosed 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.

  • 8/16/2019 Speed Control of a Permanent Magnet Dc Motor Using a Dsp

    11/76

    11

    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 MOTORA 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

  • 8/16/2019 Speed Control of a Permanent Magnet Dc Motor Using a Dsp

    12/76

    12

    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, E b.

    The back emf is given by;

    E b=P∅ZNA  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 whenthe motor is running under normal conditions.

    The net voltage across the armature circuit is, Va=Vt-E b.

    If R a is the armature resistance, then, Ia=  −Eb  Since Vt and R a are usually fixed, the value of E b determines the current Ia drawn by the motor. If

    the speed of the motor is high, then E b=P∅ZNA , is large hence the motor draws less armature

    current and vice versa.

    Vt=E b + IaR a (Motor voltage equation)

    E b= Vt - IaR a 

    Thus,

    P∅ZNA = Vt - IaR a 

  • 8/16/2019 Speed Control of a Permanent Magnet Dc Motor Using a Dsp

    13/76

    13

    Or N=  ( − )A∅PZ  Or N

    = K( – )

    ∅ 

     Where K=

    APZ  

    Armature torque =∅P  = Eb  

    SPEED CONTROL OF A DC MOTOR

    There are three main methods of controlling the speed of a dc motor, namely:

    i.  By varying the flux per pole (∅). This is called flux control method.ii.  By varying the resistance in the armature circuit. This is called armature control method.

    iii.  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 permanentmagnet 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 electromagnetictorque;

    Tem=k t∅f iaWhere k t 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 =k e∅f  mwhere k e 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  Tl(t) 

  • 8/16/2019 Speed Control of a Permanent Magnet Dc Motor Using a Dsp

    14/76

    14

    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 R a, and the

    armature winding inductance La.

    Vt=ea+R aia+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, thearmature 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.

  • 8/16/2019 Speed Control of a Permanent Magnet Dc Motor Using a Dsp

    15/76

    15

    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=k TIa 

    Ea=k EmVt=Ea + R aIa

    The steady state speed can thus be obtained as a function of Tem for a given value of Vt.

    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.

  • 8/16/2019 Speed Control of a Permanent Magnet Dc Motor Using a Dsp

    16/76

    16

    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

    CONTROLOFADJUSTABLESPEEDDRIVES

    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

  • 8/16/2019 Speed Control of a Permanent Magnet Dc Motor Using a Dsp

    17/76

    17

    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 stateoperating point.

    Δvt = Δea + R aΔia + La (Δia) 

    Δea = k E ΔmΔTem = k T Δia 

    ΔTem = ΔTWL + B Δm + J( )  Taking the laplace transforms of these equations;

    Vt(s) = Ea(s) + (R a + sLa)Ia(s)

    Ea(s) = k Em(s)Tem(s) = k TIa(s)

    Tem(s) = TWL(S) + (B + sJ) m(s)

  • 8/16/2019 Speed Control of a Permanent Magnet Dc Motor Using a Dsp

    18/76

    18

    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 V t(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;

    G2(s) =()()  = +(+)(+)+ 

    Vt(s) = 0

  • 8/16/2019 Speed Control of a Permanent Magnet Dc Motor Using a Dsp

    19/76

    19

    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) = (+)+ =   ( + +) But;

    ɾ m= = mechanical time constant.

    ɾ e=  = Electrical time constant.Using ɾ m  and ɾ e  in the expression for G1(s);

    G1(s)=   (ɾɾ++) In general, 

    ɾ m >>

    ɾ e , it is thus reasonable approximation to replace s

    ɾ m   by s(

    ɾ m  +

    ɾ e ). Therefore;

    G1(s) =()()   =   (ɾ+)(ɾ+) 

    2.2 DC –  DC BUCK CONVERTERS

    DC-DC converters are used to convert unregulated dc input voltage to a controlled dc outputvoltage 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.

  • 8/16/2019 Speed Control of a Permanent Magnet Dc Motor Using a Dsp

    20/76

    20

     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.  Step-down (buck) converter

    ii. 

    Step-up (boost) converter

    iii.  Step-down/step-up converter (buck-boost) converter

    iv.  Cuk converter

    v. 

    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.

  • 8/16/2019 Speed Control of a Permanent Magnet Dc Motor Using a Dsp

    21/76

    21

     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, V o

    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

       

  • 8/16/2019 Speed Control of a Permanent Magnet Dc Motor Using a Dsp

    22/76

    22

    =      

    =  Varying the duty ratio, D thus, controls the output voltage Vo.The circuit of figure 8 above has two drawbacks:

    i.  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.

    ii.  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 voltagefluctuations. The corner frequency of the low pass filter is chosen to much lower than the

    switching frequency f s, 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.

  • 8/16/2019 Speed Control of a Permanent Magnet Dc Motor Using a Dsp

    23/76

    23

    The average inductor current is equal to the average output current Io, since the average capacitor

    current in steady state is zero.

    CONTINUOUSCONDUCTIONMODE

    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 i L. When the switch is turned off, the inductive energy causes i L 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;

  • 8/16/2019 Speed Control of a Permanent Magnet Dc Motor Using a Dsp

    24/76

    24

    ∫   = ∫ ∫ = 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.

    THETRANSFERFUNCTIONOFABUCKCONVERTER

    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 v L and current i L, in

    time and frequency domain:

     = L

     

    () = () The expressions about the relationship between the capacitor voltage, vo and its current, ic are:

     = C  () = () 

  • 8/16/2019 Speed Control of a Permanent Magnet Dc Motor Using a Dsp

    25/76

    25

    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 i L ̂, 

    vo ̂ , vin

     ̂and

    d  ̂

     are the small signal variations of 〈〉, 〈〉, 〈〉 and respectively, we have;〈〉 = I  〈〉 = Vo  〈〉 = V     ̂ = D ̂   (4) and,i L ̂

  • 8/16/2019 Speed Control of a Permanent Magnet Dc Motor Using a Dsp

    26/76

    26

    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() = ()V  ()Cs() = () ()   } -------- (6)Therefore,

  • 8/16/2019 Speed Control of a Permanent Magnet Dc Motor Using a Dsp

    27/76

    27

    () = ()() | 

    = 0 =  V1 L C s  LsR  

    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

  • 8/16/2019 Speed Control of a Permanent Magnet Dc Motor Using a Dsp

    28/76

    28

    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 optimizedfor the operational needs of digital signal processing.

    The goal of DSPs is usually to measure, filter and/or compress continuous real-world analogsignals. 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 consumptionconstraints. 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.

  • 8/16/2019 Speed Control of a Permanent Magnet Dc Motor Using a Dsp

    29/76

    29

    The DSPs have the following advantages when used as controllers over the other controllers:

    1.  Low cost

    2.  High performance

    3.  Flexibility of quick design modifications

    4. 

    Implementation of more control schemes5.  Less susceptible to aging, environmental variations & have better noise immunity.

  • 8/16/2019 Speed Control of a Permanent Magnet Dc Motor Using a Dsp

    30/76

    30

    CHAPTER THREE: DESIGNThis 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 inter-

    operated to complete the project:

     Figure 3.1. A flow chart showing different components used in the project

  • 8/16/2019 Speed Control of a Permanent Magnet Dc Motor Using a Dsp

    31/76

    31

    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 F2802xPiccolo 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

    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

    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

  • 8/16/2019 Speed Control of a Permanent Magnet Dc Motor Using a Dsp

    32/76

    32

    o  One SCI (UART) Module

    o  One SPI Module

    o  One Inter-Integrated-Circuit (I2C) Bus

      Enhanced Control Peripherals

    o  Enhanced Pulse Width Modulator (ePWM)

    High-Resolution PWM (HRPWM) Moduleo  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.

  • 8/16/2019 Speed Control of a Permanent Magnet Dc Motor Using a Dsp

    33/76

    33

     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 thedc motor.

  • 8/16/2019 Speed Control of a Permanent Magnet Dc Motor Using a Dsp

    34/76

    34

    3.4 PERMANENT MAGNET DC MOTOR

    The motor used has the following properties:

    La = 6.6mH

    R a = 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  

  • 8/16/2019 Speed Control of a Permanent Magnet Dc Motor Using a Dsp

    35/76

    35

    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 LOWvoltage 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

  • 8/16/2019 Speed Control of a Permanent Magnet Dc Motor Using a Dsp

    36/76

    36

    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 correspondinglyhigh 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:

  • 8/16/2019 Speed Control of a Permanent Magnet Dc Motor Using a Dsp

    37/76

    37

    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) =()()   =   (ɾ+)(ɾ+) 

    K E =  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 K E.

    Thus, K E = 0.038533

  • 8/16/2019 Speed Control of a Permanent Magnet Dc Motor Using a Dsp

    38/76

    38

    Torque was calculated from the values in table 1 at different values of speed as;

    T =  

    K t = = 0.3681

     

    0.3681 is the average value calculated from the table.

    The motor inertial moment is given as;

    Jm =  

    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 =∗..  = 0.0125 kg_m2

    ɾ =  =

      .∗

      = 0.00055 = 5.5∗10− 

    ɾ =    = 12 ∗ 0.0125 0.3681∗0.038533 = 10.5753 Thus G1(s) =

    .(∗.+)(.∗+) 

    .(.

    +.+) 

    =   .+.+. =   .+.+. The buck converter transfer function is given by;

  • 8/16/2019 Speed Control of a Permanent Magnet Dc Motor Using a Dsp

    39/76

    39

    () = ()() | 

    = 0 =  V1 L C s  LsR  

    Vin is chosen as 40V.

    Thus, () =   +.∗  = .+. The motor_converter (plant) transfer function G(s) =   .+.+. ∗   .+. 

    =.+.+.+. 

    () =   324385454.5  3636.7 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:

  • 8/16/2019 Speed Control of a Permanent Magnet Dc Motor Using a Dsp

    40/76

    40

    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 =

  • 8/16/2019 Speed Control of a Permanent Magnet Dc Motor Using a Dsp

    41/76

    41

    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. = 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);

  • 8/16/2019 Speed Control of a Permanent Magnet Dc Motor Using a Dsp

    42/76

    42

    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:

  • 8/16/2019 Speed Control of a Permanent Magnet Dc Motor Using a Dsp

    43/76

    43

  • 8/16/2019 Speed Control of a Permanent Magnet Dc Motor Using a Dsp

    44/76

    44

    Figure 3. 9 Step response of the compensated system 

  • 8/16/2019 Speed Control of a Permanent Magnet Dc Motor Using a Dsp

    45/76

    45

    CHAPTER FOUR: SIMULATIONSimulation 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:

  • 8/16/2019 Speed Control of a Permanent Magnet Dc Motor Using a Dsp

    46/76

    46

    Figure 4 2 Closed Loop Simulation 

    The results of the open loop simulation and the closed loop simulation are recorded in chapter 5.

  • 8/16/2019 Speed Control of a Permanent Magnet Dc Motor Using a Dsp

    47/76

    47

    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 R a, K t and K v respectively.

    A graph of Va/Vo against Vo was plotted as shown below:

    Figure 5 1 Graph of V a /V o against V a 

    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:

  • 8/16/2019 Speed Control of a Permanent Magnet Dc Motor Using a Dsp

    48/76

    48

    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

  • 8/16/2019 Speed Control of a Permanent Magnet Dc Motor Using a Dsp

    49/76

    49

    5.3 CLOSED LOOP SIMULATION

    Table 3. Closed loop simulation

    5.4 GATE DRIVE SIMULATION RESULTS

    Figure 5 3 Gate Drive Practical waveforms 

  • 8/16/2019 Speed Control of a Permanent Magnet Dc Motor Using a Dsp

    50/76

    50

    PRACTICAL RESULTS

    The open loop practical results were as follows:

    Table 4. Practical Results

    DUTY CYCLE ARMATURE VOLTAGE SPEED IN RPM0.1 2.32 22

    0.5 13.67 370

    0.9 27.00 740

  • 8/16/2019 Speed Control of a Permanent Magnet Dc Motor Using a Dsp

    51/76

    51

    CHAPTER SIX: CONCLUSION AND RECOMMENDATIONS

    6.1 CONCLUSIONSThe 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.

  • 8/16/2019 Speed Control of a Permanent Magnet Dc Motor Using a Dsp

    52/76

    52

    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 

    http://www.ti.com/http://www.ti.com/http://www.analogdevices.com/http://www.analogdevices.com/http://www.mathworks.com/controltutorialshttp://www.mathworks.com/controltutorialshttp://www.mathworks.com/controltutorialshttp://www.analogdevices.com/http://www.ti.com/

  • 8/16/2019 Speed Control of a Permanent Magnet Dc Motor Using a Dsp

    53/76

    53

    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

  • 8/16/2019 Speed Control of a Permanent Magnet Dc Motor Using a Dsp

    54/76

    54

    // "{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"

  • 8/16/2019 Speed Control of a Permanent Magnet Dc Motor Using a Dsp

    55/76

    55

    #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

  • 8/16/2019 Speed Control of a Permanent Magnet Dc Motor Using a Dsp

    56/76

    56

    // 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

  • 8/16/2019 Speed Control of a Permanent Magnet Dc Motor Using a Dsp

    57/76

    57

    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 TrigSel[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};

    int 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,

  • 8/16/2019 Speed Control of a Permanent Magnet Dc Motor Using a Dsp

    58/76

    58

    };

    // ---------------------------------- 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

  • 8/16/2019 Speed Control of a Permanent Magnet Dc Motor Using a Dsp

    59/76

    59

    //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    %%%%%%%%%%%%%%%%%%%%%%%%

    // -------------------------------- 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; // common use incrementer

    Uint32 HistPtr, temp_Scratch; // Temp here means Temporary

  • 8/16/2019 Speed Control of a Permanent Magnet Dc Motor Using a Dsp

    60/76

    60

    //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    %%%%%%%%%%%%%%%%%%%%%%%%

    // 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.

  • 8/16/2019 Speed Control of a Permanent Magnet Dc Motor Using a Dsp

    61/76

    61

    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

  • 8/16/2019 Speed Control of a Permanent Magnet Dc Motor Using a Dsp

    62/76

    62

    //===============================================================================

    // 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;

  • 8/16/2019 Speed Control of a Permanent Magnet Dc Motor Using a Dsp

    63/76

    63

    // 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,

  • 8/16/2019 Speed Control of a Permanent Magnet Dc Motor Using a Dsp

    64/76

    64

    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

  • 8/16/2019 Speed Control of a Permanent Magnet Dc Motor Using a Dsp

    65/76

    65

    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

  • 8/16/2019 Speed Control of a Permanent Magnet Dc Motor Using a Dsp

    66/76

    66

    // 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;

  • 8/16/2019 Speed Control of a Permanent Magnet Dc Motor Using a Dsp

    67/76

    67

    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

  • 8/16/2019 Speed Control of a Permanent Magnet Dc Motor Using a Dsp

    68/76

    68

    //Also Set the appropriate # define's in the {ProjectName}-Settings.h

    //to enable interrupt management in the ISR

    ;EALLOW;

    PieVectTable.EPWM1_INT = &DPL_ISR; // Map Interrupt

    PieCtrlRegs.PIEIER3.bit.INTx1 = 1; // PIE level enable, Grp3 / Int1

    EPwm1Regs.ETSEL.bit.INTSEL = ET_CTR_PRD; // INT on PRD event

    EPwm1Regs.ETSEL.bit.INTEN = 1; // Enable INT

    EPwm1Regs.ETPS.bit.INTPRD = ET_1ST; // 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

  • 8/16/2019 Speed Control of a Permanent Magnet Dc Motor Using a Dsp

    69/76

    69

    //=================================================================================

    // 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

  • 8/16/2019 Speed Control of a Permanent Magnet Dc Motor Using a Dsp

    70/76

    70

    //-----------------------------------------------------------

    (*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

    //=================================================================================

  • 8/16/2019 Speed Control of a Permanent Magnet Dc Motor Using a Dsp

    71/76

    71

    //--------------------------------------------------------

    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;

  • 8/16/2019 Speed Control of a Permanent Magnet Dc Motor Using a Dsp

    72/76

    72

    //-----------------

    }

    //----------------------------------------------------------

    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;

    //-----------------

    }

  • 8/16/2019 Speed Control of a Permanent Magnet Dc Motor Using a Dsp

    73/76

    73

    //----------------------------------------

    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;

    //-----------------

    }

  • 8/16/2019 Speed Control of a Permanent Magnet Dc Motor Using a Dsp

    74/76

    74

    //----------------------------------------

    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;

    //-----------------

    }

  • 8/16/2019 Speed Control of a Permanent Magnet Dc Motor Using a Dsp

    75/76

    75

    //----------------------------------------

    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

    //-----------------------------------------

    {

  • 8/16/2019 Speed Control of a Permanent Magnet Dc Motor Using a Dsp

    76/76

    //-----------------

    //the next time CpuTimer2 'counter' reaches Period value go to C1

    C_Task_Ptr = &C1;

    //-----------------

    }