In a simple design, the software definition, like the hardware definition, may describe the software for a single board.. In a more complex design, where different software engineers wo
Trang 1
usually require extensive documentation detailing every function that the soft- ware performs
In a simple design, the software definition, like the hardware definition,
may describe the software for a single board In a more complex design, where
different software engineers work on different parts of the code for a single board, there may be a software definition for each individual engineer’s code
In a complex multiprocessor system, there may be an overall software docu-
ment, which I consider to be part of the system engineering specification The software specifications should include the following:
* A statement of the requirements, including the requirements definition, engineering specifications, and hardware definition, as appropriate
¢ The communication protocol to any other software, whether to another
processor or to another piece of the software for this processor This should
include descriptions of buffer interface mechanisms, command/ response protocols, semaphore definitions, and in short, anything to which the com- plementing code needs to talk
° A description of how the design was implemented, using flowcharts,
pseudocode, or other methods (Chapter 3 describes these in more detail.) Since software can be broken down more flexibly than hardware, it is diffi-
cult to pin down a single software definition format that works for everybody all the time The key is to define any interfaces that other engineers need to know about and identify the design details that engineers in the future might need to know
This discussion assumes that the hardware and software are fairly inde- pendent In a simple system like the pool timer, that is a good model The
hardware is designed, the software is written around that hardware, and that
is that While the actual design implementations may proceed in parallel, the software engineer basically writes code around the hardware available
In a more complex system, the process may be iterative For example, the
software and hardware engineers may have a meeting where they jointly decide what hardware is required to perform the function Large amounts of
memory may be required for data buffers, or the software group may request
a specific peripheral IC because an interface library already has been devel-
oped for it There are trade-offs, in this game, between ease of software devel-
opment and cost or complexity of hardware
Hardware/Software Partitioning
Once, while having lunch with a group of engineers, I jokingly made the statement that my design philosophy was to put everything under software
Trang 2control That way, bugs in the design by definition were the fault of the soft-
ware engineer
This flippant conversation touches on a real problem in any embedded system: Which functions should be performed in hardware and which in soft- ware? An example of this can be found in the pool timer As we will see in the
next chapter, the pool timer displays time information on four seven-segment
LED displays Display decoder ICs accept a four-bit input and produce the
signals necessary to drive the display This design takes a different approach and drives the display segments directly from a register, which is under soft-
ware control When the software wants to display a number, it has to convert
the number to the seven-segment pattern and write that pattern to a register The savings was a single IC in the design This approach also allows the code
to display nonnumeric symbols on the display (A, C, H, J, L, P, U), which I
used tor debugging the system
While this decision saved an IG, it had three costs: ROM space was needed for the lookup table, extra code had to be included for the hex to seven- segment conversion, and the software needed extra time to perform the trans-
lation Given the simplicity of this function, none of these was a serious
problem The table was 16 bytes long, the code took a few more bytes and
needed only a few microseconds to execute But the principle described is at
the heart of the software/hardware trade-off The more functions that can be pushed into software, the lower will be the product cost, up to the point where
a faster processor or more memory is required to implement the added
functionality
The pool timer demonstrates another example of this kind of trade-off,
which is discussed in Chapter 4
As the saying goes, there is no such thing as a free lunch Pushing func-
tionality into the software increases software complexity, development time,
and debug time This is an NRE, just like the mask ROM charges described earlier However, given the increasing speed and power of microprocessors, I expect to see an ever-increasing trend toward including as much functional-
ity in the software as possible
In a more complex system, these trade-offs can create heated discussion Should the software handle regular timer interrupts at a high rate and count them to time low-rate events or should an external timer be added that can
be programmed to interrupt the software when it times out? Should the soft-
ware drive the stepper motor directly or should an external stepper controller
be used? If the software drives the motor, should protection logic be included
to prevent damage to the motor drive transistors if the software turns on the wrong pair? And if the processor runs out of throughput halfway though the
project, did the design place too much burden on the software or did the soft-
ware engineer write inefficient code? The answers to these questions depend
Trang 3
on your design But if you stay in this field very long, be prepared to get into one of these discussions
While doing everything in software increases development costs, moving functionality to the hardware increases product cost, and these costs are meurred with every unit built In a low-cost design, addition of any extra hard- ware can have a significant effect on product cost, so the software /hardware trade-off can be extremely important In an extremely cost-sensitive design, such as a low-cost consumer product, functions that cannot be performed in software may simply be left out
Distributed Processor Systems
Multiprocessor systems will be covered in more detail in Chapter 7 Here, we summarize the trade-offs involved in choosing a multiprocessor architecture
A distributed processor system might have a single CPU that communicates
with a host computer and distributes commands and data to lower-level processors that control motors or collect data from sensors or perform some other simpler task
Distributed processor systems have the following advantages:
* The actual processing hardware can be located near the device being con- trolled or monitored In large equipment, this may be a real advantage
* If some of the functionality is optional, the cost of the processor that con- trols the option can be added or removed with the option
* In a distributed processor system, each of the distributed CPUs usually can
be a lower-performance (cheaper) part than would be required for one
central CPU
* A distributed system can be designed with a better match between the CPU and the task it must perform In a single-CPU system, the CPU must be fast enough, have enough memory, and so forth to perform all the tasks, whether simple or complex
® The code for any given CPU in a distributed system usually is simpler
* It is easier to determine if the CPU power is adequate in a distributed system, because fewer tasks are being swapped in and out and there is less interaction among the various processing that has to be performed
For example, you need not worry about how the motor control function
affects the serial interface throughput if the tasks are handled by separate
processors
* Debug of distributed systems can be simpler, since each processor performs
a limited set of tasks
Trang 4The advantages of a single-CPU system are:
Synchronization, when needed, is easier For instance, it is easier for a
single-CPU system to synchronize motor start-up to limit current surge,
simply by communication between tasks or by scheduling In a distributed system, such synchronization must be performed by CPU-to-CPU commu- nication or back through a common control CPU
All the data is in the same place, making communication with a host or other systems easier Fewer communication protocols are required to pass data around
Since there are fewer oscillators, there usually will be less EMI On the other hand, a faster processor may be required, operating at a higher frequency
and generating a lot of EMI
If the design changes so that intertask communication must be added, such
as for motor synchronization, a distributed design may require that inter-
faces be added to each distributed CPU In a single-CPU design, such a change is likely to be only to the software
It is easier to download or update code in a single-CPU system
Debug of a single-CPU system may be easier since all the functions are in
a single place and all the interactions can be examined Of course, these
interactions, task switching, and general complexity of the code can com-
plicate debug as well
Fewer development tools are needed, since there is only one processor In
a distributed system, the same thing can be achieved by using only one type
of CPU, but that defeats the ability to match the CPU to the task
If an RTOS is used, there will be fewer license fees in a single-CPU system But a more complex RTOS may be required
With increasing processor power at decreasing cost, I think more single- CPU designs are to be expected Some designs will take advantage of increased CPU horsepower to add new functions, such as real-time signal pro-
ce
so
er
ssing But motors and other electromechanical devices are getting no faster,
systems that interact with these devices probably will use fewer, more pow-
ful processors Complex systems that use a single Pentium-class CPU and a few 8-bit microcontrollers as smart sensors would not be surprising
Specifications Summary
Let us summarize the contents of the design documents described in this chapter before we look at the actual design of the rest of the book
24
The requirements document describes:
Embedded Microprocessor Systems
Trang 5What the design or system is to do
The user interface, if any
Any external interfaces to other systems What the real world I/O consists of
Hardware specifications (one per board or subsystem) describe:
The requirements, restated from engineering or requirements documents
How the hardware implements the functionality
The software interfaces to the hardware software specifications describe:
The requirements Interfaces to other software
How the software implements the requirements
A Requirements Document Outline
The following is an outline for a requirements document that will fit most products This document describes the product as a “black box”—what the product does, not how it is done
Overview A brief description of the document, such as “This document
describes the requirements for the ABC corporation swimming pool
timer.”
Related documents Related internal documents, such as product
specifications, environmental specifications, and the like Related
industry specifications such as ANSI or IEEE specifications
Specifications These could include the following:
Agency approvals List agency approvals that the product must meet, such
as FDA requirements, FEC 950, UL 1950, shock/vibration specifications, and so forth
Requirements, List system requirements The following items are typical
of the sort of thing that might be listed, and obviously all of these
items will not apply to all products This section is the core of the document and may run to dozens of pages
MTBF (mean time between failure) MTTR (mean time to repair, usually applies to products that are
serviced by a field service organization)
Trang 6Speed (How many things per minute/hour/day must be done?) Operator interface (LCD? touch panel? barcode readers?
mouse /keypad?)
External interfaces (interfaces to other systems, to a controlling host system, or to a slave subsystem Ethernet? RS-232?
Proprietary?)
Available options (may be lengthy if several need to be described) Input power (list input voltages, frequencies, and current; include
international requirements)
Export restrictions and requirements (applies if using controlled
technology; also, requirements for the product to be marketed in
certain countries may limit technology that can be used)
Input requirements (What size bottles does it use? What sizes of paper can it handle? How big or how small can the block of steel
be that goes into the input hopper?)
Capacity (How many blocks of steel or bottles or pieces of paper can it handle at a time?)
Error handling (What happens if the operator puts in too many bottles or a block of steel that is too heavy? What happens if power goes off halfway through the process?)
Weight (usually applies only to large or portable products)
Size (Does it have to fit through a standard door or on a standard
elevator? In a standard briefcase?)
Safety requirements: (Does it have to operate in standing water
with no danger of electrocution? Does it need a safety mat to
stop the robotic arm when a person steps inside the fence? Are there rotating mechanisms that must be covered or stopped when a door is opened? Must the operator be protected from
high temperatures?)
External interfaces (interfaces to external systems, like a 100 base-T
Ethernet interface to a computer network or an IRDA interface
to transfer data to and from a PC)
Note that there may be other requirements as well, such as media require- ments, customer versus field engineer maintenance items, and the like However, since we are concentrating on embedded systems, those are outside
the scope of this outline
Trang 7
Once the system is designed and the hardware requirements are established,
the next step is to design the actual hardware Of course, you will document
the design to make life easy for the software engineers, right?
Embedded microprocessors fall into two categories: Single-chip embedded
solutions with on-chip memory like the 8031 and embedded systems using a microprocessor with external memory and I/O Examples of these are a 68000-, 80186-, or 386EX-based embedded system
Figure 2.1 shows the simplest single-chip microprocessor designs and multichip designs Note that they are basically the same, except that the single- chip design has cverything inside the chip (inside the dashed line) and the multichip design has everything except the processor itself outside
Single-Chip Designs
Single-chip microprocessors (or microcontrollers) usually provide erasable
programmable read-only memory (EPROM; or ROM or flash memory), random access memory (RAM), and I/O ports Most also have internal timers, serial interfaces, or other peripherals The I/O ports are flexible, permitting each bit to be assigned as input or output
The actual design of single-IC systems is straightforward Before starting the design, you already know (or should know) that there are sufficient
I/O port pins, enough internal memory, and sufficient processor speed to do
the job
A single-IC design requires an external timebase This can be a clock
from some master source (such as a higher-level control processor), a crystal,
a ceramic resonator, or even a resistor/capacitor timing circuit on some
processors What you use depends on your cost requirements and how accu-
rate the timebase needs to be If you are using a crystal or resonator, connect
27
Trang 8
! SINGLE IC ' EPROM/ROM
'
!
1 ' ' '
1
<£=T| MICROPROCESSOR PORTS L DEVICES
CORE 1
' ' '
I
mi
CRYSTAL =]
EPROM/ROM
MULTIPLE IC
CRYSTAL | MICROPROCESSOR |_| PORTS DEVICES
T14 CORE '
L———E-—=——=——~—————-— Jd
RAM
DASHED LINES INDICATE FUNCTIONALITY CONTAINED IN MICROPROCESSOR IC
Figure 2.1
Single and Multiple IC Microprocessor Circuits
it according to the manufacturer’s data sheets If you are using an external
clock source, such as a packaged oscillator, make sure it meets the voltage and
capacitance drive specifications of the processor
Multichip Designs
While the similarity between single-chip and multichip designs shown in
Figure 2.1 is correct, it is somewhat misleading The architectures are similar,
but in the real world, a multichip design usually is more complex There
usually is more memory and generally more (or more complicated) I/O
ports A single-chip microcontroller may not be suitable for a design for many
reasons: insufficient I/O pins, insufficient RAM or ROM, or any of the other
Trang 9
considerations detailed in Chapter 1 However, once a decision has been
made to go to a multichip implementation, you take a quantum step in com- plexity A multichip design usually has most or all of the following as separate components:
Microprocessor
Random access memory (RAM)
Programmable read-only memory (PROM)
Peripherals (1/O devices)
The following table illustrates typical memory configurations for various
microprocessors The Atmel part is an 8-bit microcontroller, the NEC part is
a 32-bit microcontroller, the 80C188 is a midrange microprocessor, and the Pentium is a high-end microprocessor
Compared to a single-chip design, a multichip design costs more, takes more
PC board real estate, and is more complicated The benefits are more flexi-
bility, more expandability, and (usually) more processing power
In a multichip design, external peripherals (timers, I/O ports, analog-to- digital converters, etc.) must be connected to the microprocessor using the data and address buses There are several types of microprocessor bus cycles, but all do the same basic things: The microprocessor generates an address, which is decoded to select a peripheral (memory or I/O) device If the cycle
is a read cycle, the processor supplies a signal to tell the peripheral to drive its data onto the tristate data bus for the processor to capture If the cycle is
a write cycle, the processor drives the write data onto the data bus and
generates a signal indicating that the peripheral should capture the data Figure 2.2 shows typical timing diagrams for four families of processors:
Intel, Microchip, Zilog, and Motorola The speed of the signals varies
greatly from one processor to the next but the basic waveform is the same for
processors within a given family
The Intel timing diagram applies to Intel processors from the 8085 to
the 80188/80186 It also includes the Intel microcontroller 8x3x/8x5x family of parts, when those devices are used with external memory Other
Trang 10
INTEL TIMING DATA A
-RD OR -WR L_—
MICROCHIP DATA <p WRITE CYCLE
ZILOG Z8 “AS Li
FAMILY DATA ——x^~< vẻ
TIMING
MOTOROLA
68000 ADDRESS BUS ——><—— >>
FAMILY
TIMING DATA BUS —————“———_—>
Figure 2.2
Typical Microprocessor Bus Timing
manufacturers, such as Philips, also make variations on the 8x31 family that
use Intel-type timing to access external memory The NEC UPD7840xx micro-
controller family uses Intel timing, as does the Siemens/Infineon C167 family
when accessing external memory in a multiplexed mode
In the Intel scheme, the data bus is multiplexed with the address bus In a
processor with an 8-bit data bus, the 8 data bits are multiplexed with the 8 lower
address bits If the data bus is 16 bits, then all 16 data bits are multiplexed with
ithe lower 16 address bits Multiplexing is a common means to access external
memory because it saves pins—without multiplexing, accessing 64 kilobytes
(K) of memory with an 8-bit bus would require 24 pins just for the address and
data lines A multiplexed scheme requires only 16 pins for address and data
During the first part of the machine cycle (labeled A on the diagram), the
microprocessor places the address on the data bus, and it must be captured
by an external latch such as a 74AC373 The ALE (address latch enable) signal
is used to capture the address in the external latch After ALE goes inactive,
the processor generates a read or write strobe (-RD or -WR) to transfer data
to or from the external memory or I/O device For a read cycle, -RD is driven
low, indicating to the peripheral device that it should drive read data onto the
bus, which the processor will leave in the tristated condition For a write cycle,
-WR indicates that write data is available for the peripheral, and the proces-