microcontroller part 1
TRANSCRIPT
https://www.facebook.com/groups/embedded.system.KS/
Embedded System
PART 1ENG.KEROLES SHENOUDA
1
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
Index (1/3) Introduction to COMPUTER SYSTEM
Memory
I/O Unit
Microprocessor
The internal structure of a microprocessor.
Central Processing Unit (CPU)
Arithmetic and logic unit (ALU)
Control unit
CPU Interactions
Clocks
Cache Memory (L1 and L2) Cache
2
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
Index (2/3) Special Purpose Registers
PC Program Counter Register
Instruction Register IR
Instruction Decoder ID
STACK Pointer SP Register
STACK Pointer SP Register
Status Register (SREG)
Status Register (SREG)
Index Register (X,Y)
Accumulator Registers (A,B)
General purpose Registers (R1,R2,R3,….)
3
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
Index (3/3)
Microcontroller
Microcontroller Vs Microprocessor Vs SOC
von Neumann Architecture
Harvard Architecture
pipeline
CIS Vs RISC
AVR different groups
4
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
What will get on Embedded System
AVR Microcontroller
AVR Interfacing
ARM SOC
ARM Tiva C
5
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
GITHUP “Embedded System” Repo6
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
Please Put your Code on the Best
Place
7
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
Introduction to COMPUTER
SYSTEM
A computer is a programmable machine that receives input, stores and manipulates data//information, and provides output in a useful format.
8
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
BLOCK DIAGRAM OF A BASIC
COMPUTER SYSTEM
ROM RAM I/O
interface
I/O
devicesCPU
Basic computer system consist of a Central processing unit (CPU),
memory (RAM and ROM), input/output (I/O) unit.
Block diagram of a basic computer system
Address bus
Data bus Control
bus
9
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
Basic component of
microcomputer1. CPU - Central Processing Unit
the portion of a computer system that carries out the instructions of a computer program
the primary element carrying out the computer's functions. It is the unit that reads and executes program instructions.
The data in the instruction tells the processor what to do.
Pentium D dual core processors
10
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
physical devices used to store data or programs (sequences of instructions) on a temporary or permanent basis for use in an electronic digital computer.
Computer main memory comes in two principal varieties: random-access memory (RAM) and read-only memory (ROM).
RAM can be read and written to anytime the CPU commands it, but ROM is pre-loaded with data and software that never changes, so the CPU can only read from it.
ROM is typically used to store the computer's initial start-up instructions.
In general, the contents of RAM are erased when the power to the computer is turned off, but ROM retains its data indefinitely.
In a PC, the ROM contains a specialized program called the BIOSthat orchestrates loading the computer's operating system from the hard disk drive into RAM whenever the computer is turned on or reset.
Memory11
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
Input/output (I/O), refers to the communication between an information processing system (such as a computer), and the outside world possibly a human, or another information processing system.
Inputs are the signals or data received by the system, and outputsare the signals or data sent from it
Devices that provide input or output to the computer are called peripherals
On a typical personal computer, peripherals include input devices like the keyboard and mouse, and output devices such as the displayand printer. Hard disk drives, floppy disk drives and optical disc drives serve as both input and output devices. Computer networkingis another form of I/O.
I/O Unit12
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
Microcontroller vs MicroprocessorA Microcontroller is basically a computer on a chip. It differs form normal desktop or laptop
computers in that a microcontroller is an application specific computer that usually runs
a single program performing dedicated task(s) while the the later two are general purpose
computers that can run numerous programs depending on a users needs. A microcontroller
contains on chip CPU, input/output interface, memory, clock, timer, and an assortment of of
other peripherals.
A Microprocessor on the other hand is just a CPU one
has to add externally memory, clock, input/output
interfaces, timer and all other needed peripheral. This is
the reason a microprocessor has so many pins.
13
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
Microprocessor There are five important components in a microprocessor. They are Arithmetic
and Logic Unit (ALU), Control Unit, Registers, Instruction Decoder and Data Bus but the first three are considered significant components. The block diagram of a microprocessor with these basic components is shown below.
14
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
Microprocessor
The internal structure
of a microprocessor.
15
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
Central Processing Unit (CPU)
Arithmetic / Logic Unit
Registers
Control Unit
Small, fast
storage areas for
instructions and
data
Performs calculations
and decisions
Coordinates
processing steps
16
https://www.facebook.com/groups/embedded.system.KS/
The Little Man Computer17
https://www.facebook.com/groups/embedded.system.KS/
The Processor
The processor is the "brain" of the computer system.
Main processor is called the Central Processing Unit (CPU).
A particular computer will have a particular type of processor, such as a Pentium
or a SPARC chip.
Co-processors assist the CPU with some of the processing functions. Examples:
Math co-processors handle heavy duty math processing
Graphics coprocessors speed up the display of graphics onto the monitor
18
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
Internal structure and basic
operation of microprocessor
ALU Register
Section
Control and timing
section
Address bus
Data bus
Control bus
Block diagram of a microprocessor
19
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
20
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
Arithmetic and logic unit (ALU)
The component that performs the arithmetic and logical operations
the most important components in a microprocessor, and is typically the part of the processor that is designed first.
able to perform the basic logical operations (AND, OR), including the addition operation.
The inclusion of inverters on the inputs enables the same ALU hardware to perform the subtraction operation (adding an inverted operand), and the operations NAND and NOR.
21
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
Internal structure of ALU
2 bits of ALU 4 bits of ALU
22
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
Control unit
The circuitry that controls the flow of information through the processor, and coordinates the activities of the other units within it.
In a way, it is the "brain within the brain", as it controls what happens inside the processor, which in turn controls the rest of the PC.
On a regular processor, the control unit performs the tasks of fetching, decoding, managing execution and then storing results.
23
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
Internal structure of control unit24
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
Memory
Computer Memory - millions/billions of on/off charges
Divided into:
Bits 0 or 1
Bytes Groups of 8 bits A byte is the smallest unit of storage.(Can hold one text character)
WordsGroups of bits/bytes (8, 16, 32, 64-bits)
25
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
Memory
Storage is usually too large to be expressed in bytes or
words. Instead we use:
Kilobyte (KB) = 1024 bytes(210 bytes)
Megabyte (MB) = 1024 x 1024 bytes or one
million bytes (220 bytes)
Gigabyte (GB) = 1024 x 1024 x 1024 bytes or
one trillion bytes (230 bytes)
Terabyte (TB) = 1024 x 1024 x 1024 x 1024 bytes
one quadrillion bytes (240 bytes)
26
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
Main Memory
Each computer has a specific word size
Word sizes vary from computer to computer.
Word size is an even multiple of a bytes.
Each word within memory can hold either
data or
program instructions
27
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
Main Memory
5248
5249
5250
5251
5252
5253
5254
5255
5256
A word is stored in
consecutive
memory bytes.
10011010
Each memory cell stores a
set number of bits (some
computers use 8 bits/one
byte, others use words)
Each memory cell
has a numeric
address, which
uniquely identifies
its location
28
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
CPU and Memory
CPU can interact with main memory in two ways:
It can write a byte/word to a given memory location.
The previous bits that were in that location are destroyed
The new bits are saved for future use.
It can read a byte/word from a given memory location.
The CPU copies the bits stored at that location and stores them in a CPU register
The contents of the memory location are NOT changed.
29
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
Main Memory Characteristics
Very closely connected to the CPU.
Contents are quickly and easily changed.
Holds the programs and data that the
processor is actively working with.
Interacts with the processor millions of times
per second.
Nothing permanent is kept in main memory.
30
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
Secondary Storage Characteristics
Connected to main memory through a bus and a
device controller.
Contents are easily changed, but access is very
slow compared to main memory.
Only occasionally interacts with CPU.
Used for long-term storage of programs and data.
Much larger than main memory (GBs vs. MBs).
31
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
Program Instructions
Programs instructions are stored in secondary storage
(hard disks, CD-ROM, DVD).
To process data, the CPU requires a working area
Uses Main Memory
Also called: RAM (random access memory),
primary storage, and internal memory.
Before a program is run, instructions must first be copied
from the slow secondary storage into fast main memory
Provides the CPU with fast access to instructions to
execute.
32
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
Instructions
An instruction is a sequence of bits.
A simple instruction format may consist of an
operation code (op code) and an address or
operands.
Op Code Operands / Address
Instructions tell the computer’s CPU what to do.
33
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
Instructions
The operation code specifies the operation the computer is to carry out (add, compare, etc)
The operand/address area can store an operand or an address
An operand is a specific value or a register number
An address allows the instruction to refer to a location in main memory
The CPU runs each instruction in the program, starting with instruction 0, using the fetch-decode-execute cycle.
34
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
Fetch-Decode-Execute Cycle
During the fetch part, the CPU fetches the next instruction from the address contained in the Program Counter and places the instruction in the Instruction Register.
When a program starts, the program counter contains 0, so the instruction at address 0 is fetched.
As soon as an instruction is fetched, the CPU adds 1 word to the contents of the Program Counter, so that it will contain the address of the next sequential instruction.
35
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
Fetch-Decode-Execute Diagram
Program Counter (PC)
3023
Instruction Register
General Purpose Registers
Fetch
Get instruction and
increment PC
CPU
…
3020
3021
3022
3023
3024
3025
3026
3027
3028
…
Main Memory
add r3, r1, r2
33
45
add r3, r1, r2
r1
r2
r378
3024
Execute
In this case add r1 and
r2 and put result in r3.
Decode
Determine what the
instruction is (add)
Then begin again by Fetching the instruction in 3024….
36
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
Clocks
Computer systems have an internal clock, which is used to synchronize their
activities.
Processors run at a particular clock speed.
Clock speed is measured in Hertz
One Hertz is one clock tick per second.
MHz means mega Hertz
One MHz is one million clock ticks per second.
The clock speed determines how fast instructions can be run
37
https://www.facebook.com/groups/embedded.system.KS/
Access to Instructions
The hard disk is too slow to provide instructions to the CPU.
So programs are first loaded into main memory, which is much faster.
The CPU can then access the instructions more quickly.
38
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
Cache Memory
But as CPU speeds became faster, the main memory
couldn’t provide the CPU with the instructions at a fast
enough rate.
So even faster memory ( cache memory) is now placed
between the CPU and main memory to provide the
instructions at an quicker rate to the CPU.
39
https://www.facebook.com/groups/embedded.system.KS/
Cache Memory
When an instruction or data is accessed from main memory, it is placed in
the cache. Second and subsequent use of the same instruction/data will
then be faster, since it is accessed directly from the cache.
40
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
Primary and Secondary
Cache Memory Most modern CPUs now have a cache memory (L1), on the
same silicon wafer as the CPU, to provide the CPU with
instructions at the same clock speed as the CPU.
An additional off-the-chip secondary cache (L2) may also
interact with the CPU at a slower speed.
41
https://www.facebook.com/groups/embedded.system.KS/
L1 and L2 Cache Memory42
https://www.facebook.com/groups/embedded.system.KS/
Memory 43
https://www.facebook.com/groups/embedded.system.KS/
Random Access Memory
Its a type of memory that can be accessed randomly
- that is, a memory location can be accessed without touching other locations.
RAM is also called Read-Write Memory, as you can perform both read and
write operations on this memory device.
RAM are of two types
•Static RAM (SRAM) :1) Storage cells are made of flip-flops and therefore don’t require refreshing in order to keep their data 2) The problem of flip-flops is that each cell requires at least 6 transistors to build and this cell hold only 1 bit 3) The use of 4-transistor cells plus the use of CMOS technology give birth to a high-capacity SRAM but its capacity is so far below that of DRAM
44
https://www.facebook.com/groups/embedded.system.KS/
•Dynamic RAM :1) It’s lower than SRAM in price power consumption 2) Using a capacitor to store data cuts down the number of transistors to build the cells 3) The capacitors require constant refreshing due to charge leakage 4) While DRAM is being refreshed , its data cannot be accessed in contrast to SRAM whose data can be accessed any time as it doesn’t need refreshing
Random Access Memory45
https://www.facebook.com/groups/embedded.system.KS/
Read Only Memory•It is a memory device from which the processor can read data but to which it
cannot write data. Like CD. The programs and data that needs to be permanently
stored are kept in ROM devices. ROM Retains its contents even if power is switched
off; therefore it is used to store program codes and any permanent data
retained to initialize and operate embedded systems. A verity of ROM devices
are available, each with different capabilities.
•PROM(Programmable ROM): It can be programmed only once.
1) The kind of ROM that the user can burn information into 2) For every bit , there is a fuse 3) PROM is programmed by blowing the fuses 4) The information can be burned into PROM only once , so it’s called OTP(one-time programmable)
46
https://www.facebook.com/groups/embedded.system.KS/
Read Only Memory
•EPROM (Erasable ROM): It can be programmed many times.An
EPROM programmer is required to program the EPROM chip.
Can be programed and erased thousands of time 2) A widely used (EPROM) is called (UV-EPROM) 3) UV-EPROM has a window through which the programmer can shine ultra-violet radiation to erase its contents 4) To burn code into the UV-EPROM , the ROM burner uses 12.5 volts or higher 5) The major disadvantage with UV-EPROM is that it cannot be erased while it’s in the system board
47
https://www.facebook.com/groups/embedded.system.KS/
Read Only Memory
Mask ROM
1) It’s not a user programmable ROM
2) It’s contents are only programmed by the IC-Manufacturer
3) Cheaper than other kinds of ROMs and is one-time programmable
(OTP)
48
https://www.facebook.com/groups/embedded.system.KS/
Hybrid Memory
•Electrically Erasable Programmable ROM (EEPROM) : It
is similar to EPROM, but it can be erased electrically by
applying an electrical signal to one of the pins.
Its method of erasure is electrical and therefore instant as opposed to 20-minute erasure time required for UV-EPROM 2) In EEPROM , you can select the byte to be erased in contrast to UV-EPROM whose contents can be only entirely erased 3) It can be programmed while it’s in the system board without the need of an external erasure or programming device 4) It’s cost is higher than UV-EEPROM
49
https://www.facebook.com/groups/embedded.system.KS/
Hybrid Memory
•Non-Volatile RAM (NVRAM) : It is a SRAM with battery backup so that the
contents are not erased even if power is switched off. Its is very expensive but data
access through it is fast.
1) It allows the CPU to read and write to it and when the power is off , the contents are not lost 2) It can retain its contents up to 10 years after turning off the power 3) It uses extremely power-efficient SRAM cells built out of CMOS 4) It uses internal lithium battery as a backup energy source 5) If the power to the Vcc pin falls bellow out of tolerance condition , the control circuitry switches automatically to its internal power source (the lithium battery) 6) Another type of the NVARM combines SRAM and EEPROM so that its content is written into the EEPROM when power is off and is read back from the EEPROM when power is restored.
50
https://www.facebook.com/groups/embedded.system.KS/
Hybrid Memory
•Flash Memory : it is also a non - volatile memory, fast EEPROM. The main attraction
of flash is that it can be erased one block at a time and programmed one bit at a time.
Flash memory devices are high density, low cost, fast (to read but not to write), and
electrically programmable. It is being extensively used for embedded systems that
contain embedded OS and the application program such as handheld computers.
The erasure method is electrical so , it’s referred to as flash EEPROM 2) In old flash EEPROM you can only erase the entire contents (not just specific byte) 3) In recent decades flash memory contents are divided into blocks where erasing is done block by block 4) It can be programmed while it’s in the system board
51
https://www.facebook.com/groups/embedded.system.KS/
User view of Computer Systems
Software that
controls the
hardware devices
Operating System –
- the user interface
Applications
e.g. Word, Netscape, etc
52
https://www.facebook.com/groups/embedded.system.KS/
Watchdog Timer
Most of the embedded systems have no provision of resetting the processor in
such cases a watchdog timer is used.
It is set to a large value and is counted down.
When value reaches zero, the processor resets.
If things are fine and there is no need to reset the processor, the
processor resets the watchdog timer to that large value again.
53
https://www.facebook.com/groups/embedded.system.KS/
54
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
Register sets
The register section/array consists completely of circuitry used to temporarily store data or program codes until they are sent to the ALU or to the control section or to memory.
The number of registers are different for any particular CPU and the more register a CPU have will result in easier programming tasks.
Registers are normally measured by the number of bits they can hold, for example, an "8-bit register" or a "32-bit register".
55
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
Registers
Use of Registers
Scratchpad for currently executing program
Holds data needed quickly or frequently
Stores information about status of CPU and currently executing program
Address of next program instruction
Signals from external devices
General Purpose Registers
User-visible registers
Hold intermediate results or data values, e.g., loop counters
Equivalent to LMC’s calculator
Typically several dozen in current CPUs
56
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
57
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
PC Program Counter Register58
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
Instruction Register IR59
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
Instruction Decoder ID60
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
STACK Pointer SP Register61
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
STACK Pointer SP Register62
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
Status Register (SREG) 63
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
Status Register (SREG) 64
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
ATMega32 Programmer Model: Registers (SR)
CPUPC
ALU
registers
R1
R0
R15
R2
…
R16
R17
…
R30
R31Instruction Register
Instruction decoder
SREG: I T H S V N CZ
$0000
$0001
$0020
General
purpose
RAM
(SRAM)
$001F
$005F
TWBR
TWSR
SPH
SREG
...
General
Purpose
Registers
Standard IO
Registers
$00
$01
$3E
$3F
$0060
...
...
Data Address
Space
IO Address
...
$FFFF
SREG:
CarryZero
Negative
oVerflow
SignN+VHalf carry
Temporary
Interrupt
H S V N CZTI
65
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
ATMega32 Programmer Model: Registers (SR)
CPUPC
ALU
registers
R1
R0
R15
R2
…
R16
R17
…
R30
R31Instruction Register
Instruction decoder
SREG: I T H S V N CZ
$0000
$0001
$0020
General
purpose
RAM
(SRAM)
$001F
$005F
TWBR
TWSR
SPH
SREG
...
General
Purpose
Registers
Standard IO
Registers
$00
$01
$3E
$3F
$0060
...
...
Data Address
Space
IO Address
...
$FFFF
SREG:
CarryZero
Negative
oVerflow
SignN+VHalf carry
Temporary
Interrupt
H S V N CZTI
Example: Show the status of the C, H, and Z flags after the addition of 0x38
and 0x2F in the following instructions:
LDI R16, 0x38 ;R16 = 0x38
LDI R17, 0x2F ;R17 = 0x2F
ADD R16, R17 ;add R17 to R16
Solution: 1
$38 0011 1000
+ $2F 0010 1111
$67 0110 0111 R16 = 0x67
C = 0 because there is no carry beyond the D7 bit.
H = 1 because there is a carry from the D3 to the D4 bit.
Z = 0 because the R16 (the result) has a value other than 0 after the addition.
66
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
ATMega32 Programmer Model: Registers (SR)
CPUPC
ALU
registers
R1
R0
R15
R2
…
R16
R17
…
R30
R31Instruction Register
Instruction decoder
SREG: I T H S V N CZ
$0000
$0001
$0020
General
purpose
RAM
(SRAM)
$001F
$005F
TWBR
TWSR
SPH
SREG
...
General
Purpose
Registers
Standard IO
Registers
$00
$01
$3E
$3F
$0060
...
...
Data Address
Space
IO Address
...
$FFFF
SREG:
CarryZero
Negative
oVerflow
SignN+VHalf carry
Temporary
Interrupt
H S V N CZTI
Example: Show the status of the C, H, and Z flags after the addition of
0x9C and 0x64 in the following instructions:
LDI R20, 0x9C
LDI R21, 0x64
ADD R20, R21 ;add R21 to R20
Solution: 1
$9C 1001 1100
+ $64 0110 0100
$100 1 0000 0000 R20 = 00C = 1 because there is a carry beyond the D7 bit.
H = 1 because there is a carry from the D3 to the D4 bit.
Z = 1 because the R20 (the result) has a value 0 in it after the addition.
67
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
Index Register (X,Y)68
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
Accumulator Registers (A,B)69
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
General purpose Registers
(R1,R2,R3,….) Most instructions have direct access to all registers ▫ LD, MUL
Some only operate on R16-R31
▫ ANDI, CPI, SUBI, MULS
A few operate only on R16:R23
▫ Special multiply operations
Double word operations operate on register pairs (R24-31)
Most single-byte register or register+immediate operations are single cycle instructions
70
https://www.facebook.com/groups/embedded.system.KS/
Instruction Set Architecture ISA 71
https://www.facebook.com/groups/embedded.system.KS/
AVR Assembler Statement
• The Assembler works on source files containing instruction mnemonics, labels anddirectives. The instruction mnemonics and the directives often take operands.
• Code lines should be limited to 120 characters.
• Every input line can be preceded by a label, which is an alphanumeric string terminated by acolon. Labels are used as targets for jump and branch instructions and as variable names inProgram memory and RAM.
• An input line may take one of the five following forms:
<label> <opcode> <operand> <;comments>
<label> <opcode> <operands> <;comments>
<label> <directive> <operands> <;comments>
Comments
Empty line
test: rjmp test ; Infinite loop (Instruction)
main: ldi R16, 9 ; store value 9 into register R16label: .EQU var1=100 ; Set var1 to 100 (Directive)
.EQU var2=200 ; Set var2 to 200; Pure comment line
72
https://www.facebook.com/groups/embedded.system.KS/
AVR Assembler Output Files
EDITOR
PROGRAM
ASSEMBLER
PROGRAM
DOWNLOAD TO
AVR ’s FLASH
DOWNLOAD TO
AVR’s EEPROM
myfile.asm
myfile.objmyfile.eep myfile.hex myfile.map myfile.lst
73
https://www.facebook.com/groups/embedded.system.KS/
AVR Assembler: Example
; Start on the flash ram's address 0.org 0
000000 e009 main: ldi R16, 9000001 e016 ldi R17, 6000002 0f10 add R17, R16000003 ef2f ldi R18, 255000004 bb27 out DDRB, R18000005 bb18 out PORTB, R17000006 cff9 rjmp main
LCMachine
code
Assembly
code
Assembly complete, 0 errors, 0 warnings
74
https://www.facebook.com/groups/embedded.system.KS/
Instruction Set Architecture ISA 75
https://www.facebook.com/groups/embedded.system.KS/
Instruction Set Architecture ISA 76
https://www.facebook.com/groups/embedded.system.KS/
Instruction Life Cycle 77
https://www.facebook.com/groups/embedded.system.KS/
Microprocessor revision (funny way) 78
https://www.facebook.com/groups/embedded.system.KS/
Microprocessor revision (funny way) 79
https://www.facebook.com/groups/embedded.system.KS/
Microprocessor revision (funny way) 80
https://www.facebook.com/groups/embedded.system.KS/
Microprocessor revision (funny way) 81
https://www.facebook.com/groups/embedded.system.KS/
Microprocessor revision (funny way) 82
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
Microcontroller Microcontrollers are basically used in embedded systems. Computerized or
digital control of devices is made plausible with the development of microcontrollers. The development process of microcontroller is similar to that of a microprocessor.
Microcontrollers can be classified based on bus width, memory structure and instruction set. Bus width indicates the size of the data bus. Microcontrollers can be classified as 8 – bit, 16 – bit or 32 – bit based on the bus width. Higher bus widths often result in better performance.
83
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
84
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
What is the difference between microprocessor,
microcontroller and microcomputer...?
85
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
MICROPROCESSOR MICROCONTROLLER
Microprocessor assimilates the function of a central processing unit (CPU) on to a single integrated circuit (IC).
Microcontroller can be considered as a small computer which has a processor and some other components in order to make it a computer.
Microprocessors are mainly used in designing general purpose systems from small to large and complex systems like super computers.
Microcontrollers are used in automatically controlled devices.
86
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
MICROPROCESSOR MICROCONTROLLER
Microprocessors are basic components of personal computers.
Microcontrollers are generally used in embedded systems
Computational capacity of microprocessor is very high. Hence can perform complex tasks.
Less computational capacity when compared to microprocessors. Usually used for simpler tasks.
A microprocessor based system can perform numerous tasks.
A microcontroller based system can perform single or very few tasks.
87
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
MICROPROCESSOR MICROCONTROLLER
Microprocessors have integrated Math Coprocessor. Complex mathematical calculations which involve floating point can be performed with great ease.
Microcontrollers do not have math coprocessors. They use software to perform floating point calculations which slows down the device.
The main task of microprocessor is to perform the instruction cycle repeatedly. This includes fetch, decode and execute.
In addition to performing the tasks of fetch, decode and execute, a microcontroller also controls its environment based on the output of the instruction cycle.
In order to build or design a system (computer), a microprocessor has to be connected externally to some other components like Memory (RAM and ROM) and Input / Output ports.
The IC of a microcontroller has memory (both RAM and ROM) integrated on it along with some other components like I / O devices and timers.
88
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
MICROPROCESSOR MICROCONTROLLER
The overall cost of a system built using a microprocessor is high. This is because of the requirement of external components.
Cost of a system built using a microcontroller is less as all the components are readily available.
Generally power consumption and dissipation is high because of the external devices. Hence it requires external cooling system.
Power consumption is less.
The clock frequency is very high usually in the order of Giga Hertz.
Clock frequency is less usually in the order of Mega Hertz.
89
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
MICROPROCESSOR MICROCONTROLLER
Instruction throughput is given higher priority than interrupt latency.
In contrast, microcontrollers are designed to optimize interrupt latency.
Have few bit manipulation instructions Bit manipulation is powerful and widely used feature in microcontrollers. They have numerous bit manipulation instructions.
Generally microprocessors are not used in real time systems as they are severely dependent on several other components.
Microcontrollers are used to handle real time tasks as they are single programmed, self sufficient and task oriented devices.
90
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
Microcontroller Vs Microprocessor
https://www.youtube.com/watch?v=bJY78VIaPCE
91
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
Embedded System Classifications
There are two main families of embedded system platforms:
MICROCONTROLLER Family
High Performance (System On Chip) SOC Platform Family
92
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
93
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
94
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
SOCs Examples95
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
microcontrollers and
SoC(System on Chip). https://www.youtube.com/watch?v=yTKg8LZoIVE
96
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
Conclusion
SOC is the full system, often the computer on a chip, or at least that is the
goal. They are very powerful compared to mere micro controllers. SOC may have large amount of memory, peripheral interfaces, radio/wireless connection.May be multicore.
Microcontrollers are processor chips with inbuilt peripheral
components, ADC,DAC and some memory. Designing a system is easier with these than with a raw microprocessor.
Microprocessors are raw processors with minimal ALU+ registers
without any peripheral components. You need to connect other chips to make it useful.
97
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
Von Neumann Vs Harvard
Earlier microprocessors made use of Von Neumann
architecture where the data and instructions
(programs) are stored in the same memory. Even
though this architecture is simple, there are many draw
backs. One of the major drawbacks is that instruction and
data cannot be accessed at the same time as they share
a single data bus.
This often degrades the overall performance of the
device. Later, Harvard architecture is introduced which
makes use of separate program and data memories
with separate buses so that both data and
instructions can be accessed at the same time. Later
Modified Harvard Architecture is developed in which the
program memory is accessed as if it were data memory
98
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
von Neumann
• Same memory holds data, instructions. • A single set of address/data buses between CPU and memory
99
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
Harvard Architecture
Separate memories for data and instructions.
Two sets of address/data buses between CPU and memory
100
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
Harvard architecture
Address bus
Data bus
Control bus
Address bus
Data bus
Control bus
CPU Address bus
Data bus
Control bus
DataMemory
CodeMemory
CPUCodeMemory
DataMemory
Von Neumann architecture
Von Neumann vs. Harvard architecture 101
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
pipeline102
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
Computer SystemsNot All Processors Are Created Equal
Newer machines use specialized processor chips that have been developed to speed up the processing of data.
CISC - Complex instruction set computer
Large instruction set, many formats
RISC - Reduced instruction set computer
Small instruction set, single or small variations informat
MPP - Massive parallel processing
Many CPUs working in parallel
103
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
CIS Vs RISC104
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
CIS Vs RISC105
https://www.facebook.com/groups/embedded.system.KS/
At mega 32
Atmel family Flash size
40 pins (4 port * 8)Vref>>>ADC
106
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
AVR different groups Classic AVR
e.g. AT90S2313, AT90S4433 Mega
e.g. ATmega8, ATmega32, ATmega128 Tiny
e.g. ATtiny13, ATtiny25 Special Purpose AVR
e.g. AT90PWM216,AT90USB1287
107
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
ATmega128
ATtiny44
Atmel groupFlash =128K
AtmelFlash =4K
AT90S4433
Atmel Classic group
Flash =4KTiny group
AVR part numbers108
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
ATMega32 Programmer Model: Memory1. 2KB SRAM
– For temporary data storage– Memory is lost when power is
shut off (volatile)– Fast read and write
2. 1KB EEPROM– For persistent data storage– Memory contents are retained
when power is off (non-volatile)– Fast read; slow write– Can write individual bytes
3. 32KB Flash Program Memory– Used to store program code– Memory contents retained when
power is off (non-volatile)– Fast to read; slow to write– Can only write entire “blocks” of
memory at a time– organized in 16-bit words
(16KWords)
109
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
ATMega32 Programmer Model: Memory
Type Flash RAM EEPROM
F_END Size, kB RAMEND Size, kB E_END Size, kB
Atmega8 $0FFF 8 $045F 1 $1FF 0.5
Atmega32 $3FFF 32 $085F 2 $3FF 1
Atmega64 $7FFF 64 $10FF 4 $7FF 2
Atmega128 $FFFF 128 $10FF 4 $FFF 4
• AVR microcontrollers are Harvardarchitecture. This means, that in thisarchitecture are separate memory types(program memory and data memory)connected with distinct buses. Such memoryarchitecture allows processor to accessprogram memory and data memory at thesame time. This increases performance ofMCU comparing to CISC architecture, whereCPU uses same bus for accessing programmemory and data memory.
• Each memory type has its own addressspace:
110
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
ATMega32 Programmer Model: Data Memory
• GPRs (general purposeregisters),
• Special FunctionRegisters (SFRs), and
• Internal data SRAM.
The data memory iscomposed of three parts:
111
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
References
https://docs.google.com/viewer?a=v&pid=sites&srcid=ZmtlLnV0bS5teXxyaWR6dWFuLXMtd2Vic2l0ZXxneDo2ODU0NzlkM2JkOTg4MjRk
http://www.avrprojects.net/index.php/avr-projects/sensors/38-humidity-and-temperature-sensor-dht11?showall=&start=1
http://www.cse.wustl.edu/~lu/cse467s/slides/dsp.pdf
http://www.avr-tutorials.com/
Microprocessor: ATmega32 (SEE3223-10) http://ridzuan.fke.utm.my/microprocessor-atmega32-see3223-10
http://circuitdigest.com/article/what-is-the-difference-between-microprocessor-and-microcontroller
http://cs4hs.cs.pub.ro/wiki/roboticsisfun/chapter2/ch2_7_programming_a_microcontroller
112
https://www.facebook.com/groups/embedded.system.KS/ https://www.facebook.com/groups/embedded.system.KS/
113