Forums

MicroController control for switching regulator

Started by RogerN December 25, 2012
On 12/26/2012 2:10 PM, krw@attt.bizz 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. >> >> 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.
Hmmm... I guess it would require another chip or two, but would a switched capacitor be a viable alternative to a bunch of resistors and transistors? I looked at these some ten or more years ago in filter circuits; the capacitor switched between the input and output shuttling current. The faster it was switched the more current it carried and so the lower resistance it appeared to be. This allowed analog filters to be continuously varied. In this case it could allow for *relatively* continuous adjustment of the feedback ratio by adjusting the switching frequency. This likely would be best done in an FPGA that can use a DCO to drive the switch rate. It has similar limitations to digital designs and so needs a switching rate far above the frequency of interest. I guess that would rule it out for this app since the feedback has to be adjusted fairly quickly. Rick
mike <ham789@netzero.net> wrote:

>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?
Yes. PIC and other 8 bit controllers are a stepping stone anyway. At some point you have to move forward. Besides that the software to compile for ARM microcontrollers is completely free.
>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.
Adding more horsepower usually shortens time to market because it allow the software to stay simple and easy to maintain. Ofcourse this doesn't prevent an idiot from shooting his own foot but that is hardly an argument. I've seen many designs where people got creative using many PICs in one device where a real microcontroller would have been a much better solution. -- Failure does not prove something is impossible, failure simply indicates you are not using the right tools... nico@nctdevpuntnl (punt=.) --------------------------------------------------------------
On 12/27/2012 1:17 AM, Nico Coesel wrote:

> > Yes. PIC and other 8 bit controllers are a stepping stone anyway. At > some point you have to move forward. Besides that the software to > compile for ARM microcontrollers is completely free. >
I could use a project. Point me to your favorite free basic-like compiler for the ARM. Something with lots of available functions so I don't have to reinvent the wheel for I/O or display drivers or keyboard muxes data formatting etc. Life is too short to program in C. Period...I don't need or want to hear otherwise. Come to think about it, I already have a basic-like compiler for my Dell Axim X51v. So I guess I already program an ARM.
On a sunny day (Wed, 26 Dec 2012 19:47:39 -0500) it happened "P E Schoen"
<paul@peschoen.com> wrote in <kbg5rk$s0i$1@dont-email.me>:

>"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 >from the ISR? What if two interrupts occur only a few instruction cycles = > >apart? > >Paul
Yes, good point, laziness, cut and paste from other projects, only serial interrupt and timer interrupt are used, so if that conflicts for timer main will update the LCD some ms later, for serial port you could theoretically miss a character, never seen that though, something for verion 0.4 perhaps. Never fix something that works though... Thanks for pointing it out!
mike <ham789@netzero.net> wrote:

>On 12/27/2012 1:17 AM, Nico Coesel wrote: > >> >> Yes. PIC and other 8 bit controllers are a stepping stone anyway. At >> some point you have to move forward. Besides that the software to >> compile for ARM microcontrollers is completely free. >> >I could use a project. Point me to your favorite free basic-like compiler >for the ARM. Something with lots of available functions so I don't have >to reinvent >the wheel for I/O or display drivers or keyboard muxes data formatting etc. >Life is too short to program in C. >Period...I don't need or want to hear otherwise.
http://www.eluaproject.net/ -- Failure does not prove something is impossible, failure simply indicates you are not using the right tools... nico@nctdevpuntnl (punt=.) --------------------------------------------------------------
"rickman"  wrote in message news:kbi5tm$uek$4@dont-email.me...

>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
I got the idea after reading a description of a chopper stepper motor driver. It said something like when the current dropped below the set-point, the transistor was switched ON, when the current went above, the transistor was switched OFF. When switched OFF, the current would flow through the rectifier as the motors magnetic field collapsed. Seemed to be pretty much a buck type regulator with the motor coil as the inductor. I thought of the op-amp oscillator we made in college around 30 years ago, as the capacitor would charge, once the voltage rose above the comparator voltage, the output would go low, discharging the capacitor, it would also lower the comparator voltage making a hysteresis. Seems such a circuit would make a regulator acceptable for battery charging even if not as good as a SMPS regulator. RogerN
"Tim Wescott"  wrote in message 
news:ZO-dnalKjYHz2kbNnZ2dnUVZ_vOdnZ2d@web-ster.com...

<snip>
>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. >
<snip>
>-- >Tim Wescott >Control system and signal processing consulting >www.wescottdesign.com
If I'm thinking about this correctly, seems a DAC output of 0-5V could feed a voltage divider (or pot) set so that at 5V the divider output (or wiper) voltage is around 1.23V. This could then go to the feedback at the point the feedback resistor goes to ground. When the DAC output is 0V, the regulator would output at whatever the feedback pin was set for (maybe 13.8V), as the ADC output went from 0V up to 1.23V, the regulator output would go down from 13.8V to 1.23V. My current application is to charge LiPo's in parallel limiting the maximum current for the cell with the highest current. This is so that multiple batteries could be charged in parallel and wouldn't have to be at the same level of discharge. Such as a current limit of 1C, first cell to reach 1C current limits the charge, but if all cells are balanced then each cell in parallel can get 1C of current. (C being battery capacity, my 200 milliamp hour cells are charged at 200 milliamps. RogerN
On Dec 27, 5:26=A0am, rickman <gnu...@gmail.com> wrote:
> 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 caus=
ed a
> > capacitor to charge/discharge. =A0What if the same type of circuit was =
used in
> > a buck regulator so when the voltage reached a certain level, the outpu=
t
> > would go low, when the output dropped below a lower level, the output w=
ould
> > go back high? =A0Then an analog output could determine the comparator v=
oltage.
> > 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 measure=
ments
> > 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
"hysteretic" -Lasse
On Wed, 26 Dec 2012 23:51:09 -0500, rickman <gnuarm@gmail.com> wrote:

>On 12/26/2012 2:10 PM, krw@attt.bizz 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. >>> >>> 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. > >Hmmm... I guess it would require another chip or two, but would a >switched capacitor be a viable alternative to a bunch of resistors and >transistors? I looked at these some ten or more years ago in filter >circuits; the capacitor switched between the input and output shuttling >current. The faster it was switched the more current it carried and so >the lower resistance it appeared to be. This allowed analog filters to >be continuously varied. In this case it could allow for *relatively* >continuous adjustment of the feedback ratio by adjusting the switching >frequency. This likely would be best done in an FPGA that can use a DCO >to drive the switch rate. It has similar limitations to digital designs >and so needs a switching rate far above the frequency of interest. I >guess that would rule it out for this app since the feedback has to be >adjusted fairly quickly.
That sounds like it should work but just PWMing a switch and resistor in parallel with the bottom resistor will do the same thing. The problem with either of these solutions is that you're going to see noise in the output because you can't easily filter the feedback node.
On Thu, 27 Dec 2012 15:46:25 -0600, RogerN wrote:

> "Tim Wescott" wrote in message > news:ZO-dnalKjYHz2kbNnZ2dnUVZ_vOdnZ2d@web-ster.com... > > <snip> >>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. >> > <snip> >>-- >>Tim Wescott >>Control system and signal processing consulting www.wescottdesign.com > > If I'm thinking about this correctly, seems a DAC output of 0-5V could > feed a voltage divider (or pot) set so that at 5V the divider output (or > wiper) voltage is around 1.23V. This could then go to the feedback at > the point the feedback resistor goes to ground. When the DAC output is > 0V, the regulator would output at whatever the feedback pin was set for > (maybe 13.8V), as the ADC output went from 0V up to 1.23V, the regulator > output would go down from 13.8V to 1.23V.
Yup. That sounds about right. I wouldn't use a pot -- just a resistive divider that cuts your maximum DAC voltage down to 1.23V (or whatever voltage makes for your desired minimum output voltage).
> My current application is to charge LiPo's in parallel limiting the > maximum current for the cell with the highest current. This is so that > multiple batteries could be charged in parallel and wouldn't have to be > at the same level of discharge. Such as a current limit of 1C, first > cell to reach 1C current limits the charge, but if all cells are > balanced then each cell in parallel can get 1C of current. (C being > battery capacity, my 200 milliamp hour cells are charged at 200 > milliamps.
The switching part of the circuit should work. I'm not sure that LiPo's charge that way -- if the "at rest" voltage is always constant then this scheme will work. If the "at rest" voltage depends on charge level (which is not what most batteries do, but LiPo chemistry is different) then you may have uncontrolled currents flowing as soon as you plug things together. An alternative is to just charge at an overall current set to the maximum rate of charge of your least-capable cell. A good portion of the LiPo charge cycle is spent in constant-voltage mode, so you don't really take all that much away from the charge time, and you can pretty much just slap everything into a commercial charger at that point. -- 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