Forums

MicroController control for switching regulator

Started by RogerN December 25, 2012
"RogerN" <regor@midwest.net> wrote in message 
news:U4qdndoweLjsC0TNnZ2dnUVZ_qudnZ2d@earthlink.com...
> > 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.
Generate control DC voltage by microcontroller PWM. Add this voltage to the feedback input of the switcher. Thus higher PWM voltage results in proportionally lower switcher output. Two resistors, capacitor and little math is all it takes. Done that many times. Works very well. Vladimir Vassilevsky DSP and Mixed Signal Consultant www.abvolt.com
"RogerN"  wrote in message=20
news:U4qdndoweLjsC0TNnZ2dnUVZ_qudnZ2d@earthlink.com...

> I'm wanting to use a microcontroller to control the output of a =
switching=20
> regulator, maybe something like a LM2576 simple switcher. I see the=20 > adjustability is on the feedback lead but what's the best way make it=20 > adjustable from a microcontroller. I'm guessing the feedback may be =
used=20
> in switching timing, ie, I guess I can't just use a DAC and get an =
output=20
> 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=20
> experimentation) for custom battery charging experimentation.
You might want to look at Microchip's new line of PICs with on-board=20 switchmode controllers: http://ww1.microchip.com/downloads/en/AppNotes/01468A.pdf They are only about $2, and include other advanced peripherals: http://www.mouser.com/ProductDetail/Microchip-Technology/PIC16F1782-I-SS/= ?qs=3DsGAEpiMZZMtEh3uSYjX9TmwiJxFghZLW For a battery charger, you may do better with one of the dedicated = battery=20 management ICs, especially if you are using LiFePO4 or NiMH or other = more=20 critical chemistry: http://www.digikey.com/product-search/en?lang=3Den&site=3Dus&KeyWords=3DL= T1511&x=3D16&y=3D14 http://www.digikey.com/product-detail/en/LT3652HVIMSE%23PBF/LT3652HVIMSE%= 23PBF-ND/2334070 http://www.digikey.com/product-detail/en/BQ2000SN-B5TR/296-25915-1-ND/225= 4787 http://www.digikey.com/product-detail/en/BQ2000PN-B5/296-9313-5-ND/379879= Paul=20
On a sunny day (Tue, 25 Dec 2012 09:29:20 -0600) it happened "Vladimir
Vassilevsky" <nospam@nowhere.com> wrote in
<laGdnYSJLdTVW0TNnZ2dnUVZ5qednZ2d@giganews.com>:

> >"RogerN" <regor@midwest.net> wrote in message >news:U4qdndoweLjsC0TNnZ2dnUVZ_qudnZ2d@earthlink.com... >> >> 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. > >Generate control DC voltage by microcontroller PWM. Add this voltage to the >feedback input of the switcher. Thus higher PWM voltage results in >proportionally lower switcher output. Two resistors, capacitor and little >math is all it takes. Done that many times. Works very well. > >Vladimir Vassilevsky >DSP and Mixed Signal Consultant >www.abvolt.com
Right, way to go! That is what I did here: http://panteltje.com/pub//PMT_regulated_power_supply_diagram_img_3182.jpg
On Tue, 25 Dec 2012 21:55:40 +0800, Rheilly Phoull
<rheilly@bigslong.com> wrote:

>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 >> >> >The ADC in the Arduino is not too flash, as in not being stable. You >will see the value "jitter" up and down. Previous advice about using >purpose designed devices would seem a better idea to me :-)
Software lowpass filter the ADC samples. You'd want to do that even if the ADC was perfect. Any signal near a power switcher is going to be noisy. The most elegant way to do this job is to use the uP PWM to drive the switcher stage, and use the ADC to measure input voltage, output voltage, and current. Or, the OP could use a DAC (or a PWM made into a DAC) to push the feedback node of the Simple Switcher.
There are battery charger chips designed for universal applications, 
i.e. chemistry independent. I would go that route.

When it comes to safety, the verbiage is often repeated in the datasheet 
just in the event somebody doesn't read the whole thing. Sometimes 
repeated three times.

