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.
[...] 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.
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.