Mike - K8LH
Well-Known Member
Hey guys, could you double check my code for expanding the DS18S20 temperature reading from 9-bits (0.5° resolution) to 12 bits (0.0625° resolution), please? I think I'm doing it the way the DS18S20 Datasheet suggests, but during side-by-side testing with a DS18S20 and a DS18B20, the DS18S20 temperature readings always seem to be low.
**broken link removed**
If I leave out the last instruction where I'm subtracting 1/4° from the raw temperature value, the DS18S20 temperature readings are right on or never more than 1/10° off between the DS18S20 and the DS18B20.
What do you guys think?
Cheerful regards, Mike
Code:
/* *
* expand DS1820 or DS18S20 9-bit temperature value (1/2° *
* resolution) to DS18B20 12-bit format (1/16th° resolution). *
* */
if(familyid == 0x10) // if DS1820 or DS18S20
{ rawtemp16.0 = 0; // clear the 0.5° bit
rawtemp16 <<= 3; // make room for fraction bits
rawtemp16 |= frac; // frac = (16 - 'count_remain')
rawtemp16 -= 4; // subtract 1/4° (per datasheet)
}
If I leave out the last instruction where I'm subtracting 1/4° from the raw temperature value, the DS18S20 temperature readings are right on or never more than 1/10° off between the DS18S20 and the DS18B20.
What do you guys think?
Cheerful regards, Mike
Last edited: