Software Controlled SMPS - Page 1
Forum section: electronics / general

author: BadeBhaiya
author_rank: Regular Contributor
timestamp: May 31, 2025, 09:16:07 am
content: Hello all, hope you are doing well.I have recently been obsessed with the idea of software controlled SMPSes, where instead of using a dedicated chip, I instead use a microcontroller to handle the switching, feedback and error correction. It has been very fun, and educational. Fiddling the control loop has also been fun, albeit the pile of burnt MOSFETs. Would putting a small capacitor in series work to deal with MCU latch-ups?What boggled my mind is that even if I am switching at say 1MHz, I need an MCU which is at least 10x or more faster than the switching frequency. The ADC sampling, even with DMA takes a fair bit of time (if I want low noise samples). The timing of sampling is also very important, I need to match the ADC sampling with the switching off/on period (I am using an STM32, have configured the hardware timer handling the switching to start the ADC conversion automatically, at the turning off of the MOSFET)

author: BadeBhaiya
author_rank: Regular Contributor
timestamp: May 31, 2025, 09:25:08 am
content: Transient response is absolutely horrible, by the way, I'm getting several volts worth of overshoot and undershoot, before it takes a few milliseconds to fully settle down.Any idea what I might be doing wrong? I'm using an STM32G030F6 clocked at 64MHz. I'll post some schematics and oscilloscope captures when I can. Control loop is a simple "adjust duty cycle when lower and higher than setpoint" kind of deal, with a 50mV band where its supposed to not do anything (aka keep constant PWM)Switching frequency is 200KHz, its boosting 4.2V from a li-ion battery (3P) to 12V. Output is connected to a 20W LED. The MOSFET is begin driven by a simple BJT push-pull driver.

author: NiHaoMike
author_rank: Super Contributor
timestamp: May 31, 2025, 12:59:53 pm
content: Try reducing C20 to 1nF or even 100pF. You'll also have to learn about control loop theory to do it well.

author: voltsandjolts
author_rank: Unknown
timestamp: May 31, 2025, 01:07:54 pm
content: For quick response, C20 should be less capacity and should not go to GND, it should go to OUTPUT_VOLTAGE.

author: langwadt
author_rank: Super Contributor
timestamp: May 31, 2025, 01:27:45 pm
content: add current sense to the fet and use the trigger input on the timer to control the pwm, the stm32g4 has comparators with connection to the dac for that. You might also be able to (ab)use the adc watchdog to do that. Usign the break input to shutdown the timer if the voltage gets too high might also make sense

author: BadeBhaiya
author_rank: Regular Contributor
timestamp: May 31, 2025, 03:48:37 pm
content: A small difference to the schematics, the output decoupling is 4x 10uF X7R instead of the large 220uF. C20 is indeed however 10nFHere are some captures.Fist is the switching node waveform. Looks fine I think?Second is the gate waveform. I can see some major ringing (I removed gate resistor to experiment with switching losses, for a bit)Third is a zoom in of the rise time. This too, looks okay to me, the only point of concern being the ringing

author: nctnico
author_rank: Super Contributor
timestamp: May 31, 2025, 05:18:41 pm
content: The ringing is normal. This is caused by the parasitic capacitances and the inductor. It can be dampened by a snubber circuit.However, I'd investigate whether the PWM controller in the microcontroller you are using can support cycle-by-cycle current limiting in hardware. That way you can use a current sense circuit and turn the MOSFET off in case an overcurrent condition occurs. A current sense circuit can be anything like testing the voltage across the MOSFET, using a current sensing transformer or a current sensing resistor. Personally I like sensing across the MOSFET the best. But you'll need to gate the signal to only be active when the MOSFET is on.

author: BadeBhaiya
author_rank: Regular Contributor
timestamp: May 31, 2025, 05:42:07 pm
content: Why would I need to watch the current across the MOSFET though? In this configuration, even if I stop switching the output voltage is still going to be the BAT_P minus whatever the diode drop happens to be? In case of an overcurrent condition, I can only sit and watch in this particular case. Are you talking about current mode control, by any chance?I could probably rig something up to have an amplifier/comparator sense against a preset current draw (voltage drop) across a shunt and make that cause an interrupt on the MCU. It can probably be not done right in hardware (I am unsure, a more thorough study of the datasheet is required) I am however confident that I can do it in software and using interrupts, make it quite fast. I do have another 2 ADCs on the MCU not being used but considering the amount of time it takes for one conversion, I don't think it would be the best solution to use an ADC for this.My ultimate goal is to learn techniques to make transient response super good, if possible as good as mATX power supplies have (power quality which is expected by computer motherboards). I hope to make a decent PSU in future to power my computer directly from the 48V DC from a 450W solar panel that I have. Well that's quite far in the future, not too relevant right now

