Category Archives: Just For Fun

Experimenting with Buck Converters

If you’re like me, the first thing you do when wiring up a new circuit is to connect the power and ground rails (with the power source initially turned off… maybe).  And you’ve probably got at least one power supply that’ll do the job.  But what if you didn’t have the supply you needed?  Perhaps all you’ve got is a 12V battery, and you’re in need of a 3.3V source.  Well, if you’ve finished your chores, I hear Tosche Station will sell you some power converters.  Failing that, you could always build your own.  A simple buck converter will likely do the trick:

The Standard Buck Converter (via Microchip)

The buck converter takes a DC input voltage and reduces it by a controllable amount, much like a resistive voltage divider.  But unlike your average voltage divider, the buck converter can efficiently supply a substantial output current.  In fact, this circuit’s output current should be greater than its input current (on average).  And no, that doesn’t violate any laws of physics; the converter’s output power will still be less than its average input power because its output voltage is lower than the voltage at its input.  In mathematical terms, (PIN = VINIIN) > (POUT = VOUTIOUT), where IOUT = ILOAD above.  Make sense?

Now clearly this isn’t your typical linear regulator.  Not with that inductor sitting there anyways.  So just how does it work then?  Well, the key is in the switching action of the p-channel MOSFET – a fact that leads us to call such circuits switching regulators.

Think of the FET as a simple switch.  When this switch is on (conducting), the current through the inductor (L1) will  ramp up (since VIN > VOUT), as will the voltage at the output capacitor.  But we don’t want the output voltage to go as high as the input voltage.  So, after a very brief on-time, we turn the switch off again.  But once the FET stops conducting, the inductor’s current has to go somewhere.  Well fortunately we have diode D1 available – it provides a path for current to continue to circulate (out to the load, back to ground, up through the diode and back to the inductor).

Here’s the trick though: this on-off switching cycle happens over and over again, many thousands of times per second.  In fact, the more frequently we switch, the smoother our output voltage will become.  This is because we have an output capacitor picking up the slack (so to speak).  During the switch-off periods, as the inductor’s current drops, COUT supplies the bulk of the output current (ILOAD).  Once the FET is switched on again, the inductor’s current ramps back up and recharges the output capacitor.  Thus, we maintain a constant ILOAD while the capacitor absorbs the ripple current (IRIPPLE).

Now as you may have already guessed, the ratio of the input to the output voltage is determined based on the relative lengths of the switch’s on and off periods.  This is a method known as pulse-width modulation (and it’s used in tons of other circuits):

Typical PWM Waveforms

If the switch were turned on 100% of the time, the output voltage would eventually equal the input voltage.  On the other hand, if the switch were on 0% of the time, the output voltage would be zero.  So it makes sense then that the output voltage is equal to our duty cycle (the percent on-time) times our input voltage.  In other words, if the switch is on for 50% of a cycle, in theory VOUT = (50%)(VIN).  Now in practice, non-ideal components will cause the required duty cycle to be higher than expected, but we’ll get to that later.

By the way, if you’re wondering how to go about picking component values for your own buck converter, there are equations for that.  But instead of going into all of the details here, I’m going to refer you to this excellent guide (and video) from Microchip.  It’ll walk you through an example design for a 12V to 5V, 2A buck converter.

The Experiments

So this past Sunday I was in my “lab” (aka the table in my basement) and decided to see how efficiently I could build myself a buck converter with the parts I had on hand:

yay for protoboards!

I’ve laid out my circuit almost exactly as shown in the schematic above (ignoring the four ceramic filtering capacitors connected across the four parallel supply rails).  On the left is my p-channel MOSFET, followed by diode D1.  The large green and black thing is, you guessed it, the inductor (which I scavenged from a broken battery charger).  To the right of the inductor are three capacitors in parallel (I’ve done this to get better output filtering characteristics at high frequencies).  The white and black wires you see leaving the right side of the board are connected to my resistive load.  The circuit is configured like so:

  • VIN = 10V
  • PFET = IRF9540
  • D1 = 1N4004
  • L1 = 100uH
  • COUT = 270uF (effective)
  • FSWITCHING = 52kHz
  • D = 62%
  • VOUT = 5V

I should also note that these component values were chosen based on an expected load current of 1A and a ripple current of 0.3A.  I only had the one good inductor to play with, so I computed my switching frequency based on its value.

Experiment #1 (Bad Diode)

For this first test, utilizing the 1N4004 general purpose diode, I measured the following:

  • PIN = 8.7W
  • POUT = 5.1W
  • Efficiency = 59%
  • TPFET = 120°F
  • TDIODE = 149°F
  • TINDUCTOR = 82°F

Alright, so while an efficiency of 59% isn’t terrible (particularly by comparison to the 50% you’d achieve using a linear regulator), it’s not great either.  Simple buck converters are typically 80-90% efficient.  So unless my measurements are way off, clearly something’s not right here.  Based on the temperatures I measured using my Kintrex IR thermometer, I suspect the diode may be our efficiency bottleneck (since it’s the warmest component).  To find out, let’s measure a few voltage waveforms while the circuit operates:

Buck Converter Test #1 Scope Trace

The top waveform, in pink, is our measured 5V output, shown at 5V/div.  Below that, in green, is the voltage measured at the connection between D1, L1, and the FET, shown at 10V/div.  At the very bottom, in yellow, is our gate drive signal.  When this signal hits 10V, the p-channel FET will be off; when it’s at 0V, the FET will be conducting.  Note that because of this inverse relationship, the duty cycle calculated by the scope (~38%) is incorrect; we need to subtract this value from 100% to get our true duty cycle (~62%).

So as I suspected, the diode is clearly having some issues.  See that big (~25V) negative voltage spike across the diode each time the FET turns off?  Yea, that’s not so good.  It means our diode isn’t turning on as quickly as it should.  This puts additional stress on the FET.  But when the diode finally does turn on, it’s showing a voltage drop of just over 0.9V.  During the switch-off period of a cycle, the diode has to conduct, on average, the full load current of 1A.  Since our duty cycle is 62%, the diode will be conducting 38% of the time, meaning it conducts an average current of 0.38A.  Using P = IV, we can determine that the diode is dissipating at least (0.38)(0.9) = 0.34W.  The diode’s turn-on delay probably accounts for more loss, but I’m not entirely sure how to calculate that.

Experiment #2 (Schottky Diode)

Well let’s just see what happens when we substitute a much better Schottky diode (15TQ060) in place of that lousy 1N4004 rectifier.  Here’s the data from test #2:

  • PIN = 5.5W
  • POUT = 5.1W
  • Efficiency = 93%
  • TPFET = 81°F
  • TDIODE = 81°F
  • TINDUCTOR = 80°F

Wow, that’s quite a difference in efficiency (from 59% to 93%)!  And it’s all thanks to the minimal (<0.3V) forward voltage of that Schottky diode, as well as its fast turn-on time.  Our waveforms are starting to look a lot cleaner as well:

Buck Converter Test #2 Scope Trace

Experiment #3 (More Current!)

So what happens if we now decide to turn up the heat a little?  What if we suddenly decide to supply a 2A load instead of 1A?  Well, I tried just that.  Here’s what happened:

  • PIN = 12.8W
  • POUT = 10.5W
  • Efficiency = 82%
  • TPFET = 96°F
  • TDIODE = 85°F
  • TINDUCTOR = 81°F

Hmm, it seems our efficiency has dropped again.  But not unexpectedly.  Based on the temperatures of the components, it seems like our FET may now be the limiting factor.  And no surprise; the p-channel device I’ve chosen has an on-state resistance of ~0.2Ω.  Using P = IV = I2R, and multiplying by the duty cycle (the switch on-time), I get:

P = I2RD = (22)(0.2)(0.62) = 0.50W

And even at 0.3V, the diode is still dissipating substantial power as well:

P = IV(1-D) = (2)(0.3)(1-0.62) = 0.23W

Now unfortunately, I don’t have a better p-channel MOSFET to try out at the moment.  So I’m just going to have to accept those losses for now (shame on me).  However, there is a way to nearly eliminate the losses of the diode: replace it with another FET!

