ADC frequency not working as expected
I am using NUCLEO-STM32F446re board. It runs at 180MHz SYSCLK and ADC uses APB2CLK that can run at a maximum frequency of 90MHz. I am using STM32CubeIDE and the clock configuration looks as follows:
My ADC setup looks as follows:
My DMA setup:
Just before the while loop I call ADC to start with DMA.
/* USER CODE BEGIN PV */
volatile uint16_t adcResultsDMA[2];
const int adcChannelCount=sizeof(adcResultsDMA)/sizeof(adcResultsDMA[0]);
/* USER CODE END PV */
......
......
......
......
int main(void)
{
/* USER CODE BEGIN 2 */
HAL_ADC_Start_DMA(&hadc1, (uint32_t*)adcResultsDMA, adcChannelCount);
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
.......
}
}And the complete call back function I toggle a PIN and start ADC with DMA again.
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc) {
HAL_GPIO_TogglePin(GPIOA, time_meas_Pin);
HAL_ADC_Start_DMA(&hadc1, (uint32_t*)adcResultsDMA, adcChannelCount);
}Question
When I use an ADC Clock Prescaler = PCLK2 divided by 8 (90MHz / 8 = 11.25MHz).
- The time between the GPIO toggles is 7.6us (this is the time it takes for the ADC to sample and convert (2 channels) and the DMA to transfer the data to the memory).
- According to theory 12 bit takes 15 ADC clock cycles, thus for 2 channels it would be (30 ADC cycles / 11.25 MHz = 2.6us ). What I am measuring (7.6us) is way too high than what I expect (2.6us).
Lets assume what I am measuring (7.6us) is correct. When I then almost double the ADC frequency by changing the Clock Prescaler = PCLK2 divided by 4 (90MHz / 4 = 22.5MHz)
- The time between the GPIO toggles is 7.2us (this is the time it takes for the ADC to sample and convert (2 channels) and the DMA to transfer the data to the memory), I dont understand why do I almost get the same time (7.6us for 11.25MHz and 7.2us for 22.5MHz) when I am increasing my ADC frequency?
Please advise me on what concept am I failing to understand? I would like to start ADC with software and not a timer or so, because there is code written in While() loop that is being started manually.
I have tried to include everything that is necessary with the code and the diagrams, if I might have missed important aspects that doesnt explain my problem clearly please let me know.