Again, i want to know specifically about latency.
Richard already answered this question:
Their time resolution is basically the same as that
for tasks – which is whatever configTICKRATE
HZ is set to
There are many ways to implement “a timer”. Here are some examples:
timers.c : this is convenient if you want a function to be called at a certain moment or regularly at fixed intervals. If the tick-rate is 1000 Hz, then the expected latency is at most a ms, unless your CPU is busy running higher-priority tasks.
Note that the call-back function will be called from the timer task. So it will not have the usual stack and priority of your own task.
The properties of the timer task are configurable:
STACKDEPTH // The size of the stack
TASK_PRIORITY // The priority of the timer task
- Construct your own timer using these functions:
TickTypet xTaskGetTickCount( void )
void vTaskSetTimeOutState( pxTimeOut )
t xTaskCheckForTimeOut( pxTimeOut, pxTicksToWait )
or read-out some Timer/Counter (a so-called hardware timer).
In C++ I often use two classes: CTimer and CAlarmTimer. The former is used to measure time, the latter is used as an alarm clock.
The advantage of these “timers” is that they can be used directly in my own tasks. The downside is that these objects must be polled.
- Create your own TC interrupt. This is probably what you call a hardware-timer.
This can give the best time resolution.
As an example:
/* An example of a Timer/Counter interrupt that wakes up a task. */
void TC3_Handler ()
BaseType_t xHigherPriorityTaskWoken = 0;
/* Send a message to the task to unblock it. */
< EDIT >
Use one of these solutions: TaskNotify or
< EDIT >
vTaskNotifyGiveFromISR( xEMACTaskHandle, &xHigherPriorityTaskWoken )
xQueueSendFromISR( xMyQueue, pxItem, &xHigherPriorityTaskWoken );
portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
void vMyTask( void *pvParameters )
for( ;; )
/* No events to process now, wait for the next. */
< EDIT >
Use one of these solutions: either TaskNotify
or use a queue, not both.
< EDIT >
ulTaskNotifyTake( pdFALSE, ulMaxBlockTime );
xResult = xQueueReceive( xMyQueue, pvBuffer, ulMaxBlockTime )
if( xResult != pdFALSE )
/* TC3 expired: do something urgent. */
It is not recommended to write a lot of code within an ISR. It is best to wake-up (unblock) a task. The latency (the time between the ISR and the task waking up) is very short, normally much less than a ms. Again: unless your CPU is busy running higher-priority tasks.
These are just some examples, the choice is yours.