Introduction To AVR Microcontroller
Introduction To AVR Microcontroller
Microcontrollers
AVR Family , MSP430
Contents
• History of AVR Microcontrollers
• AVR family Overview
• Simplified Block Diagram
• Architecture
• General Purpose Registers
• Data Memory & I/O Memory
• AVR Status Register
• Program Counter & Program ROM Space
• Stack & Stack Pointer
•Addressing Modes
•Instruction Set
•ATmega32 Pin Diagram
•Delay in AVR & Pipelining
History & Features of AVR Microcontroller
• Basic architecture developed by students(Alf-Egil Bogen & Vegard Wollan) of
Norwegian Institute of Technology and then was bought and developed by
Atmel in 1996.
• AVR derived either as Advanced virtual RISC or Alf & Vegard RISC.
• Except AVR32 all AVR microcontrollers are 8 bit. i.e. they can process 8 bit at
a time.
Features:
• AVR is 8 bit RISC single chip microcontroller with Harvard architecture.
• On chip Programme ROM
• On chip Data RAM
• Data EEPROM
• Timers
• I/O Ports
• Additional Features like ADC, PWM & serial interfaces like USART, SPI, I2C, USB, CAN…
AVR Family Overview
• Classified in 4 broad groups:
• Classic
• Mega
• Tiny
• Special Purpose
• Classic(AT90Sxxxx): Original AVR now replaced by newer versions
• Mega(Atmega):
• Powerful and Popularly used. Atmega32 is most widely used device in this family.
• Programme Memory (4K to 256 K)
• Package:28 pins to 100 pins(DIP)
• Extensive Peripheral Set
• Extended instruction set (120 instructions)
Simplified Block Diagram
• AVR microcontrollers have RAM , Programme ROM and EEPROM.
• AVR have 8 Mbytes Programme ROM space but actual ROM size for
various family members varies from 1KB to 256 KB.
• AVR uses flash memory which can be developed fast (in few seconds
compared to 20 minutes for UV-EPROM)
• AVR has maximum of 64K Data RAM space. RAM space has three
components: general purpose registers , I/O memory and internal
SRAM.
• There are 32 general purpose registers in all AVRs bur I/O memory
and internal SRAM varies from chip to chip.
• It has small Data EEPROM varying from 0.5 KB to 4KB.
• Like other microcontrollers it has timers, interrupt, ports and other
supporting peripherals.
• I/O pins depends on total pins in package.AVR can have 3 to 86 pins
for I/O for 8 to 100 pin packaging devices respectively.
• Most AVRs have ADC, Timers and USART as standard peripherals.
• In AVR there is a 10 bit ADC and number of ADC channels varies upto
16 depending on package pins.
• AVR can have upto 6 timers apart from watchdog timer.
• Most of AVRs come with USART and have I2C and SPI(Serial
Periphearal Interface) bus but some may have USB or CAN as well.
Watchdog Timer in AVR
• What Is a Watchdog Timer?
• A watchdog timer is a specialized timer module that helps a
microprocessor to recover from malfunctions.
• If a watchdog timer reaches the end of its counting period, it resets the
entire processor system.
• Thus, a watchdog timer can be configured such that it will reach the
end of its counting period only if a processor failure has occurred, and
by forcing a system reset, the watchdog timer helps the processor to
escape from the failure mode and continue normal operation.
• WDT has two types :
• Windowed & Non-Windowed
• In Non-windowed WDT, there is
upper limit for count. If WDT is
provide service(attention) before
the upper limit is reached,
processor is not reset and
everything OK.
• For Windowed WDT, there is
lower limit of count apart from
upper limit.
• If WDT is attended after reaching
lower limit and before upper limit,
everything is OK.
• But if service is provided even
before reaching lower limit,
processor is reset.
General Purpose Resistors in AVR
• GPRs in CPU are used to store information temporarily.
• In AVR there are 32 general purpose registers. Most of the registers in AVR
are of 8 bits.
• Those are R0 to R31, are located in lowest location of Memory (RAM).
• They can be used to store data by
Any arithmetic or logical instruction.
AVR memory
• In AVR there is Code Memory Space & Data Memory Space
• Program is stored in Code Memory Space and Data in Data Memory
Space.
• Data Memory consist of three parts:
• GPRs; I/O memory and Internal Data SRAM.
• There are 32 GPRs and always occupies addresses from 00H to 1F H
• AVR has two memory space:
• Code Memory & Data Memory Space
• Code Memory Space: Code memory stores the program/instructions in
AVR.
• AVR flash memory is 16 bit wide. i.e. each memory location can store 16
bits data.
• Program counter is used by CPU to point to the address of next instruction
to be executed.
• Program Counter in AVR family can be upto 22 bits wide and can access
upto 4M locations.i.e. the address range for this can be from 000000 H to
3FFFFF H.
Data Memory
• It is internal Data SRAM. It is generally called ass scratch pad RAM.
• Each location can be directly accessed using its address.
• It is 8 bits i.e. 1 Byte wide and is used to store any 8 bit data in each
location.
I/O Memory(SFRs)
• I/O memory contains specific function registers like status registers,
timers, serial communication, I/O ports , ADC and so on.
• I/O memory has 8 bit wide registers.
• Most of AVR family members have at least 64 bytes of I/O meory. This
is called as standard I/O memory.
• For AVRs such as ATMega64, ATMega128 & ATMega256 have more
than 64 bytes of I/O memory and it is called as extended I/O memory.
AVR status register
31 GND GROUND