check in
Completed

【 Stars Plan 】USB programmable power supply/power monitoring

PRO【 Stars Plan 】USB programmable power supply/power monitoring

tag

82
0
0
0
Mode:Full

License

GPL 3.0

Creation time:2025-01-21 07:10:57Update time:2025-02-17 09:22:27

Description

Important Change Notices

———————————————————————————————————————————————————————————

The following R45 and R22 do not need to be soldered, which solves the problem of SC8721 hanging up inexplicably.!!!!!!!

Project Brief Introduction

———————————————————————————————————————————————————————————

In the past few days, many friends have been feedback: I can't find the information of V1.0, and the following is the project address of the original V1.0.

USB Programmable Power Supply/Power Monitor-V1.0 - JLC EDA Open Source Hardware Platform (oshwhub.com)

This design supports USB PD3.0, BC1.2 protocol, and can make the USB power adapter supporting PD/BC1.2 protocol output 5V, 9V through PD/BC1.2 protocol. 12V,15V,20V.

The power supply supplies power to the system;

Wide range of output voltage, adjustable from 2.7V ~ 20V3A load capacity;

The input voltage and current, the output voltage and current are monitored in real time, and fed back to the user through the 320X240 TFT screen or the host computer;

The output voltage and input voltage can be adjusted through a multi-function button or the host computer;

(Click on the image to enlarge it)

WeChat applet on the upper computer.

(Click on the image to enlarge it)

The Mini Program is online, and you can scan and open the Mini Program:

 

Project Background

———————————————————————————————————————————————————————————

  • I am a creative embedded software engineer, usually like to make some interesting "toys", because there is no adjustable power supply at hand, usually when making "toys" often use some voltage sources such as 12V,3.3V,5V or analog battery voltage change process, and do not want to spend that money to buy an adjustable power supply. I thought, "Can I get a portable, small, independent of a specific voltage source, can meet most of the daily needs of the adjustable power supply?" My first thought is, "Can I use the existing power adapter (USB adapter), external hanging a DC to DC chip, to achieve the voltage rise and fall can be achieved?".
  • Said to do it, the early stage also went to the open source square to see again, to see if there is a similar open source, engraved one is good; But... Otherwise, it is necessary to fix the input voltage source above 10V (this is not very rib, I in order to use your voltage source, I also have to make a special adapter, which does not meet my design needs); Or the circuit is complex, the whole machine is relatively large, not convenient to carry, not convenient DIY;
  • Forget it, I'll have to do it myself! Let's go...

 

Project Highlights:

———————————————————————————————————————————————————————————

  • Support USB PD3.0/PD2.0BC1.2 protocol, support 5V~20V input.
  • The output voltage is adjustable from 2.7V ~ 20V, and the output current carrying capacity of 3A can meet the daily experimental use.
  • The output current limit is adjustable from 500mA~3A.
  • A simple DC voltage meter function, measuring range 0V~48V.
  • The power output is controllable, which is convenient for repeatedly powering off and powering on the electrical equipment.
  • The WeChat applet configures the input and output voltages.
  • The input voltage and current of the power supply are monitored in real time.
  • The voltage detection resolution is 8mV, and the current detection resolution is 40uV/10mR=4mA.
  • The 320x240 TFT screen displays the electricity consumption in real time and can be used as a simple power meter to monitor the power consumption capacity of the electrical equipment.
  • It can communicate with the host computer through BLE to realize the expansion and development of more applications.
  • There are few peripheral components, the implementation principle is simple, and it is very convenient for DIY.
  • Compact and convenient, it does not depend on a specific power supply, and can be used as long as it is a USB adapter.
  • The software and hardware are all open source.
  • This project can also be used as an entry-level development board, most of the peripherals in embedded learning are used in this project, such as :I2C, UART, SPI, USB and IO control, unused IO ports are extracted.

 

Hardware introduction

———————————————————————————————————————————————————————————

  • Hardware resources and dimensions

(Click on the image to enlarge it)

(Click on the image to enlarge it)

 

  • Power output terminal base

(Click on the image to enlarge it)

Here to explain why the design selected the output terminal block as shown in the figure, in fact, the purpose is one, convenient, does not depend on a specific connector, just around an ordinary line can be used; And it can be operated without any additional tools (just hands).

I have seen some similar open source projects in the open source community, which use some dedicated sockets, which have certain limitations and do not meet the needs of portability and convenience.

 

  • Schematic diagram introduction (click on the picture below to see a larger picture)
    • The following is the circuit of the power input part, and the input of this design is divided into two parts, one part is input through the USB Type-C port;
    • The other part is connected to the DC power supply through the two terminal blocks of U10 and U11.

   

