SHT71 am Xmega

ThomasW69
 
Avatar
 
Subject:

SHT71 am Xmega

 · 
Posted: 01.01.2011 - 20:05  ·  #1
Hallo Zusammen.

Ich fleissig am Ausbau meines Xmega Systems und habe jetzt den SHT71 angeschlossen. Alleridngs bekomme ich mit der Routine, die ich bisher auf meinem Mega2561 mit einem SHT11 am Laufen hatte keine Werte.

Code
procedure ReadSHT;
var   Value: word;
  T              : integer;
  H              : float;
begin
  If SHT11GetStatus <> $FF then                        // wenn er da ist

    SHT11startTemp;                                   // Temperaturlesen Starten
    Value:= SHT11getTemp;                             // Temperatur holen
    Writeln(Seroutc1,'RAWT: '+inttostr(value));
    T:= integer(Value div 10) - 400;                  // 14bit resolution
    system.Temperature:= float(T)*0.1;                 // Teperaur in Systemvariable
    SHT11startHum;                                    // Feuchtigkeit starten
    Value:= SHT11getHum;                              // Feuchtigkeit holen
    Writeln(Seroutc1,'RAWH: '+inttostr(value));
    Value:= MulDivInt(Value, 405, 1000) - 40;         // 12bit resolution
    system.Humidity:= float(Value)*0.1;
    H := (log10(system.Humidity) - 2) / 0.4343 + (17.62*system.Temperature) / (243.12 + system.Temperature);
    system.Dewpoint:= 243.12*H / (17.62 - H);
  endif;
end;


Die RAW werte werden immer mit 0 augegeben.
Initialisiert habe ich das ganze folgendermassen.
Code
Import ... SHT11drvr, ...;


Define
  OSCtype        = int32MHz, PLLmul=4, prescB=1, prescC=1;
  SysTick        = 10, adj;             // msec, correct the RTC32K timer for exact mSec timing
  StackSize      = $0100, iData;
  FrameSize      = $0100, iData;
  Scheduler      = iData;
  TaskStack      = $0040, iData;
  TaskFrame      = $0020;
