You are on page 1of 105

Embedded Systems

Abrham Debasu /Assistant Professor/

Abrham Debasu (Assistant Professor)


Assessment modality

 Assessments (min. of 3): 25%


 Mid exam: 25%
 Final Exam………….50%

Abrham Debasu (Assistant Professor)


Chapter 1

Introduction to Embedded System

Abrham Debasu (Assistant Professor)


Outline

 What is a system?

 What is embedded system


 Building blocks of ES

 Characteristics of ES
 ES architecture
 Basic block diagram of MP & MC

Abrham Debasu (Assistant Professor)


What is a System?

Abrham Debasu (Assistant Professor)


What is an Embedded System ?

User Interfaces

Software
&
Input variables Hardware Output variables

MP or MC

Abrham Debasu (Assistant Professor)


Building blocks of ES
Where?
Sensor
Buttons PSU
LED
Touch pads LCD
IR

OUTPUT
INPUT

CONTROLLER
FREQUENCY
GENERATOR

Abrham Debasu (Assistant Professor)


Application of ES

Medical area:-

CT scans, Wearable Devices, MRI…

Agricultural areas:- IoTs…

Banking:- ATMs…

Military:- Radar…

Building area:- Elevators…

etc
Abrham Debasu (Assistant Professor)
Characteristics of ES

 Real time operation

 Low manufacturing cost

 Low power consumption

 Application dependent processor

 Restricted memory
Abrham Debasu (Assistant Professor)
ES architecture

 Von Neumann

 Harvard Architecture

Abrham Debasu (Assistant Professor)


By referring CAO how von Neumann machine works?

How many registers found in von Neumann machine?

How von Neumann machine works?

When Fetching cycle is completed?

Abrham Debasu (Assistant Professor)


How IBR increase computational time?
Abrham Debasu (Assistant Professor)
Von Neumann ES Architecture

MC
Memory

Program/Instruction
Bus

Data

Abrham Debasu (Assistant Professor)


Harvard Architecture block diagram

Instruction/ Program

MC

Data

Abrham Debasu (Assistant Professor)


Microprocessor
&
Microcontroller

Abrham Debasu (Assistant Professor)


What is Microprocessor ?

Abrham Debasu (Assistant Professor)


Ad
de 8086 Microprocessor
r
AX EU BIU
BX
CS
CX
DS
DX
ES
SI,BP
DI,SP SS
IP

Instruction queue
U
AL

Flags

Abrham Debasu (Assistant Professor)


What is microcontroller ?

MC Memory

I/O port

BUS

Timer A/D converter Serial I/O Others

Abrham Debasu (Assistant Professor)


Microcontroller type

Based on
 Bit operation
 Instruction set

Abrham Debasu (Assistant Professor)


 Bit operation

 8 bit MC
(Intel’s 8031,8051, Atmel AVR)
 16 bit MC
(Intel 8096)
 32 bit MC
(AVR32, ARM)

Abrham Debasu (Assistant Professor)


 Instruction Set

 CISC (Complex instruction set computer)


 RISC (Reduced instruction set computer)

CISC (Complex instruction set computer)


 A single instruction can be used in more than one task

RISC (Complex instruction set computer)


 It reduce the operational time per instruction because