(Click on the image to enlarge it)

  • PD protocol chip circuit, this part of the circuit is relatively simple, just the necessary power supply and control circuit, to complete the interaction between the PD protocol and the BC1.2 protocol.

(Click on the image to enlarge it)

  • The USB switching circuit is used for the multiplexing and switching of USB D+,D- of the PD protocol chip and MCU USB D+,D-. The working principle is: when powered on,D +,D- is handed over to the PD protocol chip to complete the BC1.2 protocol interaction; When protocol information interaction is not required, it can be used as the MCU external communication SB interface, and the MCU firmware is also downloaded through this USB port.

(Click on the image to enlarge it)

  • 3.3V DC-DC circuit, which provides a 3.3V supply voltage to the system. It supports an input voltage of 4.5V~28V.

(Click on the image to enlarge it)

  • Voltage and current detection circuit, INA3221 supports 3-way differential input and 3-way bus terminal input, the differential input here is generally used to detect small voltage changes of analog signals, such as current detection, its ADC is 16-bit, one is a symbol bit, the actual numerical representation bit is 15 bits, LSB: Is 40uV, full scale 163.8mV; The bus input can be used to measure analog signals with low resolution requirements, such as system input/output voltage detection.
    LSB: 8mV, full scale 32.76V.

The design uses IN-1 terminal to detect the input voltage of VBUS terminal,IN +1,IN-1 to detect the input current of VBUS; IN-2 terminal detects output voltage, NI+2,IN-2 detects output current; The IN-3 terminal is the voltage detection terminal of the simple voltmeter.

(Click on the image to enlarge it)

  • Digital power Buck-Boost circuit provides power to the load. Its main function is to provide power to the electrical equipment according to the output voltage set by the user and the output current limit. The output voltage and current limiting can be configured through the I2C interface.

(Click on the image to enlarge it)

  • The main control MCU circuit, including boot, Reset, IO interface and power supply parts, it should be noted here is to ensure that {BOOT1, BOOT0}=01 when burning firmware through USB port, so as to ensure that CODE starts from the boot program memory;

(Click on the image to enlarge it)

  • This design also adds a Bluetooth Low Power (BLE) chip, the following is the circuit of the BLE chip, including RF, crystal, IO control and power parts. BLE chip can physically connect with MCU UART through jumper, and realize data interaction through UART port. When downloading the BLE chip firmware, disable the jumper. For example, USB0 DP,DM is used for the BLE chip firmware download port or UART TX or RX to communicate with the MCU in normal mode.

(Click on the image to enlarge it)

  • The following is the LCD interface circuit, power supply, IO control and SPI communication circuit.

(Click on the image to enlarge it)

  • The following is a diagram of the rotary encoder circuit and the actual product.

(Click on the image to enlarge it)

 

Introduction to the user UI

———————————————————————————————————————————————————————————

  • LCD display description

(Click on the image to enlarge it)

  • The upper left corner of the lcd has two parts of information, 1. It displays the maximum voltage allowed by the current set request, that is, the maximum voltage allowed by the PD protocol or BC1.2 protocol requested by the USB power adapter; 2. Real-time display of voltage and current information of the input source.

(Click on the image to enlarge it)

  • The upper right corner of the lcd has two parts of information, 1. It displays the current set expected output voltage and current limit; 2. Yes Display Displays the actual output voltage, current, and power information in real time.

(Click on the image to enlarge it)

  • The bottom half of the lcd is used to record the output voltage and current information of the latest 250 sampling points in real time. The red line indicates the output voltage, and the light blue line indicates the output current.

(Click on the image to enlarge it)

  • Multi-function key description

The following is the multi-function key used in this design, which has three directions of freedom, respectively, counterclockwise rotation, clockwise rotation and middle down, they represent 3 different keys. In this project, counterclockwise rotation is defined as CCW, clockwise rotation is defined as CW, and the middle key is defined as the middle key (CENTER).

 

The following table shows the key events used in this project.

 Key press events Description
DOWN Press the button
UP The button is raised
SINGLE_CLICK Click
MULTI_CLICK
Multiple hits, such as: double tap, triple hit, quadruple hit, etc
LP Press and hold
VLP Press and hold it
VVLP Long press
HOLD Press and don't let go
CW Press and don't let go
CCW Rotate counterclockwise

Description of the function of the key

Key name

Prerequisites

Key press events

Trigger function

Remark

