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

Поділитися
Вставка
  • Опубліковано 25 гру 2024

КОМЕНТАРІ • 91

  • @ControllersTech
    @ControllersTech  3 роки тому +6

    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 роки тому +6

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

  • @aleks1970nbg
    @aleks1970nbg 3 роки тому +7

    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 2 роки тому +1

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

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

  • @TheDadi4
    @TheDadi4 3 роки тому +1

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

  • @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

  • @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?

  • @fano72
    @fano72 5 місяців тому

    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?

  • @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!

  • @kallehallden8692
    @kallehallden8692 3 роки тому

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

  • @fatihokuyucu5644
    @fatihokuyucu5644 3 роки тому +1

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

  • @di987654321
    @di987654321 2 роки тому

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

  • @GuadrianBM
    @GuadrianBM 4 місяці тому

    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?

  • @kallehallden8692
    @kallehallden8692 3 роки тому

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

  • @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?

  • @mohammadrahimpoor513
    @mohammadrahimpoor513 4 роки тому

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

  • @clouddev1136
    @clouddev1136 4 роки тому

    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.

    • @ControllersTech
      @ControllersTech  4 роки тому

      I use ctrl+space. I don't know if there is any other way

    • @grzesgg
      @grzesgg 2 роки тому

      indexer enable

  • @hectoreliucaballerodimas6752
    @hectoreliucaballerodimas6752 4 роки тому

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

  • @nsanandkumarak
    @nsanandkumarak 3 роки тому

    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

  • @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

  • @electronic-ebox6403
    @electronic-ebox6403 6 місяців тому

    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

  • @CarlosFCosta-qw8uf
    @CarlosFCosta-qw8uf 4 роки тому

    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  4 роки тому

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

  • @ratulchowdhury7490
    @ratulchowdhury7490 4 роки тому

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

  • @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?

  • @darkobul1
    @darkobul1 5 років тому +1

    What was max frequency you could generate sine wave?

    • @ControllersTech
      @ControllersTech  5 років тому +1

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

    • @omeranar-youtube
      @omeranar-youtube 5 років тому

      is it possible 1mhz sine wave

    • @ControllersTech
      @ControllersTech  5 років тому +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

    • @omeranar-youtube
      @omeranar-youtube 5 років тому

      @@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  5 років тому +1

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

  • @eduardodelarosaferrer2205
    @eduardodelarosaferrer2205 5 років тому +1

    awesome as ever

  • @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.

  • @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 !

  • @adesuyisunday4287
    @adesuyisunday4287 3 роки тому

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

  • @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..

  • @TheJamnikER
    @TheJamnikER 4 роки тому

    Thanks for the video, very helpful

  • @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

  • @SageBoyyy
    @SageBoyyy Рік тому

    How we will control amplitude of sine wave ?

  • @widcoshop
    @widcoshop 4 роки тому

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

    • @ControllersTech
      @ControllersTech  4 роки тому

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

  • @flankerzo
    @flankerzo 4 роки тому

    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  4 роки тому +1

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

    • @flankerzo
      @flankerzo 4 роки тому

      @@ControllersTech this is rly great :3

    • @flankerzo
      @flankerzo 4 роки тому

      @@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  4 роки тому

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

    • @flankerzo
      @flankerzo 4 роки тому

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

  • @RiccardoFranceschetto
    @RiccardoFranceschetto 4 роки тому +1

    how to change amplitude?

    • @ControllersTech
      @ControllersTech  4 роки тому +1

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

  • @MrRonychakraborty
    @MrRonychakraborty 5 років тому +1

    Nice tutorial :)

  • @jimidjoriginal9295
    @jimidjoriginal9295 3 роки тому

    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  3 роки тому

      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.

  • @ignaciozuniga7433
    @ignaciozuniga7433 4 роки тому

    how can i make an oscilloscope using stm. Thanks

  • @daviddavido9204
    @daviddavido9204 5 років тому

    Thanks for the tutorial

  • @nonstradam
    @nonstradam 4 роки тому

    very nice tutorial, thx

  • @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 9 місяців тому

      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?

  • @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 ?

  • @LL-ue3ek
    @LL-ue3ek 2 роки тому +1

    good video. but the background music is very distracting.

  • @franciscotoapanta3926
    @franciscotoapanta3926 5 років тому

    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  5 років тому +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.

  • @mohsenmazandarani7506
    @mohsenmazandarani7506 3 роки тому

    Thank you

  • @petrjanousek7613
    @petrjanousek7613 3 роки тому

    NIce, thanks!