You are on page 1of 34

4/29/2016

EE-494


Group# 16A

Topic D: Portable USB Power


Supply

FINAL DESIGN REPORT


Group Members:
1.
2.
3.
4.
5.

Mohd Khan
Emran Nur
Naved Akhter
Boson Ruan
Jianfeng Sun

Contents

I.

Introduction .......................................................................................................................................... 3

II.

Project Design ................................................................................................................................. 3

III.

Progress Summary .......................................................................................................................... 7

A.

Circuit Design ................................................................................................................................. 7

B.

Circuit Simulation ......................................................................................................................... 13

C.

Prototype ....................................................................................................................................... 17

I.

Problems Encountered and the Solution ............................................................................................. 17

I.

Introduction

A DC power supply is typically used to power-up electronic circuits for testing and
diagnosis. The traditional DC power supply uses the AC power supplied by a wall outlet in order
to provide the user-desired DC voltage output. However, this AC input requirement makes testing
of electronic circuits on the go more difficult, where AC wall outlet is not readily available. The
ultimate goal of this project is to build a DC power supply that is powered by a typical USB 2.0
port found in commonly used devices such as laptops or any devices with USB slots. This USB
DC power supply will provide DC output according to user-defined parameters, thus, making
testing of electronic circuits on the go convenient for the user. Users will most certainly will be
able to take advantage of the portability of a DC power supply, which works as similar as the one
at an electronic lab.

II.

Project Design

The primary ideology behind a DC-to-DC booster is to convert DC voltage input to AC


voltage using an oscillator and then feed the AC to a step-up transformer to boost AC voltage and
finally convert the output from the transformer back to DC voltage. The prototype is built with the
intention to provide the user with output voltage ranging from -10V to +10V with a maximum
current limit of approximately 300mA from a USB 2.0 Type B supply.
The
DC-to-DC
booster IC possesses all the circuit blocks (for each step) that follow the aforementioned ideology
of a DC booster. Therefore, the ideal step was to use a booster IC rather than assembling the circuit
blocks using discreet components.
The following three alternative concepts were initially considered before finalizing on a single
design.

Concept 1: 555 timer based DC booster


Concept 2: DCP020503W, Unregulated DC/DC Converter Modules
Concept 3: LM2587 based DC booster
Table 1. represents the comparison for each concepts and the technical challenges behind each
concept.

*The terminologies USB 2.0 Type B and USB are used interchangeably.

Concept 1
Concept 1 was to use a 555 timer to convert DC voltage to AC voltage. The pin configuration
and the function of the circuit is given in Figure 1, 2 and 3

Fig. 1. 555 Timer Schematic.

Fig. 2. 555 Timer Design Concept Using Multisim.

Fig. 3. Transient Analysis of 555 Timer.

Pin 2 and 6 get triggered itself and capacitor C1 charges through R1+R2 and R4 gets discharged
and output a 5VAC V (p-p) output and connects with a step-up transformer to achieve 10V. After
observing unstable output voltage from circuit simulation using NI Multisim software it was
decided not further proceed with concept 1. Apart from maximum current supply of 50mA there
are lot of loss within the system. [3]

Concept 2
Two of DCP020XXP ICs will take the power input from USB 2.0 Type-B and produce a
dual unregulated output of positive and negative voltage. The layout of a DCP020XXP IC is PDIP
with a total of 7 Pins. The output was connected with two voltage regulator in order for the voltage
to evenly distributed and attain two isolated constant voltage. After the implementation and
multiply attempt of regulating the voltage using voltage regulator the isolated voltage came out to
be +5V and -5V. However the isolated voltage was not persistent.
The following steps describe the working of DCP020XXP IC: 1. An oscillator takes the DC voltage input and converts it to AC voltage of 800 kHz
frequency.
2. The output of the oscillator follows a divide by-2 block to produce 400 kHz AC
voltage.
3. A three-terminal transformer is connected with the power controller as well as two
diodes to convert the stepped-up AC voltage to unregulated DC voltage output.
Finally, there are three pins +VOUT, COM and VOUT that are connected with two
positive/negative voltage regulators. A positive voltage regulator is connected with +VOUT to

LM337 to get +10V. On the other hand, VOUT will be connected with the negative voltage
regulator LM317 to get -10V as the output of the power supply COM is common in both the
positive and negative output pins. Later on a combination of relays and IC switch will be
implemented to have controlled output values.

