The question requires
a USB power meter to measure the voltage and current of the load and calculate the power. The
analysis
circuit of the question can be divided into two types of circuits. One is the 3.3V peripheral power supply circuit of digital chips such as microcontrollers; the other is the load sampling circuit, including resistor voltage division voltage sampling and load circuit low-end current sampling.
Schematic design description
LDO voltage drop circuit:
Microcontroller and peripheral circuit:
Sampling circuit:
OLED display circuit:
PCB design description
Layout: Pay attention to placing the power supply filter capacitor of the digital chip as close to the power supply pin.
Wiring: The default length of ordinary signal lines is 10mil; the load circuit requires more than 20mil due to the large current.
Software instructions
Use the official reference code, but pay attention to changing the pins, otherwise the screen will not display.
Physical display description
test results:

Load parameters:
N32G430C8L7-USBMeter.7z
PCB_PCB1_2022-11-05.pdf
BOM_Board1_PCB1_2022-11-05.xlsx
Altium_#The 7th Altium Power Competition#USB Power Meter_2022-11-05.zip
PDF_#The 7th Lichuang Electric Competition#USB Power Meter_2022-11-05.zip
BOM_Board1_#The 7th Lichuang Electronic Competition#LCSC_2_2022-11-05.xlsx
60534
#The 7th Lichuang Electric Competition#N32 voltage and current meter
Introduction: USB power meter with N32G430C8L7+INA199, can check voltage, current, power, 0.96 inch OLED display, with animation
Note: * is a required field,
please fill it in during the registration stage↓
* 1. Project function introduction
N32G430C8L7+INA199 USB power meter, which can view voltage, current, power, 0.96-inch OLED display, with boot animation, and astronaut animation on the main interface
* 2. Project attributes
are disclosed for the first time, the software and hardware refer to the official case, and the OLED display part is original
* 3. Open source agreement
CC-BY-NC-SA 3.0
* 4. The hardware part
refers to the official case design, and the OLED part is different. This project uses a 0.96-inch 12864OLED bare screen and adds its peripheral circuit and boost circuit.
Because the BL9342 part does not output voltage for unknown reasons, it is forced to use a flying wire to weld an LDO to convert the input voltage to 3.3V
* 5. The software part
refers to the official case design, and the OLED display part is original, with boot animation and astronaut animation.
See the attached project.
* 6. BOM list
* 7. Competition LOGO verification
* 8. Demonstrate your project and record it as a video and upload it
Demo video.mp4
60544
#The7thLiChuangElectricityCompetition#USB power meter
Introduction: Make a USB power meter step by step following the case of the National Technology Training Camp
* 1. Project function introduction:
USB power meter based on N32G430C8L7+INA199, with an accuracy of 1%. It can check the current when USB is working and supports 4V-24V version.
*2. Project attributes
refer to the official case of National Technology Training Camp. Laymen and non-professionals can try to replicate it.
* 3. Open source agreement
GPL 3.0
*4. Hardware part:
N32G430C8L7 is the main control, ADC samples INA199 output to calculate current, ADC samples the voltage between the voltage divider resistors to calculate the voltage value, and outputs it to the 0.91-inch OLED screen by I2C for display
*5. Software part:
Schematic diagram and PCB are drawn by lceda professional version full online version; code part is written by keil5, and the code refers to the official case routine.
*6. Competition LOGO verification

*7. Physical verification.
Reason for return: The following is not a physical picture.





*8. Problems encountered:
1. The power ground trace is only 10mil, so it needs to be widened and re-boarded;
2. The USB male and female shells are fixedly connected to the ground, and the connection with the ground needs to be disconnected, because some manufacturers like to use the shell for third-party protocols or use the shell for excessive current, so disconnect it to prevent affecting the test accuracy. Here you can see that I polished it directly;
3. The output voltage of the DCDC part is relatively low, and the problem needs to be checked;
60561
#The7thLiChuangElectricityContest#LiChuang2022SummerTrainingCamp
Introduction: Make a voltage and current meter, continue to improve on the basis of the LiChuang open source project, give full play to the chip performance, use the chip for QC deception. At the same time, make multiple output interfaces to adapt to various electronic development work.
* 1. Introduction to project functions
1. Realize voltage and current meter functions
2. Realize QC2.0 deception
3. Multiple output interfaces, which can be used for various electronic development work
* 2. Project attributes
The project is open to the public for the first time and is original.
* 3. Open source agreement
GPL3.0 Open source agreement
Please fill in during the competition stage↓
* 4. The hardware part
is developed using the professional version of LiChuang EDA, and materials are purchased in LiChuang Mall.

