PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : DS1621 auslesen



Zeroeightfifteen
21.02.2006, 20:00
Hallo

wie kann ich mit dem DS1621 eine Temperatur auslesen? ich habe schon einige Beispielprogramme versucht. Der liefert mir aber nur komische zahlen. wie muss ich denn diese zahl abspeichern?

Ich habe mir dieses Programm mal geschrieben. Ist das schon annähernd richtig?


$regfile = "M32def.dat" ' chip
$crystal = 16000000 ' frequenz
$baud = 19200 ' baud rate

$lib "i2c_twi.lbx" ' we do not use software emulated I2C but the TWI

Config Scl = Portc.0 ' we need to provide the SCL pin name
Config Sda = Portc.1 ' we need to provide the SDA pin name

I2cinit ' we need to set the pins in the proper state

Config Twi = 100000 ' wanted clock frequency
'will set TWBR and TWSR
'Twbr = 12 'bit rate register
'Twsr = 0 'pre scaler bits

Dim T As Word

Do


I2creceive &H90 , T

Print "T= " ; T
Print "receive" ; Err
Waitms 500
Loop


End

svenulm31
21.02.2006, 20:04
$baud = 9600
versuch es mal ...am pc auch

Zeroeightfifteen
21.02.2006, 20:24
ne baud 19200 passt schon die hab ich am pc auch. das funktioniert alles. die hab ich mal höher gestellt weil es da schon mal probleme gegeben hatt. aber ich glaube dass ich die temperatur vom Sensor nicht richtig einlesen kann.

hrei
21.02.2006, 20:36
Hallo,

mit Baud hat das ja nu auch nix zu tun.



Do


I2creceive &H90 , T

Print "T= " ; T
Print "receive" ; Err
Waitms 500
Loop


Ähmm.. soll das Deine gesamte DS1621 Ausleseroutine sein? Ist Dir nicht aufgefallen, daß die Beispielprogramme (die Du ja probiert hast) deutlich umfangreicher sind?

Wenn Du mir die Frage beantwortest, bekommst Du von mir noch'n Beispielprogramm :-).

Grüße
Henrik

linux_80
21.02.2006, 20:39
Hallo,
vom DS1621 kommen 2 Byte, suche mal das Datenblat dazu, da steht genau drin wie das ausschaut.
Es wird in 0.5 Grad gemessen.

http://www.alldatasheet.com/datasheet-pdf/pdf/58507/DALLAS/DS1621.html

hrei
21.02.2006, 20:44
Hallo,
vom DS1621 kommen 2 Byte, suche mal das Datenblat dazu, da steht genau drin wie das ausschaut.
Es wird in 0.5 Grad gemessen.

http://www.alldatasheet.com/datasheet-pdf/pdf/58507/DALLAS/DS1621.html

Yepp, oder auch in 0,06°C Auflösung wenn man Slope und Counter auswertet.

Etwas Initialisierung gehort aber so oder so dazu :-).

Grüße
Henrik

linux_80
21.02.2006, 20:48
So genau hab ich das DB nicht angeschut, aber mir ist nur gleich die Tabelle mit den Beispielwerten aufgefallen.

Zeroeightfifteen
21.02.2006, 20:50
@hrei
doch das ist mir schon aufgefallen. Ich habe aber die erfahrung gemacht dass die meisten Beispielprogramme sehr umständlich geschrieben sind. (z.B. einen Atmega32 als Slave zu programmieren.) dieses habe ich auch viel kürzer geschrieben.

hrei
21.02.2006, 21:06
@hrei
doch das ist mir schon aufgefallen. Ich habe aber die erfahrung gemacht dass die meisten Beispielprogramme sehr umständlich geschrieben sind. (z.B. einen Atmega32 als Slave zu programmieren.) dieses habe ich auch viel kürzer geschrieben.

Na, man kann ja bisweilen manches kürzer schreiben, aber dann sollte man schon wissen was man tut.

Eine einfache Sub sieht zum Beispiel so aus - ACHTUNG-das ist die nackte Subroutine: (Übergeben wird die Deviceadresse des DS1621, das Ergebnis steht in der Variable Value):



'-------------------------------------------------------------------------------

Sub Readtemp(byval Device As Byte)
Local Deviceread As Byte
Local Lowtemp As Byte
Local Hightemp As Byte

Deviceread = Device + 1

'I2csend , Device , &HEE 'kürzere Source, längerer Code

I2cstart
I2cwbyte Device
I2cwbyte &HEE 'Temperaturmessung anstoßen
I2cstop

'I2csend , Device , &HAA 'kürzere Source, längerer Code

I2cstart
I2cwbyte Device
I2cwbyte &HAA 'Temperaturmessung Lesekommando
I2cstop

I2cstart
I2cwbyte Deviceread
I2crbyte Lowtemp , Ack 'LSByte holen
I2crbyte Hightemp , Nack 'MSByte holen
I2cstop

Value = Lowtemp * 10
If Hightemp = 128 Then
Value = Value + 5
End If

End Sub

'-------------------------------------------------------------------------------


Grundlagen und nochmal Grundlagen lernen, Datenblätter lesen, verstehen und dann variieren ](*,) .

Grüße
Henrik

Zeroeightfifteen
21.02.2006, 21:10
was bedeutet, das ist nur die nackte sub? muss ich da noch viel dazu schreiben? bzw wann muss ich in die sub springen?

Zeroeightfifteen
21.02.2006, 21:27
Das ist jetzt mein aktuelles Programm

$regfile = "M32def.dat" ' chip
$crystal = 16000000 ' frequenz
$baud = 19200 ' baud rate

' we do not use software emulated I2C but the TWI

Config Scl = Portc.0 ' we need to provide the SCL pin name
Config Sda = Portc.1 ' we need to provide the SDA pin name


Dim Lowtemp As Byte
Dim Hightemp As Byte
Dim Value As Word '!!!!!!!
I2cinit


Do

I2cstart
I2cwbyte 144
I2cwbyte &HEE 'Temperaturmessung anstoßen
I2cstop

I2cstart
I2cwbyte 144
I2cwbyte &HAA 'Temperaturmessung Lesekommando
I2cstop

I2cstart
I2cwbyte 145
I2crbyte Lowtemp , Ack 'LSB holen
I2crbyte Hightemp , Nack 'MSB holen

I2cstop

Value = Lowtemp * 10
If Hightemp = 128 Then
Value = Value + 5
End If

Print value
' oder LCD value

waitms 500 'kurze Pause
Loop


End

Dieses Programm funktioniert glaub ich mal so weit. Die temperatur wir aber ohne Komma angezeigt.
was bedeutet denn das rechnen mit value +5 oder *10?

kann ich das ganze nicht mit hardware twi lösen?
da sind doch die befehle auch kürzer.

Zeroeightfifteen
22.02.2006, 15:30
ich habe heute mal ausprobiert ob ich Minustemperaturen auch anzeigen lassen kann. Doch wenn die Temperatur unter 0 fällt, läuft er von 256 abwärtz.

hrei
22.02.2006, 16:38
ich habe heute mal ausprobiert ob ich Minustemperaturen auch anzeigen lassen kann. Doch wenn die Temperatur unter 0 fällt, läuft er von 256 abwärtz.

Och mann 0815,

was hatte ich geschrieben? Richtig:
Grundlagen und nochmal Grundlagen lernen, Datenblätter lesen, verstehen und dann variieren.

Da fragst Du:



Dieses Programm funktioniert glaub ich mal so weit. Die temperatur wir aber ohne Komma angezeigt.
was bedeutet denn das rechnen mit value +5 oder *10?

kann ich das ganze nicht mit hardware twi lösen?
da sind doch die befehle auch kürzer.


1) Wie man Zahlen ohne Komma in Zahlen mit Komma verwandelt. Das hattest Du bereits in einem anderen Thread gefragt und auch eine Methode genannt bekommen, wie das zu bewerkstelligen ist. In meinem komplettbeispiel, das ich unten nochmal einfüge, lernst Du noc eine Methode kennen. Was die Operation mit *10 und +5 darfst Du nun selbst herausfinden.

2)Natürlich kannst Du das auch mit Hardware TWI lösen. Nur ändern sich die Befehle überhaupt nicht. Der einzige Unterschied ist der, daß die Bascom Library Hardware TWI anspricht und damit gerinfügig weniger Platz verbraucht.

3)Minus kann das Programmbeisiel nicht, ich habe es bewußt einfach gehalten, für Dich aber wohl noch nicht einfach genug.

Irgendwie scheinst Du die Funktion eines Forums falsch zu verstehen. Hier gibt es Hilfe zur Selbsthilfe, keine Rundum Sorglospakete für Denkfaule.

Ein letztes Mal --- Komplettprogramm einfach:


'-------------------------------------------------------------------------------
'----- Beispiel für das Auslesen des Temperatursensors DS1621/1631 ------------
' HR 2006
'
'Anmerkung: Dieses Beispiel ist sowohl für den 1621 als auch für den 1631
'geeignet. Der 1631 wird dabei im 1621 Kompatibilitätsmodus betrieben.
'Auf die Auswertung negativer Temperaturen wird verzichtet.
'-------------------------------------------------------------------------------

$regfile = "m8def.dat"
$crystal = 7372800
$baud = 9600

$hwstack = 32
$swstack = 32
$framesize = 32

Config Scl = Portc.5
Config Sda = Portc.4
Portc.5 = 1 'Pullup Widerstand ein
Portc.4 = 1 'Pullup Widerstand ein
I2cinit 'entbehrlich
'-------------------------------------------------------------------------------
Declare Sub Readtemp(byval Device As Byte)
Declare Sub Convertvalue_komma1()

Dim Value As Word
Dim Convert_strg As String * 10

Const Ds1 = 150 'ggf. anpassen
'----------------------------- Hauptprogramm -----------------------------------

Do
Call Readtemp(ds1)
Call Convertvalue_komma1()
Print Convert_strg
Waitms 500
Loop

End

'----------------------------- Subroutinen -------------------------------------

'Readtemp liest die Temperatur und stellt sie nach Aufruf in der Variable Value
'in 10tel Grad zu Verfügung. Übergeben wird die Deviceadresse des Sensors.

Sub Readtemp(byval Device As Byte)
Local Deviceread As Byte
Local Lowtemp As Byte
Local Hightemp As Byte

Deviceread = Device + 1

I2cstart
I2cwbyte Device
I2cwbyte &HEE 'Temperaturmessung anstoßen
I2cstop

I2cstart
I2cwbyte Device
I2cwbyte &HAA 'Temperaturmessung Lesekommando
I2cstop

I2cstart
I2cwbyte Deviceread
I2crbyte Lowtemp , Ack 'LSByte holen (Ganze Grad)
I2crbyte Hightemp , Nack 'MSByte holen (0,5 Grad Indikator)
I2cstop

Value = Lowtemp * 10
If Hightemp = 128 Then
Value = Value + 5
End If

End Sub

'-------------------------------------------------------------------------------
'Convertvalue_komma1 wandelt Value in einen String mit einer Nachkommastelle.
'Es wird gezeigt wie ein Zahlenwert in ein String gewandelt wird und dieser
'formatiert werden kann.
'Alternativ kann natürlich auch die "/10, Mod 10 Methode" angewandt werden.

Sub Convertvalue_komma1()

Convert_strg = Str(value)
Convert_strg = Format(convert_strg , " 0.0")

End Sub
'-------------------------------------------------------------------------------


und eine Erweiterung auf negative Temperaturen:



Sub Readtemp(byval Device As Byte)

Minusflag = 0
Local Deviceread As Byte
Local Lowtemp As Byte
Local Hightemp As Byte
Local Templow As Byte
Deviceread = Device + 1

I2csend , Device , &HEE 'Temperaturmessung anstoßen

I2csend , Device , &HAA 'Temperaturmessung Lesekommando

I2cstart
I2cwbyte Deviceread
I2crbyte Lowtemp , Ack 'LSByte holen (ganze Grad)

Templow = Lowtemp And &H80
If Templow = 128 Then
Minusflag = 1
Lowtemp = 255 - Lowtemp
Lowtemp = Lowtemp + 1
End If

I2crbyte Hightemp , Nack 'MSByte holen (0,5 Indikator)
I2cstop

Value = Lowtemp * 10
Value_x = Lowtemp 'um das LSB für EEprom
'Ausgabe zu retten
If Hightemp = 128 Then '+/- Auswertung
If Minusflag = 0 Then Value = Value + 5
' If Minusflag = 1 Then Value = Value - 5
End If

End Sub


Bevor Du Dich nun wieder mit Fragen meldest, wäre es schön, wenn Du endlich mal die Grundlagen von I2C lernen würdest und das Datenblatt liest. Dann wirst Du evtl. auch weitere Antworten erwarten können.

Henrik

patti16
22.02.2006, 17:29
hallo


es gab schonmal das problem einfach mal suchen dann findet man was.

hier der link:
https://www.roboternetz.de/phpBB2/zeigebeitrag.php?t=13775&highlight=ds1621

gruß
patrick

Zeroeightfifteen
22.02.2006, 21:30
Das mit den Grundlagen lernen ist schon richtig. Doch mit den englischen Datenblättern kann ich mir halt nicht so weit helfen.

Ich stehe erst am Anfang mit der Programiererei.

Spion
25.10.2006, 21:23
Hallo

Ich habe einmal dass oben von hrei, angepasst und probiert, jedoch spuckt er immer nur 255.0 aus, was mache ich falsch? Achja, ich benütze dass RN-Controll.


'-------------------------------------------------------------------------------
'----- Beispiel für das Auslesen des Temperatursensors DS1621/1631 ------------
' HR 2006
'
'Anmerkung: Dieses Beispiel ist sowohl für den 1621 als auch für den 1631
'geeignet. Der 1631 wird dabei im 1621 Kompatibilitätsmodus betrieben.
'Auf die Auswertung negativer Temperaturen wird verzichtet.
'-------------------------------------------------------------------------------

$regfile = "m32def.dat"
$crystal = 16000000
$baud = 9600

$hwstack = 32
$swstack = 32
$framesize = 32

Config Scl = Portc.0
Config Sda = Portc.1


I2cinit 'entbehrlich
'-------------------------------------------------------------------------------
Declare Sub Readtemp(byval Device As Byte)
Declare Sub Convertvalue_komma1()

Dim Value As Word
Dim Convert_strg As String * 10

Const Ds1 = 150 'ggf. anpassen
'----------------------------- Hauptprogramm -----------------------------------

Do
Call Readtemp(ds1)
Call Convertvalue_komma1()
Print Convert_strg
Waitms 500
Loop

End

'----------------------------- Subroutinen -------------------------------------

'Readtemp liest die Temperatur und stellt sie nach Aufruf in der Variable Value
'in 10tel Grad zu Verfügung. Übergeben wird die Deviceadresse des Sensors.

Sub Readtemp(byval Device As Byte)
Local Deviceread As Byte
Local Lowtemp As Byte
Local Hightemp As Byte

Deviceread = Device + 1

I2cstart
I2cwbyte Device
I2cwbyte &HEE 'Temperaturmessung anstoßen
I2cstop

I2cstart
I2cwbyte Device
I2cwbyte &HAA 'Temperaturmessung Lesekommando
I2cstop

I2cstart
I2cwbyte Deviceread
I2crbyte Lowtemp , Ack 'LSByte holen (Ganze Grad)
I2crbyte Hightemp , Nack 'MSByte holen (0,5 Grad Indikator)
I2cstop

Value = Lowtemp * 10
If Hightemp = 128 Then
Value = Value + 5
End If

End Sub

'-------------------------------------------------------------------------------
'Convertvalue_komma1 wandelt Value in einen String mit einer Nachkommastelle.
'Es wird gezeigt wie ein Zahlenwert in ein String gewandelt wird und dieser
'formatiert werden kann.
'Alternativ kann natürlich auch die "/10, Mod 10 Methode" angewandt werden.

Sub Convertvalue_komma1()

Convert_strg = Str(value)
Convert_strg = Format(convert_strg , " 0.0")

End Sub
'---------------------------------


mfg Luca

raidy
27.10.2006, 07:50
So gehts bei mir


'----------- Temperatur abfragen --------------------------------
Sub Thermometer()
Local Device As Byte
Device = &H90
Local Deviceread As Byte
Local Lowtemp As Byte
Local Hightemp As Byte

Deviceread = Device + 1


I2cstart
I2cwbyte Device
I2cwbyte &HEE 'Temperaturmessung anstoßen
I2cstop


I2cstart
I2cwbyte Device
I2cwbyte &HAA 'Temperaturmessung Lesekommando
I2cstop

I2cstart
I2cwbyte Deviceread
I2crbyte Lowtemp , Ack 'LSByte holen
I2crbyte Hightemp , Nack 'MSByte holen
I2cstop

Temperatur = Lowtemp * 10
If Hightemp = 128 Then
Temperatur = Temperatur + 5
End If
Temperatur = Temperatur / 10
End Sub
'Ende -------------- Temperatur ----------------------------------------

Spion
29.10.2006, 17:29
Hallo
Leider funktioniert dein Code bei mir nicht. So sieht dass ganze aus:


-------------------------------------------------------------------------------
'----- Beispiel für das Auslesen des Temperatursensors DS1621/1631 ------------
' HR 2006
'
'Anmerkung: Dieses Beispiel ist sowohl für den 1621 als auch für den 1631
'geeignet. Der 1631 wird dabei im 1621 Kompatibilitätsmodus betrieben.
'Auf die Auswertung negativer Temperaturen wird verzichtet.
'-------------------------------------------------------------------------------

$regfile = "m32def.dat"
$crystal = 16000000
$baud = 9600


Declare Sub Thermometer()

Dim Temperatur As Word
Config Scl = Portc.0 'Ports fuer IIC-Bus
Config Sda = Portc.1

Do

Call Thermometer()

Print Temperatur
Print
Waitms 500


Loop


'----------- Temperatur abfragen --------------------------------
Sub Thermometer()
Local Device As Byte
Device = &H90
Local Deviceread As Byte
Local Lowtemp As Byte
Local Hightemp As Byte

Deviceread = Device + 1


I2cstart
I2cwbyte Device
I2cwbyte &HEE 'Temperaturmessung anstoßen
I2cstop


I2cstart
I2cwbyte Device
I2cwbyte &HAA 'Temperaturmessung Lesekommando
I2cstop

I2cstart
I2cwbyte Deviceread
I2crbyte Lowtemp , Ack 'LSByte holen
I2crbyte Hightemp , Nack 'MSByte holen
I2cstop

Temperatur = Lowtemp * 10
If Hightemp = 128 Then
Temperatur = Temperatur + 5
End If
Temperatur = Temperatur / 10
End Sub
'Ende -------------- Temperatur ----------------------------------------


Leider bekomme ich immer nur 0 zugeschickt. Was mache ich falsch?

mfg Luca

Edit: "Device = &H90" heisst das alle Ports nach GND gezogen sind, also Hex90?

raidy
30.10.2006, 10:24
Hallo,

Dein Programm ist richtig. Genau so läuft es bei mir auch.
Wenn Du immer 255, 65535 oder 0 als Antwort bekommst, so liegt dies ziemlich sicher an deiner Verlötung oder einer falschen I2C-Adresse.

Also prüfe nochmals folgende Punkte:

1) Hast Du irgenwelche Pins vertauscht SCL mit SDA
2) Hast Du 5V und GND auf dem Chip /I2C_Bus.
Falls du RN-Control hast, ist der 5V Jumper und der I2C Jumper gesteckt?
3) Ja HEX90 heisst alle A0-A2 auf GND

Übrigens: 0,255,65535 (je nach I2C-Chip) heisst eigentlich immer, daß das Programm den Baustein nicht gefunden hat.

Mehr Ferndiagnose geht leider nicht.
Gruß

Zur Sicherheit nochmals das Datenblatt
http://pdfserv.maxim-ic.com/en/ds/DS1621.pdf

Spion
30.10.2006, 17:42
Hallo

Ich habe Heute noch mal alles duchprobiert, aber ich fand keinen Fehler:
VDD: 4.97V
GND: Gnd
A0: Gnd
A1: Gnd
A2: Gnd
Scl: Mit Port b.0 verbunden, spannung 4.97 - 4.96
Sda: Mit Port b.1 Verbunden, spannung 4.97 - 4.96
Tout: Nichts angeschlossen, Spannung 4.97V (ist das Normal?)

Was könnte falsch sein?

mfg Luca

Edit: Ich habe jetzt schnell umgelötet, jetzt habe ich auf A0-A2 +5V, die Hex habe ich auf 9E eingestellt (im prog.), funktioniert aber immer noch nicht.

linux_80
30.10.2006, 20:00
Im Programm schreibst Du bei SCL/SDA PortC und hier grad PortB, welcher ist es denn ?

Spion
30.10.2006, 20:07
Hallo

Ohh, ich meinte natürlich Port.c.
SCL/SDA ist mit Port.c. verbunden, wahr ein tipp fehler.

mfg Luca

peter02
31.10.2006, 17:48
Hallo zusammen,

ich versuche auch schon seit Tagen mit der rncontrol und einem DS1621 eine Temperatur anzuzeigen.
Ich bin recht enttäuscht, dass eine so simple Aufgabe fast unlösbar ist. Ich bin davon ausgegangen, dass soetwas schon 1000fach probiert wurde und hätte schon ein paar perfekte Lösungen erwartet.

Aber ich habe aus Euren Vorschlägen ein PRG ableiten können, das bei mir auf dem LCD und auf der RS232 die Temperatur formatiert anzeigt.

Hier ist es:

$regfile = "M32def.dat" ' chip
$crystal = 16000000 ' frequenz
$baud = 9600 ' baud rate

Config Scl = Portc.0 ' we need to provide the SCL pin name
Config Sda = Portc.1 ' we need to provide the SDA pin name

Config Lcdpin = Pin , Db4 = Portb.0 , Db5 = Portb.1 , Db6 = Portb.2 , Db7 = Portb.3 , E = Portb.5 , Rs = Portb.4
Config Lcd = 16 * 2
Config Portb = Output
Config Lcdbus = 4

Dim ___lcdno As Bit
Dim Lowtemp As Byte
Dim Hightemp As Byte
Dim Value As Word
Declare Sub Convertvalue_komma1()
Dim Convert_strg As String * 10 '!!!!!!!
I2cinit
Cls

Do

I2cstart
I2cwbyte 144
I2cwbyte &HEE 'Temperaturmessung anstoßen
I2cstop

I2cstart
I2cwbyte 144
I2cwbyte &HAA 'Temperaturmessung Lesekommando
I2cstop

I2cstart
I2cwbyte 145
I2crbyte Lowtemp , Ack 'LSB holen
I2crbyte Hightemp , Nack 'MSB holen

I2cstop

Value = Lowtemp * 10
If Hightemp = 128 Then
Value = Value + 5
End If


Call Convertvalue_komma1()
Print Convert_strg ; " C"


Locate 1 , 1
Lcd Convert_strg ; " C"

Waitms 1000 'kurze Pause
Loop


End

'-------------------------------------------------------------------------------
'Convertvalue_komma1 wandelt Value in einen String mit einer Nachkommastelle.
'Es wird gezeigt wie ein Zahlenwert in ein String gewandelt wird und dieser
'formatiert werden kann.
'Alternativ kann natürlich auch die "/10, Mod 10 Methode" angewandt werden.

Sub Convertvalue_komma1()

Convert_strg = Str(value)
Convert_strg = Format(convert_strg , " 0.0")

End Sub
'---------------------------------


Gruß aus Essen, Peter

Drifter2006
31.10.2006, 20:06
Hello,
I translated a CCBasic program I wrote into a Bascom 8051 program.
The CCBasic version works pervectly, I have not been able to test the Bascom 8051 version yet.
I think with a few modifications the Bascom 8051 program should work on a AVR.
Greetings,
Windt H.J.


'***************************************'
'* WINDT SYSTEMS *'
'* DS1621 v1.0 for 89S8252 Flash Board *'
'* 2006 / H.J. WINDT *'
'***************************************'
'----------------------------------------------------------------------------------------------------'
'This software for the 89S8252 will read the DS1621 9 bit Temperature'
'-55°C to +125°C in 0.5°C increments and display the data on a terminal program as T = xxx,x°C.'
'The temperature is read as -550 to 1250, the last digit is actually the digit behind the comma,'
'example 1: temp_c = -15 is actually -1,5°C'
'example 2: temp_c = 250 is actually 25,0°C.'
'Communication with the DS1621 is via the I2C bus.'
'Feel free to use and share this software!'
'DS1621 -->> DALLAS SEMICONDUCTOR Digital Thermometer and Thermostat'
'----------------------------------------------------------------------------------------------------'
'********************************* PORTS *********************************'
Config Sda = P1.0
Config Scl = P1.1
'************************************************* ************************'
'******************************* VARIABLES *******************************'
Dim I2c_byte As Byte
Dim Loops1 As Byte
Dim Temp1 As Integer
Dim Temp2 As Integer
Dim Temp_c As Integer
'************************************************* ************************'
'******************************* CONSTANTS *******************************'
Const Ds1621_i2c_address = &H0
Const Ds1621_i2c_r_address = &H1
'************************************************* ************************'
'********************************* SETUP *********************************'
Config I2cdelay = 800
'************************************************* ************************'
'******************************** PROGRAM ********************************'
Temp_c_loop:
Gosub Get_ds1621_temperature

Temp1 = Temp_c / 10 'calculate hundreds tens ones from temp_c'
Temp1 = Abs(temp1)

Temp2 = Temp_c / 10 'calculate 1/10th from temp_c'
Temp2 = Temp2 * 10
Temp2 = Temp_c - Temp2
Temp2 = Abs(temp2)

Print "T = "; 'display T = '
If Temp_c < 0 Then Print "-"; 'display "-" if temp_c < 0'
Print Temp1 ; "," ; Temp2 ; "°C" 'display temperature as xxx,x°C'

Goto Temp_c_loop
'************************************************* ************************'
'****************************** SUBROUTINES ******************************'
Get_ds1621_temperature:

For Loops1 = 1 To 2
Ds1621_start_convert:
I2cstart
I2cwbyte Ds1621_i2c_address
I2cwbyte &HEE
I2cstop

