FreeRTOS tick interrupt not accurate

kyanc wrote on Friday, May 24, 2019:


I’m new to embedded RTOS and I have encountered an issue where vTaskDelay() is not accurate.

i’m running a “FreeRtos Sam Example” project on Atmel Studio (SAME70 Board) that blinks the LED at a fixed rate.

led task code as follows:
static void task_led(void *pvParameters)

for( ; ; ) {


This task is triggered every two seconds instead of one second (as intended by vTaskDelay(1000)). I did not make any changes to the code, configCPU_CLOCK_HZ is set as 1000.

Can anyone verify if this is true or point out the direction which I should be looking to check for sysTick rate?


heinbali01 wrote on Friday, May 24, 2019:

You code looks Ok.
So what you observe is a LED that is on for 2 seconds, and then off for 2 seconds?
I would check the clocks of the SAME70 at start-up: is it assuming a correct speed of the X-tal? Is the processor running at the expected speed?

rtel wrote on Friday, May 24, 2019:

The value of configCPU_CLOCK_HZ looks suspicious. Are you using the
SysTick clock to generate tick interrupts? If so I would expect it to
be in the MHz range, not 1Khz.

heinbali01 wrote on Saturday, May 25, 2019:

Maybe the following helps:

configCPU_CLOCK_HZ is the clock rate of the CPU, up to 300 MHz for SAM E70
configSYSTICK_CLOCK_HZ is the clock rate that feeds the systick, possibly the same as configCPU_CLOCK_HZ
configTICK_RATE_HZ is the desired FreeRTOS tick rate, which you will put to 1000

For SAME70, the systick is initialised in portable/gcc/ARM_CM7/r0p1/port.c in the function vPortSetupTimerInterrupt() Could you check these defines and find-out the logic?

I think that:

#define configCPU_CLOCK_HZ						( SystemCoreClock )

could you check or print the actual value of SystemCoreClock?

kyanc wrote on Monday, May 27, 2019:

Thanks for the replies.

@RichardBarry my mistake, i meant configTICK_RATE_HZ = 1000.

@Hein Tibosch yes that is correct, the LED is on for 2 seconds then off for 2 seconds.
i ran a demo project without FreeRTOS (same board config settings) , no issue with tick timing. LED swtiched on for 1 second and off for 1 second.

/#define BOARD_MCK 300000000UL

checking on the settings, i noticed that:
/#define configCPU_CLOCK_HZ (BOARD_MCK << 1UL)

seems like freeRTOSconfig.h defines the configCPU_CLOCK_HZ, in this case to 600MHz.
changing this value to 300MHz resulted in the correct tick rate.

I am not sure what is the reason for the left shift bit, can i assumed that it will be alright for me to just #define configCPU_CLOCK_HZ BOARD_MCK ?

just for fun (thinking why the rate will be slower at 600MHz), I tested it with 150MHz and it resulted in a faster tick rate (0.5s). Would you happen to have any explanation as to why lowering the CPU clock rate resulted in a faster tick rate?