Current sensing for buck boost converter

Hi guys,

I'm actually working on a buck-boost led driver to power high brightness LED.
As theses LED must be driven by constant current I wish to monitor the current flowing through the LEDs, and limit it when it reach the operating current i wish for the LEDs

a) can someone comment my schematic, and point me out what's wrong ? I just have some basis in electronics so this schematics is not the best one

b) for the current sensing application what kind of algorithm should I use to have the most stable current to the leds.
ie :
arduino sense voltage out the OpAmp
while current > xAmp // derived from OpAmp out
lower dutyCycle of MOSFET
end
set dutyCycle to theoretical value

c) The frequency use for driving the mofset is ~100khz which king of filter should I use on the OpAmp input ? A simple capacitor ?

Thanks for you time
BR

Note : Rsense = 0,02
All OpAmp resistors do not have the good value so gain

Your design could not have worked.

The typical design is to put a serial resistor in with the leds. This resistor generates a voltage drop proportional to the current going through the leds. That signal is then compared with a preset threshold to determine if you shut down the switch or not.

This mode of regulation produces a (near) constant current that is irrelevant of the leds' forward voltage drop. And by changing the resistor, you can program the current going through the leds.

Your design does none of that.

I don't really have anything to add, except that I think a software-controlled boost-buck driver is a super-cool application for a microcontroller (no need for messing with PWM for dimming, simply vary the switch mode duty cycle, in software, to alter output current). So I'd love to see the final design!

Not sure what exactly you are trying to build, and I am sure avrs are completely capable here. But Freescale completely dominates that market (mcu-controlled smps), probably for a good reason. If you are serious about this, you may check those guys out.

What you have looks perfectly reasonable. the sensing is... ok but the LM358 isn't a rail to rail device so you loose some range... Possibly. I'd build the current sensor and model it carefully at the rated load and then some, I'd also try it with long wires too first with a dc supply for performance and sensitivity and then go to the switcher and see that it was as stable with the switcher in place.
the issue here is to get the current sensor working first and feeding the correct information back to the Proc.. so the proc can control it
I would also give some thought to the Hall effect current sensors made by Allegro (ACH712) as they will produce a voltage that can be above Vcc/2 or below it at up to 185mV/amp, are inexpensive and don't require a sense resistor. All in all they are at first glance an ideal solution and work off of 5 volts too. I took the liberty of attaching a data sheet.

Bob

ACS712-Datasheet.pdf (652 KB)

The attached schematic shows a simpler way for you to monitor the current and smooth the reading. Choose the ratio R2/R1 to get the range you need, and the capacitor in parallel with R2 to get the smoothing time constant you want.

However, the average power supply current is not the same as the average LED current. Maybe you should be monitoring the peak current passed by the mosfet instead?

tylernt:
I don't really have anything to add, except that I think a software-controlled boost-buck driver is a super-cool application for a microcontroller (no need for messing with PWM for dimming, simply vary the switch mode duty cycle, in software, to alter output current). So I'd love to see the final design!

For information, the final design is to drive one or more High Brightness Led in the most efficient way to use it in caving lighting (helmet mount) or dive lighting.

Docedison:
[...] the LM358 isn't a rail to rail device so you loose some range...
I would also give some thought to the Hall effect current sensors made by Allegro (ACH712) as they will produce a voltage that can be above Vcc/2 or below it at up to 185mV/amp, are inexpensive and don't require a sense resistor.

Thanks for the advice about Hall sensor I check the datasheet and seems it can sense up to 5A in normal operating mode it feet perfectly the usage. I'll check later on that.

dc42:
The attached schematic shows a simpler way for you to monitor the current and smooth the reading. Choose the ratio R2/R1 to get the range you need, and the capacitor in parallel with R2 to get the smoothing time constant you want.
However, the average power supply current is not the same as the average LED current. Maybe you should be monitoring the peak current passed by the mosfet instead?

Thank you for the schematic, I don't know why I do not use it before ! It's just a non-inverter :).
About the average LED current/ power supply current. I thought the power consume by the CPU and other components was negligible vs LED power (~0,7A to 3A).
For the capacitor value do you have any tips to size the capacitance ?

Thanks all for your help and time.

baron-robert:
About the average LED current/ power supply current. I thought the power consume by the CPU and other components was negligible vs LED power (~0,7A to 3A).

Even if you ignore the current taken by the mcu and other components, and you make the simplifying assumpton of 100% efficiency, the average battery current is not the same as the average LED current unless the LED voltage and battery voltage. More specifically:

Average_led_current * led_forward_voltage = battery_voltage * battery_current * efficiency

So if the battery voltage is double the LED forward voltage, then the average LED forward current is double the battery current in the ideal case of 100% efficiency.

If the inductance is large enough, then the current through it will be more or less constant, therefore under these conditions the current through the mosfet when it is turned on equals the current through the LED when the mosfet is off. That is why I think it would be better to monitor the peak current passed by the mosfet.

hi guys,
i resurect this old thread because i was not able to acheive my goal : sense current in a led thread.
Your advices where very usesfull but I still have some problems sensing the current on the mosfet leg. In fact I have unstable values return buy the arduino when i sense the voltage from the output of the OPA. After searching, i think this can be linked to the switching frequency. Is that right ?

If yes do I have to set a low-pass or high-pass filter between the OPA and rsense ?

Docedison:
I would also give some thought to the Hall effect current sensors made by Allegro (ACH712) as they will produce a voltage that can be above Vcc/2 or below it at up to 185mV/amp, are inexpensive and don't require a sense resistor. All in all they are at first glance an ideal solution and work off of 5 volts too. I took the liberty of attaching a data sheet.
Bob

Did anyone know a Hall effect current sensor product (like the one Docedison told) but in DIP package ? I was unable to find this kind of device produced by those manufacturers: linear, allegro or maxim

Thanks for your time !

BR

I would use basically the original arrangement, but put the sense resistor in series with the mosfet source connection instead so that you measure the mosfet source current. Reduce the resolution of the ADC to 8 bits so that you can do faster conversions. Monitor the source current while the mosfet is turned on, then when it reaches the value you want, turn the mosfet off for a predetermined time, say 100us. The snag with this is that the switching frequency will be be the audible range.

Alternatively, use a diode and capacitor to turn your current sense op amp circuit into a peak or average current detector, then you can modify the PWM amount according to the current, and use a supersonic switching frequency.

dc42:
Alternatively, use a diode and capacitor to turn your current sense op amp circuit into a peak or average current detector, then you can modify the PWM amount according to the current, and use a supersonic switching frequency.

Hi dc42!
Thanks again for your reply.
I did not understand what do you mean by using a diode and a capacitor to switch on the op amp. Can your draw a quick scheme or just explain a little bit more ?

See attached peak detector schematic. R1 is the current sense resistor. (R2 + R3)/R2 defines the op amp gain, and C1 * (R2 + R3) defines the time constant, which should be large compared to 1/f where f is the PWM frequency.

Is the Arduino the SMPS controller? if so you will have to measure the peak current when the switch is on and compensate for the inductor current by averaging several 'cycles' and controlling the pulse width from that feedback.
The alternative that I like better is to use a CC supply for each Led (they are available for less than $5.00 on Ebay) and monitor the current drawn by the CC supply for current and time used to make a 'gas gauge'.. instead. You could give your sketch the AH capacity of the battery used and when 40% is gone indicate that this is the 'half way' point so that either reserves can be added or turn around and go back.
While it is entirely possible to use the Arduino for both... it is of questionable utility as it has been pointed out that Freescale has been at this for some time.
Sometimes the Kiss method is best.

Bob
{Edit RKJ}

dc42:
See attached peak detector schematic. R1 is the current sense resistor. (R2 + R3)/R2 defines the op amp gain, and C1 * (R2 + R3) defines the time constant, which should be large compared to 1/f where f is the PWM frequency.

Ok !
So if I want to get the voltage value of Rsense I have to integrate the diode drop voltage ?

Basically :
Vc1 = Vr1 * gain - Vdrop
Otherwise my Ir1 evaluation will be lowered by a 0,7v factor !

Is that right ?

Of course, there are also current sensing MOSFETS:
http://www.nxp.com/documents/application_note/AN10322.pdf

[ The hall sensor mentioned above is ACS712, not ACH712 BTW. ]

If you have a SMPS like this you have to be really careful to shutdown the switch fast if the current goes too high - or else
use a large inductor (slower switching required, more safety margin for saturation).

If the current rises high enough to saturate the inductor then the inductor then just becomes a short-circuit and the current
will slam up to perhaps 10's of amps in a few microseconds or so and blow the MOSFET before the opamp can respond, and certainly
far faster than analogRead()'s 110us execution time.

You would normally use a fast comparator to monitor for this severe overcurrent condition - sub-microsecond response is
good here. Once you have that you might as well let it do the regulation too...

baron-robert:

dc42:
See attached peak detector schematic. R1 is the current sense resistor. (R2 + R3)/R2 defines the op amp gain, and C1 * (R2 + R3) defines the time constant, which should be large compared to 1/f where f is the PWM frequency.

Ok !
So if I want to get the voltage value of Rsense I have to integrate the diode drop voltage ?

Basically :
Vc1 = Vr1 * gain - Vdrop
Otherwise my Ir1 evaluation will be lowered by a 0,7v factor !

Is that right ?

No, the circuit is designed (i.e. op amp feedback resistor taken from the cathode of the diode) so that the diode voltage drop does not enter the equation.

hi !

I finally read a lot on OPAMP because many values seen on tech-doc were completely unknown for me.

My choice for the op-amp is now Maxim MAX4167, this one is a rail to rail input and output op-amp ! While the input can vary from 0.0165V to 0.33V the rail to rail input aspect is very important. The MAX4167 have a 0.25mV-0.85mV Input Offset Voltage so my input voltage will be correctly processed. The Gain-Bandwith is around 36Mhz (input is 170Khz)

My problem is the op-amp gain. I use a non inverting amplifier so Vout = (1+(R2/R1))Vin
With a digital multimeter (and with arduino ADC), I sense a ~0.010V voltage. On the opamp output, voltage is "only" ~0.016V... Something is wrong somewhere because i expect somewhat x10 ? I double check R1 & R2 value everything seem to be okay.

What wrong with this ?
I can attach a photo of the breadboard if you need !

Thanks for your help.
BR