# Charging and Discharging Capacitors

Some useful calculations that uncover just one of the many analog aspects of digital signals.

We all know the familiar waveform of a capacitor charging and discharging.

We also know the formulas for voltage:

$V = VG * [1 - e^{-t / RC}]$

and current:

$I = VG * {\frac{e^{-t / RC}}{R}}$

Lets now apply these basic concepts to a basic digital interface. Now I know, this blog is called Analog Anomaly, so trust me, that’s all I’m interested in here.

VG1 is the output driver which could be a GPIO of a microcontroller or an output from a digital logic gate. R1 is the source resistance of the driver and 28 Ohms is a ballpark figure for some outputs. C1 represents the input that is reading the corresponding output. 10 – 15 pF is typically for a lot of digital inputs.

When the output turns from low-to-high, the input (C1) charges through R1. When the output turns from high-to-low, the input discharges through the same R1. Nothing too ground breaking here.

What happens when we do this a lot, I mean periodically at a specified frequency. We’ve probably all heard that electronics heat up the faster or more often they switch. What we often forget to account for (or maybe just myself) is the energy it took to charge and discharge the input.

You’re probably thinking, ugh… its 10 pF, what’s the big deal, and depending on your design, it might not be anything of concern. I’m going to go ahead and dump a formula on you at this point and I’ll explain where it comes from later.

Maybe you’ve seen this, maybe not. I have a hard time finding it when I forget it and have to derive it each time I need it. Given that the output is driving a square wave at frequency, f, up to voltage, v, and then back down to 0 V. The average current across R1 can be written as:

$I_{avg} = 2 * f * C * V$

The current is actually going in opposite directions depending on if the capacitor is being charged or discharged but when we’re thinking about heat dissipation or thinking about device current draw, it doesn’t matter.

When C = 10 pF, V = 3.3 V and f = 1 MHz, the average current is 66 uA

At 10 MHz, 660 uA

At 100 MHz, 6.6 mA, okay obviously this is a linear function, you get the idea.

One thing I forgot to mention about the formula is that it assumes that within one-half cycle, the capacitor will have time to fully charge or discharge. I’ll leave it up to you to figure out if it does or not for the examples I gave.

The average current can be used to calculate power dissipation in the IC output.

$P_r = I_{avg}^2 * R$, which at 100 MHz is only 1.2 mW

These calculations can have all sorts of implications when doing designs including properly designed decoupling networks for power supplies. But I’m not going to go into that right now.

I think I’ll save the formula derivation for another short article.