CPEG300 Embedded System Design - web.mit.eduweb.mit.edu/~wbo/www/cpeg300/L2_mcu_architecture.pdf ·...

25
Hamad Bin Khalifa University, Spring 2018 CPEG300 Embedded System Design Lecture 2 Microcomputer Structure

Transcript of CPEG300 Embedded System Design - web.mit.eduweb.mit.edu/~wbo/www/cpeg300/L2_mcu_architecture.pdf ·...

Page 1: CPEG300 Embedded System Design - web.mit.eduweb.mit.edu/~wbo/www/cpeg300/L2_mcu_architecture.pdf · Clock: system beat; ... (AT89S51, AT89S52, AT89C55, AT90S1200, etc.) ... Analog

Hamad Bin Khalifa University, Spring 2018

CPEG300 Embedded System Design

Lecture 2 – Microcomputer Structure

Page 2: CPEG300 Embedded System Design - web.mit.eduweb.mit.edu/~wbo/www/cpeg300/L2_mcu_architecture.pdf · Clock: system beat; ... (AT89S51, AT89S52, AT89C55, AT90S1200, etc.) ... Analog

B. Wang

Review

2 Hamad Bin Khalifa University, 2018

■ What is embedded system?

■ The characteristics of embedded system?

■ The future development trend of embedded system design?

Page 3: CPEG300 Embedded System Design - web.mit.eduweb.mit.edu/~wbo/www/cpeg300/L2_mcu_architecture.pdf · Clock: system beat; ... (AT89S51, AT89S52, AT89C55, AT90S1200, etc.) ... Analog

B. Wang

More Terminologies

■ Integrated Circuit (IC): A miniaturized electronic circuit that consists

of semiconductor devices and passive components contained in a

package

■ Central Processing Unit (CPU): This refers to the core of the MCU

that executes code

■ Microcontroller Unit (MCU): This is the standard acronym used for

microcontrollers, and refers to the full IC that contains the CPU and

peripherals.

■ “n-bit” – the “n” refers to the data bus width of the CPU, and is the

maximum width of data it can handle at a time

● Examples: 8-bit MCU, 32-bit MCU

● kB: 210 = 1024 byte; MB: 220 = 1,048,576 byte

3 Hamad Bin Khalifa University, 2018

Page 4: CPEG300 Embedded System Design - web.mit.eduweb.mit.edu/~wbo/www/cpeg300/L2_mcu_architecture.pdf · Clock: system beat; ... (AT89S51, AT89S52, AT89C55, AT90S1200, etc.) ... Analog

B. Wang

Computer Architecture

4 Hamad Bin Khalifa University, 2018

■ Architecture refers to the internal hardware organization of a microcomputer

■ Von Neumann architecture

or Princeton architecture

● The instructions and data are stored in the same memory space

● Intel x86, TI-MSP430, ARM7, MIPS, etc.

■ Harvard architecture

● The instructions (program code) and data are stored in separate memory spaces

● Microchip - PIC, Ateml - AVR series, Intel MSC-51, etc.

Page 5: CPEG300 Embedded System Design - web.mit.eduweb.mit.edu/~wbo/www/cpeg300/L2_mcu_architecture.pdf · Clock: system beat; ... (AT89S51, AT89S52, AT89C55, AT90S1200, etc.) ... Analog

B. Wang

System on Board vs. System on Chip

5 Hamad Bin Khalifa University, 2018

■ Motherboard (system on board); Everything in a single chip (system

on chip, SoC)

● Difference in processing capability, feature size, power, cost,

development cycle, etc.

A microATX motherboard PIC16C505 MCU die photo

Page 6: CPEG300 Embedded System Design - web.mit.eduweb.mit.edu/~wbo/www/cpeg300/L2_mcu_architecture.pdf · Clock: system beat; ... (AT89S51, AT89S52, AT89C55, AT90S1200, etc.) ... Analog

B. Wang

Generic Architecture of Microprocessor

■ MCU topology (Harvard architecture)

■ Clock: system beat; RoM: program code and special data like

lookup table; RAM: user data; Internal resources: timer, A/D, etc.;

External source: Keyboard, display, spkeaer, etc.

6 Hamad Bin Khalifa University, 2018

Clock CPU

RoM

RAM

Internal

Resour

ces

External

Peripherals

DATA

ADDRESS

CONTROL

Page 7: CPEG300 Embedded System Design - web.mit.eduweb.mit.edu/~wbo/www/cpeg300/L2_mcu_architecture.pdf · Clock: system beat; ... (AT89S51, AT89S52, AT89C55, AT90S1200, etc.) ... Analog

B. Wang

RAM & RoM

■ RAM is read/write memory. It is volatile (the contents are lost when

power is removed). User data are loaded into RAM for execution.

■ ROM is read-only memory. It is nonvolatile. ROM is used to hold the

short, frequently used software routines that perform input/output

operations.

7 Hamad Bin Khalifa University, 2018

RAM RoM

Page 8: CPEG300 Embedded System Design - web.mit.eduweb.mit.edu/~wbo/www/cpeg300/L2_mcu_architecture.pdf · Clock: system beat; ... (AT89S51, AT89S52, AT89C55, AT90S1200, etc.) ... Analog

B. Wang

The Buses: Address, Data, Control

■ Address Bus

● 16-bit address can access 216 = 65,536 locations. 216 =26*210= 64K locations. The address bus is unidirectional.

■ Data Bus

● Evidently computers spend up to 2/3 of their time simply moving data. Since the majority of move operations are between a CPU register and external RAM or ROM, the number of lines (width) of the data bus is important for overall performance.

● 16-bit computer refers to a computer with 16 lines on its data bus.

● The overall computing power increasing as the width of the data bus increases. The limitation by-width is bottleneck!!

● The data bus is bidirectional. (Read or Write)

■ Control Bus

● Control signals are timing signals supplied by CPU to synchronize the movement of the information on the address bus and data bus. Such as CLOCK, READ and WRITE.

8 Hamad Bin Khalifa University, 2018

Page 9: CPEG300 Embedded System Design - web.mit.eduweb.mit.edu/~wbo/www/cpeg300/L2_mcu_architecture.pdf · Clock: system beat; ... (AT89S51, AT89S52, AT89C55, AT90S1200, etc.) ... Analog

B. Wang

I/O Devices

■ Mass storage devices

● Online storage

o is available to CPU without human intervention upon the

request of a program. (such as magnetic disk)

● Archival storage

o Holds data that are rarely needed and require manual

loading onto the system. (such as magnetic tapes or disks,

optical discs: CD-ROM)

■ Human interface devices

● Keyboard, Mouse, Printer, CRT

■ Control/monitor devices

● Temperature control of a building, home security, elevator

control, home appliance control.

● The hardware and software interfacing of these devices to

microcontroller is one of the main themes in this course.

9 Hamad Bin Khalifa University, 2018

Page 10: CPEG300 Embedded System Design - web.mit.eduweb.mit.edu/~wbo/www/cpeg300/L2_mcu_architecture.pdf · Clock: system beat; ... (AT89S51, AT89S52, AT89C55, AT90S1200, etc.) ... Analog

B. Wang

MCU Series

10 Hamad Bin Khalifa University, 2018

■ Different MCU models from different providers;

■ Different on-chip resources, bus-width (4b, 8b, 16b, 32b), etc.;

■ Most popular: MCS-51 series from Intel; AVR from Atmel and STM32 from STM;

Company MCU Model

Intel MCS-48, MCS-51

STC STC89Cxx (e.g. STC89C51RC); STC12C5A602S, etc.

Atmel AT89 and AT90 series (AT89S51, AT89S52, AT89C55, AT90S1200, etc.)

Philips NXP Semiconductor (5VLPC900, LPC9001, LPC900,LPC700, etc.)

SST SST89 series

Microchip PIC16Cxx, PIC17Cxx, PIC18Cxx (PIC16C70, PIC18C858)

TI MSP430, TMS320

STM STM32 series

ARM ARM series (ARM7, ARM9, ARM10, ARM11)

Major MCU Providers

Page 11: CPEG300 Embedded System Design - web.mit.eduweb.mit.edu/~wbo/www/cpeg300/L2_mcu_architecture.pdf · Clock: system beat; ... (AT89S51, AT89S52, AT89C55, AT90S1200, etc.) ... Analog

B. Wang

The 8051 Microcontroller - A Brief History

■ In 1980, Intel introduced the 8051, relevant today after more than

two decades;

■ First device in the MCS-51® family of 8-bit microcontrollers;

■ In addition to Intel there are other second source suppliers of the

ICs, who make microcontrollers that are compatible with the 8051

architecture (use Intel IP);

■ In recent years some companies have incorporated many different

and additional features into 8051;

■ 8051 – NMOS technology; 80C51 – CMOS technology;

■ Many MCU with 8051 core:

● STC – STC89C51;

● Philips – P89LPC900;

● Atmel – ATtiny11, AT Mega8/16/32;

● MicroChip – PIC18Cxxx;

● Zilog – Z8;

11 Hamad Bin Khalifa University, 2018

Page 12: CPEG300 Embedded System Design - web.mit.eduweb.mit.edu/~wbo/www/cpeg300/L2_mcu_architecture.pdf · Clock: system beat; ... (AT89S51, AT89S52, AT89C55, AT90S1200, etc.) ... Analog

B. Wang

Is 8-bit Still Relevant?

■ “n-bit” – the “n” refers to the data bus width of the CPU, and is the

maximum width of data it can handle at a time;

■ PCs with 64-bit microprocessors are becoming common;

■ Over 55% of all processors sold per year are 8-bit processors, which

comes to over 3 billion of them per year!*

■ 8-bit microcontrollers are sufficient and cost-effective for many

embedded applications;

■ More and more advanced features and peripherals are added to 8-

bit processors by various vendors;

■ 8-bit MCUs are well-suited for low-power applications that use

batteries;

*Note: Statistics from Embedded.com Article ID# 9900861, Dec 2002

12 Hamad Bin Khalifa University, 2018

Page 13: CPEG300 Embedded System Design - web.mit.eduweb.mit.edu/~wbo/www/cpeg300/L2_mcu_architecture.pdf · Clock: system beat; ... (AT89S51, AT89S52, AT89C55, AT90S1200, etc.) ... Analog

B. Wang

Example System: RC Car

■ Use simple 8-b MCU for control

13 Hamad Bin Khalifa University, 2018

Page 14: CPEG300 Embedded System Design - web.mit.eduweb.mit.edu/~wbo/www/cpeg300/L2_mcu_architecture.pdf · Clock: system beat; ... (AT89S51, AT89S52, AT89C55, AT90S1200, etc.) ... Analog

B. Wang

Block Diagram of the Original 8051

■ Overall system view

■ “8052” is the superset of 8051; 8052 has 256B RAM, 3 counters;

■ “8051” is typically used in place of “8052”, and also refers to 8051;

14 Hamad Bin Khalifa University, 2018

- 8-bit CPU

- 4K Internal RoM

- 128B RAM

- 16-bit counter x2

- Interrupts x5

- 8-bit I/O ports x4

- UART x1

- 64K memory extension (ROM, RAM)

Page 15: CPEG300 Embedded System Design - web.mit.eduweb.mit.edu/~wbo/www/cpeg300/L2_mcu_architecture.pdf · Clock: system beat; ... (AT89S51, AT89S52, AT89C55, AT90S1200, etc.) ... Analog

B. Wang

8051 MCU

15 Hamad Bin Khalifa University, 2018

■ CPU, RoM, RAM, I/O, UART, Counter, Interrupt, SFR;

40 pins

Page 16: CPEG300 Embedded System Design - web.mit.eduweb.mit.edu/~wbo/www/cpeg300/L2_mcu_architecture.pdf · Clock: system beat; ... (AT89S51, AT89S52, AT89C55, AT90S1200, etc.) ... Analog

B. Wang

Pin Assignment #1

■ Port1 (Pin1 to Pin8): Port1 includes pin1.0 to pin1.7 and these pins can be configured as input or output pins.

■ Pin 9 (RST): Reset pin is used to Reset 8051 Microcontroller by giving a positive pulse to this Pin.

■ Port3 (Pin 10 to 17): The Port3 Pins are similar to port1 pins and can be used as universal Input or output pins. These pins dual-function Pins and the function of each Pin is given as:

● Pin 10 (RXD): RXD pin is a Serial Asynchronous Communication Input or Serial synchronous Communication Output.

● Pin 11 (TXD): Serial Asynchronous Communication Output or Serial Synchronous Communication clock Output.

● Pin 12 (INT0): Input of Interrupt 0

● Pin 13 (INT1): Input of Interrupt 1

● Pin 14 (T0): Input of Counter 0 clock

● Pin 15 (T1): Input of Counter 1 clock

● Pin 16 (WR): Writing signal to write content on external RAM.

● Pin 17 (RD): Reading signal to read contents of external RAM.

■ Pin 18 and 19 (XTAL2, XTAL1): X2 and X1 pins are input output pins for the oscillator. These pins are used to connect an internal oscillator to the microcontroller.

16 Hamad Bin Khalifa University, 2018

Page 17: CPEG300 Embedded System Design - web.mit.eduweb.mit.edu/~wbo/www/cpeg300/L2_mcu_architecture.pdf · Clock: system beat; ... (AT89S51, AT89S52, AT89C55, AT90S1200, etc.) ... Analog

B. Wang

Pin Assignment #2

■ Pin 20 (GND): Pin 20 is a ground pin.

■ Port2 (Pin 21 to Pin28): Port2 includes pin21 to pin28 which can be configured as Input Output Pins. But, this is only possible when we don’t use any external memory. If we use external memory, then these pins will work as high order address bus (A8 to A15).

■ Pin 29 (PSEN/): This pin is used to enable external program memory. If we use an external ROM for storing the program, then logic 0 appears on it, which indicates Micro controller to read data from the memory.

■ Pin 30 (ALE): Address Latch Enable pin is an active high-output signal. If we use multiple memory chips, then this pin is used to distinguish between them. This Pin also gives program pulse input during programming of EPROM.

■ Pin 31 (EA/): If we have to use multiple memories then the application of logic 1 to this pin instructs the Microcontroller to read data from both memories: first internal and then external.

■ Port 0 (Pin 32 to 39): Similar to the port 2 and 3 pins, these pins can be used as input output pins when we don’t use any external memory. When ALE or Pin 30 is at 1, then this port is used as data bus: when the ALE pin is at 0, then this port is used as a lower order address bus (A0 to A7)

■ Pin40 (VCC): This VCC pin is used for power supply.

17 Hamad Bin Khalifa University, 2018

Page 18: CPEG300 Embedded System Design - web.mit.eduweb.mit.edu/~wbo/www/cpeg300/L2_mcu_architecture.pdf · Clock: system beat; ... (AT89S51, AT89S52, AT89C55, AT90S1200, etc.) ... Analog

B. Wang

Special Pin #1

■ Power supply

● GND: 0 V, ground;

● VCC: +5 V power supply, battery or USB cable;

■ MCU clock

● XTAL1, XTAL2: provide external clock

o Way 1: using a quartz crystal oscillator

o Way 2: using a TTL oscillator

● Typical resonant frequency:

o 32.768kHz = 215

o 3.58MHz

o 4MHZ, 8MHz, 10MHz,

11.0592MHz, 12MHz, etc.

● 8051 usually use 12MHz;

● One 8051 machine cycle = 12 crystal pulses

(clock cycle).

18 Hamad Bin Khalifa University, 2018

NC

EXTERNAL

OSCILLATOR

SIGNAL

XTAL2

XTAL1

GND

TTL

Page 19: CPEG300 Embedded System Design - web.mit.eduweb.mit.edu/~wbo/www/cpeg300/L2_mcu_architecture.pdf · Clock: system beat; ... (AT89S51, AT89S52, AT89C55, AT90S1200, etc.) ... Analog

B. Wang

Special Pin #2

■ RST (pin 9): reset

● It is an input pin and is active high (normally low).

o The high pulse must be high at least 2 machine cycles.

● It is a power-on reset.

o Upon applying a high pulse to RST, the microcontroller will

reset and all values in registers will be lost.

o Reset to default values internal registers

● Way 1: Power-on reset circuit

● Way 2: Power-on reset with debounce

19 Hamad Bin Khalifa University, 2018

Analog debouncing Digital debouncing

Page 20: CPEG300 Embedded System Design - web.mit.eduweb.mit.edu/~wbo/www/cpeg300/L2_mcu_architecture.pdf · Clock: system beat; ... (AT89S51, AT89S52, AT89C55, AT90S1200, etc.) ... Analog

B. Wang

Special Pin #3

■ I/O port pins

● Port 0 (pins 32-39) : P0(P0.0~P0.7)

● Port 1 (pins 1-8) : P1(P1.0~P1.7)

● Port 2 (pins 21-28) : P2(P2.0~P2.7)

● Port 3 (pins 10-17) : P3(P3.0~P3.7)

o Each port has 8 pins.

o Named P0.X (X=0,1,...,7), P1.X, P2.X, P3.X

o Ex: P0.0 is the bit 0 (LSB) of P0

o Ex: P0.7 is the bit 7(MSB) of P0

o These 8 bits form a byte.

● Each port can be used as input or output (bi-directional).

20 Hamad Bin Khalifa University, 2018

Page 21: CPEG300 Embedded System Design - web.mit.eduweb.mit.edu/~wbo/www/cpeg300/L2_mcu_architecture.pdf · Clock: system beat; ... (AT89S51, AT89S52, AT89C55, AT90S1200, etc.) ... Analog

B. Wang

System Clock

■ Two types of clock

● 1.2 ~ 12MHz clock

● C1, C2: 30 +/-10pF

21 Hamad Bin Khalifa University, 2018

X1

X2

C2

C1

X

8051

8051 X1

X2

Vss

TTL

Vcc

NC

Crystal oscillator External TTL clock

Page 22: CPEG300 Embedded System Design - web.mit.eduweb.mit.edu/~wbo/www/cpeg300/L2_mcu_architecture.pdf · Clock: system beat; ... (AT89S51, AT89S52, AT89C55, AT90S1200, etc.) ... Analog

B. Wang

Power-On Reset

■ > 2 machine cycle pulse on RST pin;

■ Power-On RESET with Debounce;

22 Hamad Bin Khalifa University, 2018

Vcc

10uF

8.2 K

30pF

9

31

EA/VPP

X1

X2 RST

Vcc

10uF

8.2 K

30pF

9

31

EA/VPP

X1

X2 RST

W/o debounce W/i debounce

Page 23: CPEG300 Embedded System Design - web.mit.eduweb.mit.edu/~wbo/www/cpeg300/L2_mcu_architecture.pdf · Clock: system beat; ... (AT89S51, AT89S52, AT89C55, AT90S1200, etc.) ... Analog

B. Wang

Machine Cycle

■ Clock period:

● Basic timing unit of MCU

● If the XTAL frequency is fosc, the clock period Tosc = 1/fosc;

o e.g fosc = 12 MHz, Tosc = 83.3 ns

■ Machine cycle:

● The time required by microprocessor to complete the operation

of accessing memory or I/O devices;

● For MCS-51, one machine cycle = 12 clock cycle;

● One machine cycle has 6 state cycles, and each state has 2

beats, each beat is 1 clock cycle;

23 Hamad Bin Khalifa University, 2018

S1 S2 S3 S4 S5 S6 S1 S2

P1 P2

P1

P2 P1

P2

P1 P2

P1

P2 P1

P2

P1 P2 P1

P2 fosc

1 state cycle 1 Machine cycle

T=12*(1/fosc)

X2

Page 24: CPEG300 Embedded System Design - web.mit.eduweb.mit.edu/~wbo/www/cpeg300/L2_mcu_architecture.pdf · Clock: system beat; ... (AT89S51, AT89S52, AT89C55, AT90S1200, etc.) ... Analog

B. Wang

Instruction Cycle

■ Executing an instruction can be divided into the instruction fetch

stage and the instruction execution stage.

● Fetch instruction phase: fetches the opcode and operand from

the program memory for the instruction to be executed.

● Instruction execution phase: instruction decoding generates a

series of control signals to complete the execution of the

instruction.

● The ALE signal is address latch signal, appears twice per

machine cycle.

24 Hamad Bin Khalifa University, 2018

Page 25: CPEG300 Embedded System Design - web.mit.eduweb.mit.edu/~wbo/www/cpeg300/L2_mcu_architecture.pdf · Clock: system beat; ... (AT89S51, AT89S52, AT89C55, AT90S1200, etc.) ... Analog

B. Wang

MCU Fetch-Execute Cycle

■ Fetch operation

● retrieves an instruction

from the location in code

memory pointed to by the

program counter (PC)

■ Execute operation

● executes the instruction

that was fetched during

the fetch operation. In

addition to executing the

instruction, the CPU also

adds the appropriate

number to the PC to point

it to the next instruction to

be fetched.

25 Hamad Bin Khalifa University, 2018

MCU operation