cancel
Showing results for 
Search instead for 
Did you mean: 

Generate a single pulse of 12ns with stm32u5

lucascalam
Visitor

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!

15 REPLIES 15

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.

lucascalam
Visitor

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.

LCE
Principal II

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.

waclawek.jan
Super User

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

Preloading with one pulse mode is absurd, and too place in while 

LL_TIM_EnableCounter(TIM2);

Yes, they all are mistakes, but neither of them should result in cca 10x longer pulse.

JW