Quality RTOS & Embedded Software

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


vTaskDelayUntil doesn't wait ?

Posted by Martin Cibulski on February 8, 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)))
staticportTickTypexLastWakeTime = 500;

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

RE: vTaskDelayUntil doesn't wait ?

Posted by woops_ on February 9, 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.

RE: vTaskDelayUntil doesn't wait ?

Posted by Martin Cibulski on February 9, 2008
Yes, initializing the xLastWakeTime to the actual time solved my problem.
Now my task runs every 100 ms as exspected.

Thank you,

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

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

Latest News

FreeRTOS kernel V10.0.1 is available for immediate download. Now MIT licensed.

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

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