Skip to main content
HA.5
Associate II
May 15, 2023
Question

Hi dear friends, How can i have an exact delay ? for example when i writhe HAL_Delay(1); i don't have exactly 1ms but 1,6ms for example. For example in my case between 2 PWM functions, Start and Stop, do you have any idea about that? Thank you

  • May 15, 2023
  • 3 replies
  • 872 views

..

This topic has been closed for replies.

3 replies

waclawek.jan
Super User
May 15, 2023

> for example when i writhe HAL_Delay(1); i don't have exactly 1ms but 1,6ms for example.

HAL_Delay(x) is a delay which lasts *at least* x ms, but may last more.

> How can i have an exact delay ?

Write your own, e.g. based on timers.

JW

HA.5
HA.5Author
Associate II
May 15, 2023

Thanks, is that possible if i use interrupt instead of delay in my case?

waclawek.jan
Super User
May 15, 2023

I don't know, this depends on your application.

If you mean a timer interrupt, i.e. set up a timer so that it will interrupt every 1ms and then perform the task you intended in that interrupt, then yes, the tasks will be executed 1ms apart - unless there is an interrupt with higher priority which takes too long.

JW