Skip to main content
Huzaifah Limbada
Associate III
March 29, 2018
Question

Is it possible to generate delay in microseconds in STM32L053C6?

  • March 29, 2018
  • 9 replies
  • 1391 views
Posted on March 29, 2018 at 14:52

I'm using STM32L053C6 for the project and i'm using it on the 16 MHz clock frequency,

i want to generate the delay in the microseconds but i can't found any solution regurding this,

if anyone knows please share it,

Thank you!

#stm32l053 #stm32l053-discovery-board
This topic has been closed for replies.

9 replies

Huzaifah Limbada
Associate III
March 29, 2018
Posted on March 29, 2018 at 14:54

it may not C6 it, so you can share it for the STM32L053 also.

Uwe Bonnes
Chief
March 29, 2018
Posted on March 29, 2018 at 16:30

With some timer running, get the present value of the timer, calculate the value of the timer when the delay should end and wait until the timer reaches the expected value. Do expensive calculation when starting up. Care for timer roll-over.

Tesla DeLorean
Guru
March 29, 2018
Posted on March 29, 2018 at 18:41

Would agree, you could free run a TIM at 16 MHz or 1 MHz depending on the granularity you want

uint16_t start, current;

start = TIM2->CNT;

do

{

  current = TIM2->CNT;

} while((current - start) < 32); // 2us at 16 MHz tick

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
henry.dick
Associate II
March 30, 2018
Posted on March 30, 2018 at 17:03

I generally have a free running timer in my application. SysTick often but others do as well.

Time stamp a variable and wait for a set duration to expire.

Tesla DeLorean
Guru
March 30, 2018
Posted on March 30, 2018 at 17:16

The OP wants micro-second precision, not milli-second, and the CM0 doesn't provide access to 32-bit wide DWT_CYCCNT, and the SYSTICK counter goes backward, and is 24-bit making the wrapping math more tedious for tight loops.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
henry.dick
Associate II
March 30, 2018
Posted on March 30, 2018 at 19:32

'

the SYSTICK counter goes backward, and is 24-bit making the wrapping math more tedious for tight loops.'

so what? sounds like a non-issue.