a detailed guide to building your own DC/DC converter using a little PIC, by Olin Lathrop
The guiding equation for inductive switching power supply is:
Amps = --------
In other words, if you know any three of applied voltage to a inductor, the length of time that voltage is applied, the inductance, and the resulting change in inductor current, you can find the fourth.
For a micro to control a switching power supply directly from firmware, we want switching edges to be a few uS apart. Just to see where we're at, let's see what size inductor would charge up to 1/4 amp from 3V in 10uS:
Volt Sec 3V 10uS
Henries = -------- = ------- = 120uH
OK, that's not way out of line so a 100uH inductor should be quite usable.
That's a common value and finding one with at least 500mA saturation current will be no problem. So now that we've tentatively decided on 100uH 500mA inductor, let's see what the longest guaranteed not to saturate switch on time is. Obviously, this needs to be computed at the maximum input voltage, which you said previous was 4.2V:
Amp Henries 500mA 100uH
Sec = ----------- = ----------- = 11.9uS
So this tells us that as long as the firmware never leaves the switch on for more than 11uS, and the inductor current starts out at zero, we are safe and the inductor won't saturate. Let's say the controller is a 10F204 where each instruction cycle is 1us, so that would be 11 instruction cycles.
That's actually a fairly long time, but then again that is the max
saturation limit. Nothing says we have to charge up the inductor to 500mA each pulse, and there are some reasons not to.
We'll likely use a NPN switch, since FETs that can handle 70V aren't going to switch well with only 3V on the base. The downside of a bipolar is you have to keep feeding it enough base current to stay in saturation. Let's say you can get a NPN that can withstand the voltage with a guaranteed gain of at least 40 (I haven't checked, but that sounds about right). If you wanted to max out the inductor at 500mA, the would require 500mA / 40 = 12.5mA base current to keep the transistor saturated. At least that's easily doable from a PIC pin, since those are rated for twice that current. I wouldn't actually run the transistor at the limit, since there will be some rise in C-E voltage.
I don't want to write a book here, so I'm going to cut short a few thought processes. Let's just pick 6uS as the inductor on time, and we'll use a pulse on demand system. Whenever the output voltage goes below its regulation threshold, the micro will produce a 6uS (6 instruction cycle) pulse.
Note how each time we pick a parameter, we can feed that into the equations and nail down something else more tightly. At this point we've decided to use a 100uH inductor, a NPN grounded emitter switch with a minimum guaranteed current gain of 40, and a fixed size 6uS pulse on demand control system. Now we go back and find what our highest inductor current can be:
Volt Sec 4.2V 6uS
Amps = -------- = -------- = 252mA
1/4 amp is going to be no problem for finding a inductor or transistor, so that all looks good. To keep the transistor saturated, it needs 252mA / 40 = 6.3mA base current. Obviously we want a little more for margin and to keep the saturate voltage low. 10mA sounds like a nice number given the circumstances.
Here's something that might not be obvious. The limiting case for base
current is the lowest input voltage, not the highest. You might think it doesn't matter because the inductor current will scale linearly with input voltage, so proportionately less base current is needed as the input voltage goes lower. However, there is a larger fixed offset subtracted from the base current drive voltage than from the inductor drive voltage. This is because the voltage accross the base resistor is the supply voltage minus the fixed B-E drop of the transistor, whereas the inductor charge voltage is the supply voltage minus only the transistor saturated on voltage. The net effect is that the base current scales down more quickly as the supply voltage drops than the inductor current does. So we need to know what current the transistor must sustain at 3V:
Volt Sec 3.0V 6uS
Amps = -------- = -------- = 180mA
180mA / 40 = 4.5mA minimum required base current with 3V supply. Let's say 700mV is lost between the B-E drop of the transistor and the high side output pin driver in the PIC. That leaves 3.0V - 700mV = 2.3V accross the base resistor. 2.3V / 4.5mA = 511 ohms. We of course want to build in some margin and keep the saturation voltage down. 360ohms sounds like a nice number. That provides 30% margin.
Now we need to do a sanity check at the maximum supply voltage. Again let's assume 700mV is lost that is not applied accross the base resistor. (4.2V - 700mV) / 360ohms = 9.7mA. That's real close to the 10mA we thought sounded nice earlier, so that checks fine.
I'd add another minor detail to speed up the switching transitions a little.
At 6uS on it's not a big deal, but a $.01 part can help things just a
little. Turning the transistor on isn't a issue since the inductor current starts out at 0 anyway. The base current will build up to its steady value much faster than any appreciable inductor current will. However, we want to make the transistor switch off as fast as possible. Grounding its base via a 360 ohm resistor is actually not that bad, but we can still speed it up with a small capacitor in parallel accross the base resistor. The resistor alone will probably turn off the transistor within about 100nS. To see where we're at, let's see what capacitance would result in a 100nS time constant, meaning about 2/3 of the effect is over in 100nS. 100nS / 360ohms
= 278pF. Hmm, that sounds too big. Make it 100pF. That results in a time constant of 100pF * 360ohms = 36nS.
Normally you have to consider the inductor discharge time. In this case it's obvious from casual observation it's not a issue given the 70V output, but let's do the calculation anyway just to show it:
Amp Henries 252mA 100uH
Sec = ----------- = ----------- = 383nS
Volts 70V - 4.2V
which is well under a single instruction cycle. Or put another way, the inductor current is guaranteed to reach 0 with the switch off for just one instruction cycle.
Of course the above is only true during normal operation when the output voltage is already around 70V. Startup is a whole other issue. This is one of the advantages of having a micro. You can easily use a different algorithm and different parameters during startup than during normal operation. I don't feel like getting into startup here, but it's something that has to be considered.
So the 10F204 code for the normal operating loop looks like this:
skip_low ;output below regulation threshold ?
goto loop ;no, go back and check again
switch_on ;turn on the switching element
switch_off ;turn off switch 6uS later
goto loop ;back to wait for output low again
SKIP_LO, SWITCH_ON, and SWITCH_OFF are macros that expand to single
instructions. It's a good idea to add that layer of abstraction. It
separates the control algorithm from the details of how that particular
project is wired to the micro.
Now we can calculate the maximum output current the supply can maintain
voltage regulation with. From the code above it should be obvious that
there is a minimum of 4uS between the fixed size 6uS pulses, for a maximum pulse repetition period of 10uS, and a maximum pulse rate of 100KHz.
At the lowest specified input supply voltage, we calculated earlier the
inductor charges to a maximum of 180mA. This was assuming no switch loss, but let's see what the best possible case is and scale back from there. 1/2 * (180mA)**2 * 100uH = 1.62uJ, x 100KHz = 162mW, / 70V = 2.3mA. Obviously we're not going to get 100%, but certainly this supply will be good for at least 1mA. Since the spec said "miniscule" (rant about bad engineering suppressed), we can claim we're done.
The calculations above took way longer to describe than to do. A couple of minutes with a calculator is all it should take to get to this stage. (this was posted @PICList some days ago by Olin, and I asked permission to make it available in here since I (and others) found it interesting and detailed)
post edited by DarioG - 2009/10/03 03:10:57