Bird
Raised Fist0
FreeRTOSprogramming~10 mins

One-shot vs auto-reload timers in FreeRTOS - Visual Side-by-Side Comparison

Choose your learning style10 modes available
Concept Flow - One-shot vs auto-reload timers
Timer Created
↓
Timer Started
↓
Timer Counts Down
↓
Timer Expires?
No→Continue Counting
Yes↓
Timer Callback Runs
↓
One-shot: Stop Timer
↓
Auto-reload: Restart Timer
↓
If Auto-reload: Back to Timer Counts Down
↓
End if One-shot
The timer counts down and triggers a callback when it expires. One-shot timers stop after one trigger; auto-reload timers restart automatically.
Execution Sample
FreeRTOS
TimerHandle_t timer = xTimerCreate("Tmr", pdMS_TO_TICKS(1000), pdTRUE, NULL, callback);
xTimerStart(timer, 0);
Creates and starts an auto-reload timer that calls 'callback' every 1000 ms.
Execution Table
StepTimer TypeTimer Count (ms)ConditionActionCallback CalledTimer State
1One-shot1000Count > 0Counting downNoRunning
2One-shot0Count == 0Trigger callbackYesStopped
3One-shot-Timer stoppedNo further actionNoStopped
4Auto-reload1000Count > 0Counting downNoRunning
5Auto-reload0Count == 0Trigger callbackYesRunning
6Auto-reload1000Auto-reload restarts timerRestart countingNoRunning
7Auto-reload0Count == 0Trigger callbackYesRunning
💡 One-shot timer stops after callback; auto-reload timer continues restarting after each callback.
Variable Tracker
VariableStartAfter Step 1After Step 2After Step 3After Step 4After Step 5After Step 6After Step 7
Timer Count (One-shot)10005000-----
Timer State (One-shot)RunningRunningStoppedStoppedStoppedStoppedStoppedStopped
Timer Count (Auto-reload)1000500-1000500010000
Timer State (Auto-reload)RunningRunning-RunningRunningRunningRunningRunning
Key Moments - 2 Insights
Why does the one-shot timer stop after the callback, but the auto-reload timer does not?
Because in the execution_table at step 2, the one-shot timer triggers the callback and then changes state to 'Stopped' at step 3, while the auto-reload timer restarts counting immediately after callback at step 6.
What happens to the timer count after the auto-reload timer callback?
As shown in the variable_tracker, after the callback at step 5, the auto-reload timer count resets to 1000 ms at step 6, restarting the countdown.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at step 5, what is the timer state for the auto-reload timer?
ARunning
BStopped
CPaused
DExpired
💡 Hint
Check the 'Timer State' column at step 5 in the execution_table.
At which step does the one-shot timer stop running?
AStep 1
BStep 2
CStep 3
DStep 4
💡 Hint
Look at the 'Timer State' column for the one-shot timer in the execution_table.
If the auto-reload timer interval was changed to 500 ms, how would the timer count values change in variable_tracker?
ATimer would stop after first callback
BTimer count would stay at 1000 ms
CTimer count would reset to 500 ms after each callback
DTimer count would increase after each callback
💡 Hint
Refer to the 'Timer Count (Auto-reload)' row in variable_tracker and imagine the interval change.
Concept Snapshot
FreeRTOS timers count down and call a function when expired.
One-shot timers run once and stop.
Auto-reload timers restart automatically after callback.
Create timers with xTimerCreate(name, period, autoReload, id, callback).
Start timers with xTimerStart(timer, blockTime).
Use one-shot for single delays, auto-reload for periodic tasks.
Full Transcript
This visual execution shows how FreeRTOS one-shot and auto-reload timers work. Both timers start counting down from their set period. When the timer reaches zero, it triggers a callback function. The one-shot timer stops after this callback, while the auto-reload timer automatically restarts counting down again. The execution table traces each step, showing timer count, state, and callback calls. The variable tracker shows how timer count and state change over time. Key moments clarify why one-shot timers stop and auto-reload timers continue. The quiz tests understanding of timer states and behavior changes. This helps beginners see how timers behave step-by-step in FreeRTOS.

Practice

(1/5)
1. What is the main difference between a one-shot timer and an auto-reload timer in FreeRTOS?
easy
A. One-shot timers run once after a delay; auto-reload timers run repeatedly at fixed intervals.
B. One-shot timers run repeatedly; auto-reload timers run only once.
C. One-shot timers are faster than auto-reload timers.
D. Auto-reload timers cannot be stopped once started.

Solution

  1. Step 1: Understand timer behavior

    One-shot timers execute their callback function only once after the specified delay.
  2. Step 2: Compare with auto-reload timers

    Auto-reload timers automatically restart after each expiration, running repeatedly at fixed intervals.
  3. Final Answer:

    One-shot timers run once after a delay; auto-reload timers run repeatedly at fixed intervals. -> Option A
  4. Quick Check:

    One-shot = single run, Auto-reload = repeated runs [OK]
