求助!如何在ESP32上获得一个微妙级延时

lqzero
Posts: 14
Joined: Mon Jul 22, 2019 2:22 am

求助!如何在ESP32上获得一个微妙级延时

Postby lqzero » Mon Jul 22, 2019 9:44 am

RT

jiangteng
Posts: 25
Joined: Wed Jan 30, 2019 7:08 am

Re: 求助!如何在ESP32上获得一个微妙级延时

Postby jiangteng » Tue Aug 06, 2019 5:56 am

  1. #include "sys/unistd.h"
  2. //....
  3. usleep(1000);
  4. //....

ESP_Dazz
Posts: 308
Joined: Fri Jun 02, 2017 6:50 am

Re: 求助!如何在ESP32上获得一个微妙级延时

Postby ESP_Dazz » Tue Aug 06, 2019 6:09 am

其实usleep()底层会调用ets_delay_us(),可以考虑直接用ets_delay_us()
  1. #include "esp32/rom/ets_sys.h"
  2. ...
  3. ets_delay_us(1000);

lqzero
Posts: 14
Joined: Mon Jul 22, 2019 2:22 am

Re: 求助!如何在ESP32上获得一个微妙级延时

Postby lqzero » Tue Aug 06, 2019 9:17 am

两个函数都试过啦 ,都不是很准,自己用定时器搞定啦。谢谢两位

assinass
Posts: 1
Joined: Thu Aug 22, 2019 7:52 am

Re: 求助!如何在ESP32上获得一个微妙级延时

Postby assinass » Thu Aug 22, 2019 7:57 am

;) 用用这个如何,延时100us:

Code: Select all

#include "freertos/FreeRTOS.h"

vTaskDelay(100 / portTICK_PERIOD_MS);

dialoger
Posts: 1
Joined: Fri Jan 08, 2021 9:08 am

Re: 求助!如何在ESP32上获得一个微妙级延时

Postby dialoger » Fri Jan 08, 2021 9:10 am

lqzero wrote:
Tue Aug 06, 2019 9:17 am
两个函数都试过啦 ,都不是很准,自己用定时器搞定啦。谢谢两位
你好 请问你是怎么解决的呢

zmlee79
Posts: 2
Joined: Tue Feb 09, 2021 3:50 pm

Re: 求助!如何在ESP32上获得一个微妙级延时

Postby zmlee79 » Tue Feb 09, 2021 4:18 pm

esp32 上有 __rdtsc(), 不用计时器就可用很精确的延时, 特别是关掉中断的时候超级准, 像这样 跑 240M 的时候 delay_clock(240) 就是一微秒, 我经常用这个来延时 0.1 微秒用 。。

static __inline void delay_clock(int ts)
{
uint32_t start, curr;

__asm__ __volatile__("rsr %0, ccount" : "=r"(start));
do
__asm__ __volatile__("rsr %0, ccount" : "=r"(curr));
while (curr - start <= ts);
}

muyisoldier
Posts: 2
Joined: Mon Oct 25, 2021 9:22 am

Re: 求助!如何在ESP32上获得一个微妙级延时

Postby muyisoldier » Mon Dec 06, 2021 7:09 am

lqzero wrote:
Tue Aug 06, 2019 9:17 am
两个函数都试过啦 ,都不是很准,自己用定时器搞定啦。谢谢两位
您好,我也想知道怎么解决的,我用定时器最小只能获取4us的脉冲,再小esp32就不断重启

Who is online

Users browsing this forum: No registered users and 68 guests