Concept 3
The gradual difference on the isolated voltage along with other technical challenges with the
previous concepts directed to choose concept 3. This concept is to use a flyback regulator, which
is not only designed to boost the output isolated voltage but also to adjust it at the same time [1].
LM2587 flyback regulator has a unique feature that perform as enhanced regulator than any other
boost or buck regulator in the market. Along with the flyback regulator there are six sub concepts
that were being implemented to reach the final goal. The main properties of this concept are
i.
ii.
iii.
iv.
v.

LM2587-flyback regulator
Single step-up Flyback transformer
Positive and negative voltage regulators
LCD display with MCU
Solid state relays for protection

Tables of Each Concepts


Concepts

Voltage

Regulation

Max.
Voltage

Peripherals

Drawbacks

More

Maximum current
output is only 50mA.
II. Poor loading effect
III. Complicated setup

555 timer based


DC booster
I.

15.00V

DCP020XXP IC
I.

10.00 V

More

II.

Unregulated voltage
Significant drop of
voltage when load is
attached

Negative
Feedback
Regulator

Maximum voltage
does not exceed 12.00
V using a single
flyback transformer.
However, voltage can
be further increased
using a series
transformer.

I.

12.00 V

Less

**NOTE: Minimum requirement is 10V

Table 1: Attempted Design Concept.

Please note that a test bench DC power supply in lab was initially used for testing the designs until
the final prototype is fully developed for the purposes of getting accurate measurement of the
voltage and current limit of a USB female port so as to prevent USB port damage while testing
prototype circuit. Moreover, it also provides a wide range of power than the actual USB to fully
test the circuit for overvoltage, overcurrent protection.

III.

Progress Summary

A USB 2.0 Type B connection from any portable device will provide a maximum of 5V at 500mA
(P = 4.5W MAX) to the USB based Power supply unit. The power supply unit produces two
isolated voltage outputs of 12.00 VDC. The voltage can be adjusted by the user using a precision
potentiometer connected to the positive and negative voltage regulators for a stable positive and
negative output. A microcontroller unit of ATMEL328U based Arduino is used to for user
interface and circuit protection of the PSU. Furthermore, two solid-state relays are used to provide
an interface between the microcontroller unit and the PSU circuit. Moreover, the MCU is used in
order to ensure the overall circuit protection and an operating circuit for the user to power
electronics circuits for the purposes of testing on the go.

A. Circuit Design
Power Supply to the Main Circuit Via USB Connection
Connection from any portable devices with USB 2.0 Type B port will attach to a simple circuit
board that consists of the following parts [2]

Parts Description
USB 2.0 type B connector
TO-220 Voltage Regulator (LM317
1.5A max current)
PTC Resettable Fuse
100uF 35V Capacitor
10uF 25V Capacitor
0.1uF 50V Capacitor
Power LED
SPDT Slide Switch
0.1" Header Pins
330 Resistor 1/6W
390 Resistor 1/6W
240 Resistor 1/6W
Bare PCB with Silkscreen Indicators

Quantity
1
1
1
1
1
1
1
1
4
2
2
2
1

This integrated circuit is capable of delivering 5V with 500mA to the flyback regulator. Not only
it is capable enough to supply the required voltage and current, but also it can protect its own
circuitry with a resettable fuse. Careful action towards soldering each component is taken in order
to affix components onto the PCB board.

Fig. 4. Design Layout

Flyback Regulator LM2587 and Single Flyback Transformer


LM2587 regulator is single handedly capable of supplying single or multiple isolated outputs
ranging from 4V to 40V including negative voltage in the same range. The regulator comes in
output range of 3.3V, 5.0V, 12V and adjust (ADJ). The regulator has an internal electrical
protection system that protects the chip under overcurrent, voltage lockout and thermal conditions.

As the minimum requirement for this project is to achieve 10V, choosing LM2587 is certainly
ideal both in terms of power boost, regulation and protection. Only a few components such as
capacitors, diodes and single flyback transformer are required to obtain desired output. A 5V
power is supplied to LM2587 at port 5 from the USB power module. The switch port (port 4) is
the output of LM2587 which generates AC signal that is later stepped-up using a flyback
transformer. Feedback (port 2) is used to continuously monitor the output voltage for a stable
output. A small portion of the output is fed back to the chip that uses a comparator to measure the
changes and adjust accordingly.
LM2587 contains a feature when pin 4 (switch) is energized, there is a flow of current being
supplied to the primary side of the transformer in order to create a strong electromagnetic energy.
The primary winding of transformer is energized when the switch is turned-on by the internal
circuity of flyback regulator. As a result, voltage is induced in secondary winding due to
electromagnetic induction. The stored energy in the secondary winding get discharged through
two rectifying forward biased diodes to have two isolated output of 12.00 VDC. In order to
receive output of two polarities, D1 of figure 5 from the secondary side of the transformer is in
positive polarity and D2 in figure 5 is in negative polarity [1]. This diode setup generates 180
degrees out of phase output. The equation below justifies the operation behind the switch and the
output results.