a single instruction is used for a single task
Abrham Debasu (Assistant Professor)
Criteria for choosing microcontroller

 Bit operation (8bit, 16bit and 32 bit)


 Speed (what is the highest speed that MC supports
 Power consumption (for battery )
 Amount of RAM and ROM
 The number of I/O pins
 Cost

Abrham Debasu (Assistant Professor)


Chapter 2
AVR Microcontroller

Abrham Debasu (Assistant Professor)


Outline

 Introduction to AVR family

 AVR family classification

 Simplified view of AVR architecture

Abrham Debasu (Assistant Professor)


Introduction
AVR Microcontroller

 Was first developed by Atmel in 1996

 Known as Advanced Virtual RISC.

 Based on Harvard architecture

 An 8 bit that contain code ROM,


Data RAM, Timers & I/O on a
single chip

Abrham Debasu (Assistant Professor)


AVR Microcontroller family

01 02 03 04

@ @

Mega
Special purpose Classic
Tiny 8
13 16
AT90CAN… AT90S2313
25 32
AT90WM… AT90S2323
44 64
AT90USB… AT90S4433
84 1280

Page 48-52 reading assignment

Abrham Debasu (Assistant Professor)


Mega families

MC families Code ROM Data RAM DATA I/O pins


EPROM
AT mega8 8K 1K 0.5K 23

AT mega16 16K 1K 0.5K 32

AT mega 32 32K 2K 1K 32

Abrham Debasu (Assistant Professor)


Program ROM(Flash memory)
 Used to store program or instruction
 From 1K to 256K

Data RAM (SRAM)


 Used to store data
 A maximum of 64K
 It has three components (GPR, I/o Memory and SRAM)

I/O pins
 8 to 100 pins for I/O

Abrham Debasu (Assistant Professor)


Register organization in AVR Microcontroller

32 X 8
General Purpose Registers
for alu operations

Status Register

Abrham Debasu (Assistant Professor)


GPR (General purpose registers)
R0-R31

Abrham Debasu (Assistant Professor)


SREG

LDI R16,8 LDI R16,128


LDI R17,8 LDI R17,128
Add R16,R17 Add R16,R17
Which flag register is
affected??? Page 71-74 reading assignment

Abrham Debasu (Assistant Professor)


Not directly accessible register
PC (program counter) @ next instruction

Abrham Debasu (Assistant Professor)


AVR Microcontroller Architecture

I/O Status Register


……..

Program PC
memory Register file

ALU
32KB Data
Memory
Instruction
register

Instruction
Decoder
Abrham Debasu (Assistant Professor)
LDI R16,128
LDI R17,128
Add R16,R17

Abrham Debasu (Assistant Professor)


Cycles of AVR Microcontroller

Instruction Fetching Cycle (IF)


Execution Cycle

Similar with IAS or Von Neumann machine

Abrham Debasu (Assistant Professor)


Instruction Fetching Cycle (IF)

Program counter
Program
Memory
Read Update

Instruction Register

Instruction Decoder

Abrham Debasu (Assistant Professor)


Execution Cycle

Write Write

ALU
Register File Memory

Process Write

 Register operand fetch (ROF)


 ALU execution
 Result write back (RWB)

Abrham Debasu (Assistant Professor)


RAM architecture

RAM is volatile in nature so,


To store permanently we use
EPROM

$FFFF EPROM
ROM reading assignment
Abrham Debasu (Assistant Professor)
Review questions

1. What is the basic difference between Von Neumann and Harvard architecture of
embedded system?

2. What is the difference between microcontroller and microprocessor?

3. Draw the building block of an embedded system and briefly explain the working
principle?

4. One of the characteristics of an embedded system is restricted memory. So, why


memory is restricted ?

5. Explain in detail about the working principle of AVR microcontroller?

Abrham Debasu (Assistant Professor)


Chapter 3
Addressing Mode

Abrham Debasu (Assistant Professor)


Addressing Modes
What is addressing mode ?

 A mechanism by which the microcontroller get an operand

The AVR microcontroller supports addressing modes for access to the


Program memory (Flash) and Data memory (SRAM, Register file, I/O
Memory, and Extended I/O Memory).

Abrham Debasu (Assistant Professor)


 Immediate Mode

 Register Mode

 Data Direct Mode

 Data Indirect Mode

 Data indirect with displacement

 Read about data indirect pre increment and decrement

Abrham Debasu (Assistant Professor)


Immediate Mode

Constant value is in the instruction


Stored with program code in memory

Abrham Debasu (Assistant Professor)


Data Indirect Mode

registers are 8 bit size. How ?

Abrham Debasu (Assistant Professor)


X, Y and Z registers

X-register 7 0 7 0
R27 R26

Y-register 7 0 7 0
R29 R28

7
Z-register 0 7 0
R31 R30

Used for indirect addressing for accessing flash memory


Abrham Debasu (Assistant Professor)
Register Mode
15 0
f1 Register File

OP

Abrham Debasu (Assistant Professor)


Data Direct Mode
31 16
Inst Memory
Data Memory

15 0

OP

Abrham Debasu (Assistant Professor)


Data Indirect Mode
15 0
Inst Register Memory

@ OP

Abrham Debasu (Assistant Professor)


Data indirect with displacement
15 0
f2 f1 DMEM

Register File

OP

Abrham Debasu (Assistant Professor)


Instruction Set

Abrham Debasu (Assistant Professor)


What is an instruction set?

A binary pattern inside ALU to perform a specific task

But incase of Von Neumann it is decimal pattern

Abrham Debasu (Assistant Professor)


AVR Data Types

 It has only 8 bit data type as all the register are 8 bits

AVR data format representation

 Bytes in AVR can be represented in four ways

 HEX numbers

 Ex:-

 0X15 or $15
Abrham Debasu (Assistant Professor)
 Binary numbers  Decimal numbers

 Ex:-  Ex:-

 0b01110011  15

 0B01110011  16 etc

 ASCII

Abrham Debasu (Assistant Professor)


AVR has the following classes of
instructions:
Data transfer
Arithmetic and Logic
Program control
Bit and Others
• Bit and Bit test
• MCU Control

Abrham Debasu (Assistant Professor)


AVR instruction sets

 Data transfer instruction


LDI, MOV…

 Arithmetic instruction
ADD, SUB, MUL, INC, DEC….

Abrham Debasu (Assistant Professor)


Data transfer instruction (LDI)
 Copies 8-bit data into the general purpose register
 Syntax
LDI RD,K

 RD must be R16-R31

Note: We cannot load values into registers R0-R15 using LDI instruction

Abrham Debasu (Assistant Professor)


LDS(Load direct from data space)
 Tells the CPU to load or copy from an address of data memory to GPR
 Syntax
LDS RD,K where K (0-31)

STS(Store direct to data space)


 Tells the CPU to load or copy from GPR to address of data memory
 Syntax
STS K,RD where K (0*0000-0*3FFF)

Note: you cannot copy or store an immediate value directly to SRAM. You must be
done via the GPRs

Abrham Debasu (Assistant Professor)


MOV
The MOV instruction is used to copy data among GPRs (R0-R31)
Syntax
MOV Rd,Rs

Read about IN and OUT…

Abrham Debasu (Assistant Professor)


IN

IN Rd, A ; Load an I/O location to any of the GPR


GPR (R0-R31)
A (0-63)
It can copy the content in hex
For example
IN R20,0 X 16 copy the content of port 16 in Hex to R20

Abrham Debasu (Assistant Professor)


 Arithmetic instruction
ADD, SUB, MUL, INC, DEC….

Abrham Debasu (Assistant Professor)


Bit and Bit test

LSL
LSR
ROL
ROR

Abrham Debasu (Assistant Professor)


Program control

Abrham Debasu (Assistant Professor)


Reading assignment about call and recall

Abrham Debasu (Assistant Professor)


Reading assignment about call and recall

Abrham Debasu (Assistant Professor)


Timer

 A Timer is actually a counter that counts every time the


microcontroller executes an instruction
 Used to generate precise time delay and also used as a counter
 It can be used as PWM(pulse weight modulation)

 The AVR timers are 8 bits and 16 bits


 Basically T0,T1 and T2 timer for AVR but we have 1-6 timer for MC

Abrham Debasu (Assistant Professor)


A general view of AVR Timer

0
Oscillator
16Mhz
Timer/Counter Register
1
External
PIN Flags
0/1

Abrham Debasu (Assistant Professor)


Timer 0
7 0 7 0

TOV0 TCNT0 OCR0

==
Comparator

Normal mode Clear Timer on


Compare Match
Flags
(CTC mode)
(OCF0)
Group Assignment about T1 and T2 for both oscillator and external input
Draw the architecture of T1 and T2Abrham
of AVR timers
Debasu and
(Assistant briefly discuss the working principles
Professor)
Page 348 ~
Real-time operating system (RTOS)

What is a Real-Time Operating System (RTOS)?

Real-time operating system (RTOS) is an operating


system intended to serve real time application that
process data as it comes in, mostly without buffer delay.

Abrham Debasu (Assistant Professor)


Why use an RTOS?

• It offers priority-based scheduling, which allows you to separate


analytical processing from non-critical processing.
• The Real time OS provides API functions that allow cleaner and
smaller application code.
• Abstracting timing dependencies and the task-based design results
in fewer interdependencies between modules.
• An RTOS is event-driven with no time wastage on processing
time for the event which is not occur

Abrham Debasu (Assistant Professor)


Components of RTOS

Abrham Debasu (Assistant Professor)


Types of RTOS

Hard Real Time

Soft Real Time

Firm Real time

Abrham Debasu (Assistant Professor)


Factors for selecting an RTOS

Performance
Middleware
Error-free

Task shifting

Abrham Debasu (Assistant Professor)


Difference between in GPOS and RTOS

Abrham Debasu (Assistant Professor)


Chapter 5

PIN CONFIGURTION

Reading assignment

Abrham Debasu (Assistant Professor)


Pinout Description of AVR Microcontroller

Abrham Debasu (Assistant Professor)


Abrham Debasu (Assistant Professor)
Chapter 5

Branch, Call and Delay loop

Abrham Debasu (Assistant Professor)


Laboratory session

Abrham Debasu (Assistant Professor)


Basics of Arduino UNO

Is a microcontroller (open source hardware) for prototyping)

