This project uses the LCSC CW32F030C8T6 development board. Detailed tutorials and materials are available on the LCSC development board website, including the "CW32 Digital Voltmeter and Ammeter Training Camp Project Tutorial Document." This project is
a complete replica of the training camp project, with no changes to the circuitry or code.
Digital Voltmeter and Ammeter with Calibration Function
1. Concept of
Calibration Calibration is the process of compensating for instrument system errors by measuring the deviation of a standard, thereby improving the accuracy and precision of the instrument or system. To improve the measurement accuracy and precision of the voltmeter and ammeter, calibration is required.
The common calibration principle is as follows:
Assume a sampling system where the AD section can obtain digital quantities, corresponding to physical quantities such as voltage (or current).
If an AD value point Xmin is calibrated at the "zero point" and an AD value point Xmax is calibrated at the "maximum point", according to the principle that "two points form a straight line", a straight line connecting the zero point and the maximum point can be obtained. The slope k of this line is easy to find. Then, by applying the equation of the straight line to solve for each point X (AD sample value), the physical quantity (voltage value) corresponding to the AD value can be obtained:

The slope k in the figure above is:
k = (Ymax - Ymin) / (Xmax - Xmin)
(because the first point is the "zero point", Ymin = 0 above).
Therefore, the physical quantity corresponding to the AD value at any point in the figure above is:
y = k × (Xad - Xmin) + 0.
The above algorithm only performs calibration between the "zero point" and the "maximum point". If the intermediate AD sample value is used, it will bring a large error in the corresponding physical quantity. The solution is to insert more calibration points.
As shown in the figure below, four calibration points (x1, y1), (x2, y2), (x3, y3), and (x4, y4) are inserted respectively.

This results in a line that is no longer a straight line, but a "reflected line" (equivalent to segmented processing). To find the voltage value corresponding to a point Xad between x1 and x2:
y = k × (Xad – X1) + y1.
It can be seen that the more calibration points inserted, the higher the accuracy of the physical value.
In voltage and current meter measurements, a "voltage and current calibration board" or "multimeter" can be used to calibrate the collected voltage and current. The more calibration points, the more accurate the measurement.
2. The project code file is as follows:
Link: https://pan.baidu.com/s/12OWqnW4XG8EGxlk9wCQoqw?pwd=LCKF Extraction code: LCKF.
The reference example uses 3 calibration points. The voltage calibration points are 0V, 5V, and 15V. The current calibration points are 0A, 0.5A, and 1.5A.
3. Calibration Operation Method for this Experiment
This example uses button operation for calibration. The specific operation method is as follows:
Define 5 working modes. The K1 key is used to switch the display mode. The K2 key sets the parameter value for the corresponding mode and saves it to FLASH. The K3 key returns to mode 0.
Mode 0: Displays normal voltage and current values (the upper row of the digital tube displays the voltage value *.V or .*V automatically, the lower row displays the current value _.**A).
Mode 1: 5V voltage calibration value setting. The upper row of the digital tube displays 5.05. The lower row displays the current voltage value _.V or ._V. In this mode, the multimeter should be set to 5.00V to measure the measured bit. After pressing the K2 key, the current value is calibrated as a 5V voltage value.
Mode 2: 15V voltage calibration value setting. The upper row of the digital tube displays 5.15. The lower row displays the current voltage value _.V or ._V. In this mode, the multimeter should be set to 15.0V to measure the voltage of the measured part. After pressing the K2 key, the current value is calibrated to 15V.
Mode 3: Current 0.5A calibration setting. The upper row of the digital display shows A.0.5. The lower row displays the current current value _.**A. After pressing the K2 key, the current value is calibrated to 0.5A.
Mode 4: Current 1.5A calibration setting. The upper row of the digital display shows A.1.5. The lower row displays the current current value *.**A. After pressing the K2 key, the current value is calibrated to 1.5A.