## So what the heck just happened?

You've seen me do some energy calculations and a sample energy budget, throwing numbers all over the place as I went. Even if you were able to follow along step by step, it's reasonable to wonder how I got from the beginning to the end.

There’s a method to the madness, but it can get lost behind all the details.

In fact, the basic idea of doing an energy budget is to get rid of details that make it hard to guess how much energy a circuit needs over time.

The main offenders are duty cycles and pieces operating at different voltages. All the number shuffling serves the purpose of making those values line up better.

Here’s a high-level description of the process:

## Start with what you have, and calculate power.

Circuits are defined in terms of their voltage and current, and those values are usually easy to find. If they aren't in a datasheet or some other documentation, you can hook up a multimeter and measure them directly.

They’re what you have to start with, so do the only calculation you can: power.. the amount of energy that moves from one place to another while the circuit is in operation.

## Use power and time to calculate work.

If parts of your circuit only consume power some of the time, use those times for the next calculation available to you: work.. the amount of energy the circuit uses in a given amount of time.

The time values are almost entirely under your control. There are some operational constraints.. it takes a certain amount of time to establish a Wifi connection and transmit data to the internet.. but you have enormous freedom to make tradeoffs.

Many times, you’ll want to do energy budgets to compare different timing options for the project you’re building. The usual question is, “do I want this feature enough to accept what it does to overall battery life?”

## Use work to calculate average power.

This is where we get rid of the details related to time and duty cycles. Reducing “on for this long, off for that long” to average power during the whole period condenses two currents and two time values into a single, more general number.

The details aren’t really gone of course, they’re just all mushed together. You’ll have to calculate a new average power value any time you change a duty cycle.

## Use average power to calculate average current.

Once you know the average power, you can use it to calculate the average current.

Average power and average current are intermediate products in an energy budget.. values we calculate on the way to finding some value we really want.. but they’re also handy on their own.

Circuit designers like to use values called ‘figures of merit’ that serve as a quick shorthand for comparing one circuit to another. Average power and average current are useful figures of merit. You’ll probably find yourself using them automatically once you get used to the math.

## Use average current to match voltages.

Once you have an average current, you can use it to fill in any differences in voltage.

This step is mostly about finding missing pieces: if you have a 3.3V circuit running from a 5V power supply, there has to be a 1.7V piece somewhere.

That missing piece is usually the voltage regulator: an important but easily ignored part of any circuit.

Most circuits use either linear regulators or switching regulators.

Linear regulators are basically smart resistors that adjust their own resistance to keep the output voltage where it should be. A linear regulator’s power consumption is also the same as a resistor’s: the average current times the voltage between its input and output terminals.

Switching regulators work the same way as a PowerBoost, with duty cycles that turn a higher input voltage to a lower output voltage. And like the PowerBoost, they’re constant-power devices with some efficiency loss. The loss is the only energy the the regulator consumes itself, and that’s just some fraction of the average power.

It doesn’t hurt to run the numbers on a switching regulator’s duty cycle and instantaneous current though. Those will tell you what kind of demands the regulator will make on the battery.

## Find the average power for the whole system

Once you’ve found all the missing voltages and worked out the power used by the voltage regulators, you can add the pieces together and get a single figure of merit for the whole system: the average power it consumes when operating at a given supply voltage.

## Use the average power to find battery life

That sequence of twists and turns produces a value you can compare to a battery’s stored energy: power (Joules per second) calculated for the battery’s output voltage.

There are two ways you can make the final comparison to a battery’s milliamp-hour rating:

The first is to use the average power and the voltage to calculate the average current. That will give you a value whose units are milliamps, which divide into milliamp-hours to give you an estimate for battery life.

The second is to multiply the battery’s voltage (Joules per Coulomb) by its milliamp-hour rating (a complicated way to say Joules) to get the battery’s stored energy in Joules. Divide that by the average power to get the estimated battery life.

Each is about as easy as the other. I happen to prefer working with standard units, but use whatever feels most natural to you.