Guyzz i have seen a lot of DS18S20 code where they do a "temp = temp << 3" to adapt the DS18S20 9-bit resolution to the DS18B20 12-bit resolution.

I did some thinking :lol:, as i have some DS18S20 and wanted to use the extended temparature resolution , mentioned in the DS , where you read the ScratchPad and use it to enhance the temperature resolution.

Formula for DS18S20 extended temperature:Temperature = Temp - 0.25 + ((16 - Count_Remain) / 16)

Res = 1/16 = 0.0625 degree C , the resolution of the "Compensate formel" is 1/16 degree.

Temp = Temp >> 1; Now temp is in whole degrees & we have discarded the lsb , as reqd for adding the extended precision

Temp = Temp << 4; This temp is now in 1/16 degrees , but note that now it the same scale as the adaptation for the DS18B20 where one does a' << 3.

Temp = Temp - 4; Subtract 0.25 degrees (4/16 degrees).

Temp = Temp + (16 - "Count_Remain); No conversion or division needed , as it is allready in 1/16 degrees resolutionIf the above is correct then this code below would give the maximum

resolution. (tmp isnt even needed)// only work on 12bit-base // TODO: DS18S20 "additional values" if( fc == DS18S20_ID ) { // 9 -> 12 bit if 18S20 //meas <<= 3; tmp = meas >> 1; tmp = tmp << 4; tmp -= 4; tmp += (16 - sp[6]); meas = tmp; }

The code was just originally adapting the DS18S20 to the DS18B20 by shifting right 3 times , but i added what i hope is the correct formula to get the expended precision and still keeping the 12-bit format so the same conversion routines can be used.

I think this is correct , but if there is any obvious bugs then please say so ??

/Bingo

DS18S20 DS : http://pdfserv.maxim-ic.com/en/d...

DS18B20 DS : http://pdfserv.maxim-ic.com/en/d...