Operating voltage: 1.65V~5.5V (STM32 only supports 3.3V systems, so you can directly fill it with 5V during programming without any problems)
Super strong anti-interference: HBM ESD 8KV All ESD reliability reaches the highest level of international standards (STM32 ESD 2KV)
Project Focus - Better ADC: 12-bit high-speed ADC can reach ±1.0LSB INL 11.3ENOB Multiple Vref reference voltages... ... (STM32 only supports VDD=Vref)
Stable and reliable eFLASH technology.
The SE8550K2, with a maximum input voltage of up to 40V, is chosen as the power supply to meet the needs of practical voltmeter products, which are mostly used in industrial scenarios with 24V or 36V power supplies.
The main reason for not using a DC-DC step-down circuit to handle large voltage differences is to avoid introducing DC-DC ripple interference during the design process; a secondary reason is to reduce project costs.
: https://wiki.lckfb.com/zh-hans/dwx-cw32f030c8t6/training/voltammeter-bootcamp/voltammeter.html
Pay attention to the soldering order and do not heat the LEDs for too long.
Surface mount first, then through-hole components to avoid them not being able to fit on the heating platform.
Note that after soldering the surface mount components, solder the digital tubes first, then solder the development board's headers; otherwise, you will be frustrated. (It looks difficult to solder.)
When soldering potentiometers, be sure to solder the right-side potentiometer according to the silkscreen markings; otherwise, it will block the development board's USB port.
I. Design Background
An ADC (Analog-to-Digital Converter) is an indispensable key component in electronic systems. It converts continuous analog signals into digital signals, enabling digital processing and analysis. ADCs play a crucial role in signal conversion, measurement and data acquisition, control system input, and communication and signal processing. Their widespread application promotes the intelligent and precise control of electronic equipment across various industries, and is one of the key factors driving modern technological progress. Digital voltmeters and ammeters combine ADC technology with circuit measurement principles, accurately converting analog voltage and current signals into digital displays for easy reading and analysis by electronic engineers. This device not only improves the accuracy and efficiency of circuit measurements but also helps engineers better understand circuit behavior, serving as a powerful assistant in electronic design and troubleshooting, and playing a vital supporting role in the work of electronic engineers. In product applications, digital voltmeters ensure the accuracy and safety of circuit design, while also providing strong support for product quality control and subsequent maintenance. Learning to design and build a digital voltmeter and ammeter

using a benchtop digital multimeter (Agilent 34401A)
is highly beneficial for improving one's professional skills. This digital voltmeter and ammeter project covers multiple aspects, including microcontroller circuit design and implementation, signal acquisition and processing circuit design, user interface development and optimization, and product appearance design. It integrates knowledge from multiple fields such as electronics, microcontroller programming, circuit design, and industrial design. Considering the learning pace and knowledge absorption capacity of beginners, we have specially launched this introductory-level digital voltmeter and ammeter project, which is very suitable for beginners in electronics and those who want to learn more about microcontroller applications. This project has the following highlights:
it adopts a core board plus expansion board design concept and uses plug-in components, making learning simpler and exploration more in-depth;
the core board uses the domestic Wuhan Xinyuan Semiconductor CW32 as the main controller, while also being compatible with other similar development boards; however, the CW32 has advantages.
The project is highly comprehensive and practical, and after completion, it can be used as a desktop instrument;
the project has abundant learning materials, including circuit design tutorials, PCB design, code programming learning, and training for engineers' debugging skills.
II. Hardware Design
1. Power Supply Circuit

LDO (Low Dropout Linear Regulator) Selection This project uses an LDO as the power supply. Considering that most voltmeter products are used in industrial scenarios with 24V or 36V power supplies, the SE8550K2 with a maximum input voltage of up to 40V was selected as the power supply. The main reason for not using a DC-DC step-down circuit to handle the large voltage drop is to avoid introducing DC-DC ripple interference during the design process, and the secondary reason is to reduce project costs.
2. MCU Selection Analysis
To reduce the learning cost for everyone, this project uses the LCSC CW32F030C8Tx development board (core board) as the main controller, but this does not mean that we will talk less about this section. From the perspective of training engineers, the correct selection of the main controller is very important, as it relates to the overall advantage of the project. Regarding the voltmeter and current meter, the author used STM32/CW32 and some other 32-bit microcontrollers for some debugging and testing. This comparison is only with the STM32F103C8T6 as a reference for device selection, primarily aimed at providing ideas and improving understanding.
Avoid blind selection. When selecting an MCU (Microcontroller Unit) for this project, multiple aspects need to be considered to ensure the chosen MCU meets project requirements.
Clearly define your project needs: Understand the required computing power, including clock speed, processor core type, and whether a floating-point unit is needed.
Identify the required I/O ports and important peripherals, such as ADC peripherals. Since this is a development board project, primarily for debugging and learning, there are no strict limitations on the number of I/O ports: i.e., the associated costs are not considered.
Key advantages of the CW32 in this project
: Wide operating temperature range: -40~105℃;
Wide operating voltage range: 1.65V~5.5V (STM32 only supports 3.3V systems)
; Superior interference immunity: HBM ESD 8KV; All ESD reliability meets the highest international standard (STM32 ESD 2KV)
; Project focus - Better ADC: 12-bit high-speed ADC, achieving ±1.0LSB INL 11.3ENOB; Multiple Vref reference voltages... (STM32 only supports VDD=Vref);
Stable and reliable eFLASH technology.
A detailed explanation of these advantages will be provided in the chapters on ADC sampling and related extensions.
The main characteristics of the CW32 ADC: This project requires a focus on the 4 reference voltage sources. (Content from the "CW32x030 User Manual")

3. Voltage Sampling Circuit:
The voltage divider resistors in this project are designed to be 220K+10K, therefore the voltage division ratio is 22:1 (ADC_IN11).
The voltage divider resistor selection
is designed to measure the maximum voltage. For safety reasons, this project uses 30V (the actual maximum display value can be 99.9V or 100V).
The ADC reference voltage is 1.5V in this project, and this reference voltage can be configured through the program.
To reduce the power consumption of the sampling circuit, the low-side resistor (R7) is usually chosen as 10K based on experience.
Then, the high-side resistance of the voltage divider resistor can be calculated using the above parameters.
The required voltage division ratio is calculated, i.e., the ADC reference voltage. The input voltage is designed; using known parameters, 1.5V/30V = 0.05 can be calculated.
The high-side resistance is calculated as the low-side resistance/voltage division ratio; using known parameters, 10K/0.05 = 200K can be calculated.
A standard resistor is selected: a resistor slightly higher than the calculated value of 200K is chosen. We usually choose E24 series resistors; therefore, in this project, 220K, which is greater than 200K and closest to the calculated value, is selected.
If, in actual use, the voltage to be measured is lower than 2/3 of the module's design voltage (66V), the voltage divider resistor can be replaced and the program modified to improve measurement accuracy. The following example illustrates this:
Assuming the measured voltage is no higher than 24V and other parameters remain unchanged,
calculations show 1.5V/24V = 0.0625, 10K/0.0625 = 160K. 160K is a standard E24 resistor and can be directly selected, or a higher value 180K can be chosen with some redundancy.
If, in actual use, the voltage to be measured is higher than the module's 99V design voltage, a different resistor can be selected. To expand the voltage measurement range, you can choose to replace the voltage divider resistor or modify the reference voltage. The following example illustrates this:
Assuming the measured voltage is 160V, we can choose to increase the voltage reference to expand the range.
Given that the voltage division ratio of the selected resistor is 0.0145, we can calculate 160V * 0.0145 = 2.32V using the formula. Therefore, we can choose a 2.5V voltage reference to expand the range (increasing the range will reduce accuracy).
Considering the potential fluctuations in the measured power supply, a 10nF filter capacitor is connected in parallel with the low-side voltage divider resistor in the circuit design to improve measurement stability.
(Range switching )
In this project, an additional voltage sampling circuit was added. Therefore, we can discuss the significance of range switching for improving measurement accuracy. Multimeters often have multiple range settings to achieve more accurate measurements. By adjusting different ranges, the optimal measurement accuracy of the measured point within the corresponding range can be obtained.
This project requires a combination of hardware and software to implement this function. When we first use the ADC_IN11 channel mentioned earlier to measure voltages below 30V, if the measured voltage is within 0~3V, then we use the ADC_IN9 channel for measurement. At this time, due to the reduced voltage division ratio, the measurement accuracy is greatly improved. There are many ways to implement range switching; the development board design provides more design possibilities.
4. Current Sampling Circuit
This project uses a low-side current sampling circuit for current detection. When learning the common ground between the low-side of the sampling circuit and the development board's meter interface, please do not solder R0!!!

The design analysis
for this project involves a sampling current of 3A, and the selected sampling resistor (R0) is 100mΩ. The selection of the sampling resistor mainly needs to consider the following aspects:
the maximum value of the pre-designed measurement current;
the voltage difference caused by the 3A current sensing resistor in this project; and
the power dissipation of the current sensing resistor, which should generally not exceed 0.5V. A suitable package should be selected based on this parameter. Considering the power dissipation (temperature) issue under high current, a 1W metal wire-wound resistor package was chosen
. The voltage amplification factor across the current sensing resistor is also important. Since no operational amplifier is used to build the amplification circuit in this project, the factor is 1.
The current sensing resistor value can then be calculated using the above parameters
. Since no amplifier circuit is used, a larger sampling resistor is needed to obtain a higher measured voltage for measurement.
Considering that a larger resistor would result in a larger voltage drop and higher power consumption, an unlimited selection of a larger resistor is not feasible.
This project uses a 1W package resistor, corresponding to a power consumption of 1W.
Based on the above data, a 100mΩ current sensing resistor was selected. According to the formula, 3A * 100mΩ = 300mV, 900mW can be calculated.
To cope with different operating environments, especially high-current scenarios, the R0 resistor can be replaced with constantan wire or a shunt. The replacement can be selected according to the actual application scenario. For safety and educational purposes, this project will not discuss measurements exceeding 3A in detail, but the principle is the same.
5. Digital Tube Display
This project uses a digital tube as the display unit.

This project uses two 0.28-inch three-digit common-cathode LED displays as the display device. Compared to a display screen, LED displays offer better visibility in complex environments. The brightness of the LED displays can be increased by using smaller current-limiting resistors, depending on the specific needs of the application environment. Furthermore, LED displays have better mechanical properties and are not as easily damaged by external forces as display screens. They are widely used in industrial applications where stability and reliability are crucial. From a development board learning perspective, this makes it easier to learn electronic measurement principles and related development in a targeted manner.
In this project, actual testing showed that the current-limiting resistors (R1~R6) for the LED displays were configured to 300Ω. The corresponding brightness for both red and blue LED displays was good and the brightness was soft and not glaring.
Strictly speaking, the current-limiting resistors should be added to the segments; adding them to the digits would affect the display effect. Our actual design places them in the digits to save a few resistors, but the impact on the display is not significant. Therefore, we add them to the digits for convenience.
The

