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

Поделиться
HTML-код
  • Опубликовано: 11 сен 2024

Комментарии • 89

  • @ControllersTech
    @ControllersTech  3 года назад +5

    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

  • @lawrencestark4356
    @lawrencestark4356 4 года назад +4

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

  • @aleks1970nbg
    @aleks1970nbg 3 года назад +6

    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)

  • @pedrojanini2209
    @pedrojanini2209 3 года назад +4

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

  • @martinpalomino8627
    @martinpalomino8627 Год назад +1

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

  • @TheDadi4
    @TheDadi4 3 года назад +1

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

  • @drewh0208
    @drewh0208 3 года назад +1

    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);

  • @jayakrishnanharikumaran676
    @jayakrishnanharikumaran676 2 года назад +1

    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?

  • @fatihokuyucu5644
    @fatihokuyucu5644 3 года назад +1

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

  • @bennguyen1313
    @bennguyen1313 4 года назад +2

    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);

    • @ControllersTech
      @ControllersTech  4 года назад

      The frequency of the square wave will also depend on the number of samples that you are talking. In your case, 8KHz /2 = 4KHz.
      Why is it 3.3v ? Well that depends on what values you are feeding to the DAC

  • @eduardodelarosaferrer2205
    @eduardodelarosaferrer2205 4 года назад +1

    awesome as ever

  • @kallehallden8692
    @kallehallden8692 3 года назад

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

  • @fano72
    @fano72 Месяц назад

    I have an external DAC connected by I2S. Do I need a timer to get interrupt callback? Or will the I2S fire DMA interrupt if it wants data?

  • @electronic-ebox6403
    @electronic-ebox6403 3 месяца назад

    thats nice. i am trying to play tone with 22.05KHz sampling frequency. tone data is stored in internal flash. i successfully got sine wave of desired value but noit luck for tone playing. can you make video on this topic? thanks

  • @oleksandrleskiv
    @oleksandrleskiv 2 года назад

    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!

  • @GuadrianBM
    @GuadrianBM Месяц назад

    Hi I am working with STM32 H7 board. I want to get sine wave in two channels. I am can able to write date to two channels as a sine wave but the sine wave is not so smooth because i need sine wave of around some 10kHz max. But the sampling time is around some 50khz and it is varying. Can you help me with this?

  • @adesuyisunday4287
    @adesuyisunday4287 2 года назад

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

  • @modellerdesign
    @modellerdesign 2 года назад

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

  • @MrRonychakraborty
    @MrRonychakraborty 4 года назад +1

    Nice tutorial :)

  • @TheJamnikER
    @TheJamnikER 4 года назад

    Thanks for the video, very helpful

  • @di987654321
    @di987654321 Год назад

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

  • @kallehallden8692
    @kallehallden8692 3 года назад

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

  • @nonstradam
    @nonstradam 4 года назад

    very nice tutorial, thx

  • @daviddavido9204
    @daviddavido9204 4 года назад

    Thanks for the tutorial

  • @mohammadrahimpoor513
    @mohammadrahimpoor513 3 года назад

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

  • @nsanandkumarak
    @nsanandkumarak 2 года назад

    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

  • @ratulchowdhury7490
    @ratulchowdhury7490 3 года назад

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

  • @LL-ue3ek
    @LL-ue3ek Год назад +1

    good video. but the background music is very distracting.

  • @hectoreliucaballerodimas6752
    @hectoreliucaballerodimas6752 4 года назад

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

  • @phanendrabeella
    @phanendrabeella Год назад

    i need to generate sine wave with 5hz frequency for 1ma current at dac V-I board through spi communication ... could you please help me on this

  • @petrjanousek7613
    @petrjanousek7613 3 года назад

    NIce, thanks!

  • @RiccardoFranceschetto
    @RiccardoFranceschetto 3 года назад +1

    how to change amplitude?

    • @ControllersTech
      @ControllersTech  3 года назад +1

      Check my latest video on nextion display. I have used sine wave there too, along with variation in amplitude and frequency

  • @mohsenmazandarani7506
    @mohsenmazandarani7506 2 года назад

    Thank you

  • @CarlosFCosta-qw8uf
    @CarlosFCosta-qw8uf 3 года назад

    Many Thanks for the video. I would like to know if it is possible to count number of senoidal waves generate with a counter variable and after a certain number of sinusoidal waves I stop create the waves for a period and recreate again. For example: 58 pulses of senoidal wave and 2 pulses of zero volts. This will be used in a car signal injection for test.

    • @ControllersTech
      @ControllersTech  3 года назад

      Yeah you can.. just put a variable inside the function, and increment it after the sine wave has been generated..

  • @Red_Fang.
    @Red_Fang. Год назад

    Hello, i'm using F1 Blue pill Series, how to use pin as DAC? thank you

    • @ControllersTech
      @ControllersTech  Год назад

      Bluepill doesn't support DAC. You can use some external IC, but this tutorial won't work for it.

  • @seyedsajjadmirbakht5573
    @seyedsajjadmirbakht5573 2 года назад

    Thank you for your video, however, your Sine wave has negative cycles too, it is from -1.77V to 1.36V. But the result I receive is from 0 to 3.3V. Can you please help?

    • @ControllersTech
      @ControllersTech  2 года назад +1

      maybe your scope is set for the DC.. Check that..

  • @jimidjoriginal9295
    @jimidjoriginal9295 2 года назад

    I am literally using an F446RE like you and copy pasted your code and settings in Cube... i can't generate anything... nothing on the oscilloscope no mater what... maybe some help? if i try to operate the DAC in a standard value like the first example everything is working fine... *Edit: i created a new STM32 Project and did only the sine wave part and it worked just fine... WTF?! is CubeIDE bugged or something?

    • @ControllersTech
      @ControllersTech  2 года назад

      never use the code as it is. Always generate a new one. I delete few things while uploading the code. This is why there is a video, and there is the process.

  • @SageBoyyy
    @SageBoyyy 10 месяцев назад

    How we will control amplitude of sine wave ?

  • @The2Coolest2
    @The2Coolest2 3 года назад

    For me I can generate 100 Hz but 1kHz doesn't work :(. Voltage on pin drops to around 300mV... I have DS1054z scope..., and stm32f746zg. Using TIM6 with DMA.
    Edit: I was only able to generate a 1kHz frequency if I used 10 samples instead of 100. Where is my limit? What should I look for on datasheet? Or is it my scope? I doubt it

    • @ControllersTech
      @ControllersTech  3 года назад

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

    • @The2Coolest2
      @The2Coolest2 3 года назад

      @@ControllersTech Still does not work. For example, I have TIM6 at 16MHz. prescalar 0, ARR 10-1, so 1.6MHz. Then 160 samples gives 10kHz. On the oscilloscope, still 350mV reading, flat line no sine wave.

    • @ControllersTech
      @ControllersTech  3 года назад

      Don't know what's going wrong on your end. Have you enabled the update event in the timer ?
      Today I have tested all possible frequencies i could and the response was always as per the calculation.

    • @ControllersTech
      @ControllersTech  3 года назад

      Try using hsi clock

    • @brianarianpour4702
      @brianarianpour4702 6 месяцев назад

      I'm having a similar problem using the STM32F4o7G-DISC1 board. I can only generate up to 105kHz. The HCLK is 168MHz and the external crystal is 8MHz, and if I put ARR to 1 and Prescalar to 0, I only get 105kHz. I also tried changing the sample number (ns) in the equation, but it just changes the shape of the wave generated and maintains the same frequency. Any solutions?

  • @clouddev1136
    @clouddev1136 3 года назад

    Hello? How did you manage to pop up content assist in CubeIDE? Is there any way to do so without hitting ctrl+space? Thanks in advance.

  • @darkobul1
    @darkobul1 4 года назад +1

    What was max frequency you could generate sine wave?

    • @ControllersTech
      @ControllersTech  4 года назад +1

      Actually I haven't tested it. It depends on how many samples you are taking..

    • @omeranar8769
      @omeranar8769 4 года назад

      is it possible 1mhz sine wave

    • @ControllersTech
      @ControllersTech  4 года назад +1

      Yes it's possible if u are able to keep the timer frequency at 100 MHz and than use 100 samples, or 50 MHz and 50 samples. Remember that decreasing the number of samples will increase inaccuracy in the sine wave

    • @omeranar8769
      @omeranar8769 4 года назад

      @@ControllersTech thank you very much, i tried (CPU=180MHz, Timer=CPU/2=90MHz, ARR=9-1) = (10Mhz-100ns), (10MHz/(Sample=10))=1MHz sine wave and good quality, how can i increase power of that sine wave i need minimum 50mA output

    • @ControllersTech
      @ControllersTech  4 года назад +1

      I don't know about controlling current in this prospective..

  • @TheZeroomg
    @TheZeroomg 3 года назад

    Is it possible to dynamically change the sine wave pattern(its frequency, as modulated signal) using DMA?

    • @ControllersTech
      @ControllersTech  3 года назад +1

      Yeah why not. Just change the frequency and amplitude in the sine function

    • @TheZeroomg
      @TheZeroomg 3 года назад

      @@ControllersTech Thank you !

  • @widcoshop
    @widcoshop 3 года назад

    hi how are you?that great ..how can i generate a wave but concurrent that have negative and positive voltage?

    • @ControllersTech
      @ControllersTech  3 года назад

      Look at my nextion video on waveform. I have used the sine wave there too. Maybe that code can help you

  • @antoniomartos2343
    @antoniomartos2343 3 года назад

    Hi!!! I bought STM32L4-RB-P protoboard but in STM32Cube i don't have DAC option. Does this mean this nucleo board doesn't have that option?

    • @ControllersTech
      @ControllersTech  3 года назад

      Yup it doesn't support

    • @antoniomartos2343
      @antoniomartos2343 3 года назад

      @@ControllersTech Thanks. Can u recommend me a nucleo board for getting and FM signal ADC then demodulate it and then DAC?

    • @antoniomartos2343
      @antoniomartos2343 3 года назад

      I thought about nucleo-l476rg. Is this one good enough?

  • @widcoshop
    @widcoshop 4 года назад

    hii how are u?thank you its great..how can i generate a wave with Begin and end optional voltage and frequency that user choose it?

    • @ControllersTech
      @ControllersTech  4 года назад

      Just change the sinx to "a + sin(bx)". I hope you remember the graph of this function from your school days.. just kidding

    • @widcoshop
      @widcoshop 4 года назад

      Hhh funny..dont worry i remember but i wannt contro it with software and stm...bro why you didnt it? I can make it for you like iot

  • @ignaciozuniga7433
    @ignaciozuniga7433 4 года назад

    how can i make an oscilloscope using stm. Thanks

  • @arnaudromain8177
    @arnaudromain8177 4 года назад

    I only have one sine wave when I reset the code. After that, I have a fix voltage. How can I fix it ? How can I have a infinite signal ?

    • @ControllersTech
      @ControllersTech  4 года назад

      What? What you mean reset the code?
      Infinite signal ?

    • @JamalNetChannel
      @JamalNetChannel 4 года назад

      Did you set the DMA to circular mode ?

  • @flankerzo
    @flankerzo 3 года назад

    Hi, how are you? im rly struggling to output data to internal 12b DAC from usb audio class, can you make tutorial for this?
    it looks like everything is there, but i dont know what data put to timer 6 to trigger DAC change as STM manual say.

    • @ControllersTech
      @ControllersTech  3 года назад +1

      I am working on it. Let's hope everything works out..

    • @flankerzo
      @flankerzo 3 года назад

      @@ControllersTech this is rly great :3

    • @flankerzo
      @flankerzo 3 года назад

      @@ControllersTech Im making mini tesla coil, based on NiklasFauth project, but i want to change from midi to normal audio. I reprogramed everithing but usb audio to pwm (want to use imput data from DAC to make PWM audio) all based on STM32F072.

    • @ControllersTech
      @ControllersTech  3 года назад

      Actually i made it work, but with i2s and usb msc.

    • @flankerzo
      @flankerzo 3 года назад

      @@ControllersTech nice work!! :) can you share code please ? :) what to change to make it work with internal dac ?

  • @franciscotoapanta3926
    @franciscotoapanta3926 4 года назад

    how i can generate a triangle wave using the triangle generator??
    thanks for the video, i'm allways share it with my partners

    • @ControllersTech
      @ControllersTech  4 года назад +1

      There is a section in the document linked in the description about triangular waveform..

    • @holyboyarishnik9861
      @holyboyarishnik9861 4 года назад

      STM library comes with examples. Find corresponding examples like Examples\DAC\DAC_SignalsGeneration in Cube repository.