DS18S20 Gross errors

General discussion relating to the library modules supplied with the compiler

Moderators: David Barker, Jerry Messina

Post Reply
honkerbob
Posts: 11
Joined: Sun Jul 20, 2008 9:28 am
Location: New Milton, UK

DS18S20 Gross errors

Post by honkerbob » Sat Jul 26, 2008 11:41 am

I am new to Swordfish. I have been experimenting with the DS18S20, an LCD and the USB CDC stuff.

I am currently running 3 DS18S20's together. They are taking readings when requested by a VB.Net application.

On a sample run of 100 readings, 32% were grossly inaccurate, with an ambient temperature of approximately 24 degrees. Readings were being returned of -103, -1.5, +57 etc. The code I am using is as follows :


ConvertAll // force all 1 wire devices to convert at the same time
DelayMS(750)
RomID = DeviceROMID0

GetTemp(TempA, TempB) // my overload - requires RomID
lcd.writeat(1,2,"Sensor1 : ")
lcd.write(dectostr(TempA))
lcd.write(".")
lcd.write(dectostr(TempB,1))
lcd.write(" C")

CDC.Write("Sensor1 : ",DecToStr(TempA),".",DecToStr(TempB,1), " ", "C",$0A)

RomID = DeviceROMID1

GetTemp(TempA, TempB) // my overload - requires RomID
lcd.writeat(2,2,"Sensor2 : ")
lcd.write(dectostr(TempA))
lcd.write(".")
lcd.write(dectostr(TempB,1))
lcd.write(" C")

CDC.Write("Sensor2 : ",DecToStr(TempA),".",DecToStr(TempB,1), " ", "C",$0A)


RomID = DeviceROMID2

GetTemp(TempA, TempB) // my overload - requires ROMID
lcd.writeat(3,2,"Sensor3 : ")
lcd.write(dectostr(TempA))
lcd.write(".")
lcd.write(dectostr(TempB,1))
lcd.write(" C")

CDC.Write("Sensor3 : ",DecToStr(TempA),".",DecToStr(TempB,1), " ", "C",$0A)

The function I have altered is : (saved as MyDS18S20.bas)

public sub GetTemp(byref pTemp as shortint, byref pFraction as byte)
OW.WaitForHigh
OW.Reset // added by me
OW.WriteByte(owMatchROM) // added by me
OW.WriteArray(FID) // added by me
ReadSP
pTemp = FSP(0).AsWord >> 1
pFraction = (FSP(0) and $01) * 5
end sub

I did this so that I could force a simultaneous temperature conversion, but collect the data at my leisure.

I have checked for clean supply rails - the application is USB bus powered, but everything seems to be quiet. The one wire bus is only 4-5 inches in length at present.

Can anyone see why I would be getting such bad errors? I don't want my code written for me, but any pointers would be gladly accepted.

Very best regards.

honkerbob
Posts: 11
Joined: Sun Jul 20, 2008 9:28 am
Location: New Milton, UK

Post by honkerbob » Sat Jul 26, 2008 4:57 pm

I have solved this issue by doing bubblesort and median filtering over a range of values. Many thanks to Tim Box for his excellent code in the Stein Hart linearization code sample.

I was a little naive to expect perfect data everytime. Sigh.

Very best regards.

Post Reply