PDA

View Full Version : DS1820 versus DS18S20



gadelhas
- 10th June 2010, 19:25
Hi,

I have a code that works great with the DS1820, however when i change to a DS18S20, the only thing that i get is 127.68ºC.

I allready made a search on the forum, however all the resaults are exactly the same as my code.

I have 2 DS18S20, and the show exactly the same value.

Can somebody help me;

Here is my code.



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



' REGISTOS PINOUT 1 = IN; 0 = OUT
' ================================================== =========
'76543210
TRISA = %11111111
TRISB = %00001111
TRISC = %00100000
TRISD = %00000000
TRISE = %00000000
ADCON1 = %00001110
ADCON0 = %00000000

' NOMES PINOUT
' ================================================== =========
LED VAR PORTC.3
DQ VAR PORTD.0

' DEFENIÇÕES
' ================================================== =========

DEFINE LCD_DREG PORTB ' LCD Data bits on PORTB
DEFINE LCD_DBIT 4 ' PORTB starting address
DEFINE LCD_RSREG PORTB ' LCD RS bit on PORTB
DEFINE LCD_RSBIT 3 ' LCD RS bit address
DEFINE LCD_EREG PORTB ' LCD E bit on PORTB
DEFINE LCD_EBIT 2 ' LCD E bit address
DEFINE LCD_BITS 4 ' LCD in 4-bit mode
DEFINE LCD_LINES 2 ' LCD has 2 rows
DEFINE LCD_COMMANDUS 2000 ' Set command delay time in us
DEFINE LCD_DATAUS 50 ' Set data delay time in us

' INICIO PROGRAMA
' ================================================== =========

Main:
gosub Read_Sensor_Amp
pause 100
goto Main

' LEITURA SENSOR AMPLIFICADOR
' ================================================== =========

Read_Sensor_Amp:
OWOut DQ,1,[$CC,$44]
Waitloop: OWIn DQ,4,[count_remain]
If count_remain = 0 Then Waitloop
OWOut DQ,1,[$CC,$BE]
OWIn DQ,0,[temperature.LOWBYTE,temperature.HIGHBYTE,Skip 4,count_remain,count_per_c]
temperature = (((temperature >> 1) * 100) - 25) + (((count_per_c - count_remain) * 100)/count_per_c)
Lcdout $fe, 1, " Temp. Amplificador "
Lcdout $fe, $C0," ",DEC (temperature/100),".",DEC2 temperature," C"
return
end

gadelhas
- 10th June 2010, 22:44
I think it's beacuse i'm using the DS18S20P. Can somebody confirm this?

Darrel Taylor
- 11th June 2010, 04:20
I think it's beacuse i'm using the DS18S20P. Can somebody confirm this?
I think that means it uses "Parasitic Power" only.

If so, you have to drive the DQ line HIGH for 750ms during the conversion.
After that you can read it like normal.
It doesn't get power from the VDD pin.

biggej
- 11th June 2010, 18:28
DT is on the right track but maybe for not exactly the right reason. The DS18S20 does not have to run with parisitic power but it can if needed. However this from Maxim..
"Specification Differences: The primary specification difference between the two parts is the temperature conversion time: DS1820 = 500ms (max) and DS18S20 = 750ms (max)."

I believe you may also be using "count remain" improperly to signal the end of conversion. End of conversiion may be determined by issing a "Read time slot" command until the result is non zero. (Yes, it is in the data sheet!) All that being said, you can probably get by with only adding the 750ms delay after the conversion command.
Jim

Darrel Taylor
- 11th June 2010, 19:00
DT is on the right track but maybe for not exactly the right reason. The DS18S20 does not have to run with parisitic power but it can if needed.
The DS18S20 doesn't, but the DS18S20P also called DS18S20-PAR, only uses "Parasitic Power".

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

biggej
- 12th June 2010, 02:51
I should have know Darrel had it right!
It will take a wiring change to make Parasitic Power work too.
Jim

Bill Legge
- 12th June 2010, 09:24
Thought the following code might interest someone?
It's based on the code for the DS18B20 by Bruce on the Reynolds/Renton web site.

The chip I used is the DS18B20-PAR ( the device is marked 'DS18B20P') and will only work with parasitic power. Achieved by using an 2N7000 MOSFET (gate on PORTC.1, source on the DQ line and the drain on +5 supply).

The DQ line must be driven high within 10uS of the 'convert' command and maintained for the duration of the conversion (750mS for 12 bit conversion).

The extra code to do this follows the conver command.


' -----[ Title ]-----------------------------------------------------
'
' File...... WVL Water Remote
' Purpose... Remote station for control of water heater
' Date...... June 2010
'
' 7. DS18B20P measures tank temp. Parasitic power only with DQ pulled hard
' high after 'read temp' command by MOSFET 2N7000 with gate on PORTC.1

' 8. The DS18B20P range +125C to -55C

' 9. The DQ line must be high for the conversion period. Periods and resolution:
' 9 bit 93.7mS 0.5C 1/2 degree
' 10 bit 187.5mS 0.25C 1/4 degree
' 11 bit 375.0mS 0.125C 1/8 degree
' 12 bit 750.0mS 0.0625C 1/16 degree
' 12 bit resolution used so conversion delay is 750mS and conversion factor is
' 625 that gives temperature in 1/10000 degrees C

