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