* 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