author: nctnico
author_rank: Super Contributor
timestamp: May 31, 2025, 05:48:58 pm
content: It is to watch the current through the MOSFET. At some point the inductor will saturate and become a short. With the MOSFET on, you'll have a short between the battery and ground. Likely the reason you blew a few MOSFETs alreadyUsing an interrupt may not be good enough. If the microcontroller doesn't support turning off the PWM, the best way is to use a couple of discrete flip-flops and AND gates. At overcurrent the flip-flop gets reset and switches the MOSFET off.

author: BadeBhaiya
author_rank: Regular Contributor
timestamp: May 31, 2025, 05:53:29 pm
content: Ah that makes sense, in that case it is a valuable safeguard...

author: langwadt
author_rank: Super Contributor
timestamp: May 31, 2025, 06:47:27 pm
content: Quote from: BadeBhaiya on May 31, 2025, 05:42:07 pmthe STM32G030F6 (and most other STMs) can do it right in hardware. Break input to halt the timer and set to the output to a selectable state, trigger input to do cycle-by-cycle current limiting

author: tom66
author_rank: Super Contributor
timestamp: May 31, 2025, 07:50:48 pm
content: I've done this before. It can work reasonably well but usually the MCU doesn't have enough loop bandwidth to cope with very rapid load swings which can cause ringing as you need to damp the PID loop down quite a bit. But for constant loads (e.g. LED backlight for a product is one time I have done it), it can be cheaper than using a dedicated IC.

author: scuzzyTerminator
author_rank: Regular Contributor
timestamp: May 31, 2025, 11:42:52 pm
content: Aren't capacitors kind of medieval? Why not go all the way and use digital filters (sense and/or control)? Of course you still need sample filter capacitors.Just an idea, I don't know much about this.

author: NiHaoMike
author_rank: Super Contributor
timestamp: June 01, 2025, 03:41:33 am
content: Quote from: tom66 on May 31, 2025, 07:50:48 pmThere are microcontrollers specifically designed for "digital power" applications such as dsPIC and C2000, those can outperform analog controllers.

author: Siwastaja
author_rank: Super Contributor
timestamp: June 01, 2025, 09:25:54 am
content: Quote from: NiHaoMike on June 01, 2025, 03:41:33 amAlso note dsPIC and C2000 were new and popular 15-20 years ago. They might still be relevant to some, but now many mainstream MCU series include similar features. I have used STM32F334, for example.(edit: fix part number)

author: nctnico
author_rank: Super Contributor
timestamp: June 01, 2025, 10:09:46 am
content: Quote from: tom66 on May 31, 2025, 07:50:48 pmWhether you need a lot of loop bandwidth also depends on the kind of controller and what parts are used. For a flyback style DC-DC converter, the vin / vout ratio is dictated by the PWM duty cycle. If you employ a low loss inductor, use synchronous rectification (to avoid varying diode forward voltage) and have a relatively stable input voltage, then the output voltage will be pretty stable when applying a fixed duty cycle.

author: BadeBhaiya
author_rank: Regular Contributor
timestamp: June 01, 2025, 10:14:20 am
content: Quote from: tom66 on May 31, 2025, 07:50:48 pmQuote from: Siwastaja on June 01, 2025, 09:25:54 amCould you guys share some details? What made you make your own power supply? Any interesting requirements or constraints?Please everyone feel free to talk about this topic, I'm loving the info exchange

author: Siwastaja
author_rank: Super Contributor
timestamp: June 01, 2025, 06:53:55 pm
content: Quote from: BadeBhaiya on June 01, 2025, 10:14:20 am(Note the corrected part number F334 in above post).Bidirectional synchronous buckPurpose: battery testing / cycling / measurement systemWhy? Avoid a lot of power dissipation of typical dummy resistive load, instead discharge the DUT into a larger "stationary" battery pack, and during charge cycle, charge it from there.Vin = 9-12VVout=2.5-4.5VIout = 20A per channel, each channel 1-phase synch buck, 4 channels per PCB, channels phase-interleaved by 90 deg each, channels can be paralleled, so one PCB can run a single 80A battery (as 4-phase converter), or four 20A batteries (as four separate 1-phase converters), or any other combination.f_sw I forgot, but somewhere around 150kHz it was.Why MCU control? Turns out that even though bidirectional buck is exact same topology than normal synchronous buck, getting this, plus accurate CC mode current limit (instead of hickup or some other mode where current limitation is considered a failure), is nearly unheard of in controller ICs. There was some ancient expensive AD part and that's all I could find. And datalogging etc. is needed anyway, so MCU will be there...MCU used was STM32F334 (just a few bucks), with the following idea:Internal DAC generates reference level for peak inductor current,Internal DAC is routed to internal analog comparatorInductor current measurement (from external shunt amplifier) is fed to said analog comparatorAnalog comparator output is fed to the HRTIM peripheralCycle is started with the timer (allowing synchronization and phase-shifting of the four converters) and stopped by the overcurrent signal on the top of the triangle wave.This results in peak current mode controller; i.e., if the DAC is set at 10A, and dI_L is 4A, then it would ramp between 6A and 10A, with average current of 8A.Because accurate CC mode was important, the very same inductor current signal (from same physical MCU pin!) was also routed to (internal) ADC, which sampled it with high enough sample rate so that many (IIRC well over 10) samples were taken during each switching cycle, catching the average inductor current. This controlled a simple PI control loop to adjust a "fine tune" setting added to the DAC setpoint. As a result, when current setpoint is changed, transient response is perfect within some % of value - i.e., current rises or falls as quickly as inductor physically allows, and the PI loop makes the tiny correction between the theoretical average inductor current (IL_max - dIL/2) and what it really ends up being.Voltage control was then added as it should be on a current-mode controller: on upper level so that input = voltage -> output = current setpoint. Simple PI controller it was. In my case, battery voltage does not change quickly, so I deliberately tuned it for crappy transient response.You can easily avoid blown MOSFETs during development. Start with the current sense path and test that it works - e.g. by discharging a charged electrolytic capacitor in the shunt resistor and looking at the gate driver output (without power applied to the stage yet). This way you rule out inductor saturation in edge cases (such as startup, not to mention output short circuit) leading to overcurrent killing the FETs. Now another thing you need to rule out is overvoltage killing the FETs, which you do by ramping up supply voltage carefully while testing with maximum output current and scoping the Vds, to see if you have serious switch node ringing issues. Mitigate with layout fixes or snubbers before going to final full voltage.

author: amyk
author_rank: Super Contributor
timestamp: June 01, 2025, 08:24:38 pm
content: I'd rather not have any more software running in a place where failure (or sabotage?) could cause severe damage. Traditional analog SMPS tend to fail a bit more predictably and in obvious ways.

author: jonpaul
author_rank: Super Contributor
timestamp: June 02, 2025, 06:06:55 am
content: dangerous, impractical and waste.Since 1970s, The IC controllers are low cost and prooven reliability.j

author: tautech
author_rank: Super Contributor
timestamp: June 02, 2025, 07:21:21 am
content: A novel approach is using a VCO…..

