Measuring Temperature Using The Watchdog Timer (WDT) : Theory
Measuring Temperature Using The Watchdog Timer (WDT) : Theory
Measuring Temperature Using The Watchdog Timer (WDT) : Theory
THEORY
Author: Ian Lao
Microchip Technology Inc. The WDT is an 8-bit timer with an 8-bit prescaler
Chandler, AZ option, driven from a free running on-chip RC oscillator.
This oscillator is completely independent of pins OSC1/
CLKIN, OSC2/CLKOUT, and the INTRC oscillator. As
INTRODUCTION with any RC oscillator, variances in temperature will
affect the frequency of the circuit. Cumulative effects
This application note shows how Microchip Technol- will therefore, show up as a change in the time-out
ogy’s Watchdog Timer (WDT) can be used to acquire period of the WDT.
rough temperature measurements.
By utilizing another timer as a reference, a sample may
Recent advances in sensor technology have allowed be established, whereby changes in the WDT time-out
for the development of many different sensors to mea- period can be measured. Calibrated temperature can
sure temperature. However, almost all of these are then be derived via Equation 1.
implemented as dedicated function sensors.
Microchip has now developed a method of combining EQUATION 1:
both rough temperature sensing and microcontroller
functionality on the same device, without the need for CC = COUNT*Scalar - Offset
external components. CC => calibrated count value
Preliminary analysis of the on-board WDT shows a C => COUNT; number of times TMR0 has rolled over
piece wise linear correlation between temperature and Offset => calibration offset due to voltage variance or
the time-out period of the WDT. The WDT time-out self-heating (determined by testing against a known
period appears to increase for a fixed VDD as tempera- fixed temperature)
ture increases. Tests indicate that this property may be Scalar => calibration scalar due to process or applica-
used for cost effective rough temperature sensing. tion design ("slope" determined by testing 2 known
The WDT module is similar across many families of temperatures)
microcontrollers from Microchip. This allows for a wide Process variations across lots, part families, and differ-
range of different applications to be developed using ent cores are expected. Since the WDT is clocked by
the same technique. an RC oscillator, these differences are expected to
Though actual application results may differ, an accu- influence the "slope" of the piece wise linear WDT
racy of up to +1°C may be seen. The linearity of the response (see Figure 5A and Figure 5B).
WDT is not guaranteed, but has been observed.
HARDWARE REQUIRED
Note: It is up to the user to test the device in the
system to determine accuracy/usability. 1. Voltage/temperature regulated power supply
2. Temperature-compensated oscillator or crystal
clock source
RESET
Configure
TMR0 & WDT
No
WDT? Initialize
Start Timers
Yes
Temp.
No Normal WDT
Testing
WDT? Handler
No TMR0
Rollover?
Yes
WDT
Yes
Time-out
Service
Increment Routine
Counter
Apply count to
calibration equation
605
585
counts
565
545
(counts)
525 Part 1
Un-calibrated
505 Part 2
485
Uncalibrated
Part 3
465
Part 4
445
Part 5
425
405 Part 6
385 Part 7
Part 8
0
-20
-10
10
20
30
40
50
60
70
Temp (°C)
Temp
Uncalibrated counts
1000.0000
950.0000
900.0000
Uncalibrated (counts)
20
30
40
50
60
70
-20
-10
Temp (°C)
750 Part 1
Uncalibrated (counts)
Part 2
700 Part 3
Part 4
650
Part 5
600 Part 6
Part 7
550 Part 8
500
2.5 3 3.5 4 4.5 5
Power Supply Voltage
Data Spread
points (counts)
30
datapoints
25
data
20
Real Units
rawraw
part2
of 500
15 part5
Std deviation500
part6
of
10
Std deviation
0
10
20
30
40
50
60
70
80
90
100
110
0
-20
-10
Temperature
Temperature (°C)
COUNT/deg
COUNTS/Degree C
°C (V D D = 5.0V)
2.5
2.45
count/(°C)
COUNT/deg C
2.4
2.35
2.3
1 2 3 4 5 6 7 8
part
1300
1280
offset
1260
1240
1220
1 2 3 4 5 6 7 8
part
00001
;*************************************************************************************
00002 ;This program demonstrates how the WDT and TMR0(reference timer) may be used for
00003 ;rough temperature measurements. No filtering/debounce or algorithm is applied on
00004 ;the raw data. The raw un-calibrated COUNTS are output to a PIC16C54C for transmittal
00005 ;to a PC. GP<1:0> are used for data communication and GP3 is used as an output
;enable.
00006 ;In typical applications, users will need to add code to cover WDT time out when not
00007 ;taking rough temperature measurements. WDT tracking register WDTSTAT bit 0 used to
00008 ;indicate if WDT timeouts are being used for rough temp measurements or in the normal
00009 ;application.
00010 ;
00011 ;
00012 ; Program: TSTAT2~1.ASM
00013 ; Revision Date: 9/7/99 Compatibility with MPlab 4.11
00014 ;
00015 ;
00016 ;
00017
;*************************************************************************************
00018
00019
00020 LIST P=PIC12C509A;, F=INHX8M
00021 #include "P12C509A.INC"
00001 LIST
00002 ; P12C509A.INC Standard Header File, Version 1.00 Microchip Technology, Inc.
00108 LIST
00022
0FFF 0FFE 00023 __CONFIG _MCLRE_OFF & _CP_OFF & _WDT_ON & _IntRC_OSC
00024
00025 ;;
00026 ; declare registers
00027
00028 ;Note *
00029 ; All core program variables in page 0
00030 ;
00031
00032 cblock 0x07 ;bank 0
0000 0025 00051 movwf OSCCAL ;load osc calibration for IntRC
0001 0C01 00052 movlw b’00000001’ ;clear bus driver latch
0002 0026 00053 movwf GPIO ;
0003 0CFF 00054 movlw b’11111111’ ;disable bus drivers
0004 0006 00055 tris GPIO ;
0005 04A3 00056 bcf STATUS,PA0 ;set bank pointers to page 0
0006 04A4 00057 bcf FSR,5 ;set address map to page 0
0007 04C4 00058 bcf FSR,6
0008 0A09 00059 goto Resetvector
00060
00061 ;;
00062 ; main memory
00063
00064
00065 ;reset vector
0009 00066 Resetvector ;
00067
0009 0C8B 00068 movlw b’10001011’ ;load option register word
000A 0002 00069 option ;
00070
00071 ;check for power on reset
000B 0783 00072 btfss STATUS,NOT_TO ;must test condition of TO=1
000C 0A1B 00073 goto Wdtest ;to tell if power on reset.
00074 ;there is no sleep mode support.
00075 ;if not a POR, must be a WDT reset.
00076 ;jump to the POR or WDT routines.
00077
00078 ;;
00079 ;power on reset handler
000D 00080 P_reset ;initializtion routine
00081
000D 0C00 00082 movlw 0x00 ;clear counters for measurement
000E 0027 00083 movwf T_COUNT ;
000F 0028 00084 movwf T_COUNT+1 ;
0010 002C 00085 movwf WDTSTAT ;clear wdt tracking register
00086
00087
0011 050C 00088 bsf WDTSTAT,0 ;set tracking register bit 0 to
00089 ;indicate that wdt timeouts are being
00090 ;used for rough temp measurements.
00091 ;This register is typically set elsewhere
00092 ;in a real application but for the
00093 ;purposes of this example, is set here.
00094
00095
00096 ;init timers
0012 0004 00097 clrwdt ;initialize wdt
0013 0C00 00098 movlw 0x00 ;initialize timer0
0014 0021 00099 movwf TMR0 ;and allow to free run
00100
0015 0A16 00101 goto $+1 ;delay to let tmr0 go past
0016 0A17 00102 goto $+1 ;screen point
0017 0A18 00103 goto $+1 ;
00210
00211
0047 00212 Test_lo_u ;check for clock strobe from receiving
00213 ;unit. Clock must be lo. Then go hi.
00214
0047 0004 00215 clrwdt
0048 0206 00216 movf GPIO,W ;test for clock lo to see if ready
0049 002A 00217 movwf DUMP ;put in temp register
004A 060A 00218 btfsc DUMP,0 ;
004B 0A47 00219 goto Test_lo_u ;
00220 ;
00221
004C 00222 Test_hi_u ;check for clock strobe. Send only on lo to
00223 ;hi clock transition
00224
004C 0004 00225 clrwdt
004D 0206 00226 movf GPIO,W ;test for clock hi to see if send
004E 002A 00227 movwf DUMP ;put in temp register
004F 070A 00228 btfss DUMP,0 ;
0050 0A4C 00229 goto Test_hi_u ;
00230 ;
00231
0051 00232 Upper_8_send ;xmit data 1 bit at a time by rotating thru
00233 ;carry and checking it’s value
00234
0051 0426 00235 bcf GPIO,1 ;reset data line
0052 0328 00236 rrf T_COUNT+1,F ;rotate into carry to test for 1 or 0
0053 0603 00237 btfsc STATUS,C ;test for 1 or 0
0054 0526 00238 bsf GPIO,1 ;clear sending bit
0055 0000 00239 nop
00240 ;
00241
00242
0056 0A2F 00243 goto Clock_en ;return to send next data
00244 ;
00245 ;
00246
00247
00248
00249 ;;
00250 ;counting routine
0057 00251 Countimer
00252
00253 ;test to see if timer0 rolls over
0057 00254 Tmr0_byte ;count the number of tmr0’s
00255
0057 0201 00256 movf TMR0,W ;copy tmr0 value to working register
0058 0029 00257 movwf SCREEN ;
0059 0C0A 00258 movlw 0x0A ;load masking value
005A 0089 00259 subwf SCREEN,W ;subtraction to screen for FF -> 0
00260 ;transition in tmr0
005B 0603 00261 btfsc STATUS,C ;test carry flag for
005C 0A57 00262 goto Tmr0_byte ;loop back and test for FF -> 0
00263
00264 ;increment count lo byte
005D 02A7 00265 incf T_COUNT,F ;incr count (lo byte) once for every
00266 ;tmr0 roll over
005E 0743 00267 btfss STATUS,Z ;test zero flag to see if need to
00268 ;increment hi byte of count (16 bit counter)
005F 0A57 00269 goto Tmr0_byte ;loop back and test until wdt reset
00270
00271 ;increment count hi byte
0060 02A8 00272 incf T_COUNT+1,F ;incr count (hi byte) once for every
00273 ;T_COUNT roll over
0061 0A57 00274 goto Tmr0_byte ;loop back and test until wdt reset
00275
00276
00277 ;;
00278 ;soft reset routine
0062 00279 Softreset ;clear conditions and reset for another
00280 ;rough temperature measurement
00281
0062 0004 00282 clrwdt ;clear the wdt
0063 0A0D 00283 goto P_reset ;return to reset checks
00284
00285
00286 ;;
00287 ;non-temp measurement mode wdt handler
0064 00288 Nontempwdt
0064 0A64 00289 goto $ ;normal mode wdt timeout handler.
00290 ;since only running in rough temp measure
00291 ;mode, routine is just a place holder.
00292
00293
00294 ;;
00295 end
Errors : 0
Warnings : 0 reported, 0 suppressed
Messages : 0 reported, 0 suppressed
01/30/01
All rights reserved. © 2001 Microchip Technology Incorporated. Printed in the USA. 2/01 Printed on recycled paper.
Information contained in this publication regarding device applications and the like is intended through suggestion only and may be superseded by
updates. It is your responsibility to ensure that your application meets with your specifications. No representation or warranty is given and no liability is
assumed by Microchip Technology Incorporated with respect to the accuracy or use of such information, or infringement of patents or other intellectual
property rights arising from such use or otherwise. Use of Microchip’s products as critical components in life support systems is not authorized except with
express written approval by Microchip. No licenses are conveyed, implicitly or otherwise, except as maybe explicitly expressed herein, under any intellec-
tual property rights. The Microchip logo and name are registered trademarks of Microchip Technology Inc. in the U.S.A. and other countries. All rights
reserved. All other trademarks mentioned herein are the property of their respective companies.