Vsw(off) = Vin (max) +

&

Here max input is Vin (5V), Max out Vout , Ratio of the transformer turns N and VF is the output
voltage for the forward biased diode.

The LM2587 converts the DC input to AC output at 100 KHz frequency. The switch of the
LM2587 is turned-on and turned-off at the rate of 100,000 times per second to generate AC signal.
The AC signal is fed through fly back transformer to step-up the AC signal by ratio of 1:2.5
(5.0*2.5 = 12.0 V). The external current limit of 5A is set as the maximum switch current of the
device. The frequency of the AC signal drop from 100 KHz to 25 kHz when the output voltage
from the transformer drops to 75% of maximum output. The switch turns on initially with zero
current at its switch port (pin-4). In this condition, the switch current limit will limit the peak
current, saving the device.

10

Fig. 5. Schematic of LM2587 voltage regulator.

The maximum power rating of a single Coilcraft Q4337-B flyback transformer is 3.6W. The
transformer is able to supply maximum of 12.0 V at 0.3 A (P = VI = 12.0*0.3). However, when
two transformers are connected in series, we obtained twice the voltage at half the current rating
following the same power rating of the device. Even though voltage from two transformers should
add up and produce 24V at 0.15 A, after the series connection of two Q4337-B the output voltage
came out to be 16.0V in the actual circuit. Figure 6 shows the schematic for two tap transformer

Fig. 6.Two-Tap Transformers.


Voltage Regulator
Maintaining a constant and regulated voltage from two isolated output and feed them to the next
state, two three terminal positive and negative voltage regulator LM317 and LM337 are being
used.
Two isolated voltage from the secondary side of the transformer get linked with two voltage
regulator LM317 and LM337, which supply constant and regulated output voltage. LM317 is for
the positive and Lm337 for the negative output voltage after the transformer connection end.

11

The circuit was designed to provide an adjustment with a power supply that is designed while
providing a voltage range of 1.25V to 30V. LM317 an adjustable 3-terminal positive voltage
regulator capable of supplying in excess of 1.5A over an output voltage range of 1.2V to 37V and
requires only two external resistors to set the output voltage due to its internal current limiting,
thermal shutdown and safe area compensation, constant current regulators and an adjustable power
supplies due to its features such as protected output from short circuit, product enhancement tested,
current limit constant with temperature, guaranteed thermal regulation, adjustable output down to
1.2V, guaranteed 5A, and guaranteed 7A peak output current.
The adjustment pin serves as a voltage adjustment reference for the output. This pin can be
attached to a resistor divider circuit to adjust to a user desired voltage level. The voltage dropout
for any regulator states the minimum allowable difference between output and input voltages. For
example, if a LM337 regulator is to provide 5V at its output, the input voltage must be no lower
than 5v +2.5V =7.5V. This reference voltage can also be adjusted to regulate the current and this
constant current flows through R2 from ground. Following equation comprises R1 and R2, where
R1 is fixed resistor value and R2 is used as adjustable resistance depending on the need of the
regulated value. The output that will be provided by the negative voltage regulator can be
calculated by the given formula.
A positive and negative voltage regulator is used to provide user-desired stable output. LM317
and LM337 consists of a 1.25 V voltage reference circuit. The output voltage is determined using
the ratio of R2 and R1 where R1 is fixed to 900ohms [4] [5].

= +. +

= . +

PSU Protection Unit using MCU


