What function is used to change the period of a FreeRTOS software timer at runtime?
The function xTimerChangePeriod() is used to change the timer period while the timer is active or inactive.
Click to reveal answer
beginner
What parameters does xTimerChangePeriod() require?
It requires the timer handle, the new timer period in ticks, and the block time to wait for the command to be sent to the timer command queue.
Click to reveal answer
intermediate
What happens if you call xTimerChangePeriod() on a timer that is not active?
The timer period is updated, but the timer will not start running until xTimerStart() or xTimerStartFromISR() is called.
Click to reveal answer
beginner
Why might you want to change a timer period at runtime in FreeRTOS?
To adjust the timing of periodic tasks dynamically based on system conditions, such as changing sensor read intervals or adapting to workload.
Click to reveal answer
intermediate
What is the difference between xTimerChangePeriod() and xTimerReset()?
xTimerChangePeriod() changes the timer period and optionally restarts the timer, while xTimerReset() restarts the timer with the current period without changing it.
Click to reveal answer
Which FreeRTOS function changes the timer period at runtime?
AxTimerStop()
BxTimerChangePeriod()
CxTimerReset()
DxTimerStart()
✗ Incorrect
xTimerChangePeriod() is the correct function to change the timer period dynamically.
What must you provide to xTimerChangePeriod() besides the timer handle?
ATimer name
BCallback function
CPriority level
DNew period in ticks and block time
✗ Incorrect
You provide the new timer period in ticks and the block time to wait for the command queue.
If a timer is inactive, what happens when you call xTimerChangePeriod()?
ATimer is deleted
BTimer starts immediately
CPeriod changes but timer stays stopped
DFunction returns an error
✗ Incorrect
The timer period updates but the timer remains stopped until started explicitly.
Which of these is NOT a reason to change a timer period at runtime?
AFix a bug in the timer code
BAdjust task timing dynamically
CAdapt to workload changes
DChange sensor read intervals
✗ Incorrect
Changing the timer period is for timing adjustments, not for fixing bugs.
How does xTimerChangePeriod() differ from xTimerReset()?
AChanges period vs restarts with same period
BStarts vs stops timer
CDeletes vs creates timer
DChanges priority vs changes callback
✗ Incorrect
xTimerChangePeriod() changes the timer period; xTimerReset() restarts the timer with the current period.
Explain how to change a FreeRTOS timer period at runtime and what parameters you need.
Think about the function name and what it needs to do its job.
You got /5 concepts.
Describe a practical scenario where changing a timer period at runtime is useful in an embedded system.
Consider how system needs might change during operation.
You got /4 concepts.
Practice
(1/5)
1.
What function is used in FreeRTOS to change the period of a timer while it is running?
easy
A. xTimerStop()
B. xTimerStart()
C. xTimerReset()
D. xTimerChangePeriod()
Solution
Step 1: Understand timer period change in FreeRTOS
FreeRTOS allows changing a timer's period without stopping it.
Step 2: Identify the correct API function
The function xTimerChangePeriod() is designed to change the timer period at runtime.
Final Answer:
xTimerChangePeriod() -> Option D
Quick Check:
Change timer period = xTimerChangePeriod() [OK]
Hint: Use xTimerChangePeriod() to update timer period on the fly [OK]
Common Mistakes:
Confusing xTimerStart() with changing period
Trying to stop and restart timer instead
Using xTimerReset() which resets but doesn't change period
2.
Which of the following is the correct syntax to change a FreeRTOS timer period to 100 ticks?
?
easy
A. xTimerChangePeriod(timerHandle, 0, 100);
B. xTimerChangePeriod(100, timerHandle, 0);
C. xTimerChangePeriod(timerHandle, 100, 0);
D. xTimerChangePeriod(0, 100, timerHandle);
Solution
Step 1: Recall function parameter order
The function xTimerChangePeriod() takes parameters as (TimerHandle_t xTimer, TickType_t xNewPeriod, TickType_t xTicksToWait).
Step 2: Match parameters to example
To set period to 100 ticks, pass timerHandle, 100, and 0 for no wait.
Final Answer:
xTimerChangePeriod(timerHandle, 100, 0); -> Option C
Quick Check:
Correct parameter order = xTimerChangePeriod(timerHandle, 100, 0); [OK]
Hint: Remember: timer handle first, then new period, then wait ticks [OK]
Common Mistakes:
Swapping timer handle and period parameters
Passing wait time before period
Using wrong parameter types or order
3.
Given the code snippet below, what will be the output if the timer callback prints the timer period each time it runs?
TimerHandle_t timer = xTimerCreate("MyTimer", pdMS_TO_TICKS(500), pdTRUE, NULL, TimerCallback);
xTimerStart(timer, 0);
xTimerChangePeriod(timer, pdMS_TO_TICKS(1000), 0);
// TimerCallback prints current period in ms
medium
A. The callback prints 500 ms once, then 1000 ms repeatedly
B. The callback prints 1000 ms repeatedly from start
C. The callback prints 500 ms repeatedly without change
D. The callback never runs due to period change
Solution
Step 1: Analyze timer creation and start
The timer is created with 500 ms period and started, scheduling first callback in 500 ms.
Step 2: Effect of period change
xTimerChangePeriod() removes the pending expiration, updates the period to 1000 ms, and schedules the next callback in 1000 ms from the change time. Thus, all callbacks print 1000 ms repeatedly.
Final Answer:
The callback prints 1000 ms repeatedly from start -> Option B
Quick Check:
Period change cancels pending expiry = prints 1000 ms repeatedly [OK]
Hint: xTimerChangePeriod cancels pending expiry and starts new full period [OK]
Common Mistakes:
Thinking first callback uses old 500 ms period
Assuming period change preserves pending expiration time
Believing the timer prints 500 ms first then switches
4.
Identify the error in the following code that attempts to change a timer period at runtime:
Timer is created correctly and callback is provided; pdMS_TO_TICKS() is valid for period conversion.
Final Answer:
Parameters to xTimerChangePeriod are in wrong order -> Option A
Quick Check:
Correct parameter order is timer handle first [OK]
Hint: Timer handle always comes first in xTimerChangePeriod() [OK]
Common Mistakes:
Swapping timer handle and period parameters
Not starting timer before changing period (not required)
Misunderstanding pdMS_TO_TICKS usage
5.
You have a FreeRTOS timer running with a 200 ms period. You want to double the period each time the timer callback runs, up to a maximum of 1600 ms. Which code snippet correctly changes the timer period at runtime inside the callback?