7
\$\begingroup\$

One of the most useful ability of MCUs is generating PWM signal. For example ESP32 duty resolution can be lowered down to 1 bit in which case the maximum frequency is 40 MHz.

With such fast clock speed a 200-500KHz and 10-12 bit resolution is more than enough to build a switching buck or boost converter:

schematic

simulate this circuit – Schematic created using CircuitLab

  • Is there a down-side in using of MCUs PWM to build a switching regulator? (am I going to face any problem?)

  • What advantages switching regulator ICs (like LM2596 or XL6009 etc) have over this method other than simplicity and ease of use?

\$\endgroup\$
2
  • 6
    \$\begingroup\$ One downside is that if your software fails it could damage the circuit board. \$\endgroup\$
    – user253751
    Dec 23, 2019 at 14:12
  • \$\begingroup\$ @user253751 - that's true for a lot of MCUs all of the time (e.g. incorrectly setting PLLs). You are correct that this adds an additional failure mode however. \$\endgroup\$
    – TLW
    Dec 24, 2019 at 19:43

7 Answers 7

11
\$\begingroup\$

10 bits at 200kHz requires a 200MHz peripheral clock, and 12 bits at 0.5MHz requires a 2GHz peripheral clock unless you have a fancy enhanced resolution PWM peripheral.

So lower PWM frequency means more expensive, heavier larger inductor. It’s difficult to get the MCU to regulate its own power. “Soft” firmware disruptions or bugs can cause physical damage.

Some processor bandwidth and resources are consumed by the (interrupt driven) control loop unless your chip has a dedicated processor for the purpose. That may increase latency for servicing lower priority interrupts or compromise the regulator performance.

Microchip has marketed versions of their PICs with peripherals optimized for SMPS control.. if Olin was still here he could tell you a lot more about actually using them, personally I tend to err on the conservative side.

There are also some small very low power MCUs that actually contain an entire switching regulator (except the inductor) to allow 1.5V operation.

There are a lot of similarities between a motor controller implemented by a DSP or microcontroller and a switching power supply so the existing peripherals often aimed at motor control could be used for a SMPS (although the frequency would typically be very low compared to a modern SMPS chip). Might be useful for special applications such as a polyphase low EMI power supply.

\$\endgroup\$
2
  • 3
    \$\begingroup\$ ST and TI also have ARMs targetted towards the same thing. What they all have in common is ps resolution PWM modules and built-in fast comparators. \$\endgroup\$
    – DKNguyen
    Dec 23, 2019 at 14:32
  • 1
    \$\begingroup\$ I actually consulted with a company that was using a DSP chip in the control loop of a super-duper efficient switching converter. I think it was converting tens of kW. So it can be done. IIRC, the DSP chip itself was powered by a separate itty bitty switcher, though. \$\endgroup\$
    – TimWescott
    Dec 21, 2020 at 4:06
5
\$\begingroup\$

Some points:

  • An MCU definitely requires a gate driver and power transistors (your examples have built in power transistors, though some SMPS controller may need a driver and external transistors as well)
  • A switching regulator IC is specifically built and tailored for the tasks, whereas a MCU in general is built to be able to do a lot of other tasks as well.
  • An MCU requires code and code can contain bugs, deadlocks, etc.
\$\endgroup\$
2
  • \$\begingroup\$ Using an MCU allows you to tailor the SMPS to your task despite being a general purpose device not tailored to the task. \$\endgroup\$
    – DKNguyen
    Dec 23, 2019 at 14:35
  • 2
    \$\begingroup\$ - One important issue comes to mind, but I post it as comment because I cannot prove it (yet): Regarding safety regulations, it is way harder to prove software is safe than to prove a mechanical system or pure analog electrical system is safe. \$\endgroup\$
    – Huisman
    Dec 23, 2019 at 14:49
4
\$\begingroup\$

I would not recommend using a microcontroller to make a regulated power supply for the reasons outlined in other answers for small scale production. The time cost to make resilient software will not compensate for any reduction in BOM costs. This situation may change if you're making lots of a product (as things often do).

However, it can be useful to use the PWM output to generate a low current unregulated auxiliary supply. For example, you might want a negative rail for biasing, or a high voltage for neon displays etc.

This is still prone to software errors but without a control loop the complexity is significantly reduced, and you can generate the supply in the background after you've set up the PWM system and leave the microcontroller's cycles free for other uses.

\$\endgroup\$
3
\$\begingroup\$

The main issue is you have to make your control loop run fast enough with low latency but it has been done. Look up digitally controlled/programmed regulators.

Variability in execution time from loop to loop will also cause harmonics and noise. It's less of a problem for something executed in hardware like an FPGA or ASIC since every cycle takes the same amount of time and is more deterministic cycle-to-cycle. They also react faster (less latency) to external events and more predictably compared to software.

\$\endgroup\$
2
\$\begingroup\$

Is there a down-side in using of MCUs PWM to build a switching regulator? (am I going to face any problem?)

You now have a bootstrapping problem. Most of the time you'd power your MCU... from a switching regulator.

So either you have a separate regulator for the MCU (in which case why not just use that regulator directly instead?), or you have dedicated circuitry for bootstrapping (in which case why not use that circuitry always?).


You also now have a regulation quality issue. The control loop of output voltage -> ADC -> MCU code -> DAC -> mosfet is slow. Yes, the DAC may be able to switch at 80Mhz, but the time to do a reasonably-accurate ADC measurement, process the output in software, and re-program the DAC duty cycle in response will be much slower on a typical MCU.


This all being said, this can be a valid approach in certain cases. The above kind of hints to when it can be useful:

If you already have an MCU, and you're trying to add a new voltage rail that can be powered on later, and it's not easy to generate the new voltage rail from an existing one, and regulation quality isn't too much of an issue... then yes, this can be useful.

\$\endgroup\$
1
\$\begingroup\$

I tried and realized that it's actually quite complicated.

To generate a fast PWM signal is easy, but due to the capacitance of MOSFET gate, the faster you drive the MOSFET, the higher the current you will need, the GPIO pins of MCU can only sink/source ~ 30 mA, which can only drive power MOSFET to about 10kHz or less. You will need large inductor when switching at <10kHz and likely not efficient. Modern cheap switching regulator can do 1MHz+ and only cost $0.2 with MOSFET built-in.

Another issue is the gateway voltage required to drive the power MOSFET, most MOSFET need 10V+, so you can't use GPIO pins directly, you will need another MOSFET or a transistor, and 2 resistors. Now you are using more parts than a switching regulator, less efficient and probably cost more.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Or a single gate driver. \$\endgroup\$
    – Hearth
    Dec 21, 2020 at 3:51
  • \$\begingroup\$ Have you tried using a mosfet driver? \$\endgroup\$ Dec 21, 2020 at 7:57
0
\$\begingroup\$

You can use MCU as PWM controller but then you will need MOSFET driver. Now question is why would you go difficult way when there is time proved approach -- specialized ICs?

Add a few components and you have time tested solution at minimal cost lower than cost of MCU!

https://www.ebay.com/itm/MP1584EN-Ultra-Small-DC-DC-3A-Power-Step-Down-Adjustable-Module-Buck-Converter/133251283426

https://www.ebay.com/itm/10-PCS-Mini-MP1584EN-DC-DC-Buck-Converter-3A-Power-Adjustable-Step-Down-Mod-D4M3/263829265998

I wonder can you beat $0.74US with a microcontroller? Then you should try.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.