Concept Flow - Why software timers are useful
Start Timer
Timer Counts Down
Timer Expires?
No→Wait
Yes
Execute Callback
Restart or Stop Timer
A software timer starts counting down, waits until it expires, then runs a callback function automatically.
void timerCallback(TimerHandle_t xTimer) {
// Code to run when timer expires
}
TimerHandle_t myTimer = xTimerCreate("MyTimer", pdMS_TO_TICKS(1000), pdTRUE, NULL, timerCallback);
xTimerStart(myTimer, 0);| Step | Timer State | Time Left (ms) | Condition | Action | Output |
|---|---|---|---|---|---|
| 1 | Created | 1000 | Timer started? | Start timer countdown | No output |
| 2 | Running | 700 | Timer expired? | Wait | No output |
| 3 | Running | 300 | Timer expired? | Wait | No output |
| 4 | Expired | 0 | Timer expired? | Execute callback | Callback runs |
| 5 | Running | 1000 | Auto-reload? | Restart timer | No output |
| 6 | Running | 700 | Timer expired? | Wait | No output |
| ... | ... | ... | ... | ... | ... |
| Exit | Stopped | - | Timer stopped externally? | Stop timer | No output |
| Variable | Start | After Step 1 | After Step 4 | After Step 5 | Final |
|---|---|---|---|---|---|
| Timer State | Not created | Created | Expired | Running | Stopped or Running |
| Time Left (ms) | - | 1000 | 0 | 1000 | - |
Software timers count down in the background. When they expire, they run a callback function automatically. They can be one-shot or auto-reloading. Timers free your code from manual time checks. You can start, stop, or reset timers anytime.
Pass the test and this pattern moves unknown