Real-time deadlines in embedded control: a worked example
Understand periods, deadlines and response time through a motor-control timing budget, missed deadlines, Linux and RTOS roles, and a worked exercise.
Contents
In a real-time system, a correct answer also has to reach its point of effect before a specified deadline. If a motor-control cycle must apply its new output within three milliseconds, a correct command arriving after four milliseconds is late. The equipment's requirements establish that limit; a fast processor or an operating-system label cannot replace it.
Imagine a small wheel with a speed sensor. A controller reads speed and adjusts the driver's command while a user watches a chart and the device saves a log. The design problem is to prevent a slow chart or file operation from delaying control. Every timing value below is hypothetical, rather than a ready configuration for a particular motor or board.

Period, deadline and response time are different quantities
A millisecond is one thousandth of a second. The period is the planned interval between releases of successive cycles. Here a cycle is released every 10 ms: at 0, 10, 20 and so on. The relative deadline is the permitted interval from that planned release to the completed response. Assume it is 3 ms. The cycle released at 100 ms must therefore finish by 103 ms, rather than 113 ms.
Response time is the actual interval from the defined starting event to the output taking effect. Our starting event is the sensor-sampling trigger; the endpoint is application of the new command at the driver's output. The shaft reaching its requested speed is a separate mechanical response, not the end of the calculation. If software wakes late, its deadline does not restart when it finally wakes: that delay counts too.
A worked example: where do the three milliseconds go?
Assume four non-overlapping intervals: sensing takes 0.6 ms, waiting to run takes 0.4 ms, calculation takes 0.8 ms, and delivery through to the output takes 0.2 ms. Waiting may result from another task, a shared-resource lock or a communications interface. A lock is a mechanism that prevents incompatible simultaneous access to a resource.
response = sensing + waiting + calculation + output response = 0.6 + 0.4 + 0.8 + 0.2 = 2.0 ms margin = deadline - response = 3.0 - 2.0 = 1.0 ms
For a release at 100 ms, the sample is ready at 100.6, waiting ends at 101, calculation ends at 101.8 and the output is updated at 102. This modeled response meets the 103 ms deadline. The remaining millisecond is margin under these assumptions; neither a worst-case bound nor guaranteed margin has been established.
Now increase only the waiting interval from 0.4 to 3 ms, perhaps because control waits behind a slow communication operation. The sum becomes 0.6 + 3.0 + 0.8 + 0.2 = 4.6 ms, missing the deadline by 1.6 ms. Finishing before the next release at 110 ms does not repair that failure. A 10 ms period and a 3 ms deadline impose different constraints.
What should happen after a late response?
The term real-time does not by itself specify the severity of failure. A delayed chart may make the interface unpleasant; a delayed control output may impair operation and can be hazardous in some equipment. Define a policy for the actual system: report the fault, discard an outdated command, use the last valid command for a bounded time, or enter a defined stop state. None is a universally safe policy for all motors.
Running several overdue calculations back to back cannot recreate sensor samples that were never taken. Establish whether the input is fresh or whether an old value is being processed again. The lesson on motor drivers and feedback explains the difference between commanding motion and measuring it. Even a correctly calculated command can be inappropriate when based on stale data.
Separating control from the display and network
In the proposed architecture for this example, the short control path acquires a sample, checks validity and updates the output. Chart rendering, file logging and network responses sit outside that path. The interface application can submit a speed target and receive status; each control cycle should not have to wait for a file to open or a browser to respond. Motor energy still comes from the supply and driver power stage. Running control software on a chip does not make that chip a motor-current source.
This separation does not necessarily require two boards. Tasks may share one processor with justified priorities, run on different cores, or be divided between a microcontroller and a computer. A core is a processor execution unit; adding cores does not remove shared memory or buses. The Linux documentation on hardware considerations explains how contention can introduce delay. Separation also has costs: communication, data coordination and additional testing.
A target message needs a value, unit, sequence number and freshness rule. Sequence numbers clarify order. Measuring a message's age across processors requires a known relationship between their clocks. A local receipt timestamp shows time since receipt, not time already spent in the network. Define valid target limits, missing updates and behavior during restart. An unbounded queue of old commands conceals delay. Choosing only the latest valid target must also be a deliberate application decision.
Is Linux unsuitable, and does an RTOS solve everything?
No. Linux provides real-time facilities and the PREEMPT_RT configuration. Its official theory of operation describes reducing non-preemptible regions and high-priority scheduling latency. Selecting this configuration alone does not guarantee the complete sensor-to-output response. Drivers, application behavior, hardware and simultaneous workloads remain part of the system. The Linux kernel and driver lesson introduces those roles.
An RTOS is an operating system with mechanisms suited to time-sensitive tasks. Under FreeRTOS's default single-core policy, a higher-priority ready task can preempt a lower-priority task. However, a high-priority task that stays runnable can starve other tasks. Raising priority does not make a slow peripheral or an unsuitable lock disappear. Establish task timings, resource use and requirements first.
Removing delay calls is also insufficient. The millis scheduling lesson introduces short, incremental work. In an RTOS, a function such as xTaskDelayUntil can track periodic wake times relative to the previous time reference. Becoming ready is different from starting immediately or completing before a deadline. This lesson supplies no executable control implementation or guaranteed operating-system configuration.
What makes a useful timing report?
For each cycle, record the planned release, actual sampling start, sample-ready event and output taking effect separately. Use a monotonic time base rather than a calendar clock that can jump. Document measurement resolution and uncertainty. An observed value of exactly 3 ms with unknown measurement error is weak evidence for accepting a 3 ms boundary.
Test beyond an idle system: include logging, network traffic and communication faults. On actual equipment, suitable input/output markers and instrumentation can reveal latency; the waveform and timing lesson is a useful prerequisite. A low average can hide late events. Report the observed maximum together with cycle count, workload and versions. The largest observed value is not a proof of the worst case under every possible condition.
Exercise with an answer: are we still on time?
Keep the 10 ms period and 3 ms deadline. Sensing, waiting, calculation and output now take 0.5, 0.7, 1.1 and 0.3 ms respectively. Calculate response and margin. Then add 0.6 ms of waiting. Explain why reducing the chart update rate might help, yet cannot provide a guarantee without evidence.
Worked answer
The first sum is 0.5 + 0.7 + 1.1 + 0.3 = 2.6 ms, leaving 0.4 ms. Additional waiting raises response to 3.2 ms, missing the deadline by 0.2 ms. Less chart work helps only if it actually reduces contention or waiting on this path. Both cases may finish before the next period, but the second misses the 3 ms deadline. These are calculated results.
Download the timing budget and observation worksheet. Keep predictions separate from measurements; the actual-observation columns are blank for use on your own equipment.
Question and answer article
Ask your technical question
Questions and answers are published after moderation. Authors can see their own pending drafts.
No confirmed questions have been registered for this article yet.