You are on page 1of 2

ENGR3199:ElecanismsMiniProject1Report StevenCooreman,SilasHughes,SarahSeko 09/16/2013 PreparingourComputers ThebootloaderontheboardhasbeenconstruedtocommunicateoverUSBwitha Pythonscript.Ergo,inordertoletthecomputerseetheboard,thecorrectdrivershadtobe installed.ThesolutionwastoinstallawindowsbinaryversionoflibUSB,andloadlibUSBs developmentdriverastheboardsdriver.Atthatpoint,libUSBisthelowlevelbackendfor pyUSB,the(Python)frameworkonwhichthebootloaderprogramisbuilt. Twonewbuildtoolswerealsoneededtobeinstalledtoallowustoprogramour microcontroller:thePICXC16compilerandthebuildsystemSCons.Theinstallationofthese toolswasrelativelystraightforward. ModificationstoBlink.c Totestourabilitytocorrectlyinterfacewiththeboard,wemadesimplemodificationsto blink.c,recompiledtheprogram,programmedtheboard,andranthenewprogram.

Our modificationsconsistedofadjustingtherateofblinkingandchangingwhichbuttonsactivated whichlights. CreatingServo.c Wecreatedaprogramtocontrolthepositionofahobbyservousingthepositionofa potentiometer.Tocreateournewprogram,weusedthreefilesfromthepreviousblink programasafoundation:blink.c,SConstruct,andapp_p24FJ128GB206.gld.Sincemanyof basicaspectsofbothblink.candandservo.careidentical,itmakessensetoborrowfrom previousfunctioningcode. Servo.c Startingfromtheblinkprogram,therearefivepointsofchange: Theservocodeutilizestwoextralibraries,PinandOC,ofwhichtheheaderfilesmustbe included. Thoselibrariesmustbeinitializedaswell,withtheinit_pin()andinit_oc()calls. Thepinsneedtobeconfiguredthroughthepinlibraryfortheirrespectivefunctions: Analog0beingananaloginput,andDigital13theservocontrolsignal(digitaloutput). Weneedtosetuptheservolibrary(whichusestheOutputCompareandTimer peripheralsonthechip)tousepinD13asoutput,andgeneratethecorrecttimings. Hobbyservosusuallytakeacontrolsignalwithafrequencyof50Hz(20msperiod),and thisspecificonehaspulselengthmodulation.Thefulltravelrangeoftheservo correspondstoapulselengthbetween0.8and2.2ms.1 Lastly,theinputsignalfromthepotentiometerneedstobemappedtotheservos position.Inordertoachievethis,weconnectedthepotentiometerswipertotheanalog
1

http://www.hobbyking.com/hobbyking/store/__16649__vigor_vs_5m_mg_servo_10g_1_2kg_0_17sec.html

input.Whenreadwiththepinlibrary,thisgivesusa16bit(10bitresolutionleftjustified) floatingpointnumberrangingfrom0(0x0000)to(around)1(0xFFC0).Thishappensto betheexactformatneededfortheservofunction,whichneedsthepositionoftheservo asa16bitfloatingpoint,rangingfrom0(lowerlimitoftravel)to1(upperlimitoftravel). Therefore,wecoulddothemappinginonestatement: pin_write(&D[13],pin_read(&A[0])) Thoughnotnecessary,servo.calsomakestheonboardlightsblink,andthisgivesusvisual feedbackthatthecodeisrunning. SConstruct Thetwonewlibrariesbeingusedbyservo.c,PinandOC,areaddedtotheSConstruct file. app_p24FJ128GB206.gld Theloaderfilewasnotmodifiedforthisprogram,butitisnecessarytosuccessfullyload ourcodeontothemicrocontroller.

You might also like