Instead of double defining things like SAMPLE_FREQ, you can create "User Constants" in CubeMX, assign a value there and then use that constant in both generated initialization code as well as any custom code. Those "User Constants" show up (IIRC) as #defines in main.h
I did that in the last video #14. In this case however, it is a bit more complicated. I guess I _could_ calculate the value from the prescaler and counter values of the timer. But put that down as pure laziness ;)
This couldn't have been uploaded at a better time. Been having some issues with DAC. I was hoping to trigger the DAC1 that will output triangle wave and look for the completed flag and then increment the DAC2 by value of 1. I was hoping to do this continuously in the background without interfering with processor.. most i have managed to do till now is normal mode and circular mode examples by changing the frequency of triggering but i can't yet do that combination without involving processor too much. Any advice would be appreciated
Well, the DAC of the STM32F4xx MCU I was using in this example can actually do triangle wave without any calculation at all - you just need to feed the frequencies. Let me know if you can make that work - if not I could do a short video on it.
@@stm32world actually that sounds awesome.. i'll try that today.. i'm more worried about triggering the 2nd dac after the completion of the triangule wave.. i'm hoping that i can stop the wave generation somehow with the complete callback and then switching to generation of it again once the 2nd dac is incremented? i'm not sure, i'll give it a go... also i'll record a video of what i'm trying to do. i'm sure you'll love it..
@@stm32world I tried but am unable to work with dma interrupts specifically i'm not sure how to look for interrupt when dac is finished outputting a triangle wave. Also i'm trying to start the triangle wave through built in settings but i'ts not working.. i would appreciate it if you could create a video on how how to enable and look out for transfercomplete interrupts and do some work in the callback.
@@capistor1 I am not sure I understand what it is you want to achieve. If you look at my DAC example I calculate a sine wave. Nothing would prevent you from doing a triangle wave instead - in fact the math is simpler. Then you can trigger whatever you want in that callback once the wave is completed. I can have a look at the triangle generation later, there's quite a lot about it in the reference manual. But right now I am preparing some I2C videos and I need to get them out of the way first ;)
@@capistor1 you might want to have a look at AN3126 here: www.st.com/resource/en/application_note/an3126-audio-and-waveform-generation-using-the-dac-in-stm32-products-stmicroelectronics.pdf
Instead of double defining things like SAMPLE_FREQ, you can create "User Constants" in CubeMX, assign a value there and then use that constant in both generated initialization code as well as any custom code. Those "User Constants" show up (IIRC) as #defines in main.h
I did that in the last video #14. In this case however, it is a bit more complicated. I guess I _could_ calculate the value from the prescaler and counter values of the timer. But put that down as pure laziness ;)
great vid, ta
Thanks, glad you liked it.
This couldn't have been uploaded at a better time. Been having some issues with DAC. I was hoping to trigger the DAC1 that will output triangle wave and look for the completed flag and then increment the DAC2 by value of 1. I was hoping to do this continuously in the background without interfering with processor.. most i have managed to do till now is normal mode and circular mode examples by changing the frequency of triggering but i can't yet do that combination without involving processor too much. Any advice would be appreciated
Well, the DAC of the STM32F4xx MCU I was using in this example can actually do triangle wave without any calculation at all - you just need to feed the frequencies. Let me know if you can make that work - if not I could do a short video on it.
@@stm32world actually that sounds awesome.. i'll try that today.. i'm more worried about triggering the 2nd dac after the completion of the triangule wave.. i'm hoping that i can stop the wave generation somehow with the complete callback and then switching to generation of it again once the 2nd dac is incremented? i'm not sure, i'll give it a go... also i'll record a video of what i'm trying to do. i'm sure you'll love it..
@@stm32world I tried but am unable to work with dma interrupts specifically i'm not sure how to look for interrupt when dac is finished outputting a triangle wave. Also i'm trying to start the triangle wave through built in settings but i'ts not working.. i would appreciate it if you could create a video on how how to enable and look out for transfercomplete interrupts and do some work in the callback.
@@capistor1 I am not sure I understand what it is you want to achieve. If you look at my DAC example I calculate a sine wave. Nothing would prevent you from doing a triangle wave instead - in fact the math is simpler. Then you can trigger whatever you want in that callback once the wave is completed. I can have a look at the triangle generation later, there's quite a lot about it in the reference manual. But right now I am preparing some I2C videos and I need to get them out of the way first ;)
@@capistor1 you might want to have a look at AN3126 here: www.st.com/resource/en/application_note/an3126-audio-and-waveform-generation-using-the-dac-in-stm32-products-stmicroelectronics.pdf