# Brief task suspension when using xTaskCreate - FreeRTOS on ESP32

**URL:** <https://forums.freertos.org/t/brief-task-suspension-when-using-xtaskcreate-freertos-on-esp32/14497>\
**Category:** Kernel\
**Created:** [February 16, 2022, 4:41pm UTC](https://forums.freertos.org/t/brief-task-suspension-when-using-xtaskcreate-freertos-on-esp32/14497 "2022-02-16T16:41:09Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![willESP32](https://avatars.discourse-cdn.com/v4/letter/w/ce73a5/32.png) [@willESP32](https://forums.freertos.org/u/willESP32)\
**Post date:** [February 16, 2022, 4:41pm UTC](https://forums.freertos.org/t/brief-task-suspension-when-using-xtaskcreate-freertos-on-esp32/14497/1 "2022-02-16T16:41:09Z")

</div>

I have boiled a problem I am having down to something really simple - a function toggling a pin high and low very quickly.

If I do not use freeRTOS I get a continuous oscillation on the output pin, see photo.  
However if I use the code below I get output on oscilloscope (1ms/div):

Approximately every 1ms, the pin does not toggle for around 1ms

 ![Scope](https://d2v6vdsk2p900z.cloudfront.net/original/2X/2/259231aaf57f55aac4a613f18b643ebb9c094194.png)

Here is my code:

```auto
void task1(void* pvParameters)
{
  for(;;)
  {     
    digitalWrite(27, HIGH);
    digitalWrite(27, LOW);
  }
}

void setup()
{
  pinMode(26,OUTPUT);
  pinMode(27,OUTPUT);

  // creates task to pack adc on core 1 indefinitely (for multithreading)
  xTaskCreatePinnedToCore(task1, "task1", 6080, NULL, 0, NULL, 1);
}

void loop()
{ 
  vTaskDelete(NULL);
}

```

Any suggestions as to why I get this task suspension and how to remove it will be much appreciated.

Cheers,

Will

---

<div class="post-metadata">

**Author:** ![jefftenney](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/jefftenney/32/1314_2.png) [@jefftenney](https://forums.freertos.org/u/jefftenney)\
**Post date:** [February 16, 2022, 5:10pm UTC](https://forums.freertos.org/t/brief-task-suspension-when-using-xtaskcreate-freertos-on-esp32/14497/2 "2022-02-16T17:10:23Z")

</div>

Do you have any other tasks on that core?

Is this task’s priority set to zero? [Edit: I see you posted that code – yes, it is set to priority zero.] If so, did you define `configIDLE_SHOULD_YIELD` to zero?

Is the `loop()` function you posted relevant to your question?

---

<div class="post-metadata">

**Author:** ![aggarg](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/aggarg/32/4245_2.png) [@aggarg](https://forums.freertos.org/u/aggarg)\
**Post date:** [February 16, 2022, 6:49pm UTC](https://forums.freertos.org/t/brief-task-suspension-when-using-xtaskcreate-freertos-on-esp32/14497/3 "2022-02-16T18:49:24Z")

</div>

Or you can try increasing the priority of your task.

---

<div class="post-metadata">

**Author:** ![willESP32](https://avatars.discourse-cdn.com/v4/letter/w/ce73a5/32.png) [@willESP32](https://forums.freertos.org/u/willESP32)\
**Post date:** [February 17, 2022, 9:18am UTC](https://forums.freertos.org/t/brief-task-suspension-when-using-xtaskcreate-freertos-on-esp32/14497/4 "2022-02-17T09:18:22Z")

</div>

Well that was easy. I thought that priority levels were just relative to each other but I guess it also sets how much the scheduler conducts the task. Much appreciated

---

<div class="post-metadata">

**Author:** ![richard-damon](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/richard-damon/32/38_2.png) [@richard-damon](https://forums.freertos.org/u/richard-damon)\
**Post date:** [February 17, 2022, 12:29pm UTC](https://forums.freertos.org/t/brief-task-suspension-when-using-xtaskcreate-freertos-on-esp32/14497/5 "2022-02-17T12:29:38Z")

</div>

No, not in the sense of an OS like Windows where a low priority task will get less time than a higher priority task if both are compute-bound.

Task Priority is STRICTLY observed, if a higher priority task is ready, it will be switched to at the earliest possible allowed instance (depending on things like is pre-emption allowed), and it will be given the CPU until it no longer needs it, or another task of higher priority (or equal if time-slicing is enabled) becomes ready.

There is one task that is ALWAYS ready to run, the idle task, as FreeRTOS doesn’t know how to ‘stop’ a CPU and make it do nothing, so has this idle task to use up any otherwise unneeded CPU time.

---

<div class="post-metadata">

**Author:** ![jefftenney](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/jefftenney/32/1314_2.png) [@jefftenney](https://forums.freertos.org/u/jefftenney)\
**Post date:** [February 17, 2022, 2:09pm UTC](https://forums.freertos.org/t/brief-task-suspension-when-using-xtaskcreate-freertos-on-esp32/14497/6 "2022-02-17T14:09:36Z")

</div>

To add to Richard’s explanation, any tasks you put at priority zero are time sliced with the idle task. To prevent the idle task from taking an entire timeslice when another task is ready to run at priority zero, set `configIDLE_SHOULD_YIELD` to 1 (or don’t set it at all, which results in the default setting of 1).
