Capacitors for Makers

Introducing the Stratify Toolbox

Are you a printf()-er or a code-stepper? The Stratify Toolbox is a printf()-ing awesome debug tool!

This is the fourth article in a series to teach you all the EE you need to know for working with and designing microcontroller based circuits.

Capacitors are very common in designs with microcontrollers. Though the math is more complex than with just using resistors, understanding the basics plus a few rules of thumb will let you understand what most capacitors are doing in microcontroller based circuits.

Understanding the Basics

Physically a capacitor contains two parallel plates that are separated by an insulator. The geometry of the plates and the type of insulator material determine the capacitance.

When you apply a voltage to a capacitor, a charge builds up between the two plates–somewhat similar to how charge builds up between the ground and clouds during a storm and sometimes discharges as lightning. The energy is stored in an electric field (later we will talk about how inductors store energy in a magnetic field). That energy can then be used in the circuit.

If you like the pressurized water system analogy, you can think of a capacitor as a tank that holds pressurized water and is controlled by a special valve that only accepts or releases pressure when the external pressure changes.

Math and Units

Capacitance is measured in Farads which is a ratio of charge (coulombs) per unit voltage (volts).

$$farad = \frac{coulombs}{volt} \space \to \space C = \frac{Q}{V}$$

Ohm’s law doesn’t directly apply to capacitors because they are not a purely resistive device. Because capacitors don’t simple burn off energy as heat but store and release energy, they actively “react” to energy flow in the circuit rather than passively absording energy. When a device actively reacts it has impedance rather than just resistance. Impedance is a combined measure of resistance and reactance. Other than the basic lingo, you don’t need to know much more about impedance. Let’s rather focus on a few use cases that are seen all-the-time in microcontroller circuits.

Capacitor Behavior in Microcontroller Circuits

Capacitors have much simpler behavoir in DC circuits than in AC ones. Thankfully that makes them easy to analyze.

When a DC voltage is applied to a capacitor, it has a transient response and a steady-state response. The transient response describes how the capacitor charges up (or discharges if the voltage is removed) and the steady state describes the behavior after the capacitor is charged.

Transient Response

In the circuit below, we will look at what happens when $$5V$$ is first applied and when the capacitor reaches steady state.

The rate at which the capacitor charges depends on the capacitance $$1 \mu F$$ and the series resistance between the capacitor and the charging source ($$1k \Omega$$ in this case). The resistance times the capacitance is the time constant (this will come up later) and defines how long the capacitor takes to charge. The equation is:

$$V_C = V_S \cdot (1 - e^{\frac{-t}{RC}})$$

The plot below shows our circuit with the resistor at $$1k \Omega$$ and $$2k \Omega$$. Notice the increase resistance slows down the capacitors rate of charging.

    {
"type": "line",
"data": {
"labels": ["0us", "100us", "200us", "300us", "400us", "500us", "600us", "700us"],
"datasets": [
{
"label": "Capacitor Voltage (R = 1kOhms)",
"data": [0,
3.15498155,
4.319181384,
4.748775418,
4.907297202,
4.965792326,
4.987377242,
4.995342156],
"backgroundColor":"transparent",
"borderColor":"orange"
},
{
"label": "Capacitor Voltage (R = 2kOhms)",
"data": [0,
1.962716304,
3.15498155,
3.879231108,
4.319181384,
4.586432143,
4.748775418,
4.847391935],
"backgroundColor":"transparent",
"borderColor":"blue"
}
]
}
}


The equivalent circuit of a capacitor in steady state can be modelled by infinite resistance. When the capacitor is fully charged, the circuit behaves as though it isn’t even there (at least for our considerations).

The good news is that this is how we treat most capacitors. We just pretend they aren’t there.

Capacitors in Microcontroller Circuits

Now that you have a basic grasp of what a capacitor is and how it behaves, if you learn a few rules of thumb you can understand what a lot of capacitors are doing. We will start by looking at decoupling capacitors.

Decoupling Capacitors