CENTER

Power-on status

MULTI_CLICK=2

Enables the setting of output voltage and output current limit

When this function is triggered, the corresponding adjustable option will flash

CENTER

Output voltage/current limit setting enabled

MULTI_CLICK=2

Toggles the selected output voltage and current

 

CENTER

Power-on status

MULTI_CLICK=3

循环设定PD协议/或者BC1.2协议的请求受电电压

5V->9V->12V->15V->20->5V......

CENTER

Power-on status

MULTI_CLICK=4

Cycle settingPD protocol and/or BC1.2 protocol request receive voltage

In the ON state, the system will collect the voltage and current information of the last 250 points in real time and output it to the LCD screen

CENTER

Power-on status

LP Cyclically turn on/off the voltage and current detection log function

 

CCW

The output voltage is enabled

逆时针旋转

Reduce the output voltage

 
CCW Limit current setting enabled 逆时针旋转 Reduced output current limiting  

CW

The output voltage is enabled

顺时针旋转

Increase the output voltage

 

CW

Limit current setting enabled

顺时针旋转

Increase output current limit

 
CENTER Power-on status SINGLE_CLICK Turn on/off the power output cyclically  
CENTER Power-on status

 

MULTI_CLICK=5

Turn on/off the Mini Program QR code in a loop  
         

                                                                                  

Software Introduction

———————————————————————————————————————————————————————————

The software architecture used in this project is developed by myself. The core of this software architecture is that all functional modules are separated independently, information is exchanged between modules in the form of messages, and each module maintains its own state. Based on functional cohesion and data coupling, try not to use logical coupling or directly modify each other's data. The following is the program frame diagram, the following is a brief description of some modules, you can see the source code in detail, if you do not understand the place welcome to leave a message to discuss:

(Click on the image to enlarge it)

mcu_os:

The core is the mcu_os part, which implements message processing, task scheduling, memory management and other functions. The usr_main_app, usr_input_task and usr_display_task functional task modules in this project are based on this foundation for message transmission. To achieve the various functional requirements of system UI.

usr_display_task:

Responsible for receiving some status information from usr_main_app, and implementing various interface display on the LCD screen.

usr_main_app:

Receives user input events from usr_input_task, responds to user input events, and sends some status information to usr_display_task.

usr_input_task:

Responsible for invoking io_key of the driver layer, reading io_key status information, generating key events and sending key events to usr_main_app.

Main API functions:

static void key_event_handle(mo_key_event_msg_t *k_event):User keystroke event processing
static void display_task_handle(mo_task tsk, mo_msg_id msg_id, mo_msg msg):The LCD displays event processing
static void uart_rx_msg_handle(mo_u8 *p_dat):Upper computer UART RX datagram processing
static void main_task_handle(mo_task tsk, mo_msg_id msg_id, mo_msg msg):The main application event processing, all the system event input and output have this received and emitted.

Firmware download

———————————————————————————————————————————————————————————

MCU firmware download

  • The MCU firmware download for this project only needs a USB cable at port C. Using the USB DFU download tool (Artery_ISP_Programmer), everyone can download and install it by themselves. I download docs\tools\ARTRY_ISP in this directory in the code repository. I also need to install the USB DFU driver (Artery_DFU_DriverInstall.exe), which is usually found in the download tool directory.
  • Before power-on, ensure that {BOOT1, BOOT0}=01 can enter the USB DFU mode. BOOT1(PB2) is connected to a 200K pull-down resistor. No additional operation required. BOOT0 has a terminal, the two ends can be short connected together, there is a screen on the PCB board, the process of downloading the program must be kept short, because this end has another function, that is, to switch the USB interface to the MCU side.
  • When {BOOT1, BOOT0}=01 is used to power on the device, the device enters the USB DFU mode. Figure 1 shows that the device has entered the USB DFU mode. Then click the next step until Figure 2, select the firmware to be downloaded, and click the next step to complete the shutdown download; Power off, restore BOOT1, BOOT0}=00/10; Power it on, and the device should be running normally.

Hardware settings

Software Operation

(Click on the image to enlarge it)

Bluetooth Low Energy firmware download

  • Method 1

1.  Connect the USB cable to the board in the following way. If the chip is empty, Jerry's forced upgrade development tool is not needed here. Here we only need to prepare a USB data cable as shown below; Later update the program will not use the data line (because the source code of the project is to open the OTA function), we can update the software through Jerry's OTA upgrade small program, (you can search "杰里OTA" in wechat).

(Click on the image to enlarge it)

After connecting the USB cable to the computer, you should see the following USB device in the "Device Manager" on the computer.

(Click on the image to enlarge it)

2.  Open the source code of the SDK with VS CODE, follow the following operation, compile and download the program (if your VS CODE does not have the Task Explorer plug-in installed, you need to install it yourself).

(Click on the image to enlarge it)

You should eventually see the following message indicating that the download of the program has been completed.

 

  • Method 2

If you do not have VS CODE installed on your computer, and do not care about how the source code is implemented, you can download the following attachment "uart2ble_tools.7z", decompress and click on the "download.bat" batch file, you can also quickly download the BLE firmware to the Bluetooth chip.

(Click on the image to enlarge it)

After starting the download, you must have the following prompts to count the download as successful,

(Click on the image to enlarge it)

 

 

  • BLE OTA file

1. If you need OTA, the OTA file is in the following directory.

(Click on the image to enlarge it)

Hardware display

———————————————————————————————————————————————————————————

1. Copper pillar double pass: M2*6 4pcs

2. Copper pillar single pass: M2*11+3 4pcs

3. Screws: M2*6 8pcs

 

Project Current Known Issues!!

———————————————————————————————————————————————————————————

  • Note!!
    SC8721 has been verified many times by most of the small partners, this chip is afraid of long-term high temperature blowing, if a long time with the wind gun blowing, a high probability of damage!! It is recommended that if you have teppanyaki, try to use teppanyaki welding, if the pin of the test side is not welded, try to use a soldering iron to repair welding!!!
  • The physical connection between MCU and Bluetooth needs to be established according to the two jumper caps as shown below (otherwise the small program cannot control voltage adjustment and display voltage and current information)

If you think this project is good, give it a thumbs up.
At the same time, if you think this project has practical value, you are also welcome to click on the collection.

 

Other Accessories

