Maybe you’ve seen the YouTube video in which I design a steady 5VDC power supply with the LM7805. I left many details and design decisions behind to have a more straight to the point video. In this post I will go into more detail on each design decision made.
The LM7805 and input voltage
The LM7805 is a linear regulator with a fixed voltage output. Linear regulation means that a voltage higher than the fixed output voltage is attached to the input of the regulator, and the regulator will waste electrical energy in the form of heat, until the output is at the required voltage. This is terribly inefficient but when the input voltage is kept as low as possible, losses are minimized.
The datasheet of the LM7805 tells us that we need at least 7VDC at the input to get a 5VDC output voltage. But because 7V powr supplies aren’t that common, it’s better to choose the next common voltage source which is a 9V battery.
If you can get your hands on a mains adapter from 7VDC to 12VDC, you will be fine too. I set the max at 12V because otherwise you will get too far from the 7V minimum, resulting in the regulator heating up too much.
If you only have a voltage source higher than 12V, I highly recommend to first use a TO-220 package 7805, and attach a heatsink to it.
Decoupling capacitors and ripple
Working principle
To make sure the regulator is stable (= 5V output without ripple or oscillation), decoupling capacitors are added to both the input and output of the regulator. These capacitors can be seen as small local batteries that are really good at being charged and discharged. This property is very important when for example the voltage regulator or the circuitry we’re going to power is suddenly in a high demand of power. Instead of sourcing it aaaall the way through cables etc at the voltage source, it can just use these little ideal batteries.
Capacitor values
We don’t really calculate the values of these capacitors cause it’s not an exact science. The biggest rule of thumb is that the input cap is bigger than the output cap. And when we’re talking about “decoupling” and “small”, a cap of 100nF is what we need. So it’s always good to stock up on 100nF ceramic capacitors for this job.
The input capacitor can for a rule of thumb be 10x or more bigger. So 1µF electrolytic will suffice. But this shouldnt be the standard because decoupling capacitors also have the great property to filter out ripple on the power supply.
Nasty input ripple filtering
We want an as flat as possible DC voltage to power our electronics. The moment small bits of AC or ripple is present in this DC, it’s not clean anymore and it will affect the performance of the circuitry.
To filter out this nasty AC, we use capacitors to short them to ground (because AC thinks capacitors are just wires). The nastier the AC is (= big amplitude), the heavier the decoupling has to be. Note that we’re now focussing on the input decoupling of the 7805. This is only interesting when the 7805 is fed by a mains adapter because they tend to have small amounts of ripple. This can be your typical 50/60 100/120Hz ripple, or a few kilohertz when the mains adapter uses switching technology.
The more filtering is needed, the bigger capacitors are used. So don’t be afraid if you need a 100µF electrolytic capacitor at the input, cause it is also very common.
Luckily the LM7805 also has something called ripple rejection. This means that the regulator itself will also do its best to filter ripple from the input voltage, and not have it appear at the regulated output voltage.
Nasty output ripple filtering
So now you might think, we filtered the input voltage enough and the regulator helps us too -> The output voltage must be as clean as it gets now! Yes, this is very true. The output voltage is extremely clean now, but sadly it will get dirty as soon as we start powering CMOS chips with them.
Why? Because we’re going to create lots of squarewaves and they are nothing but switching transistors. This switching will have an effect on the power supply because the demand of current keeps changing very fast. So while we produce our funky sounding squarewaves, the 5V power rail will get messed up with ripple.
This is why the output of the regulator also needs a capacitor and another rule of thumb is to have each CMOS chip have its own 100nF capacitor too. This can count up to many 100nF scattered around the circuitry because we’ll have so many CMOS chips to decouple. And that’s totally fine and is very common in both amateur and commercial electronics design.
A reminder for the type of capacitor: For low values like the 100nF capacitors, use ceramic or film capacitors. For values higher than that, use electrolytic capacitors.
A last note and warning: check the voltage ratings of the capacitors! The input capacitors need to be rated higher than the voltage of the mains adapter or battery. To be safe, you want to have a nice margin. So when using a 9V battery, get 15V capacitors and when you use a 12V DC supply, get 15V or higher rated capacitors. Not respecting the voltage ratings of capacitors will lead to unsafe conditions. The output capacitors have to be rated at 5V or higher. Most capacitors will be far higher rated than that but still check it to not get exploding surprises.
Protection against reversed voltages
Input protection
What if we connect the battery the wrong way around, or plug in a mains adapter with a reversed voltage? First of all the input capacitors are electrolytic and polarized. They will heat up or explode. Second of all, the LM7805 might die too soon after. Reverse polarity is a bitch but the protection is simple.
Just put a diode in series with the power supply, pointing towards the input of the voltage regulator. Also place it before the decoupling capacitors because we want to protect them too. When the polarity is right, the diode will just allow current to flow and everything is fine. When the polarity is reversed, the diode will block all current and nothing will be powered or explode.
The only downside to this protection is the small voltage drop across the diode. So if we have a 9V battery and a general purpose rectifier diode like the 1N4007, we will have a voltage of 8.3V at the other side of the diode (assuming a forward voltage Vf of 0.7V). This might not be much of a problem because 8.3 is still above the minimum of 7V, but we can do better. If we use a schottky diode like one from the 1N58XX series, we suddenly lower this voltage drop to about 0.3V. This has two benefits.
One, theres less of a voltage drop, so more voltage to work with. Two, the diode has less power to dissipate as the formula is P = Vf * I. But we won’t be pulling that much current that the diode might faint so it will be fine.
Output protection
There is a rare case where the output voltage of the regulator can be higher than the input voltage. For example because theres no voltage source connected at the input but the output capacitors are all still charged to 5V. This condition can damage the regulator.
To fix this, we add another diode (can be a 1N58XX schottky too) from the output of the regulator to the input. This way the capacitors all have a way to safely discharge when this scenario occurs and the regulator is safed.
Extra stuff and calculations
Power dissipation
Power dissipation of linear voltage regulator consists of two parts: The power dissipation because of the current demand of the circuitry (load) that’s going to be powered by the voltage regulator, and the power dissipation by the regulator itself due to bias current.
Ptotal = Pload + Pbias
Pload = (Vin – Vout) * Iload
Pbias = Vin * Ibias
P = (Vin – Vout) * Iload + Vin * Ibias
Often the power dissipation of the biasing circuitry is much smaller than the power dissipation caused by the load. In such cases Pbias can be omitted from the calculation.
Example:
We have an LM7805 with an input voltage of 9V, and the load pulls a constant current of 100mA. Calculate the total power dissipation of the linear regulator.
Variables:
Vin = 9V
Vout = 5V
Iload = 100mA
Ibias = 4.2mA (datasheet!)
P = (Vin – Vout) * Iload + Vin * Ibias
= (9 – 5) * 0.1 + 9 * 0.0042 = 0.4378W
So the package will have to dissipate a little less than half a watt which is fine for a TO-220 package without heatsink.
The power dissipation due to the biascurrent of the regulator is about 8.6% of the total power dissipation. This is small but still something to keep in mind.