cancel
Showing results for 
Search instead for 
Did you mean: 

ADC problem with sampling frequency of 2MSPS

smrtkai
Senior
Posted on January 27, 2016 at 18:55

Hi,

I do have some strange behavior with an ADC, that I cannot explain. I want an ADC to run with a frequency higher than 2 MHz and DMA. I am using an STM32F4 Discovery board, so the ADC's support 2,4MSPS.

My configuration is as follows:

ABP2: 86 MHz

ADC3-Prescaler: 4

Resolution: 6 Bit

Sampling Time: 3 Cycles

With this configuration, I expect a sampling frequency of ~2,4MHz (86/4/(6+3)).

I want to verify it by using a pin, that I toggle on the DMA callbacks (half-full and full). My DMA memory size is set to 160 values.

Unfortunately the pin does not toggle. When reducing the sampling frequency to ~1,2 MHz by setting the ADC prescaler to 8, I get an pulse signal at the pin with ~7,5kHz. This is axactly the freqeuncy I expected (7,5kHz*160samples = 1,2MSPS) 

So sampling with 1,2 MSPS works but with higher freqeuncies does not. Even setting the adc prescaler to 6, does not work. :(

What am I missing? I would expect, that this s

hould work.

T

3 REPLIES 3
smrtkai
Senior
Posted on January 28, 2016 at 08:10

This is my ADC configuration:

 

hadc3.Instance = ADC3;

  hadc3.Init.ClockPrescaler = ADC_CLOCKPRESCALER_PCLK_DIV4;

  hadc3.Init.Resolution = ADC_RESOLUTION6b;

  hadc3.Init.ScanConvMode = ENABLE;

  hadc3.Init.ContinuousConvMode = ENABLE;

  hadc3.Init.DiscontinuousConvMode = DISABLE;

  hadc3.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;

  hadc3.Init.DataAlign = ADC_DATAALIGN_RIGHT;

  hadc3.Init.NbrOfConversion = 1;

  hadc3.Init.DMAContinuousRequests = ENABLE;

  hadc3.Init.EOCSelection = EOC_SINGLE_CONV;

  HAL_ADC_Init(&hadc3);

  sConfig.Channel = ADC_CHANNEL_0;

  sConfig.Rank = 1;

  sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES;

  HAL_ADC_ConfigChannel(&hadc3, &sConfig);

My DMA initialization looks like this:

    hdma_adc3.Instance = DMA2_Stream1;

    hdma_adc3.Init.Channel = DMA_CHANNEL_2;

    hdma_adc3.Init.Direction = DMA_PERIPH_TO_MEMORY;

    hdma_adc3.Init.PeriphInc = DMA_PINC_DISABLE;

    hdma_adc3.Init.MemInc = DMA_MINC_ENABLE;

    hdma_adc3.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;

    hdma_adc3.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;

    hdma_adc3.Init.Mode = DMA_CIRCULAR;

    hdma_adc3.Init.Priority = DMA_PRIORITY_LOW;

    hdma_adc3.Init.FIFOMode = DMA_FIFOMODE_DISABLE;

    hdma_adc3.Init.MemBurst = DMA_MBURST_SINGLE;

    hdma_adc3.Init.PeriphBurst = DMA_PBURST_SINGLE;

    HAL_DMA_Init(&hdma_adc3);

    __HAL_LINKDMA(hadc,DMA_Handle,hdma_adc3);

smrtkai
Senior
Posted on February 01, 2016 at 17:12

In another attempt, I have setup my STM32F429I-Discovery board as described in

http://www.st.com/web/en/resource/technical/document/application_note/DM00050879.pdf

.

Clock source: external clock (8 MHz) provided by a generator, PLL is enabled, fCPU = 144 MHz

... with fADC = 36 MHz, sampling time = 3 ADC cycles and ADC resolution = 12 bits in order to achieve the fastest ADC conversion (2.4 Msps).

DMA is activated and a pin is toggled on the callbacks (half-full and full). In this configuration it does not work, too :( Only, when I decrease the sampling rate to 1.2 Msps the pin toggles.

I doubt, that the DMA limits the ADC. Or am I wrong with this assumption?

smrtkai
Senior
Posted on February 02, 2016 at 11:17

I have tried the same settings on my STM32F746G-DISCO and its works as expected. I have also tried another STM32F429I-DISCO, but it does not work too.

I would really like to understand how to get the ADC of STM32F4 working with 2.4Msps. I hope anyone can help or provide some working example code.