You are on page 1of 60

Welcome to the course

ECEG4202-Embedded Systems

1
Course Syllabus

Introduction
Embedded Microcontrollers
Study of 8051 microcontroller
Embedded Programs
Real-Time Operating Systems
Low-power Computing
Reliable System Design

Embedded Systems 2
Chapter One
Introduction

3
Embedded System (1/2)

An Embedded System is a device that includes a computer,


but is not itself a general- purpose computer.
An embedded system:
contains a microprocessor or microcontroller.
hidden or embedded as an integral part of a larger system.
runs software for its functions.
designed to perform a dedicated function.
expected to respond, monitor as well as control external
environment using sensors and actuators.

Embedded Systems 4
Embedded System (2/2)

What they do:


Sense environment (input signals)
Process input information
Respond in real-time (output signals)
Embedded Systems 5
Example: Refrigerator

Actuators Compressor
Display

Human interface

Embedded
System

Sensors Actual Temp


Required Temp

Embedded Systems 6
Example: Car

Embedded Systems 7
Embedded System Components

An embedded system has three layers:


It has hardware.
It has Real Time Operating system (RTOS) that supervises the
application software and provide mechanism to let the processor run
a process as per scheduling by following a plan to control the
latencies. RTOS defines the way the system works. It sets the rules
during the execution of application program. A small scale
embedded system may not have RTOS.
It has application software.

Embedded Systems 8
Why we study Embedded Systems?
(1/2)

There is a greater awareness now that rather


than a totally hardwired electronic system,
incorporation of a programmable processor
in a circuit makes the design more robust
with the reduction in the design time cycle.
Their compact size, low cost and design
aspects made embedded systems very
popular in the lives of human.

Embedded Systems 9
Why we study Embedded Systems? (2/2)

They are found from kitchen to space craft.


Today they are becoming key elements of every society.
Embedded Systems lead worldwide microprocessor
production.
Embedded: desktop = 100:1

Embedded Systems 10
Application of Embedded System (1/2)

Consumer Electronics: TV, DVD players , Cameras.


Household appliances: microwave oven, washing machine,
refrigerator.
Automotive industry: Ignition System, breaking system ,
engine control.
Home automation & security systems: Air conditioners,
sprinklers, fire alarms.
Telecom: Mobile phones, telephone switches.
Office Automation: Fax Machine Photocopier Printers
Monitors Scanners .

Embedded Systems 11
Application of Embedded System (2/2)

Computer networking systems: Network routers and


switches.
Healthcare: Dialysis Machines, Cardiac Monitors.
Banking : Automatic teller machines
Card Readers: Barcode, smart card readers.

Embedded Systems 12
Role of Embedded Systems (1/2)

Data Collection/Storage/Representation
Embedded system designed for the purpose of data collection
performs acquisition of data from the external world.
Data collection is usually done for storage, analysis, manipulation
and transmission.
Data can be analog or digital.
Example: Digital Camera

Embedded Systems 13
Role of Embedded Systems (2/2)

Data communication
Embedded data communication systems are deployed in
applications from complex satellite communication to simple home
networking systems.
The transmission of data is achieved either by a wire-line medium or
by a wire-less medium.
Example : Network hubs, routers and switches
Data signal processing
Embedded systems with signal processing functionalities are
employed in applications demanding signal processing like speech
coding, audio video codec, transmission applications etc.
Example: Digital hearing aid.

Embedded Systems 14
Embedded Systems Vs General purpose computers
(1/2)

An embedded system is designed to perform a specific task


whereas as per definition the general purpose computer is
meant for general use.
General purpose computers can be used for playing games,
watching movies, creating software, working on documents
etc.

Embedded Systems 15
Embedded Systems Vs General purpose computers
(2/2)
Properties Embedded System General purpose
computer
Hardware Special purpose hardware. Generic hardware.
OS Embedded OS / Real-time OS General purpose OS
Applications Execute specific set of Execute a variety of
applications that are known at applications
design-time.

Program Not programmable by end user Programmable by end user


Power Less More
Consumption
Response Time Usually Critical for some Not critical
applications
Software patch Not common Regularly done

Embedded Systems 16
Characteristics of Embedded Systems (1/3)

Dedicated systems
An embedded system usually performs a specialized operation and
does the same repeatedly.
Reactive systems
Continually reacts to changes in the systems environment (using
User-interface and/or sensors).
Real-time systems
Must finish operations by deadlines.
Hard real time: missing deadline could result in a catastrophe. Eg.
Pacemaker system
Soft real time: missing deadline results in unhappiness. Eg. Washing
machine, Printers

Embedded Systems 17
Characteristics of Embedded Systems (2/3)

Safety-critical
Must not endanger human life and the
environment.
Tightly constrained: All computing systems
have constraints on design metrics, but those
on an embedded system can be especially
tight.
Power: critical in battery powered devices.
Size: fit on a single chip.
Cost: should consider unit cost and
NRE(Non-Recurring Engineering) cost.
Reliability: R(t) = probability of a system working
Embedded Systems
correctly at time t provided that it was working at t
18
Characteristics of Embedded Systems (3/3)

Maintainability: M(d) = probability of a system working correctly d


time units after error occurred.
Availability: A(t) = probability of system working at time t.
Safety: no harm to be caused by failing system.
Security: should have confidential and authentic communication.

Embedded Systems 19
Chapter Two

Embedded
Microcontrollers

20
The basic computer system

CPU

System
interconnect
ion

I/O Memory

Embedded Systems 21
Structure of a basic computer system

INPUT OUTPUT
CPU UNIT UNIT

Control
unit

ALU
System Bus

Registers
RAM ROM

MEMORY

Embedded Systems 22
Components of a basic computer system

CPU (Central Processing Unit)


Executes information stored in memory.
I/O (Input/output) devices
Provide a means of communicating with CPU.
Memory
It is responsible for holding programs and
information essential to operation of the
computer.

Embedded Systems 23
Memory

For the CPU to process information, the data must be stored


in RAM or ROM, which are referred to as primary memory.
RAM (Random Access Memory)
It is read/write memory.
It is volatile memory, i.e. retains the contents as long as electricity is
supplied.
ROM (Read Only Memory)
It is read only memory.
It is non-volatile memory, i.e. the contents are retained even after
electricity is switched.

Embedded Systems 24
ROM

There are different types of read-only memory: PROM,


EPROM, EEPROM, Mask ROM.
PROM(Programmable ROM) refers to the kind of ROM that
the user can burn information into it.
PROM is a user-programmable memory.
For every bit of the PROM, there exists a fuse.
PROM is also referred to as OTP (one-time programmable).
If the information burned into PROM is wrong, that PROM must be
discarded since its internal fuses are blown permanently.

Embedded Systems 25
ROM

EPROM(Erasable Programmable ROM) was invented to allow


making changes in the contents of PROM after it is burned
In EPROM, one can program the memory chip and erase it
thousands of times.
Usually ultraviolet (UV) radiation is used to erase its contents.
Requires an external erasure and programming device.

Embedded Systems 26
ROM

EEPROM (Electrically Erasable Programmable ROM)


Its method of erasure is electrical and fast.
One can select which byte to be erased.
EEPROM does not require an external erasure and programming
device.
Mask ROM refers to a kind of ROM in which the contents are
programmed by the IC manufacturer, not user
programmable.

Embedded Systems 27
RAM

RAMs can be static or dynamic.


Static RAM:
Storage cells are made of flip-flops and therefore
do not require refreshing in order to keep their
data.
The problem with the use of flip-flops for storage
cells is that each cell require at least 6 transistors
to build, and the cell holds only 1 bit of data.
Dynamic RAM:
uses a capacitor to store each bit.
cuts down the number of transistors needed to
build the cell.
requires constant refreshing due to leakage.
Embedded Systems 28
System Bus

A bus is a set of parallel lines used to connect two or more


digital components of a computing system.
The system bus connects the CPU with the memory and
other peripherals.
The system bus combines the functions of the three main
buses: Data bus, Address bus, Control bus.

Embedded Systems 29
System Bus

Data bus carries the information being transmitted/ received.


Address bus tells where the information is being transferred
to/from.
Control bus carries the control, timing and coordination
signals to manage the various functions across the system.

Embedded Systems 30
Inside the CPU

The CPU, as the brain of a computing system, administers all


activity in the system and performs all operations on data.

IR PC

The CPU continuously Registers


performs three operations: Instruction
Decoder
Fetching, Decoding, Executing &
CU

ALU

Embedded SystemsEmbedded Systems 31


Inside the CPU

Register: General purpose registers used for temporary


storage of information.
Program Counter (PC): Holds the memory address of the
next instruction to be executed.
Instruction Register (IR): Holds the binary code for each
instruction as it is executed.
Decode & Control Unit: Determines the operation to perform
and sets the necessary actions to perform it.
Arithmetic & Logic Unit (ALU): Performs arithmetic and logic
operations.

