Hi,
I am new to freeRTOS, I want to get the current time during an execution of a task.
I used xTaskGetTickCount() to get the number of ticks. how can I convert it to milliseconds ?
Hi,
I am new to freeRTOS, I want to get the current time during an execution of a task.
I used xTaskGetTickCount() to get the number of ticks. how can I convert it to milliseconds ?
Your FreeRTOSConfig.h file should have a constant configTICK_RATE_HZ, which gives the frequency of the tick interrupt.
time in ms would be : tick_count returned from xTaskGetTickCount() * (1/configTICK_RATE_HZ) * 1000
I would use xTaskGetTickCount() * (1000/configTICK_RATE_HZ) as if the rate is above 1 Hz, 1/configTICK_RATE_HZ will come out as zero, since integer division truncates fractions.
Yes, found that yesterday when used it in code. Somehow escaped my mind. Thanks for the correction
The macro pdTICKS_TO_MS()
has been added. You can use that.
The default definition of pdMS_TO_TICKS()
has recently changed .
It translates ms to a tick count.
See PR #866 for a description about the changes.
/* Get the time in MS. */
TickType_t currentTime = pdTICKS_TO_MS( xTaskGetTickCount() );
/* Delay for 1000 MS. */
vTaskDelay( pdMS_TO_TICKS( 1000U ) );