PDA

View Full Version : DS18S20 & Parasite Power



CocaColaKid
- 16th August 2005, 20:11
I've tried using the parasite power option and can not seem to get it to work at all. Is there something I'm missing from my code? It works fine using three wire but not two.



read_temp:
owout portb.7,1,[$CC, $44] ' Send start temperature conversion
owout portb.7,1,[$CC, $BE] ' Send read scratchpad command
for x = 0 to 8 ' Process all 9 bytes
owin portb.7,0,[i] ' Read the scratch pad
dq[x] = i ' Place read byte into the array
next x ' Do again until all 9 bytes are processed
temp.Byte0 = dq[0] : temp.byte1 = dq[1] ' Store bytes 0 and 1 in the temp word variable
if temp.8 = 1 then ' If bit8 of temperature is set then its negative
sign = "-" ' Indicate temperature is NEGATIVE
temp.lowbyte = temp.lowbyte ^ 255 ' Reverse the bits of the lowbyte of TEMP
sign = " " ' Indicate temperature is POSITIVE
endif
half = temp.0
temp = ((temp.lowbyte) >> 1) * 10 ' Shift the lowbyte of the result right 1 place
temp = temp + (half * 5) ' Strip off bit 0 (0.5 degree) and add it to DEC

CocaColaKid
- 18th August 2005, 13:43
I figured it out. I wasn't sure if would work with the ONIN/OWOUT commands or not but it appears it works just fine. I'm now running a sensor 25ft away on a Cat5 computer cable. All I was missing was the part where I had to drive the Dallas chip to the rail for a period of 600ms.



read_temp:
owout portb.7,1,[$CC, $44] ' Send start temperature conversion
low portb.6 ' Turn on transistor connected to rail
pause 600 ' Allow enough time for Tconv
high portb.6 ' Turn off transistor
owout portb.7,1,[$CC, $BE] ' Send read scratchpad command
for x = 0 to 8 ' Process all 9 bytes
owin portb.7,0,[i] ' Read the scratch pad
dq[x] = i ' Place read byte into the array
next x ' Do again until all 9 bytes are processed
temp.Byte0 = dq[0] : temp.byte1 = dq[1] ' Store bytes 0 and 1 in the temp word variable
if temp.8 = 1 then ' If bit8 of temperature is set then its negative
sign = "-" ' Indicate temperature is NEGATIVE
temp.lowbyte = temp.lowbyte ^ 255 ' Reverse the bits of the lowbyte of TEMP
sign = " " ' Indicate temperature is POSITIVE
endif
half = temp.0
temp = ((temp.lowbyte) >> 1) * 10 ' Shift the lowbyte of the result right 1 place
temp = temp + (half * 5) ' Strip off bit 0 (0.5 degree) and add it to DEC