Ticks and tasks
A hardware timer interrupts the CPU every tick. On our ESP32-C3 with the Arduino core the tick rate is 1000 Hz, so one tick is 1 ms. Each tick FreeRTOS adds 1 to the tick count and checks whether to switch tasks.
A task is a C function that loops forever, with a priority: higher numbers matter more. Running means on the CPU. Ready means it could run now. Blocked means waiting, using no CPU. The idle task, priority 0, is always ready.
How it picks
The scheduler has one rule: run the highest-priority task that is ready. At tick 0 all are ready, and sensor has priority 2, the highest. It goes onto the CPU. display and logger wait in the priority 1 list.
sensor reads in 0.2 ms, then calls vTaskDelay(WAIT), which is 3 ticks. It moves to Blocked until the tick count reaches 0 + 3 = 3. Blocked tasks use no CPU, so the processor is free for others.
The CPU must not sit empty, so the scheduler picks again at once. Priority 2 is now empty, so it takes the first task in the priority 1 list: display. It runs from 0.2 ms to the next tick.
Tick 1. display and logger share priority 1, so the tick ends display's time slice: it goes back to Ready and logger runs. This is round robin with a time slice of one tick, 1 ms. display has not finished; it simply waits.
Waking and preempting
Tick 2 swaps them back: display runs again. Then comes tick 3. The tick interrupt sees that sensor's wait is over and moves it from Blocked to the priority 2 Ready list. Nobody else had to check the time.
sensor (2) now outranks display (1), so in the same tick interrupt FreeRTOS preempts display. A context switch saves display's registers on its own stack and loads sensor's. display will resume exactly where it stopped.
sensor reads, then blocks until tick 6. The priority 1 turn passes to logger, which finishes its job at 3.9 ms and blocks for 20 ticks, until tick 23. display gets the CPU back.
display finishes at 4.6 ms and blocks until tick 24. Every task is now Blocked except idle, priority 0, so idle runs. A task that never blocked would starve every task below it.
Tick 6: sensor wakes and preempts idle at once. So the sensor runs every 3 ms however busy the others are, while display and logger share the time left over. Priorities decide who runs; the tick decides when to look again.
What happens
;; step 1/11 · tick
tick rate configTICK_RATE_HZ = 1000 -> 1 tick = 1 ms
tick ISR tick count += 1
wake tasks whose delay is over
pick again if needed
tick count ticks since the scheduler started
The figure starts the clock at tick 0 with all three tasks already ready. On the Arduino core, setup() itself runs inside a task called loopTask at priority 1, so sensor really starts the moment it is created; loop() then deletes loopTask so it does not share priority 1. read(), draw() and save() stand for your own code. The figure assumes they need 0.2 ms, 2.5 ms and 1.7 ms of CPU time. A real job takes as long as its code does.