Chapter 1
Real-Time Computing
1.0Ā Ā Defining the Embedded System
An embedded system can be defined as a computer system that performs one or more dedicated or specialized functions usually with Real-Time constraints. It is the digital controller that is embedded as part of system, which also includes other hardware and mechanical elements. A modern dishwasher contains an embedded control system. On the other hand, a general-purpose computer such as a PC is designed to meet a variety of user needs. The control system in the dishwasher does one task: wash dishes, while the PC on your desktop can be used in word processing, browsing the Web, balancing your checkbook, and many other applications.
Embedded systems are controlled by one or more digital processing devices, typically a microcontroller or digital signal processor (DSP). The key feature of the embedded system is that it is dedicated to a specific task. Sometimes a specialized or dedicated computer system, such as the one handling a dam, or the traffic in a major city, or the operation of a nuclear power plant, is considered an embedded system. Although it is a matter of semantics, we prefer to exclude specialized or dedicated computer systems from the embedded category. We also exclude devices based on nanotechnology because in this case it is the molecular size of the component that defines the system. But even excluding specialized computing devices and molecular-scale components, embedded systems can range widely in size and complexity; from handheld or portable devices such as a digital watch to complex controllers such as the one operating a space exploration robot.
A good example of an embedded system, as considered in this context, is a programmable thermostat controlling the operation of household air conditioning and heater systems. In real-time the thermostat receives information from a sensor that reads the house temperature at predetermined intervals. The controller logic then compares this temperature value with the one programmed for the current time-of-day and turns on or off the AC or the heater component as necessary.
1.1Ā Ā Embedded Systems History
One of the first recognizably modern embedded systems was the Apollo Guidance Computer, developed at the MIT Instrumentation Laboratory in 1961. It was the Apollo Guidance Computer that first explored the viability of monolithic integrated circuits which have because become commonplace. Another early embedded system was the Autonetics D-17 guidance computer for the Minuteman missile, which was based on transistors and contained a hard disk drive as its main memory. In 1996, the D-17 controller was replaced with a new computer that pioneered the development of integrated circuits. One result from these projects was the reduction in cost of the quad nand gate ICs from $1,000 each to less than $3. Commercial applications soon followed.
The invention and development of microcontrollers relates closely to the evolution of embedded systems. The integration of processing functions, memory, and programmable input and output operations in a single circuit has simplified the design and development of embedded systems, to the point that today it is difficult to find an embedded system that does not include at least one microcontroller. Furthermore, the low cost of microcontrollers compared to full-fledged computer ICs has further increased the type of applications for which embedded systems are commercially viable. All embedded systems discussed in this book contain a microcontroller although some systems also include other digital components that provide specialized functionality. For example, an embedded system that deals in Real-Time units (such as years, months, days-of-the-week, hours, minutes, and seconds) will typically include a Real-Time clock IC such as the NJU6355, which will furnish this functionality.
1.2Ā Ā Hardware Complexity
To the developer or engineer an embedded system consists of hardware and software. The hardware typically includes a circuit board that houses and interfaces the components, one or more integrated circuits that provide the processing capabilities (usually a microcontroller), and one or more input and output devices that communicate with the outside world. But not all embedded systems are stand alone devices. For example, an embedded system that turns on and off a stepper motor and controls its rotational speed and direction may be designed to communicate with another system that provides the logic and command signals. In this case the embedded motor control system is actually a component of a larger control system and does not contain a user interface, processing logic, or other command and control functions.
On the other hand, some embedded systems come close to the functionality of a conventional computer. For example, an embedded system may include a computer screen with a graphical user interface, several buttons and control devices, LEDs, network connections, or even a touch screen. In this case it is the fact that the embedded system is dedicated to a particular task that differentiates it from a computer. But keep in mind that there is no clear demarcation line between a sophisticated embedded system and a specialized computer. One is free to classify such borderline systems in either category. In this sense an ATM machine, with its complex processing and IO capabilities, can be considered either as an embedded system or as a specialized computer.
1.2.1Ā Ā Processor
It is virtually impossible to conceive of an embedded system that does not provide some processing, although, here again, the demarcation line is not always clear. For example, the circuit that operates a household doorbell often consists of a simple pushbutton control and a buzzer or bell. Pressing the pushbutton closes the circuit that activates the sound-producing element. Because there is no logic or processing such a doorbell circuit could hardly be classified as an embedded system. However, if we add a processor that selects a different sound pattern or chime according to the time of day, then the doorbell driver could be classified as an embedded system. Here, it is the presence of a processing operation that defines the system.
Embedded processors are usually microcontrollers although it is conceivable that an embedded system can be based on a microprocessor. The principal difference between the microprocessor and the microcontroller is that the latter includes peripheral functions that simplify its application and reduce the cost of the IC. Additionally, it is usually assumed that a microprocessor system contains more complex and powerful logic; however, the advent of the Digital Signal Processor (DSP) has also diminished this perception because some DSPs match or even exceed the processing power of microcomputers.
1.2.2Ā Ā Microcontrollers
In this book we do not cover embedded systems based on microprocessors or on DSPs because the complexity of such systems clearly exceeds our present scope and intention. But even excluding these high-end devices, dealing with the many sources, types, and complexity of currently available microcontrollers can be a daunting proposition. Chapter 5 contains an overview of microcontrollers from Intel, Microchip, Motorola, and Atmel often found in embedded systems. However, for space constraints and practical didactic considerations, in this book we limit our coverage to a few popular and well-supported microcontrollers from Microchip, all based on its mid-range architecture.
1.2.3Ā Ā Hardware and Software
The hardware components that can be found in an embedded system are difficult to enumerate. They include (but are not limited to) the following elements:
ā¢Ā Ā Circuit boards
ā¢Ā Ā Processors (usually one or more microcontrollers)
ā¢Ā Ā Transistors
ā¢Ā Ā Logic gates
ā¢Ā Ā Power supplies
ā¢Ā Ā Clocks and flip-flops
ā¢Ā Ā Frequency dividers, timers, and counters
ā¢Ā Ā Multiplexers and demultiplexers
ā¢Ā Ā Memories and data storage facilities
ā¢Ā Ā Communications controllers
ā¢Ā Ā Switches and keypads
ā¢Ā Ā LEDs, seven-segement LEDs, and LCDs
ā¢Ā Ā Motors and motor control devices
ā¢Ā Ā Sensors
ā¢Ā Ā Solenoids and actuators
ā¢Ā Ā AC converters and output devices
Books can be and have been written on many of these elements. In fact, titles on some of them (such as microcontrollers) fill several good-sized shelves. Fortunately, others are rather simple devices, and their understanding and use is straightforward and direct. For example, from an embedded systems developer point of view, there is not much more that can be done with an LED than to turn it on or off.
By a stretch of the imagination we can conceive of an embedded system that operates solely on the off-the-shelf logic contained in its digital devices. However, a more common scenario is that the processing operations of an embedded system must be customized by the developer to meet a specific design functionality. This means that a program must be developed for the systemās controller. The reference in this bookās title to circuits and programming indicates that its contents relate to both the physical electronics and the software component of an embedded system.
1.3Ā Ā Execution in Real-Time
Real-time or reactive computing refers to systems that are subject to a time constraint. By definition, a real-time computing system is one that interacts with the real world or that has timing requirements related to this interaction. In general, the response of a Real-Time system must take place within a specific time frame. For example, in order to be effective, the air-bag system in the steering wheel of a car must deploy within a certain time period after the event that activates it. If the air bag deploys earlier or later than this ideal moment, its action would be useless or even counterproductive. Note that the concept of execution in real-time does not mean that the systemās interaction must take place as fast as possible.
By definition a real-time system includes not only those that must execute within a temporal constraint, but also any system that interacts with the real world. In embedded systems this interaction with the real world usually takes place through sensors and actuators. For example, the doorbell system previously mentioned executes in Real-Time because it is expected that the buzzer or chime will sound within a short time after the pushbutton is depressed.
1.3.1Ā Ā Hard and Soft Real-Time Systems
Real-Time systems are often classified as hard and soft. Systems that must meet strict timing requirements are classified as hard while those in which there is a more flexible tolerance of the timing requirement are soft RTSs, (Real-Time Systems). In this context, the air-bag system mentioned previously completely fails if its strict timing requirement is not met; therefore, it is a hard RTS. The doorbell system, on the other hand, has a much larger tolerance in its timing requirement and can be classified as a soft RTS. The timeliness requirement is one of the main issues in the design of a hard real-time system, but must also be considered in soft RTSs.
Design considerations in Real-Time systems include the following topics:
ā¢Ā Ā Real-Time operating systems
ā¢Ā Ā Scheduling
ā¢Ā Ā Real-Time communications
ā¢Ā Ā Analysis of Real-Time components
ā¢Ā Ā Testing and debugging Real-Time systems
In this context our discussion of Real-Time systems is limited to specific circuits with a specific Real-Time constraint. Most of the topics listed above fall within the field of theoretical computer science.
Chapter 2
Circuit Fundamentals
2.1 Electrical Circuit
An electrical network is a collection of electrical elements that can include voltage sources, lines, connectors, resistors, inductors, capacitors, switches, controllers, and a host of other standard and special components. The circuit is a closed-loop electrical network that provides a return path for the current and that contains at least one active electronic component.
Electronic circuits are classified as analog, digital, or mixed-signal, the latter being a combination of the analog and digital types. Circuits contain discrete components often purchased off-the-shelf. These include but are not limited to resistors, capacitors, inductors, diodes, processors (such as microcontrollers), as well as input and output devices such as pushbuttons, toggle switches, light-emitting diodes, liquid crystal displays, actuators, and motors. During the development stage, the circuit components are typica...