Is it possible to get time in the order of 10^-7 or 10^-8 second?

Hello everyone,

I am working with STM32 F446RE on mbed studio. I have one question:

  • Is it possible to get time in the order of 10^-7 or 10^-8 second?.
    I only see a function to get time in microsecond which is not enough since I work with signals travelling with speed of light.

I hope to have your advice on this.
Thank you in advance,
Huy Nguyen.

For that level of precision I would use the hardware timers of the microcontroller directly. You measure time as precise as the clock speed of the timer peripheral, which is max. 90 MHz for APB2 for F446 (see ref manual 6.2). This means the smallest interval that you can measure is ~10ns.

You can even use the system clock, which is max. 180 MHz for F446. Take a look at the DWT_CYCCNT register, which can count the processor cycles.

Hello @boraozgen

Thank you for your response. I also thought about using that clock that you recommended.

Is there a function where I can obtain that clock in mbed? (something similar to Timer.read_high_resolution_us()).

I am asking this because the code I am running right now is from mbed. I can get the system clock using STM32Cube MX but I am not sure how to get that in mbed.

Best regards,
Huy Nguyen.

Mbed uses STM32Cube HAL internally. You can basically use the code generated from STM32CubeMX to set up your own timers. You have to make sure there are no collisions though. Don’t use a timer which is being used by Mbed. Maybe someone else here can tell which timers are already occupied by Mbed.

Hello @boraozgen,
I agree that I can use the code generated by STM32CubeMX to set up my timer in mbed and the code in mbed is built up by using the HAL library.
Maybe I am not correct in this case: The way I configure the clock is that I turn on the TIM10 (can be a different timer) and set the clock frequency in the “Clock Configuration” tab in CubeMX. The former leads to the initialization function of timer 10. The latter, I am not sure where it is indicated. That was why I asked if there is some functions that I can get the precision I want.

In default is TIMER5 (STM32F4 family) reserved for a ticker.

BR, Jan

1 Like

I found the place already. Thank you