DAC in STM32 || Sine wave || HAL || CubeIDE

preview_player
Показать описание
________________________________________________________________________________________

How to use DAC (Digital to analogue converter) in STM32 using CubeIDE.
Also, generate the Sine wave using DAC with STM32.

________________________________________________________________________________________

******* SUPPORT US BY DONATING******

*******Join the Membership*******

Рекомендации по теме
Комментарии
Автор

The MAX freq of sine wave depends on the trigger frequency and the number of samples.
Let's say the HCLK is 150 MHz, and so is the timer frequency
If you keep the prescalar 0, and use ARR as 10-1, this means the trigger frequency from the timer will be 15 MHz
Now if you use 15 samples in the sine wave, you can generate the sine wave of 1 MHz
150 samples = 100 KHz
1500 samples = 10KHz

And so on

ControllersTech
Автор

Finally. Information on WHY you write the code this way instead of simply what the code is. Well done.

lawrencestark
Автор

Thank you! I really needed to know about the HAL_DAC_Start existence.

pedrojanini
Автор

Thank you very much! I got it working!
Chose to go with a uint16_t array and using Half Word's instead of Word's for Data Width at 8:41, since the DAC has 12-bit or 8-bit modes and I wanted to save memory. I needed to cast my uint16_t array to uint32_t to make the compiler stop throwing a warning. I'd though the function would expect a uint16_t array instead of a uint32_t array once you change the 8:41 Data Width parameter, but apparently not.
Thanks for the "-1" tip at 9:20 and Content Assist Template Proposal (Ctrl+Space) demos throughout (eg, at 12:03);

drewh
Автор

Good explanation, thank you very much. It is exactly what i want :))

fatihokuyucu
Автор

Thanks so much for the knowledge, I managed to get the stm32 to generate a sine wave with a frequency value = 60hz

martinpalomino
Автор

nice done.
You can use the symetry of sinus function to save some memory. Values in second half are equal to negative value of first half. (sin (x+180) = -sin(x).
Values in first and second and values in third and fourth quorter are symetrical around x=90 and x=270 degrees. sin (x+90) = sin(90-x)

aleksnbg
Автор

hii Nice tutorial, Good explanation, thank you very much. It is exactly what i want in my project

kallehallden
Автор

No need to enable Tim2 global interrupt,
thank you for the good explanation

TheDadi
Автор

hi any ideas about maximum frequency of a smooth sinewave using this dac unit?

mohammadrahimpoor
Автор

Nice tutorial.
Do you know how can I show the wave on labview?

hectoreliucaballerodimas
Автор

Regarding the timer setting and frequency expected, my TIM6 clock speed (APB1 bus) shows 64Mhz. So, for a Timer event to trigger the dma every 8khz, I set the prescaler to 0, and TIM_ARR = (64M/8k)-1.


However, with the DMA pointing to a 2 sample buffer (0 and 0xFFF), what I see on the scope is a square wave at 4khz with a 50% duty cycle!! Considering the Stm32h7's has a maximum DAC sampling rate of 18.18Msps, what I *expected* was that every 8khz the timer would cause 2 samples to get transferred from the memory buffer to the DAC peripheral, and therefore the scope should show it briefly at 0V, but most of the time it would be idle at 3.3V while it waits for the next timer event... yet this is not the case, why?? Instead it's acting as if only one sample is transferred every timer event, despite:

HAL_DAC_Start_DMA ( &hdac1, DAC_CHANNEL_1, pBuffer, *LENGTH_2*, DAC_ALIGN_12B_R);

bennguyen
Автор

how to generate noise sinewave and low pass filter to filter out the harmonics and getting pure sine wave by stm cubemx

ratulchowdhury
Автор

hi. can it be made like RF generator say till 10 mhz or so, and with encoder changing frequency with 1khz steps?

modellerdesign
Автор

hello, using this method, ho I can generate the two sinewave on DAC1 & DAC2 Simultaneously ?

kallehallden
Автор

I have an stm32G474. I tried this example and I can see that the DOR register is getting new values but the DAC doesnt output any values. Any reason why this can happen?

jayakrishnanharikumaran
Автор

I did everything like in your tutorial.
However, I'm getting a DAC/DMA underrun error immediatelly after I start the tranfer. Do you know what might be the issue? Thanks!

oleksandrleskiv
Автор

how to you remove the dc component ? are you using capacitor in the output ?

di
Автор

Hi Sir,

Thanks for video

I followed the same as mentioned . i am using stm32f407vg discovery board . but i am getting
DMA underrun error condition occurred for DAC channel2 (the currently selected trigger is
driving DAC channel2 conversion at a frequency higher than the DMA service capability rate). i reduced the timer counter frequency to 500KHz but still facing same error..

can you guide ur suggestion

nsanandkumarak
Автор

Thanks for this project. Please do complete sinewave hbridge inverter with lcd and menu keypad to set all parameters.using stm32f

adesuyisunday