driving principle of LED displays mainly involves controlling the switching state of each segment of the LED display to display numbers, letters, or symbols. The following is a detailed explanation of the driving principle:
Basic Structure of a Digital Tube:
A digital tube typically consists of seven or eight LED segments (eight segments in this project). Each segment represents a part of the digital tube and can display numbers 0-9, letters AF, etc.
Digital tubes come in two types: common cathode and common anode. The difference lies in whether the common terminal COM (the end connecting all LEDs) is connected to the negative or positive terminal of the power supply.
Driving Methods:
Segment Selection: The desired number or character is displayed by controlling the on/off state of each segment of the digital tube. Each segment corresponds to a control signal; when the control signal is on, the segment lights up, and vice versa. (a, b, c, d, e, f, g, dp)
Bit Selection: The digital tube to be displayed is selected by controlling the bit lines of the digital tube. Bit line control sets the bit line of the digital tube to be displayed to a high level, and the bit lines of other digital tubes to a low level. By continuously switching the state of the bit lines, the display switching between multiple digital tubes can be achieved.
Driving Circuit:
The driving circuit for a digital tube can be implemented using hardware circuits, such as integrated circuits like digital signal processors (DSPs), microcontrollers (MCUs), or shift registers, to generate control signals suitable for the LEDs.
These control signals can be in the form of pulse width modulation (PWM) signals, serial data signals, etc. By controlling the frequency, width, and amplitude of these signals, the brightness of the digital tube can be controlled, thereby displaying the desired numbers or letters.
Software Control:
In addition to hardware driving circuits, the driving of digital tubes can also be implemented through software control. By programming to generate control signals suitable for the digital tubes, more flexible and complex display effects can be achieved, such as scrolling or alternating display of numbers.
Driving Common Cathode and Common Anode Digital Tubes:
For common cathode digital tubes, the common cathode pin is connected to the negative terminal of the power supply, and the control pin is connected to the output pin of the control chip. When a certain number needs to be displayed, the control chip outputs the corresponding encoded signal to the control pin, causing the corresponding LED segment to light up.
For common anode digital tubes, the working principle is similar to that of common cathode digital tubes, except that the common anode pin is connected to the positive terminal of the power supply, and the control pin is connected to the output pin of the control chip.
Encoded Display:
In order for the digital tube to display the corresponding numbers or characters, the segment data port must output the corresponding character encoding. For example, to display the number "0", the character code for a common anode seven-segment display is 11000000B (i.e., C0H), while the character code for a common cathode seven-segment display is 00111111B (i.e., 3FH). The specific code depends on the actual seven-segment display.
Dynamic and Static Display:
Seven-segment displays can use either static or dynamic display methods. In static display, each of the eight segments of each seven-segment display is connected to an 8-bit I/O port address. As long as the I/O port outputs a segment code, the corresponding character is displayed and remains unchanged. Dynamic display, on the other hand, lights up each segment of the seven-segment display one by one, achieving simultaneous visual display through rapid switching.
In summary, the driving principle of seven-segment displays is to control the switching state of each segment of the seven-segment display to display numbers, letters, or symbols, and to achieve display switching between multiple seven-segment displays through segment selection and digit selection. Furthermore, the driving of seven-segment displays can be implemented through hardware circuits or software control, and common cathode or common anode seven-segment displays can be selected as needed.
This project actually uses dynamic scanning display to drive the seven-segment display.
To estimate the current required for the digital tube display,
this project actually uses dynamic scanning to drive the digital tubes. Therefore, at any given time, only a maximum of 8 segments of the digital tube (or LEDs) can be lit, or in other words, only one digit can be lit. According to the design, the required driving current is approximately 11mA, which is the high-level voltage of the I/O port: 3.3V ÷ 300Ω.
At this point, it is important to ensure that the selected MCU has sufficient current-source/current-sinking capability.


Analysis of the datasheet shows that the CW32 has no issues. (Some chips do not work.)
6. LED Indicators
This project additionally designed a power indicator and an I/O operation indicator.

LD_PWR is the power operation indicator

. Since the chip's I/O often has a greater current sinking capability than a current pulling capability, LED1 is designed to be active low (on).
To reduce the current consumption of the LED, some LED brightness is sacrificed, the number of component parameters is reduced, and the current-limiting resistor for the LED is selected as 10K.
7. Button Circuit Design

There are various design methods for the button control circuit. Thanks to the fact that the CW32's I/O port can be configured with pull-up and pull-down resistors internally, the button control circuit on the outside of the chip does not need to be configured. One end of the button is connected to the MCU's I/O, and the other end is grounded. When the button is pressed, the I/O is pulled low.
8. TL431 Circuit Design for Voltage Measurement and Calibration:
This project adds an extra TL431 circuit to provide a 2.5V reference voltage. This can be used to provide an external voltage reference for the chip to calibrate the AD converter. From a product design perspective, due to the inherent ADC performance advantages of the CW32, this circuit is not necessary. This circuit is designed on the development board to learn the relevant application principles.

