PDA

View Full Version : DS18B20 VS DS18S20 & multiple



RFsolution
- 5th February 2008, 21:50
Hi,

I'm trying to read 2 DS18S20 on a single 1wire bus

I succeed in reading DS1820 in 12bit mode,
But unable to read a DS18S20 in 9bit

Anyone out who has an example code ?

Thanks

Darrel Taylor
- 5th February 2008, 22:08
Are you saying that this didn't work?

http://www.picbasic.co.uk/forum/showthread.php?p=47692
<br>

RFsolution
- 5th February 2008, 22:17
Hi Darrel

well I only have DS18S20 or DS1820

The DS1820 works with the following code but ofcourse in 12bit
the DS18S20 does not return a valid temperature or some value chaning by it temperature
any idea ?

this is the working code with a DS1820

DS18B20_9bit CON %00011111 ; 93.75ms, 0.5°C
'DS18B20_10bit CON %00111111 ; 187.5ms, 0.25°C <-- My favorite
'DS18B20_11bit CON %01011111 ; 375ms, 0.125°C
'DS18B20_12bit CON %01111111 ; 750ms, 0.0625°C (default)

OWOUT DQ, 1, [$CC, $4E, 0, 0, DS18B20_9bit]

DS18S20:
OWOut DQ, 1, [$CC, $44] ' Start temperature conversion

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]

' Calculate temperature in degrees C to 2 decimal places (not valid for negative temperature)
temperature = (((temperature >> 1) * 100) - 25) + (((count_per_c - count_remain) * 100) / count_per_c)


HSerOut [#Temperature.Lowbyte," ",#Temperature.Highbyte," ",DEC (temperature/100),".",DEC2 temperature," C",13]
goto test

Darrel Taylor
- 5th February 2008, 22:28
The DS1820/DS18S20 are 9-bit devices.
By using the count_per_c and count_remain values, you can extend the range to 12-bit.
But if you just want the 9-bit value, you don't need them.

Only the DS18B20 has a settable resolution, that also reduces the conversion time as the resolution is reduced.

The older DS1820/DS18S20 do not have that feature, and will always have a 750ms conversion time, so using a lower resolution doesn't really help anything.
<br>

RFsolution
- 5th February 2008, 22:39
Ok Darrel well it is all about conversion time I dont need more than a 1 degree resolution
but conversiontime is important.

Meanwhile I ordered some 18B20 versions

Still dont get why my code does not work when I simple replace my DS1820 by a DS18S20

Further , can you point me out how to read 2 sensors on 1 bus,again here
conversiontime is imporant,resolution not

Thanks

Walter

Darrel Taylor
- 5th February 2008, 23:01
... can you point me out how to read 2 sensors on 1 bus ...
Well, my first instinct is to say "Don't Do It". :eek:

The overhead involved, is HUGE.
You'll end up using 2-3K words of program space just doing the SearchRom, saving the serial number to RAM/EEPROM, then sending those serial numbers each and every time you access either one of the sensors.

It's so much easier to just use another pin.
And with separate pins, the program automatically knows which sensor it's talking too.
With multiple devices on a single buss, there's no easy way to tell which sensor is in which location (without human intervention).

But with that said, if you only have the one pin available?
Here's where you need to start ...

1 Wire Search Routine (Dave)
http://www.picbasic.co.uk/forum/showthread.php?t=520

Dallas 1-wire search Routine (jimbab)
http://www.picbasic.co.uk/forum/showthread.php?t=3671

RFsolution
- 7th February 2008, 22:43
Thanks Darrel

Well I only have 1 pin free but will use only 1 sensor then

As i'm polling with HSER several AD value's and I/O if was wondering to speed up the
polling if it should not be possible to exit the loop when count_remain is not finished yet
and send meanwhile the previous temperature value as reply to the serial poll for temperature

once count_remain is 0 then update the temp value

should this be done by an interupt routing when count remain = 0 ?