2025-05-14 12:15 PM - last edited on 2025-05-14 12:43 PM by mƎALLEm
Hi,
I want to generate a bipolar square wave with a pulse width of 100us per phase using the DAC in STM32F446RET6.
But when I measured the DAC output (PA4), I found that the DAC output was not an ideal square wave, but a trapezoidal shape with a long rise time. However, according to the STM32F446RET6 manual, the DAC conversion time should be only a few microseconds. I used the DMA function and triggered the DAC output via Timer 6, but there was no improvement. How can I make the DAC output as perfect as possible?
Best,
Junzhe
Solved! Go to Solution.
2025-05-15 1:54 AM
Hi Michal,
You are correct. I previously set the sampling rate to 20KSPS, so the minimum unit was 50us, which resulted in insufficient precision. I now increased the sampling rate to 200KSPS. I got this result:
The time required for the DAC to change is about 40us, which is still longer than the theoretical time in the data sheet. But I looked at your results and found that the change time was about 1.256us when no buffer was used. I connected my PA4 pins directly with my PowerLab.
What other possible reasons could cause my results to be inaccurate?
Best,
Junzhe
2025-05-15 1:59 AM
Also attached is my TIMER6, DAC settings and code.
uint16_t square_wave[2] = {
1861, // 1.5V
1241 // 1.0V
};
HAL_DAC_Start_DMA(&hdac, DAC_CHANNEL_1, (uint32_t*)square_wave, 2, DAC_ALIGN_12B_R);
HAL_TIM_Base_Start(&htim6);
2025-05-15 2:05 AM
If you want to see real DAC output waveform you need to measure with something adequate to your situation. In best case with 200ksps you can "see" 5us rise/fall times. But your measurment device has also some bandwidth limit, which can limit slew rate of input signal (are you sure that bandwith of your DAQ is better then about 10MHz ?). And what is input capacity of DAQ and your cable connection from DAC ? Both these factors can fundamentally distort the measurement results. It seems you still have the same problem as at the beginning - you don't have the appropriate equipment, or method, to measure your DAC signal.
2025-05-15 4:18 AM
Hi Michal,
I replaced the Powerlab with an oscilloscope. You are right. From the oscilloscope, I can see that the rise time is only about 2.5us. Thank you very much for your analysis and answer!
Best,
Junzhe