SparkFun Forums 

Where electronics enthusiasts find answers.

Have questions about a SparkFun product or board? This is the place to be.
By spcutler
#4194
I'm looking to build a fairly simple switching voltage regulator, and intend to use a PIC as the controller. I realize that there are better and cheaper options, but I like the PIC idea because:
- I know how to write software, but I'm not as good yet with electronics
- The regulator needs to have some additional control functions which will be easier with a PIC
- I've already got the components available

Plus, PICs are like hammers--everything looks like a nail when you've got one :-).

The circuit is to turn automotive DC (noisy and ranging from probably 10-16 volts) to 9 VDC. My plan so far is to implement a RC buck converter with a resistor voltage divider to feed back into the PIC comparator, and then use either PWM or "bang bang" to control the MOSFET. The PIC itself will be powered by a simple linear regulator.

So if anyone has done this before and has ideas/suggestions/gotchas, or whatever, I'd like to hear them. Thanks for any help!

-Scott
By Naftie
#4730
I'm working on a buck-convertor controlled by a PIC 16F88 at the moment, for my graduating project (don't know how to call right it in english).
As i'm working with the internal oscillator (8MHz), the PWM runs at 8kHz. It regulates from 0 to 25.5V, the step is 100mV and the best result I've got was 50mV AC on the output, but then it was very lazy (changing load gave really big changes in output).

Basically you just have to make a resistor array that changes the 0 to Umax into 0 to 5V, read that with the A/D convertor, make an average of a number of measures (to compensate wrong values while the output was still changing). Then you have to find an intelligent way to adjust the duty-cycle of the PWM (wich I use to control the switching mosfet).
You could change the output voltage in little steps (by one for example): - it's slow and lazy +it doesn't make that much AC on the output, and it's easier.
Or you could adjust with the difference between wanted and measured: -big steps make it overshoot, difficult to control, measurement will happen while the change is happening on the output. +it's not lazy, fast reaction (too fast reaction in fact).

So I've made a compromis, depending on the difference, the adjustment steps are increased, and for big changes i use the value of the difference.


I'm not ready yet with my program, but if you have more questions: shoot. And if you have more information: I could use some 8)
By spcutler
#4737
Awesome, glad to hear that someone else is working on the same thing.

It sounds like your project is pretty close to what I already have in mind. Do you mind posting some details of your circuit? I barely know where to begin when it comes to selecting cap/inductor size and such.

And a newbie question regarding MOSFETs in this circuit--the typical buck converter has the MOSFET across the positive input lead. But the gate presumably connects directly to whatever PWM circuit you have (a PIC in this case). So what is the gate voltage in reference to? There's no ground level anywhere. Does it really just float?

I've heard of MOSFET types with separate gate input and output wires, which makes the problem easier in my mind. I've never actually seen one, though.

Thanks for any help.

-Scott
By Oznog
#4784
You can use an NMOS with the gate coupled with a cap to the pin. Then use a 5.1v zener in parallel with a 100k resistor between the gate and source. (search for "bootstrap mosfet").

Note many NMOS do not turn on strongly at 5v. Instead, use one specified as "logic level".

As long as the PWM does not hit a 100% or 0% duty cycle, it works. The first cycle will see a slightly glitched gate waveform. Large, very sudden variations in the can cause a bit of a glitch too.

In my experience, the PIC's ADC/PWM was too slow and there weren't enough bits to make a good response time and resolution for my buck converter driving a very high (3 watt) power LED. But in a current-mode circuit like this, the voltage is much more critical. Being off by 100 mV makes large difference in the current output.
By Naftie
#4794
Well, why make it all so difficult. The PWM output is a clear switching TTL level square wave, with low power. You have to drive a much higer power output. Well then, I guess everyone into electronics knows a transistor?
That's a small cheap device that (in this case) is used as a switch, controlled by TTL level, and outputting at the level your buck convertor will be feeded with :lol: .
A picture says more than thousand words:
Image
In your case it could be useful to place a optocoupler in stead of the transistor, so the mass is also separated, because you have lots of junk on the feeding voltage of the buck-convertor.

