Trapezoidal Resistor DAC Using STM32G431

01 DAC Trapezoidal Resistor

1. Introduction

Yesterday, I tested the development toolchain for the STM32G431. Today, I plan to try some interesting experiments. I saw a friend share their R2R trapezoidal resistor DAC solution on Bilibili, and I became quite interested. Therefore, I decided to test the performance of the trapezoidal resistor DAC solution using ordinary 1k and 2k resistors.

Trapezoidal Resistor DAC Using STM32G431

2. Circuit Design

Based on yesterday’s circuit, I designed a test circuit. I removed the RST pin from the original six-pin debugging port, keeping only the two SWD lines and the serial communication line. I still used the 1117 for 3.3V voltage regulation. On the right side are 10 resistors, forming a 10-bit DAC output. Since I do not have high-precision resistors on hand, I will first test the effect of the 10-bit DAC. After obtaining some test data, I will improve the DAC’s accuracy when the high-precision resistors arrive. I made the test circuit board using a one-minute board-making method.

AD\Test\2024\March\R2RDACG431.SchDoc

Trapezoidal Resistor DAC Using STM32G431

▲ Figure 1.2.1 Test Circuit Schematic

Trapezoidal Resistor DAC Using STM32G431

▲ Figure 1.2.2 Test Circuit Board

After one minute, I obtained the test circuit board. It was very perfect. Next, I will solder it. I removed yesterday’s chip from the circuit board and soldered it onto this circuit board. Now, I will power it on for testing.Trapezoidal Resistor DAC Using STM32G431

Trapezoidal Resistor DAC Using STM32G431
Trapezoidal Resistor DAC Using STM32G431

3. Circuit Testing

I applied a 5V power supply to the circuit board. Since it is an old chip that was disassembled, the circuit has started working. I will now use probe clips to download the software to the microcontroller. Through testing, it was proven that during SWD programming, the G431 does not require the RESET pin. This allows for a more concise design of the debugging port.

Trapezoidal Resistor DAC Using STM32G431

According to the output resistors corresponding to the ports, I set these ports as output ports in CubeMX. I wrote a subroutine to change the high and low levels of the output ports based on the set DAC value.

Trapezoidal Resistor DAC Using STM32G431

Next, I will increment the output DAC values, and a sawtooth wave signal can be measured at the trapezoidal resistor output. Overall, the output sawtooth wave looks very nice, indicating that the DAC is working properly. However, there were slight fluctuations during the voltage rise, which also indicates that the output voltage signal has a significant error.

Trapezoidal Resistor DAC Using STM32G431

▲ Figure 1.3.1 Output Voltage Signal of the Slant Edge

The output is a sine wave. During the observation, I also noticed that there were some spikes in the output waveform. For example, here is a small spike, but there will actually be larger spikes. This should occur when modifying the output DAC pins, as they were not modified simultaneously. Therefore, the above spikes appeared. This situation should be improved through algorithms later.

Trapezoidal Resistor DAC Using STM32G431

Next, I will control the output DAC data, changing from 0 to 1023, and measure the change in output voltage. I will record 100 data points, and now let’s take a look at the specific measurement results. This result is surprising. Although it is generally linearly increasing, there is still a significant error between the linearity. The maximum error reached 28mV.

Trapezoidal Resistor DAC Using STM32G431

Trapezoidal Resistor DAC Using STM32G431

▲ Figure 1.3.2 Relationship Between Output DAC and Voltage

Trapezoidal Resistor DAC Using STM32G431

▲ Figure 1.3.3 Error Range

Conclusion

This article tested the R2R trapezoidal resistor DAC solution. Due to the use of ordinary resistors instead of high-precision resistors, the output voltage error reached 28mV. The overall linearity of the output is acceptable, and the output voltage range is from 0V to 3.3V.

Trapezoidal Resistor DAC Using STM32G431

Leave a Comment