The above picture is the overall design schematic of the project, which is developed based on the open source project of the training camp. The basic part will not be introduced, and the video explains it very clearly.

The voltage regulator circuit adopts a more conventional solution ams1117, which can accept a wide range of inputs, so that the deceptive voltage or the normal connection of 5V can meet the design. The input and output of the circuit are connected to a large capacitor and a small capacitor, so that the frequency characteristics of the power supply are better.

First, let's take a brief look at the QC protocol.
QC2.0 is Quick Charge 2.0 technology, which is the 2.0 version of the fast charging technology released by Qualcomm. Chargers based on the QC2.0 protocol can output four voltage groups: 5V, 9V, 12V, and 20V, and there are two standards: ClassA and ClassB. The ClassA standard QC2.0 protocol supports three voltage groups of 5V, 9V, and 12V, and the ClassB standard QC2.0 protocol supports four voltage output groups of 5V, 9V, 12V, and 20V. Since 20V is not commonly used, the chargers and power banks on the market are mainly based on the ClassA standard.
QC3.0 is an upgraded version of QC2.0. The biggest improvement is that QC3.0 supports output voltage changes of 0.2V variable to one gear. QC2.0 only supports four sets of fixed voltage outputs, while QC3.0 supports output voltages from 3.6V to 20V.
Next, let's take a look at a table.
Gear position
5V
9V
12V
20V
D+ voltage
0.6V
3.3V
0.6V
3.3V
D- voltage
0V
0.6V
0.6V
3.3V
From the table, we can see that the output gear position depends on the voltage of D+ and D-. The IO port of the microcontroller usually has three states: input, output, and high impedance. Through the combination operation of the IO port, select the output 3.3V or 0V, and then obtain the required voltage through a simple voltage divider circuit.

There are two questions to explain here.
1. The official recommendation for the current sampling chip
is INA199B1DCKR. Since it is out of stock, I bought INA199A1DCKR. Pay attention to the different places. INA199x1DCKR can meet the needs. A and B represent the difference in process. The 1 after x represents the magnification. If this needs to be changed, the program needs to be modified.
In addition, this chip is very small, and one foot is on the side with a horizontal line. You can use the camera function of the mobile phone to zoom in and observe.
2. The problem of shell grounding
This problem is a frequently discussed problem. First of all, the training camp teaches grounding, and I also ground the shell, which can run smoothly. However, the auditor pointed out that if the shell is grounded, the current will escape from the shell, resulting in deviation, and even the inability to monitor the current. I noticed this problem before I completed the hardware development, and finally chose shell grounding. The main considerations are as follows: USB shell grounding is a common operation and has many advantages; secondly, I checked the two current monitoring open source solutions with the most hits in the LiChuang Open Source Plaza, both of which are shell grounded.
In summary, this problem should not be a key issue affecting current monitoring. If a friend's current monitoring is abnormal, see if a crystal oscillator is added. The training camp teaches to add a crystal oscillator, but in fact, the open source code does not require a crystal oscillator.
References: Homemade QC2.0 decoy, STC15W104 single-chip version (open source) | Creative DIY - Digital Home (mydigit.cn)
Our city's Dacongming-QC decoy module-single-chip version-Jialichuang EDA open source hardware platform (oshwhub.com)
*5. The software part
is developed using keil5, and you only need to download and install the attached firmware package.
See the video explanation for downloading methods: LiChuang Training Camp--National MCU Download Method_Bilibili_bilibiliIn

