## Project – DC Power and Efficiency Meter

1. Introduction

2. Bill of Materials

3. Schematic

4. Code

6. Final Thoughts

#### INTRODUCTION

This is a fun little project that actually took me awhile to put together.  What makes this project interesting and useful is that it will display your voltage, current, and power of any device you plug it into.  What also makes this project useful is that it will calculate the efficiency of your device for example a dc dc converter.

The heart of this project is two INA219 high side current sensors from Texas Instruments.  With this sensor you can measure up to 26V DC and up to +/-3.2A with a 0.1ohm shunt resistor (if you swap out the shunt with a 0.01ohm shunt you can measure up to +/-32A)

#### BLOCK DIAGRAM

Here you can see a block diagram showing how I connected the different boards to create this project. Since I used my CNC machine to create the boards, it’s always much easier to separate the circuits into different boards for routing.

The main board consist of an arduino pro mini to keep the footprint as small as I can and also host a 5V boost converter being power from the 18650 lithium ion battery.  In order to charge the battery without having to remove it from the enclosure, I decided to add a lithium ion charger board that connects in parallel with the battery.  Its powered by a 5V USB mini connector and can be bought on amazon.

The second board host x2 INA219 high side I2C current, voltage, and power sensor by Texas Instrument.  This IC is an amazing little thing because it takes a lot of the number crunching away from the Arduino and just sends the data over I2C that you need.

The final piece of this is the I2C liquidcrystal display for the arduino.  I used this library here for the display.  Make sure you connect the display and run an i2c address scanner on the examples for arduino because sometimes the displays have a different address than the default one listed.

#### CODE


/*

* Name: Steven Guzman

* Date: 2018/03/18

* Description: This is a DC power meter that measures input and output

*              power and calculates the efficiency of the system.

*              It can also measure voltage and current of one or two

*              voltage sources

*/

#include

#include

#include

LiquidCrystal_I2C lcd(0x3F,20,4); // Set the LCD address

/*

* Below are the array values to store the measurements

* and then used to convert float to string

*/

char float_volt1;  // voltage 1 array

char batt0;

char float_volt2;  // voltage 2 array

char batt1;

char float_current1; // current 1 array

char curr1;

char float_current2; // current 1 array

char curr2;

char float_eff;  // efficiency variable array

char line6;

char float_batt; // battery voltage array

char line5;

// Analog sampling number

int sample = 20;

// Inialize current sensors.

// ina219_A default address is 0x40

// Variables to store current sensor data

float busvoltage1 = 0;

float busvoltage2 = 0;

float current_mA1 = 0;

float current_mA2 = 0;

float batt = 0.00;

void setup()

{

Serial.begin(115200);

while(!Serial)

{

delay(1);

}

ina219_A.begin();

ina219_B.begin();

lcd.init();

lcd.init();

lcd.backlight();

}

void loop()

{

float xbat = 0.00;

for(int x=0;x<sample;x++)

{

xbat = xbat + batt;

}

// of the IN219 on both ICs

busvoltage1 = ina219_B.getBusVoltage_V();

busvoltage2 = ina219_A.getBusVoltage_V();

// of the IN219 on both ICs

current_mA1 = ina219_B.getCurrent_mA();

current_mA2 = ina219_A.getCurrent_mA();

// Average out the analog measurements

// for the lithum ion battery voltage

// sensing

xbat = xbat/sample;

float battery = xbat * (5.00/1024);

dtostrf(battery,4,2,float_batt);

sprintf(line5, "Battery:%-5s",float_batt);

char temp3[] = "V";

strcat(line5,temp3);

// Convert float values into an char array to

// better update on the lcd screen without

// having to use the lcd.clear function

dtostrf(busvoltage1,4,2,float_volt1);

sprintf(batt0, "V1:%-5s",float_volt1);

char temp2[] = "V";

strcat(batt0, temp2);

dtostrf(busvoltage2,4,2,float_volt2);

sprintf(batt1, "V2:%-5s",float_volt2);

char temp1[] = "V";

strcat(batt1, temp1);

// Convert mA to A readings

float C1 = current_mA1/1000;

float C2 = current_mA2/1000;

dtostrf(C1,4,2,float_current1);

sprintf(curr1, "C1:%-5s",float_current1);

char temp4[] = "A";

strcat(curr1, temp4);

dtostrf(C2,4,2,float_current2);

sprintf(curr2, "C2:%-5s",float_current2);

char temp5[] = "A";

strcat(curr2, temp5);

float power1 = busvoltage1 * C1;

float power2 = busvoltage2 * C2;

float eff = (power2/power1)*100;

dtostrf(eff,5,2,float_eff);

sprintf(line6, "Efficiency:%-7s",float_eff);

/*

* Display on LCD screen all the values.

* I used char arrays to update the values on the

* screen.  Using the lcd.clear caused flickering

* and was annoying.  With char array you can include

* the units and it will update properly and not

* overright the units.

*/

lcd.setCursor(0,0);

lcd.print(batt0);

lcd.setCursor(11,0);

lcd.print(batt1);

lcd.setCursor(0,1);

lcd.print(curr1);

lcd.setCursor(11,1);

lcd.print(curr2);

lcd.setCursor(0,2);

lcd.print(line6);

lcd.setCursor(0,3);

lcd.print(line5);

delay(500);

}



