Readinternal Temperature

comet

New Member
Hi to all!
In Manual 3 is the readinternal temperature function. There are Examples but no Values. I can do it of course, but if anyone has calulate it with Resultat, please give a Tipp.
Bye Juergen
 

papaof2

Senior Member
Code to read and process internal temperature for display. NOT MINE! UNTESTED!
Not sure where I copied it from, just have it in my folder of "might be useful" code snippets.

Code:
picaxe 20m2
#no_data
symbol ADRESL = $3b        ; A-D converter
symbol ADRESH = $3c
symbol ADCON0 = $3d
symbol ADCON1 = $3e
symbol FVRCON = $57        ; Includes Temperature sensor TSEN & TSRNG flags

do
;pokesfr ADCON1, %10010000     ; Right justify;clock/8; REF=Vdd to Vss
;pokesfr FVRCON, %00100000    ; Enable Temperature sensor with 2 diodes
;pokesfr ADCON0, %01110100     ; Select Temperature input
;pokesfr ADCON0, %01110101      ; Turn ADC On
;pokesfr ADCON0, %01110111     ; Start conversion
;peeksfr ADRESH,b3         ; Read upper byte
;peeksfr ADRESL,b2         ; Read Low byte

pokesfr FVRCON, %00110000    ; Enable Temperature sensor with 4 diodes THIS IS ESSENTIAL FOR CORRECT W3 !
;                                                **********************************
;pokesfr ADCON0, %01110111     ; Start conversion
;peeksfr ADRESH,b5         ; Read upper byte
;peeksfr ADRESL,b4        ; Read lower byte

    readinternaltemp it_raw_L,0,w3    ; ACTUALLY READS RAW_H
    readinternaltemp it_raw_H,0,w4    ; ACTUALLY READS RAW_L
    readinternaltemp it_4v0,0,w5        ; ********************

    calibadc10 w0

    w0 = w0 + 2 / 4        ; Round and scale down the supply voltage (or just use calibadc (8 bits))
    w6 = 1023 - w4 * 97    ; With 4.1v supply rail: 97 = 4 (mV/step) / 2.64 (mV/degC) * 64 (calibadc)
    w7 = w6 / w0        ; Correct for the Supply voltage
    b16 = 477 - w7        ; Negate and Subtract Diode Offset Voltage (empirically)

    w9 = 1023 - w3 * 49    ; With 4.1v supply rail: 49 = 4 (mV/step) / 5.28 (mV/degC) * 64 (calibadc)
    w10 = w9 / w0         ; Correct for the Supply voltage
    b17 = 490 - w10        ; Negate and subtract Diode Offset Voltage

    sertxd(#w0," ",#w1," ",#w2," ",#w3," ",#w4," ",#w5," ",#w6," ",#w7," ",#b16," ",#w9," ",#w10," ",#b17,cr,lf)
    pause 1000
   
loop

#rem   Sample output at room temperature

60 0 0 454 744 289 27063 451 26 27881 464 26
60 0 0 455 744 289 27063 451 26 27832 463 27
60 0 0 454 744 289 27063 451 26 27881 464 26
 

AllyCat

Senior Member
Hi,

IMHO the READINTERNALTEMP function is completely useless unless you are using a precison supply rail.

I looked into it in great detail over a period of many years and started THIS THREAD.

But I still considered the function beyond redemption so created a new function which I called CHIPTEMP{10} in the Code Snippets section.

Then Microchip released a new Application Note for the temperature module which I discussed HERE.

I've forgotten some of the details now but there should be more than you could possibly want in the above three threads and the links from them. :)

Cheers, Alan.
 

comet

New Member
Thank you, I know thats not for good measurements. But its usefull for some testings till the right Sensor is delivered.
Bye Juergen
 

hippy

Technical Support
Staff member
I know thats not for good measurements. But its usefull for some testings till the right Sensor is delivered.
One option which can sometimes help with Proof of Concept code is to implement temperature reading as a routine which can be called and will cycle through various temperature values when called, something like -
Code:
ReadTemperature:
  LookUp b13, (10, 15, 20, 255), temperature
  If temperature >= 255 Then
    b13 = 0
    Goto ReadTemperature
  End If
  b13 = b13 + 1
  Return
You may need to use something other than 'b13' as the index and may need to adjust the numbers in the LOOKUP and following IF to suit the temperature value you wish to see.
 

comet

New Member
Thank to all, I will do it in a few Days. Very interesting!
And Thanks to all for the fast answers.
Bye Juergen
 
Top