I want to increase frequency of xTaskGetTickCount(); function. In normal, the frequency is 1 ms. However, my simple task’s execution time is lower than 1ms. My idea is the measure tick count within task.
Pseudo code is shown below.
static void simpletask()
{
while (1) {
//check tick count initial
printf(“print out …\n”);
fflush(stdout);
vTaskDelay(100);
//check tick count final and measure and get difference
}
}
thanks in advance
I want to increase frequency of xTaskGetTickCount(); function.
In normal, the frequency is 1 ms.
Indeed, the usual default for the clock-tick is 1000 Hz. It is defined in your FreeRTOSConfig.h file as:
#define configTICK_RATE_HZ ( 1000U )
However, my simple task’s execution time is lower than 1ms.
My idea is the measure tick count within task.
Yes it is possible to increase the rate of the system clock tick, by changing the above macro to for instance 10000U.
But I would not recommend to use the system clock tick for precise time measurement. There are “cheaper” and more precise ways for measuring time:
Most CPU’s have hardware timers, sometimes called timer/counter (tc). They can be programmed to run at any speed. You can have it run at e.g. 1 Mhz, and let it overflow every second ( or less often ). An ISR can be called that increments a second counter.
Pseudo code is shown below.
static void simpletask()
{
while (1)
{
//check tick count initial
printf(“print out …\n”);
fflush(stdout);
vTaskDelay(100);
//check tick count final and measure and get difference
}
}
Mind you that stdio functions like printf() and fflush() may not be implemented as you think they are. Please check the documentation of the implementation that you are using.
You find one example of using a TC for precise time measurement in an STM32H7x here.
The function ullGetHighResolutionTime()returns the number of uS passed since start-up as a 64-bit unsigned number.