I was working on thermistors temperature test. It was working but it is giving wrong value.
I am using pic18f67k40 uC. Sensors I was using NTCASCWE3103F. The heater I was using for this test is CEM BX-150.
The code I was using for this test is-
Code: Select all
#define ANF6 46
#define ADC_VREF 3.3
#define RESISTANCE_REF 4700 //4700
#define RESISTANCE_FROM_VOLTAGE(v) (((ADC_VREF/v)-1) * RESISTANCE_REF)
sbit temperature_sensor_1_type at ANSELF6_bit;
sbit temperature_sensor_1_direction at TRISF6_bit;
float temperature_from_resistance(float resistance) {
const float A = 0.000800; //0.0001143060;
const float B = 0.000111;//5678; //0.0002244470;
const float C = 0.00001E-6;
return 1/(A + B*2.303*log(resistance) + (C*pow(2.303*log(resistance),3))) - 273.15;//Steinhart–Hart equation
}
float get_temperature_from_sensor_1() {
return temperature_from_resistance(RESISTANCE_FROM_VOLTAGE((float)((ADC_VREF/1024.0) * ADC_Read(ANF6))));
}
void main() {
TRISC6_bit = 0; // Tx pin set as output
TRISC7_bit = 1; // Rx pin set as input
temperature_sensor_1_type = 1;
temperature_sensor_1_direction = 1;
UART1_Init(9600);
Delay_ms(4);
ADC_Init();
while(1){
temperature = get_temperature_from_sensor_1();
UART1_Write_Text("[TMP_SNSR_1] ");
sprintf(cc1, "%0.2f", temperature);
UART1_Write_Text(cc1);
UART1_Write_Text("\r\n");
Delay_ms(500);
}
}
kumar