The microcontroller control unit is used to manage the protection unit of USB power supply
which is an integral part of the power supply unit used to monitor over-current and over-voltage
condition. A ATMEL328U based Arduino UNO is used to manage the circuit protection part of
the PSU circuit. A secondary INA219 based circuit is used to feed the voltage and current values
to the MCU. The INA219 based circuit has following four ports: - 1) VCC, 2) IN+, 3) IN- and 4)
GND. VCC and GND are used to power the INA219 chip. It can measure voltage up to 24V. IN+
also known as the high side that is used to feed the positive terminal of the circuit to the chip.
INA219 uses a sensitive resistor to measure the voltage difference and current. In other words, we
connect the circuit to the INA219 chip the same way we measure current in a circuit, INA+
connects to the positive terminal and INA- connects to the negative terminal of the PSU circuit.
INA219 communicates with the ATMEL328U via I2C bus. I2C bus communication is more
sophisticated than SPI interface and is also able to support more devices in its bus.

12

The INA219 chip monitors three values 1) bus voltage, 2) current and 3) shunt voltage.
These values are displayed in LCD and further used for overcurrent protection. The MCU
interfaces to the power supply unit circuit using a solid state relays. We used two solid state relays
for positive and negative terminal outputs. The user sets the maximum limit using the push buttons.
The maximum current limit is displayed on the LCD as part of the user interface. For current limit
protection, the circuit current is compared to the maximum current limit set by the user. The
INA219 chip is more reliable than a resettable fuse because it takes time for the fuse to cool down
and begin to normally operate again. Moreover, the user can monitor the actual voltage that is
outputted to the testing circuit.
Solid state relays are typically smaller, lighter and have faster response time than generic
relays that are larger and work based on electromagnetics. The relays are always set low and the
Vout is always set high. When a digital signal of max. 5v is applied i.e. high the Vout is LOW.
The MOSFET switch in solid-state relays is turned-off when input pin is set high. When the
MOSFET is in off-state it bypasses the voltage to and whereas when it is set low the MOSFET is
turned-on current takes the part of the least resistance which is towards Vout (testing circuit).
Figure 7 shows the block diagram of the digital display system. Source code of the MCU is
provided in Appendix B.

Fig. 7. Block Digram of the Digital Display.

13

Solid state relays are very imperative for small application like portable USB power supply.
G3VM-61A1/D1 series MOSFET relays comes with the features where they get to communicate
directly with the MCU and the operation condition comes very reliable for this particular power
supply. Two relays are connected in this project, where one is associated with positive regulator
and the other to the negative regulator. It consists of 4 pins, where pin 2 and 3 are connected
together to the ground and send signals to pin 4 for the safety operation. Pin 4 has two connections,
VDD which is connected directly from the voltage regulator and VOUT is the output terminal. Pin
1 is connected with INA219 by an MCU which will monitor the fault in the system. The MOSFET
inside this relay acts as a switch, when pin 1 reads low current the switch is on and it communicates
with pin 4 to the output. On the other hand, when pin 1 reads high current, the switch is off and
pin 4 will allow the current to bypass it to the ground. The schematic and the ON and OFF
operation of this specific relays is given in figure 8.

Figure.8 . On/Off Switch Solid-State Relay.

B. Circuit Simulation
Voltage regulator
The following figures illustrate positive and negative voltage regulation simulated circuits:

Fig.9 . LM 317 Circuit Design.

14

Fig. 10. LM 337 Circuit Design.


Fig.10 . LM 337 Circuit Design.

Analysis of Digital Potentiometer: The use of digital potentiometers was considered as an alternative means of adjusting voltage at
the output terminals with high precision. Digital potentiometers are controlled by MCU via digital
signals. For the analysis, a digital potentiometer of 10K-ohm with 128 steps are tested for exact
precision delivery. However, after careful analysis it is found that error associated with using
digital potentiometer is very high compared to using manual precision potentiometer that is
initially used. The analysis below is based on the data in Appendix C.
Given a voltage (x), the following formula is the output of the number of steps required to attain
the correct resistance in order to obtain the desired voltage illustrated in Appendix C.
= . . ;

Fig.11 . LM 337 Circuit Design.

15

The following graph illustrates the error associated on using digital potentiometer in potential
divider circuit.

Fig.12 . LM 337 Circuit Design.


Flyback Transformer
Figure 13 illustrates a two series connected transformer. In a series connected transformer the
primary windings are connected in parallel to power supply. T1s negative port is connected to the
positive port of T2 that are then connected to the ground. The positive port of secondary winding
of T1 is considered as positive terminal. Similarly, the negative terminal is negative port of T2.
Figure 13 and 14 shows the schematic for the transformer.

():
= .
:
= . + . =
=
, =

16

Fig. 13. Series Connected Transformer.

Fig. 14. Single Transformer.

17

