Detection of 1 wire device
I have a single 18B20 temp sensor and read the device using the code below
Code:
'Get and display the temperature
GIE = 0
OWOUT DQ, 1, [$CC, $44] ' Start temperature conversion
OWOUT DQ, 1, [$CC, $BE] ' Read the temperature
OWIN DQ, 0, [temperature.LOWBYTE, temperature.HIGHBYTE]
GIE = 1
temperature = temperature */ 1600
lcdout $FE,$D4+0,"TEMP ",dec(temperature / 100),$DF,"C"
What I would like to do is detect if the sensor is connected or not, and if it's not present to simply display "N/C" in place of the temperature
Any suggestions
Re: Detection of 1 wire device
Each device has it's unique serial number, you could try read it or write something in the scratch pad (just once) and try read it back.
Re: Detection of 1 wire device
From the manual, the OWIN command...
Quote:
If a device is not present, OWIN can jump to an optional Label.
You should be able to just use the Label function of the OWIN command to have your program jump to a routine that displays "N/C"
Code:
'Get and display the temperature
GIE = 0
OWOUT DQ, 1, [$CC, $44] ' Start temperature conversion
OWOUT DQ, 1, [$CC, $BE] ' Read the temperature
OWIN DQ, 0, [temperature.LOWBYTE, temperature.HIGHBYTE], NoDevice
GIE = 1
temperature = temperature */ 1600
lcdout $FE,$D4+0,"TEMP ",dec(temperature / 100),$DF,"C"
NoDevice:
lcdout $FE,$D4+0,"No One Wire Device Detected"
GOTO main
Re: Detection of 1 wire device
Thanks for the replies.
Dwight, I tried your example, but all that happened was a mixture of the text on line 4 of the LCD. I'll keep experimenting maybe taking the NoDevice a gosub rather than goto... But thanks for putting me on the right track
Re: Detection of 1 wire device
I'm sure you would get a better result if you actually waited for the ds18b20 to perform the measurement
Code:
'Get and display the temperature
GIE = 0
OWOUT DQ, 1, [$CC, $44] ' Start temperature conversion
pause 800
OWOUT DQ, 1, [$CC, $BE] ' Read the temperature
OWIN DQ, 0, [temperature.LOWBYTE, temperature.HIGHBYTE]
GIE = 1
temperature = temperature */ 1600
lcdout $FE,$D4+0,"TEMP ",dec(temperature / 100),$DF,"C"
Re: Detection of 1 wire device
Cheers Richard,
I stumbled across a PDF on one wire devices from Microchip, and it suggested the following
Code:
OW_reset_pulse
Describes 1-Wire protocol to generate Reset pulse to detect the presence of the 1-Wire slave device.
Syntax
unsigned char OW_reset_pulse(void)
Parameters
None
Return Values
Return ‘
0
’ if the slave device presence pulse is detected, return ‘
1
’ otherwise.
Precondition
None
Side Effects
None
Example
// OW_reset_pulse function return the presence pulse from the slave device
if (!OW_reset_pulse())
return HIGH; // Slave Device is detected
else
return LOW; // Slave Device is not detected
But this uses ASM, so I'll do some further reading on PBP to see if this can be done in basic rather than ASM
Re: Detection of 1 wire device
I've been reading through the PBP manual and it really peaves me when manuals state
Quote:
If a device is not present, OWIN can jump to an optional Label.
But doesn't give you a working example !!
So it would suggest the reset command would be the best option to ping the device and if it's not present it won't get an answer back
Re: Detection of 1 wire device
Not sure if the logic is correct but this works
[code]
'Get and display the temperature
GIE = 0
owin DQ, 1, [],NoDevice
OWOUT DQ, 1, [$CC, $44] ' Start temperature conversion
OWOUT DQ, 1, [$CC, $BE] ' Read the temperature
OWIN DQ, 0, [temperature.LOWBYTE, temperature.HIGHBYTE]
GIE = 1
temperature = temperature */ 1600
lcdout $FE,$D4+0,"TEMP ",dec(temperature / 100),$DF,"C"
'************************************************* ****************************** '
fan:'check to see if fan is needed
fantrigger=fanset
if (temperature / 100)> fantrigger then
high portA.4
endif
**********************************************
NoDevice:
lcdout $FE,$D4+0,"TEMP N/C "
GIE = 1
goto fan
**********************************************
[code]
The NoDevice section is outside of the main part of the program. The logic being that the PIC sends a reset pulse and if it's not received back then jumps out to the NoDevice section, and then goes to the next part of the code but skips the temperature reading section. Seems to work when I pull out the DS18B20 and then plug it back in :)
Re: Detection of 1 wire device
Hi
I use this, and it work's
check_sensorID:
'************************************************* ****************************
' Check is the sensor connected
'************************************************* ****************************
OWOUT DQ, 1, [ $33 ] ' Read Chip Family code
OWIN DQ, 2, [ FAM,ID[6],ID[5],ID[4],ID[3],ID[2],ID[1],CRC]
if (ID[1] = 0)and (ID[2] = 0)and(ID[3] = 0)and (ID[4] = 0)and (ID[5] = 0)and (ID[6] = 0) then
LcdOut $FE, 1, " NO " ' Show message
Lcdout $FE, $C0, " Sensor "
endif
return
Kent
Re: Detection of 1 wire device