Вы находитесь на странице: 1из 68

Embedded System Design and Applications

(EE-423)
Dr. Muhammad Rauf
Assistant Professor
Electronics Engineering Department
MUHAMMAD RAUF
Master of Engineering in Electronics (2009-2011)
Research Area: Embedded system and optimization

PhD. in Electrical and Electronics (2012-2016)


Research area: Applied Electromagnetics

Research Scientist (2016-2017)


Research area: Electromagnetics and optics

Assistant Professor (June 2017 onwards)


EED, SSUET

Member of:
IEEE (Karachi Chapter)
Board of Studies (EED, SSUET
FYP committee (EED, SSUET)
Post Graduate Program (SSUET)
Achievements
• 10 Journal papers
• 18 international conference papers
 GOLD Medal – SEDEX 31, UTP
 IEM best invention award – SEDEX 31, UTP
 Most Innovative award- THE CHAMPION for SEDEX 31, UTP
 GOLD Medal- MTE, Kuala Lumpur
 SILVER Medal- CITREX, UMP
Course Instructor
• Name : Dr. Muhammad Rauf
• Office : GG-07
• Phone : 021-34988000, Ext- 347
• Email : mrauf57@gmail.com

Course Schedule
Lectures
• Monday 12:40–1:30 pm @ Room No. GFT-3
• Thursday 11:50–12:40 pm @ Room No. GF-4
• Friday 8:30–9:15 am @ Room No. GFT-3
Course Learning Outcomes
CLO
Description Level
No.
Comprehend the basic knowledge of embedded
1 system and its architecture included microcontroller C2
and FPGA.
Demonstrate programming interfacing of PIC
2 microcontrollers, Arduino and FPGA with different C3
type of peripherals.
Design an embedded system for engineering C6
3
problem.
Text Books
The PIC Microcontroller And Embedded
Systems: Using Assembly And C for PIC18, ANY
Edition, Muhammad Ali Mazidi, Rolin
McKinlay, Danny Causey
What is Embedded System

 EMBEDDED SYSTEM Any device that includes


a computer, but is not itself a general purpose
computer
 HARDWARE AND SOFTWARE Part of some
larger system and expected to function without
human intervention.
 Respond, monitor, control external
environment using sensor and actuators
DESCLAIMER: The slides are re produced from the combination of several published work and online
resources. Therefore it is not original work from the lecturer presenting the slides .
Intro to the Embedded System
Implementing Embedded System
 Hardware
 Processing Element
 Peripherals
• Input and output devices
• Interfacing sensors and actuators
• Interfacing protocols
 Memory
 Bus
 SOFTWARE
 System software
 Application software
Design goals for Embedded System

 Performance
• Overall speed and deadlines
 Functionality and user interface
 Manufacturing cost
 Power consumption
 Other requirements (physical size)
Comparison
Comparison
Microcontrollers
PIC Microcontrollers
• Peripheral Interface Controller (PIC) was originally
designed by General Instruments
• In the late 1970s, GI introduced PIC® 1650 and
1655 – RISC with 30 instructions.
• PIC was sold to Microchip
• Features: low-cost, self-contained, 8-bit, Harvard
structure, pipelined, RISC, single accumulator, with
fixed reset and interrupt vectors.

17
Complex instruction set computer Reduce instruction set computer
PIC Families
PIC Family Stack Size Instruction No of Interrupt
Word Size Instructions Vectors
12CX/12FX 2 12- or 14-bit 33 None
16C5X/16F5X 2 12-bit 33 None
16CX/16FX 8 14-bit 35 1
17CX 16 16-bit 58 4
18CX/18FX 32 16-bit 75 2

‘C’ implies CMOS technology; Complementary Metal Oxide Semiconductor

‘F’ insert indicates incorporation of Flash memory technology

Example: 16C84 was the first of its kind. It was later reissued as the 16F84,
incorporating Flash memory technology. It was then reissued as 16F84A.

Dr. Gheith Abandah 20


Architectures
Von Neumann
Architecture
• Von Neumann Architecture:
• Fetches instructions and data
from a single memory space
• Limits operating bandwidth
8-bit Bus Program
& Data
Memory
CPU • Harvard Architecture:
Harvard • Uses two separate memory
Architecture spaces for program instructions
and data
• Improved operating bandwidth
8-bit Bus Data
Memory • Allows for different bus widths
16-bit Bus
CPU

Program
Memory
PIC18F Microcontroller Families
• PIC microcontrollers are designed using the Harvard
Architecture which includes:
• Microprocessor unit (MPU)
• Program memory for instructions
• Data memory for data
• I/O ports
• Support devices such as timers
Microprocessor Unit (1 of 3)
• Includes Arithmetic Logic
Unit (ALU), Registers, and
Control Unit
• Arithmetic Logic Unit (ALU)
• WREG – working register
• Status register that stores
flags
• Instruction decoder – when
the instruction is fetched it
goes into the ID
Microprocessor Unit (2 of 3)

• Registers
• Bank Select Register (BSR)
• 4-bit register used in direct addressing the data memory
• File Select Registers (FSRs)
• 16-bit registers used as memory pointers in indirect addressing data memory
• Program Counter (PC)
• 21-bit register that holds the program memory address while executing programs
Microprocessor Unit (3 of 3)

• Control unit
• Provides timing and control signals to various Read and
Write operations
Summary
• An embedded system is a product that has one or more
computers embedded within it, which exercise primarily
a control function.
• Microcontrollers are designed according to accepted
electronic and computer principles, and are
fundamentally made up of microprocessor core,
memory and peripherals.
• Microchip offers a wide range of microcontrollers,
divided into a number of different families. Each family
has identical central architecture and instruction set.
However, common features also appear across all their
microcontrollers.
26
PIC18F Programming Model
• The understanding of
the internal architecture
of a microprocessor is
necessary to write
assembly language
programs.

• Divided into two groups


• ALU Arithmetic Logic
Unit (ALU)
• Special Function
Registers (SFRs) from
data memory
Registers
• WREG
• 8-bit Working Register (equivalent to an
accumulator)
• BSR: Bank Select Register
• 4-bit Register (0 to F)
• Only low-order four bits are used to provide
MSB four bits of a12-bit address of data
memory.
• STATUS: Flag Register

Status Register contains the arithmetic status of the ALU (Arithmetic Logic Unit), the RESET
status and the bank select bit for data memory
WREG
• 8-bit Working Register (equivalent to an
accumulator)
• A most widely used register in PIC
• Used for all arithmetic and logic instruction

Any data larger than 8 bit will be broken into 8 bits chunks
before it is processed.
Flags in Status Register
Example: 9F+52 =F1
1001 1111
0101 0010
-------------
1111 0001
N=1,OV=0, Z=0, C=0, DC=1

• C (Carry/Borrow Flag):
• set when an addition generates a carry and a subtraction generates a borrow
• DC (Digit Carry Flag):
• also called Half Carry flag; set when carry generated from Bit3 to Bit4 in an arithmetic
operation
• Z (Zero Flag):
• set when result of an operation is zero
• OV (Overflow Flag):
• set when result of an operation of signed numbers goes beyond seven bits
• N (Negative Flag):
• set when bit B7 is one of the result of an arithmetic /logic operation
File Select Registers (FSR)
• There are three registers:
• FSR0, FSR1, and FSR2
• Each register composed of two 8-bit registers
(FSRH and FSRL)
• Used as pointers for data registers
• Holds 12-bit address of data register
Registrars functionality in PIC Microcontroller
Other Registers
• Program Counter (PC) • Stack
• 21-bit register functions as a • 31 word-sized registers used
pointer to program memory for temporary storage of
during program execution memory addresses during
• Table Pointer execution of a program
• 21-bit register used as a • Special Function Registers
memory pointer to copy bytes (SFRs):
between program memory • Data registers associated
and data registers with I/O ports, support
• Stack Pointer (SP) devices, and processes of
• Register used to point to the data transfer
stack
18f has 16 banks of register
Introduction to
PIC18 Instruction
Set

Taken from chapter 2


PIC18 Instruction Set
• Includes 77 instructions; 73 one word (16-bit) long and
remaining four two words (32-bit) long
• Divided into seven groups
• Move (Data Copy) and Load
• Arithmetic
• Logic
• Program Redirection (Branch/Jump)
• Bit Manipulation
• Table Read/Write
• Machine Control

Instruction set grouped into 3 categories:


 Byte oriented operations
 Bit oriented operation
 Literal and control operation
Arithmetic and logic instruction set
Byte oriented operations
• Arithmetic and logic operation
• Data management
movwf Instruction form
• “Write contents of W register to data memory location
floc”. General form:
• movwf floc, D ;floc←(w)
• floc is a memory location in the file registers (data memory)
• W is the working register
• When floc is destination, means “modify memory location floc”.
• D indicates the destination bit
• movwf 0x70 ; Move (copy) WREG contents to location 0x70
movwf Instruction Execution
 movwf 0x70

Assume the following Memory/Register contents before execution:

W = 0x2A W = 0x2A (unaffected)


Location Contents
Location Contents
0x06f 0x34
0x06f 0x34
0x070 0x8f
0x070 0x2A modified
0x071 0x00
0x071 0x00
0x072 0xf9
0x072 0xf9
BEFORE movwf 0x070
AFTER movwf 0x070
MOVE instructions
• PIC spend a lot of time moving data around as data
stored in memory
• movlw 20
• Move the hex value H’20’ into W
• To load a decimal must use the correct assembler
directive - D’20’

• Initialization of a variable
• movlw B’11100000’
• movwf TRIST
• Initialize the PORTB data direction register.
41
The movff instruction
• movff PORTB, PORTB_COPY
• movff - a two-word instruction
• Thus source and destination have 12-bit addresses
• Source – instruction bits + BSR
• Destination – instruction 2nd byte
• Moves data from a 1-byte source to a 1-byte
destination.
• For instruction memory as efficient as the regular move
instruction.

42
The movwf
• movwf f(,Banked) – Move WREG to f

• For storing back the result of an operation


• Does not affect status bits

The movf instruction


• Move the value and set the status register bits
appropriately
• Affects N and Z bits
43
Move summary
• movlw k - load literal value
• movwf MYVAR - move value but do not affect
status bits
• movff V1,V2 - move data at source address to data
at destination address
• movf f,F/W - move value and affect status bits
• What does movf COUNT,F do?

44
Example to evaluate the final values of working
register using Mov and add commands
MOVLW and ADDLW
Class assignment
Write instruction to move value 34h into working register then
add values 16H and CDH in the same register
comf
Decf/Incf
TASK: What is the final value in WREG in both of the
codes below;
PIC like many other microcontrollers, supports only
addition and subtraction
• Flag C, Z and DC are set depending on the results of
addition and subtraction.
• Since subtraction is performed like addition of the
negative number, C flag is inverse following a
subtraction.

Logic unit of PIC has capability of performing operations


like AND, OR, EX_OR, complementing (COMF)
Some commonly used Instructions
BRANCH, CALL
AND TIME
DELAY LOOP
Branches
•Needed for program flow control
•Tests on status register
• bc, bnc, bz, bnz, bn, bnn, bov, bnov
• Use the C, Z, N, and OV bits of the
status register
Branch Instructions using status register
Op-Code Description
Increment/Decrement
and Skip Next Instruction
Op-Code Description
Conventional Way: Add 3 in working register 5 times

Looping in PIC
Using DECFSZ Using BNZ
Examples using both ways

target location.
Call and Return Instructions
Op-Code Description
Test and Skip Instructions
Op-Code Description
Loop inside a loop
All locations in a file register is 8 bit. Therefore a
single loop can only go up to 255 times.
Any loop more than 255, would need another
loop.
Unconditional branch

GOTO to itself
Time Delay in PIC: The Calculations
Calculation for machine cycle
Calculation for instructions cycle

Вам также может понравиться