Saturday, August 21, 2021

Reading The Analog Temperature From LM35 With PIC16F819 In PICC

 

Overview Of LM35

The LM35 is an analog temperature sensor with only three pins, positive supply voltage, ground and analog temperature output voltage. It could convert the temperature between -55 to 150 degree Celsius.

Reading The Analog Temperature From LM35 With PIC16F819 In PICC
LM35DZ in TO-92 Package

Supply voltage ranges from 4 to 30 V. It’s temperature accuracy is about 0.25 degree Celsius. DOUT is the analog temperature output. The equivalence temperature is 10 mV per degree Celsius.

Reading The Analog Temperature From LM35 With PIC16F819 In PICC
Typical connection diagram

PIC Programming And Interfacing

I use the ADC module of PIC16F819 to read the analog temperature value, fed into RA0.

In the positive temperature condition, LM35 creates a positive output voltage. Similarly, it creates a negative voltage output value in the below-zero temperature condition. The main problem is to make PIC16F819 able to read negative voltage value.

PIC16F819 has two voltage reference pins,

  • VREF+ at RA3
  • VREF- at RA2

But by default the voltage reference is internally connected to +5 V and GND. Anyway, I use external voltage references for the ADC. VREF+ connects to +2.5 V and VREF- connects to -2.5 V. The total reference voltage still stays at 5 V.

PIC16F819 has an internal RC oscillator, clocks up to 8 MHz. I decided to use this internal clock due to extra components placement and circuit designing add-on.

A character LCD displays connects to PORTB, displays the temperature data. It works in 4-bit mode.

Reading The Analog Temperature From LM35 With PIC16F819 In PICC
Schematic Diagram

To create a -2.5/+2.5 V negative voltage pair, I use two 2.5 V zener diode pair as shown in the schematic diagram.

#include<16F819.h>
#device adc=10
#fuses INTRC_IO,NOWDT
#use delay(clock=8M)
#define LCD_ENABLE_PIN PIN_B2
#define LCD_RS_PIN PIN_B0
#define LCD_RW_PIN PIN_B1
#define LCD_DATA4 PIN_B4
#define LCD_DATA5 PIN_B5
#define LCD_DATA6 PIN_B6
#define LCD_DATA7 PIN_B7
#include<lcd.c>
void main(void){
char degree=223;
int16 adc;
float voltage;
setup_oscillator(OSC_8MHz);
output_A(0x00);
set_tris_A(0xFF);
setup_adc(ADC_CLOCK_INTERNAL );
set_adc_channel( 0 );
setup_adc_ports(AN0_VREF_VREF);
lcd_init();
lcd_gotoxy(1,1);
printf(LCD_PUTC,"Temperature:");
while(1){
adc=read_adc(ADC_START_AND_READ);
voltage=(adc*5.0)/1024;
voltage=voltage-2.5;
voltage*=100;
lcd_gotoxy(1,2);
printf(LCD_PUTC,"%0.2f %cC",voltage,degree);
}
}


Reading The Analog Temperature From LM35 With PIC16F819 In PICC
This program consumes 78 % of program memory, and 16 % of device’s RAM.

Reading The Analog Temperature From LM35 With PIC16F819 In PICC
A simulation screen shot


No comments:

Post a Comment

Search This Blog

Labels

25AA010A (1) 8051 (7) 93AA46B (1) ADC (30) Analog Comparator (1) Arduino (15) ARM (6) AT89C52 (7) ATMega32 (56) AVR (57) CCS PICC (28) DAC (1) DHT11 (2) Display (105) Distance Sensor (3) DS18B20 (3) dsPIC (2) dsPIC30F1010 (2) EEPROM (5) Environment Sensor (4) esp8266 (1) I2C (29) Input/Output (67) Interrupt (19) Keil (5) Keypad (10) LCD (47) Master/Slave (1) MAX7221 (1) MCP23017 (5) MCP23S17 (4) Meter (3) MikroC (2) Motor (15) MPLABX (71) Nokia 5110 LCD (3) OLED (2) One-Wire (6) Oscillator (8) PCB (6) PCD8544 (3) PCF8574 (5) PIC (107) PIC12F (2) PIC16F628A (2) PIC16F630 (1) PIC16F716 (3) PIC16F818 (10) PIC16F818/819 (2) PIC16F84A (15) PIC16F876A (1) PIC16F877A (9) PIC16F88 (1) PIC16F887 (60) PIC18 (19) PIC18F1220 (4) PIC18F2550 (3) PIC18F4550 (12) PWM (11) RTC (8) Sensor (10) SH1106 (1) Shift Register (11) Shift Registers (3) SPI (24) STM32 (6) STM32 Blue Pill (6) STM32CubeIDE (6) STM32F103C8T6 (6) SysTick (3) temperature sensor (11) Thermometer (21) Timer/Counter (31) TM1637 (2) UART (7) Ultrasonic (4) Voltmeter (7) WDT (1) XC16 (2) XC8 (94)