Is this optimal?
Code: Select all
vTaskDelay(configTICK_RATE_HZ / 20000); // 50us
Code: Select all
vTaskDelay(configTICK_RATE_HZ / 20000); // 50us
Hi,ESP_Angus wrote:The RTOS tick period is (by default) 1ms, so vTaskDelay() will round this down to 0 ticks, and you'll either get no delay or a full time slice (1ms) delay while another task runs. It's not advisable to make the tick period any shorter than 1ms.
The ROM function ets_delay_us() (defined in rom/ets_sys.h) will allow you to busy-wait for a correct number of microseconds. Note that this is busy-waiting, so unlike vTaskDelay it does not allow other tasks to run (it just burns CPU cycles.)
Also it doesn't guarantee that the task won't be preempted by a higher priority task or an interrupt, although you send that longer delays don't matter so this is probably OK in your case.
Code: Select all
#include "freertos/FreeRTOS.h"
#define NOP() asm volatile ("nop")
unsigned long IRAM_ATTR micros()
{
return (unsigned long) (esp_timer_get_time());
}
void IRAM_ATTR delayMicroseconds(uint32_t us)
{
uint32_t m = micros();
if(us){
uint32_t e = (m + us);
if(m > e){ //overflow
while(micros() > e){
NOP();
}
}
while(micros() < e){
NOP();
}
}
}
Thanks for your response..burgersonbrioche wrote: ↑Sat May 04, 2019 11:09 pmThe arduino-esp32 core achieves this using the following code for the delayMicroseconds() func.I know this is a bit of an old thread but hoping this will help if anyone runs into this issue.Code: Select all
#include "freertos/FreeRTOS.h" #define NOP() asm volatile ("nop") unsigned long IRAM_ATTR micros() { return (unsigned long) (esp_timer_get_time()); } void IRAM_ATTR delayMicroseconds(uint32_t us) { uint32_t m = micros(); if(us){ uint32_t e = (m + us); if(m > e){ //overflow while(micros() > e){ NOP(); } } while(micros() < e){ NOP(); } } }
Users browsing this forum: No registered users and 60 guests