PDA

View Full Version : Please help with 1-wire DS1820



hatuan291
- 7th March 2010, 01:50
I tried this code below :


temperature Var Word ' Temperature storage
count_remain Var Byte ' Count remaining
count_per_c Var Byte ' Count per degree C

DQ Var PORTD.6 ' One-wire data pin

loop :

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

OWIn DQ, 4, [count_remain] ' Check for still busy converting

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)
Lcdout $fe, 1, DEC (temperature / 100), ".", DEC2 temperature, " C"

goto loop

It worked well when i use crystal 6 Mhz , OSC_HS . Data from DS1820 was ok.

But when i used crystal 6 Mhz , OSC_HS or higher Mhz , OSC_HS . Data from DS1820 allway 54.11'C .

Maybe the speed of PIC is too high but I need the high speed process from PIC . How can i config DS1820 when connect to High-speed PIC ?

Who can help me to fix this problem ?

Many thanks !
Sory for my English.

Pic2008
- 7th March 2010, 03:06
Did you try to include the following:

DEFINE OSC 20 ' 20Mhz Osc

rsocor01
- 7th March 2010, 12:36
hatuan291,

What PIC are you using? The DS1820 has its limits in speed as stated in the datasheet. First try using a PAUSEUS after the conversion command.


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

Double check that your PIC is working with the new oscillator settings. Try a blinking LED first with the new settings.

http://datasheets.maxim-ic.com/en/ds/DS18S20.pdf

Robert

Acetronics2
- 7th March 2010, 13:23
Did you try to include the following:

DEFINE OSC 20 ' 20Mhz Osc

if using 8 Mhz Xtal, your DEFINE must be OSC 8

also ...



OWOut DQ, 1, [$CC, $44] ' Start temperature conversion
Pause 750


will be nice.

no need for


OWIn DQ, 4, [count_remain] ' Check for still busy converting


that, alone, doesn't check for anything ...

Alain

Charles Linquis
- 8th March 2010, 03:28
I won't even ask if you are using the recommended 4.7K pull-up resistor.

hatuan291
- 9th March 2010, 13:51
Did you try to include the following:

DEFINE OSC 20 ' 20Mhz Osc

When i'm not include DEFINE OSC 8 ( with xtal 8Mhz ) , test with blink LED is so fast .

but when include ( the same xtal ) , the time between Led-On and Led-Off so long .

Maybe define osc will slow down the speed of PIC ?

I used 18F4680 . DS 1820 had an resistor pull-up .I have tried

1-DS1820 work well with 10 Mhz xtal , config OSC_HS , not define osc 10
2-but with the same xtal , config OSC_HSPLL , DS1820 didn't work . not define osc 10 OR define i got the same result .


who can help me ?