Phil23 Guru
 Joined: 27/03/2016 Location: AustraliaPosts: 1667 |
Posted: 12:02pm 25 Aug 2016 |
Copy link to clipboard |
 Print this post |
|
Hoping someone can provide some feedback on this.
I currently have 2 different MM's each reading 6 DS18B20's on the same bus.
It's all working fine, with only an occasional error ~ once a day.
The failed read returns -0.0625°, all bits set;
HTemp=&b11111111 & LTemp=&b11111111.
I can see this by unplugging a single sensor.
I'm using 2 routines, one to initialise the sensors, the second reads them.
[Code] '========================OneWire Temperature Functions=========================
'Sub Initialises all DS18B20 Sensors on the Bus
'The below will set the resolution
'Onewire Write PinTmp, 2, 5, &HCC, &H4E,&H00,&H00,&HXX
' 9 bit=0.5 :1f - 93.75ms
'10 bit=0.250 :3f - 187.5ms
'11 bit=0.125 :5f - 375.0ms
'12 bit=0.0625:7f - 750.0ms
'
Sub InitTemp
Onewire Write PinTmp, 2, 5, &HCC, &H4E,&H00,&H00,&H7F 'Set the Resolution of all Sensors
OneWire Write PinTmp, 1, 2, &HCC, &H44 'Start Conversion on all Sensors
End Sub
'Function Returns the Termerature for the Serial# passed.
Function ReadTemp(TsSerial As Integer) As Float
Ts1=(TsSerial >> 48) and &hFF : Ts2=(TsSerial >> 40) and &hFF : Ts3=(TsSerial >> 32) and &hFF
Ts4=(TsSerial >> 24) and &hFF : Ts5=(TsSerial >> 16) and &hFF : Ts6=(TsSerial >> 8) and &hFF : Ts7=(TsSerial) and &hFF
'OneWire Write PinTmp, 1, 10, &H55,&H28,Ts1,Ts2,Ts3,Ts4,Ts5,Ts6,Ts7,&H44
'Check sensor is ready
Timer=0 : Status=0
Do
If Timer > 1000 Then Error "Sensor Error"
OneWire Read PinTmp,4,1,Status ' Conversion status
Loop Until Status = 1
' Do
' 'Just pause for a second
' Loop Until Timer>1000
OneWire Write PinTmp,1,10, &H55,&H28,Ts1,Ts2,Ts3,Ts4,Ts5,Ts6,Ts7,&HBE
OneWire Read PinTmp, 2, 2, LTemp, HTemp
'Calculate the Temp in C
ReadTemp=((HTemp And &b111) * 256 + LTemp) / 16
' If HTemp And &b1000 Then ReadTemp=-ReadTemp 'Adjust if negative
If HTemp And &b1000 Then ReadTemp=(ReadTemp-128) 'Adjust if negative
' Print ReadTemp
' Print HTemp,LTemp
' Print Bin$(HTemp,8),Bin$(LTemp,8)
'
End Function
'=============================================================================
[/code]
This is the fragment that I have my doubts about.
[Code] 'Check sensor is ready
Timer=0 : Status=0
Do
If Timer > 1000 Then Error "Sensor Error"
OneWire Read PinTmp,4,1,Status ' Conversion status
Loop Until Status = 1
[/code]
Can't see what it's reading the status of, as far as the 6 sensors are concerned.
All have been initialised, and would all be active on the bus.
It's not until this point,
[Code] OneWire Write PinTmp,1,10, &H55,&H28,Ts1,Ts2,Ts3,Ts4,Ts5,Ts6,Ts7,&HBE[/code]
that the other 5 go offline, before the temperature is read.
[Code] OneWire Read PinTmp, 2, 2, LTemp, HTemp[/code]
Like I said, it's all working fine & has been for a few months, but I'd prefer it be correct & would like to correctly check for an unplugged sensor in a better way than just looking for -0.0625°C, because in reality that will be a true temperature reading during overnight temperature transitions.
Thanks
Phil.
Edit:- Note there's a few things commented out, debugging etc ...
Edited by Phil23 2016-08-26 |