The TL431 is a relatively "old" device, a classic, and widely used one, still found in many electronic products.
Many beginners may be encountering this device for the first time, so we will briefly explain its principles to help everyone better apply the TL431.
TI defines it as a "Precision Programmable Reference." On the first page of the references, we can focus on several key characteristics.
Precision: Precision indicates that its output voltage is very accurate. I used a ±0.5% accuracy TL431, which measured 2.495V on the board at room temperature. Compared to common Zener diodes, the accuracy is vastly different. In the application circuit diagram, the TL431 is represented by a Zener diode symbol.
Adjustable Output Voltage: The adjustable output voltage is between Vref and 36V. In our project, we use the output Vref voltage, which is approximately 2.5V. Therefore, we use 2.5V in the description, which is approximately equal to Vref.
Sinking Current Capability: This refers to how much current the output voltage pin can provide. This is greatly influenced by the resistance value (R13) in the application circuit. It should not be less than 1mA. If there is no need for sinking current, do not design the current to be too high, as this will cause unnecessary power consumption.
This project designs a voltage and current meter, which mainly uses the CW32F030C8T6 processor as the core device to measure voltage and current. The entire process uses potentiometers to simulate voltage and current, and the voltage and current values can be directly measured and displayed through two three-digit LED displays.
Project Overview:
This project designs a voltmeter and ammeter, primarily using the CW32F030C8T6 processor as the core component to measure voltage and current. A 12-bit high-precision ADC ensures data accuracy. The entire process uses potentiometers to simulate voltage and current, directly measuring the voltage and current values. The results are displayed on two 3-digit LED displays, and can be compared with multimeter measurements. Three buttons (K1, K2, K3) are provided for calibration, achieving higher measurement accuracy.
Project Functionality
: This design is based on the CW32F030C8T6 development board. Potentiometers simulate voltage and current, enabling voltage and current measurements. The CW32 processor's internal high-precision 12-bit ADC processes the acquired data, which is then displayed on two 3-digit LED displays. The design also includes K1, K2, and K3 buttons for calibration, ensuring accurate voltage and current measurements. This design provides excellent guidance for beginners.
Project Parameters
: This section allows you to describe the relevant functional parameters of the project. Example:
This design uses a 12-bit ADC data acquisition function to ensure the accuracy of voltage and current meter data.
The CW32 microcontroller has built-in 1.5V and 2.5V reference voltages, providing highly accurate reference voltages.
A multimeter measurement port is provided, allowing for comparison and correction of multimeter measurements with circuit measurements, improving measurement accuracy.
A median filtering algorithm is applied to the acquired data, resulting in stable data display.
Principle Analysis (Hardware Description):
LDO Power Supply Circuit:
This project uses an LDO as the power supply. Considering that most voltage meter products are used in industrial scenarios with 24V or 36V power supplies, this project selected the SE8550K2, which has a maximum input voltage of up to 40V, as the power supply. The main reason for not using a DC-DC step-down circuit to handle large voltage differences is to avoid introducing DC-DC ripple interference during the design process; a secondary reason is to reduce project costs. In this project, two 0.28-inch three-digit

common-cathode LED displays
were used as the display devices. Compared to displays, LEDs offer better visibility in complex environments. The brightness of the LEDs can be increased by using smaller current-limiting resistors to meet the specific needs of the application environment. Furthermore, LEDs have better mechanical properties and are less susceptible to damage from external forces than displays. They are commonly used in industrial applications requiring stability and reliability. From a development board learning perspective, this approach facilitates targeted learning of electronic measurement principles.
In this project, actual testing showed that configuring the current-limiting resistors (R1~R6) of the LEDs to 300Ω resulted in good visibility for both red and blue LEDs, with a soft and non-glaring brightness.

The GPIO pin LED circuit
connects the positive terminal of LED1 to the positive power supply via current-limiting resistor R10, and the negative terminal of LED1 to the microcontroller's GPIO port. Based on the LED driving principle, LED1 can be lit simply by configuring the corresponding GPIO (PC13) to a low level.
The button control
circuit can be designed in various ways. Thanks to the CW32's internal I/O ports which can be configured with pull-up and pull-down resistors, the button control circuit on the outside of the chip does not require configuration. One end of the button is connected to the MCU's I/O, and the other end is grounded. When the button is pressed, the I/O is pulled low.

