Real Time Systems

Many embedded systems must react or respond to events in a well defined, limited amount of time. We call these real-time computing systems. While efficient code design is always important, most computer programs do not face real-time constraints. For most applications, the exact execution time does not define success or failure as long as the program generates the expected results. If a block of code executes in X milliseconds or Y milliseconds, as long as the code provides the correct output. For example, most users don’t care if a disc drive system responds to a read request in 0.5 milliseconds or 0.55 milliseconds, as long as the program returns the correct data. Similarly, if your embedded system is monitoring the temperature of a cooler and turning on and off a refrigeration system to maintain temperature, it probably doesn’t matter if the control system checks the temperature every 5 seconds or every 10 seconds.

In contrast, for real-time computing systems, timing is everything. Real-time computing systems have well-defined time constraints for the time that can pass before they respond to an event. If the program cannot meet the timing constraints, the system will not function properly. Looking back at our disc drive example, while the exact time required to retrieve data varies, the servo loop that controls the head location is a real-time system. The head position control algorithm is designed to run at a specific interval. During time interval the software must read the head position, calculate an error, and then calculate a control output to adjust the head position. If these calculations are not complete before the end of the interval, the control system will fail. Similarly, if the ignition control in a car engine does not fire at the correct instant in the compression cycle, the car’s engine could be severely damaged.

In each of these real-time examples, the computer system must respond to event. For the servo control example, the event is the expiration of a timer. For the engine control example, the event might be a sensor detecting piston position in its stroke. In each case, the real-time constraints start with a trigger. The maximum time allowed for a computer system response is the deadline.

Wikipedia describes three categories for real-time systems:

    • Hard – missing a deadline is a total system failure.
    • Firm – infrequent deadline misses are tolerable, but may degrade the system’s quality of service. The usefulness of a result is zero after its deadline.
    • Soft – the usefulness of a result degrades after its deadline, thereby degrading the system’s quality of service.

For the purposes of the projects discussed on this site, we will use the hard deadline real-time system definition.

Note that real-time programming does not simply mean maximizing program throughput.  The event trigger and response deadline mark the beginning and end of a time constraint that is defined by an external system and measured in clock time.

These concepts are closely related to the concept of Event Driven – Asynchronous Programming, and I encourage you to read that post.