Lesson 2:
AVR Architecture
1
Outlines:
• Microcontroller families and AVR
• AVR Architecture
• ALU and General Purpose Registers
• Status Register
• Stack and Stack Pointer
• AVR Memories
2
Families of Microcontrollers
• A microcontroller family is defined as a group of
products that share the same basic internal
architectures and who are code compatible
• Manufactures usually define an architecture and
then make variants of that design producing a
family of products
• Code written for a member of a family should be
compatible with all other members of the same
family.
3
Major Microcontroller Families
• 8051(InteI)
• AVR(AtmeI)
• PIC(Microchip)
• MSP(Texas Instruments)
• ARM(ARM)
• 68HC08/11(M0toroIa)
• …..
4
AVR Families
• Atmel has a big world of 8-bit and 16-bit
MCU (Microcontroller unit) families.
– From lowest cost TinyAVR to high
performance megaAVR or XMEGA family.
– From 16MIPS to 32MIPS
– From 8 pins to 100 pins
– From 1KB to 64KB flash memories
5
Meet the AVR Family!
6
Introduction to AVR
7
AVR Core Architecture
8
AVR Harvard Architecture
• Separated program
memory (Flash) and data
memory (SRAM, EEPROM)
9
AVR RISC Architecture
• Single Cycle Instructions:
– 16MIPS with CPUclk 16MHz.
• Lots of registers (32).
• Every register an accumulator.
• 3 index register pairs
• Many register-to-register 10
operations
General Purpose Registers (R0-R31)
Pointer (Index) Registers
Three 16-bit address registers pairs of registers 26 to 31
are used for indirect addressing.
X (R27:R26), Y (R29:R28), Z (R31:R30).
Status Register (SREG)
• SREG is an 8-bit register that contains information about
the result of the most recently executed arithmetic
instruction.
• I: Global Interrupt Enable/Disable Flag, SREG7
• T: Transfer bit used by BLD and BST instructions, SREG6
• H: Half Carry Flag, SREG5
• S: N V, For signed tests, SREG4
• V: Two's complement overflow indicator, SREG3
• N: Negative Flag, SREG2
• Z: Zero Flag, SREG1
• C: Carry Flag, SREG0
Stack Pointer (SP)
• 16-bit stack pointer (SP) holds address
in data space of area to save function
call information.
Stack and SP in AVR
• The Stack in AVR grows downwards from higher
memory locations to lower memory locations.
• The Stack space in the data SRAM must be defined by
the program by initializing SP to point above $60.
• SP is decremented by one with the PUSH instruction,
and it is decremented by two with subroutine call or
interrupt.
• SP is incremented by one with the POP instruction, and
it is incremented by two return from subroutine RET or
return from interrupt RETI.
AVR Memory Types
• A computer system today may use one of
these options for program memory:
– ROM, EPROM (UV-EPROM, EEPROM),
NVRAM, Flash EPROM
• For Temporary storage there are two main
options: DRAM and SRAM.
• AVR memory space consists of EEPROM,
flash EPROM and SRAM.
AVR Memory Space
Non Volatile ROM Space
• Program Flash
– Code, and Constant Data
• EEPROM space
– For non-volatile but alterable data
Volatile RAM Space (Data Space)
• Working Registers
– 32 Registers includes 3 pointers
• I/O Register Space
– Includes “named” registers,
– Also called special function registers (SFRs)
• internal SRAM
– for Variables, Data and Stack space
17
Assignment 2.1
• Almost all AVR MCUs have the following
peripherals. What is the function of each one of
them, and what are the their control and status
registers
1. ADC
2. SPI
3. USART
4. TWI
5. Analog Comparator
6. Watchdog Timer
7. JTAG interface
18
Peripheral Function Associated
IO registers
exp EEPROM EEPROM memory that EECR,
storespermanent EEDR,
user data EEARL,
EEARH
1 ADC
2 SPI
3 USART
4 TWI
5 Analog Comparator
6 Watchdog Timer
7 JTAG interface
19
Assignment 2.2
• Select three members of each of the
Microcontroller families; AVR, PIC, 8051
and then make a comparison between
their features according to the table shown
in the next slide
20
Feature AVR PIC 8051
AVRmember1 AVRmember2 AVRmember3 PICmember1 PICmember2 PICmember3 8051member1 8051member2 8051member3
Max CPU
frequency
# cycles per
instruction
# instructions
Memory
architecture
(Harvard/
VonNeumann)
ISA architecture
(CISC or RISC)
Size of common
memory
Size of program
memory
Size of data
memory
# GPRs
size of a register
width of data bus
width of address
bus
IC package type
# pins
embedded
peripherals
(ADC, DAC,
timers, ...)
21