Software code
GPIO initialization:
Since clock configuration has been explained in previous chapters, it will not be repeated here. We will directly initialize the port. The initialization code is slightly different from the GPIO output configuration described above.
void KEY_Configuration(void)
{
__RCC_GPIOB_CLK_ENABLE();//Turn on the GPIOB clock, PB14 controls the button input
GPIO_InitTypeDef GPIO_InitStruct;
GPIO_InitStruct.Pins = GPIO_PIN_14;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT_PULLUP; //PB14 defaults to high level when there is no input
GPIO_InitStruct.IT = GPIO_IT_NONE;
GPIO_Init(CW_GPIOB, &GPIO_InitStruct);
}
void LED_Configuration(void)
{
__RCC_GPIOC_CLK_ENABLE();//Turn on the GPIOC clock, PC13 controls the LED on/off
GPIO_InitTypeDef GPIO_InitStruct;
GPIO_InitStruct.Pins = GPIO_PIN_13;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.IT = GPIO_IT_NONE;
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
GPIO_Init(CW_GPIOC, &GPIO_InitStruct);
}
Digital tube display code
/ Common cathode digital tube encoding table:
0x3f 0x06 0x5b 0x4f 0x66 0x6d 0x7d 0x07 0x7f 0x6f
0 1 2 3 4 5 6 7 8 9
0xbf 0x86 0xdb 0xcf 0xe6 0xed 0xfd 0x87 0xff 0xef
0. 1. 2. 3. 4. 5. 6. 7. 8. 9. /
//0x3f, 0011 1111; 0x5b 0101 1011
uint8_t Seg_Table[20] = {0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f,
0xbf, 0x86, 0xdb, 0xcf, 0xe6, 0xed, 0xfd, 0x87, 0xff, 0xef};
void Seg_Configuration(void) //Find the schematic diagram to initialize the relevant pins of the digital tube
{
__RCC_GPIOA_CLK_ENABLE(); // Enables the clock for GPIOA
__RCC_GPIOB_CLK_ENABLE(); // Enables the clock for GPIOB
GPIO_InitTypeDef GPIO_InitStruct;
GPIO_InitStruct.Pins = GPIO_PIN_2 | GPIO_PIN_0 | GPIO_PIN_4 | GPIO_PIN_6 | GPIO_PIN_7 | GPIO_PIN_1 | GPIO_PIN_3 | GPIO_PIN_5 | GPIO_PIN_8 | GPIO_PIN_11 | GPIO_PIN_12 | GPIO_PIN_15;
//A:PA02;B:PA00;C:PA04;D:PA06;E:PA07;F:PA01;G:PA03;DP:PA05;
//COM1:PA08;COM2:PA11;COM3:PA12;COM4:PA15;COM5:PB03;COM6:PB04;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.IT = GPIO_IT_NONE;
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
GPIO_Init(CW_GPIOA, &GPIO_InitStruct);
GPIO_InitStruct.Pins = GPIO_PIN_3 | GPIO_PIN_4; //COM5:PB03;COM6:PB04
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.IT = GPIO_IT_NONE;
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
GPIO_Init(CW_GPIOB, &GPIO_InitStruct);
}
Mean Filtering Algorithm:
Mean filtering, also known as linear filtering, primarily uses the neighborhood averaging method. The basic principle of linear filtering is to replace the pixel values in the original image with the mean. That is, for the current pixel (x, y) to be processed, a template is selected, composed of several of its nearest neighbors. The mean of all pixels in the template is calculated, and this mean is assigned to the current pixel (x, y) as the gray level g(x, y) of the processed image at that point, i.e., g(x, y) = ∑f(x, y)/m, where m is the total number of pixels in the template, including the current pixel.
This is a method used in digital image processing, but it can also be applied to the ADC sampling data of our digital voltage and current meters. We select twenty ADC sampling values and store them in the array Volt_Buffer. Then, we remove the maximum and minimum values from the array and take the average. The resulting value is displayed on the digital tube, thus obtaining more accurate and less volatile data.
uint32_t Mean_Value_Filter(uint16_t *value, uint32_t size) // Mean filter
{
uint32_t sum = 0;
uint16_t max = 0;
uint16_t min = 0xffff;
int i;
for(i = 0; i < size; i++) // Traverse the array to find the maximum and minimum values
{
sum += value[i];
if(value[i] > max)
{
max = value[i];
}
if(value[i] < min)
{
min = value[i];
}
}
sum -= max + min; // Subtract the maximum and minimum values and then calculate the average
sum = sum / (size - 2);
return sum;
}
Note:
When measuring current, R0 should not be connected to the circuit.
The circuit at the resistance measurement point uses Kelvin connection to improve measurement accuracy .
A potentiometer is used to simulate the voltage and current measurement object, and it is not necessary to actually connect it to the external circuit.
Physical diagram shows
the physical diagram.

