@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;