system power controller: a low power circuit board … · 2012. 2. 28. · jane lubchenco under...
TRANSCRIPT
NOAA Technical Memorandum GLERL-154
SYSTEM POWER CONTROLLER: A LOW POWER CIRCUIT BOARD FOR THE CONTROL AND MONITORING OF SUBSYSTEM POWER IN DATA COLLECTION SYSTEMS
Ronald MuzziStephen ConstantJohn Lane
NOAA, Great Lakes Environmental Research Laboratory4840 S. State Rd., Ann Arbor, MI 48108
February 2012
UNITED STATESDEPARTMENT OF COMMERCE
John BrysonSecretary
NATIONAL OCEANIC ANDATMOSPHERIC ADMINISTRATION
Jane LubchencoUnder Secretary for Oceans & AtmosphereNOAA Administrator
2
NOTICE
Mention of a commercial company or product does not constitute an endorsement by the NOAA. Use of information from this publication concerning proprietary products or the tests of such products for publicity or advertising purposes is not authorized. This is GLERL Contribution No. 1611.
This publication is available as a PDF file and can be downloaded from GLERL’s web site: www.glerl.noaa.gov. Hard copies can be requested from GLERLInformation Services, 4840 S. State Rd., Ann Arbor, MI [email protected].
NOAA’s Mission – To understand and predict changes in Earth’s environment and conserve and manage coastal and marine resources to meet our nation’s economic, social, and environmental needs.
NOAA’s Mission Goals:
• Protect,restoreandmanagetheuseofcoastalandoceanresourcesthroughanecosystemapproachtomanagement
• Understandclimatevariabilityandchangetoenhancesociety’sabilitytoplanand respond
• Servesociety’sneedsforweatherandwaterinformation• SupporttheNation’scommercewithinformationforsafe,efficient,and
environmentally sound transportation• ProvidecriticalsupportforNOAA’sMission
3
TABLE OF CONTENTS
ABSTRACT .....................................................................................................................................5
1. BACKGROUND .......................................................................................................................5
2. DESIGN .................................................................................................................................................6 2.1 Board Form Factor ............................................................................................................................8 2.2ElectricalDesign ...............................................................................................................................8 2.2.1PowerSwitching .........................................................................................................................8 2.2.2PICProcessor ..............................................................................................................................9 2.2.3A/DInput .....................................................................................................................................9 2.2.4RS-232Interface ......................................................................................................................10 2.2.5SwitchingPowerSupply ...........................................................................................................11 2.2.6ProgrammingInterface.............................................................................................................11 2.3PCBLayoutDesign .........................................................................................................................11 2.4SoftwareDesign ..............................................................................................................................12 2.4.1 Main Routine ............................................................................................................................12 2.4.2CommandProcessing ...............................................................................................................12 2.4.3WatchdogTimer .......................................................................................................................14 2.4.4 Timer 2 .....................................................................................................................................14 2.4.5EEPROMStorage ....................................................................................................................15 2.4.6A/DConverter ..........................................................................................................................15 2.5 Operation ........................................................................................................................................16 2.6 Calibration & Initialization .............................................................................................................16
3.RESULTSANDLESSONSLEARNED ...............................................................................................16 3.1ElectronicDesignLessons ..............................................................................................................16 3.2SoftwareLessons .............................................................................................................................17
4. CONCLUSION .....................................................................................................................................17
Figure1.SystempowercontrollerwiredinReCONbuoyonPC/104stack ...............................................6Figure2.Functionblockdiagram .................................................................................................................7Figure3.Powerswitchingcircuit .................................................................................................................8Figure4.Watchdogrelaycontrolcircuit.......................................................................................................9Figure5.A/Dinputcircuit ..........................................................................................................................10Figure6.RS-232interfacecircuit ...............................................................................................................10Figure7.Switchingpowersupplycircuit ...................................................................................................11Figure8.Programminginterface ................................................................................................................11
Table 1. Controller command syntax list ....................................................................................................13
4
5
System Power Controller: A low power circuit board for the control and monitoring subsystem power in data collection systems
Ronald MuzziStephen Constant
John Lane
ABSTRACT
Powerefficiencyisimportantinremotedatacollectionsystemsthataretypicallysolar-powered.SystemssuchastheReal-timeCoastalObservationNetwork(ReCON)requirecontrollingpowertosensorsandcomponentswithcurrentsofupto2ampsandvoltagesupto48volts.Thoughtherearesomeoff-the-shelfsolutionsavailable,thesesystemseitherconsumeunnecessarypower,orarelimitedintheamountofcurrentandvoltagethattheycanhandle.ThedesignoftheSystemPowerControllerboardprovideseightchannelsofsemiconductor-switchedpowerthatcanhandlethecurrentandvoltagerequirementswhileconsumingalowamountofquiescentpower.Eachpowerchannelprovideshigh-sideswitchingofupto60voltsandcurrentsofupto2amps.Alow-powermicroprocessorusinganRS-232serialinterfaceallowsprogrammingofthechannels,includingtimedelayedevents.Threeanaloginputchannelsallowmeasuringsystemvoltages,suchassolarpanel,battery,andsystembusvoltages.Thecontrollerincludesawatchdogtimerwithrelayoutputwhichallowsafullpowerrebootofthedatacollectionsystem.Thesystemcanbeoperatedwithanyvoltagefrom7to60volts,andtheentirecontrolleronlyconsumes0.14wattsofpowerwhenpoweredat12volts.ThecontrollerboardconformstothePC/104standardformfactorsothatitcanbemountedonthetopofastandardPC/104stack.ThesystemhasprovenreliableinseveralyearsoffielduseandhasbeenincorporatedasanintegralcomponentoftheReCONdatacollectionnetwork.
1. BACKGROUND
Powerefficiencyisanimportantrequirementofaremotemulti-sensordatacollectionplatform,suchastheReCONbuoy1.Thesesystemsaretypicallyoffthepowergridandthereforelimitedbybatterycapacity,availablesolarenergy,orotherenergyharvestingmethods.Onemethodofimprovingpowerefficiencyistooperatethevariouscomponentsofthesystem,suchassensorsandcommunicationlinks,onadutycycle.Thedutycycleisadjustedforeachcomponentaccordingtoitsparticularrequirements.Sensorsmeasuringslowlychangingoceanographicparametersdonotneedtobesamplingatthesamerateassensorsmeasuringrapidlychangingparameters.Thecommunicationslink,whichusuallyconsumesalargeamountofpowertotransmitthedatatoaremotereceiver,onlyneedstobepoweredduringdatatransmissions.Somecomponents,suchassensors,mayonlyconsumeafewmilliampsofpower,whileothers,suchascommunications,mayconsumeafewampsofpower.Inaddition,thesecomponentsoftenoperateatvariousvoltages,typicallyranginganywherefrom5to60volts.Anefficientpowercontrollermoduleisneededtomanagethepowerofthesecomponents.Thiscontrollermustincludemultiplepowerchannels,atleasteight,thatareindependentlyprogrammed.Thecontrollerwouldbeprogrammedbythedatacollectionplatformprocessor,respondingtocommandssentfromtheprocessoroveranRS-232seriallink2.SincethePC/104isacommonformfactor3 used in data collection andotherembeddedsystems,itispreferredthatthecontrollerboardalsoconformtothisformfactor.
1RUBERG,S.A.,R.W.MUZZI,S.B.BRANDT,J.C.LANE,T.C.MILLER,J.J.Gray,S.A.CONSTANT,andE.J.Downing.Awirelessinternet-basedobservatory:TheReal-timeCoastalObservationNetwork(ReCON).Proceedings,MarineTechnologySociety/IEEEOceans2007Conference,Vancouver,BritishColumbia,Canada,September30-October5,2007,6pp.(2007).http://www.glerl.noaa.gov/pubs/fulltext/2007/20070045.pdf
2TheElectronicIndustriesAssociation(EIA)standardRS-232(RecommendedStandard)definestheelectricalcharacteristicsforserialasynchronouscommunicationsbetweendevices,e.g.,whatiscommonlyreferredtoasacomputerserialport.
3ForinformationonthePC/104Consortiumseehttp://www.pc104.org/.
6
Atthistime,thoughthereareoff-the-shelfsolutionsthatcanapproximatethesepowercontrolfunctions,wehavenotbeenabletofindanythatmeetalloftheaboverequirements.Therearethreecommonmethodsofcontrollingpower:relays,low-endswitchingsemiconductors,andhigh-endswitchingsemiconductors.Off-the-shelfsystemsareavailableemployingallofthesemethods.Systemsusingrelays,however,consumepowerrangingontheorderoftensofmilliampsperchannel.This,however,isthesameorderofmagnitudeassomeofthesensorsthemselves,sothattheuseofrelayswouldnotbeverypowerefficient.Systemsusinglow-endswitchingcauseproblemswithoceanographicsensorssincetheyintroduceanoffsetintothenegativesideofthepowersupply,resultinginanunknownvoltagedifferentialbetweenthesensorgroundandthesystemground.Thisinturnaffectsthesensormeasurements.Theavailableoff-the-shelfsystemsusinghigh-endswitchingsemiconductorsarelimitedtoasinglevoltage,usually12volts,andlimitedintheircurrentoutput,typically100milliampsorless.Theselimitationsareovercomeinourdesignbyallowingseparateinputvoltagesforeachchannelandselectingsemiconductorscapableofhandlingbothhighvoltages,upto60volts,andhighcurrents, up to 2 amps.
Thedesignwouldthenalsoincludesomeextrafeaturesthatwouldbenefittheneedsofdatacollectionsystems.Severalanaloginputchannelswouldbeincludedtomonitorsystemvoltagessuchassolarpanelandbatteryvoltage.Awatchdogtimerwouldbeincludedwitharelaytoallow“rebooting”thesystemifthesystemshouldlock-up.Andanopen-drainpowerchannelwouldbeincludedtoprovidealogic-controlchannel.
2. DESIGN
ThecontrollerwasdesignedsothatitwouldconformtothePC/104formfactor4andmountonaPC/104stackasthetopboard,althoughtheoveralldimensionsareslightlylargerthanthePC/104specifications.ItwasdecidednottousethePC/104busforpowerorcommunications,thoughavailable,becausethatwouldlimitthecontrolleroperationstoonlybeabletofunctionwhenthePC/104processorboardwasrunningandhealthy.KeepingthepowerandcommunicationsseparatealsoallowsthecontrollertopowercyclethePC/104processorboardifneeded.
Foroptimumreliabilityandsimplicity,thecontrollerispowereddirectlyfromthesystembattery.Sincesomeofoursystemsrunon12voltsandotherson48volts,wedesignedthecontrollertohaveawide-rangeinputvoltageof7-60
4ForinformationonthePC/104Consortiumseehttp://www.pc104.org/.
Figure 1. System Power Controller wired in ReCON buoy on PC/104 stack.
7
volts.Thiswouldcoverthelowendofabout9voltsfromawell-drained12voltbatterytoabout54voltsfromasolarpanelcharginga48voltbattery.
CommunicationstothecontrolleristhroughanRS-232serialconnection.Thecontrollerwillreceivespecificcommandstoturnpowerchannelsonandoff,turnpowerchannelsonandoffafteradelay,readtheanaloginputchannels,andresetthewatchdogtimer.Thecontrollerusesnon-volatilememorytostorepower-upchannelstatesandcalibrationvaluesfortheanaloginputs.
ThepowerchannelsweredesignedwithMOSFET5p-channeltransistorstoprovidehigh-endvoltageswitchingthatarecapableofhandlingupto60voltsandupto2amps.High-endswitchingispreferredoverlow-endswitching,becauselow-endswitchingcanproducegrounddifferentials.Theamountofvoltagedropresultingfromhigh-endswitchingisinsignificant,sincesystemsarealreadydesignedtoaccommodatethelargevoltageswingsseeninthebattery/solarpanelcharge/dischargecycle.Inaddition,eachpowerchannelwillhaveitsowninputandoutputterminaltoallowtheuseofdifferentvoltagesondifferentchannelsasneeded.
Figure 2. Function Block Diagram.
Thecontrollerincludesthreeanaloginputstoallowmonitoringofvarioussystemvoltages,suchassolarpanel,battery,andbusvoltages.
Awatchdogtimerisprovidedthatcanbeusedtopowercyclethesystemintheeventofasoftwarelockup.Ifthewatchdogtimerdoesn’treceiveregularresetsfromthedataloggerthroughtheserialportwithinthegiventimeoutperiod,itpulsesarelaythatmomentarilyturnsoffthepowertothedataloggerorentiresystem.Thisallowsthesystemtoself-rebootinthecaseofasystemlockup.Therelayoperatesinafail-safecondition,thatis,thenormally-closedstate.
Sincethecontrollerboardwillbepopulatedin-house,theboardwasdesignedtousethru-holecomponentsratherthansurfacemountcomponentssincethethru-holecomponentscanbemoreeasilysoldered.Theonlyexceptiontothiswasforthethree-pinvoltagereference,whichwasnotavailableinathru-holepackage.
5MOSFETmeansMetal–Oxide–SemiconductorField-EffectTransistor.
8
2.1 Board Form Factor
ThestandardsizeforaPC/104formfactorboardisspecified6as3.6x3.8inches(9.1x9.7cm).Itsoonbecameapparentthataboardofthatsizewouldnotprovideenoughareaforallthecomponentsthatwedesiredtoplaceonit.SincethestackofPC/104boardsthatwewereusingcontainedoneoversizedboardmeasuring3.8x4.8inches(9.7x12.2cm),wedecidedtoapproximatethatsizeinordertoprovidethedesiredarea,andtherefore,weusedadesignsizeof3.775x4.750inches(9.6x1.9cm).Thiswouldallowtheboardstostackuniformly.
2.2 Electrical Design
Theelectricaldesign7wasdevelopedin-housetomeetourpowercontrollingrequirementsandstillbeversatileenoughtobeusedinawiderangeofapplications.
2.2.1 Power Switching
Toprovidepowerswitching,aFQP47P06p-channelMOSFETtransistor(Q2)wasselectedtoprovidereliable,lowquiescentcurrentswitchingbetweentheINterminalandtheOUTterminal(Figure3).Screwterminalswereusedtoprovideeasyconnectiontotheboard.TheMOSFETtransistorhasaratedRDS8of0.026Ω.Inatypicalapplicationat1amp,thiswouldresultinavoltagedropofonly0.026volts.Thetransistorisratedfor47ampscurrent,VDSS9of60volts,and160wattspowerdissipation.OurmaximumpowerdissipationisI²×R=(2amps)²×(0.026Ω)=0.1watts,whichiswellhandledbytheTO-220package10ofthetransistor.SincetheVGSS11 is only rated at ±25 volts, a 15 volt zener diode,D3,isplacedacrossQ2tolimitthevoltage.R4isusedtolimitcurrentflowingthroughthezenerdiode.Q1drivesthegateofQ2lowwhenitispoweredonbythecontrolsignal.R5isusedtobiasQ2gatehighwhenQ1isturnedoff.
Figure 3. Power Switching Circuit.
R3isusedtobiasQ1gatelowwhennocontrolinputispresent.Sincepowerupspikesmaybepresentinthecontrolinput,alow-passfiltermadeupofR2andC1isused.Thisprovidesaminimuminputpulserequirementontheorderoftensofmillisecondsbasedonthetimeconstantof56KΩx1.0μF=56msec.Thisismorethanadequatetopreventfalseswitchingduringpower-uptransients.D2isincludedasafailsafetoprotectthecontrolcircuitryfromhighvoltage,whichmayoccurintheeventofQ1failinginashortedmodebetweenthegateanddrain.Lightemittingdiode(LED)D1,alongwiththecurrentlimitingR1,provideachannel“on”indicator.The5370T5LCLEDwasselectedbecauseitrequiresonly
6MOSFETmeansMetal–Oxide–SemiconductorField-EffectTransistor.7 Schematic available here: http://www.glerl.noaa.gov/ftp/publications/tech_reports/glerl-1548RDSistheResistancebetweentheDrainandtheSourcepinsofthetransistor9VDSSistheVoltagebetweentheDrainandtheSourcepinsofthetransistor.10TheTO-220packageistheIndustrystandardTransistorOutlinenumber220.11VGSSistheVoltagebetweentheGateandSourcepinsofthetransistor.
9
2mAtoilluminatetheLED.However,ifneeded,theseLEDscouldbeleftoutforapplicationsthatrequireextremelylowcurrentrequirements.Eightpowerchannels,P1-P8,areprovidedwiththisarrangement.
Onepowerchannel,P9,isprovidedasanopen-drainpowerchannelfortheuseofcontrollinglogicsignals.Itincludesalloftheabovecomponents,exceptforQ2,R4,R5,andD3.
Anotherpowerchannel,P0,controlsthewatchdogrelay(Figure4).Theinputcircuitissimilartotheabove,exceptthatD2isnotincludedsincethereisnohighvoltagebeingappliedtoQ1inthiscircuit.
Figure 4. Watchdog Relay Control Circuit.
ThedrainofQ1connectsoneendoftherelaycoiltoground.Theotherendoftherelaycoilisconnectedtothe5voltsupply.D4isusedacrossthecoilasasnubberdiode.Twobranchesoftherelayareused,insteadofone,inordertoaccommodatetheswitchingofhighvoltages.Thenormallyclosedcontactsareusedtoprovidethefail-safeonconditionforthewatchdogreset.Sincethecoilonlyconsumespowerduringthebriefresetcondition,thecoilpowerrequirementsaregenerallynotsignificantinthepowerconsumptionbudget.AredLEDwasusedfortherelaypowerchanneltodistinguishitfromtheotherchannels,whichusegreenLEDsbecauseoftheircapabilities,lowpowerconsumption,andavailabilityinathrough-holepackage.
2.2.2 PIC Processor
ThePeripheralInterfaceController(PIC)16F886CMOSmicroprocessor12waschosen.Thisprocessorprovides24Input/Output(I/O)lines,10-bitAnalogtoDigitalConverter(A/D),serialcommunications,threetimers,aninternalclock,andisavailableinathru-holepackage.Ithas8192wordsofprogrammemory,368bytesofRandomAccessMemory(RAM),and256bytesofElectricallyErasableProgrammableRead-OnlyMemory(EEPROM).Itrequires2.0to5.5voltstopoweritandconsumesamaximumof1.4mAcurrentatthe4MHzoperatingfrequency.
2.2.3 A/D Input
The10-bitA/Dinputisdesignedforclean,slowlyvarying,low-impedanceinputsourcessuchassolarpanelvoltage,batteryvoltage,andsystembusvoltages(figure5).A3.000voltreferenceisprovidedbyaMAX6030low-currentvoltagereference.
12 CMOS is Complementary Metal–Oxide–Semiconductor.
10
Figure 5. A/D Input Circuit.
Resistordividersareusedinahalf-bridgeconfigurationtoallowmeasurementofhighvoltages.Thefirsttwoanalogchannelsuse10Kand324KΩlowthermaldriftresistorstoallowinputsofuptoabout100voltswitharesolutionofabout0.1volts.Thethirdanalogchanneluses10Kand71.5Kresistorstoallowinputsofuptoabout24voltswitharesolutionofabout0.02volts.
2.2.4 RS-232 Interface
ThePICmicroprocessorprovideslogic-levelserialcommunications(Figure6).TheMAX3222RS-232TransceiverisusedtotranslatebetweenRS-232levelsignalsandlogic-levelsignals.Thetransceiverallowsinputlevelsofupto±25voltsandprovidesoutputlevelsof±5volts.
Figure 6. RS-232 Interface Circuit.
OnlylinesTX,RX,andGNDaresupported.ADE9Fconnector13 is mounted directly to the board to provide a standard serial port connector.
13DE9FisaD-subminiatureseries,Eshellsize,9pin,Femalegenderconnector.
11
2.2.5 Switching Power Supply
Forlow-poweroperation,awide-rangeinputvoltageswitchingpowersupplywasemployedtodeliver5voltsatapeakof100mAtothecircuit(Figure7).TheLM2575HV-5.0step-downvoltageregulatorwasused,whichprovidesaninputvoltagerangefrom7to60volts.ThecomponentsC1,C2,L1,andD2arespecifiedintheLM2575datasheet.D1isaddedtoprotectagainstreversepolarityinputs.Thelow-passfiltermadeupofL2andC3reducetheswitchingfrequencytransients to an acceptable level.
Figure 7. Switching Power Supply Circuit.
TheLED,D13,providesthepower-onindicator.Thoughtheoutputvoltageoftheswitchingpowersupplywilldeviateslightlyindirectcorrelationtotheinputvoltageoverthe7-60voltrange,theoutputvoltagedoesnotexceedthePICmicroprocessorpowersupplylimitof5.5volts.
2.2.6 Programming Interface
ThePICmicroprocessorcanbeprogrammedusingaPICkit2USBinterface14.ThisconnectsbetweenaprogrammingcomputerUniversalSerialBus(USB)interfaceanda6-pinconnectorontheboard(figure8).The6-pinconnectorusesstandard0.1inchspacingbetweenpins.
Figure 8. Programming Interface.
C20,D24,andR46makeuptherequiredinterface,asspecifiedinthePIC16F886datasheet.
2.3 PCB Layout Design
Theprintedcircuitboard(PCB)layout15wasdesignedin-houseusingsoftwareprovidedbythecircuitboardmanufacturer16.A4-layerdesignwasusedwithsoldermaskandsilkscreen.Twoofthefourlayersareforpowerandgroundplanes.Thepowerplanewasconnectedtothe5voltsupply.
14ManufacturedbyMicrochipTechnology,Inc.,http://www.microchip.com/15PCBlayoutavailablehere:http://www.glerl.noaa.gov/ftp/publications/tech_reports/glerl-15416ExpressPCB,http://www.expresspcb.com.
12
Atracewidthof0.01inches(0.25mm)wasusedformostlogicandpowertraces.Forthepowerswitchingpathsrequiringacapacityof2amps,atracewidthof0.05inches(1.27mm)wasused.Forthewatchdogrelaycontacttracesrequiringacapacityof4amps,atracewidthof0.1inches(2.54mm)wasused.Aminimumspacingbetweentracesof0.02inches(0.51mm)wasused.Fortracescarryinghighvoltages,aminimumspacingbetweentracesof0.03inches(0.76mm)wasused.
OversizedpadswereusedonU3,the3-pinsurfacemountMAX6030VoltageReference,inordertofacilitatehandsolderingofthecomponent.Twotestpointswereprovided:oneforthe5voltsupplyandanotherforground.Ajumperwasprovidedtoconnecttheinputvoltagedirectlytothewatchdogtimerrelaycontacts.Thesilkscreenincludedawhiteboxforwritingthecontrollerserialnumberontheboard.
Thecontrollerboardsarepopulatedbyhandinhouse.Afterassembly,theboardsarespraycoatedwithacrylicplastic(whilecoveringtheconnectors)toprovideprotectionagainstmoistureforextremeenvironmentaluse.
2.4 Software Design
ThePIC16F886microprocessorwasprogrammedintheClanguage.Theprogram17,named“SystemPowerController.c”,iscompiledandwrittentothePIC’snon-volatileprogrammemoryviaaPICsoftwaredevelopmentkit18. Comments in theprogramsourcecodeprovidesufficientinformationtounderstandtheprogramoperationandalsotofacilitatemakingchangesifneeded.
2.4.1 Main Routine
ThefirsttaskofthemainroutineistoinitializethePICmicroprocessor.ThisincludessettingthePICregisters,startingtheRS-232communications,readingstoredsettingsfromtheEEPROMmemory,settingpoweroutputchannelstotheirdefaultstates,andinitializingthegeneralpurposetimerinterrupt.ThecontrollerthenwaitsforandprocessescommandsfromtheuserreceivedovertheRS-232port.
2.4.2 Command Processing
Afterconnectingthecontrollertoaterminalemulatorprogramrunningatabaudrateof9600,theReturn key is pressedtogetthecommandpromptandconfirmthatcommunicationsareworkingproperly.Thecontrollersendsouttheprompt,“SPC>”.PressingtheReturnkeycausestheprompttobedisplayedagain.Thefirstletterofeachcommanddetermineswhichroutinewillprocessit.ThereareseparateroutinesforDelay,EEPROM,Help,Power,Query,Voltage,andWatchdogtimercommands.TheRESETcommandisprocessedbybranchingtothestartofthemainroutinesothatallthePICinitializationsareexecutedagain.Commandsareprocessedimmediately,withtheexceptionofsomeofthepowercommands.Powercommandsthatincludedelaytimesareenteredintoatabletoprovideindependenttimingtoeachpoweroutputchannel.
17Softwareprogramavailablehere:http://www.glerl.noaa.gov/ftp/publications/tech_reports/glerl-15418PICSoftwareDevelopmentKitisavailablefromMicrochipTechnology,Inc.
13
Table 1. Controller Command Syntax List
System Power Controller 2.1 Commands:
Dn = Delay secs (0-2^32) P = Show all pins Pn(L/H) = Set pin 0-9 Lo/Hi Pn(L/H)d = Wait d secs (0-65535), set pin L/H Pn(L/H)ddd,t = Wait ddd secs (0-999), pulse L/H for t secs (0-2^32) Q = Query RESET = Power up reset V(n) = Show A/D (1-3) W(n) = Show/set watchdog secs (1-2^32) Wx = Watchdog: R=Reset, OFF=Stop, C=Clear reset # H = Help List
EEPROM Commands:
E = Display all values EWSn = Write serial number n (0-65535) EWPn = Write default pin states, bits 0-9 EWTn = Write watchdog timeout default n secs (10-65535, 0=Off) EWRn = Write watchdog reset time n secs (0-65535) EWCaMn = Write calibration chan a (1-3) multiplier n (0-65535) EWCaZn = Write calibration chan a (1-3) zero offset n (-32768 to 32767) EWBs = Write boot commands (use ‘;’ between commands) EWIn = Write eeprom initialized flag: 12345=yes, other=no ERaaa = Read word from address aaa (0-255) EWaaa,n = Write word n (0-65535) to address aaa (0-255)
Examplesofcommands:
SPC> V1 à ShowvoltageonV1terminal SPC> P3H à SetP3high SPC> P1L30 à Wait30seconds,thensetP1low SPC> P2H020,15 à Wait20seconds,setP2highfor15seconds,thensetP2low SPC> WR à Resetwatchdogtimer(topreventwatchdogtimeout)
The UART_Init()routinewaswrittentoinitializetheUniversalAsynchronousReceiver/Transmitter(UART)RS-232serialcommunicationsinterface.Theputch()routineisprovidedtointerfacethePICserialI/OtotheCstdio library forstandardoutputprocessing.SerialinputisprocessedbytheUART_Ch_Ready() and UART_Ch_Get() routines to checkwhetheracharacterisintheinputstreambufferandtoretrievethecharacter.TheGetString() routine is used to retrieveanentirelineofinputasastringvariableandprovidetheprocessingofspecialcharacters,suchasBackspace and Return.
Thecontrollerfeaturesabootcommandstring,storedinnon-volatileEEPROMmemory,fortheprocessingofcommandsatpower-up.TheprocessingofthesecommandsishandledbytheGetString()routine,includingtheuseoftheCtl-Ccharactertoabortexecutionofthebootcommands.The“;”characterisusedtoseparatelinesinthebootcommandstring.Thebootcommandstringallowspowerchannelstobeturnedonaccordingtoatimedschedule.Itcanalsobeusedtoallowthesystemtooperateinastand-alonemode,i.e.,withoutacomputertosenditcommands.Tooperateinthestand-alonemode,thebootcommandstringwouldcontainvarioustimedcommandsandthenendwiththe RESETcommand,whichwillcausethebootcommandstringtobeexecutedrepeatedlyandindefinitely.TheCtl-C characterisusedtoabortexecutionofthebootcommandstringifneeded.
14
2.4.3 Watchdog Timer
ThewatchdogcounterisavaluethatisdecrementedeverysecondbytheTimer2interruptserviceroutine.Ifthewatchdogcounterreaches0,thenthewatchdogrelayisenergizedforthespecifiedresettime.Thewatchdogrelayistypicallyconnectedbetweenthesystembatteryandtheelectronicssothatwhenthewatchdogrelayisenergized,theelectronicsarepoweredcompletelyoff,withtheexceptionoftheSPCcontroller.TheEWTn command is used to set the watchdogtime-outperiodinseconds.Forexample,EWT3840 sets a 64 minute time-out period. The WR command must besenttothecontrolleronaregularbasistoresetthewatchdogcountertotheinitialvalueandpreventareset.BoththeinitialwatchdogtimeoutandresettimeparametersarestoredinEEPROMmemory.
2.4.4 Timer 2
ThePICTimer2providestheheartofthetimingneededbythecontroller.Timer2isprogrammedsothatitgeneratesaninterruptatarateof25timespersecond.TheTimer2interruptroutinerepeatedlycountsdownfrom25inordertoprovideonesecondtimingtothetimingroutines.Therearethreesectionstothetimingroutines:thedelaycounter,watchdogprocessing,andpowerchannelstateprocessing.
The delay counter simply decrements the delay_counter variable every second until it reaches zero. This counter is thenavailabletovariouscommandstoprovidedtimingasneeded.
Thewatchdogprocessingusesastatevariable,wd_state, and a counter variable, wd_secs.Atpower-upandwhenthewatchdogisresetbyausercommand,wd_secsissettothewatchdogtimeouttime,e.g.,3840seconds.Thevariablewd_stateissetto1toindicatethatitiscountingdownthewatchdogtimeouttimebydecrementingwd_secs. When wd_secsreaches0,thewatchdogrelayisenergized,wd_stateischangedto2,andwd_secsissettothewatchdogresettime,e.g.,60seconds.Thevariablewd_stateequaling2indicatesthatitiscountingdowntheresettime(howlongthesystemisheldintheresetstate)bydecrementingwd_secs. When wd_secsreaches0,thewatchdogrelayisdeactivated, wd_state is set back to 1, and wd_secsissetbacktothewatchdogtimeouttime.Todisablewatchdogprocessing,wd_state is set to 0.
Thepowerchannelstateprocessingusesarrays,oneforeachchannel.Thepowerchannelisalsoreferredtoasapin,sincetheyarecontrolledbytheoutputpinsonthePICprocessor.Thecontrolarraysincludeastatevariable,pin_state[], a level variable, pin_level[],andtwocountervariables,pin_wait[] and pin_time[]. They are indexed 0..9 torepresentP0throughP9.(P0canbecontrolledbothviathewatchdogcommandsanditcanalsobeusedasaregularpowerchannelviathePcommands.)Thesevariablesdeterminehowtoprocesseachpowerchannelattheonesecondinterval.
A pin_state[]of0indicatesthatthereisnoprocessingthatneedstobedoneforthatpin.
A pin_state[]of1isusedduringthewaittimeperiodbeforechangingthepinlevel.Thecounterpin_wait[] isdecrementedduringthistime.Whenpin_wait[] reaches 0, the pin is set to pin_level[].Ifthereisapinsettime period indicated by a non-zero pin_time[], then pin_state[]ischangedto2.Otherwise,pin_state[] is changedto0tocompletetheprocessing.
A pin_state[]of2isusedduringthepinsettimeperiod.Thecounterpin_time[]isdecrementedduringthisstate. When pin_time[]reaches0,thepinissettotheinverseofpin_level[] and pin_state[] is set to 0 to completetheprocessing.
Here’safewexamplesofhowthepinvariableswouldbeinitializedaccordingtospecificpowercommands:
Setpowerchannel(pin)3highaftera15seconddelay: Command: P3H15 pin_state[3] = 1 pin_level[3] = 1
15
pin_wait[3] = 15 pin_time[3] = 0
Setpowerchannel(pin)5lowaftera30seconddelay,thenafter20secondssetithighagain: Command: P5L030,20 pin_state[5] = 1 pin_level[5] = 0 pin_wait[5] = 30 pin_time[5] = 20
Note,however,thatbeforechangingthearrayvariableforaspecificchannel,pin_state[]mustfirstsetto0toclearandpreventanypinprocessingwhilethearrayvariablesarebeingchanged.Thenafterthevariablespin_level[], pin_wait[], and pin_time[] are set to their desired values, pin_state[]issetto1tostarttheprocessing.
2.4.5 EEPROM Storage
Systemparametersandcalibrationvaluesarestoredinthenon-volatileEEPROMmemory.TheEEPROM_Write_Word() and EEPROM_Write_String()routinesareprovidedtowritetoEEPROMmemory,andtheEEPROM_Read_Word(), EEPROM_Read_String(), and EEPROM_Read_All()routinesareprovidedtoreadfromEEPROMmemory.TheEEPROMcommands(seeTable1)areprovidedtoallowtheusertowritetoandreadtheEEPROMparameters.Inthetable,thesizeofwordis2bytesandthesizeofchar is 1 byte.
Table 2 – EEPROM Memory Storage
Parameter Address Size Description
EEPROM_SERIAL 0 word Serial numberEEPROM_PINS 2 word Pin default statesEEPROM_WD_TIMEOUT 4 word Watchdog timeout default (secs)EEPROM_WD_RESET_TIME 6 word Watchdog reset time (secs)EEPROM_CAL_V1_MULT 8 word Calibration for V1, multiplierEEPROM_CAL_V1_OFFSET 10 word Calibration for V1, offsetEEPROM_CAL_V2_MULT 12 word Calibration for V2, multiplierEEPROM_CAL_V2_OFFSET 14 word Calibration for V2, offsetEEPROM_CAL_V3_MULT 16 word Calibration for V3, multiplierEEPROM_CAL_V3_OFFSET 18 word Calibration for V3, offsetEEPROM_INIT 20 word EEPROM initialized (12345=yes)EEPROM_BOOT_CMDS 22 char[64] Boot commands string
2.4.6 A/D Converter
ThreeanalogchannelsofA/Dareavailabletoprovidemonitoringvoltagevalues.TheReadVolt() routine handles thereadingofthespecifiedanalogchannelandapplyingthecalibrationconstants.Theroutinetakes1024readingsoftheanalogchannelatarateasfastastheA/Dcansample.Thesereadingsareaveragedandthenalinearcalibrationisappliedusingthemultiplierandoffsetcalibrationvalueforthatanalogchannel.Theresultisanintegervalueinmillivolts.
Thecalibrationmultiplierandoffsetarebasedupontheinputresistorvoltagedivider.Foranalogchannels1and2,a10K/324KΩresistorhalf-bridgeisused.Thenominalcalibrationmultiplierforthesechannelsis:
VIN=(324K+10K)/10K×1024×VREAD=34202×VREAD
16
The1024multiplierisusedtoprovidebetterresolutionundertheintegerarithmeticusedbythePICmicroprocessor.Aftercalibrating,thevalueof34202isreplacedwiththecalibrationmultiplierconstant.Foranalogchannel3,a10K/71.5KΩresistorhalf-bridgeisused.Thisresultsinthefollowingnominalcalibrationmultiplier:
VIN=(71.5K+10K)/10K×1024×VREAD=8346×VREAD
The V command calls the ReadVolt()routinetwice.Thefirstcallistoallowthemultiplexertoselecttheanalogchannelandprovidetimeforthechannelmultiplexertosettledown.Thevaluefromthefirstcallisdiscardedandthevaluefromthesecondcallisused.
2.5 Operation
AtypicaloperationinvolvesconnectingthecontrollertoanRS-232serialportonaremotedatalogger.TheloggerwouldthenbeprogrammedtosendaReturncharacterandconfirmthatitreceivedthe“SPC>”prompt.Theloggerwouldthensendappropriatecommands,suchasturningonandoffpowerchannels,readingthevoltageinputs,andresettingthewatchdogtimer.Thepowerchannelswouldbeconnectedtovariouscomponentsofthesystem.Thewatchdogrelaywouldbeinsertedbetweenthebatteryandthesystemsothatitprovidesafullpowerresetofthesystem.Thecontroller,however,wouldbeconnecteddirectlytothebatterysothatitisalwayspowered.
2.6 Calibration & Initialization
TheEEPROMvaluesareinitializedwiththefollowingcommands:
EWSn àWriteserialnumbern,e.g.,EWS4writesserialnumber4. EWP0 àSetdefaultpinstatestoalloff. EWT3840 àSetwatchdogtimeoutto64mins. EWR60 àSetwatchdogresettimeto60secs. EWC1M34202 àSetdefaultcalibrationvaluesforA/Dchannels. EWC1Z0 EWC2M34202 EWC2Z0 EWC3M8346 EWC3Z0 EWB àSetemptybootcommandsstring. EWI12345 àCodetoindicateEEPROMvaluesareOK. RESET àApplychanges.
Thecontrolleristestedbyoperatingeachsub-systemandconfirmingproperoperation.Acheckoutprocedurewithlogsheet19waswrittentoguideanddocumentthetest.Theswitchingtransistorsaretestedatfullcurrentrating(2A)andfullvoltagerating(60V)simultaneously.TheA/Dchannelsarecalibratedagainstaknownvoltagereferenceatfourvoltageinputvaluesspreadthroughouttheoperatingrange.Alinearregressionisdoneontheresulttoprovidecalibrationconstants,multiplierandoffset,foreachA/Dchannel.ThesecalibrationconstantsarestoredintheEEPROMmemory.
3. RESULTS AND LESSONS LEARNED
Asofthewritingofthisreport,wehavetwoyearsoffielduseofthecontroller,involving12boards.Forthemostpart,thesecontrollershaveworkedsuccessfully,providingruggedpowercontrolandmonitoringoftheReCONplatformstheyhave been used to control.
19 Checkout sheet available here: http://www.glerl.noaa.gov/ftp/publications/tech_reports/glerl-154
17
3.1 Electronic Design Lessons
Theoriginaldesignusedonthefirstfourcontrollersthatwebuiltdidnotincludethezenerdiodeover-voltageprotection(seeD3ofFigure3)acrossthegateandsourceoftheMOSFETpowerswitchingtransistor.Oneofthepowerchannels,operatingat48volts,failedinthelocked-onstatebecauseofthis.Thoughitdidnotfailontheworkbenchorimmediatelyinthefield,thestressingofthegate-sourcejunctionoveranextendedperiodoftimecausedthetransistortofinallyfail.Thezenerdiodewasaddedtopreventthisstress.
TheMOSFETtransistorswerespacedtoocloselytogetherontheboardsothatitwaspossibleforthemetalheat-sinktabsofadjacenttransistorstotoucheachother.Thiswascorrectedbyslightlybendingalternatetransistorssothatthetabswouldn’tbedirectlynexttoeachother.
3.2 Software Lessons
Twosoftwarebugswerediscoveredduringthefirstyearofuse.Onewasaroundingerrorwhenoutputtingthevoltages.Thevoltagesarestoredasintegervaluesinmillivoltsbuttheyareoutputinvoltswithtwosignificantdigits.Theoriginalcodedidnotroundtheleastsignificantdigit,whichresultsinbiasingthevaluelowerthanactual.Codewaswrittentoroundthevaluebeforedisplaying.Thefirstattempt,however,containedabugthatcausedvaluessuchas12999mVtodisplayas12.100insteadof13.00.Thecodewascorrectedafterthefirstfieldyear.
TheothersoftwarebugwouldoccurinthecaseofaserialoverrunontheRS-232serialinput.ThePICmanual20 states thatafteraserialoverrunoccurs,nofurthercharacterscanbereceiveduntiltheCREN(receiveenable)bitiscleared.Thefirstversionsdidnothandlethiserror.CodewasaddedtotesttheOERRserialoverrunflagand,ifanoverrunhasoccurred,toclearandthensetagaintheCRENbit.Thisis,however,arareerrorcondition,anddidnotoccurduringanyofouruseoftheboards.
Afterthefirsttwofieldyears,thesoftwarewasimprovedtoprovidebootcommandsatpower-up.ThiswasprovidedbecauseoneofourReCONsystemscouldnothandlethelargecurrentspikeatpower-upwithallthedefaultcomponentspoweredon.Sequentiallypoweringonthevariouscomponentswouldreducethispower-upspike.Thebootcommandswereaddedtoallowatimed,sequentialpoweringofthedefaultchannels.
Thecurrentsoftwareversion,2.2,hasbeenoptimizedtofitintheprovidedprogramspaceof8192bytes.However,theprogramconsumes8084bytes,whichis98.7%ofthetotalavailableprogramspace.Anyfuturecorrections,improvements,orupdatestothecodewouldneedtobeveryefficientinordertofitinthesmallamountofprogramspaceremaining.OneplacewheremoreprogramspacecouldbefreedupisintheHelpcommand.TheEEPROMcommandlisthasalreadybeenremovedfromtheHelpcommand.Ifmorespaceisneeded,thehelpcommandcouldberemovedfromtheprogramaltogether.
4.0 CONCLUSION
TheSystemPowerControllerboardprovidesaruggedandversatilemeansofcontrollingandmonitoringpowerinadatacollectionsystemandhasprovedreliableintwoyearsoffieldoperations.
20MicrochipPIC16F882/883/884/886/887DataSheet,Section12.1.2.5,MicrochipTechnologyInc.,2009.