xK2bpax

Voltage and current meter detection

 
Overview
To save I/O resources, I used an SN74HC595 shift register to drive the LEDs in the hardware design
. The QA pin is the data input, which is the data you want to display. The SRCLR pin is used to shift the data bit by bit, and the RCLK pin is the latch pin to latch the data. The digital tube then dynamically refreshes the displayed data.
The current-limiting resistors R1, R2, and R3 can be omitted, or a smaller one, around 50 ohms, can be chosen.
The button circuit is very simple; it can be directly connected to ordinary I/O pins. Because the CW32 has internal pull-up and pull-down resistors, I didn't draw external resistors; you can directly use the internal pull-up and pull-down resistors when configuring the buttons.
This is the LED display circuit for my debugging purposes. Note that you need to choose appropriate current-limiting resistors; generally, the empirical value is between 1k and 4.7k.
This is the main component of the project, the LCSC Wenxin CW32F030C8T6 development board. I designed its package and schematic library myself. It has built-in 1.5V and 2.5V voltage references, and can also use external voltage references. The ADC accuracy is 0.366mV.
It features an ARM® Cortex®-M0+ 32-bit microcontroller with 64KB of FLASH and 8KB of RAM, offering abundant resources such as GPIO, II2C, SPI, USART, and ADC. Please refer to its datasheet for details.
This is a USB-to-serial module for convenient debugging. Note that CC1 needs to be connected to a 5.1k resistor. The D+ and D- differential signal lines must be of equal length. The CH340 is a USB-to-serial converter.
Set the differential pair in the rules, and then adjust
the SHT40 temperature and humidity module with equal length. Here, SDA is the data line and SCL is the clock line. The PCB traces should be differential. The R18 and R19 should be appropriately selected; general values ​​are 4.7k and 10k. The specific values ​​depend on the actual requirements.
This is the current sampling module. R14 is the sampling resistor, using a 2512 package with a power rating of 3W. In the PCB design, Kelvin wiring is required, as shown in the PCB 3D image,
3D casing
effect image, and
software section on
temperature and humidity
. `void SHT40_GetData(SHT40_t *sht40){ SHT40_I2C_Start(); SHT40_I2C_Write_Byte(SHT40_WRITE); SHT40_I2C_WaitAck(); SHT40_I2C_Write_Byte(SHT40_Read_Mode); SHT40_I2C_WaitAck(); SHT40_I2C_Stop(); delay_ms(10); SHT40_I2C_Start(); SHT40_I2C_Write_Byte(SHT40_READ); SHT40_I2C_WaitAck(); for(uint8_t i = 0; i` sht40->read_data[i] = SHT40_I2C_Read_Byte(); if(i == 5){ SHT40_I2C_NoAck(); }else{ SHT40_I2C_Ack(); } } SHT40_I2C_Stop(); sht40->Temperature = (1.0*175*(sht40->read_data[0]*256 + sht40->read_data[1])) / 65535.0 - 45.0; sht40->Humidity = (1.0*125*(sht40->read_data[3]*256 + sht40->read_data[4])) / 65535.0 - 6.0; sht40->Temp = (uint16_t)(sht40->Temperature*10); sht40->humi = (uint16_t)(sht40->Humidity*10);}
Here I wrote my own protocol using software I2C. After sending the address, there must be a 10ms delay. The chip manual says that reading the protocol is very simple. Send the address and command. Here I choose repeated measurement, then read the data, and finally
convert it according to the formula.
Display part
OLED_ShowChinese(0,0,0,24,1);OLED_ShowChinese(24,0,1,24,1);sprintf((char *)OLED_Data,":%.1fC",sht40.Temperature);OLED_ShowString(24*2,0,(uint8_t*)OLED_Data,24,1);OLED_ShowChinese(0,24,3,24,1);OLED_ShowChinese(24, ... *)OLED_Data,":%.1fH",sht40.Humidity);OLED_ShowString(24*2,24,(uint8_t*)OLED_Data,24,1);
Chinese characters are extracted using PCtoLCD2002. For easier data display, I use sprintf here. The usage of sprintf is similar to printf.

Open the extraction software and
extract Chinese characters.

2.1 Click Mode, select Character Mode
. 2.2 Click Options, set the settings
as follows: manually enter 999 for the numbers in the dot matrix, and then click OK.

Taking the generation of 16x16 Chinese characters as an example:
3.1 Select 16 for character width and height.

3.2 Enter the Chinese character to be extracted in the input field (only Chinese characters are allowed), and then click Generate Character Model.

Copy the generated character model to the h array.

Voltage and Current
if( GetTick() >= (TimeInterval + 300)){
TimeInterval = GetTick(); 
Mean_Value_Filter(&ADC_Param,ADC_SAMPLE_SIZE);
Mean_Value_Filter(&Current_Param,ADC_SAMPLE_SIZE);
 
if(ADC_Param.filter_val >= ADC_Param.X_ADC[0]){
ADC_Param.adc_buf = (ADC_Param.Slope[0]*(ADC_Param.filter_val - ADC_Param.X_ADC[0]) + 5)*1000;
}else if(ADC_Param.filter_val >= ADC_Param.X_ADC[2] && ADC_Param.filter_val
ADC_Param.adc_buf = (ADC_Param.Slope[1]*(ADC_Param.filter_val - ADC_Param.X_ADC[2]) + 2.5)*1000;
}else{
ADC_Param.adc_buf = 2500/ADC_Param.X_ADC[2]*ADC_Param.filter_val;
}
if(ADC_Param.adc_buf % 10 >= 5){
ADC_Param.adc_buf = ADC_Param.adc_buf/10 + 1;
}else{
ADC_Param.adc_buf /= 10;
}
if(ADC_Param.adc_buf >= 1000){
ADC_Param.Seg_Num[0] = ADC_Param.adc_buf/1000;
ADC_Param.Seg_Num[1] = ADC_Param.adc_buf/100%10;
ADC_Param.Seg_Num[2] = ADC_Param.adc_buf/10%10;
}else{
ADC_Param.Seg_Num[0] = ADC_Param.adc_buf/100;
ADC_Param.Seg_Num[1] = ADC_Param.adc_buf/10%10;
ADC_Param.Seg_Num[2] = ADC_Param.adc_buf%10;
}
 
if(Current_Param.filter_val >= ADC_Param.X_ADC[3]){
Current_Param.adc_buf = (ADC_Param.Slope[2]*(Current_Param.filter_val - ADC_Param.X_ADC[3]) + 0.1)*1000;
}else{
Current_Param.adc_buf = 100/ADC_Param.X_ADC[3]*ADC_Param.filter_val;
}
Current_Param.Seg_Num[0] = Current_Param.adc_buf/100;
Current_Param.Seg_Num[1] = Current_Param.adc_buf/10%10;
Current_Param.Seg_Num[2] = Current_Param.adc_buf%10;
This is the voltage and current display part and voltage and current calibration. The data needs to be filtered to remove the maximum and minimum values, and then the average is taken. After calibration, the error is about 0.01V.
 
 
 
 
 
参考设计图片
×
 
 
Search Datasheet?

Supported by EEWorld Datasheet

Forum More
Update:2026-03-27 19:44:35
  • Smart clock with 8 alarm settings (with schematic diagram)
  • LM3S811 Chinese data ZLG
  • December EEWORLD Community Theme Month Event Awards
  • How did this quadruple do it?
  • Hercules DIY Design - also submit weekly plan
  • I'm begging for a DSP development board and simulator

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号