FreeRTOS configTICK_RATE_HZ

2019-02-26 06:47发布

问题:

I am using an MSP430f5438 with version 5.4 of FreeRTOS.

I am having a funny problem that I can't figure out.

Basically, when I set configTICK_RATE_HZ to different values, the LED blinks faster or slower; it should stay the same rate. It blinks slower the higher i set configTICK_RATE_HZ, and faster when I set TICK_RATE lower.

vTaskDelayUntil( &xLastFlashTime, xFlashRate ); is such that the LED should only blink once a second no matter what the configTICK_RATE_HZ is. I stepped through and checked the xFlashRate to make sure. Its always = to the configTICK_RATE_HZ. Code:

xFlashRate = ledFLASH_RATE_BASE;//my flash base rate is 1000ms
xFlashRate /= portTICK_RATE_MS; //so xFlashrate = whatever configTICK_RATE_HZ equals

/* We need to initialise xLastFlashTime prior to the first call to vTaskDelayUntil().*/ 
xLastFlashTime = xTaskGetTickCount();
for(;;) { 
vTaskDelayUntil( &xLastFlashTime, xFlashRate ); vParTestToggleLED( uxLED ); 
flashled();//this should happen every 1 second.
}

The led blink with a period greater than 1 second when i set the configtick_rate_hz to 1000 and the led blinks with a period far less than 1s when i set the tick rate to anything less than ~200

configTICK_RATE_HZ should not affect the LED blinktime.

I realize more info is needed and will readily supply whatever code snippets are needed to help.

回答1:

The RTOS tick is generated by a Timer interrupt. The timer was set (improperly) such that it always caused a fixed tick at 400kHz no matter what you set configTICK_RATE_HZ too. Since the blink rate is set under the assumption that the RTOS tick rate is properly represented by the configTICK_RATE_HZ (portTICK_RATE_MS = 1000/configTICK_RATE_HZ), problems ensued.