vTaskDelayUntil doesn't wait ?

martin_cibulski wrote on Friday, February 08, 2008:


I’m programming a motor controller in a task.
To have a constant schedule for my controller I use the vTaskDelayUntil function.
But I found that my controller worked much too fast.

So I wrote some test code into my task to find out how long vTaskDelayUntil actually waits.
(I don’t show all code to keep my posting small)
- - - - -

#define MOT_TASK_PERIOD    ((portTickType)100)
portTASK_FUNCTION (task_mot, pParameters __attribute__ ((unused)))
    static    portTickType    xLastWakeTime = 500;

    int            nMot;
    MOTOR*            pMot;
    int            nSpeedStep;
    int            nTick1, nTick2;
    DEBUG_LINE ("task_mot(.)");
    i2c_init (MOT_I2C_BUS_NO, MOT_I2C_KHZ);
    mot_init ();

    while (1) {
        nTick1 = xTaskGetTickCount();
        vTaskDelayUntil (&xLastWakeTime, MOT_TASK_PERIOD);
        nTick2 = xTaskGetTickCount();
- - - - -

When I debug the task and stop behind these statements, the variables
have the following values:
nTick1         3    (OK, only 3 milliseconds since system start)
xLastWakeTime  600  (which is 500 + MOT_TASK_PERIOD)
nTick2         3    (should be at least 600)

Why is nTick2 not 600 or more ?
vTaskDelayUntil should wait until 600 Ticks have been counted, right ?

I use FreeRTOS 4.7.1 on an LPC2148 with GCC.
The same happened with an earlier release (4.5 ?).

What did I do wrong here ?

Thanks for help,

woops_ wrote on Saturday, February 09, 2008:

You initialized xLastWakeTime to an arbitrary value and this probably makes the scheduler think the actual time has overflowed since vTaskDelayUntil was called. You can step into vTaskDelayUntil to check this. Try initializing the xLastWakeTime to the actual time as shown in the API doc example. If this does not fix your problem check the tick is actually running.

martin_cibulski wrote on Saturday, February 09, 2008:

Yes, initializing the xLastWakeTime to the actual time solved my problem.
Now my task runs every 100 ms as exspected.

Thank you,