Using WDT as a Temp Sensor?


Closed Thread
Results 1 to 14 of 14

Hybrid View

  1. #1
    Join Date
    Apr 2005
    Posts
    96


    Did you find this post helpful? Yes | No

    Default

    Here is what I've got so far on a 12F675

    Code:
    '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
    Last edited by modifyit; - 20th June 2006 at 13:04.

  2. #2
    Join Date
    Apr 2005
    Posts
    96


    Did you find this post helpful? Yes | No

    Default

    At this point I can't seem to get the TMR0 timer to work with the code above.

Similar Threads

  1. Need a cheap touch sensor idea.. here it is
    By mister_e in forum Code Examples
    Replies: 20
    Last Post: - 16th April 2016, 22:42
  2. Graphic LCD with PICbasic pro
    By amindzo in forum mel PIC BASIC Pro
    Replies: 41
    Last Post: - 25th November 2012, 11:45
  3. RH/Temp Sensor Example Code
    By Bruce in forum Code Examples
    Replies: 7
    Last Post: - 15th June 2006, 15:55
  4. Temp sensor problem
    By Christopher4187 in forum General
    Replies: 3
    Last Post: - 14th June 2006, 14:49
  5. 1 wire Temp sensor
    By PortlandJohn in forum General
    Replies: 2
    Last Post: - 25th November 2005, 16:21

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts