All jobs / Embedded / hardware / RTOS
Embedded / hardware interview question · 1–3 years
A task should sample every 10 ms. It sleeps for 10 ms at the end of each pass, and over minutes the period slips.
What is wrong?
The strongest answer
A plain delay counts from the moment you call it, so the work time is added to every period; the delay-until form sleeps to an absolute next-wake time and holds the period
Why it works
Right — delay-until anchors to the previous wake time, so jitter stops accumulating into drift.
What a good answer covers
- Anchor a period to absolute time.
- A plain delay measures from now.
- Delay-until holds a fixed period.
- Drift ruins filters and timestamps.
Answers that fall short
- Close, but not the strongest: The sampling work takes time on top of the sleep, so I would subtract the measured work time from the delay
That works until the work time varies; the delay-until form does the arithmetic for you and never drifts. - Weak: The RTOS tick is not accurate enough; I would raise the tick rate until the period looks right
A faster tick shrinks the jitter but not the drift, because the work time is still added every pass. - Red flag: Ten milliseconds is close enough for sampling; I would leave it and mention the drift in the log
Sample timing that slips silently corrupts anything you filter, integrate or timestamp downstream.
Who gets asked this
More RTOS questions
- Two tasks write a global “state” byte. What is the grown-up move?
- A low-priority task holds a lock a high-priority task needs. What do you name?
- One task corrupts another’s stack. What do you add besides “be careful”?
- You have a 2 ms control deadline. What number do you present?
- A low-priority logger never runs. What do you check before “buy a faster MCU”?
- Two teams share one firmware, each has added mutexes, and you have now had two hangs that reproduce about…
- What does a staff engineer pin on the wall for a control product?
- When do you reach for a mutex, and when for a binary semaphore?