PDA

View Full Version : ds1820 error



CrazyCooter
- 28th August 2007, 11:01
hi all. think i got the correct spot. i am having a issue with the dallas ds1820 temp sensor. i know it has been written many times. but think this is a different issue. i keep getting the same temp (85.00 deg c) even when i put the hair drier on it. is it stuffed????????

my code for a 16f88 internal osc set at 4 mhz

OSCCON = %01101000 'INTRC = 4 MHz
TRISA = %11111111
ANSEL = 0 'DISABLE ALL ADC
CMCON = 7 'DISABLE ALL ANALOG COMPARATOR
WHILE OSCCON.2=0:WEND 'STABILISE THE CLOCK
ADCON1 = 1
DEFINE OSC 4
PAUSE 1000
DEFINE LCD_DREG PORTB
DEFINE LCD_DBIT 4 '4,5,6,7
DEFINE LCD_RSREG PORTB
DEFINE LCD_RSBIT 3
DEFINE LCD_EREG PORTB
DEFINE LCD_EBIT 2
DEFINE LCD_BITS 4
DEFINE LCD_LINES 2
DEFINE LCD_COMMANDUS 2000
DEFINE LCD_DATAUS 50
pause 1000
lcdout $fe, 1

' One-wire temperature for DS18S20

' This program must be compiled with PBP version 2.40 or later


temperature VAR WORD ' Temperature storage
count_remain VAR BYTE ' Count remaining
count_per_c VAR BYTE ' Count per degree C

DQ VAR PORTA.1 ' One-wire data pin


mainloop: OWOUT DQ, 0, [$B4] ' READ POWER SUPPLY
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)
LCDOut $fe, 1, DEC (temperature / 100), ".", DEC2 temperature, " C"

' Calculate temperature in degrees F to 2 decimal places (not valid for negative temperature)
temperature = (temperature */ 461) + 3200
LCDOut $fe, $c0, DEC (temperature / 100), ".", DEC2 temperature, " F"

Pause 500 ' Display about once a second
LCDOUT $FE, 1, "DALLAS DS1820"
PAUSE 1000
GoTo mainloop ' Do it forever


any ideas of maybe where i went wrong

thanks

crazy cooter

Darrel Taylor
- 28th August 2007, 14:03
The fact that you're getting 85°C is a good sign.

That's the power-on default for the temperature registers of the DS1820. So at least you know the hardware is working.

My guess is that the "READ POWER SUPPLY" line is not allowing the "start conversion" to work. Try it with that line commented out.
<br>

CrazyCooter
- 28th August 2007, 14:09
i have tried it without the READ POWER SUPPLY. I have also tied a 4.7k resistor from the DQ line to 5V. Am i initialising it correctly??? This was a direct copy from melabs using "onewire.bas"

james
- 28th August 2007, 15:46
Did you set internal osc?

Right after you compile, the screen comes up to program the chip. if you click view -> configuration. You can set INTOSC.

a place I've tripped up before, just a thought.

hope it helps

Bruce
- 28th August 2007, 16:29
Try changing this;
OWIn DQ, 0, [temperature.LOWBYTE, temperature.HIGHBYTE, Skip 4, count_remain, count_per_c]

to this;
OWIn DQ, 2, [temperature.LOWBYTE, temperature.HIGHBYTE, Skip 4, count_remain, count_per_c]

I beleive you need mode 2 after the last read to issue the reset pulse so the sensor
is ready for the next on return to the start of your program.

Darrel Taylor
- 29th August 2007, 05:10
I had to try it out, but all I have is a DS18B20.

The original code worked fine, except I had to change the formula. But the communications seems OK.
<br>

CrazyCooter
- 29th August 2007, 12:38
ok have got it to work. i replaced the 4k7 resistor with a 2k4 resistor and rererererereread the data sheet for the ds1820 and put a pause 750 after the start temp conversion. IE.
OWOUT DQ,1, [$CC, $44]
PAUSE 750 ' Max conversion time
OWIN DQ, 4, [count_remain]

i found it on pg 20 under AC Electrical Characteristics temperature conversion time

i found its not as fast as i would have thought. is there any other way to make it faster or is this the speed of using the 1 wire devices

the code

OSCCON = %01101000 'INTRC = 4 MHz
TRISA = %11111111
ANSEL = 0 'DISABLE ALL ADC
CMCON = 7 'DISABLE ALL ANALOG COMPARATOR
WHILE OSCCON.2=0:WEND 'STABILISE THE CLOCK
ADCON1 = 1
DEFINE OSC 4
PAUSE 1000
DEFINE LCD_DREG PORTB
DEFINE LCD_DBIT 4 '4,5,6,7
DEFINE LCD_RSREG PORTB
DEFINE LCD_RSBIT 3
DEFINE LCD_EREG PORTB
DEFINE LCD_EBIT 2
DEFINE LCD_BITS 4
DEFINE LCD_LINES 2
DEFINE LCD_COMMANDUS 2000
DEFINE LCD_DATAUS 50
pause 1000
lcdout $fe, 1

