# Tasks are not switching properly

**URL:** <https://forums.freertos.org/t/tasks-are-not-switching-properly/7124>\
**Category:** Kernel\
**Created:** [April 11, 2018, 1:26am UTC](https://forums.freertos.org/t/tasks-are-not-switching-properly/7124 "2018-04-11T01:26:26Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [April 11, 2018, 1:26am UTC](https://forums.freertos.org/t/tasks-are-not-switching-properly/7124/1 "2018-04-11T01:26:26Z")

</div>

**[rolo90](https://sourceforge.net/u/rolo90/)** wrote on [Wednesday, April 11, 2018](https://sourceforge.net/p/freertos/discussion/382005/thread/55b29684/#c61e):

Hello everyone,

I’m new to FreeRTOS and I’m playing around with creating tasks and understanding core concepts. Currently I’m using TivaC launchpad board and I’m stuck in the following problem,

I’m creating 2 tasks with equal priority, where each task will TURN ON the onboard TivaC LED and the other task will TURN OFF the onboard TivaC LED. However context switching is not happening at the appropriate time as my configTICK\_RATE\_HZ is set to 1000 (1s). Therefore the LED doesn’t blink at a rate of 1s and the LED is just ON.

Code looks like,

void FirstTask( void \*pvParameters )  
{  
for(;😉  
{  
GPIOF-\>DATA = 0x0;  
}  
}

void SecondTask( void \*pvParameters )  
{  
for(;😉  
{  
GPIOF-\>DATA = 0x2;  
}  
}

int main()  
{  
Initializing\_LEDs(); // Implementation not shown

//Creating Task  
xTaskCreate( FirstTask, “firstTask”, 256, NULL, 1, NULL );  
xTaskCreate( SecondTask, “secondTask”, 256, NULL, 1, NULL );

//Starting Scheduler  
vTaskStartScheduler();

for(;;);  
}

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [April 11, 2018, 1:32am UTC](https://forums.freertos.org/t/tasks-are-not-switching-properly/7124/2 "2018-04-11T01:32:18Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Wednesday, April 11, 2018](https://sourceforge.net/p/freertos/discussion/382005/thread/55b29684/#c61e/92dd):

What are you observing when the tasks run? You say the LED is not  
switching at the right time - is it switching all, too fast, to slow or  
erratically?

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [April 11, 2018, 1:36am UTC](https://forums.freertos.org/t/tasks-are-not-switching-properly/7124/3 "2018-04-11T01:36:02Z")

</div>

**[rolo90](https://sourceforge.net/u/rolo90/)** wrote on [Wednesday, April 11, 2018](https://sourceforge.net/p/freertos/discussion/382005/thread/55b29684/#3134):

I saw on the oscilloscope that the LED toggles at a rate of microseconds.

---

<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:** [April 11, 2018, 1:41am UTC](https://forums.freertos.org/t/tasks-are-not-switching-properly/7124/4 "2018-04-11T01:41:02Z")

</div>

**[richard\_damon](https://sourceforge.net/u/richard_damon/)** wrote on [Wednesday, April 11, 2018](https://sourceforge.net/p/freertos/discussion/382005/thread/55b29684/#30a0):

configTICK\_RATE\_HZ of 1000 means 1 MILLISECOND per tick (1000 Hz), not 1 second.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [April 11, 2018, 1:49am UTC](https://forums.freertos.org/t/tasks-are-not-switching-properly/7124/5 "2018-04-11T01:49:24Z")

</div>

**[rolo90](https://sourceforge.net/u/rolo90/)** wrote on [Wednesday, April 11, 2018](https://sourceforge.net/p/freertos/discussion/382005/thread/55b29684/#1370):

Ohh! I’ll check that silly mistake. Will post results here

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [April 11, 2018, 7:26am UTC](https://forums.freertos.org/t/tasks-are-not-switching-properly/7124/6 "2018-04-11T07:26:40Z")

</div>

**[rolo90](https://sourceforge.net/u/rolo90/)** wrote on [Wednesday, April 11, 2018](https://sourceforge.net/p/freertos/discussion/382005/thread/55b29684/#1168):

Currently the configCPU\_CLOCK\_HZ is set to 16,000,000 and configTICK\_RATE\_HZ is set to 2 . Therefore I should expect to see the LED blinking every 500ms. However the LED blinks at a rate of 160ms.

Any thoughts on this?

---

<div class="post-metadata">

**Author:** ![htibosch](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/htibosch/32/62_2.png) [@htibosch](https://forums.freertos.org/u/htibosch)\
**Post date:** [April 11, 2018, 8:47am UTC](https://forums.freertos.org/t/tasks-are-not-switching-properly/7124/7 "2018-04-11T08:47:15Z")

</div>

**[heinbali01](https://sourceforge.net/u/heinbali01/)** wrote on [Wednesday, April 11, 2018](https://sourceforge.net/p/freertos/discussion/382005/thread/55b29684/#9a51):

What CPU are you using? Have you looked up it’s “usual” operating speed?  
A tick-rate `configTICK_RATE_HZ` of `2` is very low: are there any overflows or underflows while calculating the clock settings?

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [April 12, 2018, 3:26am UTC](https://forums.freertos.org/t/tasks-are-not-switching-properly/7124/8 "2018-04-12T03:26:03Z")

</div>

**[rolo90](https://sourceforge.net/u/rolo90/)** wrote on [Thursday, April 12, 2018](https://sourceforge.net/p/freertos/discussion/382005/thread/55b29684/#c034):

Thanks, I manage to solve it. It was a misproper clock configuration on one of the CMSIS clock config file. Now the tasks are switching properly
