Thanks Jerry,
Been there and it helped a little bit but I still don't know what the count_remain is.
You could be right but I'm still not sure. To be honest, I don't think anybody knows exactly what it is. I'll just treat it as a Dallas magic number.
I monitored its value and it jumps around from 1 to 16 when the device temperature rises and falls, but when the temperature stabilises, it just sits around 8 to 9.
Anyhow I think I had a major breakthrough.
The temperature of my device right now reads 002AH
temperature2 = (temperature >> 1) effectively divides the value by 2 and gets rid of the radix point and now equals 0015h beacause of this move.
Because Dallas gave us this formula with the assumption everyone can follow it,
I just used it and hoped for the best.
first I moved 0015h left 8 bits so it becomes 1500h
then subtract 2.5 degree C (100h/4 = 40h =0.25C in Hex)
so 1500h minus 0040h = 14C0h
Dallas says count_per_C = 10h and I picked a number for count_remain - 9h
so 10h minus 9h = 7h then Dallas says to multiply this by 100h then divide 10h
okay, 7h * 100h = 0700h then divide by count_per_C (10h) = 0070h
now I have 14C0h + 70h = 1530h
so the 15h = 21C and the decimal part, 30h = 30h/100h = 48/256 = 0.1875 or 0.19
So my display now shows 21.19 C
Code:
DQ VAR PORTB.5 ' One-wire data pin
temperature VAR WORD ' Temperature storage
temperature2 VAR WORD
temperature3 VAR WORD
count_remain VAR BYTE ' Count remaining
count_per_c VAR BYTE ' Count per degree C
fractemp var word
loop:
OWOut DQ, 1, [$CC, $44] ' Start temperature conversion
pause 750 'NEEDED FOR TEMP STABILIZING
waitloop:
OWIn DQ, 4, [count_remain] ' Check for still busy converting
IF count_remain = 0 Then waitloop
OWOut DQ, 1, [$CC, $BE] ' Read the temperature
OWIn DQ, 0, [temperature.LOWBYTE, temperature.HIGHBYTE, Skip 4, count_remain, count_per_c]
temperature2 = (temperature >> 1)
temperature3= (temperature2 <<8 -64) + (((count_per_c - count_remain) * 100) / count_per_c)
fractemp = ((temperature3 <<8 >>8*64) >>8)
lcdout $FE,1, "Raw ", hex(temperature)," ", hex(temperature2), " ", dec(count_remain)
lcdout $FE, $C0, "Real ", dec(temperature2), ".", dec2(fractemp)
goto loop
I don't know how accurate the fraction part is but I reckon the whole number is okay
Bottom line is Jerry, I need someone willing to point out mistakes, offer sugestions or give constructive critisism.
Wilson
Bookmarks