Bird
0
0

You need to create a FreeRTOS task that executes precisely every 200 ms using vTaskDelayUntil(). The system tick rate is 1000 Hz. Which of the following code snippets correctly implements this?

hard📝 Application Q8 of 15
FreeRTOS - Task Scheduling
You need to create a FreeRTOS task that executes precisely every 200 ms using vTaskDelayUntil(). The system tick rate is 1000 Hz. Which of the following code snippets correctly implements this?
A<pre>TickType_t xLastWakeTime = 0; for (;;) { vTaskDelayUntil(&xLastWakeTime, pdMS_TO_TICKS(20)); // Task code }</pre>
B<pre>TickType_t xLastWakeTime; xLastWakeTime = 0; for (;;) { vTaskDelayUntil(&xLastWakeTime, 200); // Task code }</pre>
C<pre>TickType_t xLastWakeTime = xTaskGetTickCount(); for (;;) { vTaskDelayUntil(&xLastWakeTime, pdMS_TO_TICKS(200)); // Task code }</pre>
D<pre>TickType_t xLastWakeTime = xTaskGetTickCount(); for (;;) { vTaskDelayUntil(&xLastWakeTime, 200); // Task code }</pre>
Step-by-Step Solution
Solution:
  1. Step 1: Initialize xLastWakeTime

    It must be initialized with current tick count using xTaskGetTickCount().
  2. Step 2: Use pdMS_TO_TICKS macro

    Convert 200 ms to ticks correctly with pdMS_TO_TICKS(200).
  3. Step 3: Verify delay parameter

    Passing 200 directly is incorrect unless tick rate is 1 kHz, but better to use macro for portability.
  4. Final Answer:

    TickType_t xLastWakeTime = xTaskGetTickCount();
    for (;;) {
        vTaskDelayUntil(&xLastWakeTime, pdMS_TO_TICKS(200));
        // Task code
    }
    correctly initializes and uses pdMS_TO_TICKS.
  5. Quick Check:

    Check initialization and delay conversion [OK]
Quick Trick: Initialize lastWakeTime and use pdMS_TO_TICKS for delays [OK]
Common Mistakes:
  • Not initializing lastWakeTime before first call
  • Passing raw milliseconds instead of ticks
  • Using incorrect delay period

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More FreeRTOS Quizzes