Você está na página 1de 17

3241

Microprocessor and Application

1 Microcomputer Architecture
In this week, we will do a short general introduction to: (1) computer and computer architecture,
(2) microprocessor architecture, (3) microcontroller, and (4)PIC 18 microcontroller

1.1 Introduction to Computer and Computer Architecture


1.1.1 Introduction to computer
What is a computer?
There are many different definitions, more or less equivalent, of what a computer is. The
definition from Wikipedia says A computer is a programmable machine designed to
automatically carry out a sequence of arithmetic or logical operations. For any computer to
function properly, it must have the following three functions: (1) it accepts input (usually
numerical); (2) it can perform computational functions, such as addition, subtraction etc; (3) it can
communicate results with the person using it.

(Ancient) History of Computer:


Computer, broadly interpretated, has a very long history. It is widely believed that Sumerian
(todays Iraq area) people designed the first machine to help arithmetic computation abacus as
early as 2500 BC. The Abacus they designed are so effective that in 1946, it won a speed
competition against a modern desk calculation machine in Japan.
The first mechanical calculator was invented by Blause Pascal in 1642. The Pascaline (aka
Arithmatique) can perform all four arithmetic operations without human intelligence.
A central concept of modern computer is the ability to store programs. This concept is first
developed by Joseph Marie in 1801 in his Jacquard Loom. Jacquard Loom is not a computing
machine it is used to manufacture rugs and clothes. It uses a punched card to store programs to
control the machines operations to fabricate complex patterns.
Charles Babbage, considered as a father of the computer, invented the first mechanical
computer. He started to work on a machine called Difference Engine from 1822, used to compute
values of polynomial functions. Later, he started designing a different, more complex machine
called Analytical Engine. The main difference between the two engines is that the Analytical
Engine could be programmed using punched cards. This is the first fully programmable
mechanical computer, and served as the basis of early computers. Unfortunately, the Difference
Engine was never completed, and the Analytic Engine was completed in 1888 long after his death
by his son.
Although Babbage's machines were mechanical and unwieldy, their basic architecture was very
similar to a modern computer. The data and program memory were separated, operation was
instruction-based, the control unit could make conditional jumps, and the machine had a separate
I/O unit.
In 1941, Konrad Zues developed the first program controlled computer Z3. Z3 is an
electromechanical computer, using 2000 relays.

ME3241-week01.docx

3241

Microprocessor and Application

The first general purpose electronic computer Electronic Numerical Integrator and Computer
(ENIAC) - was developed in 1945-1946. Eniac weighs 27 tons and uses 1800 sqft space. It is
programmable, but rewiring is required to program the machine, hence is rather inflexible.
In 1946, Electronic Discrete Variable Automatic Computer (EDVAC) was developed. EDVAC
can store program using punch card, and is the first stored program electronic computer. Based on
EDVAC, John von Neumann draft a report which lies the foundation of modern von Neumann
Machine.

Generations of (Electronic) Computer:


Since the appearance of ENIAC/EDVAC, computers have evolved for four generations each
generation uses different components to make the computer less expensive, less power
consumption, more reliable and more powerful.
The first generation of computers (1947-1958) used vacuum tubes (ie. valves) as the main
components. Because of this choice, at most a few tens of thousands of switches (i.e., logic gates)
are used for one computer hence its computational power is limited. Also, the first generation
computer consumed much electricity, produced lots of heat and occupied large space (e.g.,
ENIAC).
The second generation of computers (1959-1965) used transistors as the main component. One
computer typically has many tens of thousans of switches, and is hence faster than the first
generation. Also, it is less expensive, use less power, smaller, and more reliable.
The third generation of computers (1966-1985) appeared following the inventionof Integrated
Ciruit (IC). IC, also refered as a chip, or a microchip, is a set of electronic circuits on one small
plate of semiconductor material. The third generations of computers used Small Scale Intergration
(SSI, several transistors on one chip), and later Medium Scale Intergration (MSI, hundreds of
transistors on one chip) and Large Scale Integration (LSI, tens of thousands of transistors on one
chip). Some other features of the third generation computers includes the use of Magnetic-core
memory (later replaced with solid-state memory) and batch processing operations systems.
One remarkable invention during the third generation is the micro-processor. A micro-processor
is one IC that contains the whole CPU. The first microprocessor appeared in 1973.
The fourth generation of computers (1986-current) use Very Large Scale Intergration (VLSI,
millions of transistors on one chip). Other features include the use of solid-state memory, timesharing operation systems, and supporting high level programming language (C, Java, etc).
Many techniques have been developed during the fourth generation. For example, microcomputer
- a computer that uses microprocessor as its CPU was invented by IBM. Also, computer
networks, email, graphical user interfact, among many others, are invented in the fourth
generation.
Because of the wide use of VLSI, the fourth generation computers are small, light, and cheap.
This makes embedded system possible. Embeded system is a system that contains a computer to
control its operation.

ME3241-week01.docx

3241

Microprocessor and Application

Classes of Computers:
Depends of the difference in speed, instruction repertoire, number of CPU registers, word length,
main memory size, complexity of I/O modules, operating system complexity, physical size, cost,
virtual address space, secondary memory size, degree of multiprogramming, modern computers
can be catergorized in to three clases: Mainframe, Minicomputer, Microcomputer. Notice that
speed is not the only difference, and often microcomputer can be faster than minicomputer or
even mainframe. Also, division between the computer classes are increasingly unclear.
Mainframe is a powerful computer used for critical application. The difference of mainframe
with other classes is not so much of spped, but high reliability and security.
Minicomputer is a mid-range computer. It is originally designed to connect microcomputer with
mainframes. It uses own Unix operating system, and is often incompatible with other machines.
Minicomputers are giving ways to microcomputers.
Microcomputer is a computer whose Central Processing Unit (CPU) is a microprocessor.
Recall notion of microprocessor: a processor that contrains the whole CPU (including control unit,
arithmetic and logic unit, and register) one one single IC chip.
Compare with the notion of micro-controller: the whole CPU and all peripheral functions (i.e.,
the whole computer system) that is implemented on one IC chip.

1.1.2 Introduction to Computer Architecture


Computer architecture is the art that specifies the relations and part of a computer system. One
early example was von Neumanns First Draft of a Report on the EDVAC, which described an
organization of logical elements. The machines following such organization is called the von
Neumann Machine. The von Neumann Machine architecture is still dominant most currently
used machines are von Neumann machines. Below is a diagram of the von Neumann machine.

Figure 1: Diagram of von Neumann machine

ME3241-week01.docx

3241

Microprocessor and Application

Components of von Neumann Machine:

A memory for holding both instructions and data required by the instructions
A control unit for fetching the instruction from memory
An arithmetic processor for performing the specific operation
Input/output and peripheral devices for transferring data to and from the system

Architechture of Microcomputer:
A von Neumann Machine can be a mainframe, a minicomputer or a microcomputer. We now
discuss the architechture of microcomputer. Almost all microcomputers are von Nermann
machines.
A microcomputer is made up of three fundamental elements: a central processor, memory and
input/output device - minimum structure. Notice that compare with the general von Neumann
machine structure, the control unit and the arithmetic processor are integrated together as the
central processor. (Why?)

Figure 2: Diagram of Microcomputer Arcitecture


Central Processor Unit (CPU) refers to the main processor in the system. Memory refers to any
component that stores data and programs used by the processor. Input/Output (I/O) refers to any
subsystem that has the responsibility of receiving data for the processor (input) and sending data
out from the processor (output). We will discuss each component in detail later.

System interconnection:
In microcomputer, system interconnection is done with the Bus Interconnection Scheme, see
below figure. Here, Bus refers to a set of 2 or more conductors grouped together to form a parallel

ME3241-week01.docx

3241

Microprocessor and Application

information path to and/or from the processor. In a microcomputer, typically three buses coexist,
namely, data bus, address bus and control bus.
Data bus is responsible for transferring data between processor and memory or processor and I/O.
Data bus width (in terms of number of bits) correlates with the default processing capacity of the
processor. For example, PIC 18 has a 8-bit data bus, and the processing capacity is one byte (=8
bit). Hence, PIC 18 is a 8-bit processor.
Address bus is responsible for transferring addresses from processor to memory or to I/O. The
width of address bus is hence correlated with the size of memory that the computer supports. For
example, a 16-bit address bus can support 65k memory.
Control bus is responsible for the control signals necessary to interface the various devices within
the microcomputer.

Figure 3: Bus interconnection Scheme

Memory:
Memory refers to any component that stores data and programs used by the processor. Since
1970s, the use of semiconductor memory (aka solid-state memory) has been dominant. Semiconductor memory has been through many generations: 1K, 4K, 16K, 256K, 1M (in late 1980s)
and now 1G bits on a single chip.
To access the memory, memory address and memory map are needed. Memory address is an n-bit
number that the processor uses to select a specific memory location. Hence, the number of unique
addresses =2n. A memory map designates the memory addresses that are connected to physical
memory locations and indicates which locations are unused. That is, it maps the address with the
physical memory. See below diagram.

ME3241-week01.docx

3241

Microprocessor and Application

Types of memory:
There are two types of memory: RAM (Random access memroy) and ROM (Read only memory).
RAM is volatile, i.e., it needs power to sustain data. It is called RAM because same amount of
time is required to access any location on the same chip. There are two types of RAM: Dynamic
random-access memory (DRAM) which needs period refersh, and Static random-access memory
(SRAM) which doesnt. DRAM is typically used for primary memory and SRAM for cache.
ROM can only be read but not written to by the processor. Mask-programmed read-only memory
(MROM) can only be programmed when being manufactured, while Programmable read-only
memory (PROM) can be programmed by the end user via a special equipment. PROM can only
be programmed once. EPROM can be programmed many time, but it must be done in a bulk
manner ie the whole chip in one erasure operation. EEPROM can be programmed many times,
either one location, one row or the whole chip. Flash memory can be programmed many times, in
bulk manner (either a block or the whole chip).

Input/output:
Input/output refers to any subsystem that has the responsibility of receiving data for the processor
(input) and sending data out from the processor (output). A port is an I/O connection that allows
the movement of data between computer and I/O device. A serial port allows two-way transfer of
data as a serial data stream (ie one bit a time). A parallel port transfers data in parallel (multiple
bit simultaneously). Analog interface is needed to cnvert analog to digital data or vice versa.

Central Processing Unit (CPU):


CPU refers to the main processor of the computer. It has three main components: Arithmetic logic
unit (ALU), register and control unit. ALU performs computation (both mathematical and logical
operations) on data, and return result of operation to register or memory. Register (aka register
file) is used to temporarily store data values and memory addresses, and to contain status and

ME3241-week01.docx

3241

Microprocessor and Application

control information. The control unit is the specific component of CPU that controls the CPU
operations, by issueing control signals or instructions.

The internal CPU interconnection is illustrated in the below figure:

ME3241-week01.docx

3241

Microprocessor and Application

Early computers have many chips for each different components of a CPU. Later on,
microprocessor contains all three units of the CPU in one chip. For modern microprocessor
(especially those general purpose ones), the CPU also contains memory on chip (aka cache
memory) for faster access.
A special type of microprocessor is microcontroller. Microcontroller contains all components of a
computer system (i.e., CPU, memory, I/O) in one single chip. See below table for comparison
between microprocessor and microcontroller.

1.2 Processor Design


1.2.1 Processor Microarchitecture
We now briefly processor microarchitecture the art to specify how the processor is built. Recall
the CPU has three components control unit, register and ALU.
The control unit performs two basic tasks: sequencing and execution. Sequencing refers to the
control unit causes the CPU to step through a series of micro-operations in the proper sequence,
based on program being executed. (instruction sequencing) Execution refers to the control unit
causes each micro-operation to be performed. (instruction interpretation).
Within the control unit, there are some special components: (1) Memory Address Register (MAR)
which contains address of current data word that is being addressed; (2) Memory Data Register
(MDR) that buffer and control the movement of data into/out of the processor; (3) Instruction
Register (IR) which contains the opcode for the current instruction; and (4) Instruction Decoder
that decodes the instruction in IR and controls the execution of the instruction. Notice that
although these component is called register, then do not belong to the registers of the CPU since
they can not be directly accessed by the program. Below is a diagram.
Example: to execute the instruction Fetch(address), three steps are needed 1. Load address
into MAR. 2. Decode address in MAR. 3. Copy memory location contents into MDR. To execute
Store(address, value), four steps are needed 1. Load address into MAR. 2.Load value into
MDR. 3.Decode address in MAR. 4.Store contents of MDR into that memory location

