Вы находитесь на странице: 1из 2

ATMega128Microcontroller

ThistutorialshouldgiveanoverviewabouttheAtmelATMega128Microcontrollerandits features.ThisdeviceshouldbeusedasthemaincontrollerandCPUoftheCanSat. Microcontrollersingeneral: MicrocontrollerscanbethoughtasCPUsincomputers.Theycanexecutecommands,evaluate expressionsandthereforeabletorunsomecodetoperformvarioustasks.TheyconsistofCPU, memoryandintegratedperipherals.Themaindifferencesbetweencomputersand microcontrollersarespeedandinstructionset.Usuallymicrocontrollersaremuchslowerthana CPUinastateoftheartcomputer(theirclockfrequencyisintheorderof10MHz,whilethis parameterisintheGHzregionatcomputers).Theirinstructionsetisusuallysmaller(reduced) whichmeanstheycantexecuteverydifficultcommandsinonestep,butthisshouldbedone bybreakingdownthedifficultoperationsintoelementaryones,whichcanbeexecuted. Inordertooperateamicrocontrolleritshouldbeprogrammedwithsomecode,which describestheoperationindetailandthecorrespondingoutputresponsesfortheinput excitations.Thiscodeisstoredinthememory(usuallyflashmemory)ofthemicrocontroller andisexecutedrightafterpoweron.Ifthememoryisempty,thedevicewillnotexecute anything,thereforethismemoryalmostalwayscontainstheapplicationand/ortheboot loader. Bootloader:Thisisaspecialcode,runningonthemicrocontrolleranditinitializessomeofits interfaces(usuallycommunicationinterfaces)inordertoprovidesomebasicfunctionswhich arenecessaryduringdevelopment.InourcasethebootloadersetsuptheUARTinterfaceof themicrocontrollerandprovidesaccesstothememorywhichcanbeloadedwiththe operationalcodeafterstartup. Interrupts:ThesearespecialsignalswhichareusedtosigntotheCPUthatsomething happenedataperipheralanditneedsattention.Thistaskcouldbeperformedbypollingas well,butthatwouldbemoretimeconsuming.Therearetwotypesofinterruptsaccordingto theperipheralitcomesfrom.Ifitisfromanintegratedperipheralitiscalledinternalinterrupt, otherwiseexternalinterrupt.Ingeneralthereisnodifferencebetweenexecutingthese,andits doneasfollows:adevicegeneratesandinterruptrequest(usuallyjustcalledinterrupt),the CPUdecideswhetherthisinterruptshouldbeservedrightatthemomentorshouldwait.After acceptinganinterrupttheCPUhaltsitsoperationandjumpstothecodewhichisassignedto thecertaintypeofinterruptintheinterruptservicesregister.Aftercompletingtheoperationit returnstonormalmodeandcontinuestoexecutethegeneralcode,whereithalted.Interrupts canbeusedtoimplementeventdrivenbehavior.

ATMega128: TheprovidedmicrocontrollerisanATMega128withclockfrequencyof14.7456MHz, programmableflashmemoryof128kbyteandwithvarioustypesofintegratedperipherals(see below). ItcanbeprogrammedinC,usingthepreferredAVRStudiodevelopmentenvironmentwith WinAVRcompilerandlibraries.ThecodecanbedownloadedtoitviaRS232/UARTafterstart up.Thebootloaderinitializestheserialinterfaceofthemicrocontrollerandwaitsfor connectionwiththeAVRStudiosprogrammingtool(AVRProg)foraboutasecond.Ifthereis noconnectiontothetool,itcontinuestoexecutethemaincodefoundinthememory. Whileprogrammingthecompiled.hexfileshouldbedownloadedtotheflash. Peripherals:ThefollowingintegratedperipheralsareavailableintheATMega128,oronthe Crum128board. 1.GeneralI/Oports:Theseportscanbeprogrammedtooperateasdigitalinputsoroutputs. Thereisadatadirectionregisterforeachpinoftheseportswheretheintendedfeaturecanbe set.IftheDDRcontainslogicaloneforacertainpin,itwillbeanoutput,ifthecontentiszeroit isaninput.Furtheroperationsshouldregardthefunctionalityoftheport,thereforeaninput shouldonlybereadandtheoutputshouldonlybewritten(set). 2.UART:Serialportforgeneralpurposeandforprogrammingthemicrocontroller.Ithas2 separatedUARTs,UART0andUART1.Bothofthembydefaultare5VTTLlevelports.UART0is connectedtoaMAX3221levelconvertercircuitwhichconvertsittoatrueRS232levelUART. UART1isconnectedtoaCP2101circuitwhichconvertsthisporttoUSBinterface. 3.I2C:ThemicrocontrollerhasanI2Ccontrollerwhichcanbeprogrammedtoimplementabus. Forfurtherinformationonthisbusrefertothedatasheetofthedeviceandtheprovided tutorialaboutprotocols. 4.A/DConverter:SomeportscanworkasAnalogtoDigitalConvertersandtheresultofthe comparisoncanbeaccessedinternally.Thesamplerateandthereferencesignalcanbesetas well. 5.SPI:TheSerialPeripheralInterface(SPI)allowshighspeedsynchronousdatatransfer betweentheATmega128andperipheraldevices. 6.JTAG:ThisportofthemicrocontrollerfollowstheJTAGstandardsandthereforeitisintended tobeusedfortestingdebugging.

Вам также может понравиться