PDA

View Full Version : Ds18b20..



karenhornby
- 17th June 2008, 22:30
I've seen many examples of code for the DS18B20 and I've successfully made it work before
However there is one thing I dont understand and could someone please explain it to me?
IN this code

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)
I can see how the various resolutions are BUT when it comes to this line

OWOUT DQ, 1, [$CC, $4E, 0, 0, DS18B20_9bit
HOW do I tell it I want to have 10 or 11 or 12 bit resolution?

Darrel Taylor
- 17th June 2008, 22:42
Hi Karen,

First you need to uncomment ALL the constants.

Then in the OWOUT statement, just change the DS18B20_9bit to the desired resolution.

DT

P.S. don't forget the trailing bracket ]

karenhornby
- 18th June 2008, 09:05
OMG how can i be so dumb sometimes!
it was So obvious that I just didn't see it
Thank you :)
umm btw what do you mean about the trailing bracket? ]

mackrackit
- 18th June 2008, 09:53
umm btw what do you mean about the trailing bracket? ]
Look at you second bit of code in post #1. I think that is what he means.

karenhornby
- 18th June 2008, 14:40
Am I right in assuming IF i dont use the constants then it would default to 0.0625°C resolution and take 750ms to take a reading?
BUT IF I want to change the resolution I'd use the constants, but the code would be

OWOUT DQ, 1, [$CC, $4E, 0, 0, DS18B20_9bit]
OR OWOUT DQ, 1, [$CC, $4E, 0, 0, DS18B20_10bit] etc?
and this would take 187.5ms?

OK figured out $33 is skip rom command, and $4E is Write scratchpad
but what's the 0,0 after it?


ANd IF I was using more than 1 temp sensor then it would be something like

OWOUT DQ, 1, [$55,$28,$B1,$FE,$22,$00,$00,$00,$5D,$44, $3F ]
; or do I HAVE to use the DS18B20_10bit instead of $3F?
Assuming the ROM address is $B1,$FE,$22,$00,$00,$00?

I know that Match ROM is $55, Read ROM is $33, and Search Rom is $F0

And I know the $44 at the end is telling it to start a temperature conversion


Sorry for asking so many questions

karenhornby
- 18th June 2008, 16:29
THINK I've sussed a bit more:
IF I want to change the resolution from the default I can use something like

OWOUT DQ, 1, [$CC, $4E, 0, 0, $5F] ' 11 bit resolution

and to address individual 1wire devices I'd use something like



OWOUT DQ, 1, [$55,$28,$B1,$FE,$22,$00,$00,$00,$5D,$44,$5F] THEN
OWIN DQ, 4, [Stat] ' Stat is constant + Check for still busy converting
IF Stat = 0 THEN W1 ' Still busy?, then loop
OWOUT DQ, 1,[$55,$28,$B1,$FE,$22,$00,$00,$00,$5D,$BE]
OWIN DQ, 2, [Temp.LOWBYTE,Temp.HIGHBYTE] 'Read two bytes, + end communications
GOSUB Convert_Temp