View
223
Download
0
Category
Preview:
Citation preview
i
UNIVERSITY OF NAIROBI
SCHOOL OF ENGINEERING
DEPARTMENT OF ELECTRICAL AND INFORMATION
ENGINEERING
PROJECT NUMBER: 148
INDUSTRIAL NICKEL CADMIUM BATTERY CHARGER
AUTHOR: RITAH KOKI MAKAU
REG NO.: F17/39625/2011
SUPERVISOR: Mr. SAYYID AHMED
EXAMINER: Dr. KAMUCHA
This project report was submitted in partial fulfillment of the requirements of
the award of the degree of Bachelor of Science in ELECTRICAL AND
ELECTRONICS ENGINEERING at the University of Nairobi.
Submitted on:
Supervisor Signature:
ii
Declaration of Originality
NAME OF STUDENT: RITAH KOKI MAKAU
REGISTRATION NUMBER: F17/39625/2011
COLLEGE: Architecture and Engineering
FACULTY/SCHOOL/INSTITUTE: Engineering
DEPARTMENT: Electrical and Information Engineering
COURSE NAME: Bachelor of Science in Electrical and Information Engineering
TITLE OF WORK: INDUSTRIAL NICKEL CADMIUM BATTERY CHARGER
DECLARATION
1. I understand what Plagiarism is and I am aware of the University‟s policy in this
regard
2. I declare that this assignment is my original work and has not been submitted
elsewhere for examination, award of a degree or publication. Where other people‟s
work, or my own work has been used, this has properly been acknowledged and
referenced in accordance with the University of Nairobi‟s requirements.
3. I have not sought or used the services of any professional agencies to produce this
work
4. I have not allowed, and shall not allow anyone to copy my work with the intention
of passing it off as his/her own work
5. I understand that any false claim in respect of this work shall result in disciplinary
action, in accordance with University Plagiarism Policy.
Signature:
Date:
iii
DEDICATION
I dedicate this project to my entire family: my dad David Makau, my mom
Joyce Makau and my siblings Will Makau, Sam Makau and Daniel Makau.
iv
ACKNOWLEDGEMENT
The success and final outcome of this project required a lot of guidance
and assistance from many people and I am extremely fortunate to have got this all
along the completion of my project work For this far I have come it‟s only through
God‟s grace, love, attention, and unending care. Therefore, my special thanks go to
God for giving me the strength and knowledge to complete this project.
Without the love and support of my family, I wouldn‟t have come this far,
but thanks to each and every member of my family; I am able to do my final year
project. My supervisor Mr. Ahmed Sayyid has been guiding me since the onset of
this project until now that it has been documented. I am extending lots of gratitude to
him for such a noble act that he has done. I would also wish to thank all my
classmates who encouraged me and helped me in research and encouraged me
throughout the entire project duration.
I am thankful and fortunate enough to get constant encouragement, support
and guidance from all teaching staff of the department of Electrical Engineering
which helped me in successfully completing my project work. Also I would like to
extend my sincere gratitude to the non-teaching staff of the department of Electrical
Engineering for their timely support.
v
ABSTRACT
This project is about the design and construction of an industrial nickel cadmium
battery charger (NiCad) that includes an end of charge detection circuit. The charger
uses a buck dc-dc converter topology to step down the input dc voltage to a lower
output dc voltage specified for the series arrangement of the NiCad cells. The
converter also provides a constant output current for charging the NiCad battery
cells. The type of charging method used is fast charge, the batteries need to be
charged and be ready for use as fast as possible.
Fast charge involves applying the battery‟s full charging current or capacity for a
shorter period of time. The charging circuit also involves a feedback loop circuit with
a DSP (Digital Signal Processor) TMS320 F28027 for control and end of charge
detection. The DSP control keeps the output current of the charger constant by
varying the duty cycle of the buck converter MOSFET switch using a PWM signal
whenever a variation in the output dc current is detected. The DSP also detects the
end of charge of the Ni-Cd cells by detecting a negative voltage gradient.
vi
LIST OF ABBREVIATIONS
CCM Continuous Conduction Mode
CMC Current Mode Control
DCM Discontinuous Conduction Mode
DSP Digital Signal Processor
EMI Electromagnetic Interference
IDE Integrated Development Environment
KCL Kirchhoff‟s Current Law
KVL Kirchhoff‟s Voltage Law
LED Light Emitting Diode
MOSFET Metal-Oxide-Semiconductor Field-Effect Transistor
NiCad Nickel Cadmium
PCB Printed Circuit Board
PI Proportional Integral
PD Proportional Derivative
PID Proportional Integral Derivative
PSIM Power Simulator
PWM Pulse Width Modulation
SMPS Switched Mode Power Supply
vii
TABLE OF CONTENTS
CHAPTER 1: INTRODUCTION ................................................................................ 1
1.1 Background information ................................................................................ 1
1.2 Project objectives ........................................................................................... 1
CHAPTER 2: LITERATURE REVIEW ..................................................................... 2
2.1 History ........................................................................................................... 2
2.2 Nickel-Cadmium charging basics .................................................................. 2
Slow charging ......................................................................................... 3 2.2.1
Fast charging .......................................................................................... 4 2.2.2
2.3 Disadvantages of fast charging ...................................................................... 5
2.4 Detecting end of charge ................................................................................. 5
Basic charger .......................................................................................... 5 2.4.1
Elapsed time / timer................................................................................ 6 2.4.2
Temperature rise ..................................................................................... 6 2.4.3
Voltage signature.................................................................................... 7 2.4.4
2.5 Discharging .................................................................................................... 8
NiCad High Current Discharge .............................................................. 8 2.5.1
NiCad over Discharge ............................................................................ 8 2.5.2
NiCad Discharge Characteristics ........................................................... 9 2.5.3
2.6 Dc-dc converter ........................................................................................... 10
Introduction .......................................................................................... 10 2.6.1
Types of dc-dc converters .................................................................... 11 2.6.2
2.7 Principles of Steady-State Converter Analysis ............................................ 13
2.8 Principle of Inductor-Volt Second Balance, capacitor charge balance, and
the small-ripple approximation ............................................................................... 15
viii
2.9 Ac equivalent circuit modelling .................................................................. 23
2.10 Buck Converter Transfer Function .............................................................. 25
2.11 Input voltage to output voltage transfer function and input voltage to
inductor current transfer function ........................................................................... 27
2.12 Buck converter transfer function ................................................................. 29
2.13 Buck converter controller design ................................................................. 30
2.14 Compensator design .................................................................................... 31
Lead (PD) Compensator ....................................................................... 31 2.14.1
LAG (PI) Compensator ........................................................................ 32 2.14.2
LAG-LEAD (PID) Compensator ......................................................... 33 2.14.3
2.15 Buck-Converter efficiency analysis............................................................. 33
Power Dissipation in the Inductor ........................................................ 34 2.15.1
Power Dissipation in the MOSFET ...................................................... 34 2.15.2
Diode Losses ........................................................................................ 35 2.15.3
Capacitor Losses .................................................................................. 35 2.15.4
2.16 Loop Compensation Design ........................................................................ 35
CHAPTER 3: METHODOLOGY ............................................................................. 39
3.1 Buck Converter Design ............................................................................... 39
Inductor value ....................................................................................... 40 3.1.1
Capacitor value ..................................................................................... 40 3.1.2
Diode selection ..................................................................................... 41 3.1.3
Control to output current transfer function .......................................... 41 3.1.4
3.2 PSIM open loop circuit design .................................................................... 42
3.3 Compensator design .................................................................................... 43
3.4 PSIM closed loop circuit design .................................................................. 44
3.5 Digital Control Design ................................................................................ 46
ix
3.6 Digital control loop circuit .......................................................................... 47
3.7 Switch gate driver design ............................................................................ 48
CHAPTER 4: PRACTICAL IMPLEMENTATION AND RESULTS...................... 50
4.1 SIMULATION RESULTS .......................................................................... 50
Open loop simulated results ................................................................. 50 4.1.1
Closed loop simulated results ............................................................... 51 4.1.2
CHAPTER 5: PRACTICAL IMPLEMENTATION.................................................. 52
5.1 Gate Driver Circuit (Optocoupler) .............................................................. 52
CHAPTER 6: DISCUSSION ..................................................................................... 56
CHAPTER 7: CONCLUSION AND FUTURE REFERENCE ................................. 57
7.1 Conclusion ................................................................................................... 57
7.2 Future works ................................................................................................ 57
LIST OF FIGURES
Figure 2-1: Charging characteristics of a NiCad cell. .................................................. 7
Figure 2-2: discharge characteristics ............................................................................ 9
Figure 2-3: Basic Regulator Block Diagram .............................................................. 10
Figure 2-4: boost type converter ................................................................................ 12
Figure 2-5: buck-boost converter ............................................................................... 12
Figure 2-6: buck type converter ................................................................................. 13
Figure 2-7: Ideal component used to reduce the dc voltage component .................... 14
Figure 2-8: Ideal switch output voltage waveform .......................................... 14
Figure 2-9: Insertion of low-pass filter ...................................................................... 15
Figure 2-10: Buck Converter circuit while the switch is in position 1 ...................... 16
Figure 2-11: inductor current waveform during converter turn-on transients ........... 19
Figure 2-12: Capacitor Current and Voltage Waveforms .......................................... 20
Figure 2-13: a simple dc-dc regulator system: buck converter and feedback network
.................................................................................................................................... 23
Figure 2-14: transistor gate drive signal ..................................................................... 24
x
Figure 2-15: Resulting converter output voltage waveform ...................................... 24
Figure 2-16: Spectrum of the output voltage waveform ............................................ 24
Figure 2-17: Open-loop Buck converter and its typical waveform in CCM a) the
circuit, b) inductor current .......................................................................................... 25
Figure 2-18: Circuit averaged model of the open-loop Buck converter .................... 26
Figure 2-19: The small-signal equivalent circuit model ............................................ 28
Figure 2-20: MOSFET Current Waveform ................................................................ 34
Figure 2-21: Buck converter with feedback ............................................................... 36
Figure 2-22: simplified system diagram .................................................................... 36
Figure 2-23: LAUNCHXL-F28027 Board Overview ................................................ 38
Figure 3-1: uncompensated bode plot of Giod(s)....................................................... 42
Figure 3-2: buck converter open loop design ............................................................. 42
Figure 3-3: Matlab SISOTOOL ................................................................................. 43
Figure 3-4: bode plot for PI controller, Gc(s) ............................................................ 44
Figure 3-5: closed loop circuit design on PSIM ......................................................... 45
Figure 3-6: bode plot for Hs ....................................................................................... 46
Figure 3-7: Discrete conversion ................................................................................. 47
Figure 3-8: Digital buck converter control circuit in PSIM ....................................... 48
Figure 3-9: gate drive circuit ...................................................................................... 49
Figure 4-1: Inductance Vs Frequency ........................................................................ 50
Figure 4-2: input voltage waveform ........................................................................... 50
Figure 4-3: Output Voltage Waveform ...................................................................... 51
Figure 4-4: Output Voltage Waveform ...................................................................... 51
Figure 5-1: Gate Drive Circuit ................................................................................... 52
Figure 5-2: input and output waveforms. ................................................................... 53
Figure 5-3: buck converter schematic ........................................................................ 54
Figure 5-4: gate drive schematic ................................................................................ 54
Figure 5-5 NiCad Battery Charger ............................................................................. 55
xi
LIST OF TABLES
Table 2-1: Salient Features of the Buck, Boost & Buck-Boost Converters ............... 29
Table 3-1: Design specification.................................................................................. 39
Table 5-1: Results....................................................................................................... 55
Table 7-1: Design components ................................................................................... 58
CHAPTER 1: INTRODUCTION
1.1 Background information
Charging is the process of restoring a discharged battery to its original
capacity. The battery charger will be used to charge NiCad (nickel cadmium) battery
cells. The battery charger will be able to increase the efficiency of the NiCad battery
cells by extending the lifespan of the batteries, preventing overcharging and
preventing current leakage.
The charger consists of the switched mode regulator, which is preferred
instead of linear regulator because of its high efficiency, low power dissipation and
high power density. The simplest and most common switched mode voltage regulator
which will be used is the buck DC/DC converter.
1.2 Project objectives
The aim of this project is to design and implement a digitally controlled
NiCad battery charger using a switched mode voltage regulator.
2
CHAPTER 2: LITERATURE REVIEW
2.1 History
The first Nickel-Cadmium battery was invented over 100 years ago in
1899 by a Swedish inventor named Waldemar Jungner. In 1906, Jungner established
a factory close to Oskarshamn, Sweden to produce flooded design NiCad batteries. It
was commercialized first at the beginning of 1960 in the USA, up to this point, the
batteries were "pocket type," constructed of nickel plated steel pockets
containing nickel and cadmium active materials. Others began producing them in
large quantities in 1963 and 1964.
Batteries for industrial use have an open label, but most of those for
general consumer use are a sealed label type to eliminate any concern about leaks. To
put the sealed battery to practical use, it was necessary to find a way of preventing
the battery from increasing inner pressure and exploding due to hydrogen and oxygen
gases generated when discharging, oxygen at the positive electrode and hydrogen at
the negative one. In the late 1940s, ideas proposed by a Frenchman named Neumann
resulted in technological improvements, such as creating a larger negative electrode
to suppress the amount of hydrogen gas produced and to increase the efficiency of
oxygen absorption that enabled the commercialization of the sealed battery.
2.2 Nickel-Cadmium charging basics
NiCad batteries are amongst the hardest batteries to charge. Whereas with
lithium ion and lead acid batteries you can control overcharge by just setting a
maximum charge voltage, the nickel based batteries don't have a "float charge"
voltage. So the charging is based on forcing current through the battery. The voltage
to do this is not fixed in stone like it is for the other batteries. This makes these cells
and batteries especially difficult to charge in parallel. This is because you can't be
sure that each cell or pack is the same impedance (or resistance), and so some will
take more current than others even when they are full. This means that you need to
use a separate charging circuit for each string in a parallel pack, or balance the
3
current in some other way, for example by using resistors of such a resistance that it
will dominate the current control.
The two ways to charge NiCad cells include slow charging and fast
charging.
Slow charging 2.2.1
Slow charge is usually defined as a charging current that can be applied to
the battery indefinitely without damaging the cell, also referred to as trickle charging.
Slow charging is usually done at a C/10 rate, which refers to the capacity of the cells
(in mAh), divided by 10 (hours). The nickel-cadmium battery can be trickle charged
but floating and constant voltage charging are not recommended. For maximum
performance in situations of long term trickle charge current required to keep the
battery fully charged is approximately the 30-50 hour rate plus whatever is necessary
to compensate for any major withdrawals. The maximum rate of trickle charging
which is safe for a given cell type is dependent on both the battery chemistry and cell
construction. When the cell is fully charged, continued charging causes gas to form
within the cell. All of the gas formed must be able to recombine internally, or
pressure will build up within the cell eventually leading to gas release through
opening of the internal vent which reduces the life of the cell.
This means that the maximum safe trickle charge rate is dependent on
battery chemistry, but also on the construction of the internal electrodes. This has
been improved in newer cells, allowing higher rates of trickle charging. The big
advantage of slow charging is that it is the charge rate that requires no end-of-charge
detection circuitry, since it cannot damage the battery regardless of how long it is
used. This means the charger is simple and very cheap. The big disadvantage of slow
charge is that it takes a long time to recharge the battery, which is a negative
marketing feature for a consumer product.
It can be difficult to determine exactly when you have fully charged a
NiCad cell. Often, the cell is overcharged, slow charging is done at about 1/10th to
1/50 C. C is the capacity of the cell in amp-hour. This charge rate is maintained for
12-14 hours for a "dead" cell and at the end of this period, you may expect it to be
4
fully charged. Because charging a cell isn't 100% efficient, you must put in
approximately 120-140% of the energy into the cell (hence the 12-14 hours part) of
its capacity rating when "slow" charging it. It is recommended by several battery
manufacturers that when doing a "slow" charge that the charge be terminated after
120% of the cell's capacity has been input by the charge cycle. After the 120%-140%
of energy has been inputted to the cell, it is recommended that the charge current
cease to avoid overcharging particularly if the cell already had a charge.
Fast charging 2.2.2
A fast charge applies a constant current of 1C or higher. Fast charge cycle
require that the charge current terminate when the battery becomes fully charged.
During a fast charge cycle, a constant current is applied to the battery while allowing
the battery voltage to rise to the level required (within limits) to force this current. As
the battery accepts charge, the battery voltage and temperature slowly rise. As the
battery approaches full charge, the voltage rises faster, reaches a peak, then begins to
drop (–ΔV); at the same time, the battery temperature begins to quickly rise (ΔT/ ).
Most fast or quick charge termination methods use one or both of these conditions to
end the charge cycle. Fast charging improves charge efficiency. At 1C, the efficiency
is 1.1 or 91 percent and the charge time of an empty pack is slightly longer than one
hour. On a 0.1C charge, the efficiency drops to 1.4 or 71 percent and the charge time
is about 14 hours. On a partially charged battery or one that cannot hold full capacity,
the charge time is shorter accordingly.
In the initial 70 percent of charge, the charge acceptance of a NiCad
battery is close to 100 percent. Almost all energy is absorbed and the battery remains
cool. Currents of several times the C-rating can be applied without causing heat
build-up. Ultra-fast chargers use this phenomenon to charge a battery to the 70
percent level within minutes. The charge continues at a lower rate until fully charged.
Past 70 percent, the battery gradually loses the ability to accept charge. The pressure
rises and the temperature increases. In an attempt to gain a few extra capacity points,
some chargers allow a short period of overcharge. Figure 2.1 illustrates the
5
relationship of cell voltage, pressure and temperature while a NiCad is being
charged.
2.3 Disadvantages of fast charging
NiCad battery present a user hazard if they are fast charged for an
excessive length of time. When the battery reaches full charge, the energy being
supplied to the battery is no longer being consumed in the charge reaction, and must
be dissipated as heat within the cell. This results in a very sharp increase in both cell
temperature and internal pressure if high current charging is continued. The cell
contains a pressure-activated vent which should open if the pressure gets too great,
allowing the release of gas. In the case of NiCad, the gas released is oxygen. A
severely overcharged cell can explode if the vent fails to open due to deterioration
with age or corrosion from chemical leakage. For this reason, batteries should never
be overcharged until venting occurs.
2.4 Detecting end of charge
Whether slow or fast charging is used, it is necessary to ensure that any
NiCad cells are not overcharged. It is therefore necessary to be able to detect end of
charge. There are a number of methods of achieving this.
Basic charger 2.4.1
Some of the very basic NiCad chargers that can be bought simply apply a
charge of around C/10. They do not include a timer and assume that the user will
remove the charging when the cell is charged. This mode is not at all satisfactory as
cells will be overcharged if the user forgets and will suffer damage as a result. Also
there is no way of knowing the exact charge state before charging begins.
6
Elapsed time / timer 2.4.2
Some of the most basic chargers assume that cells will require a full charge
and knowing their capacity, they can be given a charge for a given amount of time.
This is a simple and straightforward method of charging NiCad cells and batteries.
One of the main drawbacks of this form of end of charge termination is that it
assumes that the batteries are all fully discharged before they are recharged. To
ensure that batteries are suitable discharged, the charger may place item through a
discharge cycle. This is not a particularly accurate method of recharging batteries and
cells because the amount of charge they can hold changes over their useful lifetime.
However it is better than no form of charge termination.
Temperature rise 2.4.3
The technique used to detect when the fast charge should finish is that of
temperature sensing. The problem with this is that this is inaccurate because the core
of the cell will be at a much higher temperature than the periphery. For normal
charge rates the temperature rise rate may be insufficient to accurately detect.
Typically a temperature of 50°C is used as the cut-off temperature. Although a short
period over the a temperature of 45°C can be acceptable if the temperature is able to
fall quickly, any prolonged period at or above this causes the cell to deteriorate. More
comprehensive chargers using more advanced techniques have been made available
for fast chargers. Based around microprocessor technology they are able to detect the
rate of change of temperature. Typically charge termination occurs when a rate of
temperature increase of 1°C per minute is reached or an ultimate pre-determined
temperature (often between 50°C and 60°C) is reached. Detection of the temperature
increase rate is important because it determines when the cell is fully charged and
energy entering the cell is not being converted into stored energy by lost as heat.
One of the drawbacks of this method is that NiCad cells or batteries reinserted into a
temperature sensing charger, which is likely to be a fast charger can apply a harmful
overcharge if the battery is reinserted without being fully discharged as in the case of
someone wanting to make sure the battery has been charged.
7
Voltage signature 2.4.4
Voltage signature NiCad chargers use the voltage signature of the nickel
cadmium cell to determine where it is within its charge cycle. It is found that when a
NiCad battery is fully charged, there is a small drop in the terminal voltage.
Microprocessor based chargers are able to monitor the voltage and detect the full
charge point when they will terminate the charging process. This form of NiCad
charge termination is often called negative delta voltage. It provides the best
performance with fast charging because the negative delta voltage point is more
obvious when used with fast charging.
Figure 2-1: Charging characteristics of a NiCad cell.
8
2.5 Discharging
NiCad High Current Discharge 2.5.1
High rate Nickel Cadmium cells will deliver exceedingly high currents. If
the cells are discharged continuously under short circuit conditions, self-heating may
do irreparable damage. The heat problems vary somewhat from one cell type to
another, but in most cases internal metal strip tab connectors overheat or the
electrolyte boils. In some instances, both events occur. General overheating is
normally easy to prevent because the surface temperature of the battery can be used
to determine when to rest, for cooling, is required. In terms of cutoff temperature
during discharge, it is acceptable practice to keep the battery always below 60oC.
NiCad over Discharge 2.5.2
When cells are connected in series and discharged completely, small cell
capacity differences will cause one cell to reach complete discharge sooner than the
remainder. The cell, which reaches full discharge first, might be driven into reverse
by the others. When this happens in an ordinary nickel-cadmium sealed cell, oxygen
will evolve at the cadmium electrode and hydrogen at the nickel electrode. Gas
pressure will increase as long as current is driven through the cell and eventually it
will vent. This condition is minimized in some sealed nickel-cadmium cells by
special construction features. One technique uses a reducible material in the positive
in addition to the nickel hydroxide, to suppress hydrogen evolution when the positive
expires. Discharging to the point of reversal should be avoided.
9
Figure 2-2: discharge characteristics
NiCad Discharge Characteristics 2.5.3
The purpose of every voltage regulator is to convert a given dc or ac input
voltage into a specific stable dc output voltage and maintain that voltage over a wide
range of load conditions. To accomplish this, a typical voltage regulator consists of:
1. A reference element that provides a known stable level, ( ).
2. A sampling element to sample output voltage level.
3. A comparator element for comparing the output voltage sample to the
reference and creating an error signal.
4. A control element to provide translation of the input voltage to the
desired output level over varying load conditions as indicated by the error signal.
10
Figure 2-3: Basic Regulator Block Diagram
The voltage regulator consists of the linear regulator and switched mode
regulator. The charger for the NiCad battery uses the switched mode regulator.
2.6 Dc-dc converter
Introduction 2.6.1
The switch mode regulator is the circuit that provides voltage regulation.
The basis of switch mode regulator revolves around the ability of inductors and
capacitors to store energy. Electronic switched mode dc-dc converters convert one dc
voltage level to another, by storing the input energy temporarily and then releasing
that energy to the output at a different voltage. The storage may be in either magnetic
field storage components (inductors, transformers) or electric field storage
components (capacitors). This conversion method is more power efficient (often 75%
to 98%) than linear voltage regulation, which dissipates unwanted power as heat.
Fast rise/fall times are required for efficiency; however, these fast edges combine
with layout parasitic effects to make circuit design challenging. The higher efficiency
of a switched-mode converter increases the running time of battery operated devices
and also reduces the amount of heat sink material needed.
Switching regulators use power semiconductor switches in the „ON‟ and
„OFF‟ states. This is because little power is lost in those states, low voltage across a
switch in the on state and zero current through a switch in the off state. Hence,
switching regulators are able to achieve high energy conversion efficiencies. The
11
modern power electronic switches are capable of operating at high frequencies. As
the operating frequency increases, the transformers, capacitors, and filter inductors
becomes smaller and lighter. Moreover, the changing characteristics of dc-dc
converters improve with increase in operating frequencies. The corner frequency of
the output filter usually determines the bandwidth of the control loop.
Dc-dc converters are used for the following reasons;
1. To step down the voltage from a high voltage source to a lower voltage,
2. To match the loads to the power supply,
3. To isolate the primary and secondary circuits
4. To provide isolation between the input source and the load
5. To protect the supplied system and the input source from electromagnetic
interference.
6. To satisfy various national and international safety standards
Types of dc-dc converters 2.6.2
There are three basic types of dc-dc converter circuits, termed as buck,
boost and buck-boost. In all of these circuits, a power device is used as a switch.
Boost converter
A boost converter (step-up converter) has an output voltage greater than its
input voltage. It is a class of switched-mode power supply containing at least two
semiconductors (a diode and a transistor) and at least one energy storage element,
a capacitor, inductor, or the two in combination. Filters made of capacitors
(sometimes in combination with inductors) are normally added to the output of the
converter to reduce output voltage ripple.
12
Figure 2-4: boost type converter
Buck-boost converter
The buck–boost converter has an output voltage magnitude that is either
greater than or less than the input voltage magnitude. It operates in such a way that
while in the On-state, the input voltage source is directly connected to the inductor.
This results in accumulating energy in the inductor. In this stage, the capacitor
supplies energy to the output load. While in the Off-state, the inductor is connected
to the output load and capacitor, so energy is transferred from the inductor to the
conductor and resistor.
Figure 2-5: buck-boost converter
Buck converter
The Buck Converter is used in switched- mode power supply (SMPS)
circuits where the dc output voltage needs to be lower than the dc input voltage. The
dc input can be derived from rectified ac or from any dc supply. It is useful where
13
electrical isolation is not needed between the switching circuit and the output, but
where the input is from a rectified ac source, isolation between the ac source and the
rectifier could be provided by a mains isolating transformer.
The switching transistor between the input and output of the Buck
Converter continually switches “ON” and “OFF” at high frequency. To maintain a
continuous output, the circuit uses the energy stored in the inductor L, during the ON
periods of the switching transistor to continue supplying the load during the off
periods. The buck converter is used to distribute power in complex systems, e.g.
server motherboards, broadband communication boards, etc.
Figure 2-6: buck type converter
2.7 Principles of Steady-State Converter Analysis
The figure below shows the basic configuration of a buck converter where
the switch is integrated in the selected integrated circuit (IC). When switch S1 closes,
current flows through the inductor and into the load, charging the inductor by
increasing its magnetic field and increasing . When reaches the desired
value, we open S1 and close S2. Current continues to flow in the inductor as the
magnetic field collapses and the inductor discharges. Before the inductor completely
discharges, we open S2 and close S1 and the cycle repeats. We can adjust the ratio of
to by varying the duty cycle of S1. The longer S1 is turned on, the greater
14
will be. The duty cycle of S1 is usually called the converter‟s duty cycle. If the
switches and the inductor are lossless, Vg is converted to with no loss of power
and the conversion is 100% efficient.
The switch produces a rectangular waveform as illustrated in the figure 2-8
below. The voltage is equal to the dc input voltage when the switch is in
position 1, and is equal to zero when the switch is in position 2. The switch is
realized using power semiconductor devices, such as transistors and diodes, which
are controlled to turn on and off as required to perform the function of the ideal
switch. The switching frequency equal to the inverse of the switching period
generally lies in the range of 1 kHz to 1 MHz, depending on the switching speed of
the semiconductor devices. The duty ratio is the fraction of time that the switch
spends in position 1, and is a number between zero and one. The complement of the
duty ratio is defined as (1 – ).
Figure 2-7: Ideal component used to reduce the dc voltage component
Figure 2-8: Ideal switch output voltage waveform
15
The output voltage is a function of the input line voltage , duty
cycle d(t) and the load current . So the average value, or dc component, of
is equal to the duty cycle times the dc input voltage . The switch reduces the
dc voltage by a factor of . The converter in figure 2-9 is realized using lossless
components. The inductor, capacitor, and switch do not dissipate power. When the
switch is closed, its voltage drop is zero, and the current is zero when the switch is
open. In either case, the power dissipated by the switch is zero. Hence, efficiencies
approaching 100% can be obtained.
Figure 2-9: Insertion of low-pass filter
The low-pass filter is inserted in order to remove the switching harmonics
and pass only the dc component to the output. The network also allows control
of the output; the buck converter has a linear control characteristic. The output
voltage is less than or equal to the input voltage. Feedback systems are constructed so
as to adjust the duty cycle to regulate the converter output voltage.
2.8 Principle of Inductor-Volt Second Balance, capacitor charge
balance, and the small-ripple approximation
It is impossible to build a perfect low-pass filter that allows the dc
component to pass but completely removes the components at the switching
16
frequency and its harmonics. So the low-pass filter must allow at least some small
amount of the high-frequency harmonics generated by the switch to reach the output.
In practice the output voltage waveform appears as illustrated in Figure 2-10,
and can be expressed as shown in equation 2.1, the actual output voltage
consists of the desired dc component , plus a small undesired ac component arising
from the incomplete attenuation of the switching harmonics by the low-pass filter.
The output voltage switching ripple should be small. The magnitude of the
switching ripple is much smaller than the dc component.
|| || >>
The output voltage is approximated by its dc component V, with the
small ripple term (t) neglected.
=
The inductor current can be found my integrating the inductor voltage
waveform. Consider Figure 2-10 below;
Figure 2-10: Buck Converter circuit while the switch is in position 1
17
When the switch is in position 1, the left side of the inductor is connected
to , the inductor voltage (t) will be given by
The output voltage consists of the dc component plus a small ac
ripple value (t) as illustrated in equation 2.1. We replace the output voltage
by its dc component .
The inductor current can be found by the following equation;
=
The current through the inductor, is made up of the average current
which is equal to the load current, and the ripple current which is the change in
current as the switches are opened and closed. The peak to peak ripple current is
usually set to be about 30% to 40% of the load current at the start of the design and it
is related to the voltage across the inductor by the expression in equation (2.6) above.
∫
When the inductor is charging, is the voltage across the inductor,
- and is the time that S1 is closed. When the inductor is discharging,
18
is simply and is the time S2 is closed. is same for the two cases, when
S1 is closed and when S2 is closed.
( )
This equation is solved for the ratio of v(t) to
The following process happens when the converter is first switched on;
It is assumed that the inductor current and the output voltage are initially zero
An input is applied
When the switch is ON, the inductor current increases with a gradient of
but is initially zero.
When the switch goes OFF, the inductor current changes with a gradient of
and since is initially zero, this gradient is essentially zero.
The inductance value is proportional to the time that S1 is ON implying
that it‟s inversely proportional to the switching frequency. And it‟s inversely
proportional to the ripple current which implies that it‟s inversely proportional to the
load current. So as the switching frequency and load current increases, less
inductance is needed. Considering what happens to the inductor current when the
converter is first turned on, suppose that the inductor current and output voltage are
initially zero, and an input voltage is then applied as shown in Figure 2-11 below.
19
Figure 2-11: inductor current waveform during converter turn-on
transients
The inductor current ripple, , as shown in figure 2-11 plus the dc
component I give the peak inductor current. This peak current also flows through the
semiconductor devices in the circuit of the buck converter. Hence with knowledge of
this current, it is possible to determine our inductor rating. From figure 2-8, the
change in current, is equal to the slope times the length of the first sub-interval
of the current waveform, . Since is the peak-to-average ripple, we have the
peak-to-peak ripple to be .
We may write this as:
Solving for , current ripple, we have:
(
)
(
)
20
We take the value of IL as between 10% and 20% of the full load value of
the dc component, I. If it is too large, peak currents for our components would
necessitate the need for larger components and thus consequently increase costs.
From the small-ripple approximation, . We can therefore select our inductor
value for a desired output current ripple using equation (2.13)
(
)
The buck converter output has a 2-pole low pass filter coupled to it in
which case the small-ripple approximation predicts zero output voltage ripple
regardless of the output filter capacitance. There is only one component of the
capacitor current and which is due to the inductor current ripple. Therefore, ignoring
this inductor current ripple is not possible. To solve this, we analyze the capacitor
current waveform more accurately and by doing so, the voltage ripple can be related
to the current waveform.
Figure 2-12: Capacitor Current and Voltage Waveforms
21
From Figure 2-12, we observe a dc component I and a linear ripple
component . The dc component flows through the load entirely but divides to
the load and the output filter capacitance. For a well-designed buck converter, the
capacitor provides significant filtering of the ripple current by ensuring its impedance
at the switching frequency is much lower than the load impedance. This ensures that
most of the inductor current ripple flows through the filter capacitor. We know have
that the capacitor current waveform in Figure 2-12 is similar to the inductor current
waveform in 2-8 with a peak ripple current, .
During the positive cycle, charge is deposited on the capacitor plates
causing voltage to increase. We note that the capacitor voltage changes from its
minimum to maximum at the zero-crossings of the current waveform. The peak-to-
peak output voltage ripple is . We may relate this voltage ripple to the total
charge contained in the positive cycle of the current waveform. We know from first
principles that . Hence we may write:
)
Where is the area of the shaded triangle with a height . The zero-
crossings occur at and . Therefore, the base length of the triangle is given by
. We thus express the total charge, q, as:
(
Solving for in equation (2.16), we get the formula for capacitance as:
22
From this we are able to determine the value of our desired capacitance to
obtain a given voltage ripple in the buck converter design. We must however select a
capacitor with low equivalent series resistance to avoid increasing the voltage
The defining equation of a capacitor is;
Integration of this equation over one switching period yields;
∫
In steady state, the net change over one switching period of the capacitor
voltage must be zero, so that the left-hand side of equation (2.19) is equal to zero.
Therefore, in equilibrium the integral of the capacitor current over one switching
period should be zero. There is no net change in capacitor charge in steady state. An
equivalent statement is
∫
The average value, or dc component of the capacitor current must be zero
in equilibrium. If a dc current is applied to a capacitor, then the capacitor will charge
continually and its voltage will increase without bound. Likewise, if a dc voltage is
applied to an inductor, then the flux will increase continually and the inductor current
will increase without bound. Equation (2.20), called the principle of capacitor amp-
second balance or capacitor charge balance, can be used to find the steady-state
currents in a switching converter.
23
2.9 Ac equivalent circuit modelling
Converter systems require feedback. In a typical dc–dc converter
application, the output voltage must be kept constant, regardless of changes in
the input voltage, or in the effective load resistance . This is accomplished by
building a circuit that varies the converter control input which is the duty cycle
in such a way that the output voltage is regulated to be equal to a desired
reference value .A typical dc–dc system incorporating a buck converter and
feedback loop block diagram is illustrated in Figure 2-13
Figure 2-13: a simple dc-dc regulator system: buck converter and feedback
network
Suppose that some ac variation is introduced into the converter duty cycle
d(t), such that
and are constants, , and the modulation frequency is
much smaller than the converter switching frequency, . The resulting transistor
gate drive signal is illustrated in Figure 2-13, and a typical converter output voltage
waveform is illustrated in Figure 2-14. The spectrum of is illustrated in
Figure 2-15 this spectrum contains components at the switching frequency as well as
its harmonics and sidebands; these components are small in magnitude if the
switching ripple is small. In addition, the spectrum contains a low-frequency
24
component at the modulation frequency. The magnitude and phase of this component
depend duty cycle variation and on the frequency response of the converter
Figure 2-14: transistor gate drive signal
Figure 2-15: Resulting converter output voltage waveform
Figure 2-16: Spectrum of the output voltage waveform
25
2.10 Buck Converter Transfer Function
Figure 2-17: Open-loop Buck converter and its typical waveform in
CCM a) the circuit, b) inductor current
According to the circuit averaging technique, the switch S can be modeled
to be a current dependent source of current and diode D modeled to be a voltage
dependent voltage source in the Continuous Conduction Mode (CCM) operation,
26
Where, < >, < >, < >, and < > are average value of , , , and
respectively. Thus, the circuit averaged model of the Buck converter can be
obtained and shown in Figure 2-18 below:
Figure 2-18: Circuit averaged model of the open-loop Buck converter
Assume that , V0, Vin, and D are the DC values of < >,< 𝑂>,< 𝑛>, and
d, respectively , , and are the small AC variations of < >,< 𝑂>,< 𝑛>, and
d, respectively. Then < >,< >,< 𝑛>, and d can be represented by the
corresponding DC values plus the superimposed small AC variations, with the
assumption that the AC variations are small in magnitude compared to the steady
state values, i.e.,
27
With
2.11 Input voltage to output voltage transfer function and input
voltage to inductor current transfer function
The transfer function from the input voltage to the output voltage of the
open-loop Buck converter in CCM operation is essential in determining the close-
loop audio susceptibility in both current and voltage mode controls. The transfer
function from the input voltage to the inductor current is important for determining
the closed loop audio-susceptibility in current model control. All the above transfer
functions can be derived from the corresponding small-signal equivalent circuit
model in Figure 2-19, which is obtained by taking the perturbation of the duty cycle
equal to zero.
28
Figure 2-19: The small-signal equivalent circuit model
Based on Kirchhoff‟s current and voltage laws, the following equations
can be obtained from Figure 2-19,
Since the transfer function from the input voltage to the output voltage
expresses the effect of the input voltage changes on the output voltage when only the
input voltage works, which implies that the perturbation of the duty cycle is equal to
zero. Therefore,
29
2.12 Buck converter transfer function
For our buck converter, we require a transfer function to understand the
relationship between the output and input characteristics of the converter as a
measure of efficiency and stability and to be able to design a proper controller to
achieve the levels of stability as desired in the design process. For this, we invoke the
line-to-output transfer function and the control-to-output transfer functions of the
buck converter.
CONVERTER G
BUCK
√ √
BOOST
√ √
BUCK-BOOST
√ √
Table 2-1: Salient Features of the Buck, Boost & Buck-Boost
Converters
These salient features of the three ideal converters are defined in the
control-to-output transfer function as of the form
(
)
(
(
)
)
We also have the same salient features applying to the line-to-output
transfer function as of the form
From the equations above the boost and buck-boost converters exhibit
control-to-output transfer functions containing two poles and a right half-plane zero.
30
The buck converter exhibits two poles but no zero. The line-to-output transfer
functions of all three ideal converters contain two poles and no zeroes.
2.13 Buck converter controller design
A typical dc regulator is designed using the following specifications:
1. The effect of load current variations on the output voltage
regulation. The output voltage must remain within a specified range
when the load current varies in a prescribed way. If over some
frequency range, the open-loop output impedance, Zout(s), has a
magnitude that exceeds the limit, then the loop gain T must be
sufficiently large in magnitude over the same frequency range such
that the magnitude of the closed loop output impedance is less than
the given limit.
2. The effect of input voltage variations on the output voltage
regulation. The output voltage ripple can be reduced by increasing
the magnitude of the loop gain at the ripple frequency.
3. The transient response time. When a specified large disturbance
occurs, such as a large step change in load current or input voltage,
the output voltage may undergo a transient. During this transient,
the output voltage typically deviates from its specified allowable
range. Eventually, the feedback loop operates to return the output
voltage within tolerance. The time required to do so is the transient
response time. Typically, the response time can be shortened by
increasing the feedback loop crossover frequency.
4. Overshoot and ringing. The amount of overshoot and ringing
allowed in the transient response may be limited. Such a
specification implies that the phase margin must be sufficiently
large. Each of these requirements imposes constraints on the loop
31
gain T(s). Therefore, the design of the control system involves
modifying the loop gain. A compensator network is added for this
purpose.
2.14 Compensator design
Lead (PD) Compensator 2.14.1
This is a compensator whose transfer function is used to improve the phase
margin. A zero is added to the loop gain, at a frequency far below the crossover
frequency such that the phase margin of T(s) is increased by the specified amount.
It‟s also called a proportional-plus-derivative (PD) controller. At high frequencies,
the zero causes the compensator to differentiate the error signal. It often finds
application in systems originally containing a two-pole response. Using this type of
compensator, the bandwidth of the feedback loop extended while maintaining an
acceptable phase margin.
However, the additional zero causes the compensator gain to increase with
frequency. Since the gain of any practical amplifier must tend to zero at high
frequency, the compensator transfer function must contain high frequency poles.
These poles have the beneficial effect of attenuating high-frequency noise. Of
particular concern are the switching frequency harmonics present in the output
voltage and feedback signals. If the compensator gain at the switching frequency is
too high, then these switching harmonics are amplified by the compensator, and can
disrupt the operation of the pulse-width modulator. The compensator network should
therefore contain poles at a frequency less than the switching frequency. These
factors restrict the crossover frequency to be less than approximately 10% of the
converter switching frequency. The design must not exceed the gain-bandwidth
limits of available operational amplifiers. The transfer function of the lead
compensator therefore contains a low-frequency zero and several high-frequency
poles. To illustrate this, we may consider a simple PD controller with a single high
frequency pole. The transfer function is as given by equation below;
32
√
However, the above equation is less than unity and therefore the lead
compensator will reduce the dc gain of the system.
LAG (PI) Compensator 2.14.2
A lag compensator helps to increase low frequency loop gain. This means
that the output is better regulated at dc frequencies and frequencies lower than the
loop crossover frequency. This is achieved by adding an inverted zero to the system
at a frequency . When is lower than , the phase margin remains unchanged.
The inverted zero causes the compensator to integrate the error signal. We define the
proportional-plus-integral equation as given below:
(
)
If we make the compensator gain to be too large, the dc loop gain also
becomes arbitrarily large causing the dc component of the error signal to tend to zero.
The steady state output voltage is perfectly regulated and the disturbance-to-output
transfer functions approach zero at dc. This can be realized by using an operational
amplifier.
Equation 2.40 is used to obtain a compensated gain.
33
The high frequency gain of the compensator, , is chosen to obtain the
desired crossover frequency . The PI compensator helps in rejection of unwanted
components at the output.
LAG-LEAD (PID) Compensator 2.14.3
We are able to combine the lag and lead compensators to obtain a wide
bandwidth and improve steady state error. At low frequencies, we have large low
frequency loop gain and accurate regulation of low-frequency components of the
output voltage. At high frequency, we have improved phase margin. We may
illustrate an example of a PID controller using equation as shown below.
(
) (
)
(
) (
)
The inverted zero at frequency functions in the same manner as the PI
compensator. The zero at frequency adds phase lead in the vicinity of the
crossover frequency, as in the PD compensator. The high frequency poles at
frequencies and must be present in practical compensators to cause the gain
to roll off at high frequencies and to prevent the switching ripple from disrupting the
operation of the pulse width modulator.
2.15 Buck-Converter efficiency analysis
We require a more general method of determining efficiency of our buck
converter under different operating conditions other than those already specified. We
may categorize the main sources of losses in a DC-DC buck converter as:
Inductor conduction losses
MOSFET losses
Diode losses
Capacitor losses
34
Power Dissipation in the Inductor 2.15.1
Figures 2-11 and 2-12 show us the steady state inductor voltage and
current waveforms, respectively. From these waveforms, we may find the inductor
conduction loss is given by
Power Dissipation in the MOSFET 2.15.2
Figure 2-20: MOSFET Current Waveform
Error! Reference source not found.20 gives the MOSFET current
aveform and allows us to see that the power dissipated in the MOSFET is given by
(
)
We find that the ripple current is less than 30% of the output current and
the contribution of
can therefore be neglected. Equation 2-44 thus becomes
35
Diode Losses 2.15.3
We estimate the current through the diode as
Using equation 2-46, we can find the power dissipation in the diode as the
product of the diode forward voltage and the load current.
Capacitor Losses 2.15.4
Estimated power dissipation in the capacitor can be found using the
effective series resistance of the specific capacitor.
Total power dissipation, , can be calculated as the sum of
. MOSFET switching losses and quiescent current
losses constitute the other losses. We therefore find that if both the total power
supply losses and output power are known, the overall efficiency of our buck
converter can be calculated from:
2.16 Loop Compensation Design
Figure 2-21 is a block diagram of the system components of a buck
converter with feedback. The converter power stage accepts as its power source
and the control input to produce the output voltage . The feedback sensor
, monitors the converter output voltage which is then compared with a reference
36
voltage . The difference output of these two voltages is provided to the feedback
compensation circuit and then to the pulse width modulator (PWM) which
produces the control waveform for the switching converter . The resulting loop
gain is thus given by
(2.50)
Figure 2-21: Buck converter with feedback
Figure 2-22: simplified system diagram
37
2.17 LAUNCHXL-F28027 Overview (Instruments, Texas, 2012)
Overview 2.17.1
The C2000™ Piccolo™ LaunchPad™, LAUNCHXL-F28027, is a
complete low-cost experimenter board for the Texas Instruments Piccolo F2802x
devices. The LAUNCHXL-F28027 kit features all the hardware and software
necessary to develop applications based on the F2802x microprocessor. The
LaunchPad is based on the superset F28027 device, and easily allows users to
migrate to lower cost F2802x devices once the design needs are known. It offers an
on-board JTAG emulation tool allowing direct interface to a PC for easy
programming, debugging, and evaluation. In addition to JTAG emulation, the USB
interface provides a UART serial connection from the F2802x device to the host PC.
Users can download an unrestricted version of Code Composer Studio™
IDE version 5 to write, download, and debug applications on the LAUNCHXL-
F28027 board. The debugger is unobtrusive, allowing the user to run an application
at full speed with hardware breakpoints and single stepping available while
consuming no extra hardware resources.
As shown in Figure, the LAUNCHXL-F28027 C2000 LaunchPad features
include: • USB debugging and programming interface via a high-speed galvanically
isolated XDS100v2 emulator featuring a USB/UART connection.
• Superset F28027 device that allows applications to easily migrate to
lower cost devices.
• Nibble (4-bit) wide LED display.
• Two push buttons for user feedback and device reset.
• Easily accessible device pins for debugging purposes or as sockets for
adding customized extension boards.
• Boot selection and USB and UART disconnect switches.
38
Figure 2-23: LAUNCHXL-F28027 Board Overview
Kit Contents 2.17.2
The LAUNCHXL-F28027 C2000 LaunchPad experimenter kit includes
the following items:
• C2000 LaunchPad Board (LAUNCHXL-F28027)
• Mini USB-B Cable, 0.5m
• Quick Start Guide
Revisions 2.17.3
The first production revision of the LAUNCHXL-F28027 C2000 Piccolo
LaunchPad, version 1.0, was released in July of 2012 and is currently the only
revision available.
Installation 2.17.4
The C2000 LaunchPad installation consists of three easy steps:
1. Download Code Composer Studio and controlSUITE™.
2. Install Code Composer Studio and controlSUITE.
3. Connect and install the C2000 LaunchPad to the PC.
Now the LaunchPad is ready to develop applications or run the pre-
programmed demo.
39
CHAPTER 3: METHODOLOGY
3.1 Buck Converter Design
There are 5 rechargeable NiCad battery cells each of 1.2V connected in
series to give a total voltage of 6V. The capacity of each battery cell is 2000mAh.
Input voltage,
Output voltage,
Load current,
Input current,
Output power,
Maximum current ripple, of
Maximum output voltage ripple, of
Switching Frequency,
Duty Cycle, D
Load, (Ohms)
Table 3-1: Design specification
From the table above, the power stage specifications of the buck converter
have been defined. Using these, we see the buck converter converts a 20V power
source to a 7.5V output at a load current of 1.2A and a switching frequency of 50
kHz. To do so in continuous conduction mode, we require designing the inductor and
output capacitors based on the power stage specifications. The maximum current
ripple will be limited to 20% of the load current. The maximum output voltage ripple
will be limited to 1% of the output voltage.
Input voltage, ,
Output voltage,
40
Maximum current ripple,
Maximum output voltage ripple,
Duty cycle,
Inductor value 3.1.1
The minimum value for the inductance can be obtained from the equation
below which is defined as:
(
) 𝑛
(
)
Capacitor value 3.1.2
41
Diode selection 3.1.3
A high frequency diode of 10A was selected because it would work well in
a switching frequency of 50 kHz
Control to output current transfer function 3.1.4
MATLAB was used to generate the bode plot of the function Giod(s). The
below instructions were entered into the command window and the bode plot was
generated.
>> s=tf('s');
>> Giod=((1.6*10^-4*(s+20000))/(3.129*10^-9*s^2+6.256*10^-5*s+1));
>> bode(Giod);
42
Figure 3-1: uncompensated bode plot of Giod(s)
3.2 PSIM open loop circuit design
Figure 3-2: buck converter open loop design
For;
43
From Figure 3-1, it can be seen that the open loop systems for the charging
current is stable with an infinite gain margin but the phase margins is 92 degrees
which is too high. It is therefore necessary to compensate the system to a desired
phase margin of about 45 degrees by adding a phase lag to improve the steady state
performance of the system. A compensator which can perform this function better is
Proportional + Integral (PI).
3.3 Compensator design
PI compensator design was done using MATLAB SISOTOOL for the
system of 1.2A charging current and used for the compensation of all the other
systems.
Figure 3-3: Matlab SISOTOOL
44
The designed PI compensator has the transfer function;
The following instructions were written in the matlab command window
and the bode plot of Gc(s) generated.
>> s=tf('s');
>> Gc=9099.1*((1+2*10^-5*s)/s);
>> bode(Gc);
Figure 3-4: bode plot for PI controller, Gc(s)
3.4 PSIM closed loop circuit design
After the PI compensator was successfully designed in MATLAB, a closed
loop system was then modeled in PSIM with the PI compensator in the feedback
control loop as shown in the figure below. was chosen to be a saw tooth wave of
1V peak to peak and a duty cycle of 1, and the current sensor with a gain of
45
Figure 3-5: closed loop circuit design on PSIM
The transfer function of the compensated closed loop system will be given
by;
Hence:
The Equation was ploted in MATLAB. The figure below shows the
resultant bode plot of :
>> Giod=((1.6*10^-4*(s+20000))/(3.129*10^-9*s^2+6.256*10^-5*s+1));
>> Gc=9099.1*((1+2*10^-5*s)/s);
>> Hs=Giod*Gc;
>> bode(Hs);
46
Figure 3-6: bode plot for Hs
From figure 3-6, it can be observed that the PI controller improved the
Phase Margins to 44.9 degrees. The compensated system has an infinite Gain
Margin.
3.5 Digital Control Design
For digital control of the buck converter, the PI controller transfer function
was transformed into discrete form using s2z converter, at a sampling frequency of
50 kHz using PSIM as shown below;
47
Figure 3-7: Discrete conversion
k1=0.182
k2=9100
The discrete PI compensator has the transfer function shown below;
3.6 Digital control loop circuit
The designed digital feedback control loop of the buck converter was
modeled and simulated as shown in the figure below;
48
Figure 3-8: Digital buck converter control circuit in PSIM
3.7 Switch gate driver design
Power IGBTs and MOSFETs are voltage driven switches because they
have an insulated gate which acts like a capacitor. There turn ON and turn OFF
waveforms exhibit a step which remains at a constant level while the drain voltage
rises or falls when they are switching. Gate driver IC or optocoupler is an electronic
device which transfers a voltage signal from one part of a circuit to another while
isolating the two circuits electrically from each other.
The switch gate driver selected was a PC 817, IGBT Gate Drive
optocoupler. PC 817 has a forward current, of 5mA and collector emitter voltage of
5V. This gate drive is ideally suited for driving power IGBTs and MOSFETs used in
motor control inverter applications. The PC 817 is also used in noise suppression
switching circuits. The high operating voltage range of the output stage provides the
drive voltages required by gate controlled devices. The voltage and current supplied
by this optocoupler make it ideally suited for directly driving IGBTs with ratings up
to 1200V/100 A. The circuit below was obtained from the PC 817 datasheet, showing
the circuit of the gate drive.
49
Figure 3-9: gate drive circuit
The gate driver circuit isolates the buck converter circuit from the digital
control circuit. R is the resistance protecting the photodiode and its value depends on
the maximum forward voltage and current of the photodiode and the value of the
input signal. Vcc was chosen to be 15V.
50
CHAPTER 4: PRACTICAL IMPLEMENTATION AND RESULTS
4.1 SIMULATION RESULTS
Inductor
The inductor was wound on an iron powder toroid with a copper wire to
the desired value of .
Figure 4-1: Inductance Vs Frequency
Open loop simulated results 4.1.1
Figure 4-2: input voltage waveform
51
Figure 4-3: Output Voltage Waveform
Closed loop simulated results 4.1.2
Figure 4-4: Output Voltage Waveform
52
CHAPTER 5: PRACTICAL IMPLEMENTATION
5.1 Gate Driver Circuit (Optocoupler)
PC817 optocoupler IC was chosen for the gate driver circuit because it is
inexpensive, reliable, and readily available. It has a CTR>20%, maximum forward
voltage of 1.5V and maximum forward current of 10mA, used was 15V
Therefore,
The PC817 circuit was connected on a breadboard with the DSP supplying
a PWM signal at the input and a digital oscilloscope at the output, to observe the
input and output waveforms.
Figure 5-1: Gate Drive Circuit
53
Figure 5-2: input and output waveforms.
In practical implementation of the open loop buck converter, an N-Channel
IRFZ44 MOSFET was chosen for simplicity of the gate drive circuit and low Rds
(on). Low Rds (on) leads to low switching losses. The diode used was UF540 high
frequency switching diode with a current rating of 10A. Its forward voltage drop is
0.4V. A 10uF, 50V electrolytic output capacitor was used with an ESR of 0.12Ohms.
It was chosen because it can handle the high frequency of 50 kHz. A 390uH iron
powder toroid inductor was designed.
5.2 NiCad Battery Charger
The battery charger was designed in WinQCad, a software for designing the circuit
including all the components required. Both the buck converter circuit and the gate
drive circuit were designed using WinQCad as shown below
54
Figure 5-3: buck converter schematic
Figure 5-4: gate drive schematic
55
The circuits were etched on a pcb board and the components soldered accordingly.
The final battery charger circuit appears as shown below;
Figure 5-5 NiCad Battery Charger
CALCULATED SIMULATED PRACTICAL
Output Current(A) 1.2 1.15 1.11
Output Voltage(V) 7.5 7.46 7.2
Table 5-1: Results
56
CHAPTER 6: DISCUSSION
The designed battery charger exhibited better performance with minimum
error evidenced by the results collected from simulation and part of practical
implementation. To prolong the life of Ni-Cd battery cells, a constant current should
be provided for a particular period of time and then withdrawn once the battery is
fully charged to prevent overcharging which damages most of batteries. In this
project, various scenarios that occur while charging NiCad batteries were put into
consideration and solved.
The issue of overcharging was eliminated by providing an end of charge
indicator which signals the user to disconnect the charger. The charger uses −∆
voltage end of charge detection method. The designed charger is able to withstand
variations that occur in voltages and currents due to faults, load changes and other
forms of disturbances and still continue to provide a constant charging current to the
battery. This stability was tested when the battery circuit was supplied by a pulsating
voltage and the result was still a constant current. Future users of this charger will
have numerous options for charging their batteries. The digital control loop
implemented by DSP provides efficient operation of the buck converter because it
has a very high frequency capability. This charger is also easy to design and
implement because it contains few number of components that are inexpensive.
57
CHAPTER 7: CONCLUSION AND FUTURE REFERENCE
7.1 Conclusion
The whole of the project lifespan concentrated in the design of a more
efficient dc-dc buck converter that would be used to charge NiCad battery cells. After
the design, a digital control circuit was incorporated using DSP for current
regulation. The charger was therefore, designed successfully meeting all
specification. However, the practical implementation presented some challenges in
the part of finding the appropriate gate drive circuit that would successfully drive the
MOSFET. Several options were visited like the HCPL 3120 gate drive circuit which
wasn‟t successful because
7.2 Future works
Recommendations for future work
The designed charger can be improved to be automatic so that when
the batteries are full, it automatically disconnects.
The charger can be designed with a wider variety of charge current
specifications, so it can be used with other types of batteries too like Li+
and LiPo.
A timing circuit can be included in the charger for backup in case the
negative gradient detection method fails to detect the end of charge correctly.
REFERENCES
1. Erickson, R. W. (n.d.). DC-DC Power Converters. Colorado.
2. Instruments, Texas. (2011). C28x Digital Power Library. Dallas, Texas: Texas
Instruments Incorporated.
3. Instruments, Texas. (2012, July). LAUNCHXL-F28027 C2000 Piccolo
LaunchPad Experimenter Kit. Dallas, Texas: Texas Instruments Incorporated.
4. Robert W. Erickson, D. M. (2004). Fundamentals of Power Electronics.
Newyork, Boston: Kluwer Academic Publishers.
58
5. SHARP. (n.d.). PC817X Series Datasheet. Retrieved from
www.farnell.com/datasheets/73758.pdf
6.
7. Texas Instruments. (2011). Battery Charging. Dallas, Texas: Texas Instruments
Incorporated.
8. Texas Instruments. (2015). Basic Calculation of a Buck Converter's Power Stage.
Dallas, Texas: Texas Instruments Incorporated.
9. Vishay Siliconix. (2011). Power MOSFET Datasheet. Retrieved from
http://www.vishay.com/docs/91291/91291.pdf
APPENDIX A: BILL OF QUANTITIES
COMPONENT TYPE QUANTITY COST
DSP Launchpad F28027 1 1650
Battery cells NiCad 1.2V, 2000mAh 5 2000
Diode High frequency diode, 20A 1 100
Current sensor ACS712 1 900
Voltage sensor 25V 1 500
Optocoupler PC817 1 100
Resistor 200R,150R, 6.8K, 110R, 270R 7 100
Capacitors 10Uf, 0.1Uf 2 100
PCB board 1 500
Bread board 1 250
Table 7-1: Design components
APPENDIX B: DSP module used
59
APPENDIX C: DSP schematic
APPENDIX D: Project Code: Main.c
//----------------------------------------------------------------------------------
// FILE: ProjectName-Main.C
//
// Description: Sample Template file to edit
// The file drives duty on PWM1A using C28x
// These can be deleted and modifed by the user
// C28x ISR is triggered by the PWM 1 interrupt
//
// Version: 2.0
//
// Target: TMS320F2802x(PiccoloA),
//
//----------------------------------------------------------------------------------
#include "ProjectName-Settings.h"
#include "PeripheralHeaderIncludes.h"
#include "DSP2802x_EPWM_defines.h"
60
#include "DPlib.h"
#include "IQmathLib.h"
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// FUNCTION PROTOTYPES
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// Add protoypes 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
// 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
61
void (*C_Task_Ptr)(void); // State pointer C branch
//----------------------------------------------------------------------------------
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// VARIABLE DECLARATIONS - GENERAL
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// -------------------------------- FRAMEWORK --------------------------------------
int16 VTimer0[4]; // Virtual Timers slaved off CPU Timer
0
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,
};
// ---------------------------------- 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;
// CONTROL_2P2Z - instance #1
extern volatile long *CNTL_2P2Z_Ref1;
62
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 Adc_Out;
volatile long Filter_Out;
long Ref , Fdbk , Out;
#pragma DATA_SECTION(CNTL_2P2Z_CoefStruct1, "CNTL_2P2Z_Coef");
struct CNTL_2P2Z_CoefStruct CNTL_2P2Z_CoefStruct1;
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// VARIABLE DECLARATIONS - CCS WatchWindow / GUI support
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// -------------------------------- 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")
// Variables for background support only (no need to access)
int16 i; // common use
incrementer
Uint32 HistPtr, temp_Scratch; // Temp here means Temporary
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// MAIN CODE - starts here
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
void main(void)
{
//========================================================================
=========
63
// INITIALISATION - General
//========================================================================
=========
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.
MemCopy(&RamfuncsLoadStart, &RamfuncsLoadEnd, &RamfuncsRunStart);
// Call Flash Initialization to setup flash waitstates
// This function must reside in RAM
999999999 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
//========================================================================
=======
// INITIALISATION - GUI connections
//========================================================================
=========
// Use this section only if you plan to "Instrument" your application using the
// Microsoft C# freeware GUI Template provided by TI
64
/*
//"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;
// 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;
65
// assign a GUI "getable" parameter array address
arrayGetList[0] = &DBUFF1; //only need to set initial position of array,
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 -----------------------------------------
//----------------------------------------------------------------------
#if (INCR_BUILD == 1) // Open Loop Two Phase Interleaved PFC PWM Driver
//----------------------------------------------------------------------
// Configure PWM1 for 200Khz (Period Count= 60Mhz/200Khz = 300)
PWM_1ch_CNF(1, 1200,1,0);
// Configure ADC to be triggered from EPWM1 Period event
//Map channel to ADC Pin
ChSel[0] = 14; // ADC B5
// 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
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;
66
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
// 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"
//----------------------------------------
// Connect the PWM Driver input to an input variable, Open Loop System
// ADCDRV_1ch block connections
ADCDRV_1ch_Rlt0=&Fdbk;
// Connect the CNTL_2P2Z block to the variables
CNTL_2P2Z_Fdbk1 = &Fdbk;
CNTL_2P2Z_Out1 = &Out;
CNTL_2P2Z_Ref1 = &Ref;
CNTL_2P2Z_Coef1 = &CNTL_2P2Z_CoefStruct1.b2;
// Initialize the Controller Coefficients
CNTL_2P2Z_CoefStruct1.b2 = _IQ26(0.05);
CNTL_2P2Z_CoefStruct1.b1 = _IQ26(-0.20);
CNTL_2P2Z_CoefStruct1.b0 = _IQ26(0.0008);
CNTL_2P2Z_CoefStruct1.a2 = _IQ26(0.0);
CNTL_2P2Z_CoefStruct1.a1 = _IQ26(1.0);
CNTL_2P2Z_CoefStruct1.max =_IQ24(0.7);
CNTL_2P2Z_CoefStruct1.min =_IQ24(0.0);
PWMDRV_1ch_Duty1 = &Out;
// Initialize the net variables
67
//Filter_Out =_IQ24(0.4);
//Initialize the net Variables/nodes
Ref=_IQ24(0.5);
//Fdbk=_IQ24(0.0);
//Out=_IQ24(0.0);
#endif // (INCR_BUILD == 1)
//========================================================================
============
// INTERRUPTS & ISR INITIALIZATION (best to run this section after other initialization)
//========================================================================
============
// Set up C28x Interrupt
//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
//========================================================================
=========
// STATE-MACHINE SEQUENCING AND SYNCRONIZATION
//========================================================================
=========
68
//--------------------------------- 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
//-----------------------------------------------------------
(*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
}
69
//========================================================================
=========
// A - TASKS
//========================================================================
=========
//--------------------------------------------------------
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;
//-----------------
}
//----------------------------------------------------------
void A4(void)
//---------------------------------------------------------
{
//-----------------
//the next time CpuTimer0 'counter' reaches Period value go to A1
A_Task_Ptr = &A1;
//-----------------
}
//========================================================================
=========
// B - TASKS
70
//========================================================================
=========
//----------------------------------- USER ----------------------------------------
//----------------------------------------
void B1(void)
//----------------------------------------
{
//-----------------
//the next time CpuTimer1 'counter' reaches Period value go to B2
B_Task_Ptr = &B2;
//-----------------
}
//----------------------------------------
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;
//-----------------
}
//----------------------------------------
void B4(void) // SPARE
//----------------------------------------
{
//-----------------
//the next time CpuTimer1 'counter' reaches Period value go to B1
B_Task_Ptr = &B1;
71
//-----------------
}
//========================================================================
=========
// C - TASKS
//========================================================================
=========
//--------------------------------- USER ------------------------------------------
//------------------------------------------------------
void C1(void)
//------------------------------------------------------
{
//-----------------
//the next time CpuTimer2 'counter' reaches Period value go to C2
C_Task_Ptr = &C2;
//-----------------
}
//----------------------------------------
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
//-----------------------------------------
{
//-----------------
//the next time CpuTimer2 'counter' reaches Period value go to C1
C_Task_Ptr = &C1;
//-----------------
}
72
Recommended