Actual product image.png
Download BOM_CW32 Voltage and Current Meter.xlsx
Circuit Board Introduction 1.mp4
Voltage and current measurement demonstration.mp4
Experiment 9: Digital Voltmeter and Ammeter with Calibration Function.rar
PDF_Voltage and Current Meters.zip
Altium_voltmeter_currentmeter.zip
PADS_Voltage and Current Meter.zip
BOM_Voltage and Current Meter.xlsx
92744
ammeter and voltmeter
Voltage and current meter based on CW32F030
This project is a replica of the CW32 development board training camp project from LCSC. This was my first experience with LCSC's 3D printing and panel services. I also quickly learned how to draw panels using SolidWorks and LCSC EDA in a week. I feel that learning with a goal in mind is much more efficient. The specific selection and CW32 programming are covered in the official documentation, so I won't go into detail here. I'll mainly talk about what's not in the official documentation.
The CW32 official documentation
explains
that the code uses a 1ms timer to refresh the digital tube periodically, and
the buttons use CW32's hardware debouncing and interrupts.
Hardware debounce core code
NVIC_EnableIRQ(GPIOB_IRQn);
GPIO_InitTypeDef gpio_initStruct;
gpio_initStruct.IT = GPIO_IT_FALLING;
gpio_initStruct.Mode = GPIO_MODE_INPUT_PULLUP;
gpio_initStruct.Pins = GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14;
gpio_initStruct.Speed = GPIO_SPEED_LOW;
GPIO_Init(CW_GPIOB, &gpio_initStruct);
GPIO_ConfigFilter(CW_GPIOB, GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14, (GPIO_FLTCLK_RC10K);
Use mean filtering and two-point voltage calibration to calibrate the ADC value.
Automatic switching between high and low ranges: greater than 4.8V switches to high range, less than 4.6V switches to low range. Calibration method:
Voltage calibration
: Press buttons 1 and 2 simultaneously to enter calibration mode. Press button 1 to switch the voltage and current to be calibrated. Insert the jumper cap, use a multimeter to measure the three round holes, adjust the adjustable resistor to 5V, and press the third button to complete one calibration. Similarly, perform 11V calibration.

Current calibration:
Insert a multimeter into holes 1 and
2, and connect the external current to be measured into holes 4 and 3. Adjust the current to 0.5A, and press the third button to complete one calibration. Similarly, perform 1.5A calibration.
Calibration and basic operations are demonstrated in the attached video.

Assembly method
: Use a countersunk head self-tapping M3*8.0 screw-in from the back of the panel to fix it.
The attached file includes the Solidworks assembly file and the exported STL 3D printing order file.

The following issues were noted:
The TL431's pinout was reversed, preventing the use of an external reference voltage. [Fixed]
The current sampling resistor lacked copper plating, resulting in insufficient current. [Fixed] The
copper plating method was not selected as fill, but rather the default divergent method, which may burn out under high current. [Fixed]
The Type-C port from the 3D casing appears to be unused; if Type-C power is needed, it's better to directly plug it into the core board.
The panel's slot size lacked sufficient margin, requiring manual enlargement. [Fixed]
The 3D casing's DC power connector slot size lacked sufficient margin. [Fixed]
Shell Assembly.SLDASM
Front shell .SLDPRT
Back cover .SLDPRT
Shell Assembly - Front Shell - Front Shell - 1.STL
Shell Assembly - Front Shell - Rear Shell - 1.STL
Demo video.mp4
3D_PCB1_2024-08-08.SLDPRT
cw32Metre.7z
PDF_Ammeter and Voltmeter.zip
Altium_current_voltmeter.zip
PADS_Ammeter and Voltage Meter.zip
BOM_CurrentVoltage Meter.xlsx
92745
CW32 Voltage and Current Meter
A current and voltage meter designed based on the CW32 microcontroller development board.
1. Input/
output interfaces: Type-C and XT30 interfaces are used.

2. Power supply
: LDO (SE8550K2) is used to regulate the power supply to 5V, supporting a maximum input of 35V.

3. Voltage measurement:
Resistor voltage divider is used, followed by ADC sampling.

4. Current measurement
: INA199 amplifies the voltage across the sampling resistor and supports bidirectional current.

5. PD spoofing:
FUSB302 is used for PD spoofing, communicating via I2C

. 6. Display:
0.96-inch OELID screen displays voltage, current, power, etc.

7. Actual product image .
Demo video.mp4
PDF_CW32 Voltage and Current Meter.zip
Altium_CW32 voltage and current meter.zip
PADS_CW32 Voltage and Current Meter.zip
BOM_CW32 Voltage and Current Meter.xlsx
92746
Voltmeter and Ammeter
Design and fabrication of a voltage and current meter using the JLCPCB CW32 development board.
1. Function Introduction
This project uses the JLCPCB CW32 development board to design and fabricate a voltage and current meter. Currently, it can
measure voltage, current, capacitance, and resistance with high accuracy.
2. Schematic Diagram Description
2.1 Power Supply Circuit
Considering the portability and ease of use of the voltage and current meter, a USB + lithium battery power supply scheme is adopted. When the USB socket is plugged in, the system is powered by the USB and charges the lithium battery; when the socket is unplugged, the entire power supply is provided by a single 18650 lithium battery.

2.2 Automatic Switching of Power Supply Circuit
The key to achieving automatic switching of the power supply circuit lies in the use of a PNP MOSFET. When the MOSFET's voltage is Vgs0, it is cut off, and the lithium battery does not supply power. When only the lithium battery is supplying power, point G is grounded, and the voltage is 0V.
2.3 5V Boost Circuit
Although lithium battery power is convenient, the battery voltage cannot reach 5V, and it will further decrease with use. Therefore, a boost chip is needed to boost the voltage to 5V. The boost converter chip used in this project is the X4310 from Chipstar. This chip has a fixed output of 5V when the input is 2.7~5V, and it also has current limiting protection—when the output current exceeds 300mA, the chip will limit the current to 300mA, ensuring the safety of the entire system.

2.4 Lithium Battery Charging and Discharging Management Circuit
Regarding the lithium battery charging and discharging circuit, the commonly used TP4054 charging and discharging management chip was used. It has a maximum charging current of 500mA, which can be adjusted by changing the resistor. During charging, pin 1 of the chip is grounded, and the LED lights up. When the battery is fully charged, pin 1 switches to a high state, and the LED turns off. The battery charging status can be determined by the LED's on/off state.

2.5 Display Circuit:
The display circuit uses a 0.96-inch OLED screen. This screen communicates via I2C, requiring only 4 pins to achieve real-time data display, significantly reducing I/O resource usage.

2.6 Key Control Circuit:
Key recognition in this project uses an interrupt-driven approach. A 100nF capacitor is added around each key for filtering and debouncing. Verification has shown that this method provides high accuracy in key detection, preventing issues like unresponsive keys or double-clicks when a single key is pressed.

2.7 Current and Voltage Sampling Circuit:
The voltage sampling circuit uses a 1% accuracy voltage divider resistor to divide the voltage before it enters the MCU's ADC acquisition port. Diodes D3 and D5 limit the voltage here, preventing high voltage from entering the acquisition port and damaging the MCU. During voltage sampling, the voltage is first attenuated by 21 times before being acquired by the MCU's ADC pin and compared with an internal reference voltage. The output voltage value is then determined (if the output is less than 3V, a 2x attenuation channel is switched for re-conversion to improve measurement accuracy). The internal reference voltage is selected as 1.5V; the current sampling is similar, except that the resistor in the voltage attenuation circuit is replaced with a 100mΩ sampling resistor, and the circuit current is obtained by reading the voltage of the sampling resistor using an ADC.
2.8 Resistance and Capacitance Measurement
This resistance and capacitance measurement utilizes the principle of NE555 square wave generation. First, the capacitor and resistor to be measured are connected to the NE555 circuit, causing the NE555 circuit to output PWM waves of different frequencies. Then, the PWM waveform frequency is captured using the CW32 input capture function. Finally, the values of the resistor and capacitor to be measured are calculated. The specific calculation steps are as follows:

The above figure shows the wiring diagram when the NE555 generates a square wave. The formula for calculating the frequency and duty cycle of the square wave is as follows (period: T, frequency F, duty cycle: D):

Therefore, to measure capacitor C1, it is only necessary to control R1 and R2 to constant values and calculate according to the PWM frequency F captured by the MUC. The formula is: C1=1.44/(R1+2*R2)*F).
Similarly, the value of resistor R2 can be calculated using the formula: R2=1.44/(2*F*C1)-R1/2.
3. Physical Diagram
4. PCB Design Notes
In the PCB design, the power supply traces should be thickened, and copper pours should be used for connection when necessary.

When designing the current testing circuit, considering that the path will pass through a maximum current of 3A, it is essential to use full-connection copper plating on the pads, and the copper width must be wide to prevent the PCB from overheating due to high current, which would affect measurement accuracy.

5. Key Program Descriptions
5.1 Button Recognition Interrupt Configuration

When initializing the IO port, it is necessary to configure the external interrupt trigger condition and then enable the external interrupt.
Interrupt Service Function:

In this project, all GPIO ports share one interrupt service function. The function determines which IO port to interrupt and updates the flag bit.
5.2 ADC Configuration

In ADC conversion, three ADC ports are required. Therefore, multi-channel conversion is necessary when configuring the ADC, and it is important to ensure that the corresponding ADC conversion channel is enabled.
5.3 Timer Configuration
Timers were used for both resistor and capacitor tests. The timer configuration is as follows:

Initially, one timer with two channels was used to complete the input capture, but it was found that the same timer input capture interrupt start flag only had one bit, which could not capture two PWM waves of different frequencies simultaneously.
Ultimately, two timers were used.
6. Material Purchase
In this project example, all materials can be purchased from LCSC Mall. LCSC Mall is recommended!
7. Assembly Instructions:
All resistors and capacitors in this project use 0603 packages. Beginners can easily replace them with plug-in packages to reduce soldering difficulty. The casing and PCB are fixed with 4 M3 screws. The 18650 lithium battery is placed inside the casing.
source code.zip
shell file.zip
video.mp4
PDF_Voltage and Current Meters.zip
Altium_voltmeter_currentmeter.zip
PADS_Voltage and Current Meter.zip
BOM_Voltage and Current Meter.xlsx
92747
CW32 Beginner's Guide to Voltage and Current Meters
Experience the functions and performance of the Diwenxing CW32 development board and design a voltage and current meter.

I. Design Background
I was pleased to learn about and become familiar with a domestically developed development board during the summer: the LCSC CW32F030C8T6 development board. My learning and practical focus was on a voltmeter and ammeter.

Digital voltmeters and ammeters combine ADC technology with circuit measurement principles, accurately converting analog voltage and current signals into digital displays for easy reading and analysis by electronic engineers. This device not only improves the accuracy and efficiency of circuit measurements but also helps engineers better understand circuit behavior, making it a powerful tool for electronic design and troubleshooting, and playing a crucial supporting role in the work of electronic engineers. In product applications, digital voltmeters ensure the accuracy and safety of circuit design, while also providing strong support for product quality control and subsequent maintenance.
An ADC (Analog-to-Digital Converter)
is an indispensable key component in electronic systems, converting continuous analog signals into digital signals, enabling digital processing and analysis. ADCs play a crucial role in signal conversion, measurement and data acquisition, control system input, and communication and signal processing. Their widespread application promotes the intelligent and precise control of electronic equipment in various industries and is one of the key factors driving modern technological progress.
II. Design Approach
Learning to design and build a digital voltmeter and ammeter is highly beneficial for improving personal professional skills. The digital voltmeter and ammeter project covers multiple aspects, including microcontroller circuit design and implementation, signal acquisition and processing circuit design, user interface development and optimization, and product appearance design. It integrates knowledge from multiple fields such as electronic technology, microcontroller programming, circuit design, and industrial design. This project has the following highlights:
It adopts a core board plus expansion board design concept and uses plug-in device design, making learning simpler and exploration more in-depth;
the core board uses the domestic Wuhan Xinyuan Semiconductor CW32 as the main controller, while also being compatible with other similar development boards; however, the CW32 has advantages in ADC sampling.
The project has a high degree of integration and strong practicality; after completion, it can be used as a desktop everyday instrument;
the project has abundant learning materials, including circuit design tutorials, PCB design, code programming learning, and training for engineers' debugging abilities. III. Hardware Design
1. Power Supply Circuit

This project uses an LDO as the power supply. Considering that most voltmeter products are used in industrial scenarios with 24V or 36V power supply, and the core circuit does not require high power consumption, this project selected the SE8550K2-HF with a maximum input voltage of up to 40V as the power supply. The SOT89 packaged chip provides better heat dissipation and can provide a maximum current of 250mA. In actual use, care should be taken not to exceed 40V.
A Schottky diode D1 is also added to the circuit to prevent reverse connection of the input voltage, and fuse resistors (R1/F1) are used for voltage division and current limiting. The electrolytic capacitors and ceramic capacitors of the LDO are designed in parallel in a front-to-back sequence. The electrolytic capacitors filter out low-frequency interference, while the ceramic capacitors filter out high-frequency interference. The combination of the two can make the circuit have a good filtering effect in both high-frequency and low-frequency regions.
2. Circuit Design Points and Specifications
When drawing the power supply circuit, whether it is the schematic diagram or the PCB, the following points should be noted:
Schematic Diagram Specifications: GND should be facing down and the power supply should be facing up. Do not have the ground facing up.
Capacitor Design: In both the schematic and PCB design, electrolytic capacitors are placed first, followed by ceramic capacitors.
Grounding Design: Single-point grounding; the ground of the current power supply is connected to the GND of the main electrolytic capacitor of the current power supply; the ground of the main electrolytic capacitors of each stage power supply is connected to the GND of the main electrolytic capacitor of the preceding stage power supply. The
digital tube display area in this circuit uses a small board for in-line connection. Other spare pins are also brought out. Upgrades are planned using a small LCD board. The measurement interface uses a model aircraft battery interface, slightly protruding from the outer frame for easy insertion.
3. Key Advantages of CW32 in this Project
: Wide operating temperature range: -40 ~ 105℃;
Wide operating voltage: 1.65V ~ 5.5V (STM32 only supports 3.3V systems)
; Strong anti-interference: HBM ESD 8KV; All ESD reliability reaches the highest international standard level (STM32 ESD 2KV);
Project Focus - Better ADC: 12-bit high-speed ADC, achieving ±1.0LSB INL 11.3ENOB;
Multiple Vref reference voltages... (STM32 only supports VDD=Vref);
Stable and reliable eFLASH technology. (Flash0 pending).

