Skip to main content
Graduate
May 14, 2025
Solved

STM32F446RET6 DAC to generate "an ideal square wave"

  • May 14, 2025
  • 3 replies
  • 1322 views

Hi,

 

I want to generate a bipolar square wave with a pulse width of 100us per phase using the DAC in STM32F446RET6. 

 

Junzhe_2-1747249767726.png

 

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

 

    This topic has been closed for replies.
    Best answer by Michal Dudka

    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.

    3 replies

    Technical Moderator
    May 14, 2025

    Hello @Junzhe and welcome to the ST community,

    According to the datasheet, there is a tSETTTLING parameter: typical 3us / max 6us with the respect of the load characteritics (Buffer ON) as the following:

    mALLEm_0-1747251521386.png

    So "an ideal square wave" is something not reachable.

    Super User
    May 14, 2025

    Hmm,

    if the diagram is to scale and the timing okay, the edges look much wider than 6µs. So the load may be to high.

    hth

    KnarfB

    JunzheAuthor
    Graduate
    May 14, 2025

    Hi KnarfB,

     

    I did not put a load on the output of the DAC. I connected it directly to the Powerlab for the measurement.

     

    Best,

    Junzhe

    Super User
    May 14, 2025

    Hi,

    For a "perfect" square wave just use a timer, to put out any kind of square wave, pwm or 50:50 square.

    The DAC is better for everything else than a square wave. 

    JunzheAuthor
    Graduate
    May 14, 2025

    Hi AScha.3,

     

    Because I need the output of the DAC to drive other components. It's not just about generating a square wave. The DAC can output the value I want between 0-3.3V, but the Timer doesn't seem to be able to achieve this function?

     

    Best,

    Junzhe

     

    Graduate II
    May 14, 2025

    a) DAC with onboard buffer has slew rate about 2V/us (with negligible capacitive load).

    b) Clarify how did you made your "scope trace" - it looks distorted

    c) Consider using external buffer, then your rising and falling times can be up to ten times shorter (can be seen on following scope trace)

    d) If you need realy sharp edges, consider using another method. Like DAC + analog switch etc.

    step2.png
    Blue trace - Output directly from DAC (on board buffer) 
    Yellow trace - output by external buffer (LMH6612 there)

    There is also appnote:
    https://www.st.com/resource/en/application_note/dm00129215.pdf

    JunzheAuthor
    Graduate
    May 14, 2025

    Hi Michal,

     

    Thank you for your reply and plot. I measured the output of the DAC through Powerlab, which is similar to an oscilloscope. I connected the output of the DAC directly to it for measurement. I use the built-in buffer of the DAC in the STM32, but can't it make the output waveform as sharp as possible? If I use an additional external buffer, do I need to disable the built-in buffer?

     

    Best,

    Junzhe

    Graduate II
    May 15, 2025

    What is your powerlab (DAQ ?) specs ? In other words, does it have enought bandwidth and sampling frequency to capture microseconds rise times ? It looks like the DAC is fast as it should be and you're just observing it wrong.