vTaskDelay doesn´t delay a regular time

reny09 wrote on Friday, March 07, 2008:

Hi Everybody:
             I have a trouble vTaskDelay that I can´t understand. Surely It´s easy but I can´t find it.

If I execute the following code in a Task of the second highest priority, it doesn´t block 20 ticks everytime. Sometimes remains blocked until the following post on the queue and sometimes it last 20 ticks. I checked that the upper task, wich post on this queue, doesn´t stay freezing the system.

  for(;:wink:
    {
      if( xQueuePeek( xQueue_Tx_Rf_local, bBuffer , portMAX_DELAY) )
        {
              vTaskDelay(20);
              .
              .
        }
    }

I have another task with a lower priority that executes vTaskDelay correctly. If I use a for{} delay instead of vTaskDelay() everything works ok. What could be the cause that block vtaskDelay a different time of 20 ticks

I am using a MSP430 port.

   Thanks Reny09

davedoors wrote on Friday, March 07, 2008:

>   for(;:wink:
>     {
>       if( xQueuePeek( xQueue_Tx_Rf_local, bBuffer , portMAX_DELAY) )
>         {
>               vTaskDelay(20);
>               .
>               .
>         }
>     }

What comes after the vTaskDelay(20)? Are you guaranteed to know if it goes around the loop again.

The first thing to check is stack issues. This is the most usual cause of problems. You could try the new uxTaskGetStackHighWatermark() function, or you could simply try allocating more stack to this task.

reny09 wrote on Sunday, March 09, 2008:

Thanks davedoors for your suggestion. I have checked the stack, and there is enough room. So I´dont know what I could be doing wrong.

After the delay I check a pin and then I enter in a Critical Section writing on a SPI bus. I don´t know if going through a critical section could affect. When I´ve checked the work of delay I toggled a Led before and after of vTaskDelay() and watching it with the oscillocope is when I saw that makes the erratic work.

             Bye  Reny09

woops_ wrote on Sunday, March 09, 2008:

I presume you are not waiting in the critical section for the SPI transfer to complete?

reny09 wrote on Tuesday, March 11, 2008:

Hi woops_.
          I will check your suggestion. Also I will test disabling other tasks in order to test which one is blocking vTaskDelay. Now I am using a for based delay and everything works fine.

            Bye