Skip to main content
load2005
Associate III
October 16, 2026
Question

Wrong conversion time on ADC and two samples instead of one.

Hello,

I am using NUCLEO-U5A5ZJ-Q evaluation board.
I have configured ADC1 to do a single conversion and a software start.
I want to measure ADC conversion time.

My main test code looks like this

while(1)
{

    HAL_ADC_Start_IT(&hadc1);        
    HAL_Delay(1);        
    HAL_ADC_Stop_IT(&hadc1);
    adc_value = hadc1.Instance->DR;    
}

I have added a test pin for debugging. To check with oscilloscope.
I set pin high inside HAL_ADC_Start_IT just before ADC enabled.
And I reset pin inside interrupt procedure ADC1_2_IRQHandler.

I have connected oscilloscope to ADC input pin directly to see 
sample begin. As ADC capacitor is connected to input and it has some charge
it is possible to see discharge curve on the screen.

Here is the picture.

 

Yellow shows time between start and end of sampling.
Blue shows sampling begin (when capacitor is connected).

Why there are two discharge curves?
I have configured to do only one sample.
Also the timing is wrong.
I am using clock from external HSE.
It is 16MHZ. Divider is 32.
ADC is 12 bit so hold time is 12.5 clock cycles.
Sampling time is 5 clock cycles. (SPE is 0).
Now the time should be:
(12.5+5) * (1/16*32) = 35us

But the time on the screen is 55us.

I guess it is due to two samples but why there are two samples?

Here is screenshot from cube mx with ADC1 configuration.

Thanks.
 

1 reply

TDK
October 16, 2026

One spike when the channel is connected, another when it is disconnected. Maybe, not 100% sure.

Timing is “wrong” because you are toggling a pin before to start and after the end of the sampling, not at the same time, so there is overhead in your measurement. Toggling a pin is not an accurate method of directly timing the ADC sampling rate.

Do 100 samples using DMA to a single buffer and time it using the toggle pin method, then do 1100 samples and time it. Take the difference and divide by 1000. That will be an accurate measurement of the sampling rate.

"If you feel a post has answered your question, please click ""Accept as Solution""."