cancel
Showing results for 
Search instead for 
Did you mean: 

ADC DAC problems

Woelki
Associate

Hi, i encountered the problem on my stm32 G474RE board, that when i use the adc in dma mode i can not use a dac. The dac simply does not work. As long as i dont start the adc in dma mode, my dac is generating the right waveform, but when i start the adc the dac_setValue function is stuck and wont update? Has anybody encountered that problem? Am i doing something wrong?

5 REPLIES 5
TDK
Super User

Your ADC interrupts are triggering so fast it prevents the code from doing anything else. Decrease ADC sample rate, increase DMA buffer size. Increasing the sample rate to max is generally beneficial.

If you feel a post has answered your question, please click "Accept as Solution".

But how can i then use the maximum sampling frequency of the adc? The MCU clock is set to 120MHz so it should be way faster than the ADC sampling frequency. Is there just too much overhead, with the HAL libraries? I basically want to compare consecutive adc values in real time to react on them. Measuring a ton of values and buffering them is not suitable for my application.

Code takes time to run. You can't react to every sample at max sample rate immediately after it happens. The CPU can't keep up.

If you feel a post has answered your question, please click "Accept as Solution".

To use simple compare operation to pre-defined values you can configure AWD:

Analog window watchdog (AWD1EN, JAWD1EN, AWD1SGL,
AWD1CH, AWD2CH, AWD3CH, AWD_HTx, AWD_LTx, AWDx)
The three AWD analog watchdogs monitor whether some channels remain within a
configured voltage range (window).

For more advanced algorithm of data processing consider to sample a small array, 10-20 samples and work in interrupt. Highly optimized code may get speed above 2-4 msps that adc could stream at max

LCE
Principal II

Unless you're doing some real-time processing on each sample, use big buffers for AD and DA data, combined with DMA.

And for getting (even more) help:

show your relevant code snippets, using the </> button.

Some people don't have time / want to download and unzip.