Zur Übersicht - Zurück zur Homepage
Re: DS 16521 / P.S. höhere Auflösung Kategorie: Sensoren (von: Willi aus Oelde - 27.11.2001 21:20)
Als Antwort auf: Re: DS 16521 / P.S. höhere Auflösung von Herbert - 25.11.2001 12:33

Hallo Leute !
In Turbobasic läuft das Programm schon !
Achtung : Es geht scheinbar nicht jeder LPT Port.

Das Prinzip :

1) Sensor in One-shot Mode setzen
2) Conf. Lesen und Prüfung, ob Wandlung fertig ( Bit 7)
3) Temp wie gewohnt lesen
4) Slope und Counter lesen
5) Conversion wieder starten
6) Wenn Slope <> 0 Temp = Temp - 0,25+(C-S)/S

Auflösung : ca. 0,025 Grad ! ( Nicht die Genauigkeit )

Mfg,
Willi

Anlage : Turbobasicprogramm
( Bitte den Stil entschuldigen )
In CC2 auch schon lauffähig, ist aber so programmiert, das ich es keinem zeigen will !


'DS1621 Ansteuerung f?r parallelen Port des DS 1621

Cls

Print " Programm setzt DS1621 Adr. 150 in One Shot Mode !!
Print " Mit < Return > beenden !

PortD = &H0378
PortC = &H037A

Defint i,j,x,z,W,s,c


Gosub Stromein 'Autofeed 5 Volt ein
'Gosub Stromaus

'---- Bus l”schen falls noch Daten anstehen ----
Gosub Sclon : Gosub Scloff ' Scl ist immer Ausgang
For I=0 to 7: Gosub PulseScl: Next I : Gosub Sclon

' --- Temperatursensoren initialisieren ---
For J = 0 to 7 : Adr = &H90+2*J : Gosub Init : Next J

For I = 1 to 5000 : Next

Time$="000000"
' --- Alle Temperaturen anzeigen ---
Schleife:
For J = 0 to 7
Adr = &H90+2*J

' Nochmal:
Gosub ReadConfig
v=v+1 : If V > 1000 then Wert = 255
If Wert < 128 Goto Nochmal
V=0
Gosub ReadTemp
Gosub ReadCounter : C = Wert
Gosub ReadSlope : S = Wert : If S = 0 THen S = 1
Gosub StartConversion
Locate (5+j),2 : Print "Temp ";j;"= ";V$;Using "###.##";T-.25+(s-c)/s
Locate 20,6: Print " Z = ";Z :
Nochmal:
Next J
Z=Z+1
Print Time$

If inkey$ = "" then Schleife ' Auf Return warten
END


ReadTemp:
'-- Parameter setzen 2-Byte Kommando ---
Gosub I2CStart 'Start
Wert = Adr : Gosub Senden
Wert = &HAA : Gosub Senden
Gosub SCLon : Gosub SDAoff : Gosub SCLoff ' Repeated Start
Wert =Adr+1 : Gosub Senden ' Lesebit (+1 !)
Gosub LeseByte : If ( Wert and &H80) then v$ = "-" else V$="+"
T=( Wert and &H7F )
Gosub SDAoff : Gosub PulseSCL ' Master ackn.
Gosub LeseByte
If (Wert and &H80) then T=T+0.5 ' Print ",5 øCel." else Print ",0 øCel."
' Locate (3+j),2 : Print "Temp =";j;V$;Using "###.##";T
Gosub SDAon : Gosub PulseSCL ' Master not ackn.
Goto I2CStop

ReadConfig:
'-- Parameter setzen 1-Byte Kommando ---
Gosub I2CStart 'Start
Wert = Adr : Gosub Senden
Wert = &HAC : Gosub Senden
Gosub SCLon : Gosub SDAoff : Gosub SCLoff ' Repeated Start
Wert =Adr+1 : Gosub Senden ' Lesebit (+1 !)
Gosub LeseByte
Locate (5+j),50 : Print "Config =";Using "####";Wert;
Print " -";right$ ("0000" +Bin$(Wert),8)
Gosub SDAon : Gosub PulseSCL ' Master not ackn.
Goto I2CStop




ReadCounter:
'-- Parameter setzen 1-Byte Kommando ---
Gosub I2CStart 'Start
Wert = Adr : Gosub Senden
Wert = &HA8 : Gosub Senden
Gosub SCLon : Gosub SDAoff : Gosub SCLoff ' Repeated Start
Wert =Adr+1 : Gosub Senden ' Lesebit (+1 !)
Gosub LeseByte
Locate (5+j),21 : Print "Count =";Using "####";Wert
Gosub SDAon : Gosub PulseSCL ' Master not ackn.
Goto I2CStop


