A four-switch Buck-Boost digital power supply based on STM32G474, supporting Type-C interface with PD decoy input and DC5.5 interface input. The maximum input/output is 48V10A. This is my graduation project, now open-sourced, including schematics, PCB, program source code, 3D model of the case and other materials.
The work is just average; please be gentle with criticism. Friendly exchanges are welcome.
Demonstration Video of the Work: https://www.bilibili.com/video/BV1Ui421y7ip/
Open Source of Intelligent Electronic Load Based on CH32V307, Entry of Embedded Competition: https://blog.zeruns.com/archives/785.html
Open Source Link of This Project on LCSC Open Source Platform: https://url.zeruns.com/noGf0
QQ Group for Electronics/Microcontroller Technology Exchange: 2169025065
The data download link is at the end of the article.
The hardware circuit was designed using LCSC EDA software, which is really easy to use.
Introduction
This paper designs a synchronous rectification Buck-Boost digital power supply based on STM32. The power supply circuit consists of MOSFET drive circuit, 4-switch Buck-Boost circuit, signal conditioning circuit, PD fast charging protocol circuit, auxiliary power supply circuit, microcontroller control circuit and other parts.
The power supply can be powered through DC interface or Type-C interface. The Type-C interface supports communication with the charger via PD fast charging protocol to automatically request and obtain a maximum operating voltage of 20V. The power supply uses STM32G474 microcontroller to real-time monitor the input and output voltage and current, adjust the output PWM duty cycle through PID control algorithm, and realize over-voltage and over-current protection. It can also sample the motherboard temperature to achieve over-temperature protection. In addition, the real-time parameters of the power supply can be viewed through the OLED screen, and the output voltage and current can be set through the rotary encoder and buttons. It can also communicate with the upper computer through another Type-C interface, and the real-time parameters and waveforms of the power supply can be viewed through the upper computer software.
Design Performance Parameters
The design performance parameters of the power supply are as follows:
| Item | Parameter Index |
|---|---|
| Input Voltage Range | 12Vdc~48Vdc |
| Input Current Range | 0~10A |
| Maximum Output Power | 450W |
| Output Voltage Range | 0.5Vdc~48Vdc |
| Output Current Range | 0~10A |
| Output Voltage Ripple | Peak-Peak ≤ 200mV |
| Switching Frequency | 181.333kHz |
Physical Pictures
VOFA+ is used as the upper computer software, which can real-time view various parameters of the power supply (input voltage and current, output voltage and current, motherboard temperature, MCU temperature, power conversion efficiency, etc.) and waveform changes. As shown in the following figures.
System Block Diagram
Hardware Circuit Design
Component Selection and Calculation
Inductor Calculation
In the synchronous BUCK-BOOST power supply, the inductor calculation needs to consider the working conditions in BUCK mode and BOOST mode to ensure that the circuit requirements are met in both modes. Usually, the inductor selection is based on the mode with higher requirements for the inductor between the two modes.
When the power supply works in BUCK step-down mode, assuming the maximum input voltage is 48V and the minimum output voltage is 5V, calculate the minimum PWM duty cycle:
Define the inductor current ripple (25% of the maximum rated current ripple, set the maximum rated current to 10A):
Calculate the minimum required BUCK inductor:
When the power supply works in BOOST step-up mode, take the rated input voltage of 24V as the calculation point, calculate the PWM duty cycle:
In Boost mode, when 1A (I_{minb}) is taken, Boost enters Continuous Conduction Mode (CCM), calculate the inductor:
Based on the calculation results obtained from the formula, the minimum inductance value required to meet the predetermined ripple current requirement is determined. To ensure this condition is met, an inductor with an inductance value slightly higher than the calculated value should be selected. At the same time, it must be ensured that the saturation current of the selected inductor can carry the highest current peak in the circuit. Since the efficiency factor is not considered in the calculation process, the actual duty cycle and peak current may be lower than the theoretical calculation values. Therefore, when making a selection, a certain safety margin should be considered to adapt to various possible situations under actual working conditions.
Considering the above factors comprehensively, this design selects a 22μH inductor with a 1770 SMD package and a saturation current of more than 10A as the inductor component of the BUCK-BOOST circuit.
Capacitor Calculation
To obtain a good output voltage ripple, the designed voltage ripple is 50mV.
The inductor selected above is 22μH, so this inductance value is used for calculation here:
Calculate the minimum capacitance C_{minBuck} and C_{minBoost} required when working in BUCK step-down mode and BOOST step-up mode respectively:
The design needs to leave a certain margin and for lower output ripple, so a low ESR 220μF solid capacitor and a 470μF ordinary electrolytic capacitor are selected, totaling 690μF.
MOS Selection and Calculation
Within the rated input and output voltage range, calculate the effective value of the input MOS current:
In MOSFET selection, the rated current value I_D of the MOS tube should be more than twice the maximum current flowing through the MOS tube (to prevent damage caused by excessive current impact in fault or short circuit conditions).
The rated voltage resistance value V_{DS} for MOSFET selection should be greater than 1.5 times the maximum input voltage (to prevent spike breakdown).
After referring to the previous calculations, for conventional application scenarios, a MOSFET with a rated current exceeding 15 amperes (A) and a voltage resistance level of 100 volts (V) can be selected. The selection of the lower MOSFET is the same as that of the upper MOSFET. Considering heat generation, to minimize energy loss during conduction and switching processes, priority should be given to MOSFETs with low on-resistance (R_{DS(on)}) and low output capacitance (Coss).
The MOSFET model selected in this design is CJAC80SN10, which is a domestic MOSFET produced by Jiangsu Changjing Technology Co., Ltd. It has a drain-source voltage resistance (V_{DS}) of 100V and a maximum drain-source current (I_D) of 80A. Its on-resistance (R_{DS(on)}) is only 6.2mΩ, which is conducive to reducing power loss of the device in the on-state. At the same time, the output capacitance Coss of the device has a typical value of 420pF, which is beneficial to reducing dynamic loss during switching transitions. Therefore, CJAC80SN10 not only meets the electrical characteristics required by the project but also effectively reduces energy loss and improves the overall efficiency of the system.
Power Board Circuit Design
Main Power Circuit
The following figure shows the main power circuit diagram of the synchronous BUCK-BOOST power supply. The left side is the input. The synchronous BUCK step-down circuit is composed of MOS tubes Q2, Q4 and inductor L1. The synchronous BOOST step-up circuit is composed of MOS tubes Q3, Q5 and inductor L1. A 10kΩ resistor is connected in parallel between the gate and source of each MOS tube to ensure that the gate of the MOS is not floating and prevent false conduction.
The main power circuit has an overall left-right symmetrical structure. Both the input and output ends are equipped with a 470μF/63V aluminum electrolytic capacitor and a 220μF/63V solid aluminum electrolytic capacitor. In addition, there are 2 small SMD MLCC (Multi-layer Ceramic Capacitor) with parameters of 10μF/50V to filter high-frequency noise interference at the ports. R9 and R10 are dummy loads at the input and output ports, which can quickly dissipate the residual energy in the circuit when the power supply is disconnected. R13 and R14 are high-precision 5mΩ resistors used for current sampling, and the latter stage is connected to a differential amplifier circuit to amplify the input and output current signals. CNT1 and CNT2 are output terminals. L1 and L2 are SMD 1770 package and through-hole magnetic ring inductor package respectively; only one of them needs to be soldered. Both are drawn to facilitate testing the effects and performance of different inductors.
Power Input and Fast Charging Protocol Circuit
The following figure shows the circuit diagram of the power input interface and PD fast charging protocol communication.
The power input adopts two interfaces: DC5.5*2.5mm female port and Type-C female port. The Type-C interface supports multiple fast charging protocols such as BC1.2 and PD3.0/2.0. The fast charging protocol chip model used is CH224K, which can communicate with the fast charger to make the charger output a maximum voltage of 20V and support a maximum power of 100W.
Diodes D1, D3, and D4 are used to prevent DC interface voltage from reversing into the Type-C interface. The design does not allow both interfaces to be connected at the same time. D5 is a diode for reverse connection protection. FH1 is a power input fuse holder with a 12A fuse inserted.
Drive Circuit
In the design of the synchronous BUCK-BOOST power supply, both the BUCK circuit and the BOOST circuit include high-side N-MOSFETs. Traditionally, the drive of these high-side N-MOSFETs usually adopts the transformer isolation drive method, but this method will increase the complexity of the circuit and expand the size of the circuit board.
This design selects two MOS tube drive chips EG3112 with built-in bootstrap circuit function to drive the MOS tubes of the BUCK circuit and the BOOST circuit. EG3112 is a non-isolated complementary dual-channel drive chip; its 2A output drive current capability ensures that the MOSFET can be turned on quickly; the chip also has a built-in dead time control function to prevent shoot-through of the output drive signal, thereby improving the stability of the system. The specific circuit is shown in the following figure.
Taking the MOS tube drive of the BOOST step-up circuit as an example, PWM2L and PWM2H are PWM signals output from the STM32G474 microcontroller, which are sent to the LIN and HIN pins of the EG3112 drive chip. LO is the lower tube drive signal output with a drive resistance of 10Ω, and HO is the upper tube drive signal output with a drive resistance of 10Ω. D7 is the bootstrap diode of the upper tube drive circuit. Diodes D9 and D11 are used to quickly release gate charge and speed up the turn-off speed of the MOS tube. C14 is the bootstrap capacitor.
The function of the drive resistor is that during the switching process of the MOSFET, the drive signal may produce reflection and oscillation on PCB traces, distributed capacitance, inductance and other components. Series resistors can reduce such oscillation and improve the stability and reliability of the system.
Auxiliary Power Supply
The following figure is the schematic diagram of the auxiliary power supply circuit of the power board.
The first-stage 12V output auxiliary power supply circuit is designed using the BUCK-type power supply chip TPS54360B with integrated high-side MOSFET. According to the chip datasheet, connecting a pull-down resistor to the RT pin can set the switching frequency. Here, a 110kΩ resistor is selected, corresponding to a switching frequency of 876.5kHz. A higher switching frequency allows selecting a smaller inductor to save space. According to this frequency, the calculated inductance value should be greater than 9.75μH. Here, a 10μH inductor is selected, and SS310 is selected as the freewheeling diode. C26 and C27 are input filter capacitors; the feedback voltage divider resistors R19 and R25 divide the voltage to output a reference voltage of 0.8V to the FB pin of the chip to ensure the output voltage is 12V. C18 and C19 are filter capacitors of the first-stage 12V output auxiliary power supply. The first-stage 12V output is mainly used for the input of the second-stage 6V step-down circuit, as well as the MOSFET drive circuit and cooling fan.
The second-stage 6V output auxiliary power supply circuit is designed using the synchronous rectification BUCK-type power supply chip SY8205 with integrated MOSFET. According to the chip datasheet, the switching frequency of the chip is fixed at 500kHz, and the inductor of the auxiliary power supply BUCK circuit is selected as 10μH. C21 and C22 are input filter capacitors; the feedback voltage divider resistors R23 and R26 divide the voltage to output a reference voltage of 0.6V to the FB pin of the chip to ensure the output voltage is 6V. C24 and C25 are filter capacitors of the second-stage 6V output auxiliary power supply. Since directly using a linear voltage regulator to step down from 12V to 5V will cause relatively large losses, a switching power supply is first used to step down to a voltage close to 5V, and then a linear voltage regulator is used to step down to the target voltage. This can ensure higher efficiency and lower output ripple.
The 6V voltage output by the second stage is stepped down to 5V by the linear voltage regulator chip AMS1117-5 as the third-stage auxiliary power supply, and the voltage reference chip REF3033 is used for functional circuits such as signal conditioning, OLED display, and USB communication.
The 5V DC power is stepped down to 3.3V by the linear voltage regulator chip AMS1117-3.3 as the fourth-stage auxiliary power supply, which is used for circuits such as MCU, buzzer, and Flash chip.
The voltage reference chip REF3033 outputs a 3.3V reference voltage for the VREF port of the MCU, serving as the reference voltage for the built-in ADC of the MCU to improve the sampling accuracy of the ADC.
Signal Conditioning Circuit
As shown in the above figure, the sampling and signal conditioning circuit for the input and output voltage of this design adopts differential amplification technology. The differential amplification topology can effectively reduce the interference of high-frequency noise in the switching power supply on the signal conditioning circuit, improving signal stability and reliability. In this circuit, a low zero-offset operational amplifier GS8558-SR is selected to improve conversion accuracy. The GS8558-SR op-amp has excellent DC accuracy and low bias current characteristics, which are crucial for improving the performance of the entire signal conditioning circuit.
Feedback resistors of the differential amplifier circuit:
Calculate the differential amplification gain:
The maximum sampling voltage of the MCU’s ADC is the 3.3V output by the voltage reference chip, so the maximum input and output voltage that can be sampled can be calculated as:
To better suppress the interference of high-frequency noise in the switching power supply on the differential amplifier circuit, decoupling capacitors C40 and C41 are added to the power supply pins of the op-amp for filtering. The capacitors are MLCC (Multi-layer Ceramic Capacitors). Due to their low ESR and ESL, MLCCs have better effects in filtering high-frequency noise. At the same time, an RC low-pass filter circuit composed of resistor R35 and capacitor C39 is added to the output terminal to filter out high-frequency noise.
As shown in the above figure, the input and output current conditioning circuits adopt differential amplification. The output current sampling resistor is:
Feedback resistors of the differential amplifier circuit:
Calculate the differential amplification gain:
That is, each 1A current outputs a voltage of 310mV.
The maximum sampling voltage of the MCU’s ADC is the 3.3V output by the voltage reference chip, so the maximum input and output current that can be sampled can be calculated as:
MCU Control Circuit
The digital power supply design of this project selects the STM32G474RET6 chip as the controller, which has the remarkable characteristics of simple peripheral circuits, diverse control methods, and superior expansion capabilities. To achieve an accurate clock signal, the controller adopts an external crystal oscillator X1, a quartz crystal oscillator with a frequency of 25 megahertz (MHz). In addition, the circuit includes multiple filter capacitors, including C45, C51, C56, C46, and C52, which are used for different digital power supply pins of the microcontroller (MCU) to ensure power supply stability and reduce noise interference. Resistor R49 and capacitor C49 form a power-on reset circuit, and SW1 is the MCU reset button. U11 is a USB-to-serial port chip with model CH340C, which is connected to the second Type-C interface, and the serial port is connected to the USART1 interface of the MCU. U10 is a Flash memory chip with model W25Q64, used to store parameter settings and other information, and is connected to the SPI3 interface of the MCU. Q6 is the drive MOS tube of the buzzer, used to control the buzzer, and the gate of the MOS tube is connected to the PB5 port of the MCU. H1 terminal is the SWD programming port. H2 and H4 are PH2.0 terminal blocks used to connect to the control panel. The terminal blocks reserve the USART2 interface, which can easily replace the control panel scheme with a serial port screen, and can also add ESP32 to increase functions such as networking and wireless control. D13 is a 5V reverse connection protection diode.
Cooling Fan Drive and Motherboard Temperature Sampling Circuit
The schematic diagrams of the motherboard temperature sampling circuit and the cooling fan drive circuit are shown in the following figure. The principle of motherboard temperature sampling of the power supply is to use an NTC thermistor R2 and a pull-down resistor R4 in series for voltage division, and output to the ADC port of the MCU for sampling. The NTC thermistor used has a resistance of 10kΩ and a B-value of 3950K.
The cooling fan is driven by an N-MOS tube with model AO3400. A diode D2 is connected in reverse parallel to the cooling fan interface to prevent damage caused by back electromotive force (back EMF) generated by the motor. When the motor is powered off, due to rotational inertia, the rotor of the motor will not stop rotating immediately but will continue to rotate and generate electromotive force. This electromotive force may damage the transistors or integrated circuits in the circuit, especially when the motor is connected to these components through semiconductor switches (such as MOSFETs).
Control Panel Circuit Design
The schematic diagram of the control panel circuit is shown in the following figure. SW1 is a rotary encoder used for parameter setting, etc. SW2 and SW3 are buttons; SW2 is used to switch the setting items, and SW3 is used to control the on/off of the power output. LED1 is the system running status indicator, which flashes at an interval of 500mS during normal operation. LED2 is the output status indicator, which lights up when the output is on and turns off when the output is off. OLED1 is an OLED screen used to display power supply parameters and status.
PCB Screenshots
Power Board Top Layer
Power Board GND Layer
Power Board Inner Layer 2
Power Board Bottom Layer
Panel Top Layer
Panel Bottom Layer
User Manual
The output voltage and current values can be set through buttons and a rotary encoder. As shown in the following figure, the highlighted value is the current bit to be set, which can be increased or decreased by rotating the encoder. Pressing the encoder can switch to the next bit for setting, and the item to be set can be switched through the SW2 button. The set data will be automatically saved to the Flash memory chip, and the data will be read from the memory chip when the power is turned on next time.
The SW3 button turns on/off the power output.
You can switch to the data display page to view the current input and output voltage and current of the power supply, as well as motherboard temperature and MCU temperature, etc., as shown in the following figure.
You can switch to the setting page to set the thresholds for over-temperature/over-current/over-voltage protection, as shown in the following figure. The set data will be automatically saved to the Flash memory chip, and the data will be read from the memory chip when the power is turned on next time.
Ripple Test
An electronic load and an oscilloscope are used to test the power supply output performance and output ripple, as shown in the following figures. When inputting 36V and outputting 12V2A, the peak-peak ripple is measured to be about 42mV, as shown in the following figure.
Conversion Efficiency Test
The power conversion efficiency is 92% when testing with 20V input and 12V10A output, as shown in the following figure.
The following table shows the conversion efficiency under various input and output voltages, with the highest efficiency of 94.3%.
| Input Voltage (V) | Input Current (A) | Input Power (W) | Output Voltage (V) | Output Current (A) | Output Power (W) | Conversion Efficiency (%) |
|---|---|---|---|---|---|---|
| 20.003 | 4.035 | 80.712 | 15.010 | 5.000 | 75.050 | 92.985 |
| 47.999 | 5.335 | 256.075 | 24.040 | 9.900 | 237.996 | 92.940 |
| 48.000 | 7.875 | 378.000 | 36.020 | 9.900 | 356.598 | 94.338 |
| 48.000 | 9.860 | 473.280 | 45.030 | 9.900 | 445.797 | 94.193 |
| 23.998 | 8.835 | 212.022 | 48.070 | 4.000 | 192.280 | 90.689 |
| 23.998 | 9.830 | 235.900 | 35.998 | 6.001 | 216.024 | 91.574 |
| 12.099 | 9.166 | 110.899 | 24.070 | 4.000 | 96.280 | 86.817 |
| 20.008 | 2.645 | 52.921 | 4.970 | 9.000 | 44.730 | 84.522 |
| 20.008 | 10.550 | 211.084 | 24.030 | 8.000 | 192.240 | 91.073 |
| 36.000 | 6.418 | 231.048 | 24.010 | 9.000 | 216.090 | 93.526 |
| 36.000 | 10.540 | 379.440 | 35.950 | 9.800 | 352.310 | 92.850 |
MOSFET Gate Waveforms
Test the gate waveforms of each MOS when inputting 20V and outputting 24V.
Voltage waveforms of the upper and lower tubes of the BUCK circuit relative to ground:
Voltage waveforms of the upper and lower tubes of the BOOST circuit relative to ground:
Heating Test
Thermal imaging image under no-load condition:
Thermal imaging image after outputting 10A current for 10 minutes, the MOS tube temperature is about 100 degrees:
Unboxing and Evaluation of UNI-T UTi261M Thermal Imager: https://blog.zeruns.com/archives/798.html
Component Purchase Links
The purchase links for most components used in this project are here:
- 0805 Resistor and Capacitor Sample Book: https://s.click.taobao.com/begdskt
- STM32G474RE Chip: https://s.click.taobao.com/C5yYWlt
- CH224K Chip: https://s.click.taobao.com/4t4bskt
- CJAC80SN10 MOSFET: https://s.click.taobao.com/aPsWWlt
- EG3112 Chip: https://s.click.taobao.com/1k9Zskt
- 220μF 63V Solid Capacitor: https://s.click.taobao.com/n60Yskt
- 470μF 63V Rubycon Capacitor: https://s.click.taobao.com/WTRUWlt
- GS8558 Op-Amp: https://s.click.taobao.com/usSVskt
- TPS54360 Chip: https://s.click.taobao.com/r6lSWlt
- SY8205 Chip: https://s.click.taobao.com/GxMUskt
- AMS1117 Chip: https://s.click.taobao.com/mxASWlt
- REF3033 Reference Chip: https://s.click.taobao.com/eOcTskt
- W25Q64JVSSIQ Chip: https://s.click.taobao.com/QX7Tskt
- CH340C Chip: https://s.click.taobao.com/QYRQWlt
- 3.3V Active Buzzer: https://s.click.taobao.com/sovPWlt
- TypeC Female Socket 16P: https://s.click.taobao.com/vjLRskt
It is recommended to purchase components in LCSC Mall: https://activity.szlcsc.com/invite/D03E5B9CEAAE70A4.html
Click “Buy Now on LCSC Mall” in the BOM list of the LCSC open source link to one-click import the required components into the shopping cart.
Data Download Links
The following links include materials such as LCSC EDA project, schematic PDF file, datasheets of various chips, source code project compressed package, and some reference program codes.
123Pan Unlimited Speed Download Link: https://www.123pan.com/ps/2Y9Djv-8yevH.html
Baidu Netdisk Download Link: https://url.zeruns.com/MW2d1
Project Program Gitee Open Source Link: https://gitee.com/zeruns/STM32-Buck-Boost
Project Program GitHub Open Source Link: https://github.com/zeruns/Synchronous-Rectification-Buck-Boost-Digital-Power-Supply-Based-on-STM32
Please give a Star and a like.
Known Issues
- The SY8205 chip in the auxiliary power supply will enter PFM mode at low load, with a low frequency, resulting in slight noise.
- The PID control program for the constant current mode is not well written; the constant current is only stable under pure resistive load. (The constant voltage mode has no issues)
Recommended Other Open Source Projects
- Developed a three-phase power collector and open-sourced it, which can conveniently monitor household power consumption: https://blog.zeruns.com/archives/771.html
- LVGL project template based on STM32F407 (MSP3526 screen), including FreeRTOS version and bare-metal version: https://blog.zeruns.com/archives/788.html
- Open source of沁恒 CH32V307VCT6 minimum system board: https://blog.zeruns.com/archives/726.html
- LM25118 automatic buck-boost adjustable DCDC power module: https://blog.zeruns.com/archives/727.html
- Open source of EG1164 high-power synchronous rectification boost module with a maximum efficiency of 97%: https://blog.zeruns.com/archives/730.html
- 4G environmental monitoring node based on Hezhou Air700E (data such as temperature, humidity, air pressure), uploaded to Alibaba Cloud IoT Platform via MQTT: https://blog.zeruns.com/archives/747.html
- Open source of intelligent electronic load based on HT32F52352, entry of HOLTEK Cup: https://blog.zeruns.com/archives/784.html
Recommended Reading
- Recommendation of cost-effective and cheap VPS/Cloud Servers: https://blog.zeruns.com/archives/383.html
- Minecraft Server Setup Tutorial: https://blog.zeruns.com/tag/mc/
- Code-free Blog Website Construction! Ultra-detailed Personal Blog Construction Tutorial: https://blog.zeruns.com/archives/783.html
- Intranet Penetration Server Setup Tutorial, NPS Setup and Usage Tutorial: https://blog.zeruns.com/archives/741.html
- Performance Evaluation of Yuyun Ningbo 8272CL Large-bandwidth High-defense Cloud Server, up to 500Mbps Bandwidth and 1TB Cloud Disk: https://blog.zeruns.com/archives/789.html
- Test and Teardown of 120W Charger for 2.6 Yuan on Douyin Mall: https://blog.zeruns.com/archives/786.html



































