Embedded Systems Design with the Atmel AVR Microcontroller Part I Synthesis Lectures on Digital Circuits and Systems Editor MitchellA.Thornton,SouthernMethodistUniversity EmbeddedSystemsDesignwiththeAtmelAVRMicrocontroller–PartI StevenF.Barrett 2009 EmbeddedSystemsInterfacingforEngineersusingtheFreescaleHCS08Microcontroller II:DigitalandAnalogHardwareInterfacing DouglasH.Summerville 2009 DesigningAsynchronousCircuitsusingNULLConventionLogic(NCL) ScottC.Smith,JiaDi 2009 EmbeddedSystemsInterfacingforEngineersusingtheFreescaleHCS08Microcontroller I:AssemblyLanguageProgramming DouglasH.Summerville 2009 DevelopingEmbeddedSoftwareusingDaVinci&OMAPTechnology B.I.(Raj)Pawate 2009 MismatchandNoiseinModernICProcesses AndrewMarshall 2009 AsynchronousSequentialMachineDesignandAnalysis:AComprehensiveDevelopment oftheDesignandAnalysisofClock-IndependentStateMachinesandSystems RichardF.Tinder 2009 AnIntroductiontoLogicCircuitTesting ParagK.Lala 2008 iv PragmaticPower WilliamJ.Eccles 2008 MultipleValuedLogic:ConceptsandRepresentations D.MichaelMiller,MitchellA.Thornton 2007 FiniteStateMachineDatapathDesign,Optimization,andImplementation JustinDavis,RobertReese 2007 AtmelAVRMicrocontrollerPrimer:ProgrammingandInterfacing StevenF.Barrett,DanielJ.Pack 2007 PragmaticLogic WilliamJ.Eccles 2007 PSpiceforFiltersandTransmissionLines PaulTobin 2007 PSpiceforDigitalSignalProcessing PaulTobin 2007 PSpiceforAnalogCommunicationsEngineering PaulTobin 2007 PSpiceforDigitalCommunicationsEngineering PaulTobin 2007 PSpiceforCircuitTheoryandElectronicDevices PaulTobin 2007 PragmaticCircuits:DCandTimeDomain WilliamJ.Eccles 2006 PragmaticCircuits:FrequencyDomain WilliamJ.Eccles 2006 v PragmaticCircuits:SignalsandFilters WilliamJ.Eccles 2006 High-SpeedDigitalSystemDesign JustinDavis 2006 IntroductiontoLogicSynthesisusingVerilogHDL RobertB.Reese,MitchellA.Thornton 2006 MicrocontrollersFundamentalsforEngineersandScientists StevenF.Barrett,DanielJ.Pack 2006 Copyright© 2010byMorgan&Claypool Allrightsreserved.Nopartofthispublicationmaybereproduced,storedinaretrievalsystem,ortransmittedin anyformorbyanymeans—electronic,mechanical,photocopy,recording,oranyotherexceptforbriefquotationsin printedreviews,withoutthepriorpermissionofthepublisher. EmbeddedSystemsDesignwiththeAtmelAVRMicrocontroller–PartI StevenF.Barrett www.morganclaypool.com ISBN:9781608451272 paperback ISBN:9781608451289 ebook DOI10.2200/S00138ED1V01Y200910DCS024 APublicationintheMorgan&ClaypoolPublishersseries SYNTHESISLECTURESONDIGITALCIRCUITSANDSYSTEMS Lecture#24 SeriesISSN SynthesisLecturesonDigitalCircuitsandSystems Print1932-3166 Electronic1932-3174 Embedded Systems Design with the Atmel AVR Microcontroller Part I Steven F.Barrett UniversityofWyoming SYNTHESISLECTURESONDIGITALCIRCUITSANDSYSTEMS#24 M &C Morgan &cLaypool publishers ABSTRACT This textbook provides practicing scientists and engineers an advanced treatment of the Atmel AVR microcontroller.This book is intended as a follow on to a previously published book,titled “Atmel AVR Microcontroller Primer: Programming and Interfacing.’’ Some of the content from thisearliertextisretainedforcompleteness.Thisbookwillemphasizeadvancedprogrammingand interfacingskills.Wefocusonsystemleveldesignconsistingofseveralinteractingmicrocontroller subsystems.The first chapter discusses the system design process.Our approach is to provide the skillstoquicklygetuptospeedtooperatetheinternationallypopularAtmelAVRmicrocontroller line by developing systems level design skills. We use the Atmel ATmega164 as a representative sampleoftheAVRline.Theknowledgeyougainonthismicrocontrollercanbeeasilytranslatedto everyothermicrocontrollerintheAVRline.Insucceedingchapters,wecoverthemainsubsystems aboardthemicrocontroller,providingashorttheorysectionfollowedbyadescriptionoftherelated microcontrollersubsystemwithaccompanyingsoftwareforthesubsystem.Wethenprovideadvanced examples exercising some of the features discussed. In all examples, we use the C programming language.The code provided can be readily adapted to the wide variety of compilers available for the Atmel AVR microcontroller line. We also include a chapter describing how to interface the microcontroller to a wide variety of input and output devices. The book concludes with several detailedsystemleveldesignexamplesemployingtheAtmelAVRmicrocontroller. KEYWORDS Atmelmicrocontroller,AtmelAVR,ATmega164,microcontrollerinterfacing,embed- dedsystemsdesign ix Contents Acknowledgments ...............................................................xv Preface.........................................................................xvii 1 EmbeddedSystemsDesign........................................................1 1.1 Whatisanembeddedsystem? ...............................................1 1.2 Embeddedsystemdesignprocess.............................................1 1.2.1 ProblemDescription 3 1.2.2 BackgroundResearch 3 1.2.3 Pre-Design 3 1.2.4 Design 5 1.2.5 ImplementPrototype 6 1.2.6 PreliminaryTesting 7 1.2.7 CompleteandAccurateDocumentation 7 1.3 Example:KinesiologyandHealthLaboratoryInstrumentation..................7 1.4 Summary.................................................................14 1.5 ChapterProblems.........................................................14 References......................................................................14 2 AtmelAVRArchitectureOverview................................................15 2.1 ATmega164ArchitectureOverview.........................................15 2.1.1 ReducedInstructionSetComputer—RISC 15 2.1.2 AssemblyLanguageInstructionSet 16 2.1.3 COperatorSize 17 2.1.4 BitTwiddling 17 2.1.5 ATmega164ArchitectureOverview 18