王达业

#The7thLiChuangElectricityContest#Small power analyzer

 
Overview

# 1. Introduction to project functions

![image.png] I have previously made a low-power mobile device powered by a battery. In order to evaluate the battery life, it is necessary to know the power consumed by the device in a sleep cycle. Because the working current of the device is constantly changing, ordinary multimeters are not competent, so a precision power meter that can measure, record, and analyze current changes is needed. However, this kind of professional-grade instrument is very expensive, and it is not cost-effective for a project to practice hands, and it is not convenient to use an oscilloscope plus an amplifier circuit. So this project was born.

This project is a small, portable precision power meter that can measure a current of up to 1uA. It has a 2.4-inch QVGA screen that can record the current consumption of the device or the voltage change of the power supply, and display it in a graphical way, which is convenient for power supply or power consumption analysis. The body has its own battery and supports completely offline operation without the need for a host computer. At the same time, the sampled data can also be uploaded to the PC for more detailed data analysis. It supports trigger sampling function, which can easily record occasional events. The maximum sampling rate of 100SPS meets the needs of most scenarios.

Features:

* Digital voltmeter and ammeter function
* 2.4-inch color LCD display
* Voltmeter range: 0~5.5V, resolution 0.01V, ammeter range: 0 ~ 1A, resolution 0.1uA (effective value 1uA)
* Sampling rate: up to 100SPS, minimum 0.01SPS
* Maximum sampling depth 6kpts
* Data recording, playback and chart display function
* Support cursor, you can review the sampling record at any time
* Support trigger sampling, working mode: automatic, manual, conditional
* Conditional trigger supports voltage and current trigger
* Trigger edge: rising, falling
* Support data upload (via USB universal serial port protocol)
* Built-in 700mA battery, can be used offline for up to 4 hours, charging method: USB TYPE-C
* For more feature demonstrations, please refer to the video

. The hardware part of this project is 100% designed using EasyEDA.

The software and hardware of this project are completely open source. You can browse and download the resources of this project, or carry out secondary development on this basis, but unauthorized commercial use is prohibited.

# 2. Project attributes

This project is open to the public for the first time and is my original project. The project has not won any awards in other competitions.

# 3. Open source agreement

This project is completely open source, including the host computer code on the PC side and the code on the MCU side. Distributed using the GPL3.0 agreement.

# 4. Hardware part

## Basic working principle

The basic working principle of the device is shown in the figure. This project is essentially a packaged voltmeter plus an ammeter, but it has additional functions for sampling, storing, and processing test results, which can be used to observe the changes in voltage or current over time, or to analyze data for a specified time period.

![image.png]
## PCB Overview

### Back

![image.png]
### Front

![image.png]
## Hardware Structure

The hardware structure of the project is mainly composed of the following parts:

* Sampling and Amplification Circuit
* Analog-to-Digital Converter (ADC)
* Power Management Module
* Input (User Button) and Output Module (LCD and USB-UART)
* MCU ![image.png]
## Sampling and Amplification Circuit

### Overview of Current Sampling and Amplification Circuit

#### Schematic Diagram

![image.png]
#### PCB Diagram

![image.png]
Current sampling is the focus of this project. In this project, the sampling resistor low-side current sampling method is used to sample the current. Because the highest current resolution of this project is designed to reach 0.1uA, and the maximum current range is 1A, the difference between the two is 10 million times. If it is realized by a single sampling resistor, not only the sampling resistor should choose a higher resistance model, but also the operational amplifier needs to be used to amplify the sampling result by more than 1000 times, which may introduce a lot of errors and noise in the measurement results. Therefore, this project uses two sampling resistors with different resistance values. Among them, the low resistance (0.1Ω) resistor is used for sampling when the current is large, and the high resistance (10Ω) resistor is used for sampling when the current is small. Then the sampling results on each sampling resistor are amplified by the operational amplifier at two levels, and all the results of each level of amplification are led out. In this way, a total of four ranges can be obtained, and the magnification of each range is within the normal range (the order of magnitude of 10 to 100 times), and the maximum resolution of the ADC can be fully utilized within the range of each range. Finally, after adjusting the amplification ratio, the design goal of the lowest resolution of 0.1uA (the minimum effective value is 1uA) and the highest high measurement range of 999mA can be finally achieved in hardware.

