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
4 жыл бұрын
Finally. Information on WHY you write the code this way instead of simply what the code is. Well done.
@aleks1970nbg
3 жыл бұрын
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
3 жыл бұрын
Thank you! I really needed to know about the HAL_DAC_Start existence.
@martinpalomino8627
Жыл бұрын
Thanks so much for the knowledge, I managed to get the stm32 to generate a sine wave with a frequency value = 60hz
@TheDadi4
3 жыл бұрын
No need to enable Tim2 global interrupt, thank you for the good explanation
@drewh0208
3 жыл бұрын
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);
@bennguyen1313
4 жыл бұрын
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
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
2 жыл бұрын
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?
@electronic-ebox6403
2 ай бұрын
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
@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?
@GuadrianBM
25 күн бұрын
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
2 жыл бұрын
Thanks for this project. Please do complete sinewave hbridge inverter with lcd and menu keypad to set all parameters.using stm32f
@kallehallden8692
3 жыл бұрын
hii Nice tutorial, Good explanation, thank you very much. It is exactly what i want in my project
@fatihokuyucu5644
3 жыл бұрын
Good explanation, thank you very much. It is exactly what i want :))
@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!
@modellerdesign
2 жыл бұрын
hi. can it be made like RF generator say till 10 mhz or so, and with encoder changing frequency with 1khz steps?
@di987654321
Жыл бұрын
how to you remove the dc component ? are you using capacitor in the output ?
@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
@ratulchowdhury7490
3 жыл бұрын
how to generate noise sinewave and low pass filter to filter out the harmonics and getting pure sine wave by stm cubemx
@kallehallden8692
3 жыл бұрын
hello , using this method , ho I can generate the two sinewave on DAC1 & DAC2 Simultaneously ?
@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
@eduardodelarosaferrer2205
4 жыл бұрын
awesome as ever
@mohammadrahimpoor513
3 жыл бұрын
hi any ideas about maximum frequency of a smooth sinewave using this dac unit?
@LL-ue3ek
Жыл бұрын
good video. but the background music is very distracting.
@hectoreliucaballerodimas6752
3 жыл бұрын
Nice tutorial. Do you know how can I show the wave on labview?
@Red_Fang.
Жыл бұрын
Hello, i'm using F1 Blue pill Series, how to use pin as DAC? thank you
@ControllersTech
Жыл бұрын
Bluepill doesn't support DAC. You can use some external IC, but this tutorial won't work for it.
@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
3 жыл бұрын
Yeah you can.. just put a variable inside the function, and increment it after the sine wave has been generated..
@TheJamnikER
4 жыл бұрын
Thanks for the video, very helpful
@RiccardoFranceschetto
3 жыл бұрын
how to change amplitude?
@ControllersTech
3 жыл бұрын
Check my latest video on nextion display. I have used sine wave there too, along with variation in amplitude and frequency
@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
2 жыл бұрын
maybe your scope is set for the DC.. Check that..
@SageBoyyy
10 ай бұрын
How we will control amplitude of sine wave ?
@ControllersTech
10 ай бұрын
Use math
@MrRonychakraborty
4 жыл бұрын
Nice tutorial :)
@nonstradam
4 жыл бұрын
very nice tutorial, thx
@daviddavido9204
4 жыл бұрын
Thanks for the tutorial
@widcoshop
3 жыл бұрын
hi how are you?that great ..how can i generate a wave but concurrent that have negative and positive voltage?
@ControllersTech
3 жыл бұрын
Look at my nextion video on waveform. I have used the sine wave there too. Maybe that code can help you
@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
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.
@TheZeroomg
3 жыл бұрын
Is it possible to dynamically change the sine wave pattern(its frequency, as modulated signal) using DMA?
@ControllersTech
3 жыл бұрын
Yeah why not. Just change the frequency and amplitude in the sine function
@TheZeroomg
3 жыл бұрын
@@ControllersTech Thank you !
@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
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
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
@darkobul1
4 жыл бұрын
What was max frequency you could generate sine wave?
@ControllersTech
4 жыл бұрын
Actually I haven't tested it. It depends on how many samples you are taking..
@omeranar8769
4 жыл бұрын
is it possible 1mhz sine wave
@ControllersTech
4 жыл бұрын
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
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
4 жыл бұрын
I don't know about controlling current in this prospective..
@mohsenmazandarani7506
2 жыл бұрын
Thank you
@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
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
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
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
3 жыл бұрын
Try using hsi clock
@brianarianpour4702
5 ай бұрын
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
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.
@ControllersTech
3 жыл бұрын
I use ctrl+space. I don't know if there is any other way
@grzesgrzankaify
2 жыл бұрын
indexer enable
@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
3 жыл бұрын
Yup it doesn't support
@antoniomartos2343
3 жыл бұрын
@@ControllersTech Thanks. Can u recommend me a nucleo board for getting and FM signal ADC then demodulate it and then DAC?
@antoniomartos2343
3 жыл бұрын
I thought about nucleo-l476rg. Is this one good enough?
@petrjanousek7613
3 жыл бұрын
NIce, thanks!
@ignaciozuniga7433
4 жыл бұрын
how can i make an oscilloscope using stm. Thanks
@ControllersTech
4 жыл бұрын
I wish it would be that simple
@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
4 жыл бұрын
There is a section in the document linked in the description about triangular waveform..
@holyboyarishnik9861
4 жыл бұрын
STM library comes with examples. Find corresponding examples like Examples\DAC\DAC_SignalsGeneration in Cube repository.
@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
4 жыл бұрын
What? What you mean reset the code? Infinite signal ?
@JamalNetChannel
4 жыл бұрын
Did you set the DMA to circular mode ?
@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
3 жыл бұрын
I am working on it. Let's hope everything works out..
@flankerzo
3 жыл бұрын
@@ControllersTech this is rly great :3
@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
3 жыл бұрын
Actually i made it work, but with i2s and usb msc.
@flankerzo
3 жыл бұрын
@@ControllersTech nice work!! :) can you share code please ? :) what to change to make it work with internal dac ?
Пікірлер: 89