BUY THIS BOOK

Safari Books Online

What is this?

Looking to Reprint this content?


Designing Embedded Hardware
Designing Embedded Hardware

By John Catsoulis

Cover | Table of Contents | Colophon


Table of Contents

Chapter 1: Introduction to Computer Architecture
Each machine has its own, unique personality which probably could be defined as the intuitive sum total of everything you know and feel about it. This personality constantly changes, usually for the worse, but sometimes surprisingly for the better . . .
—Robert M. Pirsig, Zen and the Art of Motorcycle Maintenance
This book is about designing and building specialized computers. We all know what a computer is. It's that box that sits on your desk, quietly purring away (or rattling if the fan is shot), running your programs and regularly crashing (if you're not running some variety of Unix). Inside that box is the electronics that runs your software, stores your information, and connects you to the world. It's all about processing information. Designing a computer, therefore, is about designing a machine that holds and manipulates data.
Computer systems fall into essentially two separate categories. The first, and most obvious, is that of the desktop computer. When you say "computer" to someone, this is the machine that usually comes to his mind. The second type of computer is the embedded computer, a computer that is integrated into another system for the purposes of control and/or monitoring. Embedded computers are far more numerous than desktop systems, but far less obvious. Ask the average person how many computers she has in her home, and she might reply that she has one or two. In fact, she may have 30 or more, hidden inside her TVs, VCRs, DVD players, remote controls, cell phones, ovens, toys, and a host of other devices. In this chapter, we'll look at computer architecture in general, which applies to both embedded and desktop computers.
The underlying architectures of desktop computers and embedded computers are fundamentally the same. At a crude level, both have a processor, memory, and some form of input and output. The primary difference lies in their intended use, and this is reflected in their software. Desktop computers can run a variety of application programs, with system resources orchestrated by an operating system. By running different application programs, the functionality of the desktop computer is changed. One moment, it may be used as a word processor; the next, it is an MP3 player or a database client. Which software is loaded and run is under user control.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Concepts
At the simplest level, a computer is a machine designed to process, store, and retrieve data. Data may be numbers in a spreadsheet, characters of text in a document, dots of color in an image, waveforms of sound, or the state of some system, such as an air conditioner or a CD player. It is important to note that all data is stored in the computer as numbers.
The computer manipulates the data by performing operations on the numbers. Displaying an image on a screen is accomplished by moving an array of numbers to the video memory, each number representing a pixel of color. To play an MP3 audio file, the computer reads an array of numbers from disk and into memory, manipulates those numbers to convert the compressed audio data into raw audio data, and then outputs the new set of numbers (the raw audio data) to the audio chip.
Everything that a computer does, from web browsing to printing, involves moving and processing numbers. The electronics of a computer is nothing more than a system designed to hold, move, and change numbers.
A computer system is composed of many parts, both hardware and software. At the heart of the computer is the processor, the hardware that executes the computer programs. The computer also has memory, often several different types in the one system. The memory is used to store programs while the processor is running them, as well as to store data that the programs are manipulating. The computer also has devices for storing data or exchanging data with the outside world. These may allow the input of text via a keyboard, the display of information on a screen, or the movement of programs and data to or from a disk drive.
The software controls the operation and functionality of the computer. There are many "layers" of software in the computer (Figure 1-1). Typically, a given layer will interact with only the layer immediately above or below.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Memory
Memory is used to hold data and software for the processor. There is a variety of memory types, and often a mix is used within a single system. Some memory will retain its contents while there is no power, yet will be slow to access. Other memory devices will be high capacity, yet will require additional support circuitry and will be slower to access. Still other memory devices will trade capacity for speed, giving relatively small devices, yet are capable of keeping up with the fastest of processors.
Memory can be organized in two ways, either word-organized or bit-organized. In the word-organized scheme, complete nybbles, bytes, or words are stored within a single component, whereas with bit-organized memory, each bit of a byte or word is allocated to a separate component (Figure 1-10).
Figure 1-10: Eight bit-organized 8 x 1 devices and one word-organized 1 x 8 device
Memory chips come in different sizes, with the width specified as part of the size description. For instance, a DRAM (dynamic RAM) chip might be described as being 4M x 1 (bit-organized), whereas a SRAM (static RAM) may be 512k x 8 (word-organized). In both cases, each chip has exactly the same storage capacity, but they are organized in different ways. In the DRAM case, it would take eight chips to complete a memory block for an 8-bit data bus, whereas the SRAM requires only one chip.
However, because the DRAMs are organized in parallel, they are accessed simultaneously. The final size of the DRAM block is (4M x 1) x 8 devices, which is 32M. It is common practice for multiple DRAMs to be placed on a memory module. This is the common way that DRAMs are installed in standard computers.
The common widths for memory chips are x1, x4, and x8, although x16 devices are available.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Input/Output
The address space of the processor can contain devices other than memory. These are input/output devices (I/O devices, also known as peripherals) and are used by the processor to communicate with the external world. Some examples are serial controllers that communicate with keyboards, mice, modems, and so on, and parallel I/O devices that control some external subsystem or disk drive controllers, video and audio controllers, or network interfaces.
There are three main ways in which data may be exchanged with the external world:
Programmed I/O
The processor accepts or delivers data at times convenient to it (the processor).
Interrupt-driven I/O
External events control the processor by requesting the current program be suspended and the external event be serviced. An external device will interrupt the processor (assert an interrupt control line into the processor), at which time the processor will suspend the current task (program) and begin executing an interrupt service routine. The service of an interrupt may involve transferring data from input to memory or from memory to output.
Direct Memory Access (DMA)
DMA allows data to be transferred from I/O devices to memory directly without the continuous involvement of the processor. DMA is used in high-speed systems, in which the rate of data transfer is important. Not all processors support DMA.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
DMA
Direct Memory Access is a way of streamlining transfers of large blocks of data between two sections of memory or between memory and an I/O device. Let's say you want to read in 100 MB from disk and store it in memory. You have two options.
The processor can read each byte at a time from the disk controller into a register, then store the contents of the register to the appropriate memory location. For each byte transferred, the processor must read an instruction, decode the instruction, read the data, read the next instruction, decode the instruction, and then store the data. Then the process starts over again for the next byte.
The second option in moving large amounts of data around the system is DMA. A special device, called a DMA controller (DMAC), performs high-speed transfers between memory and I/O devices. Using DMA bypasses the processor by setting up a channel between the I/O device and the memory. Thus, data is read from the I/O device and written into memory without the need to execute code to perform the transfer on a byte-by-byte (or word-by-word) basis.
In order for a DMA transfer to occur, the DMAC must have use of the address and data buses. There are several ways in which this could be implemented by the system designer. The most common approach (and probably the simplest) is to suspend the operation of the processor and for the processor to release its buses (the buses are tristate). This allows the DMAC to take over the buses for the short period required to perform the transfer. Processors that support DMA usually have a special control input that enables a DMAC (or some other processor) to request the buses.
There are four basic types of DMA:
  • Standard block transfer is accomplished by the DMA controller performing a sequence of memory transfers. The transfers involve a load operation from a source address followed by a store operation to a destination address. Standard block transfers are initiated under software control and are used for moving data structures from one region of memory to another.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Embedded Computer Architecture