C. Prototype
I. Problems Encountered and the Solution
Problem encountered

Solution

USB connection to the main circuit was not


successful in terms of safety

Series transformer did not meet the


requirements for the power and current
measurements.
Series transformer 1:10 ratio

Max current, =

XY

Adjust to single transformer 1:5 ratio


Max power, P= 12 * .3= 3.6W
Max current, =

Max power, P= 3.6W


V.W

Constructed a USB type B power supply


module with resettable fuse and a voltage
regulator to maintain stable power
throughout the entire system

V.W
]X

= .3

Single transformer delivers more


current (.3A) than transformer in series.

= .15

.15A is less than the desired requirement

Table. 2. Problems and Solution Encountered

II. Loading Effect


+V Output (V)

The figure beside illustrates loading


effect. In a power supply unit system
voltage output is not the same when
loads are attached. An analysis of
different load effects are carried out in
order to fully understand the loading
effect of PSU. At an unload of 290 ohms
we obtained 75% efficiency.

12
10

+Vout

8
6

0
0

10

15

Resistance value

20

25

18

D. Cost Analysis
Comparison between Distributors
Part Name

Mouser

Digi key

Other

LM2587

$ 4.4400 $ 4.4438

LM317

$ 0.0830 $ 0.0735

LM337

$ 0.2140 $ 0.2600

USB Type B Port

$ 0.3280 $ 0.1300

USB Type B Cable

$ 0.3770 $ 0.7044

Precision Potentiometer

$ 7.6300 $ 7.3073

Flyback Transformer

$ 0.6800

Diodes

$ 0.0090 $ 0.0055

Banana Jacks

$ 0.3250 $ 0.3125

Resistors

$ 0.0890 $ 0.0950

Capacitors

$ 0.0150 $ 0.0230

LCD Screen

$ 3.9800

Cost Analyses for Each Component


Part Name

Quantity

LM2587
LM317
LM337
USB Type B Port
USB Type B Cable
Precision Potentiometer
Flyback Transformer
Diodes
Banana Jacks
Resistors
Capacitors
LCD Screen

1
2
1
1
1
2
1
2
3
15
10
1

Total Cost

Unit Price
Total
$ 4.4400 $ 4.44
$ 0.0735 $ 0.15
$ 0.2140 $ 0.21
$ 0.1300 $ 0.13
$ 0.3770 $ 0.38
$ 7.3073 $ 14.61
$ 0.6800 $ 0.68
$ 0.0055 $ 0.01
$ 0.3125 $ 0.94
$ 0.0890 $ 1.34
$ 0.0150 $ 0.15
$ 3.9800 $ 3.98

$27.02

19

E. Project Requirements
Satisfied/Not
satisfied

Minimum Requirements
Adjustable voltage in 10mV

increments ranging from -10V
to +10V DC.
Adjustable current limit setting
for overcurrent protection in
10mA increments.
Fixed percentage overvoltage

protection (no more than 20%)
i.e. when the output voltage
goes above the specified value
by a certain percent, the output
is switched off.

Isolated voltage output
User interface that displays

voltage setting, voltage reading,
current setting, and current
reading.

Selectable on/off for voltage
output.
Output via banana connector
and/or screw terminal.
Cost per unit less than $5 (>1M
units).

Remarks
The output voltage is connected with a
precision potentiometer in order to have
10V DC in 10mV increments
Push buttons associated with MCU are
used to set maximum current limit for the
circuit being tested

(Pending)

Positive voltage regulator and Negative


voltage regulator
LCD screen
Two solid- state relays associated with
MCU

Banana connectors are used at the output


terminals.

Regulator IC, precision potentiometer and


flyback transformer are relatively
expensive

No damage to USB port or


power supply when too much
current is desired by load or
output terminals are shorted
together.

Efficiency above 75% under


load.

Size less than 5.5 in x 3.5 in x 3


in.

A USB module is a voltage regulator and


resettable fuse is used.

Loading effect
(Pending)

20

F. Circuit Testing Procedures


The following procedures are carried out in order to verify if the main requirements of the
project are successfully met. An experimental procedure for each requirement is illustrated
below.

Adjustable voltage in 10mV increments ranging from -10V to +10V DC (Satisfied)

Connect the output of the power supply to the load.


Connect the testing instrument (multimeter or oscilloscope) in parallel to the electronic
load.
Figure 1 below demonstrates the connection of a testing instrument in parallel to the load.

