You are on page 1of 27

AVR Atmega

BABotre,Scientist AgriElectronicsGroup, CSIRCentral lElectroEngineering l nicsResearch hInstitute, CSIRCEERI,Pilani. ;bbotre@gmail.com g Email:bhau@ceeri.ernet.in;

Microprocessor and Microcontroller

Von Neumann Architecture and Harvard Architecture

RISC architecture
Atmel A lused d3methods h d toincrease i the h processing i powerof fAVR
Increasetheclockfrequency UsetheHarvardArchitecture UsetheRISCarchitecture Morenumberofcomplexinstructions Someofthemneverusedbyprogrammers Hugecostofimplementingalargenumberofinstructions Mostoftheportionsofthetransistorsonchipareusedbytheinstruction decoders Designersthinkofsimplifyingandreducingthenumberofinstructions Asthisconceptdeveloped,theresultingprocessorscametobeknownasRISC (Reducedinstructionsetcomputers)

CSICarchitecture(Complexinstructionsetcomputer):

RISCarchitecture:

RISC Features
RISCprocessorsh haveafi fixed dinstruction i t ti size. i I InCSICmicrocontroller i t ll instructions i t ti can be1,2,or3bytes.InaRISCarchitecture,thesizeofallinstructionsisfixed.TheCPU candecodetheinstructionsquickly. Largenumberofregisters, registers advantageisthatitavoidstheneedforalargestackto storeparameters.AllRISCarchitectureshaveatleast32registers. RISCprocessorshaveasmallinstructionset.BasicinstructionssuchasADD,SUB, MUL,LOAD,STORE,AND,OR,EXOR,CALLJUMPandsoon.Makesprogrammersjob moretedious,therefore,RSICismorecommonlyusedinhighlevellanguage environmentsuchasC programmingratherthanassemblylanguageenvironment. 95%ofallinstructionsareexecutedwithonlyonclockcycle,incontrasttoCISC instructions. RISCprocessorshaveseparatebusesfordataandcode.Useofseparatebusesfor codeanddataoperandsisreferredtoasHarvardarchitecture. Duetosmall llsetof finstructions,areimplemented l dusingthe h hardwire h d method. h d HardwiringofRISCinstructionstakesonly10%ofthetransistors. RSICusesloadstorearchitecture.

Simplified view of an AVR microcontroller

ATmega16 Block Diagram


CPU PORTB PORTA ADC

PORTD

Serial

Interrupts Timers

PORTC

AVR microcontroller i t ll
Basic architecture of AVR designed by 2 students of Norwegian Institute of Technology, Alf-Egil Bogen and Vegard Wollan Bought and developed by Atmel in 1996 Different meanings of AVR: Atmel it is a product name It may be Advance Virtual RISC or Alf and Vegard RISC (name of the AVR designers)

AVR Features
8bitRISCsinglechipmicrocontroller H Harvard d A Architecture hi Onchipprogram(code)ROM DataRAM DataEEPROM, TimersandI/Oports ADC PWM ADC, DifferentkindsofserialinterfacessuchasUSART,SPI,I2C (TWI),CAN,USBandsoon

AVR Features
AVRmicrocontrollerprogramROM
8MofprogramROMspace,notallfamilymemberscomewiththatmuch ROMinstalled ProgramROMsizevaryfrom1Kto256K UseonchipFlashmemoryforprogramstorage Flash as memory e o yis sideal dea for o fast astdevelopment de e op e t ca canbee erased asedinseco seconds ds

AVRmicrocontrollerdataRAMandEEPROM
RAMspace datastorage Maximumof64Kbytes y ofdataRAMspace p NotallfamilymemberscomewiththatmuchRAM DataRAMspace 3components:generalpurposeregisters(GPRs),I/O memoryandinternalSRAM 32GPRsinallAVRs SRAMsizeandI/Omemoryssizevariesfromchiptochip EEPROMtostorecriticaldata

AVR Features
AVRmicrocontrollerI/Opins
3to86pinsforI/O NumberofI/Opinsdependsonthenumberofpinsinthepackage itself NumberofpinsforAVRpackage 8to100 8pinAT90S2323 3I/O 100 00p pinAtmega t ega1280 80 86I/O /O

AVRmicrocontrollerperipherals
MostoftheAVRcomeswithADC,timersandUSARTsasstandard p p peripherals ADC 10bit,numberofADCchannelsvariesandcanbeupto16 Upto6timersalongwithwatchdogtimer USART connecttheAVRbasedsystemtoserialportssuchasthe COMportofx86PC AlsocomewithI2CandSPI,someofthemhaveUSBandCANbuses

Criteria for choosing g a microcontroller


Meetingthecomputingneedsofthetask:efficientlyandcost effectively
8bit,16bit,32bitcanhandlethecomputingneedsofthetask,speed, packaging(space,assemblingandprototyping),powerconsumption,amountof RAMandROMonchip, p,numberofI/O / p pins, ,timersonthechip, p,easeofupgrade pg andcostperunit

Availabilityofdevelopmenttools:softwareandhardware
Availabilityofanassemblers,adebugger,acodeefficientC languagecompiler, anemulator,technicalsupportandthirdpartyvendorsupportforthechip

Wideavailabilityandreliablesourcesofmicrocontroller
readyavailabilityinneededquantitiesbothnowandinthefuture

