Download as pdf or txt
Download as pdf or txt
You are on page 1of 62

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.
Computers

Supercomputer
Mainframe Computer

Desktop Computer Desktop Workstation


Computers Mac Mini
All-in-one Computer
Intel NUC

Raspberry PI

Raspberry PI zero

Laptop Computer Stick Computer


Computers
Surface Pro

iPad Pro

Galaxy S9 iPhone XS Max


Mainframe vs Supercomputers
• Mainframe Computers are the professional level commercial computers
that work as a server and are used by the large organizations where data
is processed in large quantity and is (concurrently) accessed by
hundreds and thousands of users at a time through consoles or terminals
(displays and keyboards/keypads).
• Supercomputers are the fastest computer of all that possess the ability to
do billions of calculations per second and can process data 1000 times
faster than the ordinary computers such as common personal computers.
• Mainframe computers are designed to deal with thousands of users
accessing the system at a time. These are used in large business
organizations such as banks, government database stations, military
organizations, health organizations, e-commerce, and e-business, etc.
• Supercomputers are designed to be more quick and efficient in data
processing. These are used in space centers such as NASA, weather
forecasting stations, scientific laboratories, nuclear power stations, etc.
• For example, a modern high-end desktop computer can perform on
average100 Gigaflops whereas a modern supercomputer can perform on
average 100 Petaflops.
9

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.
10

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!!!
11

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]
Modern CPUs

RAM Modules
13

Mainboard / Motherboard

Switching Mode Power Supply


(SMPS)
14

Processing Unit of a Modern Desktop


Computer System
15
Central Processing Unit (CPU)
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: CPU
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
16

Multi-Core CPU
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.
17
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.
18
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 19

• 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.]
20

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]
21

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
➢ARM CPU + Chrome OS
➢Intel/AMD x86 CPU + Chrome OS
➢ARM CPU + Windows on ARM
22
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.
23
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.
24

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
25
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
software even if the CPU is 64-bit.]
26

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
27
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).
28

Computer Software

Hardware Abstraction
Layer (HAL)
Types of software
29
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. ]
30

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.
31
Some Popular Microcontrollers

Microchip Atmel AVR


Intel 8051 Technology PIC (Microchip)

Texas Texas STMicroelectronics


Instruments Instruments ARM MCU
MSP430 ARM MCU
32
Block Diagram of a Computer
(usually follows Neumann Architecture)

CPU
33

Neumann (Princeton) Architecture

Program
and
Data
Memory
(RAM)

CPU
An instruction "Read a data byte from memory and store it in the accumulator"
is executed as follows: -
Cycle 1 - Read Instruction
Cycle 2 - Read Data out of RAM and put into Accumulator
Block Diagram of MCU 34

(usually follows Harvard Architecture)

CPU

Program Data
Memory Memory
Harvard Architecture 35

CPU
The same instruction (as shown under Neumann Architecture) would be executed as follows:
Cycle 1 / - Complete previous instruction & - Read the "Move Data to Accumulator" instruction
Cycle 2 / - Execute "Move Data to Accumulator" instruction & - Read next instruction
Hence each instruction is effectively executed in one instruction cycle. Thus, due to parallelism,
Harvard architecture executes more instructions in a given time compared to Neumann
Architecture.
36
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
37

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)

standard interfaces
All the parts around the
processor are usually required
38

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
39

Microcontroller (MCU)
• Primarily used in Embedded Systems
– Operations managed behind the scenes by
microcontroller(s)
• Microcontroller (MCU)
– Integrated electronic computing device that
includes three major components on a single
chip
• Microprocessor (CPU)
• Memory (RAM)
• I/O (Input/Output) ports
40

Microcontroller
• Besides the three main components, there are
some Support Devices:
– Timers
– A/D converter
– Serial I/O devices
• Common communication lines
– System Bus
– RS232
– JTAG
– I2C
– SPI
41

Microcontroller
• Input Devices
– Switches and Keypads
– Provide binary information to the MPU
– Analog or Digital
• Output devices
– LEDs and LCDs
– Receive binary information from the MPU
– PWM Signal Generators
Microcontrollers are used to create interactive systems through
programming which can take input from switches and sensors
and control physical outputs like lights, cameras, motors,
actuators or robots.
42
Typical Micro-controller Interfaces

Programmer
➢ Each MCU has its own unique PIN assignments which have to be learned from
its ‘datasheet’ supplied by its manufacturer.
➢ Each MCU series has its own hardware ‘programmer’ which needs to be
procured separately.
➢ Each MCU series has its own software programming language (many require
their own assembly language) or ‘IDE’ which needs to be learned.
➢ Each MCU series has its own customized development board to test logics.
43
Arduino
➢ Arduino is an open source
and free, hardware and
software specifications for
the Microcontroller Eco-
system.
➢ Arduino is an Italian
company, which initially
built these specifications
using an Atmel ATmega
Computer language evolution
MCU, coupled with a
language and IDE.
The benefits of Arduino eco-system are:
➢ The PIN assignments are sort of standardized, e.g. all Arduino compatible
MCUs support a digital output of 5 volts to an LED on their pin no. 13.
➢ Hardware programmers and Development boards (test-boards) are also
standardized.
➢ A single IDE with a simple language construct very similar to C is used.
44
Arduino
➢ Moreover, since the hardware and software specifications are open source
and free, many companies are manufacturing hardware programmer and
development boards at different levels of sophistication and they are
modestly priced.
➢ The primary mode of computer connection is via USB, serial or ethernet.
➢ Other manufacturers are also making their MCUs compatible with the
Arduino eco-system.
➢ Another huge benefit ofComputer
Arduinolanguage evolution
eco-system is the wide availability of
many shields, which are electronic circuit boards which can be plugged-
into the Arduino boards to extend its functionality.
➢ With Arduino shields, motors and servos can be controlled without a
separate drive circuits.
➢ Arduino shields are also available to build even cell-phones, mp3 players,
simple robots, etc. using Arduino.
45
Arduino

Computer language evolution

Arduino Shields
➢ Arduinos are facilitating the development of many ‘Internet of Things
(IoT) devices’ which are programmable devices connected to the internet
and capable of sharing information over the internet such as smart energy
meters, smart thermostats, smart refrigerators, smart cars, etc.
46
Arduino – An Introduction

Computer language evolution


ATmega328
External Microcontroller
Power Supply
47
Arduino

Clock Chip

Programmer Chip
ATmega328 MCU
Computer language evolution

USB and DC
Connectors
48
Arduino

Computer language evolution

Power PINs Digital PINs


49
Arduino

Computer language evolution

Analog PINs ˜PWM PINs


50
Arduino

Computer language evolution

Arduino IDE
51
Arduino
Four Steps to develop MCU-based System:

1. Designing the controller circuit with MCU


2. Writing code (sketch file) using Arduino IDE
3. Uploading the compiled sketch file into the MCU
Computer language evolution

4. Assemble the physical circuit and testing and


debugging the code and the circuit.
52
Arduino
Blinking LED System:

1. Designing the controller circuit with MCU

Computer language evolution


53
Arduino
2. Writing code (sketch file) using Arduino IDE
3. Uploading the compiled sketch file into the MCU
// the setup function runs once when you press reset or power the board

void setup() { // initialize digital pin LED_BUILTIN as an output.


pinMode(LED_BUILTIN, OUTPUT);
}
Computer language evolution

void loop() { // the loop function runs over and over again forever
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage
//level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage
//LOW
delay(1000); // wait for a second
}
54
Arduino
4. Assemble the physical circuit and testing and
debugging the code and the circuit.

Computer language evolution


Internet of Things
• IoT is a network of physical objects with embedded
electronics that collect and share data”
Components for IoT
• ESP8266 module

• NodeMCU 1.0

• Arduino UNO wifi Shield ESP8266 module


• OTA WeMos D1
ESP8266 module pinout

• Can be programmed by itself but


usually connected to Arduino
NodeMCU 1.0

• Built-in ESP8266,
”ESPduino”
• Works with Arduino IDE,
not officially though
• 12 V regulator for input
voltage
• Price: 5 – 10 €
• 13 GPIO, only one PWM
and ADC (0-1 V)
• Pins work with 0 – 3.3 V

NodeMCU 1.0 Pinout


Interfacing with Arduino
Raspberry Pi (Complete PC)
• University of Cambridge’s Computer Laboratory
– Decline in skill level
– Designed for education
• A credit card sized PC (Fully working PC*)
• Plugs into a TV or monitor
• Inexpensive ~$35 each
• Capability:
– Programming
– Electronic Projects
– Office
– Play HD Videos
* Fully Working PC when connected with the following peripherals:
– A display (another computer/smartphone’s display can be used with ‘ssh’ connection)
– A keyboard
– A mouse
– An SD card with linux OS and other softwares.
– Power Supply
Raspberry Pi GPIO Pinout
Programming Languages
• Any language which will compile for ARMv6 can be
used for programming GPIO pins on raspberry PI such
as C, C++, Java, Scratch, Ruby, etc.
• All softwares are open-source, all almost
tools/software are free
Resources link: www.raspberrypi.org

Other Capabilities
• Anything starting from programming, office suite,
web server, games, streaming media server, IoT
devices and even supercomputers are made using
Raspberry Pi.
Some Raspberry Pi Projects

Digital Clock
PiBot!

Supercomputer

You might also like