Fig.15. Connection of Scope in Parallel to Load

From the power supply, set a voltage to generate from its output.
Ensure that the power supply is turned on and running.
The recorded voltage from the testing instrument should be within 5% of the set voltage.
The voltage range of the power supply should be from -10V to +10V in 10mV
increments.
*The 10mV requirement was verified using the display of digital multimeter in lab.

Adjustable current limit setting for overcurrent protection in 10mA increments (Satisfied)

Measure the output current and compare to the user set current limit.
Connect the testing instrument (multimeter) in series to the electronic load.
Figure 2 below demonstrates the connection of the multimeter (labeled I) in series to the
load.

21

Fig. 16. Connection of Multimeter in Series to Load

Using a potentiometer as a load, slowly decrease the resistance.


As the resistance of the load decreases, the output current increase.
Upon reaching the user set current limit, any further decrease in load resistance should
not increase output current.
This output current limit should be adjustable by the user in 10mA increments.

Fixed percentage overvoltage protection (Not Satisfied)

Ensure that the power supply has warmed up for at least 30 minutes.
Connect an external DC power source in series with the power supply that has a rating of
at least 20% of the set output voltage.
Measure the output voltage and compare to the user set output voltage.
Upon connecting the external DC power source, the voltage across the load is the sum of
the external source and the set user voltage from the power supply.
This causes the voltage across the load to be greater than the overvoltage threshold and
the power supply should automatically be switched off.

Efficiency above 75% under load (Satisfied)

Ensure that the power supply has warmed up for at least 30 minutes.
Measure the output voltage and current without an electronic load.
Measure the output voltage and current while under an electronic load.
The output power is equal to:
abc = abc abc
The ratio between the output power with an electronic load and the output power without
an electronic load should be no less than 0.75.

22

Size less than 5.5 in x 3.5 in x 3 in (Not Satisfied)

The length of the power supply should be no more than 5.5 inches.
The width of the power supply should be no more than 3.5 inches.
The height of the power supply should be no more than 3 inches.

III. Overall Assessment of the Project


The expected outcomes during the start of the project werent all met but, overall, this
project was mostly successful based off the minimum requirements given. Out of the eleven
minimum requirements, eight of them were met. The three minimum requirements that werent
met are overvoltage protection, cost, and size. For the overvoltage protection, this requirement can
be fulfilled given more time for this project. However, regarding the cost and size, more search
needs to be done along with more time to fulfill these two requirements. The reason these two
requirements need more time is due to the uncertainty and the need of finding a solution.
The final design for the project took some time to discover. The first few designs consisted
of a buck-boost converter and the use of DCP chips. Both these designs had issues regarding the
minimum voltage requirement or voltage regulation. The final design consists a negative feedback
regulator. This design was able to meet both the minimum voltage requirement and voltage
regulation. Upon deciding on the negative feedback regulator, the other two designs were scraped.
By using the negative feedback regulator, other requirements were met along with it. The negative
feedback regulator offered an isolated voltage output, and also met the 75% efficiency
requirement.
After finalizing the decision on using negative feedback regulator to amplify the input
voltage to the required voltage, the other requirements that were met were done by implementing
new components into the initial design. The current limitation, displayed voltage and current
setting and readings, output from banana jacks, and damage prevention to USB were met by simply
adding more parts to the negative feedback regulator design. With more time, a full design that
also meets the overvoltage, cost, and size requirement will be met.

*Please refer to Appendix D for Project timeline.

*Appendix A refers to the image of USB Power Supply circuit

23

Precision Pot

USB 2.0 Type B.


Module

Flyback Regualtor
Circuit

Voltage
Regulators

Transformer
Circuit (only one in
use)

Fig. 17. Final Circuit Design

User Interface, LCD


voltage/current
Monitor

24

Appendix B.
Source Code
#include <Wire.h>
#include <LiquidCrystal.h>
#include <Adafruit_INA219.h>
Adafruit_INA219 sensor219;
LiquidCrystal lcd(7, 8, 9, 10, 11, 12); //lcd pins
const int
const int
const int

buttonPin = 2;
buttonPin1 = 4;
buttonPin2 = 3;

const int LEDOutput = 13;


int buttonPushCounter = 0;
int buttonState = 0;
int buttonState1 = 0;
int buttonState2 = 0;
int counter = 0;

//declare pins
//int relayPin0 = 13;
//int relayPin1 = 15;
//end of declare pins

