Final Mod1
Final Mod1
Embedded Systems
and MicroControllers
By
Venkata Sridhar .T M.Tech,PhD,MIETE
2
By T.VenkataSridhar , ETC
Overview and Prerequisite
Overview contd..:
Early Forms of Embedded Systems
Fig. 1. Control panel and paper tape transport view of a Colossus Mark II
3 computer (public image by the British Public Record Office, London)
By T.VenkataSridhar , ETC
Overview and Prerequisite
Overview contd..: :
Birth and Evolution of Modern Embedded Systems
The beginning of the decade of 1970 witnessed the development of the first
micro-processor designs. By the end of 1971, almost simultaneously and
independently, design teams working for Texas Instruments, Intel, and the US
Navy had developed implementations of the first microprocessors.
Microprocessor designs soon evolved from 4-bit to 8-bit CPUs. By the end of
the 1970s, the design arena was dominated by 8-bit CPUs and the market for
microprocessors-based embedded applications had grown to hundreds of
millions of dollars.
The list of initial players grew to more than a dozen of chip manufacturers that,
besides Texas Instruments and Intel, included Motorola, Zilog, Intersil, National
Instruments, MOS Technology, and Signetics, to mention just a few of the most
renowned.
Despite this flourishing in CPU sizes and manufacturers, the applications for
embedded systems have been dominated for decades by 8, 16 and 32-bit
microprocessors and so on.-
5 By T.VenkataSridhar , ETC
Overview and Prerequisite
Overview contd..: :
6 By T.VenkataSridhar , ETC
Overview and Prerequisite
Overview contd..: :
Architecture of the MSP430 Processor: Central Processing Unit, Addressing Modes, Constant
Generator and Emulated Instructions, Instruction Set, Examples, Reflections on the CPU and
Instruction Set, Resets, Clock System, Memory and Memory Organization. 2 Hrs
Functions, Interrupts, and Low-Power Mode: Functions and Subroutines, Storage for Local
Variables, Passing Parameters to a Subroutine and Returning a Result, Mixing C and Assembly
Language, Interrupts, Interrupt Service Routines, Issues Associated with Interrupts, Low-Power
Modes of Operation. 2 Hrs
8 By T.VenkataSridhar , ETC
Module-1
Introduction to Embedded Electronic Systems and
Microcontrollers
Definition:
❖ An embedded system is an applied computer system, as
distinguished from other types of computer systems such as
personal computers (PCs) or supercomputers.
10
By T.VenkataSridhar , ETC
11
By T.VenkataSridhar , ETC
12 By T.VenkataSridhar , ETC
Embedded Systems Design
When approaching embedded systems architecture design from a
systems engineering point of view, several models can be applied to
describe the cycle of embedded system design.
Most of these models are based upon one or some combination of the
following development models.
13 By T.VenkataSridhar , ETC
The waterfall model, in which there is a process for developing a
system in steps, where results of one step flow into the next step.
▪ This factor is the process shown in Figure 1-1, and this is why this model is
introduce as an important tool in understanding an embedded system’s
design process.
14 By T.VenkataSridhar , ETC
Figure 1-1: Embedded Systems Design and Development
Lifecycle Model.
15 By T.VenkataSridhar , ETC
As shown in Figure 1-1, the embedded system design and development
process is divided into four phases:
o Creating the architecture,
o Implementing the architecture,
o Testing the system, and
o Maintaining the system.
17 By T.VenkataSridhar , ETC
Architecture-level information is physically represented in the form of
structures. A structure is one possible representation of the architecture,
containing its own set of represented elements, properties, and
inter-relationship information. A structure is therefore a “snapshot” of the
system’s hardware and software at design time and/or at run-time, given a
particular environment and a given set of elements. Since it is very
difficult for one “snapshot” to capture all the complexities of a system, an
architecture is typically made up of more than one structure. All structures
within an architecture are inherently related to each other, and it is the sum
of all these structures that is the embedded architecture of a device.
18 By T.VenkataSridhar , ETC
Table 1-2
19 By T.VenkataSridhar , ETC
The Embedded Systems Model
A variety of architectural structures are used to introduce technical
concepts and fundamentals of an embedded system. This is an emerging
architectural tools (i.e., reference models) used as the foundation for these
architectural structures.
At the highest level, the primary architectural tool used to introduce the
major elements located within an embedded system design is what refer to
as the Embedded Systems Model, shown in Figure 1-2.
1. They all have at least one layer (hardware) or all layers (hardware,
system software and application software) into which all components
fall.
3. whereas the system and application software layers contain all of the
software located on and being processed by the embedded system.
23 By T.VenkataSridhar , ETC
Embedded Hardware
Prerequisite:
✔Basic Hardware Materials: Conductors, Insulators, and Semiconductors
✔Common Passive Components on Boards & in Chips: Resistors, Capacitors, & Inductors.
✔Semiconductors and the Active Building Blocks of Processors and Memory
✔Putting It All Together: The Integrated Circuit (IC): SSI to ULSI
2. These diagrams and symbols are the keys to quickly and efficiently
understanding even the most complex hardware design, regardless of how
much or little practical experience one has in designing real hardware.
Block diagrams
They typically depict the major components of a board (processors, buses, I/O,
memory) or a single component (a processor, for example) at a systems
architecture or higher level. In short, a block diagram is a basic overview of the
hardware, with implementation details abstracted out. While a block diagram can
reflect the actual physical layout of a board containing these major components, it
mainly depicts how different components or units within a component function
together at a systems architecture level.
Schematics.
Schematics are electronic circuit diagrams that provide a more detailed view of
all of the devices within a circuit or within a single component everything from
processors down to resistors. A schematic diagram is not meant to depict the
physical layout of the board or component, but provides information on the flow
of data in the system, defining what signals are assigned where—which signals
travel on the various lines of a bus, appear on the pins of a processor, and so on.
In schematic diagrams, schematic symbols are used to depict all of the
components within the system.
25 By T.VenkataSridhar , ETC
Wiring diagrams.
These diagrams represent the bus connections between the major and minor
components on a board or within a chip. In wiring diagrams, vertical and horizontal
lines are used to represent the lines of a bus, and either schematic symbols or more
simplified symbols (that physically resemble the other components on the board or
elements within a component) are used. These diagrams may represent an
approximate depiction of the physical layout of a component or board.
Logic diagrams/prints.
Logic diagrams/prints are used to show a wide variety of circuit information using
logical symbols (AND, OR, NOT, XOR, and so on), and logical inputs and
outputs (the 1’s and 0’s). These diagrams do not replace schematics, but they can
be useful in simplifying certain types of circuits in order to understand how they
function.
Timing diagrams.
Timing diagrams display timing graphs of various input and output signals of a
circuit, as well as the relationships between the various signals. They are the most
common diagrams (after block diagrams) in hardware user manuals and data
sheets.
26 By T.VenkataSridhar , ETC
Regardless of the type, in order to understand how to read and
interpret these diagrams, it is first important to learn the standard
symbols, conventions, and rules used.
27 By T.VenkataSridhar , ETC
An example of a timing diagram is shown in Figure 1-6. In this
figure, each row represents
a different signal.
A title section located at the bottom of each schematic page, listing information
that includes, but is not limited to, the name of the circuit, the name of the
hardware engineer responsible for the design, the date, and a list of revisions made
to the design since its conception.
Along with the assigned symbol comes a label that details information about
the component (i.e., size, type, power ratings, etc.). Labels for components of a
symbol, such as the pin numbers of an IC, signal names associated with wires, and
so forth are usually located outside of the schematic symbol.
Abbreviations and prefixes are used for common units of measurement (i.e., k
for kilo or 103, M for mega or 106) and these prefixes replace writing out the units
and larger numbers.
One of the most efficient ways of learning how to learn to read and/or create a
hardware diagram is via the Traister and Lisk method, which involves:
Step 1. Learning the basic symbols that can make up the type of diagram, such
as timing or schematic symbols. To aid in the learning of these symbols,
rotate between this step and steps 2 and/or 3.
Step 3. Writing a diagram to practice simulating what has been read, again until
it either becomes boring (which means rotating back through steps 1
and/or 2) or comfortable.
31 By T.VenkataSridhar , ETC
The Embedded Board and the von Neumann Model
Embedded Board
❖ PCBs are often made of thin sheets of fiber-glass. The electrical path of the
circuit is printed in copper, which carries the electrical signals between the
various components connected on the board.
❖ All electronic components that make up the circuit are connected to this
board, either by soldering, plugging in to a socket, or some other connection
mechanism.
32 By T.VenkataSridhar , ETC
Figure 1-8: Embedded board
and the Embedded Systems
Model
At the highest level, the major hardware components of most boards can be
classified into five major categories:
33 By T.VenkataSridhar , ETC
These five categories are based upon the major elements defined by the von
Neumann model (see Figure 1-9), a tool that can be used to understand any
electronic device’s hardware architecture.
The von Neumann model
35 By T.VenkataSridhar , ETC
Figure 1-10a: AMD/National Semiconductor ×86 reference board.
© 2004 Advanced Micro Devices, Inc. Reprinted with permission.
36 By T.VenkataSridhar , ETC
Figure 1-10b: Net Silicon ARM7 reference board
37 By T.VenkataSridhar , ETC
Figure 1-10c: Ampro MIPS reference board
38 By T.VenkataSridhar , ETC
Figure 1-10d: Ampro PowerPC reference board .
Copyright of Freescale Semiconductor, Inc. 2004. Used by permission.
39 By T.VenkataSridhar , ETC
Figure 1-10e: Mitsubishi analog TV reference board
Embedded Processors
Processors are the main functional units of an embedded board, and are primarily
responsible for processing instructions and data. An electronic device contains at
least one master processor, acting as the central controlling device, and can have
additional slave processors that work with and are controlled by the master
processor. As shown in Figure 1-11, the Atlas STPC is the master processor, and
the super I/O and ethernet controllers are slave processors.
40 By T.VenkataSridhar , ETC
As shown in Figure
1-11, embedded
boards are designed
around the master
processor. The
complexity of the
master processor
usually determines
whether it is
classified as a
microprocessor
or a
microcontroller.
❑ The set of machine code instructions that the processors within the architecture
group can execute.
❑ Processors are considered to be of the same architecture when they can execute
the same set of machine code instructions.
❑ Table 1-5 lists some examples of real-world processors and the architecture
families they fall under.
42 By T.VenkataSridhar , ETC
Table 1-5: Real-world architectures and processors.
43 By T.VenkataSridhar , ETC
ISA Architecture
▪Models
The features that are built into an architecture’s instruction set are commonly
referred to as the Instruction Set Architecture or ISA.
▪ The ISA defines such features as the operations that can be used by
programmers to create programs for that architecture, the operands (data) that are
accepted and processed by an architecture, storage, addressing modes used to
gain access to and process operands, and the handling of interrupts.
Operations
Operations are made up of one or more instructions that execute certain
commands. (Note that operations are commonly referred to simply as
instructions.) Different processors can execute the exact same operations using a
different number and different types of instructions. An ISA typically defines the
types and formats of operations.
Types of Operations
Operations are the functions that can be performed on the data, and they
typically include the following.
44 By T.VenkataSridhar , ETC
The instruction set on a popular lower-end processor, the 8051, includes just over
100 instructions for math, data transfer, bit variable manipulation, logical
operations, branch flow and control, and so on. In comparison, a higher end
MPC823 (Motorola/Freescale PowerPC) has an instruction set a little larger than
that of the 8051, but with many of the same types of operations contained in the
8051 set along with an additional handful, including integer
operations/floating-point (math) operations, load and store operations, branch and
flow control operations, processor control operations, memory synchronization
operations, PowerPC VEA operations, and so on.
45 By T.VenkataSridhar , ETC
In short, different processors can have similar types of operations, but usually
have different overall instruction sets. For example,
Figure 1-14b: MIPS32/MIPSI “CMP” and “ADD” operation sizes and locations.
47 By T.VenkataSridhar , ETC
Operands
▪ Operands are the data that operations manipulate. An ISA defines the types and
formats of operands for a particular architecture.
▪ For example, in the case of the MPC823(Motorola/Freescale PowerPC),
SA-1110 (Intel StrongARM), and many other architectures, the ISA defines
simple operand types of bytes (8 bits), half words (16 bits), and words (32 bits).
More complex data types such as integers, characters, or floating point are
based on the simple types shown in Figure 1-15a.
❑ Addressing Modes
ISA Models
There are several different ISA models that architectures are based upon, each
with their own definitions for the various features.
Application-specific,
General-purpose,
Instruction-level parallel,
or some Hybrid combination of these three ISAs.
50 By T.VenkataSridhar , ETC
Application-specific ISA Models
Application-specific ISA models define processors that are intended for
specific embedded applications, such as processors made only for TVs. There are
several types of application specific ISA models implemented in embedded
processors, the most common models being:
Controller Model
The Controller ISA is implemented in processors that are not required to perform
complex data manipulation, such as video and audio processors that are used as
slave processors on a TV board, for example (see Figure 1-16).
Figure 1-21:
RISC ISA implementation
example.
57 By T.VenkataSridhar , ETC
Instruction-level parallel ISA Models
Instruction-level Parallelism ISA architectures are similar to
general-purpose ISAs, except that they execute multiple
instructions in parallel, as the name implies.
In fact, instruction level parallelism ISAs are considered higher
evolutions of the RISC ISA, which typically has one-cycle
operations, one of the main reasons why RISCs are the basis for
parallelism.
Examples of instruction-level parallelism ISAs include:
58 By T.VenkataSridhar , ETC
Single Instruction Multiple Data (SIMD) Model
The SIMD Machine ISA is designed to process an instruction simultaneously on
multiple data components that require action to be performed on them.
63 By T.VenkataSridhar , ETC
These two models primarily differ in one area, and that is memory. A von
Neumann architecture defines a single memory space to store instructions and
data. A Harvard architecture defines separate memory spaces for instructions
and data; separate data and instruction buses allow for simultaneous fetches and
transfers to occur. The main reasoning behind using von Neumann versus a
Harvard-based model for an architecture design is performance.
64 By T.VenkataSridhar , ETC
As mentioned previously, most processors are based upon some variation of the
von Neumann model (in fact, the Harvard model itself is a variation of the von
Neumann model). Real-world examples of Harvard-based processor designs
include ARM’s ARM9/ARM10, MPC860, 8031, and DSPs (see Figure 1-27a),
while ARM’s ARM7 and x86 are von Neumann- based designs (see Figure 1-27b).
The CPU is responsible for executing the cycle of fetching, decoding, and
executing instructions (see Figure 1-28).
As defined by the von Neumann model, this cycle is implemented through some
combination of four major CPU components:
❖ The internal CPU buses: interconnect the ALU, registers, and the CU.
❖ The arithmetic logic unit (ALU): implements the ISA’s operations.
❖ Registers: a type of fast memory.
❖ The control unit (CU): manages the entire fetching and execution cycle.
67 By T.VenkataSridhar , ETC
Figure 1-28: Fetch, decode, and execution cycle of CPU
68 By T.VenkataSridhar , ETC
Internal CPU Buses
The CPU buses are the mechanisms that interconnect the CPU’s other components:
the ALU, the CU, and registers (see Figure 1-29). Buses are simply wires that
interconnect the various other components within the CPU (Driver controlled
wires). Each bus’s wire is typically divided into logical functions, such as data
(which carries data, bi-directionally, between registers and the ALU), address
(which carries the locations of the registers that contain the data to be transferred),
control (which carries control signal information, such as timing and control
signals, between the registers, the ALU, and the CU), and so on.
Considered the core of any processor, the ALU is responsible for accepting
multiple n-bit binary operands and performing any logical (AND, OR, NOT, etc.),
mathematical (+, –, *, etc.), and comparison (=, <, >, etc.) operations on these
operands.
The ALU is a combinational logic circuit that can have one or more inputs and
only one output. An ALU’s output is dependent only on inputs applied at that
instant, as a function of time, and “no” past conditions
The basic building block of most ALUs (from the simplest to the
multifunctional) is considered the full adder, a logic circuit that takes three 1-bit
numbers as inputs and produces two 1-bit numbers.
70 By T.VenkataSridhar , ETC
Figure 1-30a: All ALU adders at a glance
71 By T.VenkataSridhar , ETC
Figure 1-30a: All ALU adders at a glance (contd..)
72 By T.VenkataSridhar , ETC
Multifunction ALUs that provide addition operations, along with other
mathematical and logical operations, are designed around the adder circuitry, with
additional circuitry incorporated for performing subtraction, logical AND, logical
OR, and so on (see Table 1-7).
73 By T.VenkataSridhar , ETC
Figure 1-31: Multifunction ALU gate-level circuitry
74 By T.VenkataSridhar , ETC
Figure 1-32: PowerPC core and the ALU
75 By T.VenkataSridhar , ETC
Registers
✔Registers are simply a combination of various flip-flops that can be used to
temporarily store data or to delay signals.
✔A storage register is a form of fast programmable internal processor memory
usually used to temporarily store, copy, and modify operands that are
immediately or frequently used by the system.
✔Shift registers delay signals by passing the signals between the various internal
flip-flops with every clock pulse.
✔The number of flip-flops within these registers also determines the width of the
data buses used in the system. Figure 1-33 shows an example of how eight
flip-flops could comprise an 8-bit register, and thus impact the size of the data
bus.
76 By T.VenkataSridhar , ETC
77 Figure 1-33: a: 8-bit register with 8 D flip-flops example , b: Example of gate level circuit of flip-flop
While ISA designs do not all use registers in the same way to process the data,
storage typically falls under one of two categories, either general purpose or
special purpose (see Figure 1-34).
Flags
Counters
On-Chip Memory
The CPU goes to memory to get what it needs to process, because it is in memory that
all of the data and instructions to be executed by the system are stored. Embedded
platforms have a memory hierarchy, a collection of different types of memory, each
with unique speeds, sizes, and usages (see Figure 1-37).
80 By T.VenkataSridhar , ETC
Read-Only Memory (ROM)
Figure 1-38: 8 x 8
ROM logic circuit
81 By T.VenkataSridhar , ETC
Acheaper and faster variation of the EEPROM is Flash memory. Where
EEPROMs are written and erased at the byte level, Flash can be written and
82 erased in blocks or sectors (a group of bytes). By T.VenkataSridhar , ETC
Random-Access Memory (RAM)
RAM (random access memory), commonly referred to as main memory, is memory in
which any location within it can be accessed directly (randomly, rather than
sequentially from some starting point), and whose content can be changed more than
once (the number depending on the hardware). Unlike ROM, contents of RAM are
erased if RAM loses power, meaning RAM is volatile. The two main types of RAM are
static RAM (SRAM) and dynamic RAM (DRAM).
83 By T.VenkataSridhar , ETC
Cache (Level-1 Cache)
Cache is the level of memory between the CPU and main memory in the memory
hierarchy (see Figure 1-40). Cache can be integrated into a processor or can be
off-chip. Cache existing on-chip is commonly referred to as level-1 cache, and SRAM
memory is usually used as level-1 cache. Because (SRAM) cache memory is typically
more expensive due to its speed, processors usually have a small amount of cache,
whether on-chip or off-chip.
84 By T.VenkataSridhar , ETC
Cache is used to store subsets of main memory that are used or accessed often.
Some processors have one cache for both instructions and data, while other
processors have separate on-chip caches for each.
Figure 1-40: Level-1 cache in the von Neumann and Harvard models
85 By T.VenkataSridhar , ETC
Processor Input/Output (I/O)
Input/output components of a processor are responsible for moving information
to and from the processor’s other components to any memory and I/O outside of
the processor, on the board (see Figure 1-41).
87 By T.VenkataSridhar , ETC
❖ A processor’s execution is ultimately synchronized by an external system or
master clock, located on the board.
❖ The CPU’s clock rate is expressed in MHz or GHz (mega or giga hertz) .
❖ Using the clock rate, the CPU’s execution time, which is the total time the
processor takes to process some program in seconds per program (total number of
bytes), can be calculated.
❖ From the clock rate, the length of time a CPU takes to complete a clock cycle is
the inverse of the clock rate (1/clock rate), called the clock period or cycle time
and expressed in seconds per cycle.
❖ Looking at the instruction set, the CPI (average number of clock cycles per
instruction) can be determined in several ways.
88 By T.VenkataSridhar , ETC
At this point the total CPU’s execution time can be determined by:
89 By T.VenkataSridhar , ETC
Other definitions of performance besides throughput include:
Benchmarks
90 By T.VenkataSridhar , ETC
Reading a Processor’s Datasheet
A processor’s datasheet provides key areas of useful processor information.
Datasheets exist for almost any component, both hardware and software, and the
information they contain varies between vendors.
Some datasheets are a couple of pages long and list only the main features of a
system, while others contain over 100 pages of technical information.
91 By T.VenkataSridhar , ETC
Figure 1-42a: MPC860 processor block diagram.© 2004 Freescale Semiconductor, Inc.
92 By T.VenkataSridhar , ETC
Figure 1-42b: MPC860 overview from datasheet.© 2004 Freescale Semiconductor, Inc.
93 By T.VenkataSridhar , ETC
Figure 1-42b: MPC860 overview from datasheet. Continued…
94 By T.VenkataSridhar , ETC
Figure 1-42b: MPC860 overview from datasheet. Continued…
95 By T.VenkataSridhar , ETC
Figure 1-42b: MPC860 overview from datasheet. Continued…
96 By T.VenkataSridhar , ETC
97 Figure 1-42b: MPC860 overview from datasheet. Continued… By T.VenkataSridhar , ETC
98 Figure 1-42b: MPC860 overview from datasheet. Continued… By T.VenkataSridhar , ETC
99 Figure 1-42b: MPC860 overview from datasheet. Continued… By T.VenkataSridhar , ETC
MPC860 Processor Thermal Characteristics
100
Figure 1-42b: MPC860 overview from datasheet. Continued…
By T.VenkataSridhar , ETC
101 Figure 1-42b: MPC860 overview from datasheet. Continued… By T.VenkataSridhar , ETC
102 Figure 1-42b: MPC860 overview from datasheet. Continued… By T.VenkataSridhar , ETC
Figure 1-43: MPC860 Thermal parameters Figure 1-44: Memory Hierarchy
Board Memory
❑ Embedded platforms can have a memory hierarchy, a collection of different
types of memory, each with unique speeds, sizes, and usages (see Figure 1-44).
❑ Some of this memory can be physically integrated on the processor, like registers
and certain types of primary memory, which is memory connected directly to or
integrated in the processor such as ROM, RAM, and level-1 cache.
❑ This includes other types of primary memory, such as ROM, level-2+ cache, and
main memory, and secondary/tertiary memory, which is memory that is connected
to the board but not the master processor directly, such as CD-ROM, floppy drives,
hard drives, tape, pen drive memory, SD card, Flash Drives, and external Hard
discs.
Primary memory is typically a part of a memory subsystem (shown in Figure 5-2)
made up of three components:
In general, a memory IC is made up of three units: the memory array, the address
decoder, and the data interface.
Figure 1-46d:
Figure 1-46b: Figure 1-46c:
168-pin DIMM example
DIP Example 30-pin SIMM Example.
106 By T.VenkataSridhar , ETC
ROM
ROM is a type of non-volatile
memory that can be used to
store data on an embedded
system permanently, typically
through a smaller on-board
battery source that is separate
from the board’s main power
source. The type of data stored
on ROM in an embedded
system is (at the very least) the
software required by the device
to function in the field after
being shipped out of the
factory. The contents of ROM
can typically only be read by
the master processor; however,
depending on the type of ROM,
Figure 1-47: the master processor may or
8 × 8 ROM logic circuit.
may not be able to erase or
107 modify the By data located , ETC
T.VenkataSridhar in
❑ The circuit in Figure 1-47 includes three address lines ( ) for all eight
words, meaning the 3-bit addresses ranging from 000 to 111 each represent one
of the 8 bytes.
❑ D0–D7 are the output lines from which data is read—one output line for each
bit. Adding additional rows to the ROM matrix increases its size in terms of the
number of address spaces, whereas adding additional columns increases a
ROM’s data size, or the number of bits per address it can store.
❑ EPROMs are made up of MOS (i.e., CMOS, NMOS) transistors whose extra
“floating gate” (gate capacitance) is electrically charged, and the charge trapped, to
store a “0” by the Romizer (memory programmer) through “avalanche induced
migration”—a method in which a high voltage is used to expose the floating gate.
❑ The floating gate is made up of a conductor floating within the insulator, which
allows enough of a current flow to allow for electrons to be trapped within the gate,
with the insulator of that gate preventing electron leakage.
❑ The floating gates are discharged via UV light, to store a “1” for instance. This is
because the high-energy photons emitted by UV light provide enough energy for
electrons to escape the insulating portion of the floating gate.
❑ EEPROMs are based upon NMOS transistor circuitry, except insulation of the
floating gate in an EEPROM is thinner than that of the EPROM, and the method
used to charge the floating gates is called the Fowler–Nordheim tunneling method
(in which the electrons are trapped by passing through the thinnest section of the
insulating material).
❑ EEPROMs typically have more erase/write cycles than EPROMs, but are also
usually more expensive. A cheaper and faster variation of the EEPROM is Flash
memory.
111 By T.VenkataSridhar , ETC
RAM
❑ With RAM, commonly referred to as main memory, any location within it can be
accessed directly and randomly, rather than sequentially from some starting point,
and its content can be changed more than once—the number of times depending on
the hardware.
❑ Unlike ROM, contents of RAM are erased if the board loses power, meaning
RAM is volatile.
❑ The two main types of RAM are static RAM (SRAM) and dynamic RAM
(DRAM).
❑ As shown in Figure 1-48, SRAM memory cells are made up of transistor-based
flip-flop circuitry that typically holds its data, due to a moving current being
switched bidirectionally on a pair of inverting gates in the circuit, until power is
cut off or the data is overwritten.
❑ To get a clearer understanding of
how SRAM works, let us examine a
sample logic circuit of 4 K × 8 SRAM
shown in Figure 1-48b. DRAM in
Figure 1-50.
112 Figure 1-48a: Six-transistor SRAM cell, DRAM cell.
In this example, the 4 K × 8 SRAM is a 4
K × 8 matrix, meaning it can store 4096 (4
× 1024) different 8-bit bytes, or 32 768
bits of information. As shown in Figure
1-48b, 12 address lines (A0–A11) are
needed to address all 4096
(000000000000b– 111111111111b)
possible addresses—one address line for
every address digit of the address. There
are eight input and output lines
(D0–D7)—a byte for every byte stored at
an address.
There are also CS (chip
select) and WE (write
enable) input signals to
indicate whether the
data pins are enabled
(CS) and to indicate
Figure 1-51b:
DRAM write timing diagram.
❑ Because cache holds copies of what is in main memory, it gives the illusion to the
master processor that it is operating from main memory even if actually operating
from cache.
As with any scheme, each of the cache schemes has its strengths and drawbacks.
Whereas the set associative and full associative schemes are slower than the direct
mapped, the direct mapped cache scheme runs into performance problems when
the block sizes get too big. On the flip side, the cache and full associative schemes
are less predictable than the direct mapped cache scheme, since their algorithms
are more complex.
117 By T.VenkataSridhar , ETC
Finally, the actual cache swapping scheme is determined by the architecture. The
most common cache selection and replacement schemes include:
❑ Optimal, using future reference time, swapping out pages that won’t be used in
the near future.
❑ Least Recently Used (LRU), which swaps out pages that were used the least
recently.
❑ First In First Out (FIFO), another scheme that, as its name implies, swaps out
the pages that are the oldest, regardless of how often they are accessed in the
system. While a simpler algorithm then LRU, FIFO is much less efficient.
❑ Not Recently Used (NRU), which swaps out pages that were not used within a
certain time period.
❑ Second Chance, a FIFO scheme with a reference bit, if “0” will be swapped out
(a reference bit is set to “1” when access occurs, and reset to “0” after the check).
❑ Clock Paging, pages being replaced according to clock (how long they have
been in memory), in clock order, if they haven’t been accessed (a reference bit is
set to “1” when access occurs, and reset to “0” after the check).
❑ Certain types of memory can be connected directly to the master processor, such
as RAM, ROM, and cache, while other types of memory, called secondary memory,
are connected to the master processor indirectly via another device.
Figure 1-52 e: CD
❑ There are several different types of memory that can be integrated into a system,
and there are also differences in how software running on the CPU views
logical/virtual memory addresses and the actual physical memory addresses—the
two-dimensional array or row and column.
❑Memory managers are ICs designed to manage these issues. In some cases, they
are integrated onto the master processor.
The two most common types of memory managers found on an embedded board
are MEMCs and MMUs (Memory controller and Memory management unit
respectively).
MMUs mainly allow for the flexibility in a system of having a larger virtual
memory (abstract) space within an actual smaller physical memory. An MMU,
shown in Figure 1-54, can exist outside the master processor and is used to
translate logical (virtual) addresses into physical addresses (memory mapping), as
well as handle memory security (memory protection), controlling cache, handling
bus arbitration between the CPU and memory, and generating appropriate
exceptions.
123 By T.VenkataSridhar , ETC
Figure 1-54: Motorola/Freescale M68020 external memory management.
❑ There are specific timing parameters associated with memory (memory access
times, refresh cycle times for DRAM, etc.) that act as indicators of memory
performance.
124 By T.VenkataSridhar , ETC
Solutions for improving the bandwidth of main memory include:
❑ Using DRAMs, such as DRDRAM and SLDRAM, that integrate bus signals
into one line, to decrease the time it takes to arbitrate the memory bus to access
memory.
The processor communicates with these peripherals by reading from, and writing to,
particular addresses in memory.
These memory locations are called special function registers or peripheral registers to
distinguish them from ordinary memories, which simply store data, but exactly the same
commands are used—no special commands are needed.
In practice, microcontrollers spend much of their time handling the peripheral registers.
This shows the central role of memory in a microcontroller.
130 By T.VenkataSridhar , ETC
MSP430
The MSP430 is a mixed-signal microcontroller family from Texas
Instruments, first introduced on 14 February 1992. Built around a 16-bit CPU,
the MSP430 was designed for use with low power consumption embedded
applications and for low cost.
In summary, it is a particularly straightforward 16-bit processor with a von
Neumann architecture, designed for low-power applications.
Many portable devices include liquid crystal displays, which the MSP430 can
drive directly.
MSP430x3xx: The original family, which includes drivers for LCDs. It is now
obsolescent.
132 By T.VenkataSridhar , ETC
MSP430x4xx: Can drive LCDs with up to 160 segments. Many of them are
ASSPs, but there are general-purpose devices as well. Their packages have
48–113 pins, many of which are needed for the LCD.
Curiously, this is not marketed as a separate family: The devices are included in
the MSP430F2xx and MSP430F4xx families with nothing in their part number
to distinguish them. The CPU is a MSP430x if there is more than 64KB of
memory.
Pin-Out
The pin-out shows which interior functions are connected to each pin of the
package.
There are several diagrams for each device, corresponding to the different
packages in which it is produced.
There is also a plastic small-outline thin package (TSSOP). This has a similar
shape but is a surface-mount device with pins 0.65mm (about 0.025) apart.
A general warning: Packages with the same shape do not always have the same
pin-out.
Perhaps the most obvious feature is that almost all pins have several functions.
Most applications do not use all the peripherals so, with luck, there is no conflict
where a design needs more than one function on a pin simultaneously.
The memory data bus is 16 bits wide and can transfer either a word of 16 bits or a
byte of 8 bits. Bytes may be accessed at any address but words need more care.
The address of a word is defined to be the address of the byte with the lower
address, which must be even.
An important case is that instructions are composed of words and must therefore
lie on even addresses.
Figure: Ordering of
bits, bytes, and
words in memory.
There are two ways in which these two bytes can be stored in the two bytes of a
word in memory and both are in use.
Little-endian ordering: The low-order byte is stored at the lower address and the
high-order byte at the higher address. This is used by the MSP430 and is the more
common format.
Big-endian ordering: The high-order byte is stored at the lower address. This is
used by the Freescale HCS08, for instance.
Memory Map
Figure below shows the memory map of the F2013. Maps are sometimes drawn
with addresses increasing up the page, as one would normally draw the vertical
axis on a graph. Most MSP430 devices have a similar memory map, differing only
in the size of the regions for RAM and code.
Peripheral registers with byte access and peripheral registers with word
access: Provide the main communication between the CPU and peripherals. Some
must be accessed as words and others as bytes. They are grouped in this way to
avoid wasting addresses. If the bytes and words were mixed, numerous unused
bytes would be needed to ensure that the words were correctly aligned on even
addresses.
Random access memory: Used for variables. This always starts at address
0x0200 and the upper limit depends on the size of the RAM. The F2013 has 128
B.
Code memory: Holds the program, including the executable code itself and any
constant data. The F2013 has 2KB but the F2003 only 1KB.
It includes the arithmetic logic unit (ALU), which performs computation, a set of
16 registers designated R0–R15 and the logic needed to decode the instructions
and implement them. The CPU can run at a maximum clock frequency fMCLK of
16MHz in the MSP430F2xx family and some newer MSP430x4xx devices, and
8MHz in the others.
145 By T.VenkataSridhar , ETC
Figure: Registers in the CPU of the MSP430.
Program counter, PC: This contains the address of the next instruction to be
executed, “points to” the instruction in the usual jargon. Instructions are composed
of 1–3 words, which must be aligned to even addresses, so the lsb of the PC is
hard-wired to 0.
Stack pointer, SP: When a subroutine is called, the CPU jumps to the subroutine,
executes the code there, then returns to the instruction after the call. It must
therefore keep track of the contents of the PC before jumping to the subroutine, so
that it can return afterward. This is the primary purpose of the stack.
146 By T.VenkataSridhar , ETC
147 By T.VenkataSridhar , ETC
Status register, SR: This contains a set of flags (single bits).
Constant generator: This provides the six most frequently used values so that they
need not be fetched from memory whenever they are needed. It uses both R2 and
R3 to provide a range of useful values by exploiting the CPU’s addressing modes.
• A fast clock to drive the CPU, which can be started and stopped rapidly to
conserve energy but usually need not be particularly accurate.
• A slow clock that runs continuously to monitor real time, which must therefore
use little power and may need to be accurate.
Crystal: Accurate (the frequency is close to what it says on the can, typically
within 1 part in 105) and stable (does not change greatly with time or temperature).
Crystals for microcontrollers typically run at either a high frequency of a few MHz
to drive the main bus or a low frequency of 32,768 Hz for a real-time clock.
The MSP430 addresses the conflicting demands for high performance, low power,
and a precise frequency by using three internal clocks, which can be derived from
up to four sources. These are the internal clocks, which are the same in all devices:
Addressing Modes
A key feature of any CPU is its range of addressing modes, the ways in which
operands can be specified.
The MSP430 has four basic modes for the source but only two for the destination
in instructions with two operands.
150 By T.VenkataSridhar , ETC
All 16 of these are treated on an almost equal basis, including the four
special-purpose registers.
An instruction itself fits into a single word of 16 bits, although it may be followed
by further words to provide addresses or an immediate value.
There are three formats of instruction of TI’s standard abbreviations of src for
source and dst for destination. It is important to distinguish between these because
the destination has fewer addressing modes.
Double operand (Format I): Arithmetic and logical operations with two operands
such as add.w src, dst, which is the equivalent of dst += src in C.
Jumps: The jump to the destination rather than its absolute address, in other words
the offset that must be added to the program counter.
The constant in this form of indexed addressing is the absolute address of the data.
This is already the complete address required so it should be added to a register that
contains 0.
Absolute addressing is shown by the prefix & and should be used for special
function and peripheral registers, whose addresses are fixed in the memory map.
This example copies the port 1 input register into register R6:
For example, suppose that the stack were as (shown in stack Figure) with
SP=0x027C. Then the preceding instruction would load 0x1234 into R6.
This is available only for the source and is shown by the symbol @ in front of a
register, such as @R5. It means that the contents of R5 are used as the address of
the operand. In other words, R5 holds a pointer rather than a value.
This could require commonly used values like 0 and 1 to be stored frequently in
the code, which would be wasteful of both memory and time because the values
would have to be fetched from memory whenever they were needed.
To improve efficiency, most RISCs therefore have one or more registers that are
“hardwired” to commonly used values.
158 By T.VenkataSridhar , ETC
Typically there is only one value per register but the designers of the MSP430
cleverly exploited its four addressing modes for a source to get four values from
its dedicated constant generator R3/CG2.
The status register R2/SR/CG1 can be read and written almost normally in
Register mode. It therefore acts as constant generator CG1 when it is used as a
source in the other three addressing modes.
Thus seven constants are available from the two registers. These provide the base
of 0 for absolute addressing, and the six immediate values 0, 1, 2, 4, 8, and
0xFFFF=−1 for signed values.
A problem with this approach is that the constants can be used only as the source.
Do not attempt to use any of the constant generators as a destination.
159 By T.VenkataSridhar , ETC
Instruction Set
The MSP430 has 27 native instructions, and a further 24 emulated instructions are
defined to make coding easier for the programmer.
The instruction set is orthogonal with few exceptions, meaning that all addressing
modes can be used with all instructions and registers.
It show the .w form for operations that can use either bytes or words.
Stack Operations
These push data onto the stack and pop them off.
These instructions are used when operands are binary-coded decimal (BCD) rather
than ordinary binary values.
This means that the value of each nibble is restricted to the range of unsigned,
decimal integers 0–9 instead of the full hexadecimal range 0–F.
The number of MCLK cycles required for most instructions is limited by access to
memory. This is a typical feature of a RISC-like CPU with a von Neumann
architecture and also applies to the ARM7, for instance.
• Data can be fetched from a nonexistent address: empty regions of the memory
map. Execution proceeds as normal but the “fetched” value is random.
• Data for a word should be aligned to even addresses but you could attempt to
fetch a word from an odd address. I found that the lsb of the address was ignored
and the word was fetched from the resulting even address.
• A related case of this is the range of peripheral registers with word access. It
appears that the lsb of their addresses is ignored because they are intended to be
read only as words. It is possible to read the lower byte alone but not the upper
byte: An attempt to read the upper byte returns the lower byte instead.
Illegal Instructions
Instructions are 16-bit words in the MSP430 but not all 216 possible binary values
are used; roughly one eighth have no operations associated with them. The
instruction map is available at “RISC 16-bit CPU” in the family user’s guides.
170 By T.VenkataSridhar , ETC
Examples
Copying Strings
The first example is based on the standard library function strcpy (destination,
source), which copies a null-terminated string from source to destination.
• Simplicity
• Registers of the CPU
• Is the MSP430 a RISC—and Should It Be?
* Small set of general-purpose instructions:
* Large bank of general-purpose registers:
* Load–store architecture:
* Single-cycle execution:
• Addressing Modes
• Instruction Set
The initial conditions for all registers and peripherals after a POR and PUC are
specified in the family user’s guides.
175 By T.VenkataSridhar , ETC
It is important to identify the source of a reset when debugging. No single register
holds all the relevant flags but most are in the interrupt flag register 1, IFG1. This
may contain the following flags, depending on the variant:
• WDTIFG shows that the watchdog timed out or its security key was violated.
• OFIFG indicates an oscillator fault (this causes a nonmaskable interrupt, not a
reset).
• RSTIFG shows a reset caused by a signal on the RST/NMI pin.
• PORIFG is set for a power-on reset.
• NMIIFG flags a nonmaskable interrupt (not reset) caused by a signal on the
RST/NMI pin.
Clock System
All microcontrollers contain a clock module to drive the CPU and peripherals.
Figure below shows a simplified diagram of the Basic Clock Module+ (BCM+)
for the MSP430F2xx family.
176 By T.VenkataSridhar , ETC
177 By T.VenkataSridhar , ETC
178 By T.VenkataSridhar , ETC
Functions, Interrupts, and Low-Power Modes
A well-structured program should be divided into separate modules—functions in
C or subroutines in assembly language. There is nothing special about this in
embedded systems.
Interrupts are a major feature of most embedded software. They are vaguely like
functions that are called by hardware rather than software. The distinction sounds
trivial but it makes them much harder to handle because the processor must be
able to return correctly to its activity before it was interrupted.
The low-power modes of operation: they are described here because the MSP430
needs an interrupt to wake it from a low-power mode. In fact we see that no extra
effort is usually needed to handle low-power modes in interrupts:
It makes programs easier to write and more reliable to test and maintain.
Functions are obviously useful for code that is called from more than one place
but should be used much more widely, to encapsulate every distinct function.
Functions can readily be reused and incorporated into libraries, provided that
their documentation is clear.
What Happens when a Subroutine Is Called?
To recap briefly, the call instruction first causes the return address, which is the
current value in the PC, to be pushed on to the stack.
180 By T.VenkataSridhar , ETC
The address of the subroutine is then loaded into the PC and execution continues
from there.
At the end of the subroutine the ret instruction pops the return address off the stack
into the PC so that execution resumes with the instruction following the call of the
subroutine.
Most functions need local variables and there are three ways in which space for
these can be allocated:
CPU registers are simple and fast and is done by pushing their values on to the
stack.
The third approach is to allocate variables on the stack and is generally used
when a program has run out of CPU registers.
Most programs are now written in C but it is occasionally worthwhile to write parts
of the code in assembly language. This can be done in several ways, described in
the reference guide for the EW430 C compiler and in the application note Mixing C
and Assembler with the MSP430. It is not complicated in principle but there are
plenty of pitfalls.
Check first to see whether an intrinsic function is available to do the job without
leaving C. Many of these are declared in the header file intrinsics.h to perform
functions that are not possible in standard C. For example, the _ _swap_bytes()
intrinsic function calls the swpb instruction.
The third method is to write a complete subroutine in assembly language and call it
from C. Obviously it is essential to get the calling convention correct.
186 By T.VenkataSridhar , ETC
Interrupts
Interrupts are like functions but with the critical distinction that they are requested
by hardware at unpredictable times rather than called by software in an orderly
manner.
A periodic interrupt should be highly predictable in real time, but this is not
apparent to the CPU. Interrupts are commonly used for a range of applications:
192
By T.VenkataSridhar , ETC
Further Refer
Systems Architecture: A Comprehensive Guide for
Engineers and Programmers (Elsevier(Singapore) Pvt.Ltd.Publications, 2005)
By
Tammy Noergaard
By
John H. Davies
193
UP
By T.VenkataSridhar , ETC