ME3241-week01.docx

3241

Microprocessor and Application

There are two ways to implement the control unit design. The hardwired control unit views the
control unit as a sequential logic circuit to generate fixed sequences of control signals. The
advantage is its speed of operation. The disadvantage is very inflexible to changes after built, and
costly to design and debug. The microprogrammed control unit uses microprograms to interest
and execute instruction, and hence easy to design and modify.
ALU is the unit to perform mathematical and logical operations on the data. Modern processors
often contain separate units for integer and floating point computation (floating point unit). Also,
modern processors use multiple execution units to execute instructions in parallel (e.g., dual-core,
quad-core etc).
Register is a small storage area to temporarily store data that the microprocessor is using. There
are some special regiserts which we elaborate. Accumulator is a special register that is directly
linked to ALU to assist with arithmetic operation (i.e, store one operand and the result of the
operation). Program counter (or instruction counter) keeps track of address of the next location in
memory that will be accessed. Status register contains bits to indicate certain results/status of the
last operation. Other special registers include stack pointer, address register etc.

1.2.2 Instruction Set Architecture


Instruction set architecture considers designing machine instruction and instruction set for the
processor.
Typically, an instruction needs to provide the following information
where are the data located (register, memory, etc)
what to do with the data
where to store the result.
The general format for instruction Z = X op Y is as follows:
Operator
1st operand
2nd operand
Result
op
X
Y
Z
The various methods to identify locations of the operands are called addressing modes. Each
processor has its own addressing modes. We will discuss in detail the ones for PIC18 later this
course. In general, there are the following types of address modes:

ME3241-week01.docx

3241

Microprocessor and Application

10

Immediate addressing: when the operand is part of the instruction. e.g.,


acc+3-> acc, here number 3 is immediate addressed
Absolute addressing: when the address of an operand is held in the instruction. Eg
acc + [0x0010] -> acc, here [0x1000] is absolute addressed, and the processor
will fetch the data store in memory address 0x1000
Register direct addressing: when the operand is held in an addressed register. Eg
acc + [0x0010] -> acc, here acc is register direct addressed. The processor will
use the data in accumulator
Register indirect addressing: when the address of the operand location is held in a
register. Eg, fetch [acc]. Here the address of the data is stored in accumulator, and
the machine will find the data stored in this address
Relative addressing: when the address of the operand is computed by adding an
offset held in the instruction to the contents of specific register. Eg, fetch [acc+1].
Here the address to fetch is the address stored in accumulator plus 1.

Instruction set design:


There are three types of instruction set Minimal Instruction Set, Reduced Instruction Set (RISC),
and Complex Instruction Set (CISC). The difference are increasingly unclear.
Instruction Execution and Pipeline
To execute an instruction, the processor must perform the following:
Fetch the instruction read the instruction opcode from the memory (opcode is the code
indicates which instruction to execute).
Advance program counter (PC) PC is updated to pointing to the address of the next
instruction.
Decode the instruction Opcode is decoded by the instruction decoder
Perform the instruction executed the instruction based on built-in sequence for the
specific instruction
The status register is updated to reflect the status of the operation
Thus, to execute one instruction, the process needs to do several tasks sequentially, and may take
some time. To reduce the execution time, pipelining is widely used. Pipelining overlap the
execution of several instructions to reduce the total time. In particular, the execution of one
instruction is divided into sections, and place latches between them.
As an example, suppose there is a processor which needs five steps to execute an instruction,
namely: fetch instruction (IF), decode instruction (ID), read registers (RR), execute instruction
(EE), write result into register (WR). Each step takes the same time, and the total time is 100ns.
Now consider the pipelined version, it divides this 100ms into 5 stages, as follows:
Fetch instruction + latch (one clock cycle)
Decode instruction + latch (one clock cycle)
Read register + latch (one clock cycle)
Execute instruction + latch (one clock cycle)
Write result into register (one clock cycle)
Suppose the latch latency is 3ns, then each execution cycle time = 100ns/5+3ns =23ns. In one
clock cycle, the processor is IF, ID, RR, EX and WR for 5 different instruction, and thus in the
long run, each instruction is executed with in one clock cycle. The below is a diagram illustrating
this:

ME3241-week01.docx

3241

Microprocessor and Application

11

1.3 Microcontroller
Microcontroller (C or MCU) is an integration of all of the computer components (i.e., one or
more microporcessors (Ps), memory and I/O devices) on one chip. it is typically intended as a
single chip solutions for systems requiring low to moderate processing power
Examples of early microprocessors include the following:
Intel 4044 (1971): first chip to contain all components of a CPU
Born of microprocessor
Intel 8008 (1972), Intel 8080 (1974)
8-bit microprocessors built by Intel
Other 8-bit microprocessors built in Mid 70s
Motorola: M6800, Signetics: 6502, Zilog: Z80, Texas Instruments: T9900,
National Semiconductor: IMP-8 etc.
Example of microprocessors developed since late 70s and beyond:
in late 70s
Intel 8086
Microcomputer XT Intel 8088
Motorola 68000
Zilog Z8000 etc
Later - CISC
Intel 80X86
Microcomputer AT Intel 80286
Motorola 680X0
Motorola 68020

ME3241-week01.docx

3241

Microprocessor and Application

12

Later - RISC
Power PC
SUN Microsystems

Examples of micro-controllers:
Intel: 8031, 8051, 80188, 8096 etc
Motorola: MC6805, MC68HC11, MC68HC12 (16-bit) etc
Microchip: PIC16, PIC18

Classification of Microcontrollers:
Microcontrollers are typically classified according to the processing capacity of the processors
equivalently the width of the data bus. It can be catergorized as 4-bit microcontroller, 8-bit
microcontroller, 16-, 32-, 64-bit microcontroller. The larger the data bus width, the more powerful
the microcontroller (and more expensive). Hence, low end microcontrollers are used for cheap
applications (eg toys, intelligent consumer product etc), while high end ones are used for complex
machines, industrial controllers etc.

1.4 PIC18 Microcontroller


We now give an introduction of PIC18 microcontroller as well as its properties. Below is a list of
features of PIC18

8-bit CPU
16-bit instruction width, 70+ instructions
2 MB program memory space
256 bytes to 1KB of data EEPROM
Up to 3968 bytes of on-chip SRAM
4 KB to 128KB flash program memory
Operates at up to 40 MHz crystal oscillator
Instruction pipelining

Sophisticated timer functions that include: input capture, output compare,


PWM, real-time interrupt, and watchdog timer
Serial communication interfaces: SCI, SPI, I2C, and CAN
10-bit A/D converter

A simpliefied block diagram see below. You should be able to tell from the diagram the data bus
width, instruction width, address bus width, and the maximum amount of memory supported.

ME3241-week01.docx

3241

Microprocessor and Application

13

1.4.1 Memory organization of PIC 18:


A very important topic to understand is the memory organization of PIC18. In general, memory
consistes a sequence of directly addressable information units called memory locations. A
memory location has two components an address and its contents, it can be used to store data,
instruction, and the status of peripheral devices.
In PIC 18, the data memory (aka data registers for PIC 18) and program memory are separated
(this is called Harvard Architecture), see below figure. The adavantage of separating the data
memory and program memory is that it is possible to access data and instruction simultaneously.
Data memory includes general purpose registers and special function registers.

ME3241-week01.docx

3241

Microprocessor and Application

14

