PIC24F 参考手册, 章节(15)
发布时间:
Section9.WatchdogTimer(WDT
HIGHLIGHTS
Thissectionofthemanualcontainsthefollowingmajortopics:9.19.29.39.49.59.6
Introduction....................................................................................................................9-2WDTOperation..............................................................................................................9-2RegisterMaps................................................................................................................9-5DesignTips....................................................................................................................9-6RelatedApplicationNotes..............................................................................................9-7RevisionHistory.............................................................................................................9-8
9
WatchdogTimer(WDT
©2006MicrochipTechnologyInc.
AdvanceInformation
>>>>>>>>>>>>>>>>>>>>DS39697A-page9-1
>>>>>
PIC24FFamilyReferenceManual
9.1
INTRODUCTION
TheprimaryfunctionoftheWatchdogTimer(WDTistoresetthemicrocontroller,intheeventofasoftwaremalfunction,byresettingthedeviceifithasnotbeenclearedinsoftware.ItcanalsobeusedtowakethedevicefromSleeporIdlemode.TheWDTisafree-runningtimerwhichusesthelow-powerRCoscillatorandrequiresnoexternalcomponents.Therefore,theWDTwillcon-tinuetooperateevenifthesystem’sprimaryclocksource(e.g.,thecrystaloscillatorisstoppedundernormaloperation(e.g.,inSleepmode.AblockdiagramoftheWDTisshowninFigure9-1.
>>>>Figure9-1:
WDTBlockDiagram
LPRCControl
WDTPREPrescaler(5-bit/7-bit
31kHz
AllDeviceResetsTransitiontoNewClockSource
ExitSleeporIdleMode
CLRWDTPWRSAV
SleeporIdleMode
1ms/4ms
WDTCounter
WDTPOST<3:0>Postscaler1:1to1:32.768
WDTOverflowReset
SWDTENFWDTEN
WakefromSleep
LPRCInput
9.2WDTOPERATION
Whenenabled,theWDTwillincrementuntilitoverflowsor“timesout”.AWDTtime-outwillforceadeviceReset,exceptduringSleeporIdlemodes.TopreventaWDTTime-outReset,theusermustperiodicallycleartheWatchdogTimerusingtheinstructions,PWRSAVorCLRWDT.IftheWDTtimesoutduringSleeporIdlemodes,thedevicewillwake-upandcontinuecodeexecutionfromwherethePWRSAVinstructionwasexecuted.
Ineithercase,theWDTObit(RCON<4>willbesettoindicatethatthedeviceResetorwake-upeventwasduetoaWDTtime-out.IftheWDTwakestheCPUfromSleeporIdlemode,theSLEEPstatusbit(RCON<3>orIDLEstatusbit(RCON<2>willalsobesettoindicatethatthedevicewaspreviouslyinaPower-Savingmode.
9.2.1EnablingandDisablingtheWDT
TheWDTisenabledordisabledbytheFWDTEN(CW1<7>Configurationbit.WhentheFWDTENConfigurationbitisset,theWDTisenabled.Thisisthedefaultvalueforaneraseddevice.RefertothedevicedatasheetforfurtherdetailsontheFlashConfigurationWordregisters.
DS39697A-page9-2
>>>>>>>>AdvanceInformation
©2006MicrochipTechnologyInc.
Section9.WatchdogTimer(WDT
9.2.2
SoftwareControlledWDT
IftheFWDTENConfigurationbitisset,theWDTisalwaysenabled.However,theWDTcanbeoptionallycontrolledintheusersoftwarewhentheFWDTENConfigurationbithasbeenprogrammedto‘0’.
TheWDTisenabledinsoftwarebysettingtheSWDTENcontrolbit(RCON<5>.TheSWDTENcontrolbitisclearedonanydeviceReset.ThesoftwareWDToptionallowstheusertoenabletheWDTforcriticalcodesegmentsanddisabletheWDTduringnon-criticalsegmentsformaximumpowersavings.
9.2.3WDTWindow
TheWatchdogTimerhasanoptionalWindowedmodeenabledbyprogrammingtheWINDISConfigurationbit(CW1<6>to‘0’.IntheWindowedmode,theCLRWDTinstructionmustoccurwithinthelast1/4oftheWDTperiod.AnyCLRWDTinstructionthatoccurswithinthefirst3/4oftheWDTperiodwillcauseaWDTReset,similartoaWDTtime-out.Note:
TheWDTmustbeenabled(FWDTEN=1touseWDTWindowedmode.
9.2.4WDTPrescalerandTimerPeriod
TheWDTclocksourceistheLPRCoscillator,whichhasanominalfrequencyof31kHz.Thisfeedsaprescalerthatcanbeconfiguredforeither5-bit(divide-by-32or7-bit(divide-by-128operation.TheprescalerissetbytheFWPSAConfigurationbit(CW1<4>.Witha31kHzinput,theprescaleryieldsanominalWDTtime-outperiod(TWDTof1mswhenWDTPREisclear,or4mswhenWDTPREisset.
AvariablepostscalerdividesdowntheWDTprescaleroutputandallowsforawiderangeoftime-outperiods.ThepostscaleriscontrolledbytheWDTPPOST<3:0>Configurationbits(CW1<3:0>,whichallowstheselectionofatotalof16settings,from1:1to1:32.768.TheWDTPOSTbitsareconfiguredinitiallyduringdeviceprogramming.Usingtheprescalerandpostscaler,time-outperiodsrangingfrom1msto131seconds(nominalcanbeachieved.TheWDTtime-outvaluecanbecalculatedasshowninEquation9-1.AcompletelistofprescalervaluesandtheassociatedWDTtime-outperiodsisshowninTable9-1.>>>>>>>>Equation9-1:
WDTTime-outPeriod
WDTPeriod(ms=PrescalerFactorxPostscalerFactorwhere:
PrescalerFactor
=1forWDTPREis‘0’4forWDTPREis‘1’
PostscalerFactor=1/PostscalerRatio
9
WatchdogTimer(WDT
©2006MicrochipTechnologyInc.
>>>>>>>>AdvanceInformation
DS39697A-page9-3
>>>>>>>>>
PIC24FFamilyReferenceManual
Table9-1:
WDTConfigurationandTime-outPeriod
PostscalerRatio(1/Postscaler
Factor
1:11:21:41:81:16