Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


Biasing task start times with vTaskDelayUntil

Posted by Richard on October 19, 2005
[moved from bug report to support forum]


I'm trying to bias or stagger task start times using
xLastWakeTime as in the examples for vTaskDelayUntil().

For example,

task1() does something like:

xLastWakeTime = xTaskGetTickCount();

for (EVER)

// Wait for the next cycle.
vTaskDelayUntil( &xLastWakeTime, xFrequency );

which is fine - it's my understanding since the tasks
are created before the scheduler starts - that
xLastWakeTime will be 0.

task2() does this:

xLastWakeTime = (xTaskGetTickCount() +
((portTickType)15 / portTICK_RATE_MS ));

for (EVER)

vTaskDelayUntil( &xLastWakeTime, xFrequency );


In this case - I'd expect task2() to run 15 ms after
task1 -
but at the same rate since xFrequency is the same in
both examples. Also - portTICK_RATE_MS = 1 since the
is running with a 1KHz tick rate.

What I'm seeing is that task2() is running much more
frequently than task1 - in some instances almost 15 times
more frequently. I don't understand why this is happening.

Thanks In Advance for your help,

RE: Biasing task start times with vTaskDelayUntil

Posted by Richard on October 19, 2005
I think the scenario is likely to be as follows:

For task 1 the first start time is 0.
For task 2 the second start time is 15.

Now if the scheduler started instantaniously task 2 would start 15 ticks after task 1, provided task 1 had either completed and blocked, or task 2 had priority higher than task 1.

However, the scheduler does not start instantly, and other code will first execute. If more than 15 ticks has gone by the start time for task 2 will have expired before it makes its first call to vTaskDelayUnilt(). As the time it wants to start is in the past it will execute immediately. It may therefore execute immediately following task 1 - or even before task 1 depending on their relative priorities and creation order.

I cannot explain yet while one task would run more frequently than the others. Can you provide a more full example of code exhibiting this problem? Is there any conflict between the various xLastWakeTime variables being used?

I have sent you a suggestion for how the desired task staggering might be accomplished.


[ Back to the top ]    [ About FreeRTOS ]    [ Privacy ]    [ Sitemap ]    [ ]

Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


FreeRTOS and other embedded software careers at AWS.

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers


STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner