Topic 2 Introduction To AVR Architecture (ISMAIL - FKEUTM 2020)
Topic 2 Introduction To AVR Architecture (ISMAIL - FKEUTM 2020)
(AVR chip)
Ismail Ariffin
ECE, SKE, FE, UTM, Skudai, Johor
2019/2020
Contents
• AVR background history, AVR family groups,
AVR Architecture, Atmega32 programming
model
AVR
(Advanced Virtual RISC)
Introduction to AVR
• The AVR architecture was designed by two students Alf-Egil Bogen and
Vegard Wollan in Norway and then was bought and developed by
Atmel in 1996. Atmel Corporation is an American-based designer and
manufacturer of semiconductors, founded in 1984. The company
focuses on embedded systems built around microcontrollers.
• There are many kind of AVR microcontroller with different properties
such as 8-bit AVR and 32-bit AVR. Open AVR Studio to see list of AVR
microcontrollers.
• Except for AVR32 (32-bit microcontroller), AVRs are all 8-bit
microprocessors – the CPU can work only 8 bits of data at a time.
• Data larger that 8 bits has to be broken into 8-bit pieces to be
processed by the CPU.
• The AVR is a modified Harvard architecture machine where program
and data is stored in separate physical memory systems that appear in
different address spaces, but having the ability to read data items from
program memory using special instructions.
AVR Family Overview
• AVRs are generally classified into four groups:
o Classic AVR (AT90Sxxxx)
o This is the original AVR chip
o i.e. AT90S2313, AT90S4433
AVR Family Overview
o Mega AVR (ATmegaxxxx)
o These are powerful microcontrollers with more than 120
instructions
o Has lots of different peripheral capabilities, which can be
used in different designs.
o i.e. ATmega8, ATmega32, ATmega128
AVR Family Overview
o Tiny AVR (ATtinyxxxx)
o Has less instructions and smaller packages compared to
mega family.
o Can design systems with low cost and power consumption
using Tiny AVRs.
o i.e. ATtiny13, ATtiny25
AVR Family Overview
o Special purpose AVR
o The ICs of this group can be considered as a subset of other
groups.
o But their special capabilities are made for designing specific
applications such USB controller, CAN controller, LCD
controller, Zigbee, Ethernet controller, FPGA.
o i.e. AT90PWM216,AT90USB1287
Let’s get familiar with AVR part number
ATmega128
Atmel mega
ROM =128K
group
ATtiny44 AT90S4433
Atmel
Tiny ROM =4K Atmel Classic
ROM =4K
group group
ATmega32 vs ATmega16
ATmega32 ATmega16
Number of instructions 131 131
Flash program memory 32K 16K
Internal SRAM 2K bytes 1K bytes
EEPROM 1K bytes 512 bytes
External memory none none
General-purpose 8-bit registers 32 32
IO ports 4 4
Serial interfaces SPI, USART, Two-wire SPI, USART, Two-wire
Timers two 8-bit, one 16-bit two 8-bit, one 16-bit
PWM channels 3 4
Analogue comparator, Analogue comparator,
ADC
8-channel 10-bit ADC 8-channel 10-bit ADC
Interrupt vectors 21 21
ATMega32 Pin out & Descriptions
Clears all the
registers and
restart the
execution of
program -reset
Provides supply
voltage to the chip.
Port
It should be B Port A
connected to +5 -
vcc Reference voltage
for ADC-aref
These pins are
used to connect
external crystal or Supply voltage for
RC oscillator -xtal ADC and portA.
Port Cit to VCC -
Connect
Port D acc
Module 2/11
ATMega32 Pin out & Descriptions
Module 2/12
Atmega32 Pinout
Module 2/13
ATMega32 Pin out & Descriptions
Mega32/Mega16
(XCK/T0) PB0 PA0 (ADC0)
(T1) PB1 PA1 (ADC1)
(INT2/AIN0) PB2 PA2 (ADC2)
(OC0/AIN1) PB3 PA3 (ADC3)
(SS) PB4 PA4 (ADC4)
(MOSI) PB5 PA5 (ADC5)
(MISO) PB6 PA6 (ADC6)
(SCK) PB7 PA7 (ADC7)
PINA
PORTB
DDRB
PINB
RESET DDRA AREF
PORTA
VCC AGND
PORTC
GND DDRC AVCC
PINC
XTAL2 PC7 (TOSC2)
XTAL1 PC6 (TOSC1)
(RXD) PD0 PC5 (TDI)
(TXD) PD1 PC4 (TDO)
(INT0) PD2 PC3 (TMS)
(INT1) PD3 PC2 (TCK)
(OC1B) PD4 PC1 (SDA)
(OC1A) PD5 PC0 (SCL)
(ICP) PD6 PD7 (OC2)
Module 2/14
ATMega32 Pin out & Descriptions
Module 2/15
ATMega32 Pin out & Descriptions
Defining a pin as either Input or Output – The DDRx Registers
Module 2/16
ATMega32 Pin out & Descriptions
Case 1 : To make a pin go high or low ( if it is an output pin)- Data Register PORTx
Module 2/17
ATMega32 Pin out & Descriptions
The PINx register gets the reading from the input pins of the MCU
Module 2/18
ATMega32 Pin out & Descriptions
vcc
1 = Close
PORTx.n 0 = Open
pin n of
port x PINx.n
Module 2/19
ATMega32 Pin out & Descriptions
DDRx
DDRx.n 0 1
PORTx
PORTx.n high impedance Out 0
0
1 pull-up Out 1
PINx.n
Module 2/20
AVR Architecture
AVR Architecture
Module 2/22
Definition of AVR architecture
• What is AVR?
– AVR, an acronym of Advanced Virtual RISC, is a
microcontroller featured in ATMEL based
embedded system.
• What is AVR architecture and organization?
– a set of hardware units featured in AVR
– CPU, registers, memory
– Program memory and data memory use separated
busses to CPU.
AVR Architecture
o AVR uses Harvard architecture, that has separate buses for the
code and data memory.
o Two kind of busses in AVR;
o Program Bus – provide access to Program Flash ROM.
o Data Bus – to bring data to the CPU.
AVR SYSTEM BUSES
• Address Bus
– 16 bit Unidirectional line
– carry address to select data storage location in the
system
• Data Bus
– 8-bit Bidirectional line
– channel to carry data in and out the processor
• Control Bus
– Unidirectional line (majority)
– Bidirectional (minor)
– carry control signal to acknowledge processor
operation activity, for examples: read, write
AVR CPU
2/15/2020 26
CPU internal activity
• Fetch instruction from memory
– Code in IR register
Fetch
• Decode instruction
– Interpret & Enable the required
circuits for operation
• Fetch data (if applicable) Execute Decode
– Data from resources
• Execute instruction
Module 2/30
General Purpose Register in AVR
o AVR microcontrollers have many registers for arithmetic and
logic operations.
o In CPU, registers are used to store information temporarily.
o That information could be;
o A byte of data to be processed
o And address pointing to the data to be fetched.
o The vast majority of AVR registers are 8-bit registers because in
AVR only one data type: 8-bit.
MSB LSB
o With an 8-bit data type, any data larger than 8 bits must be
broken into 8-bit chunks before it is processed.
General Purpose Register in AVR
o In AVR there are 32 general purpose
registers.
o They are R01-R31 and are located in
the lowest location of memory
address.
o To understand of the purpose of
general purpose registers, two
simple instructions LDI and ADD is
used as example.
o LDI R16,10
o Load register R16 with value 10
o ADD R2,R18
o Add data in R2 with data in R18 and
save result in R2
AVR Memory
• Flash: Machine
instructions (program) go
here
• SRAM: For run time data
– Note bus independence for
data and instructions
• EEPROM: Secondary
storage
– EEPROM and Flash
memories have a limited
lifetime of erase/write
cycles
1 2 3 4 5 6 7 8
Module 2/37
ATMega32 Programmer Model: Internal SRAM
Module 2/38
AVR DATA TYPE
Data Type Binary Signed Decimal Hexadecimal Binary
Coded
Decimal
(BCD)
Digit 0 and 1 0 and 1 0 to 9 0 to 9,A to F 0 and 1