Chapter 1
Introduction to AVR
1
Topics
www. Micro Digital Ed. com
BIHE university
• Microcontrollers vs. Microprocessors
• Most common microcontrollers
• AVR Features
2
General Purpose Microprocessors vs.
www. Micro Digital Ed. com
Microcontrollers BIHE university
• General Purpose Microprocessors
General I/O Serial
Purpose RAM ROM Timer
Port Port
Micropro
cessor
(CPU) Buses
• Using Microprocessors, we must add ROM, RAM, I/O and timers to
make the system functional
• Although this makes the system bulkier and more expensive, it has
the advantage of versatility giving the designer more flexibility to
decide the amount of resources needed for a given task
3
General Purpose Microprocessors vs.
www. Micro Digital Ed. com
Microcontrollers BIHE university
• Microcontrollers
Microcontroller
I/O Serial
RAM ROM Timer
Port Port
CPU
Buses
4
Single Chip microcontrollers
• Typical elements found in a μcontroller include:
– CPU (typically 4 – 64 bit word size) – also as
multicores.
– Memory (typically a few hundred Bytes to many
MBytes) as RAM, ROM, EPROM and/or Flash.
– Clock generator.
– Timers and general interrupt logic.
– General purpose digital I/O lines – often combined with
PWM generators, counters, watchdog- or timer-
triggers.
– A/D and D/A converters (typically 6-12 bit).
– Communication channels: Ethernet, UART, I2C, Fast
serial, CAN-bus etc.,
5
Criteria for choosing a Microcontroller
• The important features that influences the choice of a
Microcontroller system :
– CPU processing power
• Word length (8, 16, 32 bits): important for precision of calculations
and memory access
• Speed: The highest speed the microcontroller supports and
Transfer rates between CPU memories and I/O.
• Number of registers: The more registers we have, the more
intermediate computation results can be held on the CPU (without
the need to access main memory), the more faster processing
• Power consumption
• Cost per Unit
– Storage capabilities and I/O interfaces:
• RAM, ROM, EPROM and auxiliary storage unit .
• Number of I/O pins and timers in the Chip.
– Availability of development tools (compiler, debugger, etc.)
6
Review questions
www. Micro Digital Ed. com
BIHE university
1. Which of the following is true?
A. Microcontrollers have CPU, RAM, ROM, I/O ports, and timers
embedded in one chip
B. Microprocessors integrate memory and many I/O peripherals within a
single IC
C. If using Microprocessors, we must add ROM, RAM, I/O, and timers to
make the system functional
D. A and C
2. Which of the following is true?
A. Microprocessors are more expensive than Microcontrollers as
generally they use complex CPUs to deal with wide task varieties.
B. A designer can add memory, I/Os, and timers to Microcontrollers
C. Microcontrollers are ideal for applications where cost and space are
critical
D. A and C
7
Review questions
www. Micro Digital Ed. com
BIHE university
1. Which of the following is true ?
A. The CPU processing power, storage capabilities, and I/O interfaces are
important features that influences the choice of a microcontroller
system.
B. The CPU processing power is the only important feature that
influences the choice of a microcontroller system.
C. Microprocessors have fixed amount of ROM, RAM, I/O and timers
D. B and C
2. Which of the following is true ?
A. Using Microcontrollers, the address, control, and data buses are
generally available to the designer.
B. The more registers we have for a CPU, the more slower the
processing is.
C. Microcontrollers have CPUs with only 8-bit word length
D. None of the above
8
Most common microcontrollers
www. Micro Digital Ed. com
BIHE university
• 8-bit microcontrollers
– AVR
– PIC
– MC68HC05
– 8051
• 32-bit microcontrollers
– ARM
– AVR32
– PIC32
9
Review Questions
10
Review Question Answers
11
The AVR Microcontroller
AVR stand for ?
Advanced Virtual RISC, (formerly: Alf and Vegard's RISC)
The founders are Alf Egil Bogen and Vegard Wollan
two students at Norwegian Institute of Technology (NTH) and
further refined and developed at Atmel Norway, the Atmel
company founded by the two chip architects.
RISC : Reduced Instruction Set Computer
CPU design with a reduced instruction set
Fast Execution of Instructions
Cheaper to design and produce
AVR : High-performance low power 8-bit
microcontrollers based on RISC Architecture
12
The AVR Architecture
• The AVR is a Harvard architecture CPU.
– Harvard Architecture
• Computer architectures uses physically separate storage and signal
pathways for their instructions and data.
– CPU can read both an instruction and data from memory at the same
time, makes it faster.
– Von Neumann architecture
• Same signal pathways for instruction and data transfers
– CPU can Read an instruction or data from/to the memory.
13
AVR internal architecture
www. Micro Digital Ed. com
BIHE university
RAM EEPROM Timers
PROGRAM
ROM
Program
Bus Bus
CPU
Interrupt Other
OSC Ports
Unit Peripherals
I/O
PINS
14
The AVR Architecture
• Single clock cycle per instruction execution
– Compared to PIC : 4 clock cycles per instruction
– One MIPS (mega instructions per second) per MHz
– Up to 20 MHz
– 8 MHz = 8Mips
• “LOAD" and "STORE“ instructions to access memory
• The AVR includes 32 8-bit General purpose registers (R0 to
R31) and 3 SPECIAL purpose registers
– Special purpose : Program counter, stack pointer, and status.
– 3 index register pairs : X (r27:r26), y (r29:r28), z (r31:r30)
– Register & IO are mapped in SRAM space
15
The AVR Memory Architecture
Two separate memories:
Data memory :
Store temporary data for variables
Also used for stack operation
Registers reassigned the 32 Data space addresses ($00- $1F),
I/O memory space
Contains 64 addresses
Accessed as the Data space location $20 - $5F.
Program Memory (Flash and EEPROM Memory)
Flash:
Opcodes, static data tables, interrupt function addresses
EEPROM:
Store configuration data
16
The AVR Memory Architecture
www. Micro Digital Ed. com
BIHE university
17
Review questions
www. Micro Digital Ed. com
BIHE university
1. Which of the following is true ?
A. Von Newman CPU architectures uses physically separate data,
address and control buses for program memory and data memory
B. The AVR can read both an instruction and data from memory at the
same time.
C. AVR microcontrollers are faster than PIC.
D. B and C
2. Which of the following is true ?
A. In AVR, the data memory includes 32 general registers, 64 I/O
registers and SRAM.
B. In AVR, the program memory bus has 16 bits data width and the data
memory bus has 8 bits data width.
C. In AVR, both program and data memories have 8 bits width data
buses.
D. None of the above
18
Let’s get familiar with the AVR part numbers
www. Micro Digital Ed. com
BIHE university
ATmega128
Atmel group
Flash =128K
ATtiny44 AT90S4433
Atmel
Tiny Flash =4K Atmel Classic
Flash =4K
group group
19
ATMEGA 8 AVR Microcontroller
• 8K bytes of Flash
• 512 bytes EEPROM
• 1K bytes SRAM
• 23 General Purpose I/O
(GPIO) lines
• Timers : 8bits (2), 16
bit (1)
• 3 PWM channels
• 8-channel 10-bit ADC
• 1 UART and 1 SPI serial
interfaces
In other models (e.g. ATmega16 & ATmega32 there is one additional port (PORT A)
20
RECOMMENDED PROBLEMS
PROBLEMS HIGHLIGHTED IN RED
www. Micro Digital Ed. com
BIHE university
CHAPTER-1 [Introduction to AVR]
Problems:
S1.1 (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13).
S1.2 (14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28).
21