Hi,
I'm reading some code that returns a 14 bit temperature value. Here is the function.
/**
* Reads the current temperature in degrees Celsius
*/
float readTemperatureC()
{
int val; // Raw value returned from sensor
float temperature; // Temperature derived from raw value
// Conversion coefficients from SHT15 datasheet
const float D1 = -40.0; // for 14 Bit @ 5V
const float D2 = 0.01; // for 14 Bit DEGC
// Fetch raw value
val = readTemperatureRaw();
// Convert raw value to degrees Celsius
temperature = (_val * D2) + D1;
return (temperature);
}
Here the function has been modified to return an int instead of a float. The reason is because the 'float library is very large'. I'm working with an arduino and another non-arduino platform. The conversion coefficients have been scaled by 10,000 to integers. i.e. 0.01 became 100.
I wondering now what bit value would the function return? It is no longer 14 bit, correct?
//Reads the current temperature in degrees Celsius
int readTemperatureC()
{
int val; // Raw value returned from sensor
int temperature; // Temperature derived from raw value
// Conversion coefficients from SHT15 datasheet
const int D1 = -400000;
const int D2 = 100;
// Fetch raw value
val = readTemperatureRaw();
// Convert raw value to degrees Celsius
temperature = (val * D2) + D1;
return (temperature);
}