ReadSlope:
'-- Parameter setzen 1-Byte Kommando ---
Gosub I2CStart 'Start
Wert = Adr : Gosub Senden
Wert = &HA9 : Gosub Senden
Gosub SCLon : Gosub SDAoff : Gosub SCLoff ' Repeated Start
Wert =Adr+1 : Gosub Senden ' Lesebit (+1 !)
Gosub LeseByte
Locate (5+j),35 : Print "Slope =";Using "####";Wert
Gosub SDAon : Gosub PulseSCL ' Master not ackn.
Goto I2CStop

End
'---------------------------------------
'Senden1:
' Gosub I2CStart ' IýC - Start
' Wert = Adr
' Gosub Senden ' Adresse senden
' Wert = Daten
' Gosub Senden ' Wert Senden
'Goto I2CStop ' Stop IýC Bus

Senden:
Out PortC,Inp(PortC) ' and 233 'Gosub Ausgang
For I = 0 to 7
If (Wert and &H80) then Gosub SDAon else Gosub SDAoff
Out PortC,Inp(PortC) xor 8 ' wie
Out PortC,Inp(PortC) xor 8 ' Gosub PulseScl
Wert = Wert*2
Next I
Out PortC,Inp(PortC) or 32 ' Gosub Eingang
Out PortC,Inp(PortC) and 247 ' Gosub Sclon /Hier kann man "Ackn." abfragen !
Goto Scloff ' Mit Goto spart ein Return aber gef„hrlich !

LeseByte:
Wert = 0
Out PortC,Inp(PortC) or 32 'Gosub Eingang 'Deact SDA
For I = 1 to 8
Wert = Wert*2
Out PortC,Inp(PortC) and 247 'Gosub SCLon
If Inp(Portd) and 1 then incr Wert
Out PortC,Inp(PortC) or 8 ' entspricht Gosub SCLoff
Next I
Return

Start:
Out PortC,Inp(PortC) ' and 223 ' Gosub Ausgang
Out PortD,1
Return

SDAoff:
' Gosub Ausgang ' Muss hier stehen !
Out PortC,Inp(PortC) and 223 ' Hier MUSS and 233 stehen !
Out PortD,0
Return

SDAon:
' Gosub Ausgang Muá nicht sein
Out PortD,1
Return

SCLon:
Out PortC,Inp(PortC) and 247
Return

I2CStart:
Gosub SDAoff
'Gosub SCLoff 'Start

SCLoff:
Out PortC,Inp(PortC) or 8
Return

PulseSCL: ' Kommt mit high raus ( invertiert )
Out PortC,Inp(Portc) xor 8
Out PortC,Inp(PortC) xor 8
Return

Eingang:
Out PortC,Inp(PortC) or 32
Return

Ausgang:
Out PortC,Inp(PortC)' and 223)
Return

Stromaus:
X=(Inp(PortC) or 2) : Out PortC,x
Return

Stromein:
X=(inp(CPort) and 253) : Out CPort,x
Return

'-- Parameter setzen 2-Byte Kommando ---
Init:
Gosub I2CStart
Wert = Adr : Gosub Senden
Wert = &HAC : Gosub Senden
Wert = &H03 : Gosub Senden 'Setze 1 Shot mode !
Gosub I2CStop

SetTL:
Gosub I2CStart ' I2C Start
Wert = Adr : Gosub Senden
Wert = &HA2 : Gosub Senden
For I = y to 500 : Next
Wert = 25 : Gosub Senden
For I = y to 500 : Next
Wert = 0 : Gosub Senden
For I = y to 500 : Next
Gosub I2CStop

SetTH:
Gosub I2CStart ' I2C Start
Wert = Adr : Gosub Senden
Wert = &HA1 : Gosub Senden
For I = y to 500 : Next
Wert = 29 : Gosub Senden
For I = y to 500 : Next
Wert = 0 : Gosub Senden
For I = y to 500 : Next
Gosub I2CStop

'-- Parameter setzen 1-Byte Kommando ---
StartConversion:

Gosub I2CStart ' I2C Start
Wert = Adr : Gosub Senden
Wert = &HEE : Gosub Senden
Wert = &H00 : Gosub Senden

I2CStop:
Gosub SDAoff
Gosub SCLon
Goto SDAon ' Stop IýC Bus


Antwort Schreiben