What a computer is used for, what tasks it must perform, and how it interacts with humans and other systems determine the functionality of the machine, and therefore its architecture, memory, and I/O.
An arbitrary desktop computer (not necessarily a PC) is shown in Figure 1-13. It has a large main memory to hold the operating system, applications, and data and an interface to mass storage devices (disks and DVD/CD-ROMs). It will have a variety of I/O devices for user input (keyboard, mouse, and audio), user output (display interface and audio), and connectivity (networking and peripherals). The fast processor requires a system manager to monitor its core temperature and supply voltages and to generate a system reset.
Large-scale embedded computers may also take the same form. For example, they may act as a network router or gateway and so will require one or more network interfaces, large memory, and fast operation. They may also require some form of user interface as part of their embedded application and, in many ways, may simply be a conventional computer dedicated to a specific task. Thus, in terms of hardware, many high-performance embedded systems are not that much different from a conventional desktop machine.
Figure 1-13: Block diagram of a generic computer
Smaller embedded systems use microcontrollers as their processor, with the advantage that this processor will incorporate much of the computer's functionality on a single chip. An arbitrary embedded system, based on a generic microcontroller, is shown in Figure 1-14.
Figure 1-14: Block diagram of an embedded computer
The microcontroller has, at a minimum, a CPU, a small amount of internal memory (ROM and/or RAM), and some form of I/O, which is implemented within a microcontroller as subsystem blocks. These subsystems provide the additional functionality for the processor and are common across many processors. The subsystems that you will typically find in microcontrollers will be discussed in the coming chapters. For the moment though, let's take a quick tour and see the purposes for which they can be used.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Chapter 2: Electronics 101
. . . in reality, nothing but atoms and void
—Democritus
In writing this book, my hope is to bring to you an understanding of the design process involved in producing an embedded computer system. To this end, I have kept the electronics, the chips, and the systems I have used as simple as possible. I want you to understand the big picture without getting lost in the details. But, no matter how simple I keep the computer designs, you won't get very far without at least a very rudimentary understanding of electronics. So this chapter presents basic background theory to guide you on your way. Electronics is a truly vast and complex multidisciplinary field, and it is not possible to cover even a thousandth of it in a single chapter. What I will do is to give you an easy-to-understand grounding in the basic principles necessary for embedded computer engineering. The rest of the vast mountain I will leave unvisited. If you want to learn more, pick up a copy of Paul Horowitz and Winfield Hill's The Art of Electronics, published by Cambridge University Press. It's a great introductory text. For some fun, interactive online tutorials go to http://www.clarkson.edu/~svoboda/eta.
It's all about electrons— hence the term, "electronics." Electrons are subatomic particles with a negative charge. They are bound to positively charged atomic nuclei through Coulombic attraction. The classical physics view was to think of electrons "orbiting" the nucleus, analogous to planets orbiting a solar system. While not at all correct, this makes it easier to visualize what goes on. The strength by which electrons are bound to the nucleus varies from atomic element to atomic element and from molecule to molecule. Substances are either conductors, insulators, or semiconductors. In a conductor, such as a metal, the energy required to shift an electron from one nucleus to another is negligible, and the electrons may easily exchange with nearby atomic nuclei. In effect, the metal is a collection of nuclei surrounded by a "sea" of semifree electrons. In an insulator, the opposite is true. The energy required to shift an electron from a nucleus is excessive, and so electrons tend to stay put. In a semiconductor, the substance may act either as a conductor or as an insulator, depending upon external influences. By controlling the external influences, you change the conductivity of the substance, and therefore change the way electrons move within that substance. In effect, a semiconductor is a switch, a switch that may be controlled by other semiconductors. This basic principle is the basis of all modern electronics, the cornerstone upon which everything digital is founded.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Voltage and Current
It's all about electrons— hence the term, "electronics." Electrons are subatomic particles with a negative charge. They are bound to positively charged atomic nuclei through Coulombic attraction. The classical physics view was to think of electrons "orbiting" the nucleus, analogous to planets orbiting a solar system. While not at all correct, this makes it easier to visualize what goes on. The strength by which electrons are bound to the nucleus varies from atomic element to atomic element and from molecule to molecule. Substances are either conductors, insulators, or semiconductors. In a conductor, such as a metal, the energy required to shift an electron from one nucleus to another is negligible, and the electrons may easily exchange with nearby atomic nuclei. In effect, the metal is a collection of nuclei surrounded by a "sea" of semifree electrons. In an insulator, the opposite is true. The energy required to shift an electron from a nucleus is excessive, and so electrons tend to stay put. In a semiconductor, the substance may act either as a conductor or as an insulator, depending upon external influences. By controlling the external influences, you change the conductivity of the substance, and therefore change the way electrons move within that substance. In effect, a semiconductor is a switch, a switch that may be controlled by other semiconductors. This basic principle is the basis of all modern electronics, the cornerstone upon which everything digital is founded.
The flow of electrons through a conductor or a semiconductor is known as current. Current is measured in Amperes, more commonly called just plain Amps (with the unit symbol A). For an electron to move through a conductor, there must be a "vacancy" at the next nucleus into which it can shift. (If the next nucleus has a full complement of electrons, the Coulombic repulsion of those electrons will prevent any others from slotting in.) Semiconductor physicists term these vacancies as
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Analog Signals
An analog signal can have an amplitude of any voltage within a range, unlike a digital signal, which can be in one of two defined voltage states (either high or low). Figure 2-1 shows a typical analog signal (in this case, a sine wave).
Figure 2-1: An analog waveform
The voltage of a signal may vary over time, or it may be constant. If the voltage varies, it may repeat at regular intervals, in which case the signal is said to be periodic. The period is the interval of time that it takes the signal pattern to repeat (for example, from one wave crest to another). The frequency of the signal is the number of times per second that the pattern repeats.
Frequency is measured in Hertz (Hz) and relates to the period in the following way:
Frequency = 1 / Period
Thus, a signal with a period of 1ms has a frequency of 1kHz.
A unipolar signal (Figure 2-2) has component voltages that are either all positive or all negative. A bipolar signal (Figure 2-3) has both positive and negative voltages.
Figure 2-2: Unipolar signal
Figure 2-3: Bipolar signal
A typical analog signal will have both an AC component and a DC component (Figure 2-4). The DC component is the fixed voltage of the signal. The AC component is a varying voltage imposed upon the DC component. The AC component is sometimes referred to as the peak-to-peak amplitude of a signal and is denoted with the suffix pp. For example, an AC component of 5V would be written as 5Vpp.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Power
A voltage difference is generated by a difference in potential energy between two points. Therefore, to generate a voltage you use a device that can create such an energy difference. Such devices may be mechanical (generators), which convert motion into a potential difference by electromagnetics, photovoltaic (solar cells), or chemical (batteries). Conversely, a voltage difference (and thereby current flow) can be used to produce mechanical movement (motors), light emission (lightbulbs, LEDs), and heat (toasters, Pentium 4 processors).
Power is the amount of work per time (Joules per second) and is measured in Watts (unit symbol W). The equation for calculating power is simply:
P = V * I
No electronic device is 100% efficient (far from it!), and so it will consume power as it performs its task. The power consumed by a device may be calculated using the preceding equation, from the voltage difference across the device and the current flowing through the device. A typical embedded computer may consume a few hundred mW (milliWatts) of power, but it can vary quite considerably. A large and powerful embedded machine may use several tens (or even hundreds) of Watts, while a tiny embedded controller may use just microWatts.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Resistors
Even a conductor (such as a metal wire) is not 100% efficient at conducting current flow. As current flows through the wire, energy will be lost as heat (and sometimes light). For very small currents, this energy loss is negligible, but for large currents, the loss can cause the conductor to become quite hot (an effect utilized in toasters) or glow brightly (lightbulbs). This loss of energy results in a voltage difference across the wire (or component). The component is said to resist the current flow. This resistance (also known as impedance, although impedance is somewhat more complex than simple resistance) is measured in Ohms (unit symbol Ω, equation symbol R). Schematics commonly leave off the Ω symbol, so 100kΩ is usually written as just 100k.
On a schematic, a 4.7kΩ value may be written not as 4.7k, but rather as 4k7. The reason is that it is too easy for a decimal point to be missed or lost when the document is photocopied. The solution is to place the multiplier (k) in the position of the decimal point. Resistors such as 24.9Ω are written as 24R9.
This convention is used by design engineers in most of the world. However, in North America, it is only sometimes followed.
The relationship between voltage, current, and resistance is known as Ohm's Law , and is given by:
V = I * R
For a fixed resistance, a varying voltage will produce a varying current, while a constant voltage will produce a constant current. Hence, a varying voltage source is known as an Alternating Current source (or AC), while a constant voltage source is known as a Direct Current source (DC). An AC voltage is normally specified as VAC, while a DC voltage is either VDC or more often just V.
The stuff that comes out of your wall socket is AC and is nominally 110-120VAC (at 60Hz) if you live in North America, 100VAC if you're in Japan (50Hz in the eastern half—Tokyo—and 60Hz in the western half—Osaka, Kyoto, and Nagoya), and 220-240VAC (at 50Hz) if you're in Australia, New Zealand, the UK, or Europe. All digital electronics, and that includes computers, use DC internally and operate at typical voltages of either 5V or 3.3V. (Some digital electronics will operate at voltages as low as 1.8V or even lower.) The
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Capacitors
While a resistor is a component that resists the flow of charge through it, a capacitor stores charge. Capacitance is measured in Farads (or more formally, Faradays) with an equation symbol C and a unit symbol F. Typical capacitors you will use will range in value from μF (microFarads) down to pF (picoFarads).
The relationship between current, capacitance, and voltage is given by:
I = C * dV/dt
where dV/dt is the rate of voltage change over time.
The schematic symbols for capacitors are shown in Figure 2-10. The component on the left is bipolar, while the other two are unipolar. A unipolar capacitor has a positive lead and a negative lead, and it must be inserted into a circuit with the correct orientation. Failing to do so will cause it to explode. (Unipolar capacitors have markings to indicate their orientation.) A bipolar capacitor has no polarity.
Figure 2-10: Capacitor symbols
Applying a voltage across a capacitor causes the capacitor to become charged. If the voltage source is removed and a path for current flow exists elsewhere in the circuit, the capacitor will discharge and thereby provide a (temporary) voltage and current source (Figure 2-11).
Figure 2-11: Capacitor charging and discharging
This is an extremely useful characteristic. A given voltage source may have a DC component (a fixed voltage) and an AC component (a ripple voltage superimposed). (Here component does not mean a physical device, but rather a fractional part of a voltage.) The capacitor becomes charged by the DC component of the voltage source to a given level and then alternately charged and discharged with the AC component. In effect, the capacitor averages out the peaks and troughs of the AC component and, as a result, removes the AC ripple from the voltage source. This is known as the capacitor
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
RC Circuits
Combining resistors and capacitors can yield some interesting and useful effects. A resistor-capacitor combination is known as an RC circuit, and they can take one of three forms. In the first form, the resistor and capacitor are in parallel (Figure 2-14).
Figure 2-14: Resistor and capacitor in parallel
Now, what does this do? A voltage (V) applied across the pair will charge the capacitor (as well as some current flowing down through the resistor). When the applied voltage is removed, the capacitor will discharge through the resistor. The resistor will limit the rate of discharge, since it limits current flow. From Ohm's Law, we have that:
I = -V / R
(The negative voltage is because we're discharging the capacitor.) Now, the current flow out of a capacitor is given by:
I = C * dV/dt
So, we have:
dV/dt = -V / RC
Integrating this with respect to time, with zero initial conditions, gives us:
V = e-t/RC
            
This gives us the discharge waveform shown in Figure 2-15, which represents the voltage across the capacitor.
Figure 2-15: Discharge of a parallel RC circuit
A parallel RC circuit will provide an exponential decay in the output voltage. The value for t when the output voltage is at 37% of the maximum is known as the time constant for the circuit and is simply the product of R and C:
t = R * C
For example, a parallel RC circuit in which the resistor is 100kΩ and the capacitor is 10μF gives a time constant of 1 second.
The second form of RC circuit is the series RC circuit, shown in Figure 2-16.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Inductors
Inductors are passive components that are essentially a coil of conductive wire. The schematic symbol for an inductor is shown in Figure 2-21. Inductance is measured in Henrie s, with an equation symbol L and a unit symbol H.
Figure 2-21: Schematic symbol for an inductor
The voltage across an inductor changes the current flow through it, by the following relation:
V = L * dI/dt
Whereas applying a current to a capacitor caused the voltage to build across it, the opposite is true for an inductor. Applying a voltage across it builds current flow through it, and the resulting energy is stored in the inductor as a magnetic field. When the applied voltage is removed, the field collapses and returns the stored energy as a voltage spike.
Figure 2-22 shows a series R-L circuit.
Figure 2-22: Series R-L circuit
The voltage across the resistor (VR) and the voltage across the inductor (VL) are shown in Figure 2-23. When a voltage is applied at VIN, the voltage across the resistor is initially small, whereas the voltage across the inductor is large. As the current flow through the inductor builds, the voltage across the resistor increases, while the voltage across the inductor diminishes accordingly.
Figure 2-23: Series R-L response to a step input
Figure 2-24 shows a series R-L-C circuit.
Figure 2-24: R-L-C circuit
The response (V
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Transformers
Transformers are related to inductors. A transformer consists of two coils of wire, known as the primary and the secondary, that are closely coupled magnetically. The schematic symbol for a transformer is shown in Figure 2-28.
Figure 2-28: Schematic symbol for a transformer
An AC current flowing through the primary coil will generate an associated electromagnetic field. The strength of the field is proportional to the number of turns in the coil of the primary. Because the secondary coil is within this field, the field will generate a current flow through (and therefore a voltage difference across) the secondary. Since the secondary has a different number of windings in the coil than the primary, the field generated by the primary will create a different voltage and current in the secondary (provided, of course, that the secondary is part of a circuit so that current can flow). Therefore, a transformer can be thought of as a voltage multiplier (or divider). The ratio of the number of turns in the primary and secondary coils will determine the voltage multiplication.
Since transformers are usually exceptionally efficient, most of the power in the primary is transferred across to the secondary. If the secondary increases the voltage of the primary, then the secondary's current will correspondingly be smaller than in the primary. Conversely, if the voltage across the secondary is less than the primary, the current through the secondary will therefore be larger than in the primary.
Transformers are commonly used inside power supplies to convert the high line voltage (110VAC or 240VAC, depending on where you live) to a much lower voltage for use by electronic systems and other appliances. They also serve to provide isolation between the powered system and the high-voltage supply.
A transformer with a ratio of
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Diodes
Diodes are extremely useful semiconductor devices. They have the interesting characteristic that they will pass a current in one direction, but block it from the other. They can be used to allow currents to flow from one part of a circuit to another but prevent other currents from "backwashing" where you don't want them.
The schematic symbol for a diode is shown in Figure 2-29. The arrow indicates the direction of conduction. The arrow represents the anode , or positive side, of the diode, while the bar represents the cathode , or negative side, of the diode. A higher voltage on the left of the component will allow current to be passed through to the right. However, a higher voltage on the right will prevent current flow to the left.
Figure 2-29: Schematic symbol for a diode
Diodes have a forward voltage drop when conducting. This means that there will be a voltage difference between the anode and the cathode. For example, a diode may have a forward voltage drop of 0.7V. If this diode is part of a larger circuit and the voltage at the anode is 5V, then the voltage at the cathode will be 4.3V.
Diodes are useful for removing negative voltages from a signal, a process known as rectification. Four diodes may be combined together to form a bridge rectifier, as shown in Figure 2-30. The bridge "flips" the negative components of the wave so that only a positive voltage is present at the output. A capacitor on the output can be used to smooth the rectified wave.
Figure 2-30: Bridge rectifier
Such configurations are commonly used on the power inputs to embedded computers and other digital systems. A voltage can be applied across the inputs on the left, with no regard to which should be positive or negative. The bridge rectifier ensures that a positive voltage will always be conducted to the upper right, and at the same time current flow is returned from the lower right, through the bridge rectifier to whichever lefthand connection is negative.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Crystals
Finally in our component tour, we come to crystals. Just as their name suggests, they are a small block of quartz (silicon dioxide). Quartz crystal is a type of material known as a piezoelectric . This is a substance that generates a voltage when it is stressed (compressed, stretched, twisted). This effect is utilized in microphones. The sound vibrates the piezoelectric material, and it produces a small AC voltage that is directly proportional to the original sound that created it. This voltage is then amplified for broadcasting, recording, or processing.
The opposite effect is also true for piezoelectric materials. Apply a voltage and the piezoelectric material will contort or vibrate. Some speakers use piezoelectric materials to produce their sound. However, most use other techniques, such as electromagnetics. Most loud buzzers are based on piezoelectrics.
Now, the neat thing about quartz is that for a block of a given size, it will vibrate at a given (and fixed) frequency. For that reason, it can be used as an oscillator to generate a sine wave, which in turn can be used to generate timing signals for microprocessors and other digital circuits. Just about every computer system will have a crystal (or two) somewhere on its circuit board, generating the timing that ultimately drives the whole machine. That crystal is simply a small block of quartz, plated at either end with wires attached and encased in a metal can.
The schematic symbol for a crystal is shown in Figure 2-35.
Figure 2-35: Schematic symbol for a crystal
Crystals require a drive circuit to make them go. These tend to be a bit temperamental and don't always oscillate at the frequency you expect, due to a range of effects that are hard to track down. Fortunately, there are two easy ways around this problem. The first is that most processors (and other chips requiring timing) have internal oscillator circuits. All you need to do is add the external crystal (and maybe a capacitor or two), and it will work beautifully. For chips that don't make life quite so easy, you can get complete oscillator modules, which include the crystal and drive circuit. All you need to do is give them power and ground, and they too work beautifully.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Digital Signals
Being an electronic circuit, the operation of a computer is about voltages and current flow. Understanding the basic principles of voltages and current flow within the computer is mandatory if you're going to produce a working system. Common operating voltages inside a computer are normally either 5V or 3.3V. For some low-power or exceptionally fast computers, voltages may be as small as 1.8V or even lower.
An output pin of a digital device can be in one of three states. It can be high (logic 1), low (logic 0), or tristate (high impedance , also known as floating ). A logic high is defined as the output voltage at the pin being higher than a given threshold. When a device's pin is outputting a high, it is said to be sourcing current to that connection. Similarly, a logic low is when the output voltage is below a given threshold, and the device's pin is said to be sinking current . Typically, components can sink more current than they can source.
A tristate pin is outputting neither a high nor a low. Instead, it becomes high impedance (high resistance) so that current flow in or out of the pin is negligible. It is, in effect, invisible to other components to which it is connected. For example, within a computer system may be several memory devices connected to the data bus. When a particular device is being read, its data outputs will be either high or low (corresponding to the bit pattern being read back). All other memory devices in the system, because they are not being accessed, will have their data buses tristate. They take no part in the read transaction between the processor and the accessed memory device.
The threshold for logic high and the threshold for logic low can vary from device type to device type. For an input device to recognize a given signal as high or low, the output device must provide that signal within the appropriate limits. The thresholds can vary, but are always consistent across devices of the same
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Understanding Schematics
You won't get very far in electronics unless you know how to draw and read schematics. They crop up everywhere, and understanding them is a must. The schematics are like an architect's blueprint. They show what components will be used in a circuit and how they are connected together. The schematics may also include other information such as construction directives. A schematic may have a list of revisions indicating what changes have been made to the original design. These are commonly called Engineering Change Orders, or ECOs for short. As a design grows and changes over time, it's a good idea to keep track of what changes were made and, just as important, why they were made. Just as commenting source code is important, so is keeping track of the ECOs.
You will come across two types of schematics. You will see schematics in datasheets, books like this one, and other technical documents. These schematics will just show the circuit (or partial circuit), maybe a note or two, and that's all. The other sort of schematic is the actual drawing(s) used to generate a circuit board. These schematics represent a full system design and will often have a title block located in the lower right of the sheet, indicating what the sheet represents, as well as who drew it and when. Figure 2-39 shows an example title block.
Figure 2-39: Title block
Essentially there are two types of objects on a schematic, components and nets. Nets are the wires that show what is connected to what. A component will have a component name and a component type. For example, a memory chip may have the name U3 and have a component type AT45DB161. The component name is simply a reference label, much like a variable name in source code. The component type is the actual part number used by the component manufacturer.
It is common practice with component names to use common prefixes for components of the same type. For example, resistors have the prefix
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Read the Datasheet
Before starting any design, you need to work out the basic requirements for your system (what it will do, how much it can cost) and select what major components you will need (such as choosing a processor, I/O, and memory). Before you do anything else, obtain the datasheets/books for these components and read them from beginning to end. These can typically be found on manufacturers' web sites (every chip used in this book was specifically chosen because it had full technical data available online). Just go to the manufacturer's web site and download the relevant documentation.
Once you've read the data thoroughly and feel you understand it, go back and reread it to pick up all the things you missed on the first pass. Stop complaining; it's good for you. Think of it as a character-building exercise. It's much better to discover something critical that you've missed before you design and build a computer than after.
Always make sure that you have the latest datasheets and errata (datasheet bug lists) before you begin a design. Using a datasheet that is even a little bit old is not a good idea. It is not unusual for the electrical and technical specifications to change from time to time, so it's critical that you're using the latest (and most accurate) data.
It is very important that you understand how the devices work. When you are debugging your system, you have to know what to look for to know whether different parts of your computer are functioning. Don't assume anything about the functionality of the devices. Read and check everything carefully, including voltage levels, basic timing, and anything else that may be relevant to the system.
If possible, a very useful thing to include in your design is a serial interface, even if you don't need a serial port for the final application. A serial port is extremely useful for printing out diagnostic and status information from the system and can be an indispensable diagnostic tool (for both hardware and software). We'll look at serial ports in Chapter 10. The other mandatory debugging tool is the status LED. A flashing LED can tell you volumes about a machine under test if used intelligently by the software and programmer. The more status LEDs you have, the better life will be! (We'll see how to add a status LED in Chapter 6.)
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Chapter 3: Power Sources
The attention span of a computer is only as long as its electrical cord.
—Turnaucka's Law
There is one important aspect that must be included in all embedded computer designs—power. In this chapter, we look at power sources for your computer and voltage regulation to keep your power smooth and reliable.
Your embedded computer system needs electricity. You have several options when it comes to powering your system: coal, nuclear, hydro, geothermal, or batteries. The first four fall under the general category of "juice from the wall."
If your system doesn't need to be portable, this is the most obvious choice. What comes down the pipe is AC and far too high a voltage to be of immediate use to a digital system. It must be converted to a DC voltage of significantly lower magnitude. There are plenty of solutions for doing this. You can use DC lab power supplies, standard PC supplies (probably overkill for your needs), or AC adapters. The last of these is probably the best choice for most applications.
AC adapters (also known as plug packs or sometimes power bricks) are the little black boxes that come with your cell phone and a host of other appliances. They are a cheap, easy, and reliable solution and can be purchased from any good electronics vendor. Typically, they will provide an output voltage somewhere in the range of +5VDC to +12VDC and can supply a current of up to 500mA, depending on the particular plug pack. Choose one that can supply an appropriate voltage and current for your system. One caveat with plug packs is the polarity of the connector. Some plug packs have the positive voltage on the center of the connector jack and ground on the outside. Other plug packs have the exact opposite arrangement! Not knowing which you have could lead to disastrous consequences for your embedded system. As always, check the technical data. A better way is to incorporate a bridge rectifier as part of your design (Figure 3-1). The input power is DC, but the polarity of the connection makes no difference. The embedded system uses the output of the rectifier as its power source and has internal voltage regulation. (We'll discuss regulators shortly.)
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Juice from the Wall
If your system doesn't need to be portable, this is the most obvious choice. What comes down the pipe is AC and far too high a voltage to be of immediate use to a digital system. It must be converted to a DC voltage of significantly lower magnitude. There are plenty of solutions for doing this. You can use DC lab power supplies, standard PC supplies (probably overkill for your needs), or AC adapters. The last of these is probably the best choice for most applications.
AC adapters (also known as plug packs or sometimes power bricks) are the little black boxes that come with your cell phone and a host of other appliances. They are a cheap, easy, and reliable solution and can be purchased from any good electronics vendor. Typically, they will provide an output voltage somewhere in the range of +5VDC to +12VDC and can supply a current of up to 500mA, depending on the particular plug pack. Choose one that can supply an appropriate voltage and current for your system. One caveat with plug packs is the polarity of the connector. Some plug packs have the positive voltage on the center of the connector jack and ground on the outside. Other plug packs have the exact opposite arrangement! Not knowing which you have could lead to disastrous consequences for your embedded system. As always, check the technical data. A better way is to incorporate a bridge rectifier as part of your design (Figure 3-1). The input power is DC, but the polarity of the connection makes no difference. The embedded system uses the output of the rectifier as its power source and has internal voltage regulation. (We'll discuss regulators shortly.)
Figure 3-1: A bridge rectifier makes an embedded system "polarity proof"
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Batteries
Batteries are easy to use. The only catch is that the battery (or batteries) you choose must supply enough current at the right voltage. With the right choice of battery and a carefully designed system, you can achieve extended operation over very long periods of time. For example, a small PIC- or AVR-based computer can (depending on application and design) operate for up to two years off a single AA battery. A poorly designed system can drain a battery in minutes. A poorly chosen battery unable to supply sufficient current will result in erratic operation or may result in the system being unable to start at all. When choosing a battery, consider not just its average current capability but also its peak current. An embedded computer may need only a constant supply of 20mA but may require as much as 100mA at peak loads. This is especially true of systems using flash memory, which may require high currents during write operations. The battery for such a system must be able to supply not just the continuous load but also the peak load when required.
Power consumption in an embedded system can be reduced in several ways. The use of low-power devices is the most obvious place to start. The power consumption of different devices varies considerably, and many low-power variants of common devices are available. RISC processors often have lower power consumption than comparable CISC processors, so they are often used in preference to CISC in lowpower applications. The PIC and AVR microcontrollers can have current draws of less than 5mA (and as low as 10nA when in sleep mode!). This is considerably less than the 35mA of a 68HC11 microcontroller.
Many memory chips and peripherals will enter a low-power mode when they are not in use. However, the power consumption of some devices can be reduced even further. A useful technique for reducing a system's power consumption is to turn off devices when not in use. If the processor is executing code from RAM and outputting data to a serial port, then the power to the ROMs and any other I/O devices may be turned off, as they are not in use.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Regulators
A voltage regulator is a semiconductor device that converts an input DC voltage (usually a range of input voltages) to a fixed-output DC voltage. They are used to provide a constant supply voltage within a system.
While many components in an embedded system can operate from a wide power-supply range, a fixed operating voltage is necessary for such devices as Analog-Digital Converters (ADCs), since many use the internal power supply as a reference. In other words, the output voltage of a sensor is sampled as a percentage of the voltage supply of the ADC. If the supply is not a known voltage, then any sampling performed by the ADC is meaningless. (We'll look at ADCs in Chapter 12.)
Therefore, a voltage regulator is required to provide a constant voltage source and, thereby, a constant voltage reference. Further, a voltage regulator can assist in removing power-supply noise and can provide a degree of protection and isolation for the embedded system from the external power source. If your system is operating from a battery, the varying current draw of your system can combine with the battery's internal resistance to create a varying supply voltage. The addition of a voltage regulator prevents this from becoming a problem to your embedded system. Including a voltage regulator in your design is good practice. National Semiconductor has a good online tutorial on using and designing voltage regulator circuits. It can be found at http://www.national.com/appinfo/power/webench.
The types of regulators we will look at are termed DC-DC converters. They take an unregulated DC voltage (often over a range of possible voltages) and provide a constant DC voltage output of a fixed value.
There are three types of DC-DC converters: linear regulators , which produce lower voltages than the supply voltage; switching regulators that can step up (boost), step down (buck), or invert the input voltage; and charge pumps
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Chapter 4: Building It
No thing happens in vain, but everything for a reason and by necessity.
—Leucippus, On Mind
Before we get into designing a machine, let's spend some time looking at how to produce the physical machine. Building a computer that doesn't work is really easy. You may have a perfect design and flawless code, but ignore the physical environment in which the machine exists, and you'll have built yourself a very intricate paperweight.
In this chapter, I'll also show you how to lay out a circuit board (and where to be especially careful) and how to debug your hardware. In particular, I'll examine how to physically produce the design for the ATtiny15 computer, which is presented in Chapter 6. I assume that you're hand building in small quantities, so I'll target the discussion accordingly. What I present here is not the state of the art in circuit board design or assembly, but guidelines for cottage-industry computer production. If you need to make production runs of hundreds of thousands, either you already know what you're doing (and can skip this section) or you need to talk to a professional.
Digital systems are inherently analog in operation. Digital signals suffer degradation and noise due to analog effects present in the system. Spurious noise or reflections from nearby electrical machinery or radio transmissions can induce signals within your circuit that can cause false events to occur or even prevent a digital system from functioning at all. The one way to ensure that your system is immune to electromagnetic interference is to avoid the use of electricity! Unfortunately, the steam-powered microprocessor is not a reality, so if your system is to operate reliably in the real world, you must take electromagnetic effects into account. What follows is not a comprehensive overview of noise and associated problems and solutions. It is far too complex a field to cover properly here. What I will do is just provide an introduction. The subject is worth seeking out more detailed information and understanding these concepts more thoroughly.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Avoid Noise
Digital systems are inherently analog in operation. Digital signals suffer degradation and noise due to analog effects present in the system. Spurious noise or reflections from nearby electrical machinery or radio transmissions can induce signals within your circuit that can cause false events to occur or even prevent a digital system from functioning at all. The one way to ensure that your system is immune to electromagnetic interference is to avoid the use of electricity! Unfortunately, the steam-powered microprocessor is not a reality, so if your system is to operate reliably in the real world, you must take electromagnetic effects into account. What follows is not a comprehensive overview of noise and associated problems and solutions. It is far too complex a field to cover properly here. What I will do is just provide an introduction. The subject is worth seeking out more detailed information and understanding these concepts more thoroughly.
The United States, Australia, the nations of the European Union, and many other countries have very strict guidelines and requirements for electromagnetic emission and immunity. The recommendations presented here are good practice only and are not necessarily sufficient to warrant compliance in your country. Therefore, it is important that you check your local regulations and ensure that you meet the appropriate requirements. Compliance cannot be guaranteed just by design. A system must be tested to ensure that it is compliant.
Noise can be a significant problem in digital systems. Noise can disturb signal transmission leading to corrupted data or may even cause a program to crash. Problems with an embedded system may or may not be noise related. Inadequate power-supply levels, insufficient decoupling capacitors, marginal timing tolerances, and software bugs can all cause seemingly random glitches in operation. However, even a well-conceived system can be disrupted by noise. There may be noise problems inherent in the design. Switching noise from integrated circuits, ringing, and cross talk are all due to aspects of the designed system. Other forms of noise may be due to environmental effects (such as nearby motors or radio emissions). The bad news is that electromagnetic problems are getting worse for digital systems. The environment is bathed in ever-increasing emissions from radio, TV, and cell phone towers. At the same time, integrated circuits are becoming increasingly sensitive as designs move toward higher speed and lower power operation.
Additional content appearing in this section has been removed.
Purchase this book now or read it online at Safari to get the whole thing!
Quick-and-Dirty Construction
It is possible to build very simple circuits by just soldering the components together in free space. For example, with the AVR design in this chapter, the leads of the watch crystal can be soldered directly onto the pins of the processor, with the crystal lying across the top of the processor. Wires are soldered onto the pins bringing in ground and power and connecting the processor's I/O to the outside world. This technique is variously referred to as "a rat's nest," a "bird's nest," or "what the hell is that?"
This is a quick-and-dirty method, useful for rapid prototyping of extremely simple circuits. It's not really recommended, but you can get away with it in a pinch. Don't try it with anything that is even slightly complicated or running at any reasonable speed. If you do, you'll spend more time debugging the construction than debugging the actual design or code!
Breadboards are plastic blocks with arrays of holes. They are designed to hold DIP-packaged integrated circuits and discrete components. The term "breadboard" dates back to the olden days when valve radios were constructed on a base of solid wood (a cutting board for bread). The term has stuck, and the modern breadboard can still be found in electronics hobbyist stores and even the occasional university teaching lab.
While it is possible to build very low-speed microprocessor systems and general digital circuits on breadboards, try not to. There be dragons! As a general rule, breadboards are bad news and you should avoid using them at all costs. (Think of them as the hardware equivalent of COBOL.) Breadboards suffer from excessive capacitance, crosstalk, and noise susceptibility, which makes them completely inappropriate for microprocessor system const