Classifiedinto4g groups: Purpose p Classic, ,Mega, g ,Tiny yandSpecial p p ClassicAVR(AT90Sxxxx) OriginalAVRchip MegaAVR(ATmegaxxxx)
Powerfulmicrocontrollerwithmorethan120instructionsandlots ofdifferentperipheralcapabilities Programmemory 4Kto256Kbytes Package:28to100pins Extensiveperipheralset Extensiveinstructionset

AVR Family overview

AVR Family overview


TinyAVR(ATtinyxxxx)
Lessinstructionsandsmallerpackages Designsystemswithlowcostsandpowerconsumptions Programmemory:1Kto8Kbytes Packages:8to28pins Limitedperipheralset Limitedinstructionset

AVR Family overview


SpecialpurposeAVR
Consideredasasubsetofothergroups Specialcapabilitiesmadefordesigningspecificapplications Someofcapabilitiesare:USBcontroller,CANcontroller,LCD controller,Zigbee,Ethernetcontroller,FPGAandadvanced PWM

AVR Architecture and instruction set


Generalpurposeregister(GPRs)in theAVR
Toprograminassemblylanguage, understandtheregistersand architectureofaCPUandtherolethey playinprocessingdata. 32Generalpurposeregisters,R0 R31, locatedinthelowestlocationof memoryaddress. GPRsinAVR sameastheaccumulator inothermicroprocessors. Usedbyallarithmeticandlogic instructions. LDIRd,k;loadRdwithimmediatevaluek,d 16to31 LDIR20,0x25;loadR20with0x25

AVR GPRs and ALU

ADDinstruction
ADDRd,Rr ;addRrtoRdandstoretheresultinRd

LDIR16 R16,0x25 LDIR17,0x33 ADDR16,R17

;loadR16with0x25 ;loadR17with0x33 ;addR16toR17andstoreresultatR16

Data memory for AVR

Data memory for AVR


GPRs(Generalpurposeregisters)
TheGPRsuse32bytesofdatamemoryspace Addresslocation0x00 0x1Finthedatamemoryspace

I/Omemory(SFRs)
Dedicatedtospecificfunctionssuchasstatusregister,timers,serial communication I/Oports communication, ports,ADCandsoon ThefunctionofeachI/OmemorylocationisfixedbyCPUdesigneratthe timeofdesign. Thenumber Th b of fl locations ti i inth thed data t memoryfor f I/Omemorydepends d d onthe th pinnumbersandperipheralfunctionssupportedbythatchip TheAVRhaveatleast64bytesofI/Omemorylocations ItisalsocalledstandardI/Omemory

InternaldataSRAM
UsedforstoringdataandparametersbyAVRprogrammersandCcompilers. compilers Itisgenerallycalledscratchpad

Data memory size for various AVR chips

Using instructions with the data memory


LDSinstruction(loaddirectfromdataspace)
LDSRd,k LDSR0,0x300 LDSR1,0x302 ADDR0 R0,R1 ;loadRdwiththecontentsoflocationk ;kaddressbetween0x0000to0xffff ;R0=contentsoflocation0x300 ;R1=contentsoflocation0x302 ;addR0andR1

STSinstruction
STSk,Rr LDI R20,0x99 STS0x200 0x200,R20 STS0x201,R20 STS0x202,R20

(storedirecttodataspace)
;storeregisterintothelocationk ;loadR20with0x99 ;storeR20inloc0x200 ;storeR20inloc0x201 ;storeR20inloc0x202

;kisaddressfrom0x0000to0xffff

Using instructions with the data memory


INinstruction(INfromI/Olocation)
INRd,A INR19,0x10 INR19,PIND ;loadanI/OlocationtotheGPR(0<=d<=31) ;(0<=A<=63) ;loadR19withlocation0x10 ;loadR19withPIND

OUTinstruction
OUTA,Rr LDIR20,0xE2

(OUTtoI/Olocation)
;storeregistertoI/Olocation ;loadR20with0xE2

OUTPORTA,R20;outR20toPORTA

MOVinstruction
MOVRd Rd,Rr R ;Rd Rd=Rr R MOVR10,R20 ;R10=R20

ALU instructions

Status register

Why using ATmega16


To support different design requirements and reduce cost, the Atmel AVR family has many microcontrollers: ATmega8515 ATmega16 etc. ATmega8515, etc Microcontrollers in the 8-bit AVR family share a similar instruction set and architecture. The ATmega16 has components that are useful for typical microcontroller applications, such as
Analog-to-digital converter, PWM, USART Timers

Comparison between ATmega8515 and ATmega16


Number of instructions Flash program memory internal SRAM EEPROM External memory General-purpose 8-bit registers IO ports Serial interfaces Timers PWM channels h l ADC Interrupt p Vectors ATmega8515 AT 8515 130 8K 512 bytes 512 bytes upto 64K bytes 32 5 SPI, USART 1: 8-bit, 1: 16-bit 3 Analogue comparator 17 ATmega16 AT 16 131 16K 1kbytes 512 bytes none 32 4 SPI, USART, Two-wire 2: 8-bit, 1: 16-bit 4 Analogue comparator, 8 channel 10 bit ADC 21

ATmega16 pin Diagram

You might also like