———————————————————————————————————————————————————————————

  • MCU source code address (the code repository has two branches, master is V1.0; HV2.0 is V2.0):

          https://gitee.com/Bryan_He/open_usb_power_supply.git

  • BLE source address: https://gitee.com/Bryan_He/uart2ble.git
  • The MCU firmware so far can be downloaded from the following attachment: usb-power-supply-v2-sw-v2.3.hex --> to improve the screen refresh rate, the screen no longer flicker; I merged the data saving function of V3.
  • Bluetooth firmware and download tool :uart2ble_tools.7z
  • The Mini Program has been successfully launched, and you can scan and open the Mini Program (friends can play to their heart's content):

(Click on the image to enlarge it)

History

———————————————————————————————————————————————————————————

2024-1-3

Drafting, conceiving the requirements of the project;

1. The USB power adapter can be converted through a DC-DC adjustable buck-boost power supply chip to output an adjustable DC power supply from 1.0V~30V.

2. Support PD3.0 protocol, when using a USB power adapter that supports PD3.0, it can communicate through the protocol to make it output 5V, 9V, 12V, 15V, 20V voltage.

3. Real-time detection and display of input voltage and current

4.  The output current can be set, and the output is turned off after the set output current

5. A relatively friendly human-computer interface

 

2024-1-5

According to the project requirements, select the DC-DC buck-boost power supply chip and some other peripheral components, and preliminarily select the hardware solution:

 1. DC-DC Buck-Boost: 南芯SC8721QFER,Vin:2.7 V to 22V;Vout:2.7 V to 22V

 2. MCU: I plan to use the Artery AT32F415KCU7

 3. Current Detection: I plan to choose TI's INA3221AIRGVR

 4. LCD: TBD

 5. PD chip: CH224K, 4V to 22V input voltage, support PD3.0/2.0, BC1.2 fast charging protocol

 

2024-1-10

Complete the schematic diagram and complete the layout of some components.

 

2024-01-24 17:50:39

Complete all PCB wiring, place orders for PCB and SMT, sort out information, and apply for free orders for PCB consumables.

2024-01-31 19:39

Wait a few days, finally wait for you!! Today, the board has been SMT posted, sent to Shenzhen, as soon as I go home to open the express, the following show the posted board, no single paste 2 pieces, finally no hand paste, too cool!! There are two chips because LCSC does not have, all can only hand welding.

2024-02-01

Today, the unglued materials are welded on, ready to power on, to measure whether the power supply is normal; You can find that the 3.3V power supply of MCU and other ics is not normal, only about 1.1V, ah really toss more than ah. After checking, it was found that the resistance of the RC filter circuit of the power supply was affixed to the wrong material.

2024-02-02

Complete in3221 drive and input/output voltage/current detection. I began to debug the SC8721 driver. During the debugging process, I repeatedly controlled the CE pin. Unfortunately, something happened, and the SC8721 of a board was smoking. It seems that years ago can only come here, tomorrow will return home, this problem can only be dealt with after the year, do not know whether it is a hardware problem or software control logic problem.

2024-02-20

SC8721 drive is complete and the output voltage can be adjusted in real time.

2024-02-26  23:38

Complete part of the LCD display, and can refresh the monitoring voltage and current in real time. Not bad!!

2024-02-28 23:48

Complete partial LCD layout display!

2024-03-01 

Complete all LCD display and data detection and refresh functions.


2024-03-02  21:47

Write development documentation and organize open source-related files for the release project

2024-03-10   10:38AM

In the past few days, I have been debugging the Bluetooth part, because I have not used this Bluetooth chip before, and I have encountered a lot of problems in the debugging process.

1. The power supply of the chip can not exceed 3.5V, otherwise the chip may be damaged, why mention this here, because I am in the debugging process of the chip because of this power supply is broken a lot; This is mainly Jerry's download tool output power is 5V. This is something that needs to be avoided; This is how I power the chip during the download so that I don't burn the chip.

 

2. When downloading the program for the first time, make sure that PA9 port has no external drop-down circuit, and disconnect it temporarily if necessary. Because the chip default this port is a low level after 4S to reset the chip function, affecting the download program.

3. The deviation of crystal oscillator should not be too large, too large will lead to the failure to search for Bluetooth, which troubled me most of the debugging time, because the program runs normally, but can not find Bluetooth, and it was found that the crystal oscillator was the problem after investigation.

4. Here is a tip to share with you, that is, most of Jerry's chips, if it is empty, there is no program in it, the first download of the program does not need to use any tools, only need an ordinary USB data cable can be downloaded! If you need to update the program later, you can use the OTA method (the premise is that the program needs to be configured to open the BLE OTA function, and then wechat terminal search "Jerry OTA" can find this small program, through this small program OTA upgrade, very convenient, this is for just want to play, do not want to spend money to buy tools (more than 80 RMB)

2024-03-10   21:01

I received the acrylic plate today and assembled one for the first time. Fortunately, it went smoothly this time without any other accidents. Let's show the results below! Um... The class is up in a flash.

                      

2024-03-17 

The basic functions of the UI interface and Bluetooth communication part of the wechat mini program have been adjusted.

 

2024-03-23 

Complete all functions of wechat mini program.

2024-03-31 

Version 2.0 begins to lay out PCB devices

2024-04-01 

The 2.0 version of the line is basically all through, and another round of optimized routing and typesetting can be sent out.

2024-04-06 

Version 2.0 PCB board is sent out for board making, ready to purchase some key materials.

2024-04-07

There are a lot of small partners applied for small program experience, but the number of experience version only 15 experience members, in order to live up to everyone's support, I decided to go online small program. I have not touched the small program before, these days I looked up the relevant information "how to go online small program", today I submitted the relevant record information waiting for review, after the review is passed, I will share it to everyone at the first time, thank you for your support!!

2024-04-14 

After some components are welded, the first time I used teppanyaki, I have no experience, and I was burned.

 

Version iteration

———————————————————————————————————————————————————————————

  • -

 

Project Vision

———————————————————————————————————————————————————————————

  • I hope that through open source sharing, we can exchange technology with more partners, grow together, and do a little bit of our own microblogging power for the industrial transformation of the motherland.
  • I hope this project can help those who want to learn and make embedded, and can provide you with a cheap and convenient solution to the power supply needs of the equipment in the development and learning process.

 

Demo video

———————————————————————————————————————————————————————————

Designed by 黑马小乌龟 (from OSHWHub)

Link:https://oshwhub.com/bryan_he/usb_dc_ps

Design Drawing

Download File
The preview image was not generated, please save it again in the editor.

Attachments

OrderFile nameDownload times
1
LCD-Brochure .pdf
761
2
MCU-Firmware download .mp4
1097
3
Bluetooth firmware download .mp4
650
4
Demonstration .mp4 of equipment operation
762
5
uart2ble_tools.7z
938
6
Acrylic-up_shell.stp
98
7
Acrylic-up_shell.stp
99
8
usb-power-supply-v2-sw-v2.3.hex
56
Add to Album
0
0
Share
Report

Comment

All Comments(1)
Sort by time|Sort by popularity
Followers0|Likes0
Related projects
Empty

Bottom Navigation