De-coupling
Once you get more than a handful of active components together you need to de-couple the power supply. What this is, and why, is described here.
The problem
When an otherwise good design works, but is erratic, unreliable or just goes crazy then nine time out of ten it is the power supply de-coupling. And you will find that the tenth time, turns out to be power supply de-coupling as well. So what is it, and why is it needed?
Basically when an integrated circuit works it works by switching current on and off. This switching happens very rapidly. Each time the current changes the voltage changes as well. This is because of the fact that everything has a resistance, even wire and copper traces on a printed circuit board have resistance. It’s not a very big resistance but it doesn't have to be. A changing current passing through a resistance will produce a changing voltage across it. Now consider a chain of several ICs being powered:-
As the current changes in ICA the voltage supplying that IC also changes, what is worse the voltage supplying all the ICs changes. But it gets worse, as ICB works its current changes and that also causes the voltage to vary on the other ICs and so on. In fact the voltage supplying the ICs is changing very rapidly due to the contribution of all the ICs in the circuit. The switching in an IC happens very rapidly so this voltage variation is very rapid or at a high frequency. The more rapid the circuit switches the higher the frequency of this voltage variation on the power supply, this is called noise, but another way of describing it is to say that the individual parts of the circuit are coupled together. Things can get so bad that the noise can stop a circuit from functioning correctly. It is to get rid of this noise that we have to de-couple the power supply. Essentially getting rid of the noise is easy, at least conceptually simply put a capacitor across the supply to smooth out the supply or filter the noise out.
Practicalities
If you look at the frequency spectrum of this noise you will find that it has a wide range so you might think it is easy to filter it out, just use a large capacitor. Unfortunately it is not as easy as that. A capacitor looks like a low resistance for high frequencies, the higher the frequency the lower it looks. The capacitive reactance (or XC ) is the name we give to the resistance of a capacitor for an alternating signal, this frequency dependent "resistance" is also known as an impedance. It is given by this formula:-
Where F is the frequency in Hz C is the capacitance in Farads. So a practical first approximation to a solution is use a 0.1uF or a 0.01uF capacitor like this one across the supply of each chip. It is much much better than nothing.
Don’t just ignore that formula, look at it for a moment. It is a reciprocal, that is it is one over something. This means that the bigger things are on the bottom of the fraction the smaller the other side of the equation gets. But while it can get small it will never get to zero. You will see the bigger the capacitance the more of a short it look like, also the higher the frequency the more of a short it look like. Great so all we need to do is put in a big capacitor and that will remove all the high frequencies. Well sorry no, life is a bit more complex than that.
Inductance
As well as everything, like wires, having a resistance they also have an inductance. That is everything acts like a coil as well. An inductor is the reverse of a capacitor, It looks like a very high resistance to an alternating signal. The effective resistance to an AC signal is called the inductive reactance (or XL) and is given by:-
Where F is the frequency in Hz L is the inductance in Henrys.
Note that it is very similar to the capacitive reactance only its not a reciprocal. That means the bigger the frequency and inductance gets the higher the effective resistance is. Here is a plot of reactance against frequency for some real capacitors with a large values.
So why does this matter? Well every capacitor has also an associated inductance and the total resistance presented to an alternating signal is the sum of them both. So over a frequency range one goes down and the other goes up. The practical upshot is that for a given capacitor it only filters noise up to a certain frequency. This is known as the “self resonant” frequency of a capacitor at at any frequency above its self resonance the component looks like an inductor and is doing nothing to remove noise from the supply. The lowest point on the graph above is this self resonance frequency.
You will also see from the graph above it is not always the largest or smallest capacitor that has the best high frequency effect.
The graph below shows both capacitive and inductive reactance for several different values of capacitor but all having an inductance of 1nH. These are theoretical curves.
In the case of large electrolytic capacitors a high inductance is produced due to the way it is built, as a sandwich of metal foil and insulator, all rolled up, this is a lot like a coil. However for small ceramic capacitors the biggest cause of inductance is the components leads. To maximise the effects these must be as short as possible.
For effective supply de-coupling that frequency has to cover as wide a range as possible and certainly the range of noise being generated by the circuits. So this is why we often see two different values of capacitor used in parallel. One large one to filter out the low frequency variations and a small on for the high frequency noise. Typical values are 47uF and 0.1uF or 0.01uF (10nF) and as low frequency variations are system wide you tend to need only one large capacitor. However, high frequency noise is no so easily suppressed and so you tend to need a small capacitor on every, or every other chip. The type of capacitor construction that produces the lowest inductance is the ceramic type and those are always used for the smaller capacitors.
The lead from the circuit board to the capacitor body can produce a lot of inductance so it is important that this is as short as possible. Surface mounting capacitors are ideal in this respect and are to be preferred if practical. Modern IC designs often have the positive supply and ground pinned out next to each other to make this de-coupling especially effective.
The way this is drawn indicates that the capacitors are close to the IC and the supply is fed to the capacitor before being passed on to the next IC. For smaller circuits you would probably get away with a de-coupling capacitor every other IC but professionals do de-couple every IC. In general I try to aim at at least half the number of de-coupling capacitors as ICs and if there is an especially heavy current IC I will often throw in another large electrolytic.
There are occasions when you require more isolation with particularly sensitive circuits like oscillators or A/D converters for example. Here I would use a series resistor to boost the isolation for that chip alone. This helps to isolate it from the rest of the chain, and is shown in the circuit below.
This has the disadvantage of reducing the supply impedance and increasing the noise for heavy currents.
For the ultimate in de-coupling use a small choke or inductor as well. This is called a Pi filter because the circuit resembles the Greek symbol for Pi π. The inductance value is not too critical, but generally as big as you can manage, a few tens of mill Henrys is normal. This is useful if the load generates a lot of noise. Not only does this protect the load from noise it also prevents noise generated by the load from getting into the rest of the circuit.
This arrangement would be especially suited to the case where the load was not an IC but a motor. Motors can generate so much noise on the supply that a single one can cause an Arduino to reset. Larger capacitors after the choke can also help in those situations.
As motors draw a lot of current these can often be several hundred micro Farads. Note any motor should have a flyback diode across it. This is easy if the motor only has to run in one direction, just a single diode with its cathode to the supply and anode to the other end of the motor. But in the case where the motor can run in either direction a more complex arrangement of four diodes need to be used. But that is for another tutorial.
In Conclusion
Decoupling is more of an Art than a Science. While the component values used here are typical they are not guaranteed to work in every case. You might need larger electrolytic capacitors when the current is larger or you can get away with smaller ones when the current is lighter.
Remember it is always better to fix a problem "at source", that means concentrating of the cause of the interference rather that mitigating the effects of it on the rest of the circuit. For example switching heavy or high voltage loads might require snubber circuits to reduce the rate of voltage with time. In other words to slow down the voltage rise and so reduce the interference.