4. Voltage Sampling Circuit:

The voltage divider resistors in this project are designed to be 220K + 10K, therefore the voltage division ratio is 22:1 (ADC_IN11).
Considering the potential fluctuations in the measured power supply, a 10nF filter capacitor is connected in parallel with the low-side voltage divider resistor to improve measurement stability.
An additional voltage sampling circuit is also added. To achieve higher accuracy, multimeters are often equipped with multiple range settings. By adjusting these settings, the optimal measurement accuracy for the measured point within the corresponding range can be obtained. This project requires a combination of hardware and software to implement this function. When we first use the ADC_IN11 channel to measure voltages below 30V, if the measured voltage is within the range of 0~3V, we then use the ADC_IN9 channel for measurement. In this case, due to the reduced voltage division ratio, the measurement accuracy is significantly improved.
The voltage divider resistor selection
design considers the maximum value of the measured voltage. For safety reasons, this project uses 30V (the actual maximum can be 99.9V or 100V).
The ADC reference voltage is 1.5V in this project, which can be configured through the program.
To reduce power consumption in the sampling circuit, the low-side resistor (R7) is usually chosen as 10K based on experience.
The high-side resistance of the voltage divider resistor can then be calculated using the above parameters.
The required voltage division ratio is calculated, i.e., the ADC reference voltage. The design input voltage can be calculated using known parameters: 1.5V/30V = 0.05.
The high-side resistance is calculated as: low-side resistance/voltage division ratio. Using known parameters, 10K/0.05 = 200K.
A standard resistor is selected: a resistor slightly higher than the calculated value of 200K is chosen. We typically choose E24 series resistors; therefore, in this project, 220K, which is greater than 200K and closest to the calculated value, is selected.
If, in practical use, the voltage to be measured is lower than 2/3 of the module's design voltage (66V), the voltage divider resistor can be replaced and the program modified to improve measurement accuracy. An example is provided below:
Assuming the measured voltage is no higher than 24V, and other parameters remain unchanged
, calculations show 1.5V/24V = 0.0625, 10K/0.0625 = 160K. 160K is a standard E24 resistor and can be directly selected, or a higher value 180K can be chosen with some redundancy.
If, in practical use, the voltage to be measured is higher than the module's 99V design voltage, the voltage divider resistor can be replaced or the reference voltage modified to achieve a larger voltage measurement range. An example is provided below:
Assuming the measured voltage is 160V, the solution is to increase the voltage reference to expand the measurement range.
Given that the voltage division ratio of the selected resistor is 0.0145, we can calculate 160V * 0.0145 = 2.32V by reverse calculation using the formula. Therefore, we can choose a 2.5V voltage reference to increase the measurement range (increasing the measurement range will reduce accuracy).
5. Current Sampling Circuit
This project uses a low-side current sampling circuit for current detection. The low-side of the sampling circuit is designed to share a common ground with the meter interface on the development board. Therefore, do not solder the sampling resistor R10 during the internal calibration test of the meter! Solder it onto the PCB only after the test is completed and it is used in actual applications.

The sampling current designed for this project is 3A, and the selected sampling resistor (R0) is 100mΩ.
The design analysis and
selection of the sampling resistor mainly considers the following aspects:
the maximum value of the pre-designed measurement current;
the voltage difference caused by the 3A current sensing resistor in this project;
and the power consumption of the current sensing resistor, which should generally not exceed 0.5V. A suitable package should be selected based on this parameter. Considering the power consumption (temperature) issue under high current, a 1W packaged metal wire-wound resistor was selected
. The voltage amplification factor across the current sensing resistor: no operational amplifier is used in this project, so the factor is 1. The current
sensing resistance value can then be calculated using the above parameters. Selection:
Since no amplifier circuit is used in this project, a larger sampling resistor is needed to obtain a higher measured voltage for measurement. However, considering that a larger resistor will result in a larger voltage difference and higher power consumption, a larger resistor cannot be selected without limit. A 1W packaged resistor was selected in this project, corresponding to a power consumption rise of 1W.
Based on the above data, this project selected a 100mΩ current-sensing resistor. According to the formula, 3A * 100mΩ = 300mV, 900mW.
To handle different operating environments, especially high-current scenarios, the R0 resistor can be replaced with constantan wire or a shunt. The choice of alternative can be based on the specific application scenario. For safety and educational purposes, this project will not discuss measurements exceeding 3A, but the principle remains the same.
6. Digital Tube Display:
This project uses two 0.28-inch three-digit common-cathode digital tubes as display devices. Compared to displays, digital tubes offer better visibility in complex environments. Depending on the specific needs of the operating environment, smaller current-limiting resistors can be used to achieve higher brightness. Furthermore, digital tubes have better mechanical