It uses a simplified version of c++ language

Abrham Debasu (Assistant Professor)


Major components of Arduino UNO

Abrham Debasu (Assistant Professor)


Microcontroller

It is the brain of the Arduino


Consists of 28 pins
It uses Atmega 328P (microcontroller produced by Atmel

Abrham Debasu (Assistant Professor)


Atmega 328P Microcontroller
Has the following components
Flash Memory
RAM
CPU
EEPROM

Atmega328P

Abrham Debasu (Assistant Professor)


Working with ultrasonic sensor

Abrham Debasu (Assistant Professor)


How Does it Work?

Abrham Debasu (Assistant Professor)


Materials
 HC-SR04 ULTRA SONIC SENSOR
 JUMPER WIRES

 ARDUINO UNO
 ARDUINO IDE SOFTWARE

Abrham Debasu (Assistant Professor)


Abrham Debasu (Assistant Professor)
Abrham Debasu (Assistant Professor)
Abrham Debasu (Assistant Professor)
Working with ultrasonic sensor and LED light

 HC-SR04 ULTRA SONIC SENSOR


 ARDUINO UNO
 JUMPER WIRES
 ARDUINO IDE SOFTWARE
 LED LIGHT FOR NOTIFICATION

Abrham Debasu (Assistant Professor)


Abrham Debasu (Assistant Professor)
Abrham Debasu (Assistant Professor)
Seven segment display

Abrham Debasu (Assistant Professor)


Hardware Required
•1 x seven segment display (common cathode)

•1 x Arduino

•1 x breadboard

•Regulators

•jumper wires

Abrham Debasu (Assistant Professor)


Abrham Debasu (Assistant Professor)
How to read from RAM ?

How to Write to RAM ?

4004, 8085, 8086, ….

Abrham Debasu (Assistant Professor)


8086 MP portioned as
EU
BIU

EU is used for execution

BIU is used for fetching

Abrham Debasu (Assistant Professor)


Why partitioned as EU and BIU?

What will happen if IP is located at EU?

Abrham Debasu (Assistant Professor)


Ad
de 8086 Microprocessor
r
AX EU
BX
CX
DX ?
SI,BP
DI,SP

Memory

U
AL

Flags

Abrham Debasu (Assistant Professor)


Ad
de 8086 Microprocessor
r
AX EU BIU
BX
CS
CX
DS
DX
ES
SI,BP
DI,SP SS
IP

Instruction queue
U
AL

Flags

Abrham Debasu (Assistant Professor)


Instruction Set

Data transfer instruction

MOV
IN
OUT… etc.

Abrham Debasu (Assistant Professor)


MOV
Syntax
MOV Dest, Src

Rule
 Must be the same size
 Both can not be memory
 An immediate value can not be directly move
to segment

Abrham Debasu (Assistant Professor)


IN
Syntax
IN AX/AL, <port #>

OUT
Syntax
OUT <port #>, AX/AL

Abrham Debasu (Assistant Professor)


Bit transfer instruction

Shift and Rotate instruction


SHR : Shift Right
SHL : Shift Left
ROL : Rotate Left
ROR : Rotate Right

Abrham Debasu (Assistant Professor)


SHR : Shift Right

SHL : Shift Left

Abrham Debasu (Assistant Professor)


ROL : Rotate Left

ROR : Rotate Right

Abrham Debasu (Assistant Professor)

You might also like