1 uS delay with timer ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2017-03-19 1:51 PM
Hello Everyone,
Does every one know on how to create a simple 1 uS delay with timer ?
Thanks
#stm32f1xx #timer #delay-1us- Labels:
-
STM32F1 Series
-
TIM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2017-03-19 1:56 PM
I've made :
void Delay(int nTime)
{
unsigned int i;
unsigned long j;
for(i = nTime;i > 0;i--)
for(j = 1000;j > 0;j--);
}�?�?�?�?�?�?�?
but not sure how much delay I got on every loop ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2017-03-19 2:43 PM
Configure a TIM at 1 MHz, so TIMx->CNT ticks each 1us
Perhaps better just to let the TIM clock at maximal speed, at 72 MHz, 1us would be 72 ticks, at 36 MHz, 36 ticks
uint16_t start = TIMx->CNT;
while((TIMx->CNT - start) < 36);
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2017-03-19 3:55 PM
and wrap that code as a function delay_us(start) ?
I'll give a try...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2017-03-19 4:06 PM
SW delays are easy traps in bare metal coding unless doing gpio direct manipulation. To be more flexible, use the output compare channels of a timer to set a flag when the programmed time has elapsed. This way, the sw can do other thing in the background while waiting. As a bonus, this compare can flip a gpio at the exactly programmed time.