//  Exceptions     = 1;              {levels}

  //MMC Port
  FAT16          = SPI_D, PortD, 4, IData;   // SPI_X, SS-Port, SS-PIN, data area
  F16_FileHandles = 2;
  F16_DirLevels  = 2;
  F16_StrLen     = 128;        // only for file of text
  F16_MMCspeed    = slow;     // standard, slow, fast

  //SHT11 Luftfeuchtesensor
  SHT11drvr      = polled;
  SHT11clk        = PortD, 1;       {Port, Pin#}
  SHT11Dat       = PortD, 2;       {Port, Pin#}


Zwar liegen der FAT16 und der SHT71 auf dem Selben Port (PortD) aber an unterschiedlichen Pins.
Mit dem Oszi habe ich mal geschaut. Beide Leitungen sind auf LOW. Beim Zugriff auf den SHT pulst die Clk (PortD.1) einmal kurzezeitig auf High-Pegel. DAT (PortD.2) geht dann auch auf HIGH, bleibt aber wesentlich länger dort. Sonst passiert eigentlich nichts. Das ist doch bestimmt so nicht korrekt?
ThomasW69
 
Avatar
 
Subject:

Re: SHT71 am Xmega

 · 
Posted: 02.01.2011 - 17:40  ·  #2
Ok hat sich erledigt.
Hatte vergessen mit
Code
    repeat
    until SHT11ConvState;
auf die fertige Konvertierung der Werte warten :-) Mein Fehler.
ThomasW69
 
Avatar
 
Subject:

Re: SHT71 am Xmega

 · 
Posted: 04.01.2011 - 17:11  ·  #3
Ich muss das Thema doch noch mal aktivieren.
Also der Sensor liefert jetzt werte. Allerdings pasiert be der konvertierung irgendwie Mist.
Code

procedure ReadSHT;
var   ww          : word;
      T           : integer;
      H           : Fix64;
begin
  If SHT11GetStatus <> $FF then                        // wenn er da ist

    SHT11startTemp;                                   // Temperaturlesen Starten
    repeat
    until SHT11ConvState;
    ww:= SHT11getTemp;                             // Temperatur holen

    Writeln(Seroutc1,'RAWT: '+inttostr(ww));       //RAW Wert des Sensors ausgeben

    T:= integer(ww div 10) - 400;                  // 14bit resolution
    Sensors.Temperature:= inttoFix64(T)*0.1;          // Teperaur in Systemvariable

    SHT11startHum;                                    // Feuchtigkeit starten
    repeat
    until SHT11ConvState;
    ww:= SHT11getHum;                              // Feuchtigkeit holen
    Writeln(Seroutc1,'RAWH: '+inttostr(ww));       //Raw Wert der Luftfeuchte ausgeben
    ww:= MulDivInt(ww, 405, 1000) - 40;         // 12bit resolution
    Sensors.Humidity:= inttofix64(ww)*0.1;

    H := (Fix64log(sensors.Humidity) - 2) / 0.4343 + (17.62*sensors.Temperature) / (243.12 + sensors.Temperature);
    Sensors.Dewpoint:= 243.12*H / (17.62 - H);

    Writeln(seroutC1,'Temperatur: '+Fix64tostr(Sensors.Temperature)+'°C');
    Writeln(seroutC1,'Humidity  : '+Fix64tostr(Sensors.Humidity)+'%');
    Writeln(seroutC1,'Taupunkt:   '+Fix64tostr(Sensors.Dewpoint)+'°C');  endif;
end;

liefert die folgende Ausgabe:
Code

RAWT: 2050
RAWH: 312
Temperatur: -19.500000018°C
Humidity  : 8.600000008%
Taupunkt:   -44.887470323°C

Problematisch daran ist, dass ich im Arbeitszimmer bei angenehmen Temperaturen von etwa 18°C sitze.
Wenn ich den Sensor anhauche, dann sollte die Luftfeuchtigkeit ansteigen. Das schaut dann so aus.
Code
RAWT: 2168
RAWH: 48
Temperatur: -18.400000017°C
Humidity  : 6551.500006102%
Taupunkt:   44.759488074°C
Auffallend ist, dass die errechnete Luftfeuchtigkeit plötzlich auf über 6551% steigt obwohl der Sensor einen geringeren Wert liefert (was an sich schon sehr mystisch ist). Kann das ein Überlaufproblem sein.
Geht das nicht mit Fix64?
Der SHT71 wird mit
Code

SHT11SetStatus($00); 

auf die korrekte Auflösung 14bit T/12bit H gebracht.
Merlin
Administrator
Avatar
Gender:
Age: 24
Posts: 1373
Registered: 03 / 2005
Subject:

Re: SHT71 am Xmega

 · 
Posted: 04.01.2011 - 18:01  ·  #4
Hi Thomas.

The calculation mostly seem to be correct, e.g. ((2050 / 10) - 400) / 10 = -19.5.

You do get an overflow, but it is nothing to do with fix64. ww is a word so

ww:= MulDivInt(ww, 405, 1000) - 40;

when ww = 48 gives -38, which wraps around to 65498.

Regards

Merlin.

btw. One thought that occurs is that perhaps -400 should be -40 (and something similar for humidity). This case the temperatures would be 36 degrees higher, i.e 16.5 and when you touch it with your finger 17.6. I don't know, because I don't know about this device, but just a thought to point you in the right direction
ThomasW69
 
Avatar
 
Subject:

Re: SHT71 am Xmega

 · 
Posted: 04.01.2011 - 19:50  ·  #5
Hi Merlin.

The -400 is correct but I found the error.
Because of the higher Clock rate of the Xmega with 32MHz the readout speed of the sensor was to fast.
Adding an Delay in the driver initialisation was solving my problem.
Code
  SHT11drvr      = polled, 100,crc;
  SHT11clk       = PortD, 1;       {Port, Pin#}
  SHT11Dat       = PortD, 2;       {Port, Pin#}

I think this hint should be added to the Standard Driver Manual for Xmega Users.

Now the sensor gives
Code
RAWT: 6298
RAWH: 866
Temperatur: 22.900000021°C
Humidity  : 31.000000029%
Taupunkt:   4.864984282°C


after heating it a 'little bit' with the blow-dryer.

BTW in the sensor manual there is a much more accurate method to calculate the temperature and humidity from the RAW values. See section 4 in http://www.sensirion.com/en/pd…-SHT7x.pdf.
rh
Administrator
Avatar
Gender:
Location: Germany
Age: 24
Homepage: e-lab.de
Posts: 5558
Registered: 03 / 2002
Subject:

Re: SHT71 am Xmega

 · 
Posted: 04.01.2011 - 22:45  ·  #6
@ Thomas,

Standard Driver Manaual page 190

rolf
ThomasW69
 
Avatar
 
Subject:

Re: SHT71 am Xmega

 · 
Posted: 05.01.2011 - 05:31  ·  #7
@ Rolf

Ja da steht zwar das mit dem warten auf SHT11ConvState aber nicht, dass man zwingend den Treiber beim XMega mit einem Delay initialisieren muss weil sonst der SHT71 überfahren wird.
Bin da auch nur drauf gekommen weil der Sensor halt spradisch irgendwelchen Mist geliefert hat und ich vermutetet, dass da einzelne Bits beim Auslesen verloren gegangen sind. Zumal auffallend oft Werte mit runden 2-erpotenzen gelesen wurden (16,32,48,64...).
rh
Administrator
Avatar
Gender:
Location: Germany
Age: 24
Homepage: e-lab.de
Posts: 5558
Registered: 03 / 2002
Subject:

Re: SHT71 am Xmega

 · 
Posted: 05.01.2011 - 13:25  ·  #8
Hallo Thomas,

ich meinte hier den Hinweis auf eine erweiterte Korrektur Routine für den SHT11, nicht das Delay.

rolf
Selected quotes for multi-quoting:   0

Registered users in this topic

Currently no registered users in this section

The statistic shows who was online during the last 5 minutes. Updated every 90 seconds.
MySQL Queries: 15 · Cache Hits: 14   135   149 · Page-Gen-Time: 0.028026s · Memory Usage: 2 MB · GZIP: on · Viewport: SMXL-HiDPI