' 10. The code is based on the DS18B20 pages at web site REYNOLDS/RENTON
'
' ----[ Includes / Defines ]-------------------------------------------
'
clear
define OSC 20 ' Use HSPLL during compilation
DEFINE LCD_DREG PORTB ' Define PIC port used for LCD Data lines
DEFINE LCD_DBIT 4 ' Define first pin of connected to LCD
DEFINE LCD_RSREG PORTB ' Define PIC port used for RS line of LCD
DEFINE LCD_RSBIT 2 ' Define pin used for RS connection
DEFINE LCD_EREG PORTB ' Define PIC port used for E line of LCD
DEFINE LCD_EBIT 1 ' Define pin used for E connection
define LCD_RWREG PORTB ' Define PIC port used for RW
DEFINE LCD_RWBIT 3 ' Define pin used for RW
DEFINE LCD_BITS 4 ' Define 4 bit communication mode to LCD
DEFINE LCD_LINES 4 ' Define using a X line LCD
DEFINE LCD_COMMANDUS 1500 ' Define delay time between sending LCD commands
DEFINE LCD_DATAUS 44 ' Define delay time between data sent
FLAGS=0
include "modedefs.bas" ' Include serout defines
'
' ----[ Variables ]----------------------------------------------------
'
TempR VAR word ' DS18B20P reading. raw data
TempC VAR WORD ' Temp in deg C
Float VAR WORD ' Holds remainder for + temp C display

Heartbeat var PORTA.0 ' Heartbeat each cycle

DQ var PORTC.0 ' DS18B20P. Comms
Pullup var PORTC.1 ' DS18B20P
'
' -----[ Initialization - PIC ]--------------------------------------
'
ADCON1 = %00000110 ' All ports digital
CMCON = %00000111 ' Comparators off. Essential or PORTF won't work
'
' -----[ Identify ]--------------------------------------------------
'
LCDOUT $fe,$80,"Water Heater"
pause 1000
LCDOUT $fe,1
'
' ************************************************** ***************************
' * *
' * M A I N P R O G R A M *
' * *
' ************************************************** ***************************

Main:
GOSUB Get_temp
LCDOUT $fe,$c0,"Temp : ",DEC TempC,".",DEC Float

toggle Heartbeat
pause 1000
goto Main

' ************************************************** ***************************
' * *
' * S U B R O U T I N E S *
' * *
' ************************************************** ***************************


Get_temp:
OWOUT DQ,1,[$CC, $44] ' Skip ROM search & do temp conversion
high Pullup ' Turns MOSFET on to make DQ line high
pause 750 ' Conversion time for 12 bit reading
low Pullup ' Turn MOSFET off after read temp command

OWOUT DQ,1,[$CC, $BE] ' Skip ROM search & read scratchpad memory
OWIN DQ,2,[TempR.Lowbyte,TempR.Highbyte]' Read two bytes / end comms

Convert_Temp:
TempC = DIV32 10 ' Use Div32 value to calculate precise deg C
TempC = (TempR & $0FF0) >> 4 ' Mask middle 8-bits, shift into lower byte
Float = ((TempR.Lowbyte & $0F) * 625) ' Lower 4-bits of result * 625

RETURN

END

The MCU is an PIC16F877A running at 20MHz.

Regards Bill Legge

gadelhas
- 12th June 2010, 11:26
Hi,

Thanks to everyone,

I i'll try the code and circuit that Bill Legge posted.

Regards
Gadelhas

barcosta
- 11th August 2010, 00:42
hi im elie,im doing my final project :temperature regulator system
im newer in the picbasic pro
i need to know a code t read the tempeature from the sensor ds1820
thank you all for your replys

mackrackit
- 11th August 2010, 03:05
http://www.picbasic.co.uk/forum/search.php?searchid=221487

Acetronics2
- 11th August 2010, 08:31
http://www.picbasic.co.uk/forum/search.php?searchid=221487

Hi,Dave


Sorry - no matches. Please try some different terms.


Did you tried a search for the Homework section or the " yesterday eve last delay to finish " section ???

BTW, this looks to be THE subject of the Year : This question appears @ all all the electronic forums I read ...

:rolleyes:

Alain

mackrackit
- 11th August 2010, 12:00
I guess the searches only live for a short time.. Was supposed to be search results from this forum for the DS1820.

But the point is search first..

barcosta
- 11th August 2010, 13:58
thank you for your reply but still no code ???????????????????

mackrackit
- 11th August 2010, 14:04
Have you searched the forum?
What about the code on this thread?

What have you tried for yourself?

malc-c
- 11th August 2010, 20:50
thank you for your reply but still no code ???????????????????

There are stacks of examples of using a DS1820 sensor with a PIC on the internet, including lots of samples within the sections of this forum ( I should know, I've been given a lot of help with a project using these devices :) ).

Use Google or the "search" function top right - enter DS18B20 as the search string...