author: Slh
author_rank: Regular Contributor
timestamp: June 02, 2025, 07:35:27 am
content: Do you have a simulation for testing the control loop? It will save you a bunch of MOSFETs (although you still have to get the PWM peripherals set up right.I spent a bit of time last year getting mixed signal dcdc controller simulations running in Kicad 8 which was quite successful.https://forum.kicad.info/t/another-tidier-mixed-mode-simulation-model-dual-phase-ipt-buck-converter/57779That's a link to one of my examples. There's a few more simpler models linked to my account there. They all have an inner current control loop and outer voltage controller.

author: BadeBhaiya
author_rank: Regular Contributor
timestamp: June 02, 2025, 07:50:46 am
content: @Siwastaja sounds very cool. From your description it sounds less like a traditional "switching converter" and more like a current limiting circuit (which it is, in a way). Very analogue peripheral heavy too, that's great because that leaves plenty of processing time for anything else you might want to run. I bet you didn't have to do much after setting up the peripherals in the beginning and letting the connected signals do the rest.

author: jonpaul
author_rank: Super Contributor
timestamp: June 02, 2025, 08:44:17 am
content: Hello again:What mains V/input/output? Power level?SMPS design and debugging takes a lot of experience, and specialized lab equipment.Above 42V, (eg mains 120/240V) debugging can be dangerous.At 1 MHz you need soft switching/resonant converters.See the many books and papers and seminars/app notes on SMPS topology, ICs, inductors, etc.Jon(consulted Power Electronics since 1970s)

author: Siwastaja
author_rank: Super Contributor
timestamp: June 05, 2025, 06:44:14 pm
content: Quote from: amyk on June 01, 2025, 08:24:38 pmStrongly disagreed.Classic analog controllers are full of design errors and totally unexpected features.During another software-driven DC/DC (case 2 which I was going to write about but didn't have time), almost all development grieve was caused by gate driver's "analog" features misbehaving seriously, unexpectedly, and against datasheet. And some more grieve from current sense amplifier IC "behaving weirdly" but that was at least "normal" phenomenon for opamps (slow recovery after saturation) we engineers "should know about".In any case, your suggestion of keeping analog is not really useful in real life, because digital power controllers are constructed in lack of having a suitable analog controller IC.Of my first case study (see above), I implemented first version analog (some opamps, comparators, and XOR logic), and while it was a really interesting project in itself, it had high component count, and it behaved in chaotic ways near zero current, and that part was just the current loop alone. The complexity and unreliability of the design was really the reason to re-do it digitally.Digital gives you possibility to analyze exactly what the code does, add error checking and reporting - even log and plot critical variables.Safety critical anything has been all digital for 30-40 years for very good reasons.But of course, if you just want some very usual topology, you will find a well-tested, used by many controller IC which costs $0.50 and does the job reliably - probably analog. Then of course use that.

author: langwadt
author_rank: Super Contributor
timestamp: June 05, 2025, 11:45:51 pm
content: Quote from: Siwastaja on June 05, 2025, 06:44:14 pmand with digital you can handle the special cases analog alone won't handle

author: radiolistener
author_rank: Super Contributor
timestamp: June 06, 2025, 12:17:56 am
content: It all depends on your goal. Let’s not forget - there are situations where reliability is actually undesirable. For example, if you're designing for planned obsolescence, analog circuits can be annoyingly long-lived. They just sit there, doing their job... for decades.With digital control, on the other hand, you get programmable wear-out, undocumented features, bugs, and even OTA firmware sabotage - all the modern luxuries a covert ops team or marketing department could dream of.So yes, analog might fail gracefully. But digital? Digital can fail on schedule.

author: kensmith
author_rank: Newbie
timestamp: June 06, 2025, 09:39:48 am
content: Sounds like you're learning a lot — and yeah, blowing up a few MOSFETs is almost a rite of passage when messing with SMPS designs 😅Using an MCU for control definitely gives you flexibility, but timing gets tricky fast. You're right that the MCU needs to be much faster than the switching frequency — not just for ADC sampling, but also for running the control loop and handling any interrupts or filtering.Triggering the ADC from the timer at MOSFET turn-off is a smart move. That should help reduce noise during sampling. As for latch-ups, a small series cap might not really fix that — better power filtering, decoupling caps, and maybe even isolating the logic supply could help more.It’s definitely a challenging project, but a fun one. Keep going!

author: BadeBhaiya
author_rank: Regular Contributor
timestamp: June 06, 2025, 12:09:26 pm
content: Quote from: jonpaul on June 02, 2025, 08:44:17 amHey Jon, sorry for the late response. I'm just bumbling around and learning for now, I don't have any particular goal except for the one mentioned above (ATX tier DC-to-DC PSU)

author: UnijunctionTransistor
author_rank: Frequent Contributor
timestamp: June 06, 2025, 02:58:37 pm
content: Wonderful project, keep us abreast of progress or stumbling blocks.My only suggestion would be to test the heck out of step response. Load, line, voltage setup.

author: paul cotter
author_rank: Regular Contributor
timestamp: June 06, 2025, 03:32:33 pm
content: I presume this is a current mode design. Most dedicated chips have a blanking interval before current monitoring is initiated to stop switch-on spikes destabilising the loop. Maybe a short pause before enabling the ADC? This is just a wild guess as I have never attempted such a scheme.

author: jnk0le
author_rank: Regular Contributor
timestamp: June 07, 2025, 10:31:56 am
content: with your circuit, you can also go for the voltage mode loop,- get rid of C20- stm32g0 is probably too slow for 200khz 3p3z/PID, not to mention lack of interrupt nesting- at 200khz the HRTIM might be necessary due to lack of timer resolution(f334 or g474 is the goto for smps, other brands offer similar devices)https://www.st.com/resource/en/application_note/an5788-stm32-digital-power-pid-and-iir-filters-for-smps-control-design-and-comparison-on-bg414edpow1-discovery-kit-stmicroelectronics.pdfhttps://www.st.com/resource/en/application_note/an5785-boost-voltage-mode-on-bg474edpow1-discovery-kit-stmicroelectronics.pdfQuoteDoes your LED have own CC driver (or at least a limiting resistor)?