Decoupling capacitors are placed next to the power pins of chips in order to both provide energy to the chip and prevent the chip from injecting noise onto the power supply. Digital chips run on a clock. Every clock cycle there is a brief moment when the internal circuitry changes state. In this moment, there is a tiny current spike.

    {
"type": "line",
"data": {
"labels": ["0ns", "1ns", "2ns", "3ns", "4ns", "5ns", "6ns", "7ns", "8ns", "9ns", "10ns", "11ns", "12ns", "13ns", "14ns", "15ns", "16ns", "17ns", "18ns", "19ns"],
"datasets": [
{
"label": "Clock",
"data": [
0, 0,
0, 0,
1, 1,
1, 1,
0, 0,
0, 0,
1, 1,
1, 1,
0, 0,
0, 0
],
"backgroundColor":"transparent",
"borderColor":"orange"
},
{
"label": "Current Consumption",
"data": [
2, 2,
2, 2,
5, 2,
2, 2,
2, 2,
2, 2,
5, 2,
2, 2,
2, 2,
2, 2
],
"backgroundColor":"transparent",
"borderColor":"blue"
}
]
}
}


The decoupling capacitor is placed physically close to the VDD and GND pins of the digital chip. This creates two current loops shown as A and B below. The decoupling capacitor delivers the energy needed for the current spikes on loop B. Loop A doesn’t have to deal with the spikes and just provides steady current to the capacitor.

Generally, you will see $$0.1 \mu F$$ capacitors place right next to pins. You will also see $$1.0 \mu F$$ and $$10.0 \mu F$$ capacitors placed in the vicinity of the part. Loop B should be kept as small as possible (because it actually acts as an inductor which counteracts the effects of the capacitor). For designs that are less than 50MHz, these simples rules will usually do the trick. The higher the frequency is, the more challenging it is to design circuit boards with good decoupling capacitors.

Now that you know all that, you can basically just ignore all the decoupling capacitors on a microcontroller schematic. Unless you are having some really weird noise or power issues then they are doing their job just fine.

Filtering Capacitors

Decoupling capacitors are actually a filtering capacitor for power lines, but capacitors are also used when filtering sensor signals. This is most commonly seen with low pass filters that are used before inputting a signal to an ADC.

The circuit below is a basic low pass filter circuit. Because of how the capacitor charges and discharges slowly, fast signals from $$V_I$$ will not make it to $$V_O$$.

The frequency at which half of the power is absorbed in the capacitor is known as the cutoff frequency. For this circuit it is:

$$\omega _{cutoff} = 2 \pi f = \frac{1}{RC}$$

$$f_{cutoff} = \frac{1}{2 \pi \cdot 1k\Omega \cdot 1 \mu F} = 159.15Hz$$

So frequencies below $$159.15Hz$$ can deliver more than half the power than they could without the filter while frequencies above $$159.15Hz$$ can deliver less than half the power. As the frequency gets higher, less power can be transferred across the filter.

DC Blocking Capacitors

DC blocking capacitors are used with audio signals to remove the average voltage of the signal so that it is centered around $$0V$$.

The circuit above just causes an AC signal with a DC offset on $$V_I$$ to become a zero-centered AC signal on $$V_O$$. This technique is used a lot with audio signals to zero-center the signal.

    {
"type": "line",
"data": {
"labels": ["0us", "100us", "200us", "300us", "400us", "500us", "600us", "700us", "800us", "900us"],
"datasets": [
{
"label": "Vin",
"data": [
3,
5,
3,
5,
3,
5,
3,
5,
3,
5
],
"backgroundColor":"transparent",
"borderColor":"orange"
},
{
"label": "Vout",
"data": [
-1,
1,
-1,
1,
-1,
1,
-1,
1,
-1,
1
],
"backgroundColor":"transparent",
"borderColor":"blue"
}
]
}
}


This circuit configuration is actually called a high pass filter and basically does the opposite of what the low pass filter does. It prevents signal transfer of low frequencies (you know, like near zero aka DC values).

You are (hopefully) smarter for having read this

Hopefully, you grasped the basics of how capacitors work (of course, you did). Capacitors are just two metals plates that store a charge. They are basically used for filtering signals. Of course they are used for more advanced circuits, but the vast majority of what I see are power decoupling caps, low pass filter caps and DC blocking (or high pass) caps.

X