Tasks are not switching properly

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 configTICKRATEHZ 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(;;); }

Tasks are not switching properly

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?

Tasks are not switching properly

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

Tasks are not switching properly

configTICKRATEHZ of 1000 means 1 MILLISECOND per tick (1000 Hz), not 1 second.

Tasks are not switching properly

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

Tasks are not switching properly

Currently the configCPUCLOCKHZ is set to 16,000,000 and configTICKRATEHZ 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?

Tasks are not switching properly

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?

Tasks are not switching properly

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