Ds1621_check_conversion_done:
I2cstart
I2cwbyte Ds1621_i2c_address
I2cwbyte &HAC
I2cstop
I2cstart
I2cwbyte Ds1621_i2c_r_address
I2crbyte I2c_byte , Nack
I2cstop
Temp1 = I2c_byte And 1
Temp2 = I2c_byte And 128
If Temp1 = 1 Then If Temp2 = 128 Then Goto Ds1621_check_conversion_done

Ds1621_read_temp:
I2cstart
I2cwbyte Ds1621_i2c_address
I2cwbyte &HAA
I2cstop
I2cstart
I2cwbyte Ds1621_i2c_r_address

I2crbyte I2c_byte , Ack
If I2c_byte > 127 Then Temp_c = &HFF00 + I2c_byte Else Temp_c = I2c_byte
Temp_c = Temp_c * 10

I2crbyte I2c_byte , Nack
Temp1 = I2c_byte And 128
If Temp1 = 128 Then Temp_c = Temp_c + 5

I2cstop
Next
Return
'************************************************* ************************'
'********************************* DATA **********************************'

'************************************************* ************************'

peter02
31.10.2006, 21:46
Hallo Windt H.J. ,

thank you, the program works like mine. I only must change a few things.
I test it with ATMEGA32.
Do you have a version, with shows the temperature more exactly?
(not only 0,5 degrees steps)

Here the source:

'***************************************'
'* WINDT SYSTEMS *'
'* DS1621 v1.0 for 89S8252 Flash Board *'
'* 2006 / H.J. WINDT *'
'***************************************'
'----------------------------------------------------------------------------------------------------'
'This software for the 89S8252 will read the DS1621 9 bit Temperature'
'-55°C to +125°C in 0.5°C increments and display the data on a terminal program as T = xxx,x°C.'
'The temperature is read as -550 to 1250, the last digit is actually the digit behind the comma,'
'example 1: temp_c = -15 is actually -1,5°C'
'example 2: temp_c = 250 is actually 25,0°C.'
'Communication with the DS1621 is via the I2C bus.'
'Feel free to use and share this software!'
'DS1621 -->> DALLAS SEMICONDUCTOR Digital Thermometer and Thermostat'
'----------------------------------------------------------------------------------------------------'
'********************************* PORTS *********************************'
$regfile = "M32def.dat" ' chip
$crystal = 16000000 ' frequenz
$baud = 9600 ' baud rate

Config Scl = Portc.0 ' we need to provide the SCL pin name
Config Sda = Portc.1 ' we need to provide the SDA pin name

Config Lcdpin = Pin , Db4 = Portb.0 , Db5 = Portb.1 , Db6 = Portb.2 , Db7 = Portb.3 , E = Portb.5 , Rs = Portb.4
Config Lcd = 16 * 2
Config Portb = Output
Config Lcdbus = 4
'************************************************* ************************'
'******************************* VARIABLES *******************************'
Dim I2c_byte As Byte
Dim Loops1 As Byte
Dim Temp1 As Integer
Dim Temp2 As Integer
Dim Temp_c As Integer
'************************************************* ************************'
'******************************* CONSTANTS *******************************'
Const Ds1621_i2c_address = 144
Const Ds1621_i2c_r_address = 145
'************************************************* ************************'
'********************************* SETUP *********************************'
Config I2cdelay = 800
'************************************************* ************************'
'******************************** PROGRAM ********************************'
Temp_c_loop:
Gosub Get_ds1621_temperature

Temp1 = Temp_c / 10 'calculate hundreds tens ones from temp_c'
Temp1 = Abs(temp1)

Temp2 = Temp_c / 10 'calculate 1/10th from temp_c'
Temp2 = Temp2 * 10
Temp2 = Temp_c - Temp2
Temp2 = Abs(temp2)

Print "T = "; 'display T = '
If Temp_c < 0 Then Print "-"; 'display "-" if temp_c < 0'
Print Temp1 ; "," ; Temp2 ; "°C" 'display temperature as xxx,x°C'

Goto Temp_c_loop
'************************************************* ************************'
'****************************** SUBROUTINES ******************************'
Get_ds1621_temperature:

For Loops1 = 1 To 2
Ds1621_start_convert:
I2cstart
I2cwbyte Ds1621_i2c_address
I2cwbyte &HEE
I2cstop

Ds1621_check_conversion_done:
I2cstart
I2cwbyte Ds1621_i2c_address
I2cwbyte &HAC
I2cstop
I2cstart
I2cwbyte Ds1621_i2c_r_address
I2crbyte I2c_byte , Nack
I2cstop
Temp1 = I2c_byte And 1
Temp2 = I2c_byte And 128
If Temp1 = 1 Then If Temp2 = 128 Then Goto Ds1621_check_conversion_done

Ds1621_read_temp:
I2cstart
I2cwbyte Ds1621_i2c_address
I2cwbyte &HAA
I2cstop
I2cstart
I2cwbyte Ds1621_i2c_r_address

I2crbyte I2c_byte , Ack
If I2c_byte > 127 Then Temp_c = &HFF00 + I2c_byte Else Temp_c = I2c_byte
Temp_c = Temp_c * 10

I2crbyte I2c_byte , Nack
Temp1 = I2c_byte And 128
If Temp1 = 128 Then Temp_c = Temp_c + 5

I2cstop
Next
Return
'************************************************* ************************'
'********************************* DATA **********************************'

BiGF00T
31.10.2006, 22:56
I thought the minimum increment of the ds1621 is 0.5°... How should one be able to get more precision if the sensor doesn't support it? Maybe you could get an average over several values but that wouldn't be more precise... There is no point in trying to get a better resolution if the sensor can't supply better values. You could probably calculate a moving average over several values and "cheat" another decimal place this way ;)


Measures temperatures from –55°C to +125°C in
0.5°C increments.

Drifter2006
31.10.2006, 23:40
Hello,
The DS1621 is capable of higher resolutions.
By reading out the 8 bit temperature (not the 9 bit), counter and slope of the DS1621 and performing a calculation you can get a higher resolution (this can also be read in the datasheet).

I’m still working on the calculation using signed integers and I hope to test it tomorrow.
Using pen and paper the calculation seems to work. O:)
Greetings,
Windt H.J.

BiGF00T
01.11.2006, 09:10
Oh, ok... Then I retract my statement.

Drifter2006
01.11.2006, 13:37
Do you have a version, with shows the temperature more exactly?
(not only 0,5 degrees steps)


Hello,
I have had success writing new software (CCBasic C-Control) that reads and shows the temperature in smaller increments. \:D/

I translated it into Bascom 8051 but I’m not able to compile and test it (demo version of Bascom 8051).

With A few modifications it should work on an AVR.
Let me know how it works out.
Greetings,
Windt H.J.



'***************************************'
'* WINDT SYSTEMS *'
'* DS1621 v1.1 for 89S8252 Flash Board *'
'* 2006 / H.J. WINDT *'
'***************************************'
'----------------------------------------------------------------------------------------------------'
'This software for the 89S8252 will read the DS1621 8 bit Temperature, Counter And Slope and'
'display the data on a terminal as T = xxx , xx°C'
'The temperature is read as -5500 to 12500, the last 2 digits are actually the digits behind the comma,'
'example 1: temp_c = -150 is actually -1,50°C'
'example 2: temp_c = 2500 is actually 25,00°C.
'Communication with the DS1621 is via the I2C bus.'
'Feel free to use and share this software!'
'DS1621 -->> DALLAS SEMICONDUCTOR Digital Thermometer and Thermostat'
'----------------------------------------------------------------------------------------------------'
'********************************* PORTS *********************************'
Config Sda = P1.0
Config Scl = P1.1
'************************************************* ************************'
'******************************* VARIABLES *******************************'
Dim I2c_byte As Byte
Dim Loops1 As Byte
Dim Count As Byte
Dim Slope As Byte
Dim Temp1 As Integer
Dim Temp2 As Integer
Dim Temp_c As Integer
'************************************************* ************************'
'******************************* CONSTANTS *******************************'
Const Ds1621_i2c_address = &H0
Const Ds1621_i2c_r_address = &H1
'************************************************* ************************'
'********************************* SETUP *********************************'
Config I2cdelay = 800
'************************************************* ************************'
'******************************** PROGRAM ********************************'
Temp_c_loop:
Gosub Get_ds1621_temperature

Temp1 = Temp_c / 100
Temp1 = Abs(temp1)

Temp2 = Temp_c / 100
Temp2 = Temp2 * 100
Temp2 = Temp_c - Temp2
Temp2 = Abs(temp2)

Print "T = ";
If Temp_c < 0 Then Print "-";
Print Temp1 ; "," ;
If Temp2 < 10 Then Print "0";
Print Temp2 ; "°C"

Goto Temp_c_loop
'************************************************* ************************'
'****************************** SUBROUTINES ******************************'
Get_ds1621_temperature:

For Loops1 = 1 To 2
Ds1621_start_convert:
I2cstart
I2cwbyte Ds1621_i2c_address
I2cwbyte &HEE
I2cstop

Ds1621_check_conversion_done:
I2cstart
I2cwbyte Ds1621_i2c_address
I2cwbyte &HAC
I2cstop
I2cstart
I2cwbyte Ds1621_i2c_r_address
I2crbyte I2c_byte , Nack
I2cstop
Temp1 = I2c_byte And 1
Temp2 = I2c_byte And 128
If Temp1 = 1 Then If Temp2 = 128 Then Goto Ds1621_check_conversion_done

Ds1621_read_temp:
I2cstart
I2cwbyte Ds1621_i2c_address
I2cwbyte &HAA
I2cstop
I2cstart
I2cwbyte Ds1621_i2c_r_address

I2crbyte Temp_c , Nack
If Temp_c > 127 Then Temp_c = Temp_c + &HFF00
Temp_c = Temp_c * 100

Ds1621_read_count:
I2cstart
I2cwbyte Ds1621_i2c_address
I2cwbyte &HA8
I2cstop
I2cstart
I2cwbyte Ds1621_i2c_r_address
I2crbyte Count , Nack
I2cstop

Ds1621_read_slope:
I2cstart
I2cwbyte Ds1621_i2c_address
I2cwbyte &HA9
I2cstop
I2cstart
I2cwbyte Ds1621_i2c_r_address
I2crbyte Slope , Nack
I2cstop

Temp1 = Count * 100
Temp2 = Slope * 100

Temp2 = Temp2 - Temp1
Temp1 = Temp2 / Slope

Temp_c = Temp_c - 25
Temp_c = Temp_c + Temp1

I2cstop
Next
Return
'************************************************* ************************'
'********************************* DATA **********************************'

'************************************************* ************************'

PiCus
01.11.2006, 14:00
Schonmal an die Pullup widerstände gedacht ??
Bei mi geht ohne gar nix auch wenn alles ander in Ordnung ist !!

PiCus
01.11.2006, 14:02
hast du auch an Pullup Widerstände gedacht bei mir geht ohne die gar nix !!

Spion
01.11.2006, 14:05
Hallo

Die Pullup Wiederstände sind bei mir schon auf dem Board (RN-Control)
Aber ich denke es liegt an meinem Sensor, werde mir bei gelegenheit mal 2 bestellen.

mfg Luca

peter02
01.11.2006, 16:27
Hallo zusammen,

Pullups sind bei mir auch drauf (rncontrol). Weil ich es erst nicht wußte habe ich auf der DS1621 Platine noch zweimal 4,7K gelötet. Macht aber im Ergebnis keinen Unterschied.

@Drifter2006:

Kannst Du deutsch lesen?
Dein Programm klappt es super!!!!!!!

Ich habe es gerade auf meinen ATMEGA32 übertragen. Die Temperatur wird z.B. als 23.56 C angezeigt. Jetzt ist die Anzeige schon zu genau, die letzte Stelle verändert sich recht schnell.

Kann man die Anzeige etwas "dämpfen"?

Ich sehe auch, dass die Hunderterstelle sich immer in Schritten von 6 oder 7 verändert. Das heißt z.B. 23.81 dann 23.87 dann 23.93 beim erwärmen.

Gruß Peter

for_ro
01.11.2006, 17:03
Ich schätze, dass die Auflösung 1/16° C ist, genau wie beim DS1820.
Besser du zeigst die letzte Stelle garnicht an.

peter02
01.11.2006, 17:15
@for_ro

Ja das denke ich auch. Ich versuche sie gerade durch ein Format auzublenden.

Gruß Peter

Drifter2006
01.11.2006, 18:04
Kannst Du deutsch lesen?
Dein Programm klappt es super!!!!!!!

Ich habe es gerade auf meinen ATMEGA32 übertragen. Die Temperatur wird z.B. als 23.56 C angezeigt. Jetzt ist die Anzeige schon zu genau, die letzte Stelle verändert sich recht schnell.

Kann man die Anzeige etwas "dämpfen"?

Ich sehe auch, dass die Hunderterstelle sich immer in Schritten von 6 oder 7 verändert. Das heißt z.B. 23.81 dann 23.87 dann 23.93 beim erwärmen.

Gruß Peter

Hello,
I’m glad you like it!
I have made a few small changes and now the increments are 0,1°C.
Try it out and let me know if it Works.
Greetings,
Windt H.J.


'***************************************'
'* WINDT SYSTEMS *'
'* DS1621 v1.2 for 89S8252 Flash Board *'
'* 2006 / H.J. WINDT *'
'***************************************'
'----------------------------------------------------------------------------------------------------'
'This software for the 89S8252 will read the DS1621 8 bit Temperature, Counter And Slope and'
'display the data on a terminal as T = xxx , x°C in 0,1°C increments'
'The temperature is read as -550 to 1250, the last digit is actually the digit behind the comma,'
'example 1: temp_c = -15 is actually -1,5°C'
'example 2: temp_c = 250 is actually 25,0°C.
'Communication with the DS1621 is via the I2C bus.'
'Feel free to use and share this software!'
'DS1621 -->> DALLAS SEMICONDUCTOR Digital Thermometer and Thermostat'
'----------------------------------------------------------------------------------------------------'
'********************************* PORTS *********************************'
Config Sda = P1.0
Config Scl = P1.1
'************************************************* ************************'
'******************************* VARIABLES *******************************'
Dim I2c_byte As Byte
Dim Loops1 As Byte
Dim Count As Byte
Dim Slope As Byte
Dim Temp1 As Integer
Dim Temp2 As Integer
Dim Temp_c As Integer
'************************************************* ************************'
'******************************* CONSTANTS *******************************'
Const Ds1621_i2c_address = &H0
Const Ds1621_i2c_r_address = &H1
'************************************************* ************************'
'********************************* SETUP *********************************'
Config I2cdelay = 800
'************************************************* ************************'
'******************************** PROGRAM ********************************'
Temp_c_loop:
Gosub Get_ds1621_temperature

Temp1 = Temp_c / 10
Temp1 = Abs(temp1)

Temp2 = Temp_c / 10
Temp2 = Temp2 * 10
Temp2 = Temp_c - Temp2
Temp2 = Abs(temp2)

Print "T = ";
If Temp_c < 0 Then Print "-";
Print Temp1 ; "," ; Temp2 ; "°C"

Goto Temp_c_loop
'************************************************* ************************'
'****************************** SUBROUTINES ******************************'
Get_ds1621_temperature:

For Loops1 = 1 To 2
Ds1621_start_convert:
I2cstart
I2cwbyte Ds1621_i2c_address
I2cwbyte &HEE
I2cstop

Ds1621_check_conversion_done:
I2cstart
I2cwbyte Ds1621_i2c_address
I2cwbyte &HAC
I2cstop
I2cstart
I2cwbyte Ds1621_i2c_r_address
I2crbyte I2c_byte , Nack
I2cstop
Temp1 = I2c_byte And 1
Temp2 = I2c_byte And 128
If Temp1 = 1 Then If Temp2 = 128 Then Goto Ds1621_check_conversion_done

Ds1621_read_temp:
I2cstart
I2cwbyte Ds1621_i2c_address
I2cwbyte &HAA
I2cstop
I2cstart
I2cwbyte Ds1621_i2c_r_address

I2crbyte Temp_c , Nack
If Temp_c > 127 Then Temp_c = Temp_c + &HFF00
Temp_c = Temp_c * 100

Ds1621_read_count:
I2cstart
I2cwbyte Ds1621_i2c_address
I2cwbyte &HA8
I2cstop
I2cstart
I2cwbyte Ds1621_i2c_r_address
I2crbyte Count , Nack
I2cstop

Ds1621_read_slope:
I2cstart
I2cwbyte Ds1621_i2c_address
I2cwbyte &HA9
I2cstop
I2cstart
I2cwbyte Ds1621_i2c_r_address
I2crbyte Slope , Nack
I2cstop

Temp1 = Count * 100
Temp2 = Slope * 100

Temp2 = Temp2 - Temp1
Temp1 = Temp2 / Slope

Temp_c = Temp_c - 25
Temp_c = Temp_c + Temp1
Temp_c = Temp_c / 10

I2cstop
Next
Return
'************************************************* ************************'
'********************************* DATA **********************************'

'************************************************* ************************'

peter02
01.11.2006, 18:11
Hi Drifter2006,
ich probiere es gleich. Hier ist meine letzte Modifikation. Jetzt wird die Temperatur 24.1 also eine Stelle hintern Komma angezeigt. Das ist schon sehr gut.

Code:

'***************************************'
'* WINDT SYSTEMS *'
'* DS1621 v1.1 for 89S8252 Flash Board *'
'* 2006 / H.J. WINDT *'
'***************************************'
'----------------------------------------------------------------------------------------------------'
'This software for the 89S8252 will read the DS1621 8 bit Temperature, Counter And Slope and'
'display the data on a terminal as T = xxx , xx°C'
'The temperature is read as -5500 to 12500, the last 2 digits are actually the digits behind the comma,'
'example 1: temp_c = -150 is actually -1,50°C'
'example 2: temp_c = 2500 is actually 25,00°C.
'Communication with the DS1621 is via the I2C bus.'
'Feel free to use and share this software!'
'DS1621 -->> DALLAS SEMICONDUCTOR Digital Thermometer and Thermostat'
'----------------------------------------------------------------------------------------------------'
'********************************* PORTS *********************************'
$regfile = "M32def.dat" ' chip
$crystal = 16000000 ' frequenz
$baud = 9600 ' baud rate

$hwstack = 32 ' default use 32 for the hardware stack
$swstack = 10 ' default use 10 for the SW stack
$framesize = 40 ' default use 40 for the frame space


Config Scl = Portc.0 ' we need to provide the SCL pin name
Config Sda = Portc.1 ' we need to provide the SDA pin name

Config Lcdpin = Pin , Db4 = Portb.0 , Db5 = Portb.1 , Db6 = Portb.2 , Db7 = Portb.3 , E = Portb.5 , Rs = Portb.4
Config Lcd = 16 * 2
Config Portb = Output
Config Lcdbus = 4

'************************************************* ************************'
'******************************* VARIABLES *******************************'
Dim ___lcdno As Bit
Dim I2c_byte As Byte
Dim Loops1 As Byte
Dim Count As Byte
Dim Slope As Byte
Dim Temp1 As Integer
Dim Temp2 As Integer
Dim Temp_c As Integer
Dim Temp2_2 As String * 16

'************************************************* ************************'
'******************************* CONSTANTS *******************************'
Const Ds1621_i2c_address = 144
Const Ds1621_i2c_r_address = 145
'************************************************* ************************'
'********************************* SETUP *********************************'
Config I2cdelay = 80
'************************************************* ************************'
'******************************** PROGRAM ********************************'

Cls
Cursor Off Noblink 'hide cursor
Temp_c_loop:
Gosub Get_ds1621_temperature

Temp1 = Temp_c / 100
Temp1 = Abs(temp1)

Temp2 = Temp_c / 100
Temp2 = Temp2 * 100
Temp2 = Temp_c - Temp2
Temp2 = Abs(temp2)

Temp2 = Temp2 / 10
Temp2 = Abs(temp2)

Print "T = ";
If Temp_c < 0 Then Print "-";
Print Temp1 ; "," ;
If Temp2 < 10 Then Print "0";
Print Temp2 ; " C"


Locate 1 , 1
Wait 1
Lcd Temp1 ; "." ; Temp2
Locate 1 , 5
Lcd " C Wohnraum"

Goto Temp_c_loop
'************************************************* ************************'
'****************************** SUBROUTINES ******************************'
Get_ds1621_temperature:

For Loops1 = 1 To 2
Ds1621_start_convert:
I2cstart
I2cwbyte Ds1621_i2c_address
I2cwbyte &HEE
I2cstop

Ds1621_check_conversion_done:
I2cstart
I2cwbyte Ds1621_i2c_address
I2cwbyte &HAC
I2cstop
I2cstart
I2cwbyte Ds1621_i2c_r_address
I2crbyte I2c_byte , Nack
I2cstop
Temp1 = I2c_byte And 1
Temp2 = I2c_byte And 128
If Temp1 = 1 Then If Temp2 = 128 Then Goto Ds1621_check_conversion_done

Ds1621_read_temp:
I2cstart
I2cwbyte Ds1621_i2c_address
I2cwbyte &HAA
I2cstop
I2cstart
I2cwbyte Ds1621_i2c_r_address

I2crbyte Temp_c , Nack
If Temp_c > 127 Then Temp_c = Temp_c + &HFF00
Temp_c = Temp_c * 100

Ds1621_read_count:
I2cstart
I2cwbyte Ds1621_i2c_address
I2cwbyte &HA8
I2cstop
I2cstart
I2cwbyte Ds1621_i2c_r_address
I2crbyte Count , Nack
I2cstop

Ds1621_read_slope:
I2cstart
I2cwbyte Ds1621_i2c_address
I2cwbyte &HA9
I2cstop
I2cstart
I2cwbyte Ds1621_i2c_r_address
I2crbyte Slope , Nack
I2cstop

Temp1 = Count * 100
Temp2 = Slope * 100

Temp2 = Temp2 - Temp1
Temp1 = Temp2 / Slope

Temp_c = Temp_c - 25
Temp_c = Temp_c + Temp1

I2cstop
Next
Return

'************************************************* ************************'
'********************************* DATA **********************************'

'************************************************* ************************'

peter02
01.11.2006, 18:20
Hi Drifter2006,

es klappt genau so, wie meine Modifikation.

Ich denke, es ist perfekt. Die Anzeige ist stabil und beim Erwärmen und Abkühlen geht die Anzeige in 0.1 Grad Schritten hoch oder runter.

Danke,

Peter

peter02
01.11.2006, 18:24
Drifter2006 hast Du noch ein paar Programme, die man mal ausprobieren kann? Ich bin noch recht neu dabei und sammel noch alles was ich bekommen kann.

Gruß Peter

Drifter2006
01.11.2006, 18:59
Hello Peter,
I think I found a small error in your modification:

You wrote:

Temp2 = Temp2 / 10
Temp2 = Abs(temp2)
Print "T = ";
If Temp_c < 0 Then Print "-";
Print Temp1 ; "," ;
If Temp2 < 10 Then Print "0";
Print Temp2 ; " C"
Locate 1 , 1
Wait 1
Lcd Temp1 ; "." ; Temp2
Locate 1 , 5
Lcd " C Wohnraum"


I think should be:

Temp2 = Temp2 / 10
Wait 1
Locate 1 , 1
If Temp_1 < 0 then Lcd "-";
Lcd Temp1 ; "." ; Temp2 ; " C Wohnraum "

The rest can be deleted.

This was my first real attempt at writing a Bascom 8051 program so I don’t have any software, yet. :)
Greetings,
H.J. Windt

peter02
02.11.2006, 20:42
Hallo Drifter2006,
ja, das hatte ich vergessen.
Ich habe auch einen Fehler in Deiner Korrektur gefunden. Temp_1 gibt es nicht, es muß Temp1 heißen. Aber jetzt klappt wieder alles. Ich wollte mal ein Innen/Außentermometer bauen, da ist natürlich das Minuszeichen wichtig.

Jedenfalls war es für Deinen ersten Versuch garnicht mal so schlecht.

Gruß Peter

Drifter2006
02.11.2006, 21:32
Hello peter02,


Ich habe auch einen Fehler in Deiner Korrektur gefunden. Temp_1 gibt es nicht, es muß Temp1 heißen. Aber jetzt klappt wieder alles.

I’m glad you mentioned this!!
This is also wrong, it should be "Temp_c", oops, my fault. #-o
I also found one more error in your modification and corrected it otherwise -0,0 could be displayed.
Here is the corrected version:


'********************************* PORTS *********************************'
$regfile = "M32def.dat" ' chip
$crystal = 16000000 ' frequenz
$baud = 9600 ' baud rate

$hwstack = 32 ' default use 32 for the hardware stack
$swstack = 10 ' default use 10 for the SW stack
$framesize = 40 ' default use 40 for the frame space


Config Scl = Portc.0 ' we need to provide the SCL pin name
Config Sda = Portc.1 ' we need to provide the SDA pin name

Config Lcdpin = Pin , Db4 = Portb.0 , Db5 = Portb.1 , Db6 = Portb.2 , Db7 = Portb.3 , E = Portb.5 , Rs = Portb.4
Config Lcd = 16 * 2
Config Portb = Output
Config Lcdbus = 4

'************************************************* ************************'
'******************************* VARIABLES *******************************'
Dim ___lcdno As Bit
Dim I2c_byte As Byte
Dim Loops1 As Byte
Dim Count As Byte
Dim Slope As Byte
Dim Temp1 As Integer
Dim Temp2 As Integer
Dim Temp_c As Integer
'************************************************* ************************'
'******************************* CONSTANTS *******************************'
Const Ds1621_i2c_address = 144
Const Ds1621_i2c_r_address = 145
'************************************************* ************************'
'********************************* SETUP *********************************'
Config I2cdelay = 80
'************************************************* ************************'
'******************************** PROGRAM ********************************'

Cls
Cursor Off Noblink 'hide cursor
Temp_c_loop:
Gosub Get_ds1621_temperature

Temp1 = Temp_c / 10 'get hundreds tens ones xxx,'
Temp1 = Abs(temp1)

