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‘04forWDTPREis‘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
Time-outPeriod
5-bitPrescaler(FWPSA=0
1ms2ms4ms8ms16ms
7-bitPrescaler(FWPSA=1
4ms8ms16ms32ms64ms
PostscalerSetting(WDTPS3:WDTPS0
000000010010
0011010001010110011110001001101010111100110111101111Note:
1:3232ms128ms1:6464ms256ms1:128128ms512ms1:256256ms1.024s1:512512ms2.048s1:10241.024s4.096s1:20482.048s8.192s1:40964.096s16.384s1:81928.192s32.768s1:1638416.384s65.536s1:3276832.768s131.072s
TheWDTtime-outperiodisdirectlyrelatedtothefrequencyoftheLPRCoscillator,
whichinturn,mayvaryasafunctionofdeviceoperatingvoltageandtemperature.PleaserefertotheappropriatePIC24FdevicedatasheetforLPRCclockfrequencyspecifications.
9.2.5

ResettingtheWatchdogTimer
TheWDTcounterandassociatedprescalersandpostscalersarereset:
OnanydeviceReset
WhenaPWRSAVinstructionisexecuted(i.e.,SleeporIdlemodeisenteredWhentheWDTisenabledinsoftware
Onthecompletionofaclockswitch,whetherinvokedbysoftware(i.e.,settingtheOSWENbitafterchangingtheNOSCbitsorbyhardware(i.e.,Fail-SafeClockMonitor
ByaCLRWDTinstructionduringnormalexecutionorduringthelast25%oftheWDTtime-outperiodifWINDISis‘0
9.2.6OperationofWDTinSleepandIdleModes
IftheWDTisenabled,itwillcontinuetorunduringSleeporIdlemodes.WhentheWDTtime-outoccurs,thedevicewillwakethedeviceandcodeexecutionwillcontinuefromwheretheinstructionwasexecuted.
TheWDTisusefulforlow-powersystemdesigns,becauseitcanbeusedtoperiodicallywakethedevicefromSleepmodetochecksystemstatusandprovideactionifnecessary.NotethattheSWDTENbitisveryusefulinthisrespect.IftheWDTisdisabledduringnormaloperation(FWDTEN=0,thentheSWDTENbit(RCON<5>canbeusedtoturnontheWDTjustbeforeenteringSleepmode.
DS39697A-page9-4
AdvanceInformation
©2006MicrochipTechnologyInc.

9.3
AsummaryoftheSpecialFunctionRegistersassociatedwiththePIC24FWDTmoduleisprovidedinTable9-2.
REGISTERMAPS
Table9-2:
Bit13
CMVREGSEXTRSWRSWDTENWDTOSLEEPIDLEBORBit12Bit11Bit10Bit9Bit8Bit7Bit6Bit5Bit4Bit3Bit2Bit1
SpecialFunctionRegisterMapAssociatedwiththeWatchdogTimer
Bit0
POR
AllResets
xxxx(1
FileNameBit15Bit14
RCONTRAPRIOPUWR
WatchdogTimer(WDT
©2006MicrochipTechnologyInc.
Legend:Note1:x=unknownvalueonReset,=unimplemented,readas0’.Resetvaluesareshowninhexadecimal.RCONregisterResetvaluesdependentontypeofReset.
AdvanceInformation
Section9.WatchdogTimer(WDT
DS39697A-page9-5
9

PIC24FFamilyReferenceManual
9.4
DESIGNTIPS
Question1:
Whydoesthedevicereset,eventhoughIhaveinsertedaCLRWDTinstructioninmymainsoftwareloop?
Answer:MakesurethatthesoftwareloopthatcontainstheinstructionmeetstheminimumspecificationoftheWDT(notthetypicalvalue.Also,makesurethatinterruptprocessingtimehasbeenaccountedfor.Question2:
WhataregoodtechniquesforusingtheWDTinmyapplication?
Answer:TherearemanytechniquesforusingtheWDTtopreventapplicationsfromlockinguporrunningaway.Whentheyarecarefullyanalyzed,mostofthemdependonthreebasicprinci-ples:1.
Useone,andonlyone,CLRWDTinstructioninyourapplication.Placingmultipleoccurrencesthroughouttheapplicationmakesitmoredifficulttotroubleshoottime-outissues.
PlacetheCLRWDTinstructioninsidethemainbodyoftheapplicationandnotinsideasubroutineoranInterruptServiceRoutine(ISR.Iftheinstructionislocatedinsideafrequentlycalledroutine,thereisagoodchancethattheWDTwillconstantlyberesetandnevertime-out.
Oncetheapplicationiscompiledandsized,placeunconditionalbranchinstructions(suchas,“GOTO.”throughouttheunusedareaofprogrammemory.Ifsomethingshouldhap-penthatmakesthecode“runaway”bybranchingintounusedcodespace,theGOTOinstructionscanbringthemicrocontrollerbacktoyourcode,wheretheWDTcanhelpbringtheapplicationbackundercontrol.
2.
3.
DS39697A-page9-6
AdvanceInformation
©2006MicrochipTechnologyInc.

Section9.WatchdogTimer(WDT
9.5
RELATEDAPPLICATIONNOTES
Thissectionlistsapplicationnotesthatarerelatedtothissectionofthemanual.TheseapplicationnotesmaynotbewrittenspecificallyforthePIC24Fdevicefamily,buttheconceptsarepertinentandcouldbeusedwithmodificationandpossiblelimitations.ThecurrentapplicationnotesrelatedtotheWatchdogTimer(WDTmoduleare:Title
Low-PowerDesignusingPICmicro®Microcontrollers

ApplicationNote#
AN606
Note:
PleasevisittheMicrochipwebsite(www.microchip.comforadditionalapplicationnotesandcodeexamplesforthePIC24Ffamilyofdevices.
9
WatchdogTimer(WDT
©2006MicrochipTechnologyInc.
AdvanceInformation
DS39697A-page9-7

PIC24FFamilyReferenceManual
9.6
REVISIONHISTORY
RevisionA(May2006
Thisistheinitialreleasedrevisionofthisdocument.
DS39697A-page9-8
AdvanceInformation
©2006MicrochipTechnologyInc.

PIC24F 参考手册, 章节(15)

相关推荐