3

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.

Trygve Laugstøl
  • 7,440
  • 2
  • 36
  • 40
michael
  • 2,577
  • 5
  • 39
  • 62
  • I think you need to be clear. Your test refers to configTICK_RATE_HZ but your code refers to configTICK_RATE_MS, and you have not given a value for ledFLASH_RATE_BASE. The word RATE implies a frequency, but MS implies a period. Which is it? What are the values. – Clifford Feb 12 '10 at 20:01
  • Why are you surprised that when you change the tick frequency the frequency of your system changes? – mocj Feb 12 '10 at 20:05
  • @mocj: He's surprised because he believes he has calculated the delay to compensate for varying tick rate. He hasn't. – Clifford Feb 12 '10 at 20:10
  • Remember that rate (or frequency) is the reciprocal of period. vTaskDelayUntil() takes a period not a rate. Your naming is ambiguous and I suspect your values incorrect. If you use rate when you mean period or vice versa it is unlikley to work as you'd expect. – Clifford Feb 12 '10 at 20:13
  • 1
    Clarification - 1)The xFlashRate is the number of RTOS ticks to delay by. 2)The ledFLASH_RATE_BASE is the period you want in ms. 3)The portTICK_RATE_MS is the period of the RTOS tick. It is derived from configTick_RATE_HZ (1000/configTICK_RATE_HZ). 4)so: If you want the led to tick every second (1000ms) and the RTOS ticks every 250ms, then you want the delay to be 4 rtos ticks. – michael Feb 12 '10 at 20:38
  • ack sorry for bad formatting, i thought the returns would be kept. – michael Feb 12 '10 at 20:39
  • The problem isn't here (i think). I have scoped the msp and I am getting something strange. Essentially. If I leave the vTaskDelayUntil in the code and keep the xFlashRate constant (10 in my case), then no matter what I change the RTOS tick to, the led blinks constantly (if the blink rate is set to 10, then the led should always blink at 1/10th the rate of the RTOS tick). This leads me to believe I have a problem with the Timer that causes the interrupt which feeds the RTOS tick. – michael Feb 12 '10 at 20:44
  • Again I ask - why are you surprised? You state yourself "so xFlashrate = whatever configTICK_RATE_HZ equals". You then change configTICK_RATE_HZ and expect xFlashrate not to change? – mocj Feb 12 '10 at 20:45
  • Yes xFlashRate does change. It should. It should become the number of RTOS ticks required to fulfill the desired led blink rate. But the actually blink rate is not correct. The actualy blink rate should remain the same if I do not change ledFLASH_RATE_BASE. If I change configTICK_RATE_HZ, and keept ledFLASH_RATE_BASE constant, than xFlashRate will = whatever is needed to keept the actual blink rate constant... – michael Feb 12 '10 at 21:07
  • If you comment out this line: xFlashRate /= portTICK_RATE_MS; What is the blink rate when configTICK_RATE_HZ = 1000 and configTICK_RATE_HZ = 2000 ? – mocj Feb 13 '10 at 00:07
  • 1
    Why didn't you clarify by editing the post rather than by comment? – Clifford Feb 13 '10 at 16:57

1 Answers1

5

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.

michael
  • 2,577
  • 5
  • 39
  • 62
  • Why improperly? the point of using a timer other than sysTick is that it keeps ticking at the same rate, even when the CPU clock is stopped. – ZiglioUK Sep 23 '15 at 22:17