Temperature measurement using PIC18F4580 microcontroller
Temperature measurement |
Hi every one this is me Owais khan from microcontrollerpicavr.blogspot.com. During Post you will learn the way how to design an Embedded system to measure temperature using PIC18F4580,we know that in an electronic instrumentation system, it consist of number of components which are doing the measurements and giving their output as the results of the measurements.
Temperature, light intensity, flow and speed are the examples of physical parameters that can be converted in to an electrical signals using Transducers. Here, electrical signal means the resulted information generated from transducer in the form of resistance, current, voltage or capacitance.
There are many temperature sensor available in market for example TC74,LM35 and many more. In this Post we will consider LM35 Temperature Sensor because LM35 is easily available in market and it is very easy to use also used in many application as well. Let's start with the introduction of LM35.
LM35 Precision Centigrade Temperature Sensor:
Description from Texas Instruments:
The LM35 series are precision integrated-circuit temperature sensors, whose output voltage is linearly proportional to the Celsius (Centigrade) temperature.
The LM35 thus has an advantage over linear temperature sensors calibrated in ˚ Kelvin, as the user is not required to subtract a large constant voltage from its output to obtain convenient Centigrade scaling.
The LM35 does not require any external calibration or trimming to provide typical accuracies of ±1⁄4˚C at room temperature and ±3⁄4˚C over a full −55 to +150˚C temperature range.
Low cost is assured by trimming and calibration at the wafer level. The LM35’s low output impedance, linear output, and precise inherent calibration make interfacing to readout or control circuitry especially easy.
It can be used with single power supplies, or with plus and minus supplies. As it draws only 60 µA from its supply, it has very low self-heating, less than 0.1˚C in still air. The LM35 is rated to operate over a −55˚ to +150˚C temperature range, while the LM35C is rated for a −40˚ to +110˚C range (−10˚ with improved accuracy).
The LM35 series is available packaged in hermetic TO-46 transistor packages, while the LM35C, LM35CA, and LM35D are also available in the plastic TO-92 transistor package. The LM35D is also available in an 8-lead surface mount small outline package and a plastic TO-220 package.
Features:
- Calibrated directly in ˚ Celsius (Centigrade)
- Linear + 10.0 mV/˚C scale factor
- 0.5˚C accuracy guarantee able (at +25˚C)
- Rated for full −55˚ to +150˚C range
- Suitable for remote applications
- Low cost due to wafer-level trimming
- Operates from 4 to 30 volts
- Less than 60 µA current drain
- Low self-heating, 0.08˚C in still air
- Nonlinearity only ±1⁄4˚C typical
- Low impedance output, 0.1 Ω for 1 mA load
Source of above description is TEXAS INSTRUMENTS
The sensor has three pins,pin1 is for 5v dc supply,pin3 is for ground and pin2 is output. So how LM35 Temperature sensor works,LM35 converts Temperature in voltage ,The LM35 requires no external calibration because it is internally calibrated. It outputs 10 m V for each degree of centigrade temperature.
Why do we need Analog to Digital(A/D) Converter:
Digital computers and controllers use 0s and ones known as binary values, but temperature, light intensity ,speed, pressure and humidity are analog or continuous signals, in fact, in the physical world, everything is analog .
Sensors for velocity, temperature, pressure, light, and many other natural quantities generate an output that is voltage (or current). To process them there is a need of an electronic circuit known as analog-to-digital converter to convert continuous signals to binary numbers so that digital processors can read and perform mathematical and logical operations to produce meaning full results.
The ADC peripheral of the PIC 18f4580 has the following characteristics:
(a) It is a 10-bitADC.
(b) 11 channels of analog input
Digital data output
In an 8-bit ADC we have an 10-bit ADC the data output is D0-D9. To calculate the output voltage, we use the following formula:
Dout = Vin / Step size
where Dout = digital data output (in decimal), Vin = analog input voltage, and step size (resolution) is the smallest change, which is 5/1024 for an 10-bit ADC.
ADC Library in miKroC
ADC (Analog to Digital Converter) module is available with a number of PIC MCU modules.Library provides you a comfortable work with the module.
Circuit Diagram:
Proteus Simulation
mikroC Code:
float temp;
char temper[7];
int finaltemp;
sbit LCD_RS at RB2_bit;
sbit LCD_EN at RB3_bit;
sbit LCD_D4 at RB4_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D7 at RB7_bit;
sbit LCD_RS_Direction at TRISB2_bit;
sbit LCD_EN_Direction at TRISB3_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;
void display1(void)
{
lcd_out(1,1,"TEMP=");
lcd_out(1,6, Ltrim(temper));
Lcd_Chr_Cp(0xdf);
Lcd_Chr_Cp('C');
}
void data_converstion(void)
{
inttostr(finaltemp,temper);
}
void READ_temp(void)
{
temp = ADC_Read(0);
temp = (temp * 5/1023) ;
finaltemp = temp *(100) ;
delay_ms(1000);
}
void main()
{
TRISA.RA0 = 1;
TRISD= 0;
PORTD=0;
CMCON = 0x07;
ADCON0 = 0x1; // A-to-D feature is powered up. see datasheet
ADCON1 = 0x07; // ADC Channel 0 is configured. see datasheet
ADC_Init();
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
lcd_cmd(_LCD_CURSOR_OFF);
lcd_out(1,4,"DIGITAL TEMP");
lcd_out(2,6,"SENSOR");
delay_ms(1000);
Lcd_Cmd(_LCD_CLEAR);
delay_ms(1000);
lcd_out(1,4,"By");
lcd_out(2,4,"M.Owais.Khan");
delay_ms(1000);
Lcd_Cmd(_LCD_CLEAR);
while(1)
{
READ_temp();
data_converstion();
display1();
}
}
Friends for further learning about PIC18 checkout:
Library Routines used in Project
- ADC_Init
- ADC_Read
Circuit Diagram:
Proteus Simulation
mikroC Code:
float temp;
char temper[7];
int finaltemp;
sbit LCD_RS at RB2_bit;
sbit LCD_EN at RB3_bit;
sbit LCD_D4 at RB4_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D7 at RB7_bit;
sbit LCD_RS_Direction at TRISB2_bit;
sbit LCD_EN_Direction at TRISB3_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;
void display1(void)
{
lcd_out(1,1,"TEMP=");
lcd_out(1,6, Ltrim(temper));
Lcd_Chr_Cp(0xdf);
Lcd_Chr_Cp('C');
}
void data_converstion(void)
{
inttostr(finaltemp,temper);
}
void READ_temp(void)
{
temp = ADC_Read(0);
temp = (temp * 5/1023) ;
finaltemp = temp *(100) ;
delay_ms(1000);
}
void main()
{
TRISA.RA0 = 1;
TRISD= 0;
PORTD=0;
CMCON = 0x07;
ADCON0 = 0x1; // A-to-D feature is powered up. see datasheet
ADCON1 = 0x07; // ADC Channel 0 is configured. see datasheet
ADC_Init();
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
lcd_cmd(_LCD_CURSOR_OFF);
lcd_out(1,4,"DIGITAL TEMP");
lcd_out(2,6,"SENSOR");
delay_ms(1000);
Lcd_Cmd(_LCD_CLEAR);
delay_ms(1000);
lcd_out(1,4,"By");
lcd_out(2,4,"M.Owais.Khan");
delay_ms(1000);
Lcd_Cmd(_LCD_CLEAR);
while(1)
{
READ_temp();
data_converstion();
display1();
}
}
Friends for further learning about PIC18 checkout:
Comments
Post a Comment