How do we add sleep/delay in microsecond [ 20 to 65535us (microsecond)] range in FreeRTOS Firmware to block execution?

Hi Team,

We want to add delay/sleep of 20 to 65,535 us (microsecond) range b/w 2-operation and block execution of task for that time.

We have checked “vTaskDelay()” and that APIs add delay of ticks which is supported in millisecond (pdMS_TO_TICKS). Is it correct ?

=============================================================

const TickType_t timeInTick = pdMS_TO_TICKS(timeInMs);

vTaskDelay(timeInTick);

=============================================================

In that case how do we add delay of microsecond [20 to 65535us (microsecond) range] range in FreeRTOS Firmware?

Thanks,
Nisarg

FreeRTOS doesn’t have any direct resource for that.

The typical way to do that is using a hardware timer programmed to interrupt in that time interval that notifies the task (which blocks for that notification) or for the shorter end, just use a spin wait loop.

One thing you need to look at is how fast is your processor and how long will it take to do a context switch. Also, how critical is your timing, anything at the task level has the issue that a higher priority task can make things take longer.

The typical way to do that is using a hardware timer programmed to interrupt in that time interval that notifies the task

This is I exactly what I would recommend doing if you need microsecond level accuracy. Increasing the FreeRTOS tick frequency to support a microsecond period could cause significant inefficiencies due to a context switch taking up a majority of the tick period. If you only need something in the range of milliseconds (like 1,000->65,535us mentioned above) you could use the FreeRTOS tick with a 1kHz frequency.