Biasing task start times with vTaskDelayUntil

rtel wrote on Wednesday, October 19, 2005:

[moved from bug report to support forum]

Hello,

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
system
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,

rtel wrote on Wednesday, 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.

Regards.