Embedded Systems 32
Fetching an instruction

Fetching an instruction from memory involves the following


steps:
1. The contents of program counter (PC) are placed on address bus.
2. READ control signal is activated.
3. Instruction code are read from memory and placed on data bus.
4. Instruction code is latched into CPUs instruction register (IR).
5. PC is incremented to prepare for the next fetch from memory.

Embedded Systems 33
Bus Activity for Fetch Cycle

Embedded Systems 34
Input/output Devices

I/O devices or peripherals provide the path for


communication between the computer system and the
external world.
3 classes of I/O devices:
Mass Storage Devices: disk, CD-ROM
Human Interface Devices: keyboard, mouse, printer, monitor,
speaker
Control/Monitor: actuators, sensors

Embedded Systems 35
Microprocessor and Microcontroller

A CPU built into a single VLSI chip is called microprocessor


(P or MPU).
A microcontroller (C or MCU) is a small computer usually
implemented on a single IC that contains a processor core,
some memory, and programmable input/output peripherals.
Microcontrollers are mostly designed for embedded
applications and are widely used in automatically controlled
electronic devices.
Microcontrollers are used in situations where limited
computing functions are needed.

Embedded Systems 36
Microcontroller

It is composed by:
Microprocessor (CPU),
ROM (for the program),
RAM (for the data)
Peripheral devices (to make easier the interfacing
and implementation of the desired functionalities)

MPU = CPU
MCU = MPU + Peripherals + Memory
Peripherals = Ports + Clock + Timers + ADC + DAC + LCD
Drivers + Other
Memory = SRAM + EPROM + EEPROM
Embedded Systems 37
Microprocessors vs. Microcontrollers

Embedded Systems 38
Microprocessors vs. Microcontrollers
Microprocessor Microcontroller
assimilates the function of a CPU can be considered as a small
on single IC. computer which has a
processor and some other
components
used in designing general used in automatically
purpose systems controlled devices
components of personal generally used in embedded
computers systems
High computational capacity low computational capacity
has to be connected externally to The IC of a microcontroller has
some other components like memory integrated on it along
Memory (RAM and ROM) and I/ O with some other components
ports. like I / O devices and timers.
High cost Low cost
High power consumption Low power consumption
Embedded Systems 39
Types of microcontrollers

Microcontrollers can be classified on the basis of internal bus


width, architecture, memory and instruction set.
On the basis of internal bus width microcontrollers can be:
8-bit : Example Intel 8051 and Motorola MC68HC11 families
16-bit: Example Intel 8096 and Motorola MC68HC12 families
32-bit: Examples Intel 80960 and Motorola M683xx families

Embedded Systems 40
Microcontroller Architecture

There are mainly two categories of processors, namely,


Von-Neuman architecture and Harvard Architecture.

Von Neumann architecture Harvard architecture

Embedded Systems 41
Embedded memory Vs External Memory
Microcontroller

Embedded Memory Microcontroller: When an embedded


structure is built with a microcontroller which comprises of
all the functioning blocks existing on a chip it is named as
embedded memory microcontroller.
Example : 8051 microcontroller.
External Memory Microcontrollers: When an embedded
structure is built with a microcontroller which does not
comprise of all the functioning blocks existing on a chip it is
named as external memory microcontroller.
Example: 8031 has no program memory on the chip.

Embedded Systems 42
Instruction Set Architecture

CISC is a Complex Instruction Set Computer. It is a computer


that can address a large number of instructions.
In the early 1980s, computer designers recommended that
computers should use fewer instructions with simple
constructs so that they can be executed much faster within
the CPU without having to use memory. Such computers are
classified as Reduced Instruction Set Computer or RISC.

Embedded Systems 43
RISC vs CISC

RISC:
has simple instructions which often take only one or a few clock
cycles to execute.
has comparatively small and fixed code size with.
few instructions and few addressing modes.
execution of instructions is very fast.
CISC:
complex microcoded instructions which take many clock cycles to
execute.
has a large and variable code size.
many powerful instructions and addressing modes.
execution of instructions is slower than RISC.
Embedded Systems 44
CPU families used in microcontrollers

Microcontroller family defines the controllers


architecture.
All microcontrollers of a family
contain the same processor core and hence are
code-compatible.
they may differ in the additional components like
the number of timers or the amount of memory.

Embedded Systems 45
Timers and Counters

Timers and counters are distinguished from one another


largely by their use, not by their logic.
Both are built from adder logic with registers to hold the
current value, with an increment input that adds one to the
current register value.
A timer has its count connected to a periodic clock signal to
measure time intervals.
A counter has its count input connected to an aperiodic signal in
order to count the number of occurrences of some external event.

Embedded Systems 46
Interrupts

There are two techniques which can be used by the


processor to communicate with memories or I/O(peripheral)
devices: Polling and Interrupt.
Polling: In this technique the processor polls the device (asks
question) repeatedly at regular intervals to check if the device has
completed the given task or has any new task to execute.
Interrupt: An interrupt is a signal sent from a peripheral to the
processor. A peripheral may send an interrupt signal to a processor
when it has some job to perform which requires the processors
intervention.

Embedded Systems 47
Interrupts v/s Polling

An interrupt is like a shopkeeper. If one needs a service or


product, he goes to him and tells him his needs.
In case of interrupts, when the flags or signals are received, they
notify the controller that they need to be serviced.
The polling method is like a salesperson. The salesman
goes from door to door while requesting to buy a product or
service.
Similarly, the processor keeps monitoring the flags or signals one by
one for all devices and provides service to whichever component
that needs its service.

Embedded Systems 48
Interrupts

An interrupt is an event that disrupts the


normal execution of a program and causes
the execution of special instructions.
Interrupt signals can cause a program to
suspend itself temporarily to service the
interrupt by branching into another program
called Interrupt Service Routines (ISR) for
the specified device which has caused the
interrupt.
When the ISR completes, the processor
returns to the work that was interrupted.
The interrupts can be either hardware
Embedded Systems interrupts or software interrupts. 49
Hardware Interrupts

Hardware Interrupts: A hardware interrupt is an electronic


alerting signal sent to the processor from an external device,
like a disk controller or an external peripheral.
For example, when we press a key on the keyboard, it
triggers hardware interrupt which cause the processor to
read the keystroke.

Embedded Systems 50
Software Interrupts

Software Interrupts: A software interrupt is caused either by


an exceptional condition or a special instruction in the
instruction set which causes an interrupt when it is executed
by the processor.
For example, if the processor's arithmetic logic unit runs a
command to divide a number by zero, to cause a
divide-by-zero exception, thus causing the computer to
abandon the calculation or display an error message.
Software interrupt instructions work similar to subroutine
calls.

Embedded Systems 51
Interrupt Service Routine (ISR)

For every interrupt, there must be an interrupt service


routine (ISR), or interrupt handler.
When an interrupt occurs, the microcontroller runs the
interrupt service routine.
For every interrupt, there is a fixed location in memory that
holds the address of its interrupt service routine, ISR.
The table of memory locations that holds the addresses of
ISRs is called the Interrupt Vector Table.

Embedded Systems 52
Steps to Execute an Interrupt

When an interrupt gets active, the microcontroller goes


through the following steps:
The microcontroller closes the currently executing instruction and
saves the address of the next instruction (PC) on the stack.
It jumps to the memory location of the interrupt vector table that
holds the address of the interrupts service routine.

Embedded Systems 53
Steps to Execute an Interrupt

The microcontroller gets the address of the ISR from the interrupt
vector table and jumps to it.
It starts to execute the ISR until it reaches the last instruction of
the subroutine which is RETI (return from interrupt).
Upon executing the RETI instruction, the microcontroller returns to
the location where it was interrupted.
First, it gets the program counter (PC) address from the stack by
popping the top bytes of the stack into the PC.
Then, it start to execute from that address.

Embedded Systems 54
Interrupt

Program

time t

Embedded Systems 55
Interrupt

Program Program

Interrupt Service Routine

time t

Embedded Systems 56
9
fahr= (cent * ) +32
5

Interrupt

Program
mov R1, cent mul R1, 9 div R1, 5 add R1, 32 mov fahr, R1

time t

Embedded Systems 57
Interrupt

Program Program
mov R1, cent mul R1, 9
Interrupt Service Routine
mov R1, 0x90 mov sensor, R1 ret

time t

Embedded Systems 58
Interrupt

Program Program
Save Restore mul R1, 9
mov R1, cent Interrupt
Context Context
Service
Routine

time t

Embedded Systems 59
Interrupt

Program Program
Save Restore mul R1, 9
mov R1, cent Interrupt
Context Context
eg push R1 Service
eg pop R1
Routine

time t

Embedded Systems 60

You might also like