Als DS1820 gemarkeerde sensor blijkt DS18B20

@rweust, zou je mij kunnen helpen. Ik heb een probleem met het juist uitrekenen vd temperatuur.
Nu gaat het tempverloop zo:

21.4, 21.5, 22.6, 22.7, 22.8, 22.9, 22.0

ik denk dat ik Count Remain berekening fout heb voor deze sensor.
Ik gebruik de lib uit de OneWire-SDK van Dallas voor Delphi.

code:


Function TSensorThread.ReadTemperature(session_handle : longint): Extended;
var
 tsht, i, tmp1 : smallint;
 cr,cpc,tmp : Extended;
 rbuf : array[0..9] of smallint;
 CRCByte : Byte;
begin
 tmp := 0.00;
 {access the device}
 if (TMAccess(session_handle,@StateBuf)= 1) then
  begin
   {Send the recall E2 command (by setting $B8 to outbyte in TMTouchByte)
    make sure Scratch is correct}
   TMTouchByte(session_handle, $B8);
   {Send the start T command }
   if (TMAccess(session_handle,@StateBuf) = 1) then
    begin
     {Prepare the strong pullup after next TMTouchByte}
     TMOneWireLevel(session_handle,LEVEL_SET,LEVEL_STRONG_PULL_UP, PRIMED_BYTE);
     {Send the conversion command (by setting $44 to outbyte in TMTouchByte)}
     TMTouchByte(session_handle, $44);
     {Sleep for a second}
     Windows.Sleep(1000);
     {Disable the strong pullup}
     TMOneWireLevel(session_handle, LEVEL_SET,LEVEL_NORMAL,PRIMED_NONE);
     {verify conversion is complete by setting $01 to outbit in TMTouchBit and
      check the return value with 1}
     if (TMTouchBit(session_handle,$01) = $01) then
      begin
       {Access device}
       If (TMAccess(session_handle,@StateBuf) = 1 ) then
        begin
         {Send read scratch command by setting $BE to outbyte in TMTouchByte}
         TMTouchByte(session_handle,$BE);
         CRC8 := 0;
         {Read scratch (setting $FF to outbyte in TMTouchByte) and check crc for
           each byte}
         for i := 0 to 7 do
          begin
            rbuf[i]:= TMTouchByte(session_handle, $FF);
            CRCByte := Byte(rbuf[i]); { the byte to run through CRC8 routine }
            CRC8 := TMCRC(1, @CRCByte, CRC8, 0);
          end;
         {Check crc}
         CRCByte := Byte(TMTouchByte(session_handle, $FF)); { the byte to run through CRC8 routine }
         CRC8 := TMCRC(1, @CRCByte, CRC8, 0);
         if ( CRC8 = 0 ) then
          begin
            {Calculate the temperarure}
             tsht := rbuf[0];
             if ((rbuf[1] and $01)= 1) then
               tsht := tsht or (-256);
             tmp1 := Round((tsht)/2);
             tmp := tmp1;
             cr := rbuf[6];
             cpc := rbuf [7];
             if (rbuf[7] <> 0) then
               tmp := tmp - (0.25) + (cpc-cr)/cpc;

          end;
        end;
      end;
    end;
  end;
  ReadTemperature := tmp;
end;

@william22: Dit was een topic uit 2016 wat je weer naar boven hebt gehaald en vraagsteller heeft hier maar ooit één vraag gesteld en is nooit weer gezien.

Maak je eigen topic aan!!!!

Domoticz en ESP8266, goede combo!!!

@Roches,
Je hebt gelijk. Grote kans dat @rweust geen oplossing biedt.
Voor mijn gevoel is het een simpel softwarefoutje. Omdat DS18B20 geen rocketscience is, is er vast wel een CO-er die @william22 kan helpen.
Je kunt ook de heer @william22 uit de puree helpen. Dan kan dit topic weer een tijdje slapen of op slot. Dat is aan de modjes.

Er is een Chinese fabrikant die fakes verkoopt. Dit zijn waarschijnlijk deze componenten. Dat verklaart ook waarom ze de sensor hier
https://dochub.com/pieterhoeben/6xJ6nv/ds18b20-stainless-steel-package…
goedkoper kunnen verkopen dan het component.

De namaak is RW1820 van Rayway International. Ik kan je de datasheet wel sturen, bij interesse.

four NANDS do make a NOR . Kijk ook eens in onze shop: http://www.bitwizard.nl/shop/

code:


Function TSensorThread.ReadTemperature(session_handle : longint): Extended;
var
 tsht, i, tmp1 : smallint;
 cr,cpc,tmp : Extended;
 rbuf : array[0..9] of smallint;
 CRCByte : Byte;
begin
 tmp := 0.00;
 {access the device}
 if (TMAccess(session_handle,@StateBuf)= 1) then
  begin
   {Send the recall E2 command (by setting $B8 to outbyte in TMTouchByte)
    make sure Scratch is correct}
   TMTouchByte(session_handle, $B8);
   {Send the start T command }
   if (TMAccess(session_handle,@StateBuf) = 1) then
    begin
     {Prepare the strong pullup after next TMTouchByte}
     TMOneWireLevel(session_handle,LEVEL_SET,LEVEL_STRONG_PULL_UP, PRIMED_BYTE);
     {Send the conversion command (by setting $44 to outbyte in TMTouchByte)}
     TMTouchByte(session_handle, $44);
     {Sleep for a second}
     Windows.Sleep(1000);
     {Disable the strong pullup}
     TMOneWireLevel(session_handle, LEVEL_SET,LEVEL_NORMAL,PRIMED_NONE);
     {verify conversion is complete by setting $01 to outbit in TMTouchBit and
      check the return value with 1}
     if (TMTouchBit(session_handle,$01) = $01) then
      begin
       {Access device}
       If (TMAccess(session_handle,@StateBuf) = 1 ) then
        begin
         {Send read scratch command by setting $BE to outbyte in TMTouchByte}
         TMTouchByte(session_handle,$BE);
         CRC8 := 0;
         {Read scratch (setting $FF to outbyte in TMTouchByte) and check crc for
           each byte}
         for i := 0 to 7 do
          begin
            rbuf[i]:= TMTouchByte(session_handle, $FF);
            CRCByte := Byte(rbuf[i]); { the byte to run through CRC8 routine }
            CRC8 := TMCRC(1, @CRCByte, CRC8, 0);
          end;
         {Check crc}
         CRCByte := Byte(TMTouchByte(session_handle, $FF)); { the byte to run through CRC8 routine }
         CRC8 := TMCRC(1, @CRCByte, CRC8, 0);
         if ( CRC8 = 0 ) then
          begin
            {Calculate the temperarure}
             tsht := rbuf[0];
             if ((rbuf[1] and $01)= 1) then
               tsht := tsht or (-256);


    tmp1 := Round((tsht)/2); Ik denk dat deze instructie fout is;
    tmp1 := Trunc((tsht)/2); Ik denk dat dit het moet zijn. 
Als ik gelijk heb is het goed, anders wordt het een grote bende.
Dat wordt dus effe uitproberen.

             tmp := tmp1;
             cr := rbuf[6];
             cpc := rbuf [7];
             if (rbuf[7] <> 0) then
               tmp := tmp - (0.25) + (cpc-cr)/cpc;

          end;
        end;
      end;
    end;
  end;
  ReadTemperature := tmp;
end;

Bedankt heren!
Code zojuist aangepast en nu druk bezig met testen.
Ik houd jullie op de hoogte.
Geweldig die hulp van jullie.