INTRODUCTIONTOMICROCONTROLLERSWhataremicrocontrollers?Theyarewhattheirnamesuggests.Todaytheycanbefoundinalmostanycomplexelectronicdevice-fromportablemusicdevicestowashingmachinestoyourcar.Theyareprogrammable,cheap,small,canhandleabuse,requirealmostzeropower,andtherearesomanyvariatiestosuiteveryneed.Thisiswhatmakesthemsousefulforrobotics-theyareliketinyaffordablecomputersthatyoucanputrightontoyourrobot.AugmentedMicrocontrollersandDevelopmentBoardsInapuresense,amicrocontrollerisjustanIC(integratedcircuit,orablackchipthingwithpinscomingoutofit.Howeveritisverycommontoaddadditionalexternalcomponents,suchasavoltageregulator,capacitors,LEDs,motordriver,timingcrystals,rs232,etctothebasicIC.Formally,thisiscalledanaugmentedmicrocontroller.Butinreality,mostpeoplejustsay'microcontroller'evenifithasaugmentation.OtherabbreviationswouldbeuncontrollerandMicroControllerUnit(MCU.UsuallywhenIsay'microcontroller'whatIreallymeantosayis'augmentedmicrocontroller.'Asabeginneritisprobablybesttobuyanaugmentedmicrocontroller.Why?Wellbecausetheyhavetonsofgoodiesbuiltontothemthatareallassembledanddebuggedforyou.Theyalsooftencomewithtechsupport,samplecode,andacommunityofpeopletohelpyouwiththem.Mymicrocontrollerpartslistshowsthemorepopulartypesthatyoucanbuy.Theytendtocostfrom$30to$150dependingonthefeatures.Thiswillgiveyouagoodintroductorytomicrocontrollerprogrammingwithouthavingtobeconcernedwithallthetechnicalstuff.Inthelongtermhoweveryoushouldbuildyourownaugmentedmicrocontrollersothatyoumayunderstandthembetter.Theadvantagetomakingyourownisthatitwillprobablycostyoufrom$10-$30.Betweengettingafullaugmentedboardanddoingityourselfissomethingcalledadevelopmentboard.Theseboardscomepre-augmentedwithjustthebarebasicstogetyoustarted.Theyaredesignedforprototypingandtestingofnewideasveryquickly.Theytypicallycostbetween$15and$40.WhatcomeswiththeIC?Thereisahugevarietyofmicrocontrollersoutonthemarket,butIwillgooverafewcommonfeaturesthatyouwillfindusefulforyourroboticsproject.Forrobots,oreimportantthananyotherfeatureonamicrocontroller,istheI/Oports.Inputportsareusedfortakinginsensordata,whileoutputisusedforsendingcommandstoexternalhardwaresuchasservos.TherearetwotypesofI/Oports,analoganddigital.AnalogInputPortsAnalogPortsarenecessarytoconnectsensorstoyourrobot.Alsoknownasananalogtodigitalconverter(ADC,theyrecieveanalogsignalsandconvertthemtoadigitalnumberwithinacertainnumericalrange.Sowhatisanalog?Analogisacontinuousvoltagerangeandistypicallyfoundwithsensors.Howevercomputerscanonlyoperateinthedigitalrealmwith0'sand1's.Sohowdoesamicrocontrollerconvertananalogsignaltoadigitalsignal?First,theanalogismeasuredafterapredefinedperiodoftimepasses.Ateachtimeperiod,thevoltageisrecordedasanumber.Thisnumberthendefinesasignalof0'sand1'sasshown:Theadvantageofdigitaloveranalogisthatdigitalismuchbetterateliminatingbackgroundnoise.Cellphonesarealldigitaltoday,andalthoughthedigitalsignalislessrepresentativethanananalogsignal,itismuchlesslikelytodegradesincecomputerscanrestoredamageddigitalsignals.Thisallowsforacleareroutputsignaltotalktoyourmomorwhoever.MP3'sarealldigitaltoo,usuallyencodedat128kbps.Higherbitratesobviouslymeanhigherqualitybecausetheybetterrepresenttheanalogsignal.Buthigherbitratesalsorequiremorememoryandprocessingpower.Mostmicrocontrollerstodayare8bit,meaningtheyhavearangeof256(2^8=256.Thereareafewthatare10bit,12bit,andeven32bit,butasyouincreaseprecisionyoualsoneedamuchfasterprocessor.WhatdoesthisbitstuffmeanforADC?Forexample,supposeasensorreads0Vtoan8bitADC.Thiswouldgiveyouadigitalouputof0.5Vwouldbe255.Nowsupposeasensorgaveanoutputof2.9V,whatwouldtheADCoutputbe?Doingthemath:2.9V/5V=X/255X=2.9*255/5=148Sohowdoyouuseananalogport?Firstmakesureyoursensoroutputdoesnotexceedyourdigitallogicvoltage(usually0V-5V.Thenplugthatoutputdirectlytotheanalogport.Thisbitrangecouldalsobeseenasaresolution.Higherresolutionsmeanhigheraccuracy,butoccasionallycanmeanslowerprocessingandmoresucceptabilitytonoise.Forexample,supposeyouhada3bitcontrollerwhichhasarangeof2^3=8.Thenyouhaveadistancesensorthatoutputedanumber0-7(atotalof8thatrepresentsthedistancebetweenyourrobotandthewall.Ifyoursensorcanseeonly8feet,thenyougetaresolutionof1bitperfoot(8resolution/8feet=1.Butthensupposeyouhavean8bitcontroller,youwouldget256/8=32~1bitpercentimeter-waymoreaccurateanduseful!Withthe3bitcontroller,youcouldnottellthedifferencebetween1inchand11inches.DigitalI/OPortsDigitalportsarelikeanalogports,butwithonly1bit(2^1=2hencearesolutionof2-onandoff.Digitalportsobviouslyforthatreasonarerarelyusedforsensors,exceptformaybeon/offswitches...Whattheyaremostlyusedforissignaloutput.Youcanusethemtocontrolmotorsorled'sorjustaboutanything.Sendahigh5Vsignaltoturnsomethingon,oralow0Vtoturnsomethingoff.OrifyouwanttohaveanLEDatonlyhalfbrightness,oramotorathalfspeed,sendasquarewave.Squarewavesareliketurningsomethingonandoffsofastthatitsalmostlikesendingoutananalogvoltageofyourchoice.Neat,huh?ThisisanexampleofasquarewaveforPWM:ThesesquarewavesarecalledPWM,shortforpulsewidthmodulation.Theyaremostoftenusedfor