cancel
Showing results for 
Search instead for 
Did you mean: 

FreeRTOS xTaskGetTickCount() erroneously skips ahead

asvatik
Associate
xTaskGetTickCount() erroneously skips ahead after every 65536 ticks. So when calculating timing using values returned by xTaskGetTickCount(), there are problems!
 
vTaskDelay() has no problems. The problem is with xTaskGetTickCount()...
 
For example:
Code:
 

 

TickType_t tickCount1, tickCount2;
while (1) {
	tickCount1 = xTaskGetTickCount();
	vTaskDelay(25);
	tickCount2 = xTaskGetTickCount();
	printf("[%ld] %lu ms have passed!\r\n",
			tickCount2, (tickCount2-tickCount1));
}

 

Output:

 

[64887] 25 ms have passed!
[64912] 25 ms have passed!
[64937] 25 ms have passed!
[64962] 25 ms have passed!
[66087] 1125 ms have passed!
[66112] 25 ms have passed!
[66137] 25 ms have passed!
[66162] 25 ms have passed!
[66187] 25 ms have passed!

 

 
Workaround is to use vTaskDelay() instead:
 

 

TickType_t tickCount = 0;
while (1) {
	vTaskDelay(25);
	tickCount += 25;
	printf("[%ld] %lu ms have passed!\r\n",
		xTaskGetTickCount(), tickCount);
}

 

 
PLATFORM:
Microprocessor: STM32L496xx (ARM Cortex-M4)
GNU Tools for STM32 (11.3.rel1)
FreeRTOS API CMSIS v2
FreeRTOS version 10.3.1
CMSIS-RTOS version 2.00
1 ACCEPTED SOLUTION

Accepted Solutions
asvatik
Associate

There is no problem with FreeRTOS. I let myself become fooled.

If I move my test-code to a separate task with a high enough priority, I am unable to reproduce the problem. 

View solution in original post

2 REPLIES 2
liaifat85
Senior II
asvatik
Associate

There is no problem with FreeRTOS. I let myself become fooled.

If I move my test-code to a separate task with a high enough priority, I am unable to reproduce the problem.