1. Project Introduction
A small USB power meter based on the domestic N32G430 chip, supporting fast charging. With a 3D printed shell.
2. Project attributes
Based on N32G430+INA199
3. Hardware
(1) Main control chip: N32G430C8L7
The N32G430C8L7 microcontroller product uses a high-performance 32-bit ARM Cortex™-M4F core, integrated floating-point unit (FPU) and digital signal processing (DSP), and supports parallel computing instructions. The maximum operating frequency is 128MHz, integrated up to 64KB on-chip encrypted storage Flash, and supports multi-user partition permission management, and supports 16KB embedded SRAM. It has an internal high-speed AHB bus, two low-speed peripheral clock buses APB and bus matrix, supports 40 reusable I/Os, provides a rich set of high-performance analog interfaces, including a 12-bit 4.7Msps ADC, supports 16 external input channels and 3 internal channels, and provides a variety of digital communication interfaces, including 4 U(S)ARTs, 2 I2Cs, 2 SPI/I2Ss, and 1 CAN 2.0B communication interface. The N32G430C8L7 microcontroller product can stably operate in a temperature range of -40°C to +105°C, with a supply voltage of 2.4V to 3.6V, and provides a variety of power consumption modes. This case uses few resources, and the internal clock has been open sourced to meet the design requirements, so there is no need for an external clock circuit. It should be noted that each power pin of the chip needs to be connected to an additional 100nF external filter capacitor, and the 1st pin of the chip needs to be connected to an additional 4.7uf filter capacitor

(2) The crystal oscillator circuit
uses an external 8M crystal oscillator

(3) Reset circuit

(4) Download options
support SWD download and serial port download.

(5) The power circuit
supports fast charging. It uses a DC/DC power supply with high efficiency. Prevent the circuit from heating up when the input voltage is too large. The output voltage Vout=0.8*(R1+R3)/R1.

(6) The current detection circuit The
current sampling part is the INA199B1DCKR current sensing amplifier (also called current sensing amplifier), which is commonly used for overcurrent protection, precision current measurement for system optimization, or closed-loop feedback circuits. This series of devices can sense the voltage drop across the shunt resistor at a common-mode voltage of –0.3V to 26V independent of the power supply voltage. There are three fixed gains to choose from: 50V/V, 100V/V, and 200V/V. This series of devices uses a zero-drift architecture with low offset, so the maximum voltage drop across the shunt resistor can be kept to a minimum of 10mV full-scale when performing current sensing. The parameters are as follows:
Common-mode range: –0.3V to 26V
Offset voltage: ±150μV (maximum)
Supports 10mV full-scale shunt voltage drop
This sampling uses low-side sampling, that is, the sampling resistor is connected to the GND loop. This design can calculate the complete differential, follow, amplify, and output when the differential signal is sent to the op amp. If high-side sampling is used, that is, the sampling resistor is placed at a high position between the power supply and the load, although this placement not only eliminates the ground interference generated in the low-side detection scheme, but also detects accidental shorts from the battery to the system ground, but high-side detection requires the detection amplifier to handle a common-mode voltage close to the power supply voltage. This common-mode voltage value range is very wide, ranging from the level required to monitor the processor core voltage (about 1V) to hundreds of volts commonly seen in industrial, automotive, and telecommunications applications. Application examples include typical laptop battery voltage (17 to 20V), 12V, 24V or 48V batteries in automotive applications, 48V telecom applications, high-voltage motor control applications, current sensing for avalanche diodes and PIN diodes, and high-voltage LED backlights. Therefore, an important advantage of high-side current sensing is that the detection amplifier has the ability to handle large common-mode voltages. Therefore, the current sampling method of sampling resistor plus op amp is best performed at the low end. Although low-end sampling will affect the ripple of the signal due to common ground interference. However, compared with the high end, the solution is simple, low-cost and highly reliable. Quiescent current: 100μA (maximum)
Inserting a low-resistance detection resistor in series in the current path will form a small voltage drop, which can be amplified and treated as a signal proportional to the current. However, depending on the specific application environment and the location of the detection resistor, this technology will pose different challenges to the detection amplifier. Generally, the resistance value of sampling resistors is below 1 ohm, which belongs to milliohm-level non-inductive resistors. However, some resistors have sampling voltage and other requirements, so large resistance value resistors must be selected, but the resistance base is large and the error is large. In this case, it is necessary to select high-precision non-inductive resistors (which can reach 0.01% accuracy, that is, one ten-thousandth accuracy) to make the sampling data very reliable. The temperature coefficient of products such as ultra-low resistance value resistors (0.0005 ohms, 2 milliohms, 3 milliohms, 10 milliohms, etc.) of SMDs, SMD alloy resistors, and high-power resistors (20W, 30W, 35W, 50W, 100W) is plus or minus 5PPM.
If the inventory of INA199B1DCKR is insufficient, you can replace the INA199A3DCKT chip. It should be noted that the magnification of INA199B1DCKR is 50, and the program calibration needs to be re-modified when using other magnifications.

(7) Voltage detection circuit
The voltage sampling part is composed of a voltage divider circuit composed of two resistors.

(7) OLED display
The display part uses a 0.91-inch 4P white OLED screen module, using IIC communication, and the display effect is clear.
4. Software part
Compiler: ARM Compiler version 5
Debugger: ST-Link V2
5. 3D preview

6. Physical display

7. Notes
The 3D printed shell cannot be fixed, I fixed it with tape.
8. Demonstration video
link: https://www.bilibili.com/video/BV1zP4y1f7PZ?spm_id_from=333.999.0.0&vd_source=1d89d957f45bfff307c7b2df72ea0abc