I'm working with a code that reads min/max from a thermistor and I have used one of the thermistor codes from the playground that utilize the A/B/C coefficients and I've also increased the accuracy of the readout by incorporating an example of an external 24 bit ADC. Accuracy is still a little bit off on the high and low ends though. Even though I may not move forward with using a look up table I would like to know how to create one and be able to reference temperatures from that table based on ADC voltage. I have to be accurate to within +/-.5 degrees F after it is converted from C.
The table would include even temperatures from -60 to +55 degrees C and the code would need to perform interpolation between those values so that I could display temperatures to within a tenth of a degree. So a total of 115 entries each for voltage and the corresponding temperature.
example of the voltage and temp readings just so I can get started would be:
Temp: -60 VDC: 0.1125
Temp: -59 VDC: 0.1212
Temp: -58 VDC: 0.1305
................
Temp: 55 VDC: 4.579
This is a 20K ohm thermistor with a 65K ohm resistor used as the balance resistor portion of the voltage divider. I know typically a resistor of the same value is used (which I am using right now for the coefficient version of the code) but if a look up table is used the 65K resistor will give me more use of the full 5VDC range (0.1125 to 4.579) vice the 20K resistor (0.351 to 3.85).
I've heard something of this size will need to go to PRGM memory.
I know the interpolation would go in the normal code but how would I conduct that operation?
Below is portions of the current code using coefficients that deal with getting ADC value and doing temp conversion
float Thermistor(float volt)
{
long Resistance;
float Temp; // Dual-Purpose variable to save space.
Resistance=((pad * v_ref / volt) - pad);
Temp = log(Resistance); // Saving the Log(resistance) so not to calculate it 4 times later
Temp = 1 / (0.000969711 + (0.000232887 * Temp) + (0.0000000801420 * Temp * Temp * Temp));
Temp = Temp - 273.15; // Convert Kelvin to Celsius
return Temp; // Return the Temperature
}
float GetAdcVoltage()
{
cbi(PORTB,LTC_CS); // LTC2400 CS Low
delay(200);
if (!(PINB & (1 << PORTB4))) { // ADC Converter ready ?//
cli();
ltw=0;
sig=0;
b0 = SPI_read(); // read 4 bytes adc raw data with SPI
if ((b0 & 0x20) ==0) sig=1; // is input negative ?
b0 &=0x1F; // discard bit 25..31
ltw |= b0;
ltw <<= 8;
b0 = SPI_read();
ltw |= b0;
ltw <<= 8;
b0 = SPI_read();
ltw |= b0;
ltw <<= 8;
b0 = SPI_read();
ltw |= b0;
delayMicroseconds(1);
sbi(PORTB,LTC_CS); // LTC2400 CS Low
delay(200);
if (sig) ltw |= 0xf0000000; // if input negative insert sign bit
ltw=ltw/16; // scale result down , last 4 bits have no information
volt = ltw * v_ref / 16777216; // max scale
}
sbi(PORTB,LTC_CS); // LTC2400 CS hi
delay(20);
return volt;
//part of loop//
if (millis() - tempMillis >= 15000UL) //take reading every 15 seconds
{
digitalWrite(thermGnd, LOW);
delay(500);
float temp;
temp=Thermistor(GetAdcVoltage()); // read ADC and convert it to Celsius
temp = (temp * 9.0)/ 5.0 + 32.0; // converts to Fahrenheit
digitalWrite(thermGnd, HIGH);
Thanks for any assistance you could provide.