0
0
FreeRTOSprogramming~30 mins

vTaskDelay() for periodic tasks in FreeRTOS - Mini Project: Build & Apply

Choose your learning style9 modes available
Using vTaskDelay() for Periodic Tasks in FreeRTOS
📖 Scenario: You are working on a simple embedded system using FreeRTOS. You want to create a task that prints a message every 1 second to simulate a periodic sensor reading.
🎯 Goal: Build a FreeRTOS task that uses vTaskDelay() to run periodically every 1 second and prints a message each time it runs.
📋 What You'll Learn
Create a task function named vPeriodicTask.
Use vTaskDelay() inside the task to wait for 1 second between prints.
Create the task in main() with a stack size of 100 and priority 1.
Print the message "Task running" each time the task runs.
💡 Why This Matters
🌍 Real World
Periodic tasks are common in embedded systems to read sensors, update displays, or communicate regularly.
💼 Career
Understanding how to use FreeRTOS task delays is essential for embedded software engineers working on real-time applications.
Progress0 / 4 steps
1
Create the periodic task function
Write a task function called vPeriodicTask that takes a void *pvParameters argument. Inside the function, write an infinite loop using for(;;). Inside the loop, print the message "Task running". Do not add any delay yet.
FreeRTOS
Need a hint?

Remember to use for(;;) for an infinite loop and printf to print the message.

2
Add delay using vTaskDelay()
Inside the infinite loop of vPeriodicTask, after the printf statement, add a call to vTaskDelay() to delay the task for 1000 milliseconds (1 second). Use pdMS_TO_TICKS(1000) to convert milliseconds to ticks.
FreeRTOS
Need a hint?

Use vTaskDelay(pdMS_TO_TICKS(1000)) to delay for 1 second inside the loop.

3
Create the task in main()
In main(), create the task vPeriodicTask using xTaskCreate(). Use a stack size of 100, priority 1, and pass NULL for parameters and task handle. Then start the scheduler with vTaskStartScheduler().
FreeRTOS
Need a hint?

Use xTaskCreate() with the correct parameters and then call vTaskStartScheduler().

4
Run and observe the periodic output
Run the program and observe the output. The program should print Task running every 1 second repeatedly.
FreeRTOS
Need a hint?

You should see the message Task running printed every second repeatedly.