The Synchronous Buck Converter (via Microchip)

This time I’ll be using an n-channel MOSFET which, as you may know, contains it’s own diode (called the body diode; the p-channel FET contains one as well, but I’ve omitted it in the diagrams above).  But we won’t be relying on that diode to handle any current.  Instead, we’re going to switch on the n-channel FET whenever the p-channel FET turns off (they’ll be complimentary).  In doing so, we’ll create a low resistance path (<0.1Ω) through which the ripple current can continue to flow during the P-FET’s switch-off period.

Sadly, I can’t claim credit for this brilliant idea.  I’m not sure who first thought it up, but it’s called the synchronous buck converter (as opposed to the asynchronous, or standard, buck converter).  I imagine this is because you have to operate the two FETs in sync with one another.  This makes life a little tricky, as you don’t want to accidentally turn on both transistors at once (thus creating a short from power to ground).  But it’s not bad.

Here’s a scope trace showing the n-channel FET’s additional gate drive signal (in purple):

Buck Converter Test #4 Scope Trace

Experiment #4 (More Current, More FET!)

Well I’m sure you’re just dying to know how much of an efficiency improvement this synchronous converter will provide.  Well fear not, here are the results of my last test:

  • PIN = 12.0W
  • POUT = 10.4W
  • Efficiency = 87%
  • TPFET = 96°F
  • TNFET = 84°F
  • TINDUCTOR = 82°F

Indeed, this is an improvement!  We’re not quite back to the 93% efficiency we saw at a load current of 1A, but 87% is still better than 82%, no?

So, lessons learned?  Use quality components.  That means FETs with as low an on-resistance as possible.  And if you don’t want to go with the synchronous converter, make sure you pick a fast diode with low forward voltage.

By the way, although I haven’t done it here, you’ll probably want to wrap your buck converter in a controller of some kind (unless your load current will be fairly constant).  If you don’t, with a constant duty cycle, variations in load will cause your output voltage to change by a fair amount.  Fortunately, If you look around the interwebs, you’ll find a number of ICs that provide buck converter control.  But if you’re clever, you could whip up your own op-amp control circuit.  Or just program an AVR to do the job for you – they’re great at PWM.  Give it a shot and let me know how you make out.

One last thing: if you’ve been counting, you’ll notice that the losses I’ve calculated don’t add up to the difference between input and output power.  Lest we forget, there are still resistive losses in the inductor and output capacitor, as well as switching losses on the transistor(s).  This switching loss has to do with the power dissipated in the FET’s gate capacitance, as well as resistive losses as the transistor ramps between on and off states (nothing happens instantly you know).  The solution?  Again, buy better parts. 🙂

Questions, comments, suggestions, requests?  Feel free to leave them below.  Thanks!

Ozone and Earthquakes?

Tangshan Earthquake (1976)The words “earthquake” and “ozone” are two terms you don’t often find used in the same sentence.  Like “congress” and “effective”, or “health food” and “delicious.”  And yet, MSNBC recently published an interesting news item whose title did just that: “Is ozone gas an earthquake precursor?

As it turns out, when rocks such as basalt and granite are crushed, they produce substantial quantities of O3 – ozone gas.  According to researchers at the University of Virginia, the amount of ozone released varied between 100ppb and 10ppm.  To put that into perspective, the low end of this range is comparable to a very smoggy day in Los Angeles.  The high end is one hundred times worse.

So I guess now we’ve got yet another reason to hate earthquakes: they split houses, swallow cars, and pollute the air.  Although, perhaps if a quake destroyed enough cars this would offset the amount of ozone released.  But I digress.  The real question here is, “Can elevated ozone concentrations predict earthquakes?”  Well according to researcher Catherine Dukes, no, not really: “It’s just a way to warn that the Earth is moving and something — an earthquake, or a landslide or something else — might follow.”

I suspect that any rock crushing action which produces ozone is also detectable via seismograph (although I’m just guessing).  So perhaps this discovery isn’t so useful.

