Bird
Raised Fist0
FreeRTOSprogramming~20 mins

Tick timer and scheduler in FreeRTOS - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Tick Timer Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
Tick Count Increment Behavior

What will be the output of the following FreeRTOS tick count code snippet after 3 ticks?

FreeRTOS
#include "FreeRTOS.h"
#include "task.h"
#include <stdio.h>

TickType_t tickCount = 0;

void vApplicationTickHook(void) {
    tickCount = xTaskGetTickCount();
}

int main() {
    // Simulate 3 ticks
    for (int i = 0; i < 3; i++) {
        vApplicationTickHook();
    }
    printf("Tick count: %u\n", (unsigned int)tickCount);
    return 0;
}
ATick count: 1
BTick count: 3
CTick count: 0
DTick count: 2
Attempts:
2 left
💡 Hint

Observe that the scheduler is not started in the code, so xTaskGetTickCount() returns 0.

🧠 Conceptual
intermediate
1:30remaining
Role of the Tick Timer in FreeRTOS

What is the primary role of the tick timer in FreeRTOS?

ATo provide a periodic interrupt that drives the scheduler and time-related functions
BTo handle all hardware interrupts in the system
CTo manage memory allocation for tasks
DTo initialize the CPU clock frequency
Attempts:
2 left
💡 Hint

Think about what triggers task switching and delays.

🔧 Debug
advanced
2:30remaining
Why Does the Scheduler Not Switch Tasks?

Given the following FreeRTOS configuration snippet, why does the scheduler never switch tasks?

#define configUSE_PREEMPTION 0
#define configTICK_RATE_HZ 1000

void vTask1(void *pvParameters) {
    while(1) {
        // Task code
    }
}

void vTask2(void *pvParameters) {
    while(1) {
        // Task code
    }
}

int main() {
    xTaskCreate(vTask1, "Task1", 1000, NULL, 1, NULL);
    xTaskCreate(vTask2, "Task2", 1000, NULL, 1, NULL);
    vTaskStartScheduler();
    return 0;
}
ABecause preemption is disabled, so tasks only switch on yield or blocking calls
BBecause the tick rate is too high causing scheduler overload
CBecause tasks have the same priority and scheduler cannot decide
DBecause tasks are missing calls to vTaskDelay()
Attempts:
2 left
💡 Hint

Check the configUSE_PREEMPTION setting.

📝 Syntax
advanced
1:30remaining
Identify the Syntax Error in Tick Hook Implementation

Which option contains the correct syntax for implementing the FreeRTOS tick hook function?

Avoid vApplicationTickHook() { /* user code */ }
Bvoid vApplicationTickHook(void) { /* user code */ }
Cvoid vApplicationTickHook(void) -> void { /* user code */ }
Dvoid vApplicationTickHook(void); { /* user code */ }
Attempts:
2 left
💡 Hint

Check the correct C function declaration syntax.

🚀 Application
expert
3:00remaining
Calculating Tick Overflow Time

Given a FreeRTOS tick rate of 1000 Hz and a 32-bit tick counter, how long in days will it take for the tick count to overflow?

AApproximately 24 hours
BApproximately 365 days
CApproximately 100 days
DApproximately 49.7 days
Attempts:
2 left
💡 Hint

Calculate total ticks before overflow and convert to time.

Practice

(1/5)
1. What is the main role of the tick timer in FreeRTOS?
easy
A. To handle input/output operations
B. To store task priorities
C. To allocate memory for tasks
D. To count time in small steps called ticks

Solution

  1. Step 1: Understand tick timer function

    The tick timer counts time in small units called ticks, which are the basic time measurement in FreeRTOS.
  2. Step 2: Differentiate from other functions

    Other options like storing priorities or handling I/O are not related to the tick timer's role.
  3. Final Answer:

    To count time in small steps called ticks -> Option D
  4. Quick Check:

    Tick timer = counts ticks [OK]
Hint: Tick timer counts time steps, not priorities or memory [OK]
Common Mistakes:
  • Confusing tick timer with task priority management
  • Thinking tick timer handles memory or I/O
  • Mixing tick timer with scheduler directly
2. Which of the following is the correct way to delay a task for 100 ticks in FreeRTOS?
easy
A. xTaskDelay(100);
B. vTaskDelay(1000);
C. vTaskDelay(100);
D. delayTask(100);

Solution

  1. Step 1: Identify correct function name

    The correct FreeRTOS function to delay a task is vTaskDelay().
  2. Step 2: Check parameter correctness

    The parameter is the number of ticks to delay. For 100 ticks, vTaskDelay(100); is correct.
  3. Final Answer:

    vTaskDelay(100); -> Option C
  4. Quick Check:

    Delay task = vTaskDelay(ticks) [OK]
Hint: Use vTaskDelay with tick count to pause tasks [OK]
Common Mistakes:
  • Using wrong function name like xTaskDelay or delayTask
  • Passing milliseconds instead of ticks
  • Using too large or incorrect delay values
3. Consider this code snippet in FreeRTOS:
TickType_t start = xTaskGetTickCount();
vTaskDelay(50);
TickType_t end = xTaskGetTickCount();
TickType_t diff = end - start;
What is the expected value of diff?
medium
A. 0
B. 50
C. 100
D. Depends on task priority

Solution

  1. Step 1: Understand xTaskGetTickCount()

    This function returns the current tick count since the scheduler started.
  2. Step 2: Analyze vTaskDelay(50)

    The task delays itself for 50 ticks, so the tick count advances by 50 during the delay.
  3. Step 3: Calculate difference

    Subtracting start from end gives the delay duration, which should be 50 ticks.
  4. Final Answer:

    50 -> Option B
  5. Quick Check:

    Delay ticks = 50 [OK]
Hint: Delay of 50 ticks means tick count difference is 50 [OK]
Common Mistakes:
  • Assuming delay is zero or doubled
  • Thinking task priority affects tick count difference
  • Confusing ticks with milliseconds
4. What is wrong with this FreeRTOS code snippet?
vTaskDelay(0);
TickType_t ticks = xTaskGetTickCount();
medium
A. vTaskDelay(0) does not delay the task
B. xTaskGetTickCount() returns an error
C. vTaskDelay requires a pointer argument
D. TickType_t is not a valid type

Solution

  1. Step 1: Check vTaskDelay parameter

    Passing 0 to vTaskDelay means no delay; the task yields but continues immediately.
  2. Step 2: Verify xTaskGetTickCount()

    This function correctly returns the current tick count; no error here.
  3. Final Answer:

    vTaskDelay(0) does not delay the task -> Option A
  4. Quick Check:

    Delay(0) means no wait [OK]
Hint: vTaskDelay(0) yields but does not pause task [OK]
Common Mistakes:
  • Expecting delay with zero ticks
  • Thinking xTaskGetTickCount returns error
  • Misunderstanding TickType_t type
5. You want a task to run every 200 ticks precisely using FreeRTOS. Which approach ensures this timing despite task execution time?
hard
A. Use vTaskDelayUntil() with a previous wake time variable
B. Use vTaskDelay(200) at the end of the task loop
C. Use xTaskGetTickCount() inside the task and delay manually
D. Use vTaskDelay(100) twice in the task loop

Solution

  1. Step 1: Understand vTaskDelay() limitation

    Using vTaskDelay(200) delays from current time, so task execution time adds up causing drift.
  2. Step 2: Use vTaskDelayUntil() for fixed periodic timing

    vTaskDelayUntil() uses a previous wake time to maintain exact periodic intervals regardless of execution time.
  3. Step 3: Evaluate other options

    Manual delay or multiple delays do not guarantee precise timing; only vTaskDelayUntil() does.
  4. Final Answer:

    Use vTaskDelayUntil() with a previous wake time variable -> Option A
  5. Quick Check:

    Precise periodic task = vTaskDelayUntil() [OK]
Hint: Use vTaskDelayUntil() for exact periodic task timing [OK]
Common Mistakes:
  • Using vTaskDelay causes timing drift
  • Trying manual delay calculations
  • Ignoring task execution time in timing
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard