PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : SHT11 - instabile Messwerte



Marten83
22.07.2007, 22:33
Guten Abend zusammen!


Habe mir vor einiger Zeit den Luftfeuchtigkeits und Temperatursensor zugelegt.
Nun habe ich zum Test einfach mal die Zeilen von der Mcselec-Homepage in meinen Mega32 geladen.
Leider bekomme ich sich ständig ändernde Werte auf dem Display angezeigt.
Sie schwanken bis zu knapp 1°C.
Kann sich da jemand einen reim drauf machen?
Anbei poste ich mal den Code:

$regfile = "m32def.dat"

$crystal = 8000000


Config Lcd = 20 * 4
Cursor Off
Cls
Dim Ctr As Byte
Dim Dataword As Word
Dim Command As Byte
Dim Dis As String * 20

Dim Calc As Single
Dim Calc2 As Single
Dim Rhlinear As Single
Dim Rhlintemp As Single
Dim Tempc As Single
Dim Tempf As Single

Const C1 = -4
Const C2 = 0.0405
Const C3 = -0.0000028
Const T1c = .01
Const T2 = .00008
Const T1f = .018

Sck Alias Portb.0
Dataout Alias Portb.1
Datain Alias Pinb.1
Redled Alias Portb.2

Declare Sub Getit()

Ddrb = &B11111111 'all port b are output
Config Pinb.0 = Output 'sck
Config Pinb.1 = Output 'datain

Waitms 12

'reset the serial communications first, it is easily confused!
Set Dataout
For Ctr = 1 To 12
Set Sck
Waitus 2
Reset Sck
Waitus 2
Next Ctr


Do 'continually read the tempfature and humidity

Command = &B00000011
Call Getit 'Get the temperature, puts result in "dataword" for us
'
Tempf = T1f * Dataword
Tempf = Tempf - 40

Tempc = T1c * Dataword 'get celcius for later calculations and for "the rest of the world"
Tempc = Tempc - 40

Dis = Fusing(tempc , "###.##")
Locate 1 , 1
Lcd "Temp = " ; Dis ; " (F)"

Command = &B00000101
Call Getit 'get the humidity
Calc = C2 * Dataword
Calc2 = Dataword * Dataword 'that "2" in the datasheet sure looked like a footnote for a couple days, nope it means "squared"!
Calc2 = C3 * Calc2
Calc = Calc + C1
Rhlinear = Calc + Calc2

'Dis = Fusing(rhlinear , "##.##")
'Print "Humidity adjusted for linear = " ; Dis


Calc = T2 * Dataword
Calc = Calc + T1c
Calc2 = Tempc - 25
Calc = Calc2 * Calc
Rhlintemp = Calc + Rhlinear

Dis = Fusing(rhlintemp , "##.##")
Locate 2 , 1
Lcd "Humidity = " ; Dis


Wait 3
Loop


Sub Getit()

Local Datavalue As Word
Local Databyte As Byte

'start with "transmission start"
Set Sck
Reset Dataout
Reset Sck
Set Sck
Set Dataout
Reset Sck


'now send the command
Shiftout Dataout , Sck , Command , 1

Ddrb = &B11111101 'datain is now input
Config Pinb.1 = Input 'datain
Set Sck 'click one more off
Reset Sck
Waitus 10 'no idea why, but it doesn't work without it!
Bitwait Pinb.1 , Reset 'wait for the chip to have data ready

Shiftin Datain , Sck , Databyte , 1 'get the MSB
Datavalue = Databyte

Ddrb = &B11111111
Config Pinb.1 = Output

Reset Dataout 'this is the tricky part- Lot's of hair pulling- have to tick the ack!
Set Sck
Reset Sck

Ddrb = &B11111101 'datain is now input
Config Pinb.1 = Input

Shiftin Datain , Sck , Databyte , 1 'get the LSB
Shift Datavalue , Left , 8
Datavalue = Datavalue Or Databyte
'don't tick the clock or ack since we don't need the CRC value, leave it hanging!
Dataword = Datavalue

Ddrb = &B11111111
Config Pinb.1 = Output

Reset Dataout
Set Sck
Reset Sck

Ddrb = &B11111101 'datain is now input
Config Pinb.1 = Input

Shiftin Datain , Sck , Databyte , 1 'not using the CRC value for now- can't figure it out! Anybody know how to impliment?
'Print "CRC value was - " ; Databyte

Ddrb = &B11111111
Config Pinb.1 = Output

Set Dataout
Set Sck
Reset Sck
End Sub

End
End

Hat diesen Sensor vielleicht schonmal jemand erfolgreich ausgewertet?

Vielen Dank

Marten83

darxon69
13.08.2007, 12:17
Bis jetzt noch nicht, aber ich habe mir mal ein Muster bestellt und will das in den nächsten Tagen mal testen. Da er sich nicht mit dem I²C Protokoll verträgt muss ich da noch etwas an meiner Schaltung herum bauen, da der SHT11 nicht an den I²C-bUs des AVR passt.

lowtzow
13.08.2007, 16:12
hallo

na so ein zufall
hab heut meinen sht75 in betrieb genommen.
konnte aber keine starken schwankungen wahrnehmen

hab schon dazu in https://www.roboternetz.de/phpBB2/viewtopic.php?p=306344#306344
gepostet!

@darxon
hast du dir ein gratis muster bestellt oder wie?!
wollt mir auch ein paar gratis pca8574 über nxp bestellen aber irgendwie kenn ich mich da nicht aus ob das auch nach österreich funktioniert.

mfg
piri

darxon69
13.08.2007, 17:38
Ja ich habe ein Gratis ;uster bestellt. HAbe es aber über die Firma gemacht. Da wittert man bei Sensirion immer das größe Geschäft und liefert prompt.