0% found this document useful (0 votes)
15 views6 pages

Embedded Computer Systems

This document is an assignment exploring the differences between vTaskDelay and vTaskDelayUntil functions in FreeRTOS, highlighting their functionalities, interactions with the RTOS scheduler, and use cases. vTaskDelay is used for relative delays, while vTaskDelayUntil is for precise periodic task execution. Understanding these differences is crucial for designing efficient real-time systems.

Uploaded by

Mohamedberry210
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views6 pages

Embedded Computer Systems

This document is an assignment exploring the differences between vTaskDelay and vTaskDelayUntil functions in FreeRTOS, highlighting their functionalities, interactions with the RTOS scheduler, and use cases. vTaskDelay is used for relative delays, while vTaskDelayUntil is for precise periodic task execution. Understanding these differences is crucial for designing efficient real-time systems.

Uploaded by

Mohamedberry210
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Ain Shams University

Faculty of Engineering – Masters in Mechatronics Engineering

Embedded Computer Systems

Assignment 1

Understanding the Difference Between


vTaskDelay and vTaskDelayUntil in
FreeRTOS.

Name: Mohamed Maged Elsayed

ID: 2401845
1- Introduction:
Real-Time Operating Systems (RTOS) are designed to manage multiple tasks
efficiently, ensuring predictable behavior and real-time constraints. FreeRTOS, a
popular open-source RTOS, provides various task management functions, including
vTaskDelay and vTaskDelayUntil. These functions allow tasks to delay their
execution, which plays a crucial role in task scheduling and resource management.
This report explores their functionality, interaction with the RTOS scheduler, and
key differences.

2- vTaskDelay and Its Uses


vTaskDelay is a function that suspends a task for a specified number of tick periods.
The syntax for vTaskDelay is:

void vTaskDelay(const TickType_t xTicksToDelay);

How It Works:

• The function takes one parameter, xTicksToDelay, which specifies the number of
tick interrupts to wait.

• When a task calls vTaskDelay(xTicksToDelay), it enters the Blocked state and


remains inactive until the specified number of ticks elapses.

• After the delay period, the task transitions back to the Ready state, where it waits
for the scheduler to allocate CPU time.
Interaction with RTOS Scheduler:
• vTaskDelay is a relative delay function, meaning the delay starts from the
moment it is called.

• The function allows the RTOS scheduler to execute other tasks while the calling
task is delayed.

• It does not guarantee precise periodic execution but simply ensures a minimum
delay.

Example Usage:
The following example demonstrates a task that blinks an LED every 500ms using
vTaskDelay:

void LED_Task(void *pvParameters)

for (;;)

ToggleLED(); // Toggle LED state

vTaskDelay(pdMS_TO_TICKS(500)); // Delay for 500ms

Use Cases:
• Blinking an LED at fixed intervals.

• Waiting for a non-time-critical sensor to stabilize.

• Giving time for peripherals to initialize or complete operations.


• Adding a simple delay to avoid overwhelming a communication interface (e.g.,
UART).

• Yielding processor time in cooperative multitasking systems

3- vTaskDelayUntil and Its Uses


vTaskDelayUntil is used for creating tasks that need to execute at precise time
intervals. The function signature is:

void vTaskDelayUntil(TickType_t *pxPreviousWakeTime, const TickType_t


xTimeIncrement);

How It Works:
• The pxPreviousWakeTime parameter holds the last wake-up time and must be
maintained across function calls.

• The xTimeIncrement parameter specifies the exact time interval between


successive wake-ups.

• When a task calls vTaskDelayUntil, it calculates the next wake-up time and
enters the Blocked state until that time is reached.

Interaction with RTOS Scheduler:


• Unlike vTaskDelay, which starts the delay from the moment it is called,
vTaskDelayUntil ensures execution at fixed time intervals.

• It helps maintain precise task periodicity, making it suitable for real-time


applications where timing is crucial.

Example Usage:
The following example demonstrates a task that reads a sensor every 500ms using
vTaskDelayUntil:
void SensorTask(void *pvParameters)

TickType_t xLastWakeTime;

const TickType_t xFrequency = pdMS_TO_TICKS(500); // 500ms interval

// Initialize xLastWakeTime with the current time

xLastWakeTime = xTaskGetTickCount();

for (;;)

ReadSensor(); // Read sensor data

vTaskDelayUntil(&xLastWakeTime, xFrequency);

Use Cases:

• Reading sensor data at precise intervals (e.g., temperature, pressure).

• Logging system data every N millisecond for monitoring or debugging.

• Periodically updating a display or user interface.

• Sending heartbeat signals to indicate that the system is alive.

• Polling external hardware at accurate intervals.

• Triggering periodic control system calculations (e.g., PID controller updates)


4- Comparison: vTaskDelay
vs.vTaskDelayUntil:
Feature vTaskDelay vTaskDelayUntil

Delay Type Relative Absolute

Timing Less precise More precise


Accuracy

Scheduler Blocks task for a given delay Ensure fixed periodic


Interaction execution

Use Case General task delays Periodic task execution

Risk of Drift Yes, drift accumulates No, drift is corrected

5- Conclusion
Both vTaskDelay and vTaskDelayUntil serve essential roles in FreeRTOS task
management. vTaskDelay is useful for simple delays where timing precision is not
critical, while vTaskDelayUntil is preferred for periodic tasks requiring precise
execution timing. Understanding their differences and appropriate use cases helps
in designing efficient and predictable real-time systems.

6- Video Link:
https://drive.google.com/drive/folders/1meZyox2he7F8lKiqVc7yhIYXcC5Z1fqy?
usp=sharing

You might also like