2025-11-25 12:55 AM - last edited on 2025-11-25 1:48 AM by Andrew Neil
Hi there.
I’m trying to generate a 12 ns pulse for a time-of-flight (ToF) application.
I’m using an STM32U5 microcontroller, and I’d like to know whether one of the general-purpose timers (TIM2/TIM3/TIM4/TIM5) can produce a pulse that narrow. With a 160 MHz timer clock, the time resolution is about 6 ns, so in principle it seems feasible, but I may be overlooking something.
Thanks!
2025-11-25 6:26 AM
I think you will need to get deeper into the reference manual of your MCU.
Most STM32 devices have a dozen or more timers, usually on different peripheral busses, while not all those busses support the same clock frequencies.
In most devices I worked with, the peripheral busses support only a maximum of core-clock/2.
I have no specific knowledge of STM32U5 devices, though.
2025-11-25 6:32 AM
hello @T_Hamdi , the frequency of the clock is set to 160MHz.
I checked also the value with LL_RCC_GetSystemClocksFreq().
Additonally, in the measurement I got the following: (see IMG_0794.jpeg).
which shows that the period between pulse is 1.25us. In the code, I set the period to 200 ticks:
LL_TIM_SetAutoReload(TIM2, 200);
therefore, we can confirm that the frequency is properly set (otherwise, the period would be different not 1.25us).
I have no clue what might be causing this issue.
2025-11-25 8:58 AM
Looks at least that you're quite close with 62.5 ns (?).
Check the timer registers, compare to ref manual. Is the "compare" register really set to 2 (or does this have the typical +1, wouldn't make sense in this case...) ?
The basic timer functions like this are not to hard to do with direct register settings.
2025-11-25 9:35 AM
What's your hardware, a "known-good" board like Nucleo or Disco, or your own?
Do you measure directly at the PA1 pin? What is connected to that pin?
JW
2025-11-25 9:36 AM
Preloading with one pulse mode is absurd, and too place in while
LL_TIM_EnableCounter(TIM2);
2025-11-25 9:39 AM
Yes, they all are mistakes, but neither of them should result in cca 10x longer pulse.
JW