Every electronic device includes a DC-DC converter for its power supply. That supply might come from a USB port, a "brick", a wall-wart, or in larger systems, there could be multiple point-of-load converters scattered around a single circuit board.
When you have a DC voltage that you need to change into another voltage, you have two options: a linear regulator or a switch-mode power supply design. Let's take a look at the difference between the two and a couple of cases where you might choose one or the other.
Linear Regulator
Linear regulators are straightforward devices that can only reduce voltage. In other words, their input voltage is always higher than their output voltage. That output is determined by a feedback network that monitors the voltage coming out and compares it to a stable reference. Often that reference is something like a Zener diode junction. A typical reference voltage is 1.25 volts.
On some linear regulators, you have access to that feedback network through a pin called "Feedback" or "Adjust." As an example, the LM317 LM317 is an adjustable regulator. It has three pins: input, output, and adjust. It is possible to "set" the output voltage to anything between 1.25 and 37 volts by using a voltage divider. Remember that reference voltage of 1.25 volts mentioned a moment ago? It comes into play with adjustable regulators.
The output voltage divider creates a voltage drop across R1 that is the difference between the desired output and the reference voltage. In the case of the LM317, it is 1.25 volts! From a user's perspective, that reference voltage only matters because you use it along with Ohm's Law to set the output voltage.
When you look at an LM7805LM7805 or the more modern NCP1117NCP1117, these regulators have the feedback network integrated into their silicon. That is the only significant difference between a fixed and adjustable linear regulator.
How do they work
One way to think of linear regulators is that they are voltage-controlled resistors. The regulator adjusts its practical resistance so that the voltage on the output node is at the desired level. This model also explains why linear regulators are so inefficient: they drop the voltage difference from input to output, like a resistor. Since the current going in is the same as the current going out, it is easy to calculate the linear regulator's power dissipation.
For example, a 5 volt NCP1117NCP1117 with 12 volts in and 5 volts out creates a 7 volt drop across the regulator. With just 100 mA of current, the regulator would have to dissipate 700 milliwatts. Another way to look at the conversion, it is only 40% efficient at delivering power to its load!
If you need the linear regulator is going to dissipate around 1 watt, you should consider a TO-220 or DPAK package. With the TO-220, I would still recommend a heat sink. And with the surface mount DPAK, make sure the PCB has a large copper fill connected to the package's tab.
Low Drop-Out
A common type of linear regulator is the low drop-out regulator. Low drop-out refers to the difference between the output and input voltage. Older regulator designs like the 7805 need the input voltage to be about 2 volts higher than the 5 volts out. A low drop-out regulator can function with as little as 1 volt difference. (and some even less than that.)
Unless you have a pile of older designs sitting around a modern LDO style regulator is a better choice. For general purpose work, the NCP1117 NCP1117 is one of my favorites to use.
Linear Regulator Decoupling capacitors
For proper regulation, there should be a small capacitor on the regulator's input and one on the output. To choose a value, the first place you should always look at is the datasheet. There may be special requirements, such as low (or high) ESR, or recommendations on size and type. Lacking specific information, here is a guideline I follow.
For modest loads (< 2 Amps), I place between 1uF and 10uF on both the input and output. If I have to use an electrolytic, I put a 100nF ceramic in parallel with it. (Unless the regulator says to use Tantalum, which means it expects high ESR. Skip the ceramics then.) Generally, I put a larger capacitor on the Input side than on the Output Side.
I have two reasons for that decision. First, the input capacitor is truly a decoupling capacitor. It is attempting to decouple the linear regulator from its source supply. So I want it to have plenty of charge available to respond quickly. On the output side, however, the larger the capacitance, the slower the regulator may respond. So at the regulator's output pin, I keep the capacitance relatively small.
Now, if you have a large load, like a motor, then that is where you might want to put another 10uF or slightly larger capacitor. (So that it decouples the load.) With all of that said, do not put a considerable capacitor, like 1000uF, directly on the output of a linear regulator. If the capacitor is too large, then it will cause the regulator's short circuit protection to trip during power-on, creating a "hiccup" operation. In short, if you're using more than 100uF for decoupling a linear regulator, you might need to re-think your power solution.
Switch mode Power Supply
A switching supply has an entirely different architecture compared to the linear regulator. Switching supplies, or "switchers," make use of the energy storage capabilities of capacitors and inductors.
Capacitors store energy in an electric field. Inductors, however, use a magnetic field to store energy. By charging and discharging these devices, it is possible to create output voltages that are higher or lower than the input voltage.
In a switching supply, a transistor charges up an inductor and then allows the inductor to discharge. The capacitor smooths out the ripple created by this charge and discharge cycle. Depending on the capacitor and inductor configuration, this arrangement could increase (boost) or decrease (buck) the input voltage. Switching supplies can also do both, in which case, they are a boost-buck converter.
Another advantage of a switching supply is that they are incredibly efficient. In the linear regulator, the transistor is always on and always dissipating power. A switching supply's transistor is either ON or OFF. When it is on, it has milliohm resistance. When it is off, it is open. In both cases, the dissipated power is meager.
Neither the transistor, capacitor, or inductor is ideal. So all three have some losses associated with them. However, it is still possible to design a switching regulator where over 90% of the input energy gets converted to the output. Even a poorly designed switching supply might be at least 70% efficient. Not bad when compared to the linear regulator's 40% efficiency, eh?
The trade-off comes in the design process. Switch-mode power supplies are sensitive to values picked for the inductor and capacitor. You have to pay attention to characteristics like the capacitor's ESR. When laying out a PCB for a switching supply, you need to follow stringent rules. If not, there can be a large amount of ripple voltage, poor performance, and EMI issues from the switching elements. Fortunately, most switch-mode ICs have well-written application notes to describe their proper design.
Linear vs. Switching
You might be asking, "when do I pick one or the other?" The first question to ask is: do I want a power rail that has less noise or is more efficient. If you're building a device that runs on battery, efficiency is probably more important, so you would likely pick a switching regulator.
For applications like audio, linear regulators offer benefits like lower noise. The switching elements of a switching supply can cause ripple on DC power rails. That ripple can make their way into audio circuits, which is not always desirable.
Okay, now you might ask, "what if I need both high efficiency and low noise, then what?" Because of how quickly they can respond to changes in their input, an LDO after a switching supply may filter out some of the switcher's noise. So one example might be to use a switching supply to step down from a high voltage to near the point-of-load voltage. Then drive into an LDO.
In short, linear power supplies are cheap, simple, but inefficient. While switching power supplies are very efficient, but can be complex to design.
Do you have experience or fears with designing in either? If so, let me know in the comments.