scieee AI-readable full text Open interactive document viewer

Repositorio Institucional de Documentos

Abstract

El proyecto describe el funcionamiento y control de un motor DC Brushless. En el documento queda recogida la realización de las placas electronicas correspondientes al controlador y la electrónica de potencia. Fraguas Tejero, Diego; Steenbuch Vester, Heiko

Full text

Diego FraguasTejero CRUISE CONTROL ON AN ELECTRIC BIKE Report Report regarding the Electrical Power Engineering Project, from the corresponding course, at the Southern Denmark University, during the Autumn semester. Supervisor: Heiko Steenbuch Vester ODENSE 2011 Índice 1. SYNOPSIS....................................................................... 1 2. PREFACE ....................................................................... 1 3. IN TR ODUC T ION ............................................................ 2 4. THE BATTERY.................................................................. 4 5. THE MOTOR .................................................................. 6 5.1. INTRODUCTION ..................................................... 6 5.2. WORKING PRINCIPLE ........................................... 6 5.3. KIND OF DC BRUSHLESS MOTOR ........................ 8 5.4. OUR MO T OR .......................................................... 9 5.5. FEEDING SEQUENCE............................................. 12 6. SENSOR ......................................................................... 14 6.1 NUMBER OF POLES. ............................................... 15 7. CONTROLLER AND POWER ELECTRONIC ................ 17 7.1. CONTROLLER......................................................... 18 7.1.1. Introduction.................................................... 18 7.1.2. Analogic ......................................................... 18 7.1.3 Digital ............................................................... 22 7.2 POWER E L EC T RONICS ...........................................38 7.2.1 Power supply ................................................... 38 7.2.2. Driver ............................................................... 41 8. CONCLUSIONS............................................................. 46 9. BIBLIOGRAPHY .............................................................. 48 ANNEX A – MOTOR DATASHEET .................................... 49 ANNEX B – F IRMWARE ..................................................... 51 ANNEX B -CIRCUIT ........................................................... 67 ANNEX C- CIRCUIT WITH OPTOCOUPLER..................... 68    1 1.SYNOPSIS Themaingoalofthisprojectisapplythelearntknowledgeduringthissemesteratthe SDUinthecoursesofPEMandCES. Theprojectthatwehavechosenconsistsoncontrolanelectricbikemotor,soitcan assisttheride.So,ifthespeedislowerthanthedesiredspeed,themotormustspeed up,andviceversa. Inordertoachievethisgoal,weneedtodealwiththreedefinedsubjects:themotor, thecontrollerandthepowerelectronics. 2.PREFACE Thefirsttwowheelvehiclewithsteeringsystemwasdesignedin1816byaGerman scientist.Although,thereareoldtestimoniesaboutthisvehicle.ItissaidthatLeonardo DaVincipaintedacycleinoneofhisworks. In1839,pedalswereincludedinthismachinewiththepurposeofridingitwithout touchingthegroundwiththefeet. Inthefollowingyears,theexpertsdedicatedthetimetoimprovethepreviousmodels anddesigns. Asananecdote,wewanttocommentthatin1887,ThomasStevens,originfromthe USA,wasthefirstmanwhowentaroundtheworldridingacycle.Hetook3yearsto completethewholetrip. In1889,thefirstofficialcyclingcompetitionappears.Fromthenonwards,thereis morecuriosityinimprovingthecharacteristicsandtheperformanceofthecycle. Inthelastdecade,theelectricalbicycleshavebeguntomarket.Theyhaveanengine tohelpthecyclistinhisride.Theusuallybikesdon´tneedenergythereforeitsusedis increasing,butalthoughthisisadisadvantagefortheelectricalbikes,theyarevery usefulinplaceswithlargeslopes,andfactorslikethewindwillbeeliminated.Onthe otherhand,youcanridebiggerdistanceswithmuchlesseffort.    2 3.INTRODUCTION Fortherealizationofthisprojectwehavetotakeintoaccountsomeaspectsrelated withtheideaofourproject:cruisecontrolonanelectricbike. Firstofall,wemusthaveaclearideaaboutwhatanelectricalbikeconsiston:isa machinedesignedtomovethroughtheeffortofthecyclistusinganelectricalmotorin ordertohelpthecyclist,andnottoreplace.Incasethereisnoeffortofthecyclist,the vehiclewillbeconsideredasamotorbike. Therearesomeaspectsthatdeterminethecycling:thewaytodrive,thestateofthe bicycle(forexamplethetirepressure),thestateofthebattery,ambienttemperature, thewind,topography,theweight,theage,therider´sphysicalcondition… Ontheotherhand,acruisecontrolisanelectronicsystemthatautomaticallycontrols thespeedofavehiclemotorandmaintainsitsteadyassetbythedriverwithoutuse theacceleratororbreak. Wethinkthatourcruisecontrolmustsatisfysomeconditions: ‐Themotorcanalsobeturnedonoroffusingaswitch,inordertolettherider chooseuseitornot. ‐Thespeedmustbesteadywithouttakingcareabouttherequiredtorque. ‐Asasafetycondition,themotorhastostopwhenthecyclistbreaks. ‐Theenergydissipatedduringthebreak,willbeusedtochargethebattery.    3 Thesystemcanbedescribedintheimageshownbelow:  Aswecansee,oursystemisdividedinfourparts:themotor,thesensor,thecontroller andthepowerelectronics.Aswell,we’llneedapowersupplytofeedoursystemanda load(bicycletorque). Theelectricaldriveisasystemwhichperformstheconversionofelectricalenergyto mechanicalenergy. Nowwearegoingtodescribebrieflythecomponentsoftheelectricaldrive: Themotor:Themotorobtainpowerfromelectricalsources.Itconvertselectrical energyintomechanicalenergy.ThemotorscanbeclassifiedinACorDCmotors. Powerprocessor:Withcontrollablesources,themotorcanbereversed,bakeorcan beoperatedwithvariablespeed.Thecharacteristicofthemotorscanbechangedat will.Powerelectronicconvertershaveseveraladvantagessuchasmoreefficiencyor flexibility Controller:Thecomplexityofitdependsonthedesireddriveperformanceandthe typeofmotorused.Themaincontrollerscanbe:analog,digital,DSP/microprocessor Source:Electricalsourcesorpowersuppliesprovidetheenergytotheelectricalmotor. Forhighefficiencyoperation,thepowerobtainedfromtheelectricalsourcesneedto beregulatedusingpowerelectronicconverters. PowersourcescanbeofACorDC.Therecanbeseveralfactorsthataffectthe selectionofdifferentconfigurationofelectricaldrivesystemsuchas:torqueand    4 speed,capitalandrunningcostorspaceandweightrestrictionsenvironmentand location Withtheprovidedinformationinthisintroduction,wecanconcludethatthepurpose ofourprojectistocreateanelectronicsystem,whichcontrolamotor.It’sformedbut twoquitedifferencedparts:controllerorlogicalpartanddriverorpowerelectronics part. Toachievethisgoal,weneedtostudythedifferentpartsdescribedbefore,inorderto knowthespecificationsofoursystem.    5 MAINREPORT 4.THEBATTERY AswehaveaDCmotor,wewillneedtofeeditwithsomesource,asDCpowercanbe stored,wearegoingtouseabattery. ThebatterythatwewasgivenisaLiFePO4one,anditfitsperfectlywithourmotor. Themainadvantagesofthiskindofbatteriesare,astheconventionallithium‐ion battery: ‐Lightweightthatfitswiththepoweritgives ‐Nomemoryeffect(effectthatcausethebatterytoholdlesscharge) ‐Self‐dischargerateapprox.5‐10%permonth ‐Environmentalfriendly ‐Butitalsohashighercurrentandmorepeakpowercurrent.     6 Someofthespecificationsare: ‐ 5.26kgofweigh ‐ 361x149x83mm ‐ 36V ‐ 10AH Wemustsaythatthespecificationsareratedvalues.Whenthebatteryiscompletely chargedisexpectedtohavehighervaluesofvoltageandmaximumcurrentthanthe ratedvalues.Tomakesurethatourelectronicdevicescanhandlethispeaks,we decidedtotestthebattery. Wemeasuredthevoltageofthebatteryfullychargedwithoutload;wemeasureda valueof41V.Knownthepowerofthemotor:500W,wecancalculatealoadvaluein ordertogetthecurrent.  Ω== 362.3 2 P U R  Inthelaboratorytherewerethreevariableresistances,abletohandlethispower, whichminimumvaluewas10ohms,soweconnectedtheseresistanceswiththeir minimumvalueinparallelinordertogetavalueclosedtothedesiredresistance.  Ω= ++ =33.3 111 1 321 RRR Req   Tomeasurethecurrentwecouldn’tuseanammeterbecauseitsfusejustcanhandle 10Aasmaximumvalue,soweusedapegpluggedtotheoscilloscope,gettingthe followingvalue:    7  Thepeghasagainof100mV/A)sothecurrentisof10.8A 5.THEMOTOR 5.1.INTRODUCTION DuetotheDCpowersupply,ourmotormustbeaDCone.WecanfindtwokindofDC motor:brushedandbrushlessmotor.Duetotheimprovementthatthebrushless motorhas(lessmaintenance,moreefficiency...)wechooseit. 5.2.WORKINGPRINCIPLE InaDCbrushedmotorthetorqueisobtainedbytheinteractionofthemagneticfield inductionandthecurrentoftherotatingarmaturewinding. TheDCbrushlessmotorisverysimilartotheconvectionalDCmotorbuttheyarebuilt indifferentway: ‐Theswitchingisdoneelectronicallyratherthanmechanically. ‐Permanentmagnetsareintherotorinsteadofthestator. ‐Thecoilsarelocatedinthestator,formingasingle‐phasewinding. Brushlessdcmotorsaretypicallyconfiguredaspermanentmagnetsynchronous motors..Itsperformanceisbasedonsequentialfeedingofeachstatorphasesin synchronismwiththemovementoftherotor.Sothepermanentmagnetsfollowthe movementofthemagneticfield.    14 6.SENSOR TheHallsensorusestheHalleffecttomeasuremagneticfieldsorcurrentsinorderto determinetherotorposition. IfcurrentflowsthroughaHallsensorandit’sclosetoamagneticfieldwhichflows perpendiculartothesensor,thesensorcreatesavoltageproportionaltotheproduct projectionofthemagneticfieldandcurrent.Thenwiththecurrentvalue,wecan calculatethemagneticfieldforce.Ifthemagneticfieldcreatedbycurrentflowing throughawinding,thenyoucanmeasurethevalueofthecurrentintheconductoror coil. Inordertodeterminethemotorspeedweneedasensor,ourmotorisprovidedwith threehallsensors,duetothefactthatisabrushlessDCmotor. TheHallsensordetectsthedirectionandthemagneticfieldfromthemotor.The outputofthesesensorsis5Vwhentherotorisclosetoit.     15 Usingthedigitaloscilloscopewecanknowthesequencethatfollowourmotor,it’s showninthefollowingimage:   TheyellowwaveisthehallsensorA,thegreenoneisthehallsensorBandtheblue oneisthehallsensorC. 6.1NUMBEROFPOLES. Nowwearegoingtocalculatethenumberofpolesofourmachine. Howcanwedothis? Weperformedthemotorwithnoloadandtheratedvalues.Wecanfindthespeedfor thatcaseinthedatasheet,n=343.4rpm,soweneedtoknowthevalueofthe physicalfrequencyorperiod: 1º)Passtherpmtorevolutionpersecond.  2º)Wehave5.75revolutionspersecond,sowecanknowhowmanytimespendin onerevolution,theinverseistheperiodofaphysicalrevolution.Tp=174,67ms. 3º)Inthepictureofthehallsensorstest,wecanmeasuretheperiodofaelectrical cycle,ifeachsquareis5m/s,andonecyclespend4squaresandaquarterofother square,theperiodofthecycleisTe=21.5ms    16 4º)Theratiobetweenthephysicalperiodandtheelectricalperiodisthenumberof poles.  Sowecanconcludethatourmotorhas4pairofpoles.    17 7.CONTROLLERANDPOWERELECTRONIC 7.1.CONTROLLER 7.1.1.Introduction Thecontrollerisoneofthemostimportantthingsinourproject.It’sadevicewhich doesn’thandlehighvaluesofvoltagesandcurrent,buthastoprocessalotof informationencodedinsignals,inordertogetthedesiredbehaviourofourmotor. Thecontrollermusthavethefollowingfeatures: ‐Furnishthecorrectvoltageaccordingtodesiredspeed ‐Feedthewindingsinthecorrectsequence ‐Acquirethemeasuredspeed Afterdiscussingaboutwhichkindofcontrollerwasmoresuitableforourproject,we decidedtoimplementadigitalcontroller.Inordertoshowtheimprovementsthatthis kindofcontrollerprovidesus,wearegoingtoshowabitofinformationaboutanalogic controllersaswell. 7.1.2.Analogic ‐ Closedloopcontrol Aswecanseeinthefollowingimagethemaincharacteristicisthatafeedbackisused tocontroltheprocess.Thefeedbackismeasuredbyasensorwhichsendasignalto thecontroller.   Thesystemsareshownasblackboxeswhereyoucanchecktheinputandtheoutput, that’scalledtransferfunction.WorkingintheLaplacedomainyoucanmakea mathematicalmodelofanyprocess.    18 ‐PIDcontroller ThePIDcontrolleristhemostextendedoneintheindustrialsector.Thecontroller transferfunctionisshownbelow: sk s k ksR d i p⋅++=)(  Accordingtothisparametres,wecanmakethatoursystemgetadesiredbehavior. Theproportionalpartusetomakearoundthe80%ofthetask,theintegralpartmake aroundthe15%ofthetaskandthederivativeparttherest. Theproportionalpartusetofixtheerrorbetweenthedesiredvalueandthemeasured value(feedback)whiletheintegralparttakescareofthedesiredresponsetime.Tofix thisvalueswealwayshavetotakecareaboutthestabilityofthesystem.Ifweneedto makethesystemstableweshouldincreasethederivativepart. Now,weshowsomeimagesoftheresponsesthatwecangetfromaregulator accordingtotheparametersdescribedbefore:    19                         Desired response Low integral gain Ver y hi g h PID g ains Very low PID gains Very high derivative gain Very high integral gain and very low    20 Aswecanseeintheimages,thekindofsignalthatwecangetischangingwiththe gains,soisimportanttochooseasuitablePIDgains. Therearemanywaystoimplementthiskindofcontrollers; Wecanclasifythemaccordingtothekindofelectronicsused:analogicanddigital controllers. Inthenextsub‐chapters,wearegoingtoseewhattheyconsiston,inordertodecide whichisthemoresuitableforthisproject. Now,weexplaintheanalogiccontroller. ‐PIDanalogiccircuit ThePIDtransferfunctionandthedifferencebetweenthetwooutputscanbe representedwiththefollowingelectroniccircuit:   Thetwoinputs(u1andu2)arevoltageproportionaltothespeed,accordingtothe usedsensorgain.       21 Thefirstoperationalamplifierworksasasubstractor,whichrepresentthesubstractor drawninthetransferfunction. 1 3 1 1 13 42 4 21 R R U R RR RR R UV ⋅− + ⋅ + ⋅=  Thisvoltageisconnectedtothreeoperationalamplifierswhichworkasaninverter, integratorandderivator,respectively: 1 5 6 2V R R V⋅−=  ∫⋅⋅ ⋅ −= tdttV CR V 0 1 17 3)( 1 dt tdV CRV )( 1 284 ⋅⋅−=  Thelastoperationalamplifierworksasanadder. )( 11 4 10 3 9 2 12 R V R V R V RVo++⋅−=  So: dt tdV R CR dttV CRR tV R R RV t o )( )( 1 )(( 1 10 28 0 1 1710 1 7 6 12 ⋅ ⋅ +⋅ ⋅⋅ +⋅= ∫ )() 1 ( 1 3 1 1 13 42 4 2 11 82 107195 6 12 R R V R RR RR R V R RC RRCRR R RVo⋅− + ⋅ + ⋅⋅ ⋅ + ⋅⋅ + ⋅ ⋅=  Aswecansee,thecircuitrepresentthebehaviourofaPID,whereitsconstantscanbe adjustedwithcapacitorsandresistances. 95 6 RR R Kp⋅ = 1071 1 RRC Ki⋅⋅ =    22 11 82 R RC Kd ⋅ = Theanalogicoutputhaveavoltagesignal,soinordertoproduceaPWMweneedto converttheoutput,usingadivicelikeLM331orAD650. Finally,withthiskindcontrollerwecan’tusethehallsensorsignalinasimpleway, lookingasensorlessdriveraeasierway,butwearen’tgoingtogetsuchasmooth performanceaswecangetusingthehallsensor.Alsoanotheranalogicsensorwe’llbe needed. Ontheotherhand,wehavethedigitalcontroller,whichofferusasimplercircuit,with thedisadvantageofacomplexprogramming.Ithasenoughinputtohandlethesignals fromthethreehallsensorandthethrottle,andcanmeasurethespeedwithoutany additionalsensor,sothebudgetisalsosomethingthatbetfortheanalogicway. 7.1.3Digital Digitalcontrolisaverydifferentapproachfromtheanalogueway,becauseitallows youtoactivelymanagethesystem.Also,itobtainsmoreflexibility,moreopportunity tomanagethesystemandmoresafetyincaseofsomefaultofthesystem,like overcurrentorovervoltage. Thepurposesofthedigitalcontrollerare: ‐Closed‐loopspeedcontrolforprecisespeedregulation ‐Readsetspeed(Speedcruisecontrol) ‐Implementthecruisecontrol ‐Readthepositionofrotorwiththehallsensorandmeasurethespeed ‐Logicprotectionforover‐voltage,over‐currentandthermalprotection Torealizethisdigitalcontrollerweneedamicrocontrollerwithadriver,thatit’s performedtocontrolabrushlessDCmotor(BLDC).    23 ThefollowingfigurerepresentsthediagramblockoftheDigitalsystem:  Thediagramblockiscomposedbyamicroprocessor,the3‐phaseMosfetBridge (driver),signalconditioningforthehallsensorandthethrottle. ThedesigninvolvesrunningtheBLDCmotorinaclosedloop,withthespeedsetbythe throttle,thatit’srealizedwithapotentiometerthatgiveanoutputof0‐5V.Thissignal isreadbytheAnalog‐DigitalConverter(ADC)ofthemicrothatconvertstheinput voltageinadigitalvaluethatrepresentsthesetspeed. Thisvalueisreadbythelogicunitthatconvertsthisvalueinaproportionalsignalthat issenttothePWMmodule. ThePWM(pulsewidthmodulation)isatypeofdigitalmodulation,whichallowsfora mediumvoltagevariabledependentontherelationshipbetweenthedurationofthe positiveand0V.Thedurationofeachpulsecanbeexpressedinrelationtotheperiod    30 programming,thecodeisstoredinthemicroandwhenthesupplyvoltageisfurnished tothemicro,thefirmwarestartstorun. Themicroworksatthefrequencyof20Mhz,thatisprovidedbyacrystal. Thethrottleisavariableresistancethatfurnishesavoltagesignalproportionaltothe setresistance. Theinterfaceofthethrottleiscomposedbyaconnectorthatfurnishes5v,middle signalandgnd.Themiddlesignalisaninputtothemicrocontrollerthatisinsertedin oneofthepinsthatimplementstheADCconverter. Thereadvoltage(0‐5V)bytheADCisconvertedinadigitalvaluethatisproportional tothespeedfortheCruiseControl. Thisvalueisimportantbecauseitsetstherelativeaveragecurrentthatflowinthe motor.So,thisisrealizedwiththePWMsignalofthemicrocontroller. Thismicrohas3PWMmodules,whereeverymoduleiscomposeby2PWMsignal(one directandoneincomplementarymode).Intotal,themicrohas6PWMsignal. Themicrousesthissignaltocontrolthedriverofthepowerelectronicsandfinallythe motor. Then,themicrohastoturnonoroffthecorrectPWMsignalaccordingtotherelative sequenceofthehallsensor.ThisPWMsignalisasignalwithavariableaverage voltage,dependentontherelationshipbetweenthedurationofthehighlogiclevel (5V)andlowlogiclevel(0V).Theswitchingfrequencyissetto20KHz. ThedutycycleofthePWMisdirectlyproportionaltothethrottlepotentiometerinput. Thechangesinthedutycyclecontrolthecurrentthroughthemotorwinding,thereby controllingmotortorque. ThisPWMsignalisactivatedinasequencethatisgivenbytheHallsensorssignal, whichindicatethepositionoftherotor.Aninterruptisgeneratedwhentheinputstate onanypinchanges.Thissignalispluggedintheboardintoaconnectorthatprovides3 hallsensorssignal(Ha,HbandHc),5voltsandground.Also,thehallsensorsignal needsaninterfaceofpull‐upresistortowork. So,whenthemotorisrunning,thestateofthethreeHallsensorschangesaccordingto therotorposition.Thesupplyofeachmotorphaseisswitchedbasedonthestateof thesensors(commutation).Also,Hallsensorsinterruptsarecountedtomeasurethe    31 motorspeedthatiscalculatedeverysecondwithaninternaltimerofthemicro.This valuerepresentstheRPS(RevolutionPerSecond),thatit’sobtainedwiththisformula:  Ifit’smultiplyby60,it’sobtainedinRPM(RoundperMinute). Similarly,thespeedreferenceinputistranslatedintoaspeedvalueinordertohave bothreferenceandfeedbackinthesameplatform.Nextequationshowsconverting speedreferencefromapotentiometersettingreadthroughanADchannel.  Inthenextsection,thecalculationerrorisdescribedinordertocontrolthespeed. Also,thisboardmanagesthesystemincaseofoverload,under‐voltage,andovertemperaturewithsomesignaltakenfromthedriver. Firmwareimplementation Generally,thefirmwareisaprogramthatinternallycontrolsvariouselectronicdevices. Inthiscase,thefirmwareisinsidethemicroandcontrolsalltheperipheralsofthe microandofthesystem.Then,it’sthemainpartofthecontroller,becauseitdescribes howthesystemisworking. Insidethefirmware,theclosed‐loopspeedcontrolisimplemented,reducingtheerror betweenthespeedsetbythepotentiometerandtheactualmotorspeed.Theoutput oftheloopchangesthedutycycleofthePWMmodule,therebychangingtheaverage voltagetothemotor. Thefirmwareiscomposedbythreeparts: ‐ Mainloop ‐ InterruptHandlerofHallsensor ‐ Speederrorcalculation(Cruisecontrol)     32  FlowchartofMainloop Themainloopflowchartdescribesthemainfunctionofthefirmware,thatexecute everycycleofthecode.Theinitialpartisfortheinitializationofthemicro.Oneofthe mostimportantinitializationsregardstheroutineoftheinterruptthatdetectsthe changeofthestateofthehallsensorsignal.Thenextstepintheloopischeckingthe stateofthepinRC2,thatit’slinkedtothejumperoraswitch.Whenthejumperorthe switchisclosed,themotorstarttorunatthesetspeedthatisreadfromtheADC.     33  FlowchartofInterruptHandlerofHallsensor ThisflowchartexplainshowtheInterruptoftheHallsensorworks.Theinterrupthasa specialfunctionthatit’sexecuting(inthiscase),whenonesignalofthethreeHall sensorchangesitsstate.Thisfunctionisveryimportantbecause,it’spossibleto energizethecorrectwinding,accordingtotheactualstateoftheHallsensor(position oftherotor).Also,thisroutinesetstheactualspeedthatisreadbytheADC.     34  FlowchartofSpeederrorcalculation TheSpeederrorcalculationisthefunctionthatimplementstheCruiseControl.This functioncalculatestheerrorfromthesetspeedofthethrottleandtheactualspeed. Theerrormaybepositiveornegative,indicatingifthespeedismoreorlessthanthe setspeed.ThiserrorispassedthroughaPIDalgorithmtoamplifytheerror.The amplifiederrorisusedtoreadjustthePWMdutycyclesoriginallycalculated. Then,nowit’spossibletodescribethesystemwithablockdiagramofacontrolloop withaPIDalgorithm.    35  BlockdiagramofacontrolloopwithaPIDalgorithm Realizationandtest  TheLogicalcircuitisrealizedinaprototypeboard,thatit’ssuppliedbythepower supplypartwith5V.Themicrocontrollerisprogrammedwiththefirmware,described intheflowchartofthemainloopandoftheInterruptHandlerofHallsensor,butnot aboutFlowchartofSpeederrorcalculation.Itmeansthat,themicrocontroller executesthepartofinitializationandacquiresthechangeofthestateoftheHall sensor,withtheactivationoftherelativePWM.    36 TheSpeederrorcalculationisnotimplementedbecausewedidn´thaveenoughtime tomakethispart.So,thatmeansthattheCruiseControlisnotimplemented.But,we willexplainhowtoimplementthispart. Beforeactivatingtheboard,werealizedthetestofisolationandcontinuitytoensure thatthereisn’tanyshortcircuitoranywrongconnection. Inthenextphoto,it’spossibletoseehowtheHallsensorisworking.Theledindicates theactualsequenceofthehallsensor,wherethefirstledinthetopisHallsensorA, thesecondinthemiddleisB,thethirdisHallsensorisCandthelastindicatesthe5V intheboard.Inthiscase,thereisthesequence101.     37 7.2POWERELECTRONICS 7.2.1Powersupply  Thisistheelectricalcircuitofthepowersource.Thiscircuitisveryimportantbecause withoutthis,alltheelectronicpartwouldnotworkcorrectly.Themaingoalofthis circuitistosupplythecorrectvoltagetotherestoftheelectronicboard. Asweknow,ourboardisdividedin3differentiatedparts(thepowersupply,the logicalpart,andthedriverforthemotor). Allthese3partsworkatdifferentvoltagesandwedon´thaveinthecircuit,3different variablepowersourcestosupplyeachofthecircuits.Thisisthereasonforwhatwe needthispowersupplycircuit. Weonlydisposeonebattery.Thisonewillworkasourpowersupplyanditwillgiveus 36Volts.Withthisreferencevoltageweshouldgetanother2differentvoltages. Thelogicalpartwherethemicrocontrollerisconnectedisgoingtoworkwith5volts. Wehavetobeverycarefulwiththesevaluesbecauseahighvoltagecanburnand destroyalltheelectronicpart.Thedriversectionwillneedavoltageof15volts Togetthesevoltageswearegoingtouse2regulators.Theregulatorhas3pins,Input, Groundandoutput.Withtheseregulators,whichevervoltageentersfromtheinput, theregulatorprocessesitandtakesoutthroughtheoutput,thedesirevoltage.Inour case,howwementionedbefore,weneed15Vand5V. TheLEDdiodesareonthecircuitjusttoindicateusthatthereiscurrentandvoltage flowingthroughthecircuit.      38 Thiscircuitalsoneedssomeelectrolyticcapacitors.Theirmissionistostabilizethe voltagethatgoestotheregulator.Weneedtomaintainthevoltagethatentersinto theregulatortoafixvaluesandsometimesthesource(battery,commonelectric network)hasvoltagepeaksthatcanburntheregulatorandthecapacitorsmaintain thelevelofthevoltageinastabilizedvalue. Realization: Toimplementthispartofthecircuitwehavetobeveryattentivetoallthe componentsthatweuseandthevaluesandthedirectionsthatweintroducethemin theboard Abouttheregulators,wehadsomeproblemsfixinganddecidingthem.Concretelythe onewhichsuppliesthe15voltageattheoutputhasaproblembecausethe36volts thatcomestraightfromthebatterywillarrivedirectlytotheregulator. Lookingatthedatasheetofthefirstregulatorthatwaschosen(7815)werealizedthat thisonewasnotgoingtobecorrectbecausethemaximumallowancevoltageofthis regulatoris35Vandjustthebatterygivesminimum36Vanditcangivemorewhenis fullycharged. Tosolvethiswehavetolookforanotherregulatorthatbearshighvoltage.Wefound theregulatorLM317HVthathasthecapacityofhandlinghighvoltage(60volts). Anotherfactortotakeintoaccountisthepolarityoftheelectrolyticcapacitor.Itis veryimportanttoputthecapacitorinarightwaybecauseaproblemwiththis,can automaticallyburnthecomponents.    39  Inthisimagewecanseethevoltagethatthebatterygivesus.Howwesaidbeforeitis notexactly36Volts.Normallythisshouldnotbeaproblem,butwehaditbecauseour regulatoracceptedmaximum36Volts.Becauseofthisreasonwehadtochangeitand putanotheronethatcouldbearmorevoltage.   Inthispicturewearetestingtheoutputofthefirstregulatorwhenweputthevoltage ofthebatteryintothepowercircuit(40volts).Wecanseethatispractically15V.How wementioned,thisvoltagewillgostraighttothedriver.    46 correctlythewindingsofthemotoraccordingtothesequencewithourownelectronic board. Alsowehavetotakeintoaccountthegoalsthatwecouldn’tachieve:testthedriver, installthedriverheatsink,programagenerativebreakinordertomakethemotor workasageneratorwhileit’sbreakingandchargeourbatteryandbuildourcircuitina PCBboardaftertestingtheproto‐board.Finally,inordertoavoidnoisefromthe powerpartinthelogicalpart,weshouldhaveseparatedopticallythetwoparts(we showtheschematicintheannex). Althoughwegetalongverywellwiththegroup,wecanmakeacriticalviewaboutour workingmethod,thewaywefocusedtheprojectwasn’ttheoptimalone.Inour opinionweshouldhavemadeabetterplanningandtasksdistributionsoeverybody wouldworknotonlythesame,butfasterandeasier.Ifwerecognizeourselvesthat despitethefinalworkisdonewemadethesemistakes,nexttimewemayworkso muchbetter.      47 9.BIBLIOGRAPHY AN857_BrushlessDCMotorControlMadeEasy AN898_DeterminingMOSFETDriverNeedsforMotorDriveApplications AN899_BrushlessDCMotorControlUsingPIC18FXX31MCUs AN885_BrushlessDC(BLDC)MotorFundamentals DCMotorControlTips‘nTricks ElectricBikeBLDCHubMotorControlUsingtheZ8FMC1600MCU AVR448:ControlofHighVoltage3‐PhaseBLDCMotor ElectronicCircuitsDesingForBeginners–Chapter5 IRAM136‐3023B_IntegratedPowerHybridICforLowVoltageMotorApplications PIC18F2331/2431/4331/4431_MicrocontrollerswithnanoWattTechnology,High‐ PerformancePWMandA/D  BOOKS: FirstcourseonPowerelectronics_NedMohan,year2003Edition PrinciplesofElectricsMachinesandPowerElectronics_P.C.Sen,SecondEdition ElectricalMachines,Drives,andPowerSystems_TheodoreWildi,FifthEdition  WEBSITES: http://www.goldenmotor.com/hubmotors/HBS‐36V500W%20Performance.pdf http://bicicletaselectricas.wordpress.com/electronica‐de‐una‐bicicleta‐electrica/ http://ww1.microchip.com/downloads/en/AppNotes/00857a.pdf http://www.brushlessmotor.com.ar/Caracteristicas.html     48 ANNEXA–MOTORDATASHEET     49     50 ANNEXB–FIRMWARE  #include<18F2431.h>//headerfileforthisPIC #deviceADC=10//initializeforADC #fuses HS,NOFCMEN,NOIESO,PUT,BROWNOUT,BORV45,NOWDT,NOPWMPIN,LPOL_LOW,HPO L_LOW,NOLVP,NOPROTECT #usedelay(clock=20000000)//setclockofthemicro #usefast_io(A)//initializeINPUT‐OUTPUT #usefast_io(B) #usefast_io(C)  #byteOVDCOND=0x0F6B//initializeregisterofthemicro #byteOVDCONS=0x0F6A #byteFLTCONFIG=0x0F6C #bytePWMCON1=0x0F6E #bytePDC0L=0x0F79 #bytePDC1L=0x0F78 #bytePDC2L=0x0F77 #bytePDC0H=0x0F76 #bytePDC1H=0x0F75 #bytePDC2H=0x0F74 #bytePORTA=0x0F82 #bytePORTB=0x0F81    51 #bytePORTC=0x0F80 #byteSSPBUF=0x0FC9 #byteSSPSTAT=0x0FC7 #byteSSPCON=0x0FC6 //encoder: #byteCAP1CON=0x0F63 #byteCAP2CON=0x0F62 #byteCAP3CON=0x0F61 #byteDFLTCON=0x0F60 #byteMAXCNTL=0x0F64 #byteMAXCNTH=0x0F65 #bytePOSCNTL=0x0F66 #bytePOSCNTH=0x0F67 //#byteQEICON=0x0FB6 #byteVELRH=0x0F69 #byteVELRL=0x0F68  #include<stdio.h> #defineFW_VERSION13 charbuildVers[10]={__DATE__};  //‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ //DEFINESPERI/O: //‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐    52  //#defineDEBUG1 #defineLED_MOTOR_ONoutput_low(PIN_B7) #defineLED_MOTOR_OFFoutput_high(PIN_B7) #defineLED_DIR_ONoutput_low(PIN_B6) #defineLED_DIR_OFFoutput_high(PIN_B6) #defineLED_CYCLE_ONoutput_low(PIN_C0) #defineLED_CYCLE_OFFoutput_high(PIN_C0)  #defineOFF0x00//motorOFF #defineON0x01//motorON  #defineBACKWARD0x00//directionbackward #defineFORWARD0x01//directionforward  #defineMAX_SPEED80 #defineDEFAULT_SPEED72 #defineMID_SPEED8 #defineMIN_SPEED1  //Dutycyclelimitdefinition,for20KHz@20MHz,2uSdeadtime //minimumdutycyclecorrespondsto3xdeadtime=3x2uS=6uSPDC= 6uS/(4/Fosc) #defineMIN_DUTY_CYCLE0x003C//trydoublingfrom0x1E;    53 #defineMAX_DUTY_CYCLE0x03E0//maximumdutycycleis4xPTPER  #defineGO_MIN0x44 #defineTYPE_COMMAND0x4C enumSTATUS_ENUM { STATUS_OFF=0, STATUS_RUN_FW, STATUS_RUN_BK, STATUS_BRAKE, STATUS_BRAKE_IN_POSITION, STATUS_GOTO_IN_POSITION };  //variabiliglobali unsignedint8_direction=0;//flagdirection unsignedint8_status=STATUS_OFF;  unsignedint8_phaseOffset1;//Phase1offsettotheSinetable(0) unsignedint8_phaseOffset2;//Phase2offsettotheSinetable(120) unsignedint8_phaseOffset3;//Phase3offsettotheSinetable(240) voidinit_PCPWM(void) { unsignedcharportbStatus;    54  //setup_power_pwm(modes,postscale,time_base,period,compare, compare_postscale,dead_time); //clockxPWMdiviso4,freerun,clockperdeadtimeclockdiviso2,postscale1:1,time base=0,periodo=F9. //compareecomparepostscale=0,deadtime=18(1secsecondoilsourceassembly) setup_power_pwm(PWM_CLOCK_DIV_4|PWM_FREE_RUN |PWM_DEAD_CLOCK_DIV_2,1,0,0xF9,0,0,20); set_power_pwm0_duty(0); set_power_pwm2_duty(0); set_power_pwm4_duty(0); set_power_pwm6_duty(0);  if(_status==STATUS_BRAKE) { setup_power_pwm_pins(PWM_ODD_ON,PWM_OFF,PWM_OFF,PWM_OFF); portbStatus=PORTB&0xC0; PORTB=portbStatus|0x1B; } else { portbStatus=PORTB&0xC0; PORTB=portbStatus|0x3F; setup_power_pwm_pins(PWM_COMPLEMENTARY, PWM_COMPLEMENTARY,    55 PWM_COMPLEMENTARY, PWM_OFF); }  OVDCOND=0xFF;  PWMCON1=1; OVDCONS=0;//OVDCONSisconfiguredsuchthatallPWMoutputsare0upon power‐up. //bsfTRISC,1;EnsurethatRC1isaninput FLTCONFIG=0; }  voidinitMotorStart(void) { _phaseOffset1=0;  if(_direction==BACKWARD) { _phaseOffset2=12; _phaseOffset3=24; } elseif(_direction==FORWARD) {    62 { if(!CheckInput(PIN_A3)) { LED_DIR_ON; }else{ LED_DIR_OFF; } }  #INT_IC3DR voidHall_C()//inputcaptureIC3 { //LED_CYCLE_ON; if(!CheckInput(PIN_A4)) { LED_CYCLE_ON; }else{ LED_CYCLE_OFF; } } voidmain(void) { unsignedint8i;     63 //Inizializzazioni set_tris_a(0xFD);//allinputexceptRA1 set_tris_b(0x00);//alloutput set_tris_c(0x7E); output_a(0xFD); output_b(0xFF); output_c(0xFF);  setup_wdt(WDT_OFF); setup_timer_0(RTCC_DIV_1|RTCC_INTERNAL); setup_timer_1(T1_DIV_BY_1|T1_INTERNAL); setup_adc_ports(sAN0); set_adc_channel(0);//initializeADC //initializeADC setup_adc(ADC_CLOCK_DIV_8);  //Setencoder DFLTCON=0x7E; MAXCNTH=0x00; MAXCNTL=0xFF;  CAP1CON|=0b01001000; CAP2CON|=0b01001000; CAP3CON|=0b01001000;    64  //‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ //inizializzazioneperpilotaggiodiodiIRED: //Timer=4*Tx_DIV_x)/clock //Timer=(4*8)/20000000=0.0000016 //‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ setup_timer_5(T5_INTERNAL|T5_DIV_BY_1); enable_interrupts(INT_TIMER5); enable_interrupts(INT_IC1);//INTERRUPTINPUTCAPTURE enable_interrupts(INT_IC2QEI); enable_interrupts(INT_IC3DR);  _speed=DEFAULT_SPEED; _status=STATUS_OFF;  enable_interrupts(INT_SSP); enable_interrupts(INT_TIMER1); enable_interrupts(GLOBAL);  for(;;) {  LED_CYCLE_ON; delay_ms(200);    65 LED_CYCLE_OFF; delay_ms(200);  if(!CheckInput(PIN_A4)) { LED_CYCLE_ON; }else{ LED_CYCLE_OFF; }  _speed=misura()&0x7F;//numerochevariada0a15  if(CheckInput(PIN_C2)) { _status=STATUS_RUN_FW;  startMotor(_status); LED_MOTOR_ON; } else { stopMotor(); LED_MOTOR_OFF; }    66 ANNEXB‐CIRCUIT             67 ANNEXC‐CIRCUITWITHOPTOCOUPLER          