Introduction
A USB voltage and current meter based on N32G430C8L7 can easily show the three parameters of the charger output voltage, current and power.
Project Description
This project is used in this LiChuang Electric Competition, supports fast charging, and the measured 5-20V can work normally! Limited by the current carrying capacity of the USB output port, the output current is not suitable for a long time exceeding 2.5A!
Hardware part The
main control
N32G430C8L7 microcontroller product adopts a high-performance 32-bit ARM Cortex™-M4F core, with a maximum operating frequency of 128MHz, supports floating-point operations and DSP instructions, integrates up to 64KB embedded encrypted Flash, 16KB SRAM, integrates a wealth of high-performance analog devices, built-in 1 12bit 4.7Msps ADC, 3 high-speed comparators, and integrates multiple U(S)ART, I2C, SPI, CAN and other digital communication interfaces.
The N32G430C8L7 microcontroller product can work stably in the temperature range of -40°C to +105°C, with a supply voltage of 2.4V to 3.6V, and provides multiple power consumption modes.
This case uses the I2C communication interface and ADC analog-to-digital converter. The clock accuracy requirement is not high. The internal clock has met the design requirements, so there is no need for an external clock circuit. In order to improve the stability of the power supply and reduce the mutual interference between the main control and the power supply, a 0.1uF decoupling capacitor needs to be connected to each power supply pin of the chip. In order to adapt
the reset circuit and BOOT circuit
to the public version housing, the PCB space of this design is limited, and the buttons of the reset circuit and BOOT circuit are replaced by solder joints.
The burning interface
uses the ST-Link burner in this case, and the corresponding interface uses a 2.54-pitch pin header for burning.
The power supply circuit
uses the UA78M33 LDO chip as a voltage conversion chip in this case, with a maximum input support of 25V and an output of 3.3V. It should be noted that the LDO input and output must be connected to 10uF and 0.01uF filter capacitors. To prevent the charger from being damaged by a short circuit in the later stage, this design adds a 500MA self-recovery fuse to the power input. Current
sampling
This design uses low-side sampling (GND loop series resistor) to collect current, which is amplified by the INA199B1DCKR current sensing amplifier and then sent to the ADC of the MCU for processing. Among them, the INA199B1DCKR current sensing amplifier can sense the voltage drop on the shunt resistor at a common-mode voltage of –0.3V to 26V independent of the power supply voltage. The device adopts a zero-drift architecture with low offset, so the maximum voltage drop across the shunt resistor can be kept at a minimum of 10mV full scale when current sensing is performed. The sampling resistor uses a high-precision chip alloy resistor (0.01Ω/1W) in a 1206 package to reduce losses while ensuring sampling accuracy.
Voltage sampling
The voltage sampling circuit uses a simple and economical voltage division sampling, which is composed of two high-resistance resistors in series. This can detect higher input voltages, and the high resistance is to reduce the power consumption of the ammeter itself, but because the high resistance is also susceptible to external interference, the sampling circuit signal line should be as short as possible when designing the PCB.
Display part
The display part uses a 0.91-inch white OLED screen module with IIC communication.
Physical picture
Software part
The compiler used in this design is Keil uVision5
Debug tool is ST-Link V2
Demo video