But crushed rocks producing ozone?  This is still a rather strange phenomenon.  Scientists are not yet certain of the precise mechanism at work here, but suspect that differences in electric charge between rock surfaces are the most likely cause.  As you may know, lightning strikes are another natural means of ozone formation, particularly in the upper atmosphere, where ozone is more beneficial.  While the strike itself does not directly form ozone, it breaks apart O2 into atomic oxygen, which may then recombine as O3 (see this PDF for details).  Lightning also yields nitrogen oxides (also a popular automotive pollutant) which, in the presence of sunlight, react with other chemicals to form ozone.  So the theory here is that differences in electric charge between the crushed rocks are producing small electrostatic arcs (miniature lightning strikes) which result in ozone gas.

Well, perhaps we should just chalk this up as another oddity of the universe – like X-ray-producing tape, or radioactive bananas…  Still, it would interesting to know if there are preliminary tremors which aren’t detectable by seismographs but might be picked up by ozone detectors.  Such predictions probably wouldn’t be too accurate though.

Happy New Year

Greetings People of the Internet!  First off, Happy New Year!  The last twelve months have proven quite interesting, yes?  Whether good or bad, I think the term “interesting” is fairly safe here.  I can’t say my 2011 has been all that great, but it’s certainly been interesting.  I do hope, however, that you’ve had a good year.  🙂

One other quick note; in case you’re wondering what happened to Grieg, he died of heart failure in 1907.  And in case you’re wondering what happened to grieg.gotdns.com (my former domain name), I finally bit the bullet and purchased a real address for this trite little blog: nlvocables.com.  If you subscribe, you may want to update your links (although I intend to leave grieg.gotdns.com alive and forwarding for as long as the internet allows).  Please let me know if you have any issues.

As usual, keep the comments and questions coming.  Best wishes for a successful 2012!

LabVIEW: The Simple Talking Voltmeter

A couple of weeks ago I spent some time examining a fairly complex circuit board from my old, but still functional, clock radio/CD player.  I was using the probe of my handheld multimeter to measure voltages at various IC pins and circuit traces.  At one point during the process I thought, “Gee, wouldn’t it be nice if I had someone here to read the voltmeter to me as I test various points?  That way I could focus on my probe and not accidentally short neighboring pins.”  But then I realized that I did have someone to do just that: Microsoft Sam.  I present to you the NI LabVIEW talking voltmeter:

For those of you without LabVIEW, here are a few screenshots of the subVIs shown in the video above.  Don’t forget that you can always download a free, unrestricted 30-day trial of LabVIEW from the NI website (seriously, it’s awesome, you should try it).

First, the initialization VI, which opens the Microsoft ISpeechVoice reference:

Initializing the Speed Interface

Next, the blocks responsible for detecting new steady-state voltages:

Detecting New Steady-State Voltages

Finally, the code which converts numbers into strings and sends them to Sam:

Convert and Speak the Values

Many thanks to Grant Heimbach, whose sample speech VI saved me a lot of development time (his original code is available on the NI Developer Community).

Click here to download a simple example VI which utilizes the code shown above.

The full, unmodified IOBoard Voltmeter program, as well as all of its supporting components, can be located at the bottom of the Mobile Studio Downloads page.

Got questions or comments?  As always, feel free to leave them below!

Small Stuff: An Optical Mouse Sensor

A few weeks ago I was given a broken Microsoft Wireless Optical Mouse 4000.  When powered on, its LED glowed and appeared to blink and fade as expected, depending on whether or not the mouse sensed motion.  The USB receiver seemed to be working fine as well; Windows detected it and installed the appropriate drivers.  And yet no mouse clicks or motions would register.  So I decided to open it up and take a look.  Long story short: I couldn’t find any obvious problems, but I did snap a few pictures of its optical sensor.  Sadly, I can’t find a datasheet for this particular part.  One document I found called it a Microsoft proprietary sensor.  Oh well.  Here are some nifty pictures taken with a sweet microscope I have access to through work:

Other cool links on the subject:

  • The optical mouse cam (an optical mouse text scanner)
  • An overview of various optical mice and sensors (a bit older, but still cool)
  • More neat pictures of the same sensor (and possibly the same mouse?)
  • A datasheet for the VD5376 optical mouse sensor (comparable, not identical)