### Range switching circuit

![image.png] Because two sampling resistors are used, if the two sampling resistors are always connected to the circuit, then when the current is large, the voltage drop on the large resistance sampling resistor will become very considerable (there will be a voltage drop of 1V when the current is 0.1A), which will cause heat on the one hand, and on the other hand, it will cause the voltage at the output end to drop, which may affect the normal use of the output end device. So in order to solve this problem, this project designed a range switching circuit. When the current is large (the threshold set in this project is 10mA), a MOSFET is used to short-circuit the large-resistance sampling resistor, and then the MOSFET is turned off when the current is less than the threshold, and the sampling resistor is connected to the circuit. In this way, the voltage drop problem on the high-resistance sampling resistor under large current is perfectly solved.

### Current amplifier circuit

![image.png] The amplifier circuit corresponding to each sampling resistor is composed of a secondary op amp amplifier circuit, in which the primary amplifier circuit uses a differential amplification method to further reduce the error caused by the resistance on the wire, and the secondary amplifier circuit uses a general positive feedback amplification. For this project, the amplification factor of the primary amplifier circuit is 33 times (10xADC measurement range), and the amplification factor of the secondary amplifier circuit is 9.2 (about 10) times. The amplification results of the two stages are introduced into the ADC, plus the two-stage input of another sampling resistor, a total of four stages of amplification results are input into the ADC through four channels. Because the resistance value of the two sampling resistors differs by 100 times, for the same current signal, the ADC will simultaneously obtain four levels of input (i.e., four gears) of the signal, namely x10, x100, x1000, and x10000. In this way, the ADC can select the appropriate gear within its dynamic range as the final output result.

### Voltage Amplifier Circuit

Voltage is not the focus of this project, because usually, the power supplies we have used are constant voltage power supplies, the voltage will not produce a large fluctuation, and basically there is no need to measure ultra-low voltage (such as less than 1V). Compared with voltage, we are more concerned about the change of current (some similar instruments on the market do not even have the voltage measurement function, they are just high-precision ammeters). Therefore, the voltage measurement range designed in this project is 0~5.5V, with a resolution of 0.01V.

![image.png]
The specific voltage sampling is implemented using a differential amplifier (attenuation) circuit, which attenuates the input voltage by 2.13 times. In this way, when the ADC range is 0~3.3V, the maximum allowable voltage input is about 7V. Compared with the design target of 0~5.5V, it not only leaves enough margin, but also can give full play to the performance of ADC and achieve a resolution of 0.01V.

### Op amp selection The current

signal amplification part uses two high-precision, zero-offset dual R2R op amps COS8552, which are responsible for amplifying the signals on the two sampling resistors

![image.png]
The voltage amplification part uses a general single-channel op amp RS321 because the requirements are not high

![image.png]
## ADC

From the previous introduction, we can see that the ADC needs at least 5 channels to meet the requirements, that is, 4 current channels and one voltage channel. In addition, in order to achieve a sampling rate of 100SPS, the sampling rate of the ADC must also be higher than this design goal. Multi-channel, high-resolution, and high-sampling-rate ADCs are very expensive. Because our requirements for each sampling channel of the ADC are different, we hope for a higher current resolution, but the voltage resolution is not high. Therefore, for the most optimized choice, this project chooses to use an independent ADC to sample the current channel, while the voltage and other analog channels (such as battery power and joystick input) are sampled using the ADC built into the MCU.

The independent ADC used for current sampling finally selected the ADS1115 model, which has a 4-channel 16-bit resolution, uses IIC to communicate with the MCU, and has a maximum sampling rate of 860SPS, which meets the needs of this project.
![image.png]
## Power Management

### Battery and Charge and Discharge Management

In order to facilitate use and meet the design requirements of completely offline use, this project chose a built-in lithium battery solution. The charge and discharge management of the lithium battery is implemented using the classic TP4056. The designed lithium battery capacity is 700mAh and the size code is 642745 (64mmx27mm in length and width, 4.5mm in thickness)

![image.png]
The corresponding battery installation position on the PCB version:

![image.png]
The charging management uses the classic TP4056 charging management IC:

![image.png]
The related circuits are as follows:

![image.png]
### Power supply solution

Because the working current demand of this project is not large and it is sensitive to circuit interference, the LDO solution was selected for the power supply solution. The LDO used is XC6206 (the classic 662k)

![image.png]
In order to achieve digital-analog isolation for power supply, and the backup power supply required by the RTC part of the MCU, a total of 3 XC6206s are used to power the digital circuit, analog circuit and MCU RTC (backup circuit) respectively. It should be noted that the digital power supply VCC and the analog power supply VCC are turned on by the switch control, while the backup power supply bypasses the switch and is directly connected to the battery.

![image.png]
### Battery power and charging detection

This part of the circuit is to detect the battery power and charging status, and both are implemented using a resistor divider circuit. In order to reduce the consumption of battery power, the power detection circuit is located after the switch. The output signals of both are directly connected to the ADC channel of the MCU:

![image.png]
### Analog ground and digital ground

In order to reduce the crosstalk between the analog circuit and the digital circuit, this project uses the analog ground and digital ground isolation method, and the two are connected at a single point through a 0Ω resistor:

![image.png]
## User input and output

### LCD

LCD is the main user output channel, and most of the data of this machine is displayed to the user through the LCD. After balancing the completeness of the display content, the processing power of the MCU and the project cost, this project chose a 2.4-inch color dot matrix TFT-LCD display with a resolution of QVGA (320X240). The LCD communicates with the MCU via the 8-bit 8080 bus. After testing, the maximum refresh rate can reach 60Hz. In actual use, in order to reduce the pressure on the MCU, this screen finally works in 8-bit (LUT) color mode.

The LCD circuit at a refresh rate of 30Hz is as follows

![image.png]
The LCD backlight circuit uses a MOSFET through PWM control, the dimming frequency is about 1KHz, and the maximum operating current is about 40mA

![image.png]
### Buttons

The user input of this project is all completed by buttons, including a five-way switch (joystick) and two touch buttons.

In order to reduce IO consumption and PCB wiring difficulty, the joystick uses the ADC button connection method:

![image.png]
The other two buttons use independent IO. For the possible MCU sleep function in the future, the run button is a high-level trigger and is connected to the PA0 sleep wake-up IO of the MCU. The other option/setting button uses a general low-level trigger and is connected to the ordinary GPIO of the MCU.

![image.png]
### USB serial port

In order to realize the upload function of sampled data, this project additionally designs a USB-UART bridge circuit, which can upload data to the host computer through the USB serial port.

![image.png]
The model of the USB serial port IC selected is CH340E:

![image.png]
In this project, the communication parameters of the serial port are **11500 baud rate, 8 data bits, 1 stop bit, no parity bit**

## MCU

The MCU used in this project is STM32F407VE, which has 192KB of SRAM, a maximum frequency of 168MHz, and an ADC and 8080 bus interface, which can meet the needs of this project for signal sampling and processing as well as driving LCD

![image.png]
# 5. Software part

## Development environment

This project is developed using STM32CubeIDE based on Eclipse, and the compiler is GCC:
![image.png]
## Software architecture

The software architecture of this project is relatively simple. It uses the HAL library as the hardware driver of the MCU and FreeRTOS as the software foundation of the entire project. The OS is divided into two threads, one of which is the ADC sampling thread, which is a high-priority thread, and the other is the main thread. The ADC sampling thread is only responsible for sampling the ADC at a fixed frequency. Other signal processing, user interaction, data display, logic processing, etc. are all completed in the main thread.

The graphics processing part uses an 8-bit full-screen framebuffer to reduce the development difficulty and improve the screen refresh efficiency. The font processing part of the graphics library used uses part of the LVGL code, and the rest is all self-written.

Screenshot of the part of the graphics library code used

! [image.png]
The structure of the sampled data is defined using a structure, so that the voltage, current and timestamp data at the time of sampling are saved at each sampling point. The memory consumption of a single data is 8 bytes, and a total of 48KB of memory is used to achieve a maximum storage depth of 6Kpts

![image.png]
# 6. Project material list

![image.png]
![image.png]
# 7. Competition LOGO verification

![image.png]
# 8. Other pictures

## Finished product picture

![image.png]
## Front (not powered on)

![image.png]
## PCB back

![image.png]
参考设计图片
×
 
 
Search Datasheet?

Supported by EEWorld Datasheet

Forum More
Update:2025-06-23 13:01:50

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
community

Robot
development
community

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号