Professional Documents
Culture Documents
Matrix Display To Microcontroller
Matrix Display To Microcontroller
ByMattStabile UniversityofCaliforniaSantaBarbara MediaArtsandTechnology MAT200CWinter2008 Abstract Atutorialonthebasicsofchoosingand settingupamicrocontrollertocontrolan LEDmatrixisprovided.Fundamentalsof LEDmatricesandmicrocontrollersarefirst covered,followedbytipsonmakingthe necessaryinterconnectionsbetweenthe two.Relevantsoftwarefordevelopmentis surveyedandfinallysomeexamplecodeis providedfortestingtheLEDmatrix. Introduction Thispaperwillprovideacomprehensive tutorialonhowtodriveandcontroladot matrixLightEmittingDiode(LED)display withamicrocontroller.Thedisplayusedisa commerciallyavailablePCBmount8x8dot matrixRGBLEDdisplay,withatotalof192 individualLEDsthatarecontrolledby32 controlsignals.Themicrocontrollerusedis anAtmelATMega128;however,thecontrol
Figure1:8x8DotMatrixLEDDisplay TheDotMatrixLEDDisplay AnLEDMatrixconsistsofanarrayofLEDs whichareinterconnectedsuchthatthe positiveterminal(anode)ofeachLEDinthe samecolumnareconnectedtogetherand thenegativeterminal(cathode)ofeachLED inthesamerowareconnectedtogether. Notethatthiscouldbetheotherway aroundaswell,withthepositiveterminals connectedtotherowsandthenegative terminalsconnectedtothecolumns.Figure 2showsaschematicforatypical8x8 matrixwithsinglecolorLEDs.
ineachrowandcolumn,itisnotpossibleto controleachindividualLEDatthesame time.Instead,thematrixiscontrolledby cyclingthrougheachrowveryquicklywhile triggeringthecorrectcolumnpinstolight thedesiredLEDsforthatparticularrow.If theswitchingisdoneataquickenough rate,therewillbenovisibleflickerandthe Figure2:8x8LEDMatrixSchematic AnLEDdotmatrixdisplay(dotrefersto thecircularlensesinfrontoftheLEDs)can alsocomewithmultipleLEDsofvarying colorsbehindeachdotinthematrix.For example,thematrixusedinthisprojecthas aRed,GreenandBlueLEDbehindeachdot inthe8x8grid.Aconfigurationwith multipleLEDsbehindeachdotaddsanother controlpintoeverycolumn(positive terminal)foreachadditionalcolorofLED, whiletherows(negativeterminals)arestill allconnectedtogether.ThereforeanRGB matrixhas32controlpinscomparedtothe 16pinsseeninFigure2. Whenchoosingamicrocontrollerthatwill ControllingtheLEDMatrix SincealloftheindividualLEDsinamatrix sharetheirnegativeandpositiveterminals meettherequirementsnecessaryfor controllinganLEDmatrix,thespecifications thatmustbemetarethoseofthenumber LEDmatrixdisplaywillappeartohaveeach LEDturnedonatthesametime.Thisworks becauseoftheprincipleknownas PersistenceofVision,whichisthetheory thattheretinaofthehumaneyeretainsan imageforaboutatenthofasecond.Thus anLEDmatrixmustbeveryprecisely controlled,withtheRowsbeingscanned throughsequentiallyatarategreaterthan about40Hz(tobesafe)whilesendingout thecolumndataattheexactsamerate. Thiskindofcontrolismosteasily accomplishedwiththeaidofa microcontroller,plussomeadditional components. Choosingamicrocontroller
ofI/Opinsavailable,theamountofcurrent thateachpincansourceandsinkandthe speedatwhichthemicrocontrollercan sendoutcontrolsignals.Anotheroption thatonemightdesireisthatofanonboard AnalogtoDigitalConverterforsamplingan inputsignal(suchasanaudiowaveform) whichcantheninfluencethecontrolsignals beingsenttotheLEDs. Moderndaymicrocontroller technologyhasmadetheissueofcontrol signalspeedandavailableI/Opinsalmost trivialforthisapplication.Almosteverychip onthemarketnowhasupwardsof32I/O pinsavailableandalmostalloperateat speedsgreaterthan10MHz,whichallows forcontrolsignalstobesentatratesmuch greaterthanthe40Hzthatisrequiredto satisfythePersistenceofVisionprinciple. Forexample,themicroprocessorthatI choseranatanoperatingspeedof16MHz andintheloopofcodethatcycledthrough therowsIwasstillabletoputa2msdelay betweeneachiteration,meaningthatthere wasaguaranteed16msofdelayinmycode (excludingtheactualcodeexecutiontime) andstillnovisibleflickeronthematrix display.Upuntilrecentyears,18decoder chips(whichallowthe8rowspinstobe
controlledbyjust3I/Opins)werealmost alwaysusedtominimizethenumberofI/O pinsrequiredonthemicrocontroller; however,withthelargeamountofI/Opins availableonalmostallmicrosnow,these chipsseemlikeanunnecessary complicationtothedesign. Thefinalspecificationthatmustbe metisthatofcurrentconsumption, meaningthattheamountofcurrentthat eachI/Opincansourceandsinkisgreater thantheamountofcurrentneededto illuminatearowofLEDs.Thesenumbers mustbedeterminedfromthespecifications sheetoftheLEDmatrixinconjunctionwith themicrocontrollersmaximumcurrent values.Thisspecificationisalsoeasilymet inmostsituationsthough,duetothewayin whichweareswitchingtheLEDsoffandon insucharapidmanner.Whenatypical currentspecificationisgivenontheLED matrixdatasheet(usuallyaround20mAper LED),thespecisforsteadystate consumption(continuouslyon).Sincethe LEDsarebeingswitchedonandoffso quickly,ourcurrentconsumptionisactually muchlowerduetothecurrentdraws continuouslytransientstate.WiththeLEDs fullyswitching,Iobservedtheretobeonly
Puttingitalltogether Withallofthespecificationsmet,now comesthefunpartofwiringthewhole matrixup.Thisinvolvesfabricatingmany cablesastheRGBmatrixrequires32control signals,whichfirsthavetogofromthe microcontrollertoaboardwiththebias resistorsandDarlingtontransistorarray, andthenfromtheretothe32pinsonthe backofthematrix.
Figure3:BlockDiagramofConnections
moresimpleandintuitive.Themosttime consumingpartofwiringupthematrixis mappingthepinsfromthemicrocontroller portstothePCBmountpinsonthebackof thematrix.Thisturnsouttobequite complexbecausethe32pinsonthematrix areinaseeminglycompletelyrandomorder andmustbecorrectlyassignedtopins07 oneachportofthemicrocontroller.Table1 providesthepinmappingswiththematrix pinnumbersinboldandthecorresponding microcontrollerportletterandnumber directlybelow. 1 A0 9 B5 17 E7 25 B1 2 F0 10 B4 18 A7 26 B0 3 E1 11 A4 19 F6 27 F3 4 A2 12 E4 20 E5 28 A3 5 F2 13 F5 21 A5 29 E2 6 E3 14 A6 22 F4 30 F1 7 B7 15 E6 23 B3 31 A1 8 B6 16 F7 24 B2 32 E0
correctlymakingalloftheconnections,we arethenreadytowriteatestprogramand begintestingtheboard. ProgrammingtheMicrocontroller TheAtmelATMEGA128canbeprogrammed usingBASIC,C,orAssemblylanguage.After thecodeiswritten,itiscompiledusingthe WinAVRcompilerwhichoutputsaHexfile thatcanthenbedirectlydownloadedtothe microcontroller.TheHexfileisdownloaded viaanInCircuitProgrammerthatconnects themicrocontrollertotheparallelportofa PC.
Figure4:InCircuitprogramdownloadtool
Table1:MatrixPinNumbersinBold,corresponding microcontrollerPortLetterandnumberdirectlybelow.
LEDinthearray.Figure5showsanexample programthatdemonstrateshowtoturnon everyLEDinthematrix,changingwhich colorLEDsarelitatevenintervals.Notethe infinitewhileloop,sincewejustwantthe microcontrollertorunthisroutineforas longasitispoweredup.Thissectionof codewouldappearinthemain()ofyourC sourcefile.Theonlyothercodethatwould benecessarywouldbethe#include librariesforyourspecificmicrocontroller andwhateverlinesofinitializationmaybe requireddependingontheapplication.The codeisextrememlysimple,withthemain forloopsimplyiteratingdowntherowsof thematrixwhilesimultaneouslyupdating thecolumndataonthePortsofthe microcontroller.Thedelayinbetweeneach rowmustbecalibrateddependingonthe speedofthemicrocontrollerbeingused. Thetargetvalueistousethelongestdelay possiblewithoutbeingabletoseeany flickeringoftheLEDs.Thedelayisdesired toensurethattheLEDsaregettingenough currenteachtimetoachievefullbrightness. Thecountervariableoutsideoftheforloop allowsstatestochangeaccordingtothe lengthofthedurationvariable.
fordevelopingmicrocontrollerprograms dependingonthelanguagethatisdesired andthechiparchitecturebeingused.For AtmelsAVRfamilyofchips,Atmelprovides afreeAssemblyLanguageIDEcalledAVR Studio4whichcanbedownloadedfrom www.atmel.com.Forprogrammingin BASIC,ademoversionofBASCOMAVRis availablefromMCSElectronicsat www.mcselec.com.Thedemoversions onlylimitationisthatofa4kBmaximum sourcecodefilesize.ForprogramminginC thereisCodeVisionAVR,availableinademo versionwitha2kBfilesizelimitationat www.codevision.be.AgoodfreeC/C++IDE iscalledCode::Blocksandisavailableat www.codeblocks.org.Code::Blocksalready haspreconfiguredsettingsforusingthe WinAVRcompiler,soitisaverygoodchoice forafree,fullyfunctionalIDE. Thefirstprogramusedtotestthe
setupshouldbeverysimpleandtestevery
Figure5:ExampleControlPrograminC
OnLineReferences Arduinowww.arduino.cc Opensourcemicrocontrollerprojectbased onAtmelAVRfamilyofchips Atmelwww.atmel.com ManufactureroftheAVRseriesof microcontrollers BestMicrocontrollerProjects www.bestmicrocontrollerprojects.com ManyexampleprojectswithPICmicros Code::Blockswww.codeblocks.org FreeC++IDEwithbuiltinsupportformany differentcompilers Futurlecwww.futurlec.com Sellsmicrocontrollerevaluationboardsand starterkits,aswellasLEDmatrices Microchipwww.microchip.com ManufacturerofPICfamilyof microprocessors Parallaxwww.parallax.com Sellsmicrocontrollerstarterandadvanced kits SparkFunElectronicswww.sparkfun.com SellsmicrocontrollersandLEDmatrices TheLEDLightwww.theledlight.com SellsalltypesofLEDs,hasgoodbeginner tutorialsonsettingupLEDs.
RGBLEDDotMatrixDisplay www.foryard.com
FYM-23881ABxxx ManufacturedbyForyard