Report
4 years, 2 months ago.

AnalogIn() reading speed (Sampling rate) of STM32F401RE shows weird results

Hi, I have the following code to test the speed of analogin.read( ) on STM32F401RE. Right after flashing the code, the time for analog read is 5us. However, if I press reset button on the board (the black one), then the time it takes is 44us. Does anyone know why?

ADC analogin speed test

#include "mbed.h"
Timer t;
float x;
AnalogIn   ain(A0);

int main(void)
{
    t.start();
    x = ain.read();
    t.stop();
    printf("time for analog read: %d\r\n", t.read_us());
    printf("read data: %f\r\n", x);
    
    
}

logs of the above program (first run and subsequent runs after pressing of reset button

Logs: 
time for analog read: 5
read data: 0.303297
time for analog read: 44
read data: 0.224420
time for analog read: 44
read data: 0.217338
time for analog read: 44
read data: 0.179976

Question relating to:

Comment on this question

1 Answer

3 years, 5 months ago.

How about if you try loop ? like .. t.start(); for(int i=0; i<100; i++) { x = ain.read(); } t.stop();

The result may be 44uS + 99*5us, if so, it shows more start-up time is required after reset by button.


To post an answer, please log in.