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

  Рет қаралды 67,294

ControllersTech

ControllersTech

Күн бұрын

Пікірлер: 91
@ControllersTech
@ControllersTech 3 жыл бұрын
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 жыл бұрын
Finally. Information on WHY you write the code this way instead of simply what the code is. Well done.
@aleks1970nbg
@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
@pedrojanini2209 3 жыл бұрын
Thank you! I really needed to know about the HAL_DAC_Start existence.
@drewh0208
@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);
@martinpalomino8627
@martinpalomino8627 Жыл бұрын
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 жыл бұрын
No need to enable Tim2 global interrupt, thank you for the good explanation
@bennguyen1313
@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
@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 жыл бұрын
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 3 ай бұрын
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 4 ай бұрын
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
@GuadrianBM
@GuadrianBM 3 ай бұрын
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?
@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!
@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?
@adesuyisunday4287
@adesuyisunday4287 2 жыл бұрын
Thanks for this project. Please do complete sinewave hbridge inverter with lcd and menu keypad to set all parameters.using stm32f
@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
@fatihokuyucu5644
@fatihokuyucu5644 3 жыл бұрын
Good explanation, thank you very much. It is exactly what i want :))
@kallehallden8692
@kallehallden8692 3 жыл бұрын
hello , using this method , ho I can generate the two sinewave on DAC1 & DAC2 Simultaneously ?
@eduardodelarosaferrer2205
@eduardodelarosaferrer2205 5 жыл бұрын
awesome as ever
@kallehallden8692
@kallehallden8692 3 жыл бұрын
hii Nice tutorial, Good explanation, thank you very much. It is exactly what i want in my project
@di987654321
@di987654321 Жыл бұрын
how to you remove the dc component ? are you using capacitor in the output ?
@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
@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..
@mohammadrahimpoor513
@mohammadrahimpoor513 4 жыл бұрын
hi any ideas about maximum frequency of a smooth sinewave using this dac unit?
@hectoreliucaballerodimas6752
@hectoreliucaballerodimas6752 4 жыл бұрын
Nice tutorial. Do you know how can I show the wave on labview?
@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 2 жыл бұрын
good video. but the background music is very distracting.
@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 жыл бұрын
maybe your scope is set for the DC.. Check that..
@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
@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.
@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?
@TheJamnikER
@TheJamnikER 4 жыл бұрын
Thanks for the video, very helpful
@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.
@TheZeroomg
@TheZeroomg 3 жыл бұрын
Is it possible to dynamically change the sine wave pattern(its frequency, as modulated signal) using DMA?
@ControllersTech
@ControllersTech 3 жыл бұрын
Yeah why not. Just change the frequency and amplitude in the sine function
@TheZeroomg
@TheZeroomg 3 жыл бұрын
@@ControllersTech Thank you !
@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
@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 7 ай бұрын
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?
@darkobul1
@darkobul1 5 жыл бұрын
What was max frequency you could generate sine wave?
@ControllersTech
@ControllersTech 5 жыл бұрын
Actually I haven't tested it. It depends on how many samples you are taking..
@omeranar-youtube
@omeranar-youtube 4 жыл бұрын
is it possible 1mhz sine wave
@ControllersTech
@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
@omeranar-youtube
@omeranar-youtube 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 жыл бұрын
I don't know about controlling current in this prospective..
@MrRonychakraborty
@MrRonychakraborty 5 жыл бұрын
Nice tutorial :)
@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
@daviddavido9204
@daviddavido9204 5 жыл бұрын
Thanks for the tutorial
@nonstradam
@nonstradam 4 жыл бұрын
very nice tutorial, thx
@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 жыл бұрын
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 ?
@SageBoyyy
@SageBoyyy Жыл бұрын
How we will control amplitude of sine wave ?
@ControllersTech
@ControllersTech Жыл бұрын
Use math
@RiccardoFranceschetto
@RiccardoFranceschetto 4 жыл бұрын
how to change amplitude?
@ControllersTech
@ControllersTech 4 жыл бұрын
Check my latest video on nextion display. I have used sine wave there too, along with variation in amplitude and frequency
@petrjanousek7613
@petrjanousek7613 3 жыл бұрын
NIce, thanks!
@ignaciozuniga7433
@ignaciozuniga7433 4 жыл бұрын
how can i make an oscilloscope using stm. Thanks
@ControllersTech
@ControllersTech 4 жыл бұрын
I wish it would be that simple
@mohsenmazandarani7506
@mohsenmazandarani7506 3 жыл бұрын
Thank you
@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 ?
@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 жыл бұрын
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.
Getting started with ESP8266 using AT COMMANDS
12:32
ControllersTech
Рет қаралды 19 М.
Tutorial STM32 DAC Timer Triggered DMA
34:08
PR TechTalk
Рет қаралды 4,3 М.
ЗНАЛИ? ТОЛЬКО ОАЭ 🤫
00:13
Сам себе сушист
Рет қаралды 3,6 МЛН
Osman Kalyoncu Sonu Üzücü Saddest Videos Dream Engine 269 #shorts
00:26
When mom gets home, but you're in rollerblades.
00:40
Daniel LaBelle
Рет қаралды 100 МЛН
SPI peripheral with STM32 and PCM1792 audio DAC | VIDEO27
47:46
Matej Blagšič
Рет қаралды 12 М.
12-bit DAC Arduino MCP4725 How To Use It - Stable Voltage Reffrence
11:21
Introduction to Free RTOS in STM32 || CubeIDE || Tasks || priorities
16:26
Using I2C for any device on STM32 with HAL | VIDEO 26
37:51
Matej Blagšič
Рет қаралды 79 М.
Flawless PCB design: RF rules of thumb - Part 1
15:45
Hans Rosenberg
Рет қаралды 82 М.
STM32 Guide #3: PWM + Timers
20:24
Mitch Davis
Рет қаралды 147 М.
Using the ESP32 DAC - Voltages, Waveforms & Sounds
34:46
DroneBot Workshop
Рет қаралды 83 М.