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] temperature sensor using pic16f887

Status
Not open for further replies.

kbtan

Member level 2
Joined
Jul 8, 2011
Messages
45
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,583
I am trying to do a temperature sensor using pic16f887 and then display on LCD. The output from the LM35 is constant but the display temperature on LCD won't be constant, the reading always jump. So is my code got problem??
IMG_20130721_0001.jpg
PHP:
// LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;

sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End LCD module connections

char disp[] = "Temp: ";
char cel[] = "'C";
int temp_res = 123 ;
float temp;
char *test= "00.00";
int tempint;


void main(){
  ANSEL  = 0x04;              // Configure AN2 pin as analog
  ANSELH = 0;
  C1ON_bit = 0;               // Disable comparators
  C2ON_bit = 0;
  TRISA  = 0xFF;              // PORTA is input

  Lcd_Init();                        // Initialize LCD
  Lcd_Cmd(_LCD_CLEAR);               // Clear display
  Lcd_Cmd(_LCD_CURSOR_OFF);          // Cursor off
  Lcd_Out(1,1,disp);                 // print "Temp: " to lcd
  //Lcd_Out(2,1,disp);                 // print "Temp: " to lcd
  Lcd_Out(1,13,cel);                 // print "'C" to lcd


  do {
    temp_res = ADC_Read(2);   // Get 10-bit results of AD conversion
    temp = 5.00*temp_res*100.00/1023.00;   // convert voltage to degree celcius
    //print temperature in 2 decimal point
    tempint = temp * 100;
    test[0]= (tempint/1000) % 10 + 48; // add 48 to get the ASCII char value
    test[1]= (tempint/100)  % 10 + 48;
    test[3]= (tempint/10) % 10 + 48;
    test[4]=  tempint % 10 + 48;

    Lcd_Out(1,7,test);     // display temperature
    Delay_ms(500);


  } while(1);


  // Moving text



}
i am using c programing
 

Try to put capacitor like this :

**broken link removed**


Capacitor values 1uF, 2,2uF, ....


Best regards,
Peter
 

I am trying to do a temperature sensor using pic16f887 and then display on LCD. The output from the LM35 is constant but the display temperature on LCD won't be constant, the reading always jump. So is my code got problem??

Most likely it is an issue with noise on the ADC input, such as EMI, etc.

The solution proposed by Peter implements a low pass filter on the output from the LM35, essentially filtering any higher frequency noise before it reaches the ADC.


Another possible option is utilizing an averaging technique in your code.

Essentially creating a queue of samples which are then averaged before being displayed.



BigDog
 

Try to put capacitor like this :
lm35_circuit.jpg
Capacitor values 1uF, 2,2uF, ....


Best regards,
Peter
can I knw the value of resistor. Thank you
 

It all depends on what your "ADC_Read(2)" routine does, and how it does this.

Also, what sort of 'jumping' display do you get ? Are they random values or what ?
 

random values. some times jump to 80'c sometime jump to 10'c
 

AN2 pin is not configures as analog input and or input and or no Compatator mode and or no CVREF mode. Have you used ADC reference voltage? ADCON1 Configured?

ADCON1 = 0x80;
 
Last edited:

random values. some times jump to 80'c sometime jump to 10'c

I think your most likely error sources are : (1) code for initializing & using of the ADC, and (2) the float --> int conversions.

check out these 2 areas thoroughly.
 

Sir, after I put the low pass filter to the Lm35 the temperature reading now change from 28 to 40
I use RS232 to supply the voltage for the circuit. is it got any impact on the circuit? here is my latest schematic
IMG_20130722_0001.jpg
 

Sir, after I put the low pass filter to the Lm35 the temperature reading now change from 28 to 40
I use RS232 to supply the voltage for the circuit. is it got any impact on the circuit? here is my latest schematic
View attachment 93888

You cant power this circuit from RS232 I already tell you that in your second thread for that:

https://www.edaboard.com/threads/294228/


Probably you will damage RS232 port.



Best regards,
Peter

:wink:
 

You cant power this circuit from RS232 I already tell you that in your second thread for that:

RS232 as power supplyer


Probably you will damage RS232 port.



Best regards,
Peter
Sir, may I know why RS232 cannot be a power supplier, cuz the LCD can display when I put a 100uF capacitor parrallel to V+ and ground
 

Sir, may I know why RS232 cannot be a power supplier, cuz the LCD can display when I put a 100uF capacitor parrallel to V+ and ground

I hope you will not see why on your PC.

RS232 port is not dedicated for draining higher currents. Ports should be used just for signals in mA range. You can connect and power circuit if current demand is in mA range, for example some uC programmer.

Use USB port for power supply or use FT232 to use only USB port, or use some external power source.


Best regards,
Peter

:wink:
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top