cancel
Showing results for 
Search instead for 
Did you mean: 

Is there any possibilities to produce nanosecond delay from STM32F4 Discovery ? because using HAL_Delay can only produce 1ms delay which is 500KHz

SSade
Associate II
1 ACCEPTED SOLUTION

Accepted Solutions
turboscrew
Senior III

Your Discovery board seems to have F407 on it, and you can run it with 168 MHz -> 6ns clock.

The closest you can get is 33 tick period = 5.05 MHz and 17 tick duty = 102 ns using a timer on APB2.

Timers 9, 10 and 11 are good candidates.

View solution in original post

7 REPLIES 7
turboscrew
Senior III

You mean 1ms delay between toggling gives you 500kHz?

I don't think you can get nanosecond delays in any way. A single instruction takes a couple - depending on your HCLK frequency. Is microsecond enough? Although I don't think HAL gives you those either. But you can set up a timer to give you that (= making your own clock).

Note that period of 180MHz is 5.56 ns.

SSade
Associate II

0690X000006Cni1QAC.jpgaaah i see, if iam set up timer for myself, how do i do that ?,

actually i want to produce 5MHz frequency as shown as above

You can't expect interrupts at such a rate bit you can use a high speed free running timer to observe the passage of time. For signal generation consider using a TIM to manage the pin directly. ​

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
turboscrew
Senior III

You want that kind of signal to show on a pin?

Then you need at least general purpose timer.

The easiest way is probably put that timer in a PWM mode with period of the frequency and duty cycle of the pulse width. That way the timer generats the signal without processor (except for setting it up).

Basically PWM mode is a kind of output compare mode, but easier to use.

And as a plus, you can change the pulse width on the fly by writing a new count value to the compare-register.

Note, however, that if it works well, depends on the chip you use - its frequency. Typically, with STM32s, the maximum count frequency of the timers is the HCLK., and that also gives the accuracy.

turboscrew
Senior III

BTW, what do you need nanosecond range timings for?

turboscrew
Senior III

Your Discovery board seems to have F407 on it, and you can run it with 168 MHz -> 6ns clock.

The closest you can get is 33 tick period = 5.05 MHz and 17 tick duty = 102 ns using a timer on APB2.

Timers 9, 10 and 11 are good candidates.

oh thank you very much, i will try it, so i have to manipulate te TIM function to produce the nanosecond timer

at first i need nanosecond delay because of with 200ns delay it equal with 5MHz, so i think if i can produce 200ns delay i already got what i want.

this 5MHz i will apply it in Ultrasound Tranducer.