// Relay 0
// Relay 1

void setup(void)
{
Serial.begin(250000);
sensor219.begin();
lcd.begin(16, 2);
pinMode(buttonPin, INPUT);
pinMode(buttonPin1, INPUT);
pinMode(buttonPin2, INPUT);
pinMode(LEDOutput, OUTPUT);
}
void loop(void)
{
//relay code
digitalWrite(relayPin0, HIGH);
// sets the relay 0 on
delay(1000);
// waits for a second
digitalWrite(relayPin1, HIGH); // sets the relay 1 on
delay(1000);
// waits for a second
//end of relay code

25

buttonState = digitalRead(buttonPin);
Serial.println(buttonState);
buttonState1 = digitalRead(buttonPin1);
buttonState2 = digitalRead(buttonPin2);
if (buttonState == 1)
{
counter = counter + 5;
}
else if (buttonState1 == 1)
{
counter=counter - 5;
}
/*else if (buttonState2 == 1)
{
counter = 0;
}*/
Serial.println("Counter " + (String) counter);
float busVoltage = 0;
float current = 0; // Measure in milli amps
float power = 0;
char outstr[15];
//read sensor
busVoltage = sensor219.getBusVoltage_V(); //voltage in V
current = sensor219.getCurrent_mA(); //current in mA
power = busVoltage * (current/1000); // power in W
//end of read sensor
String msg1 = "";
String msg2 = "";
//lcd refresh
lcd.setCursor(0, 0);
lcd.print("");
lcd.setCursor(0,1);
lcd.print("");
//end of lcd refresh
//lcd 1st line
lcd.setCursor(0,0); //16x1
msg1 = "";
//dtostrf(busVoltage,4, 1, outstr); //converts the value to one value
after decimal
msg1 = (String) busVoltage;
Serial.println(busVoltage);
lcd.print("");
//lcd.print(msg1+"

"+counter);

26
//end of lcd 1st line
Serial.println(counter);
//lcd 2nd line
lcd.setCursor(0, 0); //16x2
msg2 = "";
msg2 = (String) (current);
lcd.print("");
lcd.print(msg1+" "+msg2);
//end of lcd 2nd line
lcd.setCursor(0, 1);
lcd.print("");
lcd.print("C= " + (String) counter);
Serial.println("Current " + (String) current);
Serial.println("Counter " + (String) counter);
if(current>counter)
{
digitalWrite(LEDOutput, HIGH);
}
else
{
digitalWrite(LEDOutput, LOW);
}

//serial print
Serial.println(msg1);
Serial.println(msg2);
Serial.println("");
//end of serial print
delay(2000);
/*
for (int i = 256; i >= 0; i--)
{
digitalPotWrite(i);
delay(10);
}
delay(500);
*/
/*
delay(10);
digitalPotWrite(8);
delay(10);

Appendix C

27

28

29

30

31

32

33

Appendix D: - (Red -> Expected, Dark Blue -> Actual)

Table. 3. Design Timeline

34

IV.

References

[1] "LM2587", Texas Instruments, 2016. [Online]. Available:


http://www.ti.com/lit/ds/symlink/lm2587.pdf. [Accessed: 28- Apr- 2016]
[2]S. 5V/3.3V, B. (White), B. (Clear), U. Foot, B. Classic, V. Adjustable and S. 3.3V/1.8V,
"SparkFun Breadboard Power Supply USB - 5V/3.3V - PRT-08376 - SparkFun Electronics",
Sparkfun.com, 2016. [Online]. Available: https://www.sparkfun.com/products/8376. [Accessed:
28- Apr- 2016].
[3]2016. [Online]. Available: http://www.ti.com/lit/ds/symlink/lm555.pdf. [Accessed: 28- Apr2016].
[4]2016. [Online]. Available: http://www.ti.com/lit/ds/symlink/lm317.pdf. [Accessed: 28- Apr2016].
[5]2016. [Online]. Available: http://www.ti.com/lit/ds/symlink/lm337.pdf. [Accessed: 28- Apr2016].
[6] Keysight Technologies, (2014, August 3) Overvoltage Protection in Power Supplies [Online].
Available: http://literature.cdn.keysight.com/litweb/pdf/5989-9395EN.pdf
[7] Keysight Technologies, (2014, July 31) Power Supply Testing [Online]. Available:
http://literature.cdn.keysight.com/litweb/pdf/5952-4190.pdf

You might also like