PDA

View Full Version : Using WDT as a Temp Sensor?



modifyit
- 16th June 2006, 23:32
Has anyone used the watchdog timer as a temp sensor per AN720?

http://ww1.microchip.com/downloads/en/AppNotes/00720c.pdf

Just curious on the results and if this has been done using PBP. In the mean time I will start trying to write the code myself.

Thanks in advance,

Archilochus
- 17th June 2006, 17:24
Looks like an interesting project. The PBP code should not be difficult to write - remember to disable PBP's automatic watchdog timer clearing function (and then to clear the WDT as needed elsewhere in your code).

Calibrating the setup without a controlled temperature environment seems like it will be rough.
Some of the charts in the app note show a pretty bad deviation at around +30°C, not a good sign as far as reliability goes.

Also - Microchip says:



The linearity of the WDT is not guaranteed, but has been observed.


Not very encouraging. How about the TCxx series of temp sensors from Microchip instead?

Arch

Acetronics2
- 17th June 2006, 20:17
not worse than a using a NTC !!!

Archilochus
- 18th June 2006, 02:21
Was just thinking about this idea some more - couldn't this be used to calibrate PBP's 'SLEEP' and 'NAP' commands?

Arch

modifyit
- 18th June 2006, 03:48
How do I disable PBP autoclear of the WDT?

modifyit
- 18th June 2006, 03:58
Looks like DEFINE NO_CLRWDT is the command

paul borgmeier
- 19th June 2006, 09:15
Also see Melanie's post on getting the WDT to timeout even without the Define set.

@ goto $
http://www.picbasic.co.uk/forum/showthread.php?t=172&highlight=no_clrwdt

I have not read the AN (yet) and am therfore not sure if this is helpful. It sounds like you could do some stuff in your program and then sit in a tight loop and count time outs ...

Paul Borgmeier
Salt Lake City, Utah.
USA

modifyit
- 19th June 2006, 15:12
I'm still trying to figure out how to get this to work. I think undersand the concept of the Microchip AN, but I am having a little difficulty implementing it.

This is my understanding, basically you have two timers WDT and TMR0. TMR is based on a temperature compensated crystal (in my case a temperature compensated INTOSC) and WDT is based on a non temperature compensated RC.

A prescaler in the code is setup so that timer TMR0 rolls over multiple times before the WDT rolls over. By counting the number of times TMR0 rolls over in a WDT period an inference on the temperature can be made.

The confusion I am having is how to setup the WDT correctly. How do I setup the WDT up so that it rolls over without reseting the pic, and how do I tell that the WDT rollover has occured. Since it may matter I am using a 12F675 for this project. I assume I set the pic fuse to not use the WDT to reset the pic, but I am not sure how to use it in my code.

I think I am missing one minor piece and I will be able to get this to work.

Thanks for any help

Archilochus
- 20th June 2006, 01:41
The confusion I am having is how to setup the WDT correctly. How do I setup the WDT up so that it rolls over without reseting the pic, and how do I tell that the WDT rollover has occured. Since it may matter I am using a 12F675 for this project. I assume I set the pic fuse to not use the WDT to reset the pic, but I am not sure how to use it in my code.

I think I am missing one minor piece and I will be able to get this to work.

Thanks for any help

I'm not experienced in assembly, but it looks like the idea in the app note is that you WANT the WDT to cause a PIC reset. Once the PIC is reset by a WDT timeout, you then check to see if the WDT timeout caused the PIC to reset, or if some other condition caused a reset. There are several flags that will tell you whether a PIC has just powered up, or has reset due to various other conditions - one of them being a WDT timeout. See "STATUS" and "PCON" registers in the device data sheet.

You'll need to set the WDT ON in the config fuse.

Arch

modifyit
- 20th June 2006, 02:39
If I am counting the number of times the TMR0 rolls over before a WDT reset, wouldn't I have to use eeprom to save this count variable? It does not seem that this is the intent of the AN to me, so I wonder if there is a way to watch when the WDT rolls over without having it reset the pic.

Archilochus
- 20th June 2006, 03:00
Hi modifyit,
If you check the app note section:

"FIGURE 1: FIRMWARE FLOW DIAGRAM"
there is a flowchart describing how the code works... RESET > TestWDT > Etc

This is from the 12F675 data sheet about resets, and what registers are changed on various resets:



Some registers are not affected in any RESET
condition; their status is unknown on POR and
unchanged in any other RESET. Most other registers
are reset to a RESET state on:
Power-on Reset
MCLR Reset
WDT Reset
WDT Reset during SLEEP
Brown-out Detect (BOD) Reset

They are not affected by a WDT wake-up, since this is
viewed as the resumption of normal operation. TO and
PD bits are set or cleared differently in different RESET
situations as indicated in Table 9-4. These bits are
used in software to determine the nature of the RESET.
See Table 9-7 for a full description of RESET states of
all registers.
A simplified block diagram of the On-Chip Reset Circuit
is shown in Figure 9-4.
The MCLR Reset path has a noise filter to detect and
ignore small pulses. See Table 12-4 in Electrical
Specifications Section for pulse width specification.


Arch

modifyit
- 20th June 2006, 03:15
maybe this is what I am missing: Does the WDT reseting of the PIC clear existing variables? For example will a variable "count" be zeroed out on this reset or will it maintain its value prior to the reset?

modifyit
- 20th June 2006, 04:02
Here is what I've got so far on a 12F675




'defines
DEFINE OSCCAL_1K 1
define OSC 4
DEFINE NO_CLRWDT
'end defines

'includes
'Include "Elapsed.bas"
'end includes

' Config Fuses
@ __config _INTRC_OSC_NOCLKOUT & _CPD_OFF & _CP_OFF & _BODEN_ON & _MCLRE_ON & _PWRTE_ON & _WDT_ON

' Variable Definitions

LED VAR GPIO.1
TEMPERATURE_CNT VAR WORD
TEMPERATURE VAR WORD

'End Variable Defs

' Initialize

INTCON=%10100000
CMCON=7
TRISIO=%11111101 ' Input 0,2,3,4,5 Output 1
ANSEL=0

'End Initialize

ON INTERRUPT GOTO TMR:

OPTION_REG.3=1 ; set WDT prescaler to 1:8
OPTION_REG.2=0
OPTION_REG.1=1
OPTION_REG.0=1

startup:

LED=0

main:

IF STATUS.4=0 THEN ;CHECKS TO SEE IF WDT TIMEOUT OCCURED
TEMPERATURE = TEMPERATURE_CNT ;TEMPERATURE EQUALS COUNT VARIABLE
TEMPERATURE_CNT=0 ;CLEARS COUNT VARIABLE
@CLRWDT ;CLEARS STATUS.4 REG BACK TO 1
ENDIF

IF TEMPERATURE>300 THEN
LED=1 ;IF TEMPERATURE IS ABOVE A DETERMINED COUNT VARIABLE TURN ON LED
ELSE
LED=0
ENDIF

GOTO MAIN


DISABLE INTERRUPT
TMR: ;INTERUPT OCCURS WHEN TMR0 ROLLS OVER
TEMPERATURE_CNT=TEMPERATURE_CNT+1 ;INCREMENT COUNT VARIABLE
INTCON=%10100000 ;CLEAR TMR0 INTERRUPT
resume
ENABLE INTERRUPT

modifyit
- 20th June 2006, 17:55
At this point I can't seem to get the TMR0 timer to work with the code above.