# Tick rounding

**URL:** <https://forums.freertos.org/t/tick-rounding/5637>\
**Category:** Kernel\
**Created:** [April 30, 2014, 5:49am UTC](https://forums.freertos.org/t/tick-rounding/5637 "2014-04-30T05:49:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [April 30, 2014, 5:49am UTC](https://forums.freertos.org/t/tick-rounding/5637/1 "2014-04-30T05:49:22Z")

</div>

**[znatok](https://sourceforge.net/u/znatok/)** wrote on [Wednesday, April 30, 2014](https://sourceforge.net/p/freertos/discussion/382005/thread/f7712e97/#53de):

Hi,  
If I need guaranteed at least 2 ticks delay should I use  
vTaskDelay( 2 ) or  
vTaskDelay( 3 ) ?

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [April 30, 2014, 8:08am UTC](https://forums.freertos.org/t/tick-rounding/5637/2 "2014-04-30T08:08:00Z")

</div>

**[davedoors](https://sourceforge.net/u/davedoors/)** wrote on [Wednesday, April 30, 2014](https://sourceforge.net/p/freertos/discussion/382005/thread/f7712e97/#85ad):

vTaskDelay(3) means 3 tick interrupts from the time the function is called. The function will be called part way through a time slice so the first tick interrupt will come after a fraction of a time slice, the second one complete time slice later, and the third another complete time slice after that. So 3 is your answer because it means two complete time slices plus whatever fraction of a time slice is left between when the function is called and the next tick interrupt.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [April 30, 2014, 10:18am UTC](https://forums.freertos.org/t/tick-rounding/5637/3 "2014-04-30T10:18:58Z")

</div>

**[znatok](https://sourceforge.net/u/znatok/)** wrote on [Wednesday, April 30, 2014](https://sourceforge.net/p/freertos/discussion/382005/thread/f7712e97/#85ad/fa44):

Thanks.  
That’s exactly what I was asking for.

Now another question.

My task blocks on  
rc = xQueueReceive( xQueue, data, xTicksToWait );  
Queue is updated from UART IRQ for example.

If xTicksToWait expires but due to low priority task is not executed for  
some time. And during this time IRQ executed and Queue updated.  
What would xQueueReceive return in this case?  
In other words who has a higher precedence expiration, Queue update of  
first occurred between two?

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [April 30, 2014, 10:46am UTC](https://forums.freertos.org/t/tick-rounding/5637/4 "2014-04-30T10:46:10Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Wednesday, April 30, 2014](https://sourceforge.net/p/freertos/discussion/382005/thread/f7712e97/#ad06):

If:

1. A task is blocked on a queue.
2. The task unblocked because there is a time out, but because of its priority it does not run.
3. An interrupt writes to the queue
4. The task does get some CPU time after the interrupt has written to the queue

then…

The xQueueReceive() function will return pdPASS and the item that was written to the queue between the task unblocking and the task actually running.

Regards.