Temp2 = Temp_c / 10 'get 1/10 ,x'
Temp2 = Temp2 * 10
Temp2 = Temp_c - Temp2
Temp2 = Abs(temp2)

Locate 1 , 1
If Temp_c < 0 Then Lcd "-"; 'print "-" if temp_c is negative'
Lcd Temp1 ; "." ; Temp2 ; " C Wohnraum " 'print xxx.x C Wohnraum'
Wait 1
Goto Temp_c_loop

'************************************************* ************************'
'****************************** SUBROUTINES ******************************'
Get_ds1621_temperature:

For Loops1 = 1 To 2
Ds1621_start_convert:
I2cstart
I2cwbyte Ds1621_i2c_address
I2cwbyte &HEE
I2cstop

Ds1621_check_conversion_done:
I2cstart
I2cwbyte Ds1621_i2c_address
I2cwbyte &HAC
I2cstop
I2cstart
I2cwbyte Ds1621_i2c_r_address
I2crbyte I2c_byte , Nack
I2cstop
Temp1 = I2c_byte And 1
Temp2 = I2c_byte And 128
If Temp1 = 1 Then If Temp2 = 128 Then Goto Ds1621_check_conversion_done

Ds1621_read_temp:
I2cstart
I2cwbyte Ds1621_i2c_address
I2cwbyte &HAA
I2cstop
I2cstart
I2cwbyte Ds1621_i2c_r_address

I2crbyte Temp_c , Nack
If Temp_c > 127 Then Temp_c = Temp_c + &HFF00
Temp_c = Temp_c * 100

Ds1621_read_count:
I2cstart
I2cwbyte Ds1621_i2c_address
I2cwbyte &HA8
I2cstop
I2cstart
I2cwbyte Ds1621_i2c_r_address
I2crbyte Count , Nack
I2cstop

Ds1621_read_slope:
I2cstart
I2cwbyte Ds1621_i2c_address
I2cwbyte &HA9
I2cstop
I2cstart
I2cwbyte Ds1621_i2c_r_address
I2crbyte Slope , Nack
I2cstop

Temp1 = Count * 100
Temp2 = Slope * 100

Temp2 = Temp2 - Temp1
Temp1 = Temp2 / Slope

Temp_c = Temp_c - 25
Temp_c = Temp_c + Temp1

Temp_c = Temp_c / 10 'get rid of last digit xxxxx becomes xxxx'
I2cstop
Next
Return

'************************************************* ************************'

Success and greetings,
Drifter2006

peter02
03.11.2006, 08:28
Hallo Drifter2006,

danke, das hatte ich gar nicht bemerkt. Hätte ich warscheinlich gesehen, wenn der Außenfühler angeschlossen ist.
Heute oder morgen kommt noch ein zweiter DS1621 dazu. Weißt du wie ich die "Jumper" setzen muß? Jetzt haben wir ja 144 und 145 genommen weil alle drei Addresseingänge auf Masse sind.
Die Angaben in dem Datenblatt verstehe ich nicht.

Gruß Peter

Drifter2006
03.11.2006, 09:04
Hallo Drifter2006,

danke, das hatte ich gar nicht bemerkt. Hätte ich warscheinlich gesehen, wenn der Außenfühler angeschlossen ist.
Heute oder morgen kommt noch ein zweiter DS1621 dazu. Weißt du wie ich die "Jumper" setzen muß? Jetzt haben wir ja 144 und 145 genommen weil alle drei Addresseingänge auf Masse sind.
Die Angaben in dem Datenblatt verstehe ich nicht.

Gruß Peter

Hello,

Pins 5, 6 and 7 are the I2C address selection pins and must be connected to Vcc or GND .
The program uses address 144, this means that pins 5,6 and 7 must be connected to GND.

To connect a 2nd DS1621 you need a different address which can be adjusted with these pins.
Example: for the 2nd DS1621 connect pin5 to GND, pin 6 to GND and pin 7 to Vcc.
This will adjust the 2nd DS1621 address to 146.

I2C Write address of the DS1621:
[1] [0] [0] [1] [A2 pin 5] [A1 pin 6] [A0 pin 7] [0]

As you can see: connecting pin 5,6 and 7 to GND will create I2C address 10010000 -> 144
144 is now the write address and 145 is the read address

Connecting pin 5 and 6 to GND and pin 7 to Vcc will create I2C address 10010010 -> 146
146 is now the Write address and 147 is now the Read address.

The Read address is always the Write address + 1

Greetings,
Drifter2006

peter02
03.11.2006, 17:51
Hallo Drifter2006,

danke, das hört sich ja einfach an. Ich konnte es aus dem Datenblatt nicht ersehen.
Du schreibst "As you can see: connecting pin 5,6 and 7 to GND will create I2C address 10010000 -> 144 " Frage: wie kann ich es sehen? Kann man den I2C Bus nach vorhandenen Devices scannen?

Kannst Du das Programm auf einen zweiten DS1621 erweitern? Er soll in der zweiten LCD Zeile die Aussentemperatur anzeigen.

Gruß Peter

ZwieBack
12.11.2006, 10:46
Mahlzeit,

ich steh auch vor dem problem das ich entweder 0 oder 255 ausgegeben bekomme, hab schon mit den ganzen sachen die hier stehen rumprobiert, ich komme aber immer wieder auf die oben genannten werte. Kann ich den DS1621 irgendwie testen ob er überhaupt funktioniert?

Gruss ZB

peter02
14.11.2006, 05:43
Hallo ZB,
nur in einer funktionierenden Schaltung.

Ich habe meinen DS1621 folgendermaßen angeschlossen:

Pin1 SDA
Pin2 SCL
Pin4 GND
Pin8 VDD
Pin7 GND A0
Pin6 GND A1
Pin5 GND A2

dazu passend:

Device = 144
Deviceread = 145

Die hier vorgestellten Programme klappen.
Eine kurze Plus/Minus Vertauschung zerstört den DS1621.

Gruß Peter

peter02
14.11.2006, 05:52
Hallo zusammen,
leider meldet sich Drifter2006 nicht mehr.
Vielleicht kann sonst noch jemand helfen.

Ich habe noch ein Problem mit dem DS1621:
Bei Temperaturen um die 10 Grad scheint sich die Temperaturanzeige nur noch in 1 Grad Schritten zu bewegen. Die Stelle hinter dem Komma steht fest.

Bei ca. 20 Grad ist alles OK.

Es scheint noch ein Fehler in der Berechnung zu sein.


Gruß Peter

Drifter2006
14.11.2006, 16:32
Hello peter02,
Sorry for taking so long, I was having some PC problems that needed sorting out. ](*,)
I’m not completely sure about your problem; it could be that you have the I2C bus frequency too high.
Try slowing down the frequency ex. Config I2Cdelay = 10000.
Greetings,
Drifter2006

peter02
14.11.2006, 17:03
Hallo Drifter2006,
schön das du wieder da bist. Ich hoffe du kannst deine PC Probleme schnell lösen.

Ich habe "unsere" Schaltung als Innen / Aussen Termometer erweitert.
Config Twi = 100000 habe ich schon recht lange drin - ohne kommen zuviele Messfehler.
Aber was ich meine: Die innentemperatur liegt so zwischen 19 und 24 C.
Aussen haben wir zwischen 8 und 13 C. Innen ist alles OK.

Aussen hat man den Eindruck, dass die Temperatur nur in 1 C Schritten wechselt. z.B. wenn es kälter wird von 10,1 direkt auf 9,1. Kann es sein, dass die Berechnung einen Fehler enthält??

Hier mal meine letzte Version:

'********************************* PORTS *********************************'
$regfile = "M32def.dat" ' chip
$crystal = 16000000 ' frequenz
$baud = 19200 ' baud rate

$hwstack = 32 ' default use 32 for the hardware stack
$swstack = 10 ' default use 10 for the SW stack
$framesize = 40 ' default use 40 for the frame space
$lib "I2C_TWI.LBX"

Config Scl = Portc.0 ' we need to provide the SCL pin name
Config Sda = Portc.1 ' we need to provide the SDA pin name
Config Twi = 100000 ' wanted clock frequency
'Twbr = 12 'bit rate register 'will set TWBR and TWSR
'Twsr = 0 'pre scaler bits

Config Lcdpin = Pin , Db4 = Portb.3 , Db5 = Portb.2 , Db6 = Portb.1 , Db7 = Portb.0 , E = Portb.5 , Rs = Portb.7 ' Pinbelegung "LCD-Port)"
Config Lcd = 20 * 4a , Chipset = Ks077 ' LCD 204 DIP 20x4
'Config Lcd = 16 * 2 , Chipset = Dogm163v5 , Contrast = &H702 ' EA DOGM162W-A
Config Portb = Output
Config Lcdbus = 4

Config Portc.6 = Output 'Toggle bei jeder Messung die LED C.6
Config Portc.7 = Output 'Temperatur unter 0 °C LED C.7

'************************************************* ************************'
'******************************* VARIABLES *******************************'
Dim ___lcdno As Bit
Dim I2c_byte As Byte
Dim Loops1 As Byte
Dim Count As Byte
Dim Slope As Byte
Dim Temp1 As Integer
Dim Temp2 As Integer
Dim Temp3 As Integer
Dim Temp_cor As Integer
Dim Temp3_s As String * 16
Dim Temp_c As Integer
Dim Ds1621_i2c_address As Integer
Dim Ds1621_i2c_r_address As Integer
'************************************************* ************************'
Config I2cdelay = 800
Initlcd
Deflcdchar 1 , 3 , 3 , 32 , 32 , 32 , 32 , 32 , 32 ' replace ? with number (0-7)
Cls
Cursor Off Noblink 'hide cursor
'************************************************* ************************'
'******************************** PROGRAM ********************************'

'***** Innen
Temp_c_loop:
Ds1621_i2c_address = 144
Ds1621_i2c_r_address = 145
Temp_cor = 0
Gosub Get_ds1621_temperature

Print "oben"
Print "Temp1" ; " " ; Temp1 ; " " ; "Temp2" ; " " ; Temp2 ; " " ; "Temp3" ; " " ; Temp3 ; " " ; "Temp_c" ; " " ; Temp_c 'Test auf das Terminal
Print " "

Temp1 = Temp_c / 10 'get hundreds tens ones xxx,'
Temp1 = Abs(temp1)

Temp2 = Temp_c / 10 'get 1/10 ,x'
Temp2 = Temp2 * 10
Temp2 = Temp_c - Temp2
Temp2 = Abs(temp2)
Temp3 = Temp1 * 10
Temp3 = Temp3 + Temp2
Temp3 = Temp3 + Temp_cor ' fuer den Korrekturfaktor
Temp3_s = Str(temp3) ' der Formatbefehl erfordert einen String

Toggle Portc.6 'Toggle bei jeder Messung

Locate 1 , 1
If Temp_c < 0 Then Lcd "-"; 'print "-" if temp_c is negative'
Locate 1 , 2
Lcd Format(temp3_s , "00.0") ; Chr(1) ; "C Innen" 'print xxx.x C Wohnraum'

Print "unten"
Print "Temp1" ; " " ; Temp1 ; " " ; "Temp2" ; " " ; Temp2 ; " " ; "Temp3" ; " " ; Temp3 ; " " ; "Temp_c" ; " " ; Temp_c 'Test auf das Terminal
Print " "

Wait 1
'Goto Temp_c_loop ' nur bei einer Temperatur


'***** Aussen
'Temp_c_loop:
Ds1621_i2c_address = 146
Ds1621_i2c_r_address = 147
Temp_cor = 0
Gosub Get_ds1621_temperature

Temp1 = Temp_c / 10 'get hundreds tens ones xxx,'
Temp1 = Abs(temp1)

Temp2 = Temp_c / 10 'get 1/10 ,x'
Temp2 = Temp2 * 10
Temp2 = Temp_c - Temp2
Temp2 = Abs(temp2)
Temp3 = Temp1 * 10
Temp3 = Temp3 + Temp2 ' fuer den Korrekturfaktor
Temp3_s = Str(temp3) ' der Formatbefehl erfordert einen String

Locate 2 , 1
If Temp_c < 0 Then Lcd "-"; 'print "-" if temp_c is negative'

Locate 2 , 2
If Temp1 < 10 Then
Lcd " " ; Format(temp3_s , "0.0") ; Chr(1) ; "C Aussen" ' unter 10 C print x.x C Aussen'
Else ' über 10 C print xx.x C Aussen'
Lcd Format(temp3_s , "00.0") ; Chr(1) ; "C Aussen"
End If

'Print "Temp1" ; " " ; Temp1 ; " " ; "Temp2" ; " " ; Temp2 ; " " ; "Temp3" ; " " ; Temp3 'Test auf das Terminal

Wait 1
Goto Temp_c_loop

'************************************************* ************************'
'****************************** SUBROUTINES ******************************'
Get_ds1621_temperature:

For Loops1 = 1 To 2
Ds1621_start_convert:
I2cstart
I2cwbyte Ds1621_i2c_address
I2cwbyte &HEE
I2cstop
Waitms 25

Ds1621_check_conversion_done:
I2cstart
I2cwbyte Ds1621_i2c_address
I2cwbyte &HAC
I2cstop
Waitms 25
I2cstart
I2cwbyte Ds1621_i2c_r_address
I2crbyte I2c_byte , Nack
I2cstop
Waitms 25
Temp1 = I2c_byte And 1
Temp2 = I2c_byte And 128
If Temp1 = 1 Then If Temp2 = 128 Then Goto Ds1621_check_conversion_done

Ds1621_read_temp:
I2cstart
I2cwbyte Ds1621_i2c_address
I2cwbyte &HAA
I2cstop
Waitms 25
I2cstart
I2cwbyte Ds1621_i2c_r_address

I2crbyte Temp_c , Nack
If Temp_c > 127 Then Temp_c = Temp_c + &HFF00
Temp_c = Temp_c * 100

Ds1621_read_count:
I2cstart
I2cwbyte Ds1621_i2c_address
I2cwbyte &HA8
I2cstop
Waitms 25
I2cstart
I2cwbyte Ds1621_i2c_r_address
I2crbyte Count , Nack
I2cstop
Waitms 25

Ds1621_read_slope:
I2cstart
I2cwbyte Ds1621_i2c_address
I2cwbyte &HA9
I2cstop
Waitms 25
I2cstart
I2cwbyte Ds1621_i2c_r_address
I2crbyte Slope , Nack
I2cstop
Waitms 25

Temp1 = Count * 100
Temp2 = Slope * 100

Temp2 = Temp2 - Temp1
Temp1 = Temp2 / Slope

Temp_c = Temp_c - 25
Temp_c = Temp_c + Temp1

Temp_c = Temp_c / 10 'get rid of last digit xxxxx becomes xxxx'
I2cstop
Next
Return

'************************************************* ************************'

Gruß Peter

ZwieBack
14.11.2006, 17:33
Hallo ZB,
nur in einer funktionierenden Schaltung.

Ich habe meinen DS1621 folgendermaßen angeschlossen:

Pin1 SDA
Pin2 SCL
Pin4 GND
Pin8 VDD
Pin7 GND A0
Pin6 GND A1
Pin5 GND A2

dazu passend:

Device = 144
Deviceread = 145

Die hier vorgestellten Programme klappen.
Eine kurze Plus/Minus Vertauschung zerstört den DS1621.

Gruß Peter

ja so hab ichs auch angeschlossen, hab mit dem Datenblatt gearbeitet.

a) kann ich Pin3 (Tout) einfach frei lassen oder auf GND?

b) ich kann also nicht davon ausgehen, das wenn ich nach vershiedenen Tests mal 0 und ma 255 rausbekomm der DS1621 noch funktionstüchtig ist?

Gruss ZB

peter02
14.11.2006, 17:44
Hallo ZB,
Pin 3 ist ein Schaltausgang, den kannst Du freilassen.

Hast Du das Programm von Drifter2006 und mir genommen?
Hast Du am DS1621 mit einem Multimeter die Spannung gemessen?

0 und 255 heisst eigentlich - kein DS1621 auf dieser Adresse.

Gruß Peter

Drifter2006
14.11.2006, 19:55
Hello peter02,
I’m not sure what Bascom AVR will do if the byte to be sent is defined as an integer.
Try changing the “Dim Ds1621_i2c_address As Integer” To “Dim Ds1621_i2c_address As Byte” and “Dim Ds1621_i2c_r_address As Integer” To “Dim DS1621_i2c_r_address As Byte”.

What is the length of your cable to the outside DS1621?

Greetings,
Drifter2006

peter02
14.11.2006, 20:21
Hallo Drifter2006,
die Änderung hat keinen Unterschied ergeben.
Die Kabellänge des Innen und Aussenfühlers sind je 2m.

Ich habe gerade mal einen dritten Fühler in einen Becher gesteckt, der 1 Std. im Eisfach war. Ich konnte die Temperatur auf 3 Grad C senken. Die Anzeige kam exact in 0,1 Grad Schritten runter. Alles OK.

Ich habe den Aussenfühler in einen Plastikdeckel mit ca. 2 cm Durchmesser mit Expoxy eingegossen. Er reagiert durch die Isolierung wohl recht langsam. Er steht jetzt schon seit einer Stunde auf 12,9 Grad.

Ich werde das mal ein paar Tage beobachten und vielleicht mal einen anderen DS1621 für draußen nehmen. Das Programm scheint OK zu sein.

Gruß Peter

ensacom
31.10.2007, 15:27
Ich bekomme immer -0.2 C Wohnraum.
Woran kann das liegen?
Egal was ich mache der Wert ändert sich nicht