PDA

View Full Version : 18B20 temperature sensor and PIC



boban
- 30th May 2007, 23:16
Hello, does anyone has an experience with the 18B20 temperature sensor? I have big problem, that the temperature measured with this sensor is approx. by 5 degrees celsius bigger, than the reality. Dont know why. Here is the part of code, whic I am using to compute the temperature:

OWOUT HEATING_SENSOR, 1, [$CC, $44] 'Skip ROM search & do temp conversion
Wait_Up:
OWIN HEATING_SENSOR, 4, [Busy] 'Read busy-bit
IF Busy = 0 THEN goto Wait_Up 'Still busy..?, Wait_Up..!
OWOUT HEATING_SENSOR, 1, [$CC, $BE] 'Skip ROM search & read scratchpad memory
OWIN HEATING_SENSOR, 2, [TEMP1_WORD.Lowbyte, TEMP1_WORD.Highbyte] 'Read two bytes to Temp1_word variable
CURRENT_TEMPERATURE = (TEMP1_WORD / 16)*10 'resolution is 16
TEMP1_BYTE = TEMP1_WORD // 16 'store temporarilly remainder
lookup TEMP1_BYTE, [0,0,1,1,2,3,3,4,5,5,6,7,7,8,9,9,9], TEMP2_BYTE
CURRENT_TEMPERATURE = CURRENT_TEMPERATURE + TEMP2_BYTE / here is the temperature value e.g. for 23,8 degrees celsius in this variable is 238

skimask
- 31st May 2007, 00:33
What reading do you get when you put the sensor in a glass of ice water?

rgregor
- 4th June 2007, 13:51
Hello, thanks for the answer. I finally found, what was the problem. The sensor was connected very close to the stabiliser 7805, which produced the temperature, and if even the sensor was outside the box, the temperature has been injected to it via the cu wires ( approx 1 cm ). So just I replaced the cu wires with the normal one and make them longer ( approx. 10 cm ) and the problem is not there any more. Thanks, Robert