' One-wire temperature for DS18S20

' This program must be compiled with PBP version 2.40 or later


temperature VAR WORD ' Temperature storage
count_remain VAR BYTE ' Count remaining
count_per_c VAR BYTE ' Count per degree C

DQ VAR PORTA.1 ' One-wire data pin

mainloop:
OWOut DQ, 1, [$CC, $44] ' Start temperature conversion
pause 750 'NEEDED FOR TEMP STABILIZING
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)
LCDOut $fe, 1, DEC (temperature / 100)," C"

GoTo mainloop ' Do it forever
end

thanks

crazy cooter

Darrel Taylor
- 29th August 2007, 13:57
Hmmm, something doesn't seem right.

The lower value pull-up, and pause 750 shouldn't be needed.
The OWIn DQ, 4, [count_remain] will check the busy bit until the conversion is complete.

..... Unless it's running on "Parasite Power". In which case you need a Strong Pull-up on DQ during the conversion, and you can't read from the device for 750ms.

If that fixed your problem, then you probably don't have 5V on pin 3 of the 1820.
And if "Parasite Power" was intentional, you may need to do things differently.
<br>

CrazyCooter
- 30th August 2007, 07:59
Hi everyone
Well this ds1820 ic is being a real pain. have gone over things with a multimeter and i have 5v going to pin 3. data is pin 2 and gnd is pin 1

This is what the front of the ic looks
________
dallas
ds1820
0634C3
+552AC
________
1 2 3
GND 5V
DATA
2k4 resistor tied between pin 2 and pin 3

I did notice "Vpu" figure 1 page 2 of the data sheet. What is Vpu is that the 5v line as i am using it. I assume it is. Could this be the problem??

Am BALD cause of this ic. hahaha

Darrel Taylor
- 31st August 2007, 02:50
Yes, Vpu is VDD or +5V.

If you have time, can you try this...
;-----------------------------------------------------------------------------
Done VAR BIT
Parasite VAR BIT
Family VAR BYTE

Diag:
OWIn DQ, 4, [Done]
LCDOUT $FE,1,"Done =", bin1 Done

OWOUT DQ, 1, [$CC, $B4] ' READ POWER SUPPLY
OWIn DQ, 4, [Parasite]
LCDOUT $FE,$C0,"Power="
if Parasite = 0 then
LCDOUT "Parasite"
else
LCDOUT "VDD"
endif

OWOUT DQ, 1, [$33]
OWIN DQ, 2,[Family]
LCDOUT $FE,$89,"FAM=",IHEX2 Family

PAUSE 1000
goto Diag
;-----------------------------------------------------------------------------

Just stick it before the main loop in your program.

Ideally, you should see this on the LCD ...
Done = 1 FAM=$10
Power=VDD
<br>

CrazyCooter
- 31st August 2007, 07:47
Thanks darren you have been a big help.

The program initialy comes up with

Done =1 FAM=$10
Power=VDD

then half second later changes to

Done =1 FAM=$10
Power=Parasite

Regards
crazy cooter

Darrel Taylor
- 31st August 2007, 08:15
Well, it's reporting the correct Family number so the communications is working.
But as suspected, it's also reporting that there's no power on VDD Pin 3.

Since you said you already verified that there is +5V on Pin 3.

The only thing left, is to say that that particular part has a problem with it's power pin.
Maybe it was plugged in backwards at some point along the way.

The rest still seems to be working, I guess you can just use it in Parasite mode.
But you may want to approach it differently than just a smaller Pull-Up resistor.

HTH,
&nbsp; Darrel

CrazyCooter
- 31st August 2007, 08:19
Ok i i flipped the wires on the ds1820 around (PIN1=3 PIN2=2 PIN3=1)
And now get

Done =1 FAM=$FF
Power=VDD

When i put a 10K pullup resistor on i get

Done =1 FAM=$10
Power=Parasite

when i take the resistor away i get

Done =0 FAM=$00
Power=Parasite

I flipped the ic around and get these readings

When i put a 10K pullup resistor on i get

Done =1 FAM=$FF
Power=VDD

when i take the resistor away i get

Done =1 FAM=$FF
Power=VDD

Does anyone have these problems?

Regards CC

CrazyCooter
- 9th September 2007, 07:34
Thanks To Everyone Who Gave Me Advice Here. It Ended Up Being Two Dead Ds18s20. I Got Some New Ones Now And Its All Working Well.


Regards

Crazy Cooter