There might be some issues with how wordpress displays the arduino code but I attached the original files at the end this tutorial.

As mentioned before, the libraries used here I obtained from other sources:

I designed the enclosure in fusion 360 and printed the both with matterhackers pro series PETG red.  I used a monoprice maker select v2 to print this enclosure.

Here is the step file for the enclosure

#### FINAL THOUGHTS

This was one of my favorite projects yet because the design alone makes me feel accomplished learning everything on my own.  I still feel like I can make some upgrades to how I mount the internals and to be honest, I really rushed this part because I wanted to finish it.

Some upgrades I’m considering is using the arduinos internal 1.1V reference with a voltage divider to measure the battery voltage because it wasn’t as accurate as I wanted it to be.

## How-to: Design a Boost Converter Figure 1: Basic Boost Converter Circuit

#### Designing a boost converter sounds complicated and intimidating, well that was always my impression when it came to this topic in school.  In reality, the design and testing of a boost converter is a lot easier than meets the eye.

Here I will walk you step by step on designing your first boost converter and how the datasheet is your best friend when designing.  For this tutorial we will be using the L6920DC IC Boost converter from skyworks.

This information was referenced from TI reference report.

First and foremost, download the highlighted datasheet, datasheet-l6920dc. This has all the highlighted paremeters that you will need when designing a boost converter.

Step 1:

You need to decide what are your specifications.  These are the key parameters:

• Vin(min)
• Vin(max)
• Vout
• Iout
• n = efficiency; Most boost converters average around 85 to 90% under medium load and up to 95% on heavy load.  We will use the lowest percentage to be safe.

Example:

• Vin(min): 1.8V
• Vin(max): 2.4V
• Vout: 3.3V
• Iout: 0.4A
• n = 87% or 0.87

Step 2:

With your specifications, next step is to find your DUTY CYCLE: $\bf \Huge D= 1 - \cfrac{(V_{\text{IN}}*n)}{V_{\text{OUT}}}$

We calculated the duty cycle for both lowest input voltage and highest input voltage.

• Lowest input voltage gives you the highest switching current you will see
• Highest input voltage gives you the highest output current your converter can produce

Example: $\bf \Huge V_{\text{IN-MIN}}$ $\Huge D = 1 - \cfrac{1.8V*0.85}{3.3V}$ = 0.52 $\bf \Huge V_{\text{IN-MAX}}$ $\Huge D = 1 - \cfrac{2.4V*0.85}{3.3V}$ = 0.36

Step 3:

Next we will estimate the switching current or CURRENT RIPPLE of the Inductor:

ΔIL = $(0.3) * I_\text{OUTmax} * \cfrac{(V_\text{OUT})}{(V_\text{IN})}$

Example: $\bf \Huge V_{\text{IN-MIN}}$

ΔIL = $\Huge (0.3) * 0.4A * \cfrac{3.3V}{1.8V}$ = 0.22A $\bf \Huge V_{\text{IN-MAX}}$

ΔIL = $\Huge (0.3) * 0.4A * \cfrac{3.3V}{2.4V}$ = 0.165A

Step 4:

Next we calculate the minimum INDUCTANCE we need: $\bf \Huge L_\text{MIN} = \cfrac{(V_\text{IN})*(V_\text{OUT} - V_\text{IN})}{\Delta I_\text{L}*f_\text{S}*V_\text{OUT}}$ $\bf \Huge f_\text{S}$ – This is the switching frequency that the converter will operate at.

Example: $\bf \Huge V_{\text{IN-MIN}}$ $\Huge L_\text{MIN} = \cfrac{(1.8V)*(3.3V - 1.8V)}{0.22A*1MHz*3.3V}$ = 3.72uH $\bf \Huge V_{\text{IN-MAX}}$ $\Huge L_\text{MIN} = \cfrac{(2.4V)*(3.3V - 2.4V)}{0.165A*1MHz*3.3V}$ = 3.97uH

We would select the highest inductance value to meet our input voltage rage of 1.8V-2.4V

When selecting the inductor, the key parameters you need to look for is low DCR, package size, and max current the inductor can handle.

DCR – Is the resistance in the coil because at the end of the day, an inductor is still a wire. When you keep this value at a minimum, it will increase your effieciency and the ability to provide a higher output power.

In step 7 , you will calculate the maximum current the inductor will see and there you will have all the necessary parameters needed to chose the inductor.

Step 5:

Now that we have our inductor value, we can calculate the actual CURRENT RIPPLE of the Inductor:

ΔIL = $\bf \Huge \cfrac{V_{IN}*D}{f_\text{S}*L}$

Example: $\bf \Huge V_{\text{IN-MIN}}$

ΔIL = $\Huge \cfrac{1.8V*0.525}{1MHz*3.72uH}$ = 0.19A $\bf \Huge V_{\text{IN-MAX}}$

ΔIL = $\Huge \cfrac{2.4V*0.36}{1MHz*3.97uH}$ = 0.18A

Step 6:

Next we need to calculate the MAX OUTPUT CURRENT the boost converter can output: $\bf \Huge I_\text{MAXOUT}$ = $\bf \Huge (I_\text{LIM} - \cfrac{\Delta I_\text{L}}{2}) * (1 - D)$ $I_\text{LIM}$ – This is the current switch limit of the boost converter.

Example: $\bf \Huge V_{\text{IN-MIN}}$ $\Huge I_\text{MAXOUT}$ = $\bf \Huge (0.8A - \cfrac{0.19A}{2}) * (1 - 0.52)$ = 0.33A $\bf \Huge V_{\text{IN-MAX}}$ $\Huge I_\text{MAXOUT}$ = $\bf \Huge (0.8A - \cfrac{0.18A}{2}) * (1 - 0.36)$ = 0.45A

Step 7:

Next we will calculate the MAX SWITCHING CURRENT, $I_\text{SW}$ the Inductor will see.  This value cannot exceed the ILIM value of the boost converter: $\bf \Huge I_\text{SW-MAX} = \cfrac{\Delta I_\text{L}}{2} + \cfrac{I_\text{OUT}}{1 - D}$

Example: $\bf \Huge V_{\text{IN-MIN}}$ $\Huge I_\text{SW-MAX} = \cfrac{0.19A}{2} + \cfrac{0.4A}{1 - 0.525}$ = 0.94A $\bf \Huge V_{\text{IN-MAX}}$ $\Huge I_\text{SW-MIN} = \cfrac{0.18A}{2} + \cfrac{0.4A}{1 - 0.36}$ = 0.72A

Note: $\Huge I_\text{SW-MAX}$ value cannot exceed $\Huge I_\text{LIM}$ which can be found in the datasheet.  In this example we see that with a low input voltage, the switching current exceeds the limit in the datasheet.  The boost converter might still be able to output the desired current at that low input voltage because $\Huge I_\text{LIM}$ is the minimum switching current it can handle.  But better to be safe than sorry.

Here you can see the inductor will see a max of 0.94A at its lowest input voltage. Now we can chose the inductor for our design.

