I want to sample a signal at 44kHz.

I've tried to set up the ADC with DMA and calculated the conversion time so that I get that 44kHz sampling frequency.

My thinking is that with continuous mode ADC, after each ADC conversion immediately the next one starts, so by choosing the conversion time I get my 44kHz = (1/conv_time).

Turns out this didn't work, I got much fewer samples than expected. Only when I set up the ADC triggered by a timer I got my correct 44kHz frequency.

Can anyone explain to me where is my thinking wrong with the first attempt (without timer)?

(I'm using STM32L432KC MCU)

Straight from the reference manual: The total conversion time is calculated as follows: TCONV = Sampling time + 12.5 ADC clock cycles Example: With FADC_CLK = 80 MHz and a sampling time of 2.5 ADC clock cycles: TCONV = (2.5 + 12.5) ADC clock cycles = 15 ADC clock cycles = 187.5 ns (for fast channels)

So sampling freq = 1/Tconv if I understand it correctly (https://www.st.com/resource/en/reference_manual/dm00151940-stm32l41xxx42xxx43xxx44xxx45xxx46xxx-advanced-armbased-32bit-mcus-stmicroelectronics.pdf page 389)

My code since you asked for it:

float32_t FFT_buffer_in[2048];
.
.
.
{
if (i<2048)
{
i++;
}
else
{
i = 0;
doFFT();
}

}
.
.
.
int main(void)
{
.
.
.
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_DMA_Init();
MX_DAC1_Init();
MX_TIM2_Init();
MX_TIM1_Init();
MX_USART2_UART_Init();

arm_rfft_fast_init_f32(&fft_handler, 2048);

.
.
.
}
{

/* USER CODE BEGIN ADC1_Init 0 */

/* USER CODE END ADC1_Init 0 */

/* USER CODE BEGIN ADC1_Init 1 */

/* USER CODE END ADC1_Init 1 */
/** Common config
*/
{
Error_Handler();
}
/** Configure Regular Channel
*/
sConfig.Offset = 0;
{
Error_Handler();
}
/* USER CODE BEGIN ADC1_Init 2 */

/* USER CODE END ADC1_Init 2 */

}



These are just fragments from the code, If more is needed - let me know

• What ADC??? They are not all created equal.... Some ADC's do not have a 'fixed' conversion time, some do. Without sharing the datasheet of the device in question, nobody can tell you much of what's going on here. Mar 5 at 20:55
• Internal ADC of STM32L432KC. To my understanding, it does have a fixed conversion time but I can be wrong, that's why I'm asking Mar 5 at 21:04
• How exactly you configured the ADC to adjust the conversion time? We are not mind-readers you know, and your code may have bugs. Can you please post the source code? Mar 5 at 21:09
• "so by choosing the conversion time", how did you choose it, exactly? Mar 5 at 21:10
• Make it easy for those you want to help you. Convert the STM part number into a datasheet link. They're usually hundreds of pages so give a page number too. Mar 5 at 21:15