On Arduino I have the following (working) code:
#include <math.h>
void setup()
{
Serial.begin(115200);
}
void loop()
{
int AnalogValue = analogRead(0);
Serial.print(AnalogValue);
Serial.print(" = ");
Serial.println(Thermistor(AnalogValue)); // display Fahrenheit Serial.println("c");
delay(200);
}
double Thermistor(int RawADC)
{
double Temp;
Temp = log(((10240000/RawADC) - 10000));
Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp );
Temp = Temp - 273.15; // Convert Kelvin to Celcius
return Temp;
}
In TinyCLR, using the same thermistor, I needed to perform the following:
private static UartController DebugPort = null;
static void Main()
{
var adc = AdcController.FromName(SC20100.AdcChannel.Controller1.Id);
var analog = adc.OpenChannel(SC20100.AdcChannel.Controller1.PA0);
int AnalogValue = 0;
ConfigDebugPort();
while (true)
{
AnalogValue = analog.ReadValue();
AnalogValue = (int)((double)AnalogValue / 88.5);
DebugWrite(AnalogValue.ToString());
DebugWrite(" = ");
DebugWrite(Thermistor(AnalogValue) + "\r\n");
Thread.Sleep(200);
}
}
private static double Thermistor(int RawADC)
{
double Temp;
Temp = Math.Log((((double)10240000 / (double)RawADC) - (double)10000));
Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp)) * Temp);
Temp = Temp - 273.15; // Convert Kelvin to Celcius
return Temp;
}
The problem is the use of the 88.5 value. Why do I need to divide the returned value by this arbitrary value to get the same result as with the Arduino?