Overview
Based on the N32G430C8L7 main control, the USB power meter is made with a current sampling error of 1%. It can view the current, voltage and power of the device connected to the USB in real time, and can be used as a simple voltmeter to measure the external voltage.
Hardware design requirements
There are no special requirements for the software of this design, but the hardware design requires that the ADC acquisition and power supply circuits should pay attention to reasonable wiring. High-frequency and power supply VCC lines are not allowed to pass around and below the ADC acquisition circuit to ensure accurate and efficient ADC data acquisition. The power supply of the main control chip pin 1 should be matched with 4.7uf and 100nf filter capacitors, and the 3.3V first passes through the 4.7uf capacitor to filter out low-frequency clutter and then passes through the 100nf capacitor to filter out high-frequency clutter before flowing into the main control MCU through pin 1. In terms of data acquisition and display
during software execution,
INA199A1DCKR is used with peripheral devices as the current sampling circuit, 91K and 10k resistors are connected in series as the voltage acquisition circuit, and a 0.91-inch I2C protocol OLED is used as the display, and a button is used for interface switching.
In terms of software, the on-chip peripherals used in this design include GPIO, ADC, EXTI, and TIM1. The design scheme is that TIM1 generates a 500ms interrupt base to control ADC data acquisition and processing. When the key is pressed, the external interrupt is triggered, and the interface switching control bit state (the initial value is 0x01, that is, interface 1) is incremented by 1. When it is greater than or equal to 0x04, the control position is 0x01. When state is equal to 0x01, interface 1 displays "HUANGHUAI UNIVERSITY", when state is equal to 0x02, interface 2 displays the current voltage, current, and power in real time, and when state is equal to 0x03, interface 3 displays the external measurement voltage (switch to external measurement mode through the jumper cap).