You are on page 1of 42

Introduction to Micro-processors &

Micro-controllers

Micro-processors

Micro-controllers
2

Micro-processors
A microprocessor is a computer processor which incorporates the functions of
a computer's Central Processing Unit (CPU) on a single integrated circuit (IC)
or at most a few integrated circuits.

The microprocessor is a multipurpose, clock driven, register based, digital-


integrated circuit which accepts binary data as input, processes it according
to instructions stored in its memory, and provides results as output.

Microprocessors contain both combinational logic and sequential digital logic.


Microprocessors operate on numbers and symbols represented in the binary
numeral system.

The integration of a whole CPU onto a single chip or on a few chips greatly
reduced the cost of processing power, increasing efficiency.
3

Micro-controllers
A microcontroller (or MCU for MicroController Unit) is a small computer on a
single integrated circuit. In modern terminology, it is a System on a Chip (SoC).

A microcontroller contains one or more CPUs (processor cores) along with


memory and programmable input/output (I/O) peripherals. Program memory in
the form of Ferroelectric RAM, NOR flash or OTP ROM is also often included
on chip, as well as a small amount of RAM.

Microcontrollers are designed for embedded applications, in contrast to


the microprocessors used in personal computers or other general purpose
applications consisting of various discrete chips.

Microcontrollers are used in automatically controlled products and devices, such


as automobile engine control systems, implantable medical devices, remote
controls, office machines, appliances, power tools, toys and other embedded
systems. By reducing the size and cost compared to a design that uses a
separate microprocessor, memory, and input/output devices, microcontrollers
make it economical to digitally control even more devices and processes.
4
Computer – Micro-processor Based System
 A computer is a general-purpose electronic device, which can
input, process (according to instructions provided), and output
data.
Programs
(Instructions)

Data Data
input processing output

• A computer is a machine that stores data, interact with devices,


and execute programs (provides computing capabilities to its
users).
A computer is an electronic device that stores, retrieves, and
processes data, and can be programmed with instructions. A
computer is composed of hardware and software, and can exist in
a variety of sizes and configuration, e.g., Mainframe computer as
large as an entire building, Supercomputer, Single Board Computer
(SBC) such as Raspberry Pi, Smartphone, Tablets, PC on a Stick, etc.
5

Major Components of a Computer System


 A computer system consists of two sub-systems: hardware and
software.

 Hardware is the electronic and mechanical parts of a computer


system.
 Software is the data and the computer programs of a computer
system.
6

Hardware vs. Software


• Hardware – Physical Components
(CPU, Mainboard, RAM, HDD, Keyboard, Monitor, etc.)
• Software – Logical Instructions
(OS, User programs, User Data, etc.)
• Firmware – Logical Instructions imprinted on
physical Components
(BIOS, UEFI, etc. installed in Mainboard)

[Basic Input Output System (BIOS) or Universal Extensible Firmware


Interface (UEFI) provides the start-up (‘booting’) instructions which the
CPU executes immediately after the computer is powered on.]
Without instructions, the CPU cannot even start the computer!!!
7

Computer Hardware
Main Hardware Components of a Processing Unit:

o CPU – Central Processing Unit (Processor)


o Main Memory (RAM – Random Access
Memory )
o MainBoard (Motherboard)
o Power Supply Unit (PSU)
o Secondary Memory /Auxiliary Storage
[Hard Disk (Mechanical/SSD), Flash Disk (eMMC,
SD), Optical Disk (DVD) and/or other Storage Devices]
8

Primary Memory
RAM Modules
9

Mainboard / Motherboard

Switching Mode Power Supply


(SMPS)
10

Processing Unit of a Modern Desktop


Computer System
11
Hardware vs. Software
CPU is the ‘brain’ plus ‘heart’ of the computer system. It renders the whole
computing system live and useful. It does the fundamental computing within the
system. It directly or indirectly controls all the other components. A single-core of a
CPU consists of 3 units:
1. The Arithmetic and Logic Unit (ALU).
2. The Control Unit (CU).
3. Registers (Memory).
When a computer is switched on, the CPU continuously goes through a process
called fetch-decode-execute cycle:
 The Control Unit fetches the current instruction from memory, decodes it and
instructs the ALU (Arithmetic Logic Unit) to execute the instruction.
 The execution of an instruction may generate further data fetches from memory
 The result of executing an instruction is stored in either a register (CPU’s own
memory) or RAM
A multi-core CPU consists of a multiple of these 3-unit-core in a single chip so that
multiple fetch-decode-execute (multi-threading) can take place making computation
faster and efficient.
12
Hardware vs. Software
Thus CPU continuously transfers data to and from the RAM.
Instructions/Data transfer to and from the CPU are done in units called
word (16 bit).

If a CPU can handle a maximum word-size of 32 bits (Dword-double


word), the CPU is called 32-bit CPU.

If a CPU can handle a maximum word-size of 64 bits (Qword-quad


word), the CPU is called 64-bit CPU.

In addition to the registers, a CPU also has cache memories which are
used to store the instructions that are used by the CPU repeatedly or the
instructions in the pipeline (next executable instructions). Usually the
higher the amount of the cache memory, the better the CPU performs.
But cache memories are very expensive.
13
Hardware vs. Software
There are two types of CPU architecture* in wide use today:

• CISC (Complex Instruction Set Computer) – Intel x86, AMD64,


x86_64, Intel Xeon, Atom, etc. are CISC CPUs. These CPUs
support many instructions (sophisticated ones as well) but are power
hungry. These are used in regular Desktop, Laptop, Netbook
computers for their huge existing user-base, system frameworks and
software libraries.

• RISC (Reduced Instruction Set Computer) – ARM (v5, v6, v7) CPUs are
RISC ones. They support fewer instructions (often simpler ones) and are
power saver. So they are used in smart phones, tablet computers, etc.

[*‘CPU architecture’ means physical and logical design-base, i.e.,


number and layout of physical transistor circuits and logical
instruction sets implemented in the CPU.]
Hardware vs. Software 14

• Mainboard is a sophisticated PCB (Printed Circuit Board). It


mainly provides the required circuitry to connect different devices
with the CPU, for example, RAM to the CPU. It contains electrical
wires plus some special-purpose IC chips (chipsets) to facilitate
the connectivity of different devices with the CPU. Mainboards
also contain the startup instructions (BIOS ROM chip).

[The CPU is connected to RAM and I/O devices by the ‘bus’.


When more than two devices can communicate (as a network) using the
same set of connected wires (without the need for dedicated one-to-one
connection between all devices) then this connectivity is termed as ‘bus
topology’. Bus topology is implemented by a set of wires plus dedicated
ICs which follow some communication protocols (a set of agreed-
upon rules). For example, Universal Serial Bus (USB) is used to connect
keyboard/mouse, pen drives, etc. to the CPU, SATA bus is used to connect
hard disk drives, DVD drives to the CPU, etc. Other buses are SCSI, RS-
232, PCI-E, Firewire, Thunderbolt, etc. Some buses used in MCUs are SPI,
I2C, JTAG, etc.]
15

Basic Computer System


Main Hardware Components
+

Main Software Components:


OS - Operating System
[User Software Programs / Packages]
+
One Input device + One Output device
[Keyboard/Mouse + Monitor/Printer]
16

Computing Platform (Environment)


 The computing platform or environment consists of any existing
suitable combinations the main hardware component, i.e., CPU
plus the main software component, i.e., OS (Operating System).

Examples are:
Intel/AMD x86 CPU + Windows OS (32 bit)
Intel x86_64/AMD64 CPU + Windows OS (64 bit)
Intel CPU + Linux
Intel CPU + Mac OS X
ARM CPU + Linux
ARM CPU + Android
ARM CPU + iOS
17
Computing Platform (Environment)
 The basic knowledge of a suitable platform is necessary for a
programmer.

Because all that a CPU understands are


patterns of 1’s and 0’s.
i.e., Machine language (or Object Code)
 Any program written in any language (called “Source Code”) must
be compiled into Machine language of a particular CPU type (CISC
/ RISC) for the CPU to understand and execute accordingly. Note
that, Different CPU understand different machine languages (bit
patterns).
 Different OSs provide different ready-to-be-used machine code
(called “API routines/Library”) that are used by the programmer
in their own program. API routines don’t match among OSs.
18
Primary Memory (RAM)
Primary memory is divided into a number of memory
cells (bits) or bytes.
A bit (binary digit) is the smallest storage unit within a computer.
It is a tiny electrical circuit that can be in one of two states:
 A voltage high represented by the symbol 1
 A voltage low represented by the symbol 0

 Any system of symbols can be represented by bit or byte patterns.


A byte is a chunk of 8 bits. OSs keep track of the RAM on byte
count.
 Each RAM byte must have a unique unsigned integer address,
i.e., no two RAM bytes can have the same address. Byte
addresses are automatically assigned by the OS.
19

16-byte RAM – Logical State


byte-1 byte-2 byte-3 byte-4
Address 0000 0001 0010 0011
Value 00101101 00101101 00101101 00101101

byte-5 byte-6 byte-7 byte-8


Address 0100 0101 0110 0111
Value 00101101 00101101 00101101 00101101

byte-9 byte-10 byte-11 byte-12


Address 1000 1001 1010 1011
Value 00101101 00101101 00101101 00101101

byte-13 byte-14 byte-15 byte-16


Address 1100 1101 1110 1111
Value 00101101 00101101 00101101 00101101
20
Primary Memory
 A 4-bit CPU/OS can only keep track of 24 =16 byte of RAM.
 A 16-bit CPU/OS can only keep track of 216 =65,536 byte (64 KB) of RAM.
 A 32-bit CPU/OS can only keep track of 232 =4,294,967,296 ≈ 4 billion (giga)
addresses of RAM bytes, i.e., 4 GB of RAM
 Also storages such as HDDs are divided into 512-byte sectors with unique
addresses. Since only 4 billion addresses are available, A 32-bit CPU/OS can
only address 4 × 512 =2 partition of HDD.

This 4 GB RAM limit are avoided by 64-bit CPUs and 64-bit OSs.
 A 64-bit CPU/OS can keep track of 264 =18,446,744,073,709,551,616 byte (18
EB, i.e., 18 Giga GB) of RAM and 9 ZB (9 Giga TB) partition of HDD.

 In order to avail the 64-bit computing advantages, one must have both 64-bit
CPU and 64-bit OS.
[32-bit CPUs cannot run 64-bit OSs and 32-bit OSs cannot run 64-bit
softwares even if the CPU is 64-bit.]
21

Address Primary Memory


Value UNIT SYMBOL POWER Number of
OF 2 bytes
Byte 0 1
2

Kilobyte KB 10 1,024
2

Megabyte MB 20 1,048,576
2

Gigabyte GB 30 1,073,741,824
2

Terabyte TB 40 1,099,511,627,776
2
22
Primary Memory
 Each bit of information (programming instructions/data) for
processing by the CPU is fetched from the RAM or stored back to
the RAM after/or during processing. Not only that, every devices
communicates to the CPU via its reserved area inside RAM
(allocated by the OS).

 Since RAM is volatile, (i.e., it loses all the instructions/data once


the power is off), secondary persistent storage devices such as hard
disk, usb flash drives, etc. are used to store the programming
instructions/data permanently.

 However, for any processing to be done by the CPU, all the


programming instructions/data must be loaded into the RAM
byte(s).
23

Computer Software

Hardware Abstraction
Layer (HAL)
Types of software
24
Hardware Abstraction Layer (HAL)
 The core component of an OS is its ‘kernel’. Kernel consists of
hardware device drivers which control the hardware at their lowest level.
 OSs also provide a set of API libraries/routines/framework to the user at a
higher level to use those hardware in an efficient way, thus increasing the
productivity of the programmer.

 Through kernel and APIs, OSs implement Hardware Abstraction Layer


(HAL) to facilitate the usage of computer by the user/programmer. HAL
removes the hardships to control the hardware at their lowest levels. HAL
also prevents direct access to the hardware by the user/programmer.
 With the evolution of the OSs, the HAL is growing thicker* and creating
more restrictions* for the user to directly access the hardware but
providing more and more API libraries/routines/framework to increase
productivity.
[ *Android ‘rooting’ or iOS ‘jailbreaking’ refers to the circumvention (like creating a ‘hole’
through the HAL layer) of these hardware as well as software restrictions. Rooting or
jailbreaking allows the programmer to install 3rd-party software and make direct access to
different hardware components of the smartphones and tablets. ]
25

Software
Application Programs Systems Programs


 Word processors Operating system.
 Game programs Networking system.
Spreadsheets Programming
Data base systems language software.
Graphics programs Web site server.
Web browsers Data backup.
26

Microcontrollers
• Embedded Systems
– Operations managed behind the scenes by a
microcontroller
• Microcontroller (MCU)
– Integrated electronic computing device that
includes three major components on a single
chip
• Microprocessor (MPU)
• Memory
• I/O (Input/Output) ports
27

Microcontrollers
• Support Devices
– Timers
– A/D converter
– Serial I/O
• Common communication lines
– System Bus
28

Block Diagram (CPU vs MCU)

CPU
29

Block Diagram (CPU vs MCU)

Micro-controller
30

Microprocessor-Based Systems
31

Microchip Atmel AVR


Intel 8051 Technology PIC (Microchip)

Texas Texas STMicroelectronics


Instruments Instruments ARM MCU
MSP430 ARM MCU
32

Input/Output (I/O)
• Input Devices
– Switches and Keypads
– Provide binary information to the MPU
• Output devices
– LEDs and LCDs
– Receive binary information from the MPU

32
33
Microprocessor vs. Microcontroller
Microprocessor Microcontroller
• CPU is stand-alone, RAM, • CPU, RAM, ROM, I/O and timer
ROM, I/O, timer are separate are all on a single chip
• designer can decide on the • fixed amount of on-chip ROM,
amount of ROM, RAM and RAM, I/O ports
I/O ports.
• for applications in which cost,
• expensive power and space are critical
• versatility
• single-purpose (control-oriented)
• general-purpose
• Low processing power
• High processing power
• High power consumption • Low power consumption
• Instruction sets focus on • Bit-level operations
processing-intensive • Instruction sets focus on control
operations and bit-level operations
• Typically 32/64 – bit • Typically 8/16 bit
• Typically deep pipeline (5-20 • Typically single-cycle/two-stage
stages)
pipeline
34

Typical Micro-processor based


(General-purpose) architecture
Display
CPU Memory (with
dual-port
video RAM)

system bus

I/O
(serial line, Disk Network
keyboard, Interface
mouse)

all the parts around the


standard interfaces processor are usually required
35

Typical Micro-controller based


(Task-specific) architecture
medium-speed low-speed
interactions interactions
Microcontroller

I/O custom
Interface ROM RAM logic
high-speed
interactions

any of the parts around the


standard interface microcontroller are optional
36

Typical Micro-controller Interfaces

Programmer
37
Arduino – An Introduction

Computer language evolution


38
Arduino – An Introduction

Computer language evolution


39
Arduino – An Introduction

Computer language evolution


40
Arduino – An Introduction

Computer language evolution


41

Watchdog Timer
In many cases, embedded devices operate in total isolation
and are not accessible to an operator.
Manually resetting a device in this scenario when its software
“hangs” is not possible.

A watchdog timer is a hardware timing device that triggers a


system reset, or similar operation, after a designated amount of
time has elapsed.
42

Watchdog Timer
To avoid a reset, an application must periodically reset the
watchdog timer before this interval elapses. This is also
known as “kicking the dog”.
Many processors and microcontrollers have built-in
watchdog circuitry available to the programmer.

This typically consists of a memory-mapped counter that


triggers a reset, when the counter reaches a predefined value.

Resetting the watchdog timer must be part of the overall


design

You might also like