On 12/25/2012 9:35 AM, John Larkin wrote:
> On Tue, 25 Dec 2012 21:55:40 +0800, Rheilly Phoull > <rheilly@bigslong.com> wrote: > >> 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 >>> >>> >> The ADC in the Arduino is not too flash, as in not being stable. You >> will see the value "jitter" up and down. Previous advice about using >> purpose designed devices would seem a better idea to me :-) > > Software lowpass filter the ADC samples. You'd want to do that even if > the ADC was perfect. Any signal near a power switcher is going to be > noisy. > > The most elegant way to do this job is to use the uP PWM to drive the > switcher stage, and use the ADC to measure input voltage, output > voltage, and current.
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. 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. For a 20kHz. PWM frequency, can you really get enough resolution? Or do you dither the clock and the duty factor or???? Got some sage advice on the tricks of the trade?
> > Or, the OP could use a DAC (or a PWM made into a DAC) to push the > feedback node of the Simple Switcher. > >
On Tuesday, December 25, 2012 8:13:12 PM UTC+2, mike wrote:
> On 12/25/2012 9:35 AM, John Larkin wrote: > > The most elegant way to do this job is to use the uP PWM to drive the > > switcher stage, and use the ADC to measure input voltage, output > > voltage, and current.
> 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 do the measurement at the same rate as the PWM PRF. Even if you did, a low end PIC can cope easily.
> > 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.
Actually it gets remarkably elegant using interrupts. YMMV I guess. High priority interrupts A to D that controls the PWM driving the switching FET and low priority interrupts for the keyboard, serial port or whatever.
> For a 20kHz. PWM frequency, can you really get enough resolution?
I've used a bit higher, 28Khz or so. Depending what you want (battery charger?) 6+ bits is fine - it will dither due to the measurement on the A to D correcting it.
On 12/25/2012 11:08 AM, Rocky wrote:
> On Tuesday, December 25, 2012 8:13:12 PM UTC+2, mike wrote: >> On 12/25/2012 9:35 AM, John Larkin wrote: >>> The most elegant way to do this job is to use the uP PWM to drive the >>> switcher stage, and use the ADC to measure input voltage, output >>> voltage, and current. > >> 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 do the measurement at the same rate as the PWM PRF. Even if you did, a low end PIC can cope easily. > >> >> 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. > > Actually it gets remarkably elegant using interrupts. YMMV I guess. > High priority interrupts A to D that controls the PWM driving the switching FET and low priority interrupts for the keyboard, serial port or whatever. > >> For a 20kHz. PWM frequency, can you really get enough resolution? > > I've used a bit higher, 28Khz or so. Depending what you want (battery charger?) 6+ bits is fine -
it will dither due to the measurement on the A to D correcting it. Ok, if you're gonna tolerate the noise of a cycle/cycle regulator, I guess 2% resolution is fine. I don't have a problem with dither as long as it's filtered and doesn't show up in the output. I've never tried to use a switcher as a bench supply. I think I'd want to start with a high-res PWM and cycle skip to handle load dumps.
On Tue, 25 Dec 2012 10:13:12 -0800, mike <ham789@netzero.net> wrote:

>On 12/25/2012 9:35 AM, John Larkin wrote: >> On Tue, 25 Dec 2012 21:55:40 +0800, Rheilly Phoull >> <rheilly@bigslong.com> wrote: >> >>> 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 >>>> >>>> >>> The ADC in the Arduino is not too flash, as in not being stable. You >>> will see the value "jitter" up and down. Previous advice about using >>> purpose designed devices would seem a better idea to me :-) >> >> Software lowpass filter the ADC samples. You'd want to do that even if >> the ADC was perfect. Any signal near a power switcher is going to be >> noisy. >> >> The most elegant way to do this job is to use the uP PWM to drive the >> switcher stage, and use the ADC to measure input voltage, output >> voltage, and current. > >Got any tips on how to do this?
The easy way is exponential smoothing, the equivalent of a 1st order RC lowpass filter. Filt_Val = Filt_Val + (ADC_Val - Filt_Val) / K where, if you work in intgers, you can do the divide-by-K as a right shift. Filt_Val = Filt_Val + ( (ADC_Val - Filt_Val) >> N ) It's all signed. N might be, say, 16 or 256 or something. The data has to be aligned such that you don't roll bits off the end when you do the right shift. Using a 32-bit Filt_Val simplifies life; the ADC sample should be up-shifted maybe 16 bits before the math is done. If you do this in floats, it's simpler but slower; don't worry about alignment at all. Filt_Val = Filt_Val + J * (ADC_Val - Filt_Val) since multiplies are faster than divs. J = 0.01 would give the filter a time constant 100x the sample rate.
>At 20 kHz. you have 50microseconds to do two measurements, update >the displays, and decide whether and how to tweak the PWM.
If you do all the math as ints, that should be possible. We've done more complex stuff, filtering and PID control and error checks at 100 KHz on a cheap ARM.
> >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. > >For a 20kHz. PWM frequency, can you really get enough resolution? >Or do you dither the clock and the duty factor or????
If you don't have a real DAC, run the PWM as fast as it will go. That's not the same rate at which you might run the filtering and control algorithm. One trick is to filter the ADC data twice; a fast filter for the control path and a slow one for display cosmetics. If you filter too much in the control path, the loop can go unstable. A P+I controller with low P may not need filtering at all.
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