cancel
Showing results for 
Search instead for 
Did you mean: 

Signal generation with dac and DMA problem

Oliver Trajkovski
Associate
Posted on July 07, 2018 at 13:56

So i am using stm32f469NI processor on discovery development board 

I already generated signals with processor , but that is not good since it doesn't allow for anything else to happen while the signal is being generated .

So i want to use dma .

I have been trying for 2 days now but i can't get it to work.

I can't seem to find good tutorials or documentation and my code is spaghetti.

I found a code snippet that works directly with the registers and not with hal or CubeMx

__HAL_RCC_TIM6_CLK_ENABLE();

__HAL_RCC_DMA1_CLK_ENABLE();

TIM6 -> DIER |= TIM_DIER_UDE;

TIM6 -> PSC = 5;

TIM6 -> ARR = 5;

TIM6 -> CR2 |= TIM_CR2_MMS_1;

DAC1 -> CR = DAC_CR_DMAEN1 | DAC_SR_DMAUDR1 | DAC_CR_TEN1 | DAC_CR_BOFF1;

DAC1 -> CR |= DAC_CR_EN1;

DMA1_Stream7 -> NDTR |= 1024;

DMA1_Stream7 -> PAR = (uint32_t)(DAC -> DHR12R1);

DMA1_Stream7 -> M0AR = (uint32_t)(sinTable);

DMA1_Stream7 -> CR = (DMA_SxCR_TEIE | DMA_SxCR_CHSEL | DMA_SxCR_CIRC | DMA_SxCR_DIR_0 | DMA_SxCR_EN | DMA_SxCR_PSIZE_0 | DMA_SxCR_MSIZE_0 | DMA_SxCR_MINC | DMA_SxCR_PL_0);

TIM6 -> CR1 |= TIM_CR1_CEN;

But it does't work.

Generating the code with CubeMx isn't an option because I have an existing project . 

There are like 50 datasheets for this board , I am confused and frustrated .

Any help is appreciated 

#dma #dac #stm32
4 REPLIES 4
Posted on July 08, 2018 at 16:26

There are like 50 datasheets for this board , I am confused and frustrated .

Who cares? Do your reading. Learn. Do things one at a time. Things Take Time ((C) Piet Hein).

it does't work.

What is 'it'? The timer does not run? The DMA does not transfer data as supposed? DAC does not output levels you expect? Divide et impera. Resolve, what your problem is.  Read back the registers and check if they are set as you want them. Observe, whether each particular module does what is expected to do. 'It does not work' is not a question.

But, first of all, go to DMA chapter in the RM, and check whether TIM6 can trigger the Stream you selected and on the Channel you've set in the stream's configuration register.

JW

Posted on July 08, 2018 at 16:39

It is the Reference Manual for the chip which is the critical document to understand.

https://www.st.com/content/ccc/resource/technical/document/reference_manual/29/77/09/5a/b1/60/4e/bd/DM00127514.pdf/files/DM00127514.pdf/jcr:content/translations/en.DM00127514.pdf

 

The max drive rate for the DAC is 1 Msps, don't know what speed you're running this at, but I'm assuming TIMCLK/36 > 1 MHz

The reference manual associates TIM6_UP(DATE) with DMA1 Channel 7 Stream 1, where as DAC1 would be DMA1 Channel 7 Stream 5.

Decide what is driving the DMA, usually you configure the DAC to use a specific periodic trigger, and have the DAC initiate the DMA. You are trying to use the TIM directly, which might well work, but using random resources won't.

0690X00000604l0QAA.jpg
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
T J
Lead
Posted on July 09, 2018 at 02:12

I use the cube for this exact reason..

the cube is suggesting to use a different DMA...

0690X0000060LhNQAU.png
Posted on July 09, 2018 at 08:01

The reference manual, when carefully read, suggests the same.

Only it is two orders of magnitude smaller than an installed Cube ...

Not sure if there are F46x SPL examples, but for the F40x they exist. I used to pick a similar example, and modified it for my purposes. This gets you started quicker.

And if you wish, you can then start to strip unnecessary HAL code layers, for speed/size optimizations.

BTW, be aware that the DAC->DR throughput is not equal to the DAC throughput. The DAC settling time limits the available bandwidth to about 200kHz.