Skip to main content

Temperature measurement using PIC18F4580 microcontroller


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:

LM35 sensor IC


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:

  1. Calibrated directly in ˚ Celsius (Centigrade) 
  2. Linear + 10.0 mV/˚C scale factor 
  3. 0.5˚C accuracy guarantee able (at +25˚C) 
  4. Rated for full −55˚ to +150˚C range 
  5. Suitable for remote applications 
  6. Low cost due to wafer-level trimming 
  7. Operates from 4 to 30 volts 
  8. Less than 60 µA current drain 
  9. Low self-heating, 0.08˚C in still air 
  10. Nonlinearity only ±1⁄4˚C typical 
  11. 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:

Analog to Digital conversion block diagram




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.

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

Popular posts from this blog

How to use SPI Debugger

  SPI Debugger Hi Friends, in this post, we will discuss how to use SPI Debugger available in proteus for serial peripheral interface (SPI) which is a built-in feature of PIC microcontroller to communicate and data exchange between PIC and other devices. SPI Debugger Introduction to SPI Guys, SPI can be considered as a programmable shift  register, The SPI module is a synchronous serial I/O port that shifts a serial bit stream of variable length and data rate between the PIC and other peripheral devices. Here “synchronous” means that the data transmission is synchronized to a clock signal. To avoid further delay, let's see some important connections and different configurations to effectively use SPI Debugger. How to use SPI Debugger in MASTER & SLAVE configuration Select the virtual instrument and from the instrument, list selects "SPI Debugger". SPI Debugger Insert two SPI Debugger on the working area, select any one of them,

PIC18f4580 Timer0 calculation using miKroC , CSS and proteus

PIC18f4580 TIMER PROGRAMMING The PIC18f4580 has four timers. they're named as Timers zero, one, two, and three. they will be used either as timers to come up with a time delay or as counters to count events happening outside the microcontroller. First, we see however Timers zero is employed to come up with time delays. Every timer wants a clock pulse to tick. The clock supply will be internal or external. If we have a tendency to use the inner clock supply, then 1/ fourth of the frequency of the crystal oscillator on the OSC1 and OSC2 pins (Fosc/4) is fed into the timer. Therefore, it's used for time delay generation and for that reason is termed a timer. By selecting the external clock choice, we have a tendency to feed pulses through one among the PIC18's pins: this is often known as a counter. GIF  taken from  https://exploreembedded.com Basic registers of the timer Majority of t timers in 18F are 16 bits wide. Because the PIC 18 has an 8- bit ar

Frequency Counter using Interrupts PIC18f4580 Project

Frequency Counter  using PIC18f458 0 Proje ct This POST describes the construction of small frequency counter with a cheap PIC18f4580 microcontroller with 16 x 2 LCD.   Prerequisites: PIC18F4580 TIMER Programming. PIC18F4580 COUNTER Programming. PIC18F4580 Interfacing with 16x2 LCD. PIC18F4580 Interrupts Programming  ( we will cover in this POST) Concept: Frequency  is the number of occurrences of a repeating event per unit time. in our case we will measure a number of clocks generated by clock source per unit time. In this project, LCD is used to display the frequency and PIC timer 1 to measure the input signal and Timer0 to generate an indication that one second has gone. System software utilizes Timer-1 in the 16-bit counter mode to count the input signal and overflows of the counter are added to provide the aggregate count in multiples of 65536. Totaling the existing value of the counter at the conclusion provides the full count.