cancel
Showing results for 
Search instead for 
Did you mean: 

I need to generate sinusoidal signal with DAC and DMA, how to do it?

macam1
Associate III

I have a project to generate a sinusoidal signal using DAC and DMA. The waveform looks like a peak-flat-valley-flat pattern. I am using an array of 500 values, with the peak at 4095, flat at 2048, and the valley at 0. I utilize circular DMA to repeat the data (as I understand it). I want to determine how many signals are generated by my DMA in one second when running. I also want to access the memory, but I'm still confused about how DMA actually works. Please help me.

@SofLit 

5 REPLIES 5
Danish1
Lead II

DMA is a circuit that, when triggered, reads a specified memory location (in your case the next entry in your array of values) and then writes it to another specific memory location (in your case the DAC's data-output register.) To make this more useful, with each read, the DMA can be told to move to the next memory-location for the read (but not in your case the next memory-location for the write).

This is all described in great technical detail in the Reference Manual for your stm32. Do download it and browse it.

So then the question is how does the DMA get triggered? Typically in an application like yours, you'd set up a Timer to deliver that trigger every time the timer completed its timing period. The timer would be driven off the processor clock.


@Danish1 wrote:

This is all described in great technical detail in the Reference Manual for your stm32.


Indeed.

@macam1 The Reference Manual, along with all other support materials, can always be found via the Product Page for the particular microcontroller.

You haven't said what microcontroller you're using but, by way of example, here's the Product Page for the STM32F407VE:

https://www.st.com/en/microcontrollers-microprocessors/stm32f407ve.html

See the 'Documentation' tab for datasheet, Reference Manual, Application Notes, etc:

https://www.st.com/en/microcontrollers-microprocessors/stm32f407ve.html#documentation

There is a search facility:

AndrewNeil_0-1733913336018.png

 

 

 

gregstm
Senior III

DMA is an extra helping hand. It can transfer the data to the DAC at regular intervals determined usually by a timer. You can use the half-transfer and transfer complete interrupts to update/modify one half of the buffer while the DMA is working in the other half of the buffer. If you want to do different sine frequencies, you will need a sine table of higher resolution and probably use interpolation to calculate in-between sine values (you step through the sine table at different rates to change your frequency, use 8 or 16 bits to represent the "fractional" part of your step value to maintain accuracy)

Sample rate and pacing is determined by a TIM selected as a trigger source.

The bandwidth for the DAC is under 1 MHz as I recall. 

The pattern can have up to 65535 elements, you can get HT and TC interrupts from the DMA as each half of the output starts/completes

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
SofLit
ST Employee

I've already said in another thread, please refer to this example and inspire from it. It generates signal using DAC:

https://github.com/STMicroelectronics/STM32CubeF4/tree/master/Projects/STM324xG_EVAL/Examples/DAC/DAC_SignalsGeneration

It's using DAC and DMA with TIM6 to tune the DAC "sampling" time.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.