temperature sensors giving wrong value

General discussion on mikroC PRO for PIC.
Post Reply
Author
Message
kumar123
Posts: 68
Joined: 17 Oct 2023 07:32

temperature sensors giving wrong value

#1 Post by kumar123 » 07 Mar 2024 10:18

Hi,
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);
   }
}
The sensors I was using-
ses.png
ses.png (124.47 KiB) Viewed 248 times
Regards,
kumar

paulfjujo
Posts: 1544
Joined: 24 Jun 2007 19:27
Location: 01800 St Maurice de Gourdans France
Contact:

Re: temperature sensors giving wrong value

#2 Post by paulfjujo » 11 Mar 2024 15:28

hello,


Post your schematic ... it could help to understand what do you want to do ...
if i get a good understanding, RESISTANCE is calculated via a Voltage ratio ?
Did you get test the result of the function
float temperature_from_resistance(float resistance)
ie : trace the curve R=f (Temperature)

is 4700 ohms the nominal value of your CTN
give a link on the datasheet ...

kumar123
Posts: 68
Joined: 17 Oct 2023 07:32

Re: temperature sensors giving wrong value

#3 Post by kumar123 » 12 Mar 2024 05:24

Hi paulfjujo,

What is happening at my end, I am getting the wrong value of temperature. Although it is working but it is not making a constant difference.
For example- Let's say initially the temperature value at heater is 40 degree celsius and sensors also sensing the 40 degree celsius.
If I increment 42(40 + 2) degree celsius at the heater, It should be shown near to 42 degree celsius but it is showing 41 degree celsius.
The same thing happens if I do a major change in temperature at the heater means it is not making the same constant difference.
The microcontroller I have is pic18f67k40. The heater I have is CEM BX-150.

i dont't have schematic, I just write this code on mikroC pro for pic compiler to work with temperature sensors for my purpose. I am using 12v and 2 Amp voltage and current respectively.
Yes I am getting the result but it is showing wrong value(not making the constant changes). I am sharing the datasheet of both sensors and uCs.
PIC18(L)F67K40 Data Sheet 40001841D.pdf
(6.46 MiB) Downloaded 9 times
ntcascw (1).pdf
(70.85 KiB) Downloaded 12 times
The result I was getting:
In the result you can see it not making the same constant change.
test_res.png
test_res.png (22.76 KiB) Viewed 167 times
Regards,
Kumar

paulfjujo
Posts: 1544
Joined: 24 Jun 2007 19:27
Location: 01800 St Maurice de Gourdans France
Contact:

Re: temperature sensors giving wrong value

#4 Post by paulfjujo » 12 Mar 2024 19:35

hello,

Impossible to give an answer without Schematic ...


Does the PIC control Power delivered for the Heater ?
Algorithm used PI , or PID ?
The CTN formula is very long, use POW , log ...

difference beetween TARGET and MEASURE needs an Integrale action .... (PI proportionnal and Integrale controler)

Maybe a problem of Accuracy for calculus
float with 32 bits arithmetique is not enough
you need to use 64 bits ..
not available with 8 bits .. see DSP or 32 bits MCU

Post Reply

Return to “mikroC PRO for PIC General”