For this design I went with,MSS5131-472MLB, a 4.7uH inductor from coilcraft.

Since I chose an inductor that has a higher value than previous calculated, the inductor current ripple and output power will be slightly lower but it will not effect your design negatively.

Step 8:

This step is only if your boost converter has an adjustable output voltage.

(This boost converter is a fixed output and does not require these resistors.  Step 8 values are dummy values but the process )

Here we will find R1 AND R2 values for the feedback network: $\bf \Huge I_\text{R0.5} >= 100 * I_\text{FB}$ $\bf \Huge I_\text{FB}$ – This is the current that the feedback resistor draws. $\bf \Huge R_2 = \cfrac{V_\text{FB}}{I_\text{R0.5}}$ $\bf \Huge V_\text{FB}$ – This is the feedback reference voltage $\bf \Huge R_1 = R_2 * (\cfrac{V_\text{OUT}}{V_\text{FB}}-1)$

Example: $\Huge I_\text{R0.5} >= 100 * 350nA$ = 35mA $\Huge R_2 = \cfrac{1.24V}{35mA}$ = 35.4kΩ $\Huge R_1 = 35.4k \Omega * (\cfrac{3.3V}{1.24V}-1)$ = 58.74kΩ

Step 9:

Next l, we will calculate the INPUT CAPACITOR and OUTPUT CAPACITOR needed to minimize the ripple going in and out of the system:

First, you find your input capacitor: $\bf \Huge C_\text{IN}$: Typically this value is 4.7uF to 10uF

Next, we need to first to look at these two equations below: $\bf \Huge \Delta V_\text{OUT}= \cfrac{I_\text{OUT} *T_\text{ONmax}}{ C_\text{OUT}}$ $\bf \Huge T_\text{ONmax}$ – This is the maximum on time of the boost converter.  It is also written as $\bf \Huge D * T_\text{S}$

Were $\bf \Huge T_\text{S} = \cfrac{1}{f_\text{S}}$ $\bf \Huge \Delta V_\text{OUTesr} = ESR* I_\text{SW-MAX}$

ESR – All capacitors are not ideal capacitors and therefore have what is known as Equivalent Series Resistance. This is an important parameter that you need to consider when choosing the right output capacitor.

Example:

Cin = 10uF

First, we need to choose a voltage ripple that we can live with. Here I chose 50mV, and if we rearrange the first equation, we get: $\Huge \Delta C_\text{OUTmin}= \cfrac{0.4 *6.25us}{50mV}$ = 50uF

Now we have a couple of options to choose from when it comes to materials for capacitors.

Most common are ceramic and electrolytic capacitors.  Each have there own pro and con.

Ceramic capacitors offer lower ESR for lower ripple but they typically do not have the bulk capacitance.

Electrolytic capacitors have bulk capacitance but generally have a high ESR that adds to ripple.

In this case I decided to go with both, getting the benefit of bulk capacitance and low ESR.

I went with a 1206 package, 10uF ceramic capacitor and a 47uF Electrolytic in parallel. For the electrolytic, they also have an aluminum polymer that has high capacitance with the added benefit of low ESR. I went with a 47uF that has an ESR of 40mΩ.

Now we plug in the values we got back into the equations and we get:Special Note: For ceramic capacitors, you need to be careful of which class and package size you choose because you only see a certain percentage of your nominal value (ex. 1206 10uF X7R will see 73% of 10uF). Click here for more info. I generally go with 1206 or 1210 with capacitors. $\Huge \Delta V_\text{OUT}= \cfrac{0.4A * 6.25us}{50uF}$ = 50mV $\Huge \Delta V_\text{OUTesr} = 40m\Omega*0.94A$ = 37mV $\Huge \Delta V_\text{OUT}$ = 87mV

Always refer to the datasheet and compare recommended value vs calculated

You’ve now designed your own boost converter regulator.  See it wasnt too hard :).

I will post this project soon that has the schematic and bill of materials, it’ll be under the projects menu bar, stay tuned!!

Feel free to comment below and correct me if anything seems incorrect to you.

References:

5. Ceramic or electrolytic output capacitors