Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] 16F887 with LM35DZ (measurement of positive temp only)

Status
Not open for further replies.

Eric_O

Advanced Member level 4
Joined
May 31, 2020
Messages
104
Helped
0
Reputation
0
Reaction score
0
Trophy points
16
Activity points
996
When measuring room temperature (approximatively between 21°C to 25°C) with PIC 16F887 and LM35DZ, LCD displays a room temperature of 100°C when room temperature is 21°C.

LM35 GND (pin 3) : connected to GND of MCU.
LM35 output (pin 2) : connected to ADC 3 of MCU and also to VCC thru a 2.2 K resistor.
LM35 output (pin 1) : not connected (instead of connected to VCC in some cases)

Regarding the datasheet of LM35 I wrote the code as follow and respected the math formulas.

Code:
void main()
{
 PORTB = 0;                                                 // Initialisation du PORT B à 0.
 PORTC = 0;                                                 // Initialisation du PORT C à 0.
 PORTD = 0;                                                 // Initialisation du PORT D à 0.

 ANSEL = 0b00001000;                                        // b3 = 1 (ANS3) : sets pin 5 (AN3) as analog input.
 ANSELH = 0b00000000;

 TRISB = 0b00000000;                                        // PORT B : b0 à b7 configurés en sortie.
 TRISC = 0b00000000;                                        // PORT C : b0 à b7 configurés en sortie.
 TRISD = 0b00000000;                                        // PORT D : b0 à b7 configurés en sortie.

 C1ON_bit = 0;                                              // CMC1CON register > b7 > C1ON bit = 0 > Disable comparator 1.
 C2ON_bit = 0;                                              // CMC2CON register > b7 > C1ON bit = 0 > Disable comparator 2.

 SCS_bit = 0;                                               // OSCCON register > b0 > SCS bit = 0 > External oscillator (quartz) is used as a clock source.

 LCD_Init_v4 (void);

 pointeur_de_char = &texte[0];                              // pointeur_de_char pointe sur le premier élément du tableau "texte", soit texte[0].
                                                            // Autrement dit, pointeur_de_char contient l'adresse (&) de texte[0].
 do
  {
   float adc;
   float volt, temp;

   char txt[13];

   ADC_initialization();

   TRISD = 0x00;

    while(1)
    {
     adc = (ADC_read(3));                                   // Reads analog values.
     volt = adc * 4.88281;                                  // Converts it into the voltage.
     temp = volt / 10.0;                                    // Gets the temperature values.
     temp = temp - 273;                                     // Converts Farenheit to Celcius.

     StrConstRamCpy(pointeur_de_char, "Temperature ...  "); // OK.
     LCD_Write_String_At(0, 0, pointeur_de_char);           // OK. Voir dans void LCD_Write_String(char *msg), le while(*(msg + k) > 0).

     float2ascii_v2(temp, &txt[0], 2);

     LCD_Write_String_At(1, 0, &txt[0]);                    // Write txt in 2nd row, starting at 1st digit.
     LCD_Write_String_At(1, 13, " °C");                     // Write " °C" in 2nd row, starting at 14th digit.

     delay_ms(3000);
    }
  }
 while(1);
}

Could somebody explain me why the displayed temperature is so inconsistent ?

Thanks !
 

Thanks Brian.
« The ADC input voltage and the LCD reading are in accord, aside from possibly being scaled by 10 so the ADC itself seems to be working OK. » : It is my opinion too.
Multimeter was on

Thank you Paul.
Made corrections.
👍🏻
--- Updated ---


Thank you Brian.
Concerning your feedback « The ADC input voltage and the LCD reading are in accord, aside from possibly being scaled by 10 so the ADC itself seems to be working OK. » : I have same opinion.
Selector knob was on 200 mV.
Will try with MCP9701A.
And what about LM135DZ ? 🤔
Eric
Thanks,

MCP9701A works well. Displayed temp on LCD meets room temp displayed on an digital thermometer. Needed to write a new mV to ºC formula according datasheet and considering the offset for negative temp.

Now I plan to put MCP in a steel tube for different measurements. Have already an idea for connecting using thermo-retractable sheath.

But what type of paste should I use and put in the hollow tube where the sensor will be located to ensure the tightness and transmission of heat from the outside to the sensor in the tube ?
 

Attachments

  • IMG_1160.jpeg
    IMG_1160.jpeg
    59.4 KB · Views: 41

Steel conducts heat fairly well but consider that the conduction will be along the tube length as well as to the sides. If you want to measure 'spot' temperature in a small area, an insulated tube with a conductive tip would work better.

For conduction I would suggest using normal heat sink compound. Fix the sensor where it has to be but leave the area around the plastic body free of any fixing. Then fill the gap between sensor body and the tube inner wall with heat sink compound and finally seal the end of the tube to make it 'environment proof'.

FYI, I use these sensors underwater for measuring the temperature about 2.5m below surface level. After experimenting I found the most reliable construction was to use a narrow plastic tube, about 15mm diameter filled with bathroom silicone sealant! The MCP9701A has a 100nF capacitor across its supply pins and all the exposed metal is covered in heat shrink sleeve in case the silicone contains anything corrosive (acetic acid for example). The reaction time is slow but temperatures in 150 tonnes of water don't change quickly!

Brian.
 
  • Like
Reactions: Eric_O

    Eric_O

    Points: 2
    Helpful Answer Positive Rating
Hi,

mind the different expansion coefficient of tube and mold. Better use some elastic mold like silicone to avoid high mechanic force on electronic parts.

Klaus
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top