addition to the basic template code in the main function, I wrote the key scanning function myself. Key 1 is mainly used for mode switching, which can be switched between QC 2.0, QC 3.0, and normal mode. Key 2 has two functions. First, when in QC 2.0, switch between 9V mode and 12V mode. Second, when in QC 3.0, step by 200mv.
Note: The QC 3.0 code was written by me according to the protocol information. Since there is no tool test, it has not been verified. Developers verify it as needed.
*6. BOM list

1. 10uF capacitors can choose smaller packages by themselves (using 1206 because I don’t need to purchase additional ones)
2. Please choose 902 and 202 resistors by yourself
*7. Competition LOGO verification
* 8. Demonstrate your project and record it into a video and upload
it Video link: LiChuang Training Camp--USB METER_Bilibili_bilibili
Nations MCU Download Tool V1.2.5.zip
Nations.N32G430_DFP.1.0.0.pack
N32G430C8L7-USBMeter_v1.0.1-2.zip
PDF_#The 7th Lichuang Electronic Competition#Lichuang 2022 Summer Training Camp_2022-11-05.zip
BOM_Voltage and Amperemeter (Verified)_PCB1_2022-11-05.xlsx
Altium_#The 7th Altium Electronic Competition#Altium 2022 Summer Training Camp_2022-11-05.zip
PCB_PCB1_2022-11-05.pdf
BOM_Voltage and Amperemeter (verified)_#The 7th LiChuang Electric Competition#LiChuang 2022 Summer Training Camp_2022-11-05.xlsx
60562
#The 7th Lichuang Electric Competition# Expandable USB current meter
Introduction: Based on n32 USB ammeter, the main body supports 5V general charging, and with the high-voltage expansion module, it can support high-voltage fast charging
1. Introduction to project functions
The current sampling can detect and display the current passing through the meter, the voltage at both ends of the power supply, and the power in real time. It supports general 5V charging. After plugging in the expansion module, it can support high-voltage fast charging.
2. Project attributes
This is my first attempt at open source design, and it is also my first time to do something really practical. Referring to the official schematic diagram, the sampling circuit is mainly retained. The core board circuit refers to the national technology hardware evaluation version. For cost considerations, the high voltage support is expanded into a detachable module, which reduces the cost of the ammeter itself. The project must have shortcomings and areas worth improving. If I have time, I will try my best to improve it.
3. The open source agreement
uses the GPL3.0 open source agreement
. 4. The hardware part
is designed using the professional version of EasyEDA.
1. Current sampling: The current measurement relies on the sampling resistor to convert the current signal into a voltage signal (Ohm's law). Since the voltage is relatively small, an amplifier circuit is used to amplify the voltage. ASM1117 is used here, and then the PA1 of N32 is used. ADC measures the voltage value and calculates the corresponding current.
2. Voltage sampling: Since the maximum sampling voltage of the microcontroller ADC is 3.3V, and the USB output is at least 5V, a resistor divider must be used. Here (91k
and 10k resistors are used to construct a 110 voltage divider, and then PA2 is used to sample the value.

3. Power supply circuit: For cost considerations, the ammeter body disconnects the USB data line , so that the charger can only output 5V voltage, so that the main body can use LDO voltage reduction, which is low-cost and sufficient for 5V to 3.3V reduction;
if you need to test the fast charging mode, the LDO power supply mode has too much power loss and too much thermal power, so the main body has introduced six sockets for power module expansion sockets to expand the power supply mode. Plug in the power expansion module, the module can change the MOS tube gate level, turn off the MOS tube to shield the LDO circuit and use the BUCK voltage reduction circuit in the module to power the main body,

and at the same time connect the two differential data lines of the USB to realize the communication between the charger and the power-consuming device, thereby triggering fast charging.
4. Display circuit: Use PB13 and PB14 to simulate IIC communication to establish a connection with the 0.91-inch oled, and directly insert the module into the socket.
5. Download circuit: In order to save interfaces, use serial port download, two data cables of the common female socket, download, just need to connect the four wires of USB to serial port to a male connector, and then insert the female socket to connect to the computer to download.

5. The software part
is mainly based on the official program to modify the program of simulating IIC interface.
6. BOM list

7. Competition LOGO verification


8. Demonstrate your project and record it into a video and upload it
[Self-made USB ammeter based on N32-Bilibili] https://b23.tv/KSzh46D
N32G430C8L7-USBMeter.zip
PCB_PCB1_2022-11-05.pdf
BOM_Board1_PCB1_2022-11-05.xlsx
Altium_#The 7th Altium Electric Competition#Extensible USB Amperemeter_2022-11-05.zip
PDF_#The 7th Lichuang Electric Competition# Expandable USB Amperemeter_2022-11-05.zip
BOM_Board1_#The 7th Lichuang Electric Competition#usb ammeter_2022-11-05.xlsx
60583
#The7thLiChuangElectricityContest#USB Ammeter
Introduction: It can measure USB charging voltage, current and power, and can also use the host computer to view and record the data.
* 1. Introduction to project functions
1. Current detection function.
2. Voltage detection function.
3. Power consumption calculation function.
4. Serial port data reporting function. 5.
Data graphical monitoring function.
6. Network data interface.
7. Data storage function.
*2. Project attributes
The project is an original design and is open to the public for the first time. This type of product has not been designed before.
* 3. Open source agreement
GPL 3.0 Open source agreement
*4. Hardware part
1. Use INA199B1DCKR to measure current and voltage.
2. The USB input and output are close to each other, shortening the wiring distance and facilitating the circuit layout of other chip components. The input port is TYPE-C port and the output port is USB-A.
3. The serial port led out by the N32G430C8L7 chip is used as the firmware burning port and the data upload interface.
4. Lead out SWCLK and SWDIO ports as debugging ports.
Note: It is recommended to use Jiali Chuang EDA. If you choose other EDA tools, please upload the schematic diagram in PDF format, the PCB drawing in PDF format, and the PCB file in Gerber format in the attachment. Here you can explain in detail the implementation principle and mechanism of your project, precautions, debugging methods, testing methods, etc. It is recommended to introduce your ideas to others in the form of pictures and texts.
*5. The software part
uses PYTHON as the upper computer software development tool to receive the uploaded voltage, current, and power data and store them in a CSV file. Open WEB browsing function and HTTP API data interface, you can use a computer or mobile phone to view data in real time.
*6. BOM list,
please refer to the engineering BOM list
*7. Competition LOGO verification
* 8. Demonstrate your project and record it as a video and upload it
myUSBMeter firmware code.rar
Ammeter host computer.rar
Instructions for use.txt
Demo.mp4
60646
#The 7th Lichuang Electric Competition#Power consumption monitor
Introduction: The power consumption detector designed based on N32G430C8L7 and INA199A1DCKR can monitor the power consumption of low-power or high-power loads with a supply voltage of 1V-20V and a current of 0.1A-3A, or monitor the reverse current by switching the welding resistor.
Note: * is a required field,
please fill it in during the registration stage↓
* 1. Introduction to project functions
In a laboratory environment, it is very convenient to monitor voltage and current. Through some adjustable power supplies, multimeters, or high-end monitoring equipment, it is very convenient to monitor the input and output power consumption of the equipment in real time. However, these devices are relatively large in size, poor in portability, complex in measurement methods, and single in connection terminals. In order to more conveniently monitor the power consumption of some devices outdoors, or quickly measure the power consumption of devices indoors, a power consumption detector with an optional range is designed. By welding current sampling resistors with different resistance values, it can adapt to the measurement of high-power or low-power devices. In addition, in order to improve the measurement accuracy of low-power devices, the device comes with a battery to independently power the measuring device, which can reduce measurement errors and improve measurement accuracy.
*2. Project attributes
The project is open to the public for the first time; the project is original; it has never won an award; it mainly refers to the USB ammeter case provided by National Technology.
* 3. Open source agreement
GPL3.0 open source
* 4. Hardware part
1. Only one of the R2 and R12 resistors is pasted. If the current flows in the forward direction, R2 is welded. If it is reverse power supply, R12 is welded. The two resistors cannot be welded at the same time.

2. In order to adjust the resistance value of the current sampling resistor, you can choose to weld the resistor R*. The purpose of this is to target different current measurement ranges. The default 10mΩ resistor R1 is more suitable for large current measurement (up to 6A). When it is necessary to measure the power consumption of low-power devices, you can choose to weld a higher resistance resistor R*, such as 100mΩ, to improve the measurement accuracy of small currents.

3. Switch SW1 is used to switch the power supply of the power consumption meter. This is very necessary - it can avoid the extra current consumption of the external power supply, and it can also avoid the high voltage of the external power supply from burning the power consumption meter. When measuring the power consumption of a 5V powered USB device, the power meter can be powered directly by the TYPE-C port and output power at the same time without connecting VIN+ and VIN-; when measuring the power consumption of a higher powered device (voltage>6V), it is necessary to connect the power supply through the VIN+ and VIN- ports, and output through VOUT+ and VOUT-. At this time, the switch SW1 needs to be switched to lithium battery power to avoid damage to the device.

4. After testing, the maximum external power supply voltage is 30V, which is mainly limited by the ratio of the voltage divider sampling resistor R10/R11. If you need a higher voltage measurement range, you can increase the ratio of R10/R11, and accordingly, the voltage conversion value in the program also needs to be modified accordingly.
5. An additional IIC interface is added to the right side of the power meter, which can be connected to the temperature sampling module (AHT20) of the IIC interface to realize the function of ambient temperature calibration, but this function is not currently implemented because the selected sampling resistors are basically low temperature drift resistors, and the current use environment is not so bad that additional ambient temperature calibration is required.
*5. The software part
is fully compatible with the program in the USB ammeter case provided by National Technology. Although there are some differences in circuit design, including the power supply part, interface part, sampling circuit, and the display module uses a 0.96-inch OLED, it does not affect the display. The program only fine-tunes the error ratio during sampling, which can significantly improve the error in a larger measurement range. It should be noted that the software design provided by National Technology also uses an internal crystal oscillator source, that is, no external crystal oscillator is required.
*6, BOM list
No.
Quantity
Designator
Footprint
Supplier Part
Comment
1
4
C1,C3,C6,C9
C0603
C412628
4.7uF
2
10
C2,C4,C5,C7,C8,C10,C11,C12,C13,C14
C0603
C385971
100nF
3
1
CN1
CONN-SMD_1251SMT-2P
C132528
W-1251M02P-0400
4
2
H1,H2
Power supply pad
C49661
5
1
H3
HDR-TH_4P-P2.54-VM
Program burning port
Do not solder
6
2
H4,H5
HDR-TH_4P-P2.54-VF
Display screen interface / external IIC port
solder according to demand
7
1
R1
R2512
C500718
0.01Ω
8
2
R2,R12
R0603
C2909476
0Ω
9
2
R3,R4
R0603
C136596
10Ω
10
2
R5,R6
R0603
C23025
300Ω
11
1
R7
R0603
C23186
5.1kΩ
12
2
R8,R 9
R0603
C25804
10K
13
1
R10
R0603
C136946
91kΩ
14
1
R11
R0603
C136139
10kΩ
15
1
R*
R2512
C500718
0.1Ω
16
1
SW1
SW-SMD_JS202011JAQN
C221664
JS202011JAQN
17
1
U1
SOT-23-5_L3.0-W1.7-P0.95-LS2.8-BR
C82942
ME6211C33M5G-N
18
1
U2
MSOP-10_L3.0 -W3.0-P0.50-LS5.0-BL
C99652
CH340E
19
1
U3
SC-70-6_L2.2-W1.3-P0.65-LS2.1-BR
C59135
INA199A1DCKR
20
1
U4
LQFP-48_L7.0-W7.0-P0.50-LS9.0-BL
C3032170
N32G430C8L7
21
2
U5, U6
short terminal
does not need to be welded
22
1
USB1
USB-C-SMD_TYPE-C16PIN
C393939
TYPE-C16PIN
*7, Competition LOGO Verification
By comparing the measurement data with the power analyzer, it can be found that the power consumption meter has higher measurement accuracy, with an average voltage error of 1.2% and an average current error of about 1%.




* 8. Demonstrate your project and record it as a video and upload it
The 7th Electronic Design Competition - Power Consumption Monitor (1).mp4
The 7th Electronic Design Competition - Power Consumption Monitor (2).mp4
Power Analyzer Program.zip
60659
electronic