How to know the adc sampling time?


the ADC sampling time could set in stm32cubemx or by c-code .
how to know the ADC sampling time in micropython?

Please see the ADC driver: micropython/ports/stm32/adc.c at 5452a286cb6491e7879cb664c5fa142b83b7f672 · openmv/micropython (github.com)

1 Like

micropython/ports/stm32/adc.c at 5452a286cb6491e7879cb664c5fa142b83b7f672 · openmv/micropython · GitHub

#line 334
#if defined(STM32F0)
    adch->Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4;        // 12MHz
    adch->Init.ScanConvMode = DISABLE;
    adch->Init.DataAlign = ADC_DATAALIGN_RIGHT;
    adch->Init.DMAContinuousRequests = DISABLE;
    adch->Init.SamplingTimeCommon = ADC_SAMPLETIME_55CYCLES_5;    // ~4uS
    #elif defined(STM32F4) || defined(STM32F7)
    adch->Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV2;
    adch->Init.ScanConvMode = DISABLE;
    adch->Init.DataAlign = ADC_DATAALIGN_RIGHT;
    adch->Init.DMAContinuousRequests = DISABLE;
###############################
#line 413
 #if defined(STM32F0)
    sConfig.SamplingTime = ADC_SAMPLETIME_55CYCLES_5;
    #elif defined(STM32F4) || defined(STM32F7)
    if (__HAL_ADC_IS_CHANNEL_INTERNAL(channel)) {
        sConfig.SamplingTime = ADC_SAMPLETIME_480CYCLES;
    } else {
        sConfig.SamplingTime = ADC_SAMPLETIME_15CYCLES;
    }

so,i get 15/24Mhz=0.625us. is it right?

    t = time.ticks_us()       
        
    Adc_rpm=Vadc_POT.read()
    
    delta = time.ticks_diff(time.ticks_us(), t)
    print('Vadc_POT.read Time = {:6.3f}us'.format(delta))

BUT , i run above code and get as following:
MPY: sync filesystems
MPY: soft reboot
Vadc_POT.read Time = 61.000us

how to reduce the read time?

Hi, you’ll need to tweak the firmware and get into how the driver works. The default code is good enough for basic analog value reading… it’s 10K samples per second right now. Which can do basic voice only audio. If you want that to be higher you’ll need to modify the firmware and push the hardware to go faster. This is not something we provide support for.

1 Like