A PIC 18 MCU can have up to 4096 bytes of data memory (recall 12-bit register address bus).
Data memory is implemented in SRAM and consists both general purpose registers (used to hold
dynamic data) and spcial-function registers (used to control the operation of peripheral functions).
A special property of PIC 18 data memory is that it is divided into banks. This property has
very profound impact on programming with PIC 18. Data memory is divided into 16 banks, each
bank has 256 bytes. At any time, only one bank is active. Which bank is active is specified by the
BSR register. Thus, to access data from another bank, one need to do bank switching this is an
overhead and can be error-prone. To reduce bank switching, PIC implemented the access bank.
Access bank is a special region of the data memory it consists of the lowest 96 bytes and highest
160 bytes of the data memory space. One can access memory locations within the access bank
regardless of which bank is active.

The group of registers from The group of registers from 0xFD8 to 0xFFF are dedicated to the
general control of MCU operation in CPU. Two examples are WREG and STATUS register. The
WREG register is involved in the execution of many instructions. The STATUS register holds the
status flags for the instruction execution
In terms of the program memory the program memory address bus and the program counter
(PC) are 21 bit long, hence the maximum amount of program memory supported is 2MB. PIC 18
also has a 31-entry stack to hold the return address of subrounting call. When power on, PIC18
starts to executre instruction from address 0. The location 0x08 is reserved for high-priority
interrupt service routine, 0x18 is reserved for low-priority interrupt service routine. Part of the
program memory is inside the chip (depends on the models, currently up to 128kb) and part of the
program memory is outside the side.

ME3241-week01.docx

3241

Microprocessor and Application

15

1.4.2 Instruction Format


There are 5 different types of instructions for PIC 18. They have different formats. Most
instruction are 16 bit long, some of them are 32bit (i.e., use two locations of the program
memory).
1. Byte oriented instruction : eg. movf 0x20, W, A

2. Byte-to-byte operations: eg. movff 0x100, 0x200. Here, no bank selection is needed since
12 bits are used to address a memory location

3. Bit-oriented file register operations: eg. bcf 0x20, 2, A

4. Literal operations (literal is a number to be operated upon) e.g., movb 3

ME3241-week01.docx

3241

Microprocessor and Application

16

5. Control operations instructions that change the program exection sequence and make
subroutine calls they all have different formats

Addressing mode:
There are five addressing modes (ways to identify locations of the operands) in PIC 18:
1. Register direct: Use an 8-bit value to specify a data register. Eg. movf 0x20, W, A. Here
0x20 is a register that is directly addressed
2. Immediate Mode: A value in the instruction to be used as an operand. Eg., movlb 3. Here
number 3 is a number that is immediately addressed
3. Inherent Mode: an implied operand. Eg, movf 0x20, W, A, here the register WREG is
inherently addressed
4. Indirect Mode: A special function register (FSRx) is used as a pointer to the actual data
register. Eg. movwf INDF0. This command copies the contents of the WREG register to
the data memory whose location is stored in FSR0.
5. Bit direct: deal with individual bit. E.g., BCF PORTB, 3, A. This command Clears bit 3
of the data register PORTB
Because in most instruction, only 8 bit is used to identify a file register, while we have 4096 bytes
of file register (212 bytes), we have to divide into banks- each bank have 256 bytes (28 bytes) .
Refer to page 14 for the information of bank and access bank.

ME3241-week01.docx

3241

Microprocessor and Application

17

1.4.3 Pipelining
The PIC18 divide most of the instruction execution into two stages: instruction fetch and
instruction execution. Hence, up to two instructions are overlapped in their execution - One
instruction is in fetch stage while the second instruction is in execution stage, see below diagram.
Notice that this is made possible since the fetch stage accessess program memory and the
execution stage accesses data memory (i.e., file registers). Since the two memory are separated
with individual buses, pipelineing is possible. Because of pipelining, each instruction appears to
take one instruction cycle to complete. For example, suppose for unpiplined version, one
instruction takes 60ns, and assume latch requires 3ns, then for the pipelined version, each time
cycle = 60/2+3=33 ns.

ME3241-week01.docx

Você também pode gostar