This article was originally published on Digital-DIY and is an original work by Jon Chandler. It is licensed under a Creative Commons 3.0 BY SA agreement.
Featured on Hack-A-Day.
One thing all of our projects need is a power supply. Sometimes batteries are the best answer, but often a AC line-power - DC supply is the right answer. Linear power supplies are easy to build but a "wall wart" is usually cheaper and easier to use. Wall warts come in a confusing array of shapes and sizes. This article will cover some power supply basics and provide guidance for selecting and using these useful power supplies.
In order to select an appropriate power supply, several factors must be considered.
The first consideration in selecting a power supply is whether the board you're powering has a voltage regulator. If you designed the board, you should know :) If you're working with a dev board, the acceptable supply voltage should be specified in the documentation. Using mrbasher's board as an example, if the board has a regulator, it will usually be located near the power connector and look something like the photo below. Not all voltage regulators use this TO-220 package shown but it is quite common.
The next consideration is what voltage the parts on the board actually need. Many PIC circuits require 5 volts but 3.3 volts is becoming common too. If the board does not have an on-board regulator (the TAP-28 board is a prime example), we'll need a regulated power supply of the correct voltage. If there is a regulator on the board, the power supply will have to supply a voltage higher than the regulator voltage + the regulator dropout voltage. Some details follow.
The next consideration is how much current the board draws. This is the current to power the chips, light the LEDs, power anything attached to the board and to support any pull-up or pull-down resistors on the board. LEDs and other things attached to the board are probably the biggest draw. Still using mrbasher's board as an example, the resistors look to be 270 ohms, and a typical green LED has a voltage drop of 2.1 volts, so
We'll call it 11 mA per LED x 8 LEDs = 88 mA when all the LEDs are illuminated. The current for the PIC and the 74HC595 shift register won't add much, so our power budget is around 100 mA.
Our power supply has to supply at least 100 mA, but more current is ok.. The circuit draws only the current it needs to operate. If the power supply is rated for say 1000 mA, it's going to be perfectly happy loafing along supplying 100 mA or less.
Back to the question of what voltage is needed. Assume the voltage regulator is an LM7805. The dropout voltage for a LM7805 is 2 volts. Think of this as the overhead it needs to work. The maximum voltage an LM7805 can handle is 35 volts. So any voltage between 7 volts (Vreg + Vdropout) and 35 volts (the maximum voltage) will provide a 5 volt output from the regulator. Piece of cake.... Unfortunately, it's not quite this simple. LDOs (low dropout) regulators are available that reduce the needed overhead voltage.
The LM7805 is a linear regulator (the following applies to all linear regulators). The current into the regulator is the same as the current out of the regulator. Our circuit uses about 500 mW maximum (5 volts x 100 mA = 500 mW). If we supply 35 volts to the regulator, a total of 30 volts is dropped or lost across the regulator. 30 volts x 100 mA = 3 watts. Where does this energy go? Heat. Have you ever burned your finger on a night light bulb? They draw 4 watts. Our regulator isn't going to be too happy dissipating this much power.
The voltage supplied to the regulator should be close to the voltage it needs to work to minimize power dissipation. What happens if we supply it with 9 volts? The drop across the regulator is 4 volts, so the power is 400 mW. This change drops the power dissipation by a factor of 10 and now our regulator is happy. How high a voltage level is acceptable depends on the current draw of the circuit. If the current draw is high, the voltage should be close to the voltage needed by the regulator. If the current draw is low, there's more latitude. The maximum allowable voltage depends on the actual regulator used. The equation below is the power dissipated by the regulator:
Current must be greater than the maximum draw of the circuit being powered but anything larger is ok
Voltage for a board without a regulator must be regulated at the voltage required
Voltage for a board with a regulator must be greater than Vreg + Vdropout but not too much higher
A linear power supply is pretty simple. A few principles will help in understanding how to use wall warts. A transformer reduces line-level AC to a lower voltage. The low voltage is converted to pulsing DC using either half or full-wave rectification as shown below. Half-wave rectification uses only one side of the AC power; full-wave rectification "flips over" the negative part of the sine wave so it uses the full potential of the AC power. The pulses vary in level between 0 volts and √2 x the RMS voltage of the transformer. As an example, the peak voltage from a 12 volt RMS transformer is almost 17 volts. The illustrations below neglect the voltage drop across the rectifier diodes, which is a function of diode type and the current through the diode.
The magenta lines above show the resulting waveforms. This pulsating voltage isn't too useful for powering circuits. A large value filter capacitor must be added to the basic circuit to provide a DC voltage. The capacitor charges to the peak value when the pulsating wave is at the peak and discharges through the load until the next cycle of the sine wave as shown below.
The ripple voltage depends on the value of the capacitor and the load current. Drawing more current increases the ripple. A larger value of filter capacitance reduces ripple.
The load current effects the RMS level of the transformer and the voltage drop across the rectifier diodes . As the load increases, the voltage falls.
Without a regulator, the output voltage and ripple are dependent on load current.
Adding voltage regulation to a basic linear supply is simple, often requiring nothing more than a regulator and a couple capacitors, as shown below. You may wonder about the input capacitor in parallel with the filter capacitor. Since they just add together, adding a tiny amount of capacitance to the large filter capacitor doesn't seem to accomplish anything. The smaller capacitor reacts better to high frequency transients.
They circuits are included here to aid in understanding how to use wall wart power supplies. These basic circuits are functional but improvements can be made for specific applications.
A detailed description of switching power supplies is beyond the scope of this article. Wikipedia has a nice explanation of their operation. A key feature for our discussion is that the output voltage of switching power supplies is most often regulated although some switching power supplies are designed for other purposes, such as being a constant-current supply for driving LEDs.
Wall warts are those ubiquitous power supply modules that come with cell phones and many other electronics products. Wall warts that are intended to power electronics are well designed power supplies and can be useful for many different applications, including powering development boards and finished projects. Some wall warts that are built to run electric razors and charge batteries of cheap devices may not be suitable for our applications.
Wall warts fall into three basic types:
AC Output: these are essentially just the transformer shown in the examples above and provide low-voltage AC power. The receiving device must have the rectifiers and rest of the circuitry shown above. These are not too useful for our intended purpose.
Linear DC Supplies: These units have a transformer, rectification circuit and usually filter capacitors shown in the circuits above. Rarely do they include voltage regulators, so the output voltage is a function of load current. These are ideal for devices with on-board voltage regulators, but should not be used with devices requiring a regulated voltage.
Switch mode DC Supplies: These units use switch mode technology to convert line-voltage AC to regulated DC. A supply of this type of the correct voltage may be used to power a circuit requiring regulated voltage or may be used to power a circuit that includes a regulator as long as its output voltage is greater than the regulator operating voltage.
In order to demonstrate the differences between linear and switch mode supplies, I've tested a number of supplies to show how they react to output current. The first group of supplies tested includes a total of 7 linear supplies and switchers rated at 12 volts and between 1 & 1.6 amps output. The photo below shows the collection of power supplies. Photos and ratings of each supply follow. As you can see, they come in many shapes and sizes. Wall warts are available across the voltage and current range; these 7 wall warts were selected because they have similar specifications. Supplies of other voltages will behave in the same way. Clicking on the ratings or plot links for each wall wart will bring up detailed rating information and test data.
The results clearly break down into two groups: 1) those that maintain the desired voltage over the load range and 2) those whose output voltage varies widely with load current. One of the supplies puts out nearly 17 volts when it's unloaded. That would be bad news if our circuit was expecting a regulated 12V supply!
If you compare the above measurements to the details of each supply above, you'll see that all of the measurements that vary widely from our target of 12 volts come from linear supplies. The group that is close to our target of 12 volts contains the switching power supplies.
Let's look at the linear supplies in more detail. The graph below shows that at light load, the voltage is higher than the rated voltage. The output voltage is near the rated value only when the full load is drawn. This is exactly what's expected from the basic DC supplies without regulators discussed above. Linear wall warts seldom if ever include voltage regulation, usually consisting of a transformer, rectifiers and filter capacitors.
Since linear supplies usually do not include voltage regulation, they are only useful for supplying circuits that have an integrated voltage regulator. Keep in mind that the power supply voltage must be greater than Vreg + Vdropout. If the regulator is a standard dropout type, correct operation of the regulator with a 12 volt supply like these shown is only ensured for a maximum regulated voltage of 10 volts.
The switching supplies are suitable for both boards requiring regulated voltage or having an integrated regulator if the output voltage is greater than the regulator's operating voltage.
Now that we know a little about what's needed in a power supply and the output characteristics of some representative units, let's consider the practical aspects of putting them to use.
The first question, why a wall wart over alternatives? If you're testing a circuit on the bench, a lab power supply is a nice option. You can adjust the voltage to what you need and even examine the affects of changing the voltage. Some supplies include metering to keep an eye on current draw. A PICkit 2 or PICkit 3 is great for powering microcontroller circuits too.
At some point you'll want to deploy your device in the real world or you may want to keep your circuit running while you use for lab supply for something else. Options include powering by batteries which works great for 3.3 volt chips like the PIC18F25K20 but this isn't a practical solution for a device that's going to run full time. If a line-powered supply is desired, you could build one as shown near the start of this article, but transformers aren't cheap and you'll need a bunch of other parts and an enclosure. Often, using a wall wart is the cost-effective, expeditious answer. You may have some leftover from long-ago replaced cell phones and other electronics, but if not, most thrift shops and computer recyclers have dozens to choose from in many different voltages and current ranges.
For a couple bucks, you can get a high quality, UL or CSA rated supply and have no worries about hazardous voltages. This is cheaper than the postage to buy the parts to build your own.
So how do we know if a wall wart is a linear or switcher supply? Here are some typical characteristics:
A liner supply has a transformer similar to the photo at left. The transformer has an iron core (the gray laminations in the photo) with copper wire wound around it (the paper-covered part with the leads sticking out) so it's fairly heavy. The housing will be roughly cube shaped to allow room for the transformer with a little extra room for the rectifiers and filter capacitors. The picture at right shows the transformer, 4 rectifier diodes in a bridge arrangement and a filter capacitor.
Notice that the filter capacitor shown is relatively small. Some linear supplies skimp on filtering, which will result in larger ripple levels. With some supplies, additional filter capacitors prior to the voltage regulator will be needed.
(photos courtesy Wikipedia)
A switching power supply uses a much smaller transformer, possible because it's operating at a high frequency (several kHz or higher), so this type of supply will be smaller, lighter and not constrained to a cube shape. The photo below (from hackedgadgets.com) shows a typical switching power supply. Note the small transformer, surrounded by additional components. Switching power supplies are also able to handle a wide range of input voltage and are often designed to be compatible with power systems around the world.
(photo from HackedGadgets.com)
If you refer back to the power supply details above, you'll see these characteristics. Particularly note the "energy density" which is rated output power (watts) per gram. The switching supplies output about ten times more power per gram. If you click the rates link next to each supply, you can see the ratings for each supply.
Wall warts are designed for many purposes and it's often not
possible to tell from the nameplate if there are any unique features
that could interfere with our re-purposing. Therefore, I would
suggest a quick check with a voltmeter before connecting an unknown
supply to a circuit. Some switching supplies of older designs
don't work properly at no load which our simple testing will also check.
connector but you can't find a supply with the correct ratings and a mating connector, you might buy two wall warts - one with the correct output ratings and a second with the correct connector. If you do find a supply with the correct size of connector, be sure to check the polarity as well. There is no standard arrangement. Polarity is often marked on the enclosure.
Two parameters are important to coaxial power connectors in addition to polarity. The OD (outer diameter) and ID (inner diameter) of the plug must match the socket. If the OD is too large or the ID is too small, the connector simply won't fit. A worse situation is when the OD is correct but the ID is too large. The connector will appear to fit, but the clearance between the inner sleeve of the plug and the pin of the socket can be so large that they don't touch at all and no connection will be made.
Something to watch out for is reversed coaxial connectors. Rather than a hole (sleeve) in the middle, there's a pin. These are used on some computer power supplies; there's actually a third contact on the inside of the connector for data communication to validate the supply.
If the connector is wrong or not needed, cut it off; you may wish to leave some length of cable on the connector just in case it turns out to be the right size for something else. Strip the jacket to expose the conductors. You'll probably find one of three situations: 1) the cable is zip cord and the 2 conductors can easily be separated, 2) the supply has a round cable with 2 conductors inside or 3) the supply has a round cable with a insulated center conductor and outer shield. If your supply has more than 2 conductors, it may be a multi-voltage supply or it may contain additional circuitry to charge batteries or for some other function.
The photos above show two types of cables that may be found. The color of the conductors may or may not indicate polarity. It's always safest to check since mistakes may damage your dev board or circuit.
Measure the DC voltage from the supply, paying attention to polarity. If the color code is not something like red (positive) and black (negative) as is the case in the left picture, it's a good idea to label the cable to avoid problems later. Also note the voltage. If you have a regulated switching supply, it should measure approximately the value shown on the nameplate. If this is the case, the supply should be ready to use with no minimum load required. If the supply is a linear unit, it may measure up to √2 x the nameplate voltage. For a 12-volt rated supply:
Once the voltage and polarity is verified, the power supply can be connected to the dev board or other circuit. If the connection is made using a terminal block, connect the leads ensuring correct polarity. If the supply has the mating connector for the circuit, plug it in. If the connector on the power supply doesn't fit, a new one can be installed. A new connector might be soldered on to the cable or a connector salvaged from another power supply. If splicing on a salvaged connector, a Western Union splice covered with heat shrink tubing is an excellent way of making the connection.
The above comparison of 12 volt supplies is a good summary and illustrates the differences between linear and switching supplies. Since many of our circuits require a 5 volt supply and there are some unique features with 5 volt supplies, I've tested a small sample of these as well. This collection only includes regulated 5 volt switchers as there are few if any linear wall wart supplies in this category. Cell phone chargers are easy to find which supply 500 mA or more.
Two unique types of power supplies in this group are USB power modules (supplies J & K above) which have a connector for a USB cable and supplies that have a cable fitted with a USB connector. This is handy for powering a board that has a USB connector, such as the TAP-28 board. Be aware however that USB connectors come in several sized and types; a good eye may be necessary to select the desired connector.
Output voltage vs percentage load for the group of 5 volt supplies is shown below. The plot shows an interesting feature of some switching supplies - the output is self-limiting in the event of overload to prevent damage to either the supply or whatever is connected to it. The dashed vertical magenta line is the rated output level. If the current draw is in excess of the rated load, the voltage falls dramatically, limiting power dissipated in the supply.
We've covered some basics of power supplies in this article to aid in understanding wall wart performance, learned how to determine what voltage a dev or application board requires and considered linear vs switching power supply applications. We can make the following conclusions about wall wart power supplies:
Wall warts provide an easy, cost effective means of powering microcontroller boards.