The values of the caps and inductors are just some that were standard in our company. The first set you will probably know from the basic schematic, the other set is an additional filter. It works quite good for us, mainly we make 13/18 volts (for DisEqC) out of 28V.

If you start programming, you should notice the fact that the output will certainly change periodically, I've made mine to have a max voltage of 25,5V (8 bits resolution), so every step is 100mV. When stable it will constantly go up and down 100mV, that's the disatvantage of a switched supply.
By spcutler
#4795
Cool, thanks for the great info, guys. Gotta think about the best plan still (and do some reading on "bootstrap" MOSFET circuits), but that's a great start.

Naftie--the only problem I see with your circuit is that the MOSFET driving voltage is dependent on the input voltage. In my case, the input might be anywhere from roughly 10-16 volts. Do you think that putting a Zener diode in the right spot would do the trick? Or will the MOSFET do fine over a range like that?

-Scott
By Oznog
#4796
Naftie wrote:Well, why make it all so difficult. The PWM output is a clear switching TTL level square wave, with low power. You have to drive a much higer power output. Well then, I guess everyone into electronics knows a transistor?
That's a small cheap device that (in this case) is used as a switch, controlled by TTL level, and outputting at the level your buck convertor will be feeded with :lol:
Well, that is one way to do it. But this is frankly more complicated than a zener diode, resistor, and cap! You're talking 3 resistors and an NPN.

So there are several things here which are inferior to bootstrapping. One, the turn-off behavior of this type of circuit can be fairly poor due to the RC time constant of R29 and the gate. R30 even increases the turn-on time. Thus it may generate a lot of heat, particularly at high freq. I've toasted MOSFETs due to this type of circuit's turn-on/off time.
You're also talking about a P-channel, which is generally a poorer performer than N-channel.
The choice of R29/R30 as a divider makes it sensitive to source voltage voltage. If the source voltage drops down, the Q5 may go into the saturation region and burn up. If too high, it can also exceed vgs-max.
Also, if you are trying to keep the quiescent current low, you're looking at constant current through the base and collector when Q5 is on.

All these things are why bootstrapping became popular.

PIC has an excellent current drive for pushing FET gates really fast. Cap coupling it via bootstrap arrangement yields really good results, with the one issue- no 100% duty cycles (actually I made a mistake before- 0% duty cycle is ok)
By Naftie
#4797
Well Oznog, seems like you totally taught this out.
As the PWM frequency is only 8 kHz, I think there will be no problem with heat. My circuit is powered by 2 15V/2A supply's, and the max current would be about 1A (in xtremely rare situations), so the supply voltage should stay OK.
I guess that a zener diode and a cap will cost more than 3 SMD resistors and 1 SMD transistor. That's one thing I should keep in mind, its a circuit for a testbox, and each box will have 16 prints with this schematic, so price should be lower if possible (that the RF part will use 32 relays of 3€/piece doesn't seem to matter :) ).
As it's for a testbox, the other thing is that it should withstand everything, from shorting (for 200 ms or so, then the PIC should notice the current is too big and shut down). Will a bootstrap circuit improve it's behavior (at this low frequency, 8 khz) noticably? Could you post a circuit on how you would do this (i will keep the FET, because in the company I know this is one we have in stock). I will take a look at the theory of bootstrapping too, we only have learned bootstrapping ordinary transistors in school.
By Oznog
#4802
Well you couldn't do a bootstrap and keep that transistor. It should be an NMOS and turn on strongly at 5v.

High freq will often benefit the rest of your circuit. When you double freq, all your caps & inductors can generally be made half the size (within limits). At 8KHz switching freq, it's in the audio range and some degree of buzz may come up if this is an audio circuit.

I do need a methood to put up schematics. Basically the cap couples the PIC pin to the gate. The cap should be 20x or more larger than the mosfet's internal gate capacitance. There's a zener on gate-source, with cathode on the gate and anode on source. That forces the cap to charge to the correct voltage to make 0-5v on the gate as long as the pwm is running by conducting in either the forward or reverse direction. There's also a 10k-100k resistor running g-s to drain the cap and guarantee it tuns off when the pwm stops- not necessary in normal behavior, but it improves the turn-on/turn-off behavior.
By Naftie
#4814
I've tried to make a schematic:
Image
(I use the webspace that came with my internet account, but www.imageshack.us should also be possible to put images on).

I've took the first NFET I've found, i will als wich one they have in stock tuesday. Wich zener should it be, 5V?

And the frequency can't be changed, unless I decrease the resolution of the PWM, wich creates bigger steps, so I would need even more filtering. I know it's quite low, but it mainly has to provide 13/18V DC level for switching sattelite devices with DisEqC. DisEqC also communicates with a 22kHz, 0,6Vpp signal, so with 8*2=16kHz i could interfere with that communication, especially because the voltage swing would become greater (lower resolution).
By Oznog
#4833
How much current is this running?
Personally, just looking at what you're trying to do, I would say a PIC isn't the best circuit, at least not at this freq. 8KHz isn't a great switching freq, for one. Audible hum is going to be hard to avoid if this circuit handles audio or possibly if it shares the power source with anything that runs audio. The size of caps & inductors needed when using a lower freq goes up, and that increases the cost. You're also going to need a voltage divider again for the PIC adc. The PIC may not have a really fast response either, the thing that you will need to look out for is oscillation. This may be particularly true here if you choose the LC filter's output for the feedback point (this factor is not a shortcoming of using a PIC, of course). On the other hand, if you lower the response feedback to prevent oscillation, it will not respond quickly to changes in the source or load.

There are plenty of good switching regs out there that will do this in not only a simpler manner, but more accurately & reliably as well.
By Naftie
#4835
It should run 1A max in rare occasions, but can (and will) be shorted regularly (it's a testing device), usually around 20mA will flow. Is the bootstrap circuit right?
As it's my (and my fellow student's) thesis, it may be difficult. We've seen that solving this with an analog circuit would run quite heat, so we're trying to make a switched supply to prevent heat. In the programming, I'll see if I can get it fast enough, but I know I will have to use very smart tricks to combine fast response and no oscillations (slow response).
Wouldn't it be great if it works? 8kHz switching supply in a PIC, made by me :) If noone tries something new, we were still living in caves.

And if I really don't get it to work, we can use the plain old analog system, or a specific IC.
By SOI_Sentinel
#4836
Depending on what you think your PWM rate can be, there's also 1MHz dedicated PWM chips from Microchip now, such as:

http://www.microchip.com/MCP1630/

(I am not a power supply designer, but I probably will be soon enough)
By Oznog
#4838
Naftie wrote:It should run 1A max in rare occasions, but can (and will) be shorted regularly (it's a testing device), usually around 20mA will flow. Is the bootstrap circuit right?
As it's my (and my fellow student's) thesis, it may be difficult. We've seen that solving this with an analog circuit would run quite heat, so we're trying to make a switched supply to prevent heat. In the programming, I'll see if I can get it fast enough, but I know I will have to use very smart tricks to combine fast response and no oscillations (slow response).
Wouldn't it be great if it works? 8kHz switching supply in a PIC, made by me :) If noone tries something new, we were still living in caves.

And if I really don't get it to work, we can use the plain old analog system, or a specific IC.
Your schematic is correct except the NMOS has the gate-source swapped. The body diode will be forward biased like that which is bad.

Now a switching regulator, off the shelf, will do the same thing without burning a lot of power as heat (that's a linear regulator). There are any number of ways to do this in a bit more involved way with a 555, etc. Some better than others. One of the practical notes is that the PIC requires a 5v reg to run and only puts out 5v to drive a gate, whereas switching reg ICs will take in 30v, 50v, whatever. As you may have noted, your PIC really needs an external Xtal too because that internal osc is impractically slow.

Unfortunately, as response goes, basically nothing can fix the problem that delays require you to lower the response time to avoid oscillation.

I guess I'd see it more if this was a programmable supply, maybe some specific form of current limiting. Something else that requires a PIC's services than just using the PWM. It's too simple for pulling in a PIC which won't do the job as well as an IC built for the purpose, and be much more complicated.
By Naftie
#4840
Well, I certainly need the PIC there, it also needs to send out and receive a 22kHz tone on the output for communication with the DUT. If it doensn't work good enough, I'll use a low pass on the PWM output, 0-5V to control a specific IC (if not too expensive).