Making a buck converter

In my previous post I explained how to decide when you need a buck converter rather than a linear regulator. In this post I am going to explain how to build a buck converter into your project.

Drop in replacement

The simplest option, if you are used to using a linear regulator in a TO-220 package, is to buy a drop in replacement. For example Adafruit sell 1A 5V and 1A 3.3V drop in buck converters for just under $15 at the time of writing. Or for around $4.30 you could get a muRata OKI-78SR 1.5A 5V or 1.5A 3.3V module from DigiKey or Mouser.

From China

You can get small buck converters from China for a dollar or less, for an example search for Mini-360 buck converter. These are usually small PCBs with connection holes suitable for a wire or a header pin. The hole spacing is rarely breadboard compatible, but you can attach wires or carefully bend long header pins. They typically don’t come with datasheets, so you might want to test them before depending on the maximum advertised specifications. Shipping is slow, but you can’t beat the price.

Make your own

Finally you can make you own buck converter. Some reasons for building one yourself:

  • It is a great learning experience
  • You have complete control over and knowledge of the specifications
  • You can design the buck converter into the same PCB as the rest of your project

Picking components

There are thousands of buck converter ICs available. Your voltage and current requirements will help to narrow the field, but there will still be a large number to choose from. Other considerations are efficiency, frequency, circuit size, the number of external components, features, availability and price.

Small, simple and cheap

A common requirement is for a circuit that takes up a relatively small amount of board space at a reasonable cost. Unless you need a large amount of power a buck converter with built in MOSFETs will be ideal. While all in one modules do exist, they are currently much more expensive, so a few external components such as an inductor, capacitors and resistors are to be expected.

Efficiency, frequency and package

Improved efficiency means less heat is generated, requiring less space for thermal management, for this reason prefer synchronous designs that substitute a less efficient flyback diode for a second MOSFET. Higher frequency switching allows for smaller inductors and capacitors leading to a smaller design. Choose a package that matches you skills, avoid small packages like BGA unless you are used to working with them.

A handy search tool

Texas Instruments have a large number of buck converters, and nice tools for picking designs, you can try entering your criteria into the Power Quick Search tool.

And the winner is

My criteria for a recent project was a 12V input, 5V output and <500mA. I chose a Texas Instruments TPS560200 with the following specs:

  • 4.5V to 17V input
  • 0.8V to 6.5V output
  • 500mA maximum current
  • Synchronous
  • 80% efficiency
  • 600 KHz switching frequency
  • SOT-23 package
  • Light load efficiency, thermal protection and over current protection
  • Price about $0.89 for one, about $0.36 each for a real of 3000

This is a five pin SOT-23 surface mount component with about 0.04″/1mm lead pitch which should be manageable as a first surface mount design.

Picking passive components

A buck controller will generally need to be paired with the following components:

  • Input capacitor
  • Inductor
  • Output capacitor
  • Voltage divider resistors

The datasheet will provide guidance on how to pick the components. If you are using a TI buck controller then you can also use their WeBench tool to help you pick the right components for your design.

I don’t recommend the schematic and layout export from WeBench. My experience was that none of the wires were connected in the schematic and the board layout wouldn’t import into the free version of Eagle CAD.

Equivalent series resistance

In power circuits the capacitors are normally moving large amounts of current, so the equivalent series resistance, ESR, becomes an important consideration. For instance a typical 22uF electrolytic capacitor might have an ESR of 10 ohms whereas a multilayer ceramic capacitor might have an ESR of 10 mOhms (1/1000th).

In general:

  • Use ceramic multilayer XR5 or XR7 capacitors as they have very low equivalent series resistance. Otherwise look for low-ESR capacitors
  • You will generally pair a high frequency input bypass capacitor, usually 0.1uF, with a larger bulk capacitor, e.g. 10uF
  • You can use two capacitors in parallel to lower the ESR

Layout guidelines

There a several things to consider when laying out your circuit:

The current loop has high current slew rate so needs to be kept as small as possible to reduce parasitic inductance

    • Place the input bypass capacitor (small, high frequency) close to the IC
    • The input bulk capacitor should be reasonably close to the IC
    • Place the output capacitor close to the inductor
    • Connect directly to the ground plane

Removing heat

    • Use copper pours to improve heat dissipation
    • Use thermal vias to move heat to the bottom of the board

Watch out for noise from switching

    • Place the inductor close to the IC
    • Don’t expand copper to the inductor beyond what’s required for current
    • Keep the feedback return path away from the inductor and input capacitor

To improve efficiency

    • Don’t run ground plane under the inductor

Putting the rules into practice

Here is an example PCB layout for 5V 500mA Buck converter with breadboard friendly headers. U1 is a Texas Instruments TPS560200 buck controller IC. C1 and C2 are 10uF output capacitors. C3 is a 0.1uF input bypass capacitor and C4 is a 10uF input bulk capacitor. The R1 and R2 resistors act as a voltage divider on the feedback from the output to the IC. The ratio of the voltage divider determines the output voltage.

Buck Converter Layout

To minimize parasitic inductance in the current loop, the inductor and input capacitors are right next to the IC and the output capacitors are placed right next to the inductor. These current loop components are connected directly to a top layer ground pour which is connected to the bottom layer ground plane with lots of vias.

To maximize heat dissipation there are thermal vias underneath the IC and in the ground pour close to the IC to help move heat to the large ground plane on the bottom of the board. As this package doesn’t have a thermal pad around 40% of the heat will dissipate through the pins, so there are large pours connected to the ground pin and Vin pin.

To minimize switching noise the inductor is close to the IC and the connection to the IC hasn’t been expanded into a large copper pour. The traces and voltage divider resistors for the feedback signal have been routed away from the inductor.

Efficiency is optimized by adding a cutout in the ground plane under the inductor to avoid inductor efficiency being reduced by eddy currents forming in the ground plane.

Tented vias

Some of the thermal vias (smaller green circles) are very close to the SMD pads. This introduces some risk of an accidental connection to ground if the solder from the pads were to stray to the exposed copper of the via. To avoid this risk we can arrange for each via to be covered in solder mask, the term for this is a tented via.

OshPark PCB with Tented Vias

In the board above, ordered from OSH Park, you can see the 16mil tented vias. The annular rings of the small tented vias are covered in purple solder mask, whereas the annular rings for the large header pin vias are exposed.

Eagle CAD

To make small enough vias to fit under the package for your IC you may need to specify a new drill size if one of the default drill sizes isn’t appropriate. In Eagle CAD you can select a new 16mil drill size by selecting:

Change –> Drill –> … (New Drill)

Entering 0.016 (or 16mil) and then clicking on any existing vias you want to resize or using the “Draw a via” tool to create new vias.

The Eagle DRC (Design Rule Check) rules in Eagle typically specify that vias over a certain size should always have a stop mask. That is the copper annular ring should not be covered in solder mask.

Eagle Tented Via DRC

To ensure the thermal vias are tented (covered in solder mask) you should change the DRC rules so the stop mask is only automatically applied to vias larger than your selected tented via size, e.g. 16mil

Tools –> DRC –> Masks –> Limit –> 16mil

Then for vias 16mil or smaller you will be able to turn the stop mask on or off in the via properties.


Creating thermal vias, also referred to as via stitching, can be confusing in the current version of KiCad as lone vias created by the Tracks And Vias tool will become disconnected from the GND net when you refill the filled zones or run DRC. There are plans to address this in version 5.0 of KiCad, but until then there are a couple of workarounds.

The simplest, if not the prettiest, is to make sure that your vias are connected to a GND pad with a track. The tracks will be absorbed by the copper pour (filled zone) so they don’t affect the final PBC.

The other solution is to create a new “via” footprint in Footprint Editor and add this footprint directly to your board in PcbNew.

To create a via footprint:

  • Launch Footprint Editor
  • Click New Component
  • Make the Name and Ref text Invisible
  • Add a pad at the origin (x=0, y=0)
  • Edit the pad
  • Set Copper to All Copper Layers
  • Remove F.Mask and B.Mask from Technical Layers to make the via tented
  • Set the hole size (e.g. 0.016″) and pad size (e.g. 0.03″)
  • Set Copper Zones Pad Connection to Solid
  • Save to an existing or new library with a name like via-16mil

To add the via footprint to you board

  • Click Add Footprint in Pcbnew
  • Click on the board and select your new via footprint (e.g. via-16mil)
  • Edit the pad (not the footprint)
  • Set the Net Name to GND

You can do this again to add another via or use Duplicate Footprint to copy an existing via footprint.

A finished example

Here is an example of a completed breadboard friendly 5V buck converter.

500ma DC-DC Buck Converter on a Breadboard



Powering a circuit with linear regulators and buck converters

Most electronic projects need a stable voltage source, typically 5V or 3.3V DC. Here we discuss how to choose when to use a linear voltage regulator and when to use a buck converter.

What’s the difference?

The standard advice for beginners is to use a linear voltage regulator, for example an LM7805. Linear voltage regulators are great for low current draws and low voltage drops, but become inefficient and surprisingly hot when used for higher current draws or larger voltage drops. The reason for this is that they turn the excess voltage into heat.

Buck converters turn the input voltage on and off quickly (PWM) to generate a lower average voltage and smooth the output to generate a consistent output voltage. This makes them far more efficient: capable of dropping a large voltage at a higher current while dissipating less heat.

Which one should you use?

Which is best for your project depends on:

  • Cost
    Buck converters typically cost more, although that difference is diminishing as buck converters become more common
  • Efficiency
    How much of the power is available for your circuit and how much is wasted might be a concern especially if you are powering your circuit from a battery.
  • Heat
    Excess heat can be an issue especially if your circuit is in an enclosure. It is essential to understand how much heat you need to dissipate and have a strategy for getting rid of it.
  • Size
    For small loads linear regulators are usually smaller, but for larger loads buck converters can be smaller.

Voltage and current requirements

Before picking components you need to understand the voltage and current requirements of your circuit. You will need to match voltage specifications closely, but you don’t have to match current requirements exactly.

You will want sufficient current to power your circuit during its peak current draw. Having more current available than your circuit requires will give you a safety margin and will also enable your power supply to run cooler. However, you might be adding unnecessary cost and size to your project if you over specify too much.

As an example I want to power a circuit with 5V and 3.3V logic from a 12V input supply. I don’t expect to draw more than 50mA from the 3.3V supply or more than 200mA from the 5V supply. So I have a maximum current requirement of 250mA. To add a safety margin and ensure my circuit runs cool I would ideally be looking for something than can supply 500mA.

Dissipating heat in linear regulators

To get the maximum power (in Watts) that a linear regulator would need to dissipate we multiply the voltage drop by the maximum current.

Power Dissipated = Voltage Drop * Current

In my example to get to 5V from a 12V supply the linear regulator needs to drop 7V volts. If we assume that the 3.3V will be sourced from the 5V output then the we have a maximum current of 250mA.

Power Dissipated = 7 V * 0.250 A = 1.75 W

A linear regulator is limited by its maximum junction temperature, which is normally 125 or 150 °C. You can use the thermal information in the datasheet to estimate what this temperature would be in your application.

Thermal resistance measures how heat flow is resisted, similar to the way electrical resistance resists current flow. For a linear regulator standing in still air without a heat sink the junction to ambient thermal resistance measures how heat flow from the junction to the surrounding air is resisted.

To estimate the junction temperature rise above the ambient temperature you multiply the power that the linear regulator needs to dissipate by the junction to ambient thermal resistance specified in the datasheet.

Temperature Rise = Power * Junction to Ambient Thermal Resistance

We add the temperature rise to ambient temperature to get the junction temperature. It’s typical to use a value of 25°C (77°F), but the actual operating environment of your circuit could be a 21°C air conditioned home or a 105°C engine compartment.

Junction Temperature = Ambient Temperature + Temperature Rise

Check the datasheet of your component for the junction to ambient thermal resistance as this number varies between devices even within the same package. For example, just considering the ubiquitous LM7805 TO-220 1.5A linear regulator. Texas Instruments specifies 23.9 °C/W whereas ST specifies 50 °C/W and I have seen values as high as 78 °C/W in a TO-220 package.

The ST LM7805 datasheet specifies a maximum current of 1.5A and a junction-to-ambient thermal resistance of 50 degrees C/W in a TO-220 package. So we just multiply this by the number of watts we need to dissipate to get a temperature rise of 87.5°C.

Temperature Rise = 1.75 W * 50 °C/W = 87.5 °C

Assuming an ambient temperature of 25 degrees C we get a junction temperature of 112.5 °C, which is just below typical maximum gate temperature of 125 degrees C.

Junction Temperature = 25°C + 87.5°C = 112.5°C

So this TO-220 linear regulator would work fine as long as the ambient temperature is less than 37.5 degrees C (100 degrees F), but it would run too hot to touch without a heat sink.

Adding a heat sink

To dissipate more heat you can add a heat sink. This adds some additional cost and takes up more space. Also as you start dissipating more heat you might need to consider how heat is managed within your circuit enclosure.

To see the impact of a heat sink you need to calculate the new junction to ambient thermal resistance of the linear regulator plus the heat sink. To do this look up the junction to case thermal resistance of the linear regulator and the thermal resistance of the heat sink. Then add these two numbers together.

Junction to Ambient Thermal Resistance = 
    Junction To Case Thermal Resistance + Heat Sink Thermal Resistance

The ST LM7805 TO-220 has a junction to case thermal resistance of 5 °C/W, so if we attach a 23 °C/W heat sink from Adafruit we get a total junction to ambient thermal resistance of 28 °C/W.

Junction to Ambient Thermal Resistance = 5°C/W + 23°C/W = 28°C/w

Which would give us a junction temperature rise of 49 °C.

Temperature Rise = 1.75 W * 28°C/W = 49°C/W

Assuming an ambient temperature of 25 °C would give us a junction temperature of 74 °C. About the temperature of a hot beverage from your favorite coffee shop.

Junction Temperature = 25°C + 49°C = 74°C

Buck converters

Buck converters are not perfectly efficient and will generate some heat. How much heat can be determined by the efficiency specified in the datasheet.

To determine how much power is dissipated as heat we need to know the difference between the input power and the output power.

Power Dissipated = Output Power - Input Power

To get the input power we can divide the output load by the efficiency of the buck converter.

Output Power = Input Power * Efficiency

Input Power = Output Power / Efficiency

For instance the TI TPS560200 buck controller is about 80% efficient when converting from 12V to 1.05V at 250mA. It will likely be slightly more efficient when converting 12V to 5V. At 80% efficient the buck converter will dissipate 20% of its input power as heat.

In our example we have a 250mA load at 5V which is 1.25 W.

Output Power = 0.25 A * 5 V = 1.25 W

So the input power is 1.5625 W.

Input Power = 1.25 W / 0.80 = 1.5625 W

And the power dissipated as heat is 0.3125 W.

Power Dissipated = 1.5625 W - 1.25 W = 0.3125 W

The MOSFETs are contained within this IC and the MOSFETs account for most of the losses in a buck converter, so we are going to ignore that some of the losses are in the external components.

The datasheet specifies a junction to ambient thermal resistance of 166.8 °C/W. The junction to ambient thermal resistance isn’t a perfect metric as PCB design will affect the actual thermal resistance, but it’s good enough for us to work with as an estimate.

With 0.3125 W to dissipate the temperature rise would be 52.125 °C.

Temperature Rise = 0.3125 W * 166.8°C/W = 52.125°C

So with an ambient temperature of 25 °C the junction temperature would be approximately 77.125 °C.

Junction Temperature = 25°C + 52.125°C = 77.125°C

Additional voltages

To get 3.3V we could we could use the 12V supply directly (dropping 8.7V), but seeing as we already have a 5V output, we can drop 1.7V from 5V. At 50mA this would be just 0.085W for a linear regulator to dissipate.

Power Dissipated = 1.7 V * 0.050 A = 0.085 W

The Microchip Technology MCP1700T-3302E/TT is a 3.3V linear regulator in a 3 pin SOT-23 surface mount package. The datasheet quotes the junction to ambient thermal resistance of 336 °C/W. So the gate temperature with a 25 °C ambient temperature would be 53.56 °C.

Temperature Rise = 0.085 W * 336°C/W = 28.56°C

Junction Temperature = 25°C + 28.56°C = 53.56°C

So in this case a linear regulator is sufficient and a SOT-23 takes up very little board space (about 3mm by 3mm).

So for our example circuit a good choice might be to use a buck converter to drop from 12V to 5V and a linear regulator to drop from 5V to 3.3V.

In my next post Making a buck converter we look how to incorporate a buck converter into your circuit.

Arduino PWM MOSFET Gate Resistor


If you are driving a logic level MOSFET directly from an Arduino, or another Atmel AVR such as an ATTiny85, you may have wondered what value resistor should be placed between the output pin and the MOSFET Gate.

In the tutorials referenced by Adafruit and Sparkfun they connect an Arduino output pin directly to the MOSFET gate. But others insist that you need a current limiting resistor to protect the microcontroller output pin.

Voltage controlled device

A MOSFET is normally thought of as a voltage controlled device, sufficient voltage at the gate opens the MOSFET and allows a large current to flow through the drain/source. In this model very little current is required at the gate. So with this simplistic model of MOSFET operation a current limiting resistor is not required.

Charging the gate

However during switching a MOSFET behaves more like a capacitor that needs to be charged in order to open and discharged in order to close. The datasheet for a STP16NF06L 16A 60V logic level  MOSFET shows a 345nF input capacitance and a 7.3 nC total gate charge. Coulombs are a measure of capacity, current time in units of amp seconds. The datasheet quotes a 47nS on/rise time with a 4.7 ohm gate resistor, so it took an average of 7.3nC/47nS = 155mA average current to charge the gate – that’s far more than the 40mA maximum current for an Atmel AVR output pin. So with this in mind it’s important to protect the microcontroller with a current limiting resistor.

Charging speed

A MOSFET is an efficient switch when completely on or off,  but it is inefficient when switching and dissipates those losses as heat. The more resistance we put between the microcontroller output pin and the MOSFET gate, the more slowly the gate will charge and the hotter the MOSFET will run. This becomes particularly important if you are switching the MOSFET on and off quickly with a PWM output.

PWM stands for Pulse Width Modulation and is a method of controlling the average voltage output of a microcontroller pin by turning the output on (5V) and off (0V) very quickly. The duty load on an Arduino PWM pin can be set with analogWrite and ranges from zero, always off, to 255, always on. Set to 63 the pin would be on a quarter of the time so the average voltage would be 5V/4 = 1.25V.

LEDs have very fast switching times, approximately 20 nanoseconds for white LEDs, so when a PWM output is used to control the brightness of a LED the duty load determines what percentage of time the LED is turned on. As long the PWM frequency is greater than 200Hz the human eye cannot detect any flicker.

Microcontroller source resistance

If you look at an Atmel datasheet you will find a graph showing IO PIN OUPUT VOLTAGE vs. SOURCE CURRENT.

At 25 Celsius this this shows a nice straight line from 5V at 0mA to 4.5V at 20mA.


What this tells us is that the output pins have an internal resistance within the microcontroller,  (5V – 4.5V)/20 mA, which is 25 ohms. So the maximum theoretical current we can attempt to source with the microcontroller running at 5V is 5V/25ohms which is 200mA. This is considerably higher than the 40mA absolute maximum in the data sheet.

To get down to 40mA we need to add a 100 ohm resistor, 5V/125ohms = 40mA. To get down to the 20mA level, recommended by Arduino, would require 225 ohms, 5V/250ohms = 20mA, the nearest standard resistor value of 220 ohms is close enough.

A real world test

To see what really happens I hooked an ATTiny85 8kHz PWM output pin to STP16NF06L logic level MOSFET through a 100ohm resistor. I used an oscilloscope to measure the voltage with respect to ground on both sides of the resistor.

An oscilloscope can only measure voltage directly, but by measuring the voltage drop across the resistor we can calculate the current flowing. I used the math function of the oscilloscope to display the difference between the two signals.


This showed a maximum 2.5V voltage drop across the resistor during turn on and a maximum 3V voltage drop during turn off. So the current flowing was 2.5V/100ohms = 25mA during turn on and 3V/100ohms = 30mA during turn off, both under the 40mA absolute maximum. It’s a good idea to drive components below their absolute maximum ratings, so it’s nice to see that we are below 40mA.

So in summary a 100 ohm resistor between an Arduino or similar Atmel AVR output pin and a logic level MOSFET looks like a good balance between switching speed and protecting the output pin from damage.