* 1. Project function introduction
This USB power meter based on the National Technology N32G430C8L7 MCU supports TYPE-C and TYPE-A power supply, input voltage 4.5V-28V, maximum current 5A (limited by the USB interface, over 5A for a long time will cause heat), with PD deception function (the power adapter must support the PD protocol), can trigger different output voltages by pressing buttons, and can be used as a small DC power supply.
It can realize the stopwatch function and calculate the total amount of power charged within the time (the actual measurement error is large, Figure 1 is happy).
*2. Project attributes
This project is the first public release of the Lichuang Electric Competition.
* 3. Open source agreement
GPL 3.0
*4. Hardware part
(1) DCDC
The DCDC of this project uses Ruiyuan's RY9320AT6, because the power meter MCU and OLED have low power consumption, and the general DCDC has low efficiency under low load conditions. This DCDC has a light load energy saving function, which fully meets the project requirements. Pay attention to the input capacitor voltage resistance.
(2) Current sampling
This current sampling adopts TI's INA199A1 chip, the chip gain is 50V/V, and the sampling resistor is 10mΩ. A high-side sampling scheme is adopted.
(3) Voltage sampling
This voltage sampling adopts a scheme of resistor voltage division and sending it to the MCU ADC to collect voltage. The voltage division resistors are 10K and 90K, but the actual 90K resistor is difficult to buy, so you can buy 91K and use a multimeter to select a resistor close to 90K.
(4) Independent buttons
This design adopts 3 independent buttons, using the default pull-up, and a low level is generated when the button is pressed. SW1 realizes the start and pause of the timing. SW2 realizes the timing reset (only valid when the timing is paused). SW3 realizes the switching of PD deception voltage (some voltages require adapter support).
(5) The USB interface
adopts two TYPE-A and two TYPE-C interfaces. The TYPE-A port uses 5P 5A high current male and female sockets. Compared with the ordinary 4P TYPE-A port, it has an ID pin, which can identify private protocols such as OPPO. TYPE-C is mainly used for PD voltage deception.
(6) PD deception
PD deception uses Qinhengwei's CH224K PD power granting protocol chip, and deduces voltages of different gears by changing the CFG1-3 pin level. Xiaomi 30W adapter uses TYPE-C female port to decoy 12V, which has a temporary problem.
(7) OLED
This time, a separate OLED design is used, and the screen driver board and the main control board are connected through the FPC board-to-board connection line, which greatly saves space and makes the layout more beautiful. The screen driver design refers to the SSD1306 data sheet.

Please purchase components according to the attached bom. For more details, see the schematic diagram and PCB! ! !
*5. Software Some
software is compiled using KEIL and debugged using ST-LINK. It is modified based on the official routine, adding a timer to be responsible for timing tasks and adding a key interrupt to be responsible for function switching. The code contains comments. For details, see the attached program compressed package.
I would like to thank the little bee for helping me with the program.
Some program screenshots:


*6. BOM list
*7. Competition LOGO verification

* 8. Physical verification