Hint: One-shot = once, Auto-reload = repeat [OK]
Common Mistakes:
  • Confusing which timer runs repeatedly
  • Thinking one-shot timers repeat automatically
  • Assuming auto-reload timers cannot be stopped
2. Which of the following is the correct way to create an auto-reload timer in FreeRTOS using xTimerCreate?
easy
A. xTimerCreate("Timer", pdMS_TO_TICKS(1000), pdFALSE, NULL, TimerCallback);
B. xTimerCreate("Timer", 1000, pdTRUE, NULL, TimerCallback);
C. xTimerCreate("Timer", 1000, pdFALSE, NULL, TimerCallback);
D. xTimerCreate("Timer", pdMS_TO_TICKS(1000), pdTRUE, NULL, TimerCallback);

Solution

  1. Step 1: Identify auto-reload parameter

    The third parameter of xTimerCreate is uxAutoReload, which should be pdTRUE for auto-reload timers.
  2. Step 2: Check time parameter format

    Use pdMS_TO_TICKS(1000) to convert milliseconds to ticks correctly.
  3. Final Answer:

    xTimerCreate("Timer", pdMS_TO_TICKS(1000), pdTRUE, NULL, TimerCallback); -> Option D
  4. Quick Check:

    Auto-reload needs pdTRUE and tick conversion [OK]
Hint: Auto-reload = pdTRUE, use pdMS_TO_TICKS for time [OK]
Common Mistakes:
  • Using pdFALSE for auto-reload timers
  • Passing raw milliseconds instead of ticks
  • Confusing parameter order
3. Consider this FreeRTOS timer code snippet:
TimerHandle_t timer = xTimerCreate("MyTimer", pdMS_TO_TICKS(500), pdFALSE, NULL, TimerCallback);
xTimerStart(timer, 0);

What will happen when this timer expires?
medium
A. The TimerCallback function will be called once after 500 ms.
B. The TimerCallback function will be called repeatedly every 500 ms.
C. The timer will never start because pdFALSE is invalid.
D. The TimerCallback function will be called immediately and repeatedly.

Solution

  1. Step 1: Analyze timer creation parameters

    The timer is created with pdFALSE for auto-reload, meaning it is a one-shot timer.
  2. Step 2: Understand timer start and expiration

    After starting, the timer waits 500 ms, then calls TimerCallback once and stops.
  3. Final Answer:

    The TimerCallback function will be called once after 500 ms. -> Option A
  4. Quick Check:

    pdFALSE means one-shot = single callback [OK]
Hint: pdFALSE means one-shot, callback runs once [OK]
Common Mistakes:
  • Thinking pdFALSE means repeated calls
  • Assuming timer starts immediately
  • Confusing pdFALSE with invalid parameter
4. You wrote this code to create an auto-reload timer but it only runs once:
TimerHandle_t timer = xTimerCreate("Timer", pdMS_TO_TICKS(1000), pdFALSE, NULL, TimerCallback);
xTimerStart(timer, 0);

What is the likely error?
medium
A. The timer period is too short to see repeated calls.
B. xTimerStart was called with zero block time.
C. The auto-reload parameter is set to pdFALSE instead of pdTRUE.
D. The timer callback function is missing.

Solution

  1. Step 1: Check auto-reload parameter

    The timer was created with pdFALSE, which means it is a one-shot timer.
  2. Step 2: Understand effect on timer behavior

    Because of pdFALSE, the timer runs only once and does not auto-reload.
  3. Final Answer:

    The auto-reload parameter is set to pdFALSE instead of pdTRUE. -> Option C
  4. Quick Check:

    pdFALSE disables auto-reload, causing single run [OK]
Hint: Auto-reload needs pdTRUE, not pdFALSE [OK]
Common Mistakes:
  • Ignoring auto-reload parameter
  • Thinking block time affects reload
  • Assuming callback absence causes single run
5. You want to toggle an LED every 2 seconds indefinitely using a FreeRTOS timer. Which timer type and setup should you use?
hard
A. Create a one-shot timer with 2000 ms period and restart it manually each time.
B. Create an auto-reload timer with 2000 ms period to toggle LED automatically.
C. Create a one-shot timer with 1000 ms period and toggle LED twice per cycle.
D. Create an auto-reload timer with 1000 ms period and toggle LED every 2 cycles.

Solution

  1. Step 1: Identify requirement for repeated action

    Toggling LED every 2 seconds indefinitely means the action repeats automatically.
  2. Step 2: Choose timer type and period

    An auto-reload timer with 2000 ms period will call the toggle function every 2 seconds without manual restart.
  3. Final Answer:

    Create an auto-reload timer with 2000 ms period to toggle LED automatically. -> Option B
  4. Quick Check:

    Repeated action = auto-reload timer with correct period [OK]
Hint: Repeated tasks use auto-reload timers with correct period [OK]
Common Mistakes:
  • Using one-shot timer and forgetting to restart
  • Setting wrong timer period
  • Confusing toggle frequency with timer period
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