Pages

Wednesday 2 July 2014

Digital Thermometer Design

Temperature and man!

Daily activities in life require measuring and monitoring of our surrounding environment. A Digital Thermometer capable of measuring and displaying temperature values within the range of 0 to +99 degrees centigrade was designed and simulated.


System Analysis

The block diagram for the proposed system is shown in figure 1.0. The block diagram highlighted the system components that initiated considerations for technologies that could provide possible solutions.


Figure 1.0: System block diagram


Solutions of choice

The LM35 provided an ideal solution for the temperature sensor technology while the Varitronix VI-302-1 segment display module was a viable solution for the temperature display. Considering the fact the LM35 sensor produces an analogue output proportional to temperature, an economical and low power PIC16F88 microcontroller with ADC peripheral suits perfectly as the system controller.


Putting things together

The complete system schematic is shown in figure 2.0. The  AY0438 segments display Driver created a perfect interface between the PIC micro and the VI-302-1 display module.


Figure 2.0: The system schematic


Software Implementation

In order to add life to the system, the software development was pursued using Microchip HI-TECH C Compiler. The full code documentation that implements the proposed system is shown in the scroll box below. Appropriate comments where added to ensure that the code is comprehensible enough.

/****************************************************************************
  Code for Temperature display using PIC16F88 and LM35 sensor 
Author - U Ejiofor,Embedded Systems Engineer@ E-Cracked Solutions
Revision Version 1.2  26/06/14
*/

#ifndef _XTAL_FREQ
 // This definition is required to calibrate __delay_us() and __delay_ms()
#define _XTAL_FREQ 4000000L // 4MHz
#endif

#include <htc.h>
#include <math.h>

#define D_CLK RB0 // set pin for display driver clock
#define D_DIN RB1 // set pin for display driver data input
#define D_LOAD RB2 // set pin for display driver load

// set chip configuration bits
__CONFIG(FOSC_INTOSCIO & WDTE_OFF& PWRTE_OFF & BOREN_OFF & CPD_OFF & CP_OFF & LVP_OFF );

// prototype declarations
void init_a2d(void);
unsigned char read_a2d();
void convert_BCD(void);
unsigned char get_segment_dat(char digit);
void display_update_segments(char *data);
void display_send_byte(unsigned char data); 

// GLOBAL VARIABLE DECLARATIONS

unsigned char mask_R[] = {0x00,0x10,0x20,0x30,0x40,0x50,0x60,0x70,0x80,0x90};
unsigned char mask_L[] = {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09};
unsigned char data[]= {0x30,0xE0,0xFE,0x9c}; //0x9c = C and 0x30= +
unsigned char temp_bcd;
unsigned char buffer;
char n;

//function that converts decimal to BCD
int bcd(int dec)
{
return ((dec/10)<<4)+(dec%10);
}

void main(void)
{
// VARIABLE DECLARATIONS
int x, t;

OSCCON = 0X60; //SET Internal Oscillator to 4 MHz

INTCON=0; // Disable the interrupts.

TRISA=0x09; //configure analog input pins as input
TRISB = 0; // Set all PORTB pins as outputs

init_a2d(); // initialise the A2D module
//initialize LCD driver
D_CLK=0;
D_CLK=1;
D_DIN=0;
D_DIN=1;
D_LOAD=0;
D_LOAD=1;


// Loop Forever
while(1) {
x=read_a2d(); // sample the analog value on RA0

t=round(x*0.588);//Convert to Degree Celcius

temp_bcd = bcd(t); //convert dec temp to BCD
convert_BCD();
display_update_segments(data);

} // end of while
} // end of main

/* code to set up the A2D module */
void init_a2d(void){
ANSEL=0x09; //make ANO(RA0 ) and AN3(RA3) pin analogue channel
ADCON1=0x20; // configure A/D clock,
ADCON0=0x0C1; // left justify for 8 bit conversion, A/D REF = VREF+ and VREF-  
ADON=1; // turn on the A2D conversion module
}

/* Function to Return an 8 bit ADC result */
unsigned char read_a2d(){
ADON=1; // turn ON the A2D conversion module
__delay_us(100);
GO = 1; //GO=1; // initiate conversion on the selected channel
while(GO==1);
ADON=0; // turn oFF the A2D conversion module
return(ADRESH); // return 8 MSB of the result
}

/* Function to convert BCD for seven segment display*/
void convert_BCD(void){

for (n=0;n<10;n++){

buffer = temp_bcd;
buffer = buffer << 4;
if((buffer^mask_R[n])==0)
data[2] = get_segment_dat(n);

buffer = temp_bcd;
buffer = buffer >> 4;
if((buffer^mask_L[n])==0)
data[1] = get_segment_dat(n);

}
}

/* Function to fetch digit display values*/
unsigned char get_segment_dat(char digit){
 switch(digit){
  case 0: digit = 0xfc; break;
  case 1: digit = 0x60; break;
  case 2: digit = 0xda; break;
  case 3: digit = 0xf2; break;
case 4: digit = 0x66; break;
  case 5: digit = 0xb6; break;
  case 6: digit = 0xbe; break;
  case 7: digit = 0xe0; break;
case 8: digit = 0xfe; break;
  case 9: digit = 0xf6; break;
  default: digit = 0;
 }
return digit;
}

/* Function to display temperature values on LCD*/
void display_update_segments(char *data)
{
display_send_byte(data[0]); // lefthand display
display_send_byte(data[1]);
display_send_byte(data[2]);
display_send_byte(data[3]);
D_LOAD = 1; // move data from shift register to segment latches
D_LOAD = 0;
}

/* Fuction to write to the LCD Driver - AY0438 */
void display_send_byte(unsigned char data) 
{
unsigned char mask = 0x01;
int n;

for (n=0;n<8;n++)
{
if ((data & mask) == 0)
D_DIN = 0;
else
D_DIN = 1;
D_CLK=1;
D_CLK=0;

mask = mask << 1;
}

}


Results

In order to appreciate the work, simulation results obtained from the system is sampled below in video 1.


Video 1: The Digital Thermometer simulation results 


End Note 

To get the system working in real life, the rigorous processes of PCB development and troubleshooting should be followed with a cool head.

4 comments:

  1. Thanks for sharing your informative post, Digital Thermometer

    ReplyDelete
  2. Fantastic Post! Lot of information is helpful in some or the other way. Keep updating.digital thermometer

    ReplyDelete
  3. Southern Stars Enterprises Co Ltd is a professional 7 inch to 55 inch LCD advertising player manufacturer for 8 years. The products are widely used in supermarkets, DIY shops, chain stores, shopping malls and other sales points for product advertising and promotion. Many companies are using 7” small digital signage display, retail store marketing video screen, loop playing lcd display advertising(Model AD705) for branding.

    Visit here:- Lcd video screen

    ReplyDelete
  4. Thankyou for sharing such as nice article post keep it sharing.
    Do you Need to Purchase In Bulk ? We also do Custom Gauges and logo Art Work.
    Welcome to Noshok Authorized Mass Measure Ultimate DISTRIBUTOR at 40-80% off List Prices-Transducers-Transmitters-Switches-Gauges-Needle Valves-Seals -Prices Can be Negotiable.
    Digital Temperature Indicators

    ReplyDelete