cancel
Showing results for 
Search instead for 
Did you mean: 

ADC values reading with DMA

brent Kim
Associate II
Posted on January 21, 2017 at 07:17

The original post was too long to process during our migration. Please click on the attachment to read the original post.
5 REPLIES 5
valentin
Senior
Posted on January 21, 2017 at 08:39

Did you set your DMA stream to circular?

And your adc to continuous?

Posted on January 21, 2017 at 09:30

Yes I had set to circular, and ADC set to continuous.

Philippe Cherbonnel
ST Employee
Posted on January 23, 2017 at 17:46

Your file main.c looks correct, can you send also the file stm32XXxx_hal_msp.c ?

Can you also attach the CubeMX file '.ioc' ?

Posted on January 24, 2017 at 02:08

Thanks Philippe,

Attached file is my current source code with .ioc file.

https://drive.google.com/open?id=0Bwq94iD4_g4ycU1kWEJoal9JZXc

Posted on January 25, 2017 at 13:56

I have tested your code, the ADC and DMA are working correctly: buffer is updated indefinitely with ADC conversion data.

But there is a problem of overhead situation in IRQ handler: the buffer size is small (array of 4 addresses) and the ADC is configured to convert at high frequency.

The DMA half-transfer and DMA transfer complete interruptions will occur too frequently, the CPU is overloaded with these interruptions to handle.

With your settings, ADC conversion frequency is:

  • 1 ADC conversion: ADC clk  * (Tsampling + Tconversion) = 1/(72MHz/2) * (1.5 + 12.5) = 0.389us
  • 4 ADC conversions in continuous mode: 1.56us

=> Every 1.56us, CPU must handle 2 DMA interruptions

To reduce the ADC conversion frequency, you can increase sampling time.

Change

 

sConfig.SamplingTime = ADC_SAMPLETIME_1CYCLE_5;

to

 

sConfig.SamplingTime = ADC_SAMPLETIME_181CYCLES_5;

If you want to keep ADC conversions at high frequency with DMA transfer, either with DMA optimized interruption handling or without DMA interruptions (use case to pick ADC conversion data in buffer at will), you should use LL driver to customize the ADC and DMA configuration to your need.

LL driver for STM32F3 will be managed soon by CubeMX (in Project Settings -> Advanced Settings -> Driver). In the meantime, LL driver is in STM32F3 FW package and can be downloaded here:

http://www.st.com/en/embedded-software/stm32cubef3.html

.

Then, you can find an example here: STM32Cube_FW_F3_V1.7.0\Projects\STM32F334R8-Nucleo\Examples_LL\ADC

\ADC_MultiChannelSingleConversion\

Something else, not related to your issue:

You are using only 1 ADC (therefore in single mode, not in multimode). This configuration is missing, you should add

  multimode.Mode = ADC_MODE_INDEPENDENT;

before

  multimode.DMAAccessMode = ADC_DMAACCESSMODE_12_10_BITS;

  multimode.TwoSamplingDelay = ADC_TWOSAMPLINGDELAY_1CYCLE;

  if (HAL_ADCEx_MultiModeConfigChannel(&hadc1, &multimode) != HAL_OK)

  {

    Error_Handler();

  }

(and you can also remove configuration of 'multimode.DMAAccessMode' and 'multimode.TwoSamplingDelay')