Electronics-Related.com
Forums

MicroController control for switching regulator

Started by RogerN December 25, 2012
mike <ham789@netzero.net> wrote:

>On 12/26/2012 1:46 AM, Jasen Betts wrote: >> On 2012-12-25, mike<ham789@netzero.net> wrote: >> >>> Got any tips on how to do this? >>> At 20 kHz. you have 50microseconds to do two measurements, update >>> the displays, and decide whether and how to tweak the PWM. >> >> you don't need to update the displays at 20Khz >> 2Hz would be plenty for update 40hz would be a sufficient refresh rate >> if you need to do that. >> >>> Even if you dedicate the whole processor to the task, you still >>> gotta get data in and out. A 50 millisecond key debounce timer >>> is an eternity when the output is shorted. >> >>> So you make everything interrupt driven...and it gets messy. >> >> no, everything gets tidy when it's interrupt driven, the critical code >> is no longer at the mercy of the main loop, you can use float >> arithmetic and printf, and other slow code in the main loop without >> breaking anything. > >I'm not saying that it can't be done. >I'm saying that my PIC with 200ns instruction cycle and one level >of interrupt and inaccessible stack and 20us A/D conversion time,
So if a PIC can't handle it the problem must be wrong? If you start asking these kind of questions it really is time to move away from PIC and switch to ARM. Otherwise you'll find yourself creating kludges. -- Failure does not prove something is impossible, failure simply indicates you are not using the right tools... nico@nctdevpuntnl (punt=.) --------------------------------------------------------------
On Tue, 25 Dec 2012 06:05:02 -0600, RogerN wrote:

> I'm wanting to use a microcontroller to control the output of a > switching regulator, maybe something like a LM2576 simple switcher. I > see the adjustability is on the feedback lead but what's the best way > make it adjustable from a microcontroller. I'm guessing the feedback > may be used in switching timing, ie, I guess I can't just use a DAC and > get an output of 1.23V more than the DAC output? I want to monitor > voltage and current and use a control algorithm in the microcontroller > (Arduino at first for experimentation) for custom battery charging > experimentation.
I don't know that anyone actually answered the question that you asked. You got a lot of good responses -- personally, if I were doing this I'd see if the microprocessor had a suitable PWM output and think about using that. But to answer your _actual question_, no you can't just hook the feedback pin to a DAC. It's a _feedback_ pin: it needs to be connected to the output in some way or another. The action of the chip is to hold the feedback pin to 1.23V (or whatever the reference voltage is); thus, your responsibility as a circuit designer is to wire up that feedback pin so that when the output voltage is at the desired value, the feedback pin is at 1.23 volts. So you probably want a resistor (or lead-lag network) going from output to the feedback pin, and another resistor going to a DAC. As your DAC output voltage goes up, it'll contribute more to that 1.23V, meaning that the output of your regulator will go down. So, essentially you'll have built an inverting amplifier with a switching element to it. When you're all done, if you just have a single resistor for feedback your circuit may not be stable -- hence, my suggestion to use a lead-lag network. If you do need to start messing with the lead-lag you'll have to do it b'guess and b'gosh, because National Semiconductor (at least the last time I looked) thinks you're a stupid git and doesn't share SPICE models of their switchers, which means you have to use their Web Bench design tool, which doesn't include fancy things like a DAC-pushed feedback pin. Here's what I mean by a lead-lag network. R1 and R3 form the "main" resistive divider. If you leave out R2 or C1, that's that. If you put in real components for R2 and C1, then R1, R2 and C1 are a lead-lag network. If you do need to do something with those components, then you probably want to start out with a value of C1 such that C1 * R1 is about four to ten times longer than the period of the oscillation that you're trying to kill, and play with values of R2 that range from R2=R1 to R2=R1/10. output o------------------------------. | ___ | .--------|___|---------o | R1 | | | | || ___ | o-----||-------|___|---' | || R2 feedback o-------o C1 | | | .-. | | | |R3 '-' | | | from DAC o-------' (created by AACircuit v1.28.6 beta 04/19/05 www.tech-chat.de) -- Tim Wescott Control system and signal processing consulting www.wescottdesign.com
On Wed, 26 Dec 2012 12:52:30 -0600, Tim Wescott
<tim@seemywebsite.please> wrote:

>On Tue, 25 Dec 2012 06:05:02 -0600, RogerN wrote: > >> I'm wanting to use a microcontroller to control the output of a >> switching regulator, maybe something like a LM2576 simple switcher. I >> see the adjustability is on the feedback lead but what's the best way >> make it adjustable from a microcontroller. I'm guessing the feedback >> may be used in switching timing, ie, I guess I can't just use a DAC and >> get an output of 1.23V more than the DAC output? I want to monitor >> voltage and current and use a control algorithm in the microcontroller >> (Arduino at first for experimentation) for custom battery charging >> experimentation. > >I don't know that anyone actually answered the question that you asked. >You got a lot of good responses -- personally, if I were doing this I'd >see if the microprocessor had a suitable PWM output and think about using >that. > >But to answer your _actual question_, no you can't just hook the feedback >pin to a DAC. It's a _feedback_ pin: it needs to be connected to the >output in some way or another. The action of the chip is to hold the >feedback pin to 1.23V (or whatever the reference voltage is); thus, your >responsibility as a circuit designer is to wire up that feedback pin so >that when the output voltage is at the desired value, the feedback pin is >at 1.23 volts.
However, the DAC can be in the feedback. A multiplying DAC is the most obvious solution but there are easier ways to do this. For crude control a few NPNs or NFETs (assuming a positive regulator) can be used to switch bottom resistors in the feedback divider. It's really a multiplying DAC, anyway.
>So you probably want a resistor (or lead-lag network) going from output >to the feedback pin, and another resistor going to a DAC. As your DAC >output voltage goes up, it'll contribute more to that 1.23V, meaning that >the output of your regulator will go down. So, essentially you'll have >built an inverting amplifier with a switching element to it.
That works but can be tricky. Gotta make sure you don't go beyond the range of the output to control the feedback point.
>When you're all done, if you just have a single resistor for feedback >your circuit may not be stable -- hence, my suggestion to use a lead-lag >network. If you do need to start messing with the lead-lag you'll have >to do it b'guess and b'gosh, because National Semiconductor (at least the >last time I looked) thinks you're a stupid git and doesn't share SPICE >models of their switchers, which means you have to use their Web Bench >design tool, which doesn't include fancy things like a DAC-pushed >feedback pin.
Gotta make sure it's stable in any case.
>Here's what I mean by a lead-lag network. R1 and R3 form the "main" >resistive divider. If you leave out R2 or C1, that's that. If you put >in real components for R2 and C1, then R1, R2 and C1 are a lead-lag >network. If you do need to do something with those components, then you >probably want to start out with a value of C1 such that C1 * R1 is about >four to ten times longer than the period of the oscillation that you're >trying to kill, and play with values of R2 that range from R2=R1 to >R2=R1/10. > > > output o------------------------------. > | > ___ | > .--------|___|---------o > | R1 | > | | > | || ___ | > o-----||-------|___|---' > | || R2 > feedback o-------o C1 > | > | > | > .-. > | | > | |R3 > '-' > | > | > | > from DAC o-------' >(created by AACircuit v1.28.6 beta 04/19/05 www.tech-chat.de)
That's an "integrator" style of compensation. There are others. I'd use what the regulator's manufacturer suggests and just change the feedback - no injection from another source.
On 12/26/2012 7:08 AM, Nico Coesel wrote:
> mike<ham789@netzero.net> wrote: > >> On 12/26/2012 1:46 AM, Jasen Betts wrote: >>> On 2012-12-25, mike<ham789@netzero.net> wrote: >>> >>>> Got any tips on how to do this? >>>> At 20 kHz. you have 50microseconds to do two measurements, update >>>> the displays, and decide whether and how to tweak the PWM. >>> >>> you don't need to update the displays at 20Khz >>> 2Hz would be plenty for update 40hz would be a sufficient refresh rate >>> if you need to do that. >>> >>>> Even if you dedicate the whole processor to the task, you still >>>> gotta get data in and out. A 50 millisecond key debounce timer >>>> is an eternity when the output is shorted. >>> >>>> So you make everything interrupt driven...and it gets messy. >>> >>> no, everything gets tidy when it's interrupt driven, the critical code >>> is no longer at the mercy of the main loop, you can use float >>> arithmetic and printf, and other slow code in the main loop without >>> breaking anything. >> >> I'm not saying that it can't be done. >> I'm saying that my PIC with 200ns instruction cycle and one level >> of interrupt and inaccessible stack and 20us A/D conversion time, > > So if a PIC can't handle it the problem must be wrong? If you start > asking these kind of questions it really is time to move away from PIC > and switch to ARM. Otherwise you'll find yourself creating kludges. >
You're saying that I should drop everything, learn a new processor, buy the new tools instead of dropping in a 50-cent regulator chip so I don't create a kludge? I don't think I said that the problem was wrong...or the solution was wrong, for that matter. I asked and I didn't learn any magic that would cause me to reconsider my position in my current situation. I spent much of my career fixing stuff designed by engineers with tunnel vision. They keep adding horsepower instead of widening their search for options. Context is very important.
On Wed, 26 Dec 2012 14:10:22 -0500, krw wrote:

> On Wed, 26 Dec 2012 12:52:30 -0600, Tim Wescott > <tim@seemywebsite.please> wrote: > >>On Tue, 25 Dec 2012 06:05:02 -0600, RogerN wrote: >> >>> I'm wanting to use a microcontroller to control the output of a >>> switching regulator, maybe something like a LM2576 simple switcher. I >>> see the adjustability is on the feedback lead but what's the best way >>> make it adjustable from a microcontroller. I'm guessing the feedback >>> may be used in switching timing, ie, I guess I can't just use a DAC >>> and get an output of 1.23V more than the DAC output? I want to >>> monitor voltage and current and use a control algorithm in the >>> microcontroller (Arduino at first for experimentation) for custom >>> battery charging experimentation. >> >>I don't know that anyone actually answered the question that you asked. >>You got a lot of good responses -- personally, if I were doing this I'd >>see if the microprocessor had a suitable PWM output and think about >>using that. >> >>But to answer your _actual question_, no you can't just hook the >>feedback pin to a DAC. It's a _feedback_ pin: it needs to be connected >>to the output in some way or another. The action of the chip is to hold >>the feedback pin to 1.23V (or whatever the reference voltage is); thus, >>your responsibility as a circuit designer is to wire up that feedback >>pin so that when the output voltage is at the desired value, the >>feedback pin is at 1.23 volts. > > However, the DAC can be in the feedback. A multiplying DAC is the most > obvious solution but there are easier ways to do this. For crude control > a few NPNs or NFETs (assuming a positive regulator) can be used to > switch bottom resistors in the feedback divider. It's really a > multiplying DAC, anyway.
That may work, but if you need to do any loop compensation it'll be at least as complicated as the method that I suggested.
>>So you probably want a resistor (or lead-lag network) going from output >>to the feedback pin, and another resistor going to a DAC. As your DAC >>output voltage goes up, it'll contribute more to that 1.23V, meaning >>that the output of your regulator will go down. So, essentially you'll >>have built an inverting amplifier with a switching element to it. > > That works but can be tricky. Gotta make sure you don't go beyond the > range of the output to control the feedback point.
True. Everything has its drawbacks.
>>When you're all done, if you just have a single resistor for feedback >>your circuit may not be stable -- hence, my suggestion to use a lead-lag >>network. If you do need to start messing with the lead-lag you'll have >>to do it b'guess and b'gosh, because National Semiconductor (at least >>the last time I looked) thinks you're a stupid git and doesn't share >>SPICE models of their switchers, which means you have to use their Web >>Bench design tool, which doesn't include fancy things like a DAC-pushed >>feedback pin. > > Gotta make sure it's stable in any case.
Well, yes, but National makes sure that you can't do that on paper or in simulation beforehand, by withholding so much information from you that you can only do it by letting yourself be hand-held by their in-house application, and that in-house application's assumptions. So you're stuck with building a circuit and hoping that you've got the topology close enough that you can achieve stability just with component changes.
>>Here's what I mean by a lead-lag network. R1 and R3 form the "main" >>resistive divider. If you leave out R2 or C1, that's that. If you put >>in real components for R2 and C1, then R1, R2 and C1 are a lead-lag >>network. If you do need to do something with those components, then you >>probably want to start out with a value of C1 such that C1 * R1 is about >>four to ten times longer than the period of the oscillation that you're >>trying to kill, and play with values of R2 that range from R2=R1 to >>R2=R1/10. >> >> >> output o------------------------------. >> | >> ___ | >> .--------|___|---------o >> | R1 | >> | | >> | || ___ | >> o-----||-------|___|---' >> | || R2 >> feedback o-------o C1 >> | >> | >> | >> .-. >> | | >> | |R3 >> '-' >> | >> | >> | >> from DAC o-------' >>(created by AACircuit v1.28.6 beta 04/19/05 www.tech-chat.de) > > That's an "integrator" style of compensation. There are others. I'd > use what the regulator's manufacturer suggests and just change the > feedback - no injection from another source.
Have you tried to use National's WebBench to do any real design tasks? -- My liberal friends think I'm a conservative kook. My conservative friends think I'm a liberal kook. Why am I not happy that they have found common ground? Tim Wescott, Communications, Control, Circuits & Software http://www.wescottdesign.com
On Wed, 26 Dec 2012 18:11:20 -0600, Tim Wescott <tim@seemywebsite.com>
wrote:

>On Wed, 26 Dec 2012 14:10:22 -0500, krw wrote: > >> On Wed, 26 Dec 2012 12:52:30 -0600, Tim Wescott >> <tim@seemywebsite.please> wrote: >> >>>On Tue, 25 Dec 2012 06:05:02 -0600, RogerN wrote: >>> >>>> I'm wanting to use a microcontroller to control the output of a >>>> switching regulator, maybe something like a LM2576 simple switcher. I >>>> see the adjustability is on the feedback lead but what's the best way >>>> make it adjustable from a microcontroller. I'm guessing the feedback >>>> may be used in switching timing, ie, I guess I can't just use a DAC >>>> and get an output of 1.23V more than the DAC output? I want to >>>> monitor voltage and current and use a control algorithm in the >>>> microcontroller (Arduino at first for experimentation) for custom >>>> battery charging experimentation. >>> >>>I don't know that anyone actually answered the question that you asked. >>>You got a lot of good responses -- personally, if I were doing this I'd >>>see if the microprocessor had a suitable PWM output and think about >>>using that. >>> >>>But to answer your _actual question_, no you can't just hook the >>>feedback pin to a DAC. It's a _feedback_ pin: it needs to be connected >>>to the output in some way or another. The action of the chip is to hold >>>the feedback pin to 1.23V (or whatever the reference voltage is); thus, >>>your responsibility as a circuit designer is to wire up that feedback >>>pin so that when the output voltage is at the desired value, the >>>feedback pin is at 1.23 volts. >> >> However, the DAC can be in the feedback. A multiplying DAC is the most >> obvious solution but there are easier ways to do this. For crude control >> a few NPNs or NFETs (assuming a positive regulator) can be used to >> switch bottom resistors in the feedback divider. It's really a >> multiplying DAC, anyway. > >That may work, but if you need to do any loop compensation it'll be at >least as complicated as the method that I suggested.
It really isn't. It's the preferred method, actually.
>>>So you probably want a resistor (or lead-lag network) going from output >>>to the feedback pin, and another resistor going to a DAC. As your DAC >>>output voltage goes up, it'll contribute more to that 1.23V, meaning >>>that the output of your regulator will go down. So, essentially you'll >>>have built an inverting amplifier with a switching element to it. >> >> That works but can be tricky. Gotta make sure you don't go beyond the >> range of the output to control the feedback point. > >True. Everything has its drawbacks.
A multiplying DAC doesn't have that problem.
>>>When you're all done, if you just have a single resistor for feedback >>>your circuit may not be stable -- hence, my suggestion to use a lead-lag >>>network. If you do need to start messing with the lead-lag you'll have >>>to do it b'guess and b'gosh, because National Semiconductor (at least >>>the last time I looked) thinks you're a stupid git and doesn't share >>>SPICE models of their switchers, which means you have to use their Web >>>Bench design tool, which doesn't include fancy things like a DAC-pushed >>>feedback pin. >> >> Gotta make sure it's stable in any case. > >Well, yes, but National makes sure that you can't do that on paper or in >simulation beforehand, by withholding so much information from you that >you can only do it by letting yourself be hand-held by their in-house >application, and that in-house application's assumptions. > >So you're stuck with building a circuit and hoping that you've got the >topology close enough that you can achieve stability just with component >changes.
Why wouldn't you? I don't undestand your point, here.
>>>Here's what I mean by a lead-lag network. R1 and R3 form the "main" >>>resistive divider. If you leave out R2 or C1, that's that. If you put >>>in real components for R2 and C1, then R1, R2 and C1 are a lead-lag >>>network. If you do need to do something with those components, then you >>>probably want to start out with a value of C1 such that C1 * R1 is about >>>four to ten times longer than the period of the oscillation that you're >>>trying to kill, and play with values of R2 that range from R2=R1 to >>>R2=R1/10. >>> >>> >>> output o------------------------------. >>> | >>> ___ | >>> .--------|___|---------o >>> | R1 | >>> | | >>> | || ___ | >>> o-----||-------|___|---' >>> | || R2 >>> feedback o-------o C1 >>> | >>> | >>> | >>> .-. >>> | | >>> | |R3 >>> '-' >>> | >>> | >>> | >>> from DAC o-------' >>>(created by AACircuit v1.28.6 beta 04/19/05 www.tech-chat.de) >> >> That's an "integrator" style of compensation. There are others. I'd >> use what the regulator's manufacturer suggests and just change the >> feedback - no injection from another source. > >Have you tried to use National's WebBench to do any real design tasks?
No, I don't use it. I run the equations from the datasheets. I haven't had any real problems, well, for components that work. I have one that looks like it has a nasty phase reversal in the error amplifier that tends to cause smoking holes. This isn't the sort of thing that simulations will warn of, though.
"Jan Panteltje"  wrote in message news:kberrs$s34$1@news.albasani.net...

> LOL > http://panteltje.com/panteltje/pic/pwr_pic/
> Mant PICs have hardware comparators that also control the PWM by > hardware. > Thats is what I use here, among other things such as interrupts. > This code also has a real time clock, but I left it out in the LCD =
display
> for clarity, and space IIRC.
Looks pretty good, but why do you reset all of the interrupt flags upon = exit=20 from the ISR? What if two interrupts occur only a few instruction cycles = apart? Paul
On 12/25/2012 9:31 AM, Jan Panteltje wrote:
> On a sunny day (Tue, 25 Dec 2012 20:46:09 +0800) it happened Dennis > <none@null.net.au> wrote in<1OqdneW6opiTPUTNnZ2dnUVZ_jGdnZ2d@westnet.com.au>: > >> On 25/12/2012 8:05 PM, RogerN wrote: >>> I'm wanting to use a microcontroller to control the output of a switching >>> regulator, maybe something like a LM2576 simple switcher. I see the >>> adjustability is on the feedback lead but what's the best way make it >>> adjustable from a microcontroller. I'm guessing the feedback may be used in >>> switching timing, ie, I guess I can't just use a DAC and get an output of >>> 1.23V more than the DAC output? I want to monitor voltage and current and >>> use a control algorithm in the microcontroller (Arduino at first for >>> experimentation) for custom battery charging experimentation. >>> >>> RogerN >>> >>> >> >> >> What did Jan Pabntelje's uC switcher do? I remember it but not the details. > > It is my lab suply, on 12 hours a day: > http://http://panteltje.com/panteltje/pic/pwr_pic/ > > I dunno about arduino, > but I use a Microchip PIC PWM output, and monitor current in real time > (with an internal PIC comparator), called cycle by cycle current limiting. > The real time thing avoids the need for a specialized chip. > Can arduino do that? > Looks like overkill to me even if it can. > > The LM2576 could be controlled by a multiplying DAC over some range, > seems a bit dangerous... > > (reference DAC on output, output DAC on feedback of LM2576). > Output voltage limited to whatever the DAC can stand, > add resistor divider for more, could even work, but DAC to zero would > create zero feedback and push the output way up and saturate that inductor I am sure. > > ------- R -------- Vout > | > 8 bit control --> DAC ----> pin 4 feedback LM2576 > form arduino? | > /// > > And you cannot go to zero that way.
I look at this approach and I see an FPGA rather than a micro. I guess if the switcher is running slow enough an MCU can do the job. But an FPGA can do it for MHz rates. A few external resistors allow adequate DAC and successive approximation ADCs to be used. Rick
On 12/25/2012 6:22 PM, RogerN wrote:
> > Thanks for the replies. > > So around 30 years ago in school we made an oscillator using an Op Amp, > IIRC, this was a comparator circuit with hysteresis and the output caused a > capacitor to charge/discharge. What if the same type of circuit was used in > a buck regulator so when the voltage reached a certain level, the output > would go low, when the output dropped below a lower level, the output would > go back high? Then an analog output could determine the comparator voltage. > That may not be perfect SMPS design but I would think it would be good > enough to charge batteries, probably need to switch off to take measurements > or at least filter the measurement. > > RogerN
I'm not really a switching regulator guy, but I bet that has a name and is one of the older techniques with some well known set of limitations. Rick
On 12/25/2012 8:45 AM, Nico Coesel wrote:
> "RogerN"<regor@midwest.net> wrote: > >> >> I'm wanting to use a microcontroller to control the output of a switching >> regulator, maybe something like a LM2576 simple switcher. I see the > > Use a fast microcontroller (IOW: ARM) and use the PWM + ADC from the > controller to do what you want. >
Wouldn't a PWM be rather slow to control the feedback to the switcher? A PWM takes time to settle to a new value if it has much resolution. Rick