How to Build a Buck Converter with a PIC Microcontroller

Constant Current Verification

Close up photograph of current (measured in milliamps) by the microcontroller in the buck converter circuit.
Close up photograph of current (measured in milliamps) by the microcontroller in the buck converter circuit.

Please Select an Efficiency

How does 10% efficiency sound? Pretty bad? I thought so too. I decided to build a buck converter circuit for an ultra miniaturized high power controller. When I say high power I'm talking about four channels, each at 25 watts, all enclosed on a 1" square PCB board. That's pretty power packed. My buck converter, designed and built from scratch, operates at 85% efficiency and generates virtually no heat to the touch as it sends high wattage to the circuits (shown in this demonstration as a halogen bulb, for example).

Modern buck converters can exceed this rating and it's not altogether uncommon for a 90% to 95% buck converter to be seen in the wild. I saw 97% in a datasheet recently. However, to build your own circuit, of such high efficiency, requires very specific component placing and small trace lengths between parts. It's almost impossible to do this without fabricating the whole circuit on a single silicon die. This is the advantage of buying monolithic buck converters, although they are more expensive.

One of the prominent features my design employs is a built in high precision internal current gauge, which it uses to attempt an auto efficiency calibration!

Overview of the microcontroller side of the circuit. The microcontroller multiplexes the 4 7-segment displays as well as controlling the proportional-integral software to monitor the buck converter.
Overview of the microcontroller side of the circuit. The microcontroller multiplexes the 4 7-segment displays as well as controlling the proportional-integral software to monitor the buck converter.

The picture above illustrates the four digit, 7-segment, display used on my circuit. I'm using the PIC18F2525, which is probably my favorite 8-bit microcontroller, but it doesn't have many I/O pins. So, I am forced to multiplex the screen, which worked nicely with my high brightness green displays. The number is read from top to bottom, which is left to right, in the photo. Currently, it says, 0620 milliamps (0.62 Amps), which is referring to the amount of current consumed in the output stage of the buck converter.

To read the current draw, I first send the output power through a 0.047ohm - 2 watt resistor, which hardly affects anything. Then, I measure the voltage across this resistor, which is close to zero. Instead of reading it directly with one of the microcontroller's ADC lines, I first send it to an op-amp for amplification. Then, the output is fed into the microcontroller and a simple multiplication factor is used to tune the read-out for the actual current consumption. I backed up these readings with a high precision multimeter. It works well over the full range!

The microcontroller also reads the voltage at the buck converter's output, in a similar fashion. By multiplying the voltage and current together, the power output (in watts) is immediately determinable. Then, I simply do the exact same thing for the input power line to the circuit, including the power used to drive the microcontroller and the op-amps themselves, and determine the total power input. This whole setup requires a total of 4 ADC lines, which fortunately the PIC18F2525 has.

Now... since efficiency is essentially output power (Pout) divided by input power (Pin), we determine the efficiency in percentage form as: Eff = Pout/Pin*100, which for my circuit was 85%. Of course, to get this high I went through days of tuning, calculating, recalibrating, redesign, theoretical research, until finally, I made it here!

Visible here is the main components of the buck converter, like the inductor coil, and switching Schottkey diode. The halogen bulb is brightly illuminated by it's high current output.
Visible here is the main components of the buck converter, like the inductor coil, and switching Schottkey diode. The halogen bulb is brightly illuminated by it's high current output.

Let there be LIGHT

The buck converter seems to have no problem driving a 25 watt halogen. This light bulb gets too hot to get close too, but the MOSFET, inductor, and switching diode, are all cool to the touch. In fact, I can't even tell if they're warmer than ambient by hand. By calculation, however, they should be about 5-10 degrees Celsius warmer than the room temperature.

My finished circuit has to have four independent circuits all potentially driving a 25 watt load. It is very important when space is limited, and power control is high, to have very good efficiencies.

Overview of entire breadboard. All components can be seen here. The buck converter and ADC circuits are at the top, while the microcontroller and digital readout are at the bottom.
Overview of entire breadboard. All components can be seen here. The buck converter and ADC circuits are at the top, while the microcontroller and digital readout are at the bottom.

Auto Calibration

While a set of formulas and a lot of electrical theory background would allow one to calculate the components' values which would yield the highest efficiencies, what happens when the situations dynamically change? In my example, the circuit must be able to take an input of any voltage from 3.6 to 25 volts. To complicate matters, the load output (LED, light bulb, etc.) may be selected arbitrarily. If the circuit has the power to drive it, then it needs to drive it! AND... it needs to do so with constant current regulation and overload protection.

To achieve the constant current part, I implemented a proportional-integral-controller, which automatically adjusts to maintain the brightness by adjusting the PWM duty cycle, based on the current output, measured by the ADC. The circuit does this over 10,000 times per second! Additionally, the circuit performs what I call, "experiments". These are it's own things it does, to maximize the efficiency. It attempts to modify the PWM frequency, MOSFET switching timers, and such, to raise that self measured efficiency rating. Then, with some genetic programming algorithms and a touch of intelligence, the software evolves to approach maximum efficiency.

ULTIMATELY: No matter what the input voltage, no matter what the output load, the circuit WILL adapt, staying cool, saving battery life, and controlling a lot of power!

Now I just have to build 3 more of these and cram them into a 1" square PCB! At least its double sided and 6-layered!

More by this Author

  • Alternative Biochemistries Available to Life
    1

    Arsenic based DNA example - click for source All life on Earth needs carbon, hydrogen, nitrogen, oxygen, phosphorous, and sulfur. These are the elements which all known life, ever discovered, always contains. But now,...

  • Make Your Own Wattmeter With A Microcontroller
    6

    A typical commercially available watt meter watt meter example Inside a watt meter. This is the current sense board which converts the current into a voltage which can be interpreted by a microcontroller. The...

  • Energy Density Comparison
    4

    Almost always, people misunderstand the notions of energy density. For example, people often ask me why cars still use gasoline and not lithium ion batteries for example. The answer to this is straightforward. Batteries...


Comments 4 comments

Henk Hofstra 5 years ago

hi

Can you share this Project with me? I am looking for a buck convertor for a wind-mill.

Thanks in advance.

Henk@can-west.nl


Jitin 4 years ago

can you please mail me the circuit of just your buck converter. I wanna make a buck converter with high efficiency but could get only 30% efficiency


npolynomial profile image

npolynomial 4 years ago Author

30%!! Don't feel bad, it's a start. I progressively refined this circuit originally from 30%. When I reached 65% efficiency I was pretty excited, and it took a lot more work to get any higher. You need to choose quality parts and keep all traces on the circuit board to a minimal, lots of copper. On a breadboard efficiencies will always be less than on the finished circuit board. I never drew the schematic, but when I get some time I will post one.


piccontroller profile image

piccontroller 18 months ago

what is the rating this buck converter?

    Sign in or sign up and post using a HubPages Network account.

    0 of 8192 characters used
    Post Comment

    No HTML is allowed in comments, but URLs will be hyperlinked. Comments are not for promoting your articles or other sites.


    Click to Rate This Article
    working