0
\$\begingroup\$

I would like to know how many samples I have per second for the ADC and what is its maximum samples per second and can I achieve a sample per 1 µs?

Clock : 84 Mhz

The board is Nucleo F401RE

Here is the ADC configuration with DMA :

 void ConfigureDMA_ADC() {
 __DMA2_CLK_ENABLE()
;
g_DmaHandle.Instance = DMA2_Stream4;

g_DmaHandle.Init.Channel = DMA_CHANNEL_0;
g_DmaHandle.Init.Direction = DMA_PERIPH_TO_MEMORY;
g_DmaHandle.Init.PeriphInc = DMA_PINC_DISABLE;
g_DmaHandle.Init.MemInc = DMA_MINC_ENABLE;
g_DmaHandle.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD;
g_DmaHandle.Init.MemDataAlignment = DMA_MDATAALIGN_WORD;
g_DmaHandle.Init.Mode = DMA_CIRCULAR;
g_DmaHandle.Init.Priority = DMA_PRIORITY_HIGH;
g_DmaHandle.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
g_DmaHandle.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_HALFFULL;
g_DmaHandle.Init.MemBurst = DMA_MBURST_SINGLE;
g_DmaHandle.Init.PeriphBurst = DMA_PBURST_SINGLE;

HAL_DMA_Init(&g_DmaHandle);

__HAL_LINKDMA(&g_AdcHandle, DMA_Handle, g_DmaHandle);

HAL_NVIC_SetPriority(DMA2_Stream4_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(DMA2_Stream4_IRQn);
}

void ConfigureADC() {
GPIO_InitTypeDef gpioInit;

__GPIOA_CLK_ENABLE()
;
__ADC1_CLK_ENABLE()
;

gpioInit.Pin = GPIO_PIN_1;
gpioInit.Mode = GPIO_MODE_ANALOG;
gpioInit.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOA, &gpioInit);

HAL_NVIC_SetPriority(ADC_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(ADC_IRQn);

ADC_ChannelConfTypeDef adcChannel;

g_AdcHandle.Instance = ADC1;

g_AdcHandle.Init.ClockPrescaler = ADC_CLOCKPRESCALER_PCLK_DIV2;
g_AdcHandle.Init.Resolution = ADC_RESOLUTION_12B;
g_AdcHandle.Init.ScanConvMode = DISABLE;
g_AdcHandle.Init.ContinuousConvMode = ENABLE;
g_AdcHandle.Init.DiscontinuousConvMode = DISABLE;
g_AdcHandle.Init.NbrOfDiscConversion = 0;
g_AdcHandle.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
g_AdcHandle.Init.ExternalTrigConv = ADC_EXTERNALTRIGCONV_T1_CC1;
g_AdcHandle.Init.DataAlign = ADC_DATAALIGN_RIGHT;
g_AdcHandle.Init.NbrOfConversion = 1;
g_AdcHandle.Init.DMAContinuousRequests = ENABLE;
g_AdcHandle.Init.EOCSelection = DISABLE;

HAL_ADC_Init(&g_AdcHandle);

adcChannel.Channel = ADC_CHANNEL_1;
adcChannel.Rank = 1;
adcChannel.SamplingTime = ADC_SAMPLETIME_144CYCLES;
adcChannel.Offset = 0;

if (HAL_ADC_ConfigChannel(&g_AdcHandle, &adcChannel) != HAL_OK) {
    asm("bkpt 255");
   }
}
\$\endgroup\$
2
  • 1
    \$\begingroup\$ @MichelKeijzers please stop making silly edits to old posts, it needlessly churns them in the queue and generates attention they don't deserve \$\endgroup\$ Commented Dec 18, 2018 at 20:12
  • \$\begingroup\$ @ChrisStratton Ok agreed, sorry for the inconvenience. \$\endgroup\$ Commented Dec 18, 2018 at 20:13

1 Answer 1

1
\$\begingroup\$

The datasheet for STM32F401 says in Table 66. ADC characteristics (continued) for Sampling rate (fADC = 30 MHz, and tS = 3 ADC cycles) and 12-bit resolution Single ADC 2 Msps, so yes, it could achieve 1µs/sample.

However, that uses a sampling time of 3 ADC-clock cycles, a 30MHz ADC-clock, and relies on a relatively low impedance source (under 1k IIRC)

For an 84MHz clock, the ADC-clock will be 21MHz.
The maximum ADC-clock is 30MHz, but it is derived from the main clock by dividing by 2, 4, 6 or 8, and 4 is the smallest divider that keeps it within 30MHz.

So, it's going to get about 2/3rds of 2Msps, specifically \$2 \times 21/30 = 1.4\$Msps, which is still better than 1µs.

\$\endgroup\$
2
  • \$\begingroup\$ So what should I change in the config of the adc configuration? :) \$\endgroup\$ Commented May 23, 2016 at 11:17
  • \$\begingroup\$ adcChannel.SamplingTime = ADC_SAMPLETIME_3CYCLES; \$\endgroup\$ Commented May 23, 2016 at 14:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.