Microsecond level periodic task (~50us)

Hi, I’m trying to create a task that runs periodically every 50 µs.
Due to some design constraints, I need to perform the work inside a task, not in the ISR.

After doing some research, I’ve found two possible approaches

  1. Increase configTICK_RATE_HZ to 20,000 (50 µs) and use vTaskDelayUntil() to block the task with a 50 µs period.
  2. Keep configTICK_RATE_HZ at 1000 (1 ms) and instead use a hardware timer that triggers every 50 µs. In the timer ISR, I call vTaskNotifyGiveFromISR() to unblock the task.

I understand increasing configTICK_RATE_HZ will result in more context switch
But in other hand, hardware timer + vTaskNotifyGiveFromISR() also cause context switch

My question is:
Do both methods result in same overhead and CPU load?
I’m trying to confirm the method has fewer drawback and less impact on the system

Many thanks for any leads and help!

Using a higher tick rate will add more load to the system then just using a hardware timer to unblock the task at a high rate, as there are other scheduling operations looked at on the system tick. It isn’t just the context switches.

Be very careful to evaluate and measure the load you are going to put on your system. Hopefully your processor is running in the multiple 100s of MHz, our you may be underpowered to do the work

Note knowing the reasons you say you can’t do the work in the ISR, I would still suggest looking if the most critical parts can be done there, and perhaps not need to activate the task every time, as the ISR entry/exit is MUCH faster triggering a task switch.

Thanks so much for the advise. I’ll see if I can move the critical parts to ISR.
Really appreciate your help!