Compte Rendu Henna, Nurcahyono, Lamin

Embed Size (px)

Citation preview

  • 7/28/2019 Compte Rendu Henna, Nurcahyono, Lamin

    1/15

    0

    Project Report

    Temperature Monitoring by using

    Microcontroller PIC 18F6722

    Prof : CEDRIC BRAZEILLES

    Name of members group :

    DIALLO Mamadou Lamine

    KUSHARDIANTO NurCahyono

    NURDIANSARI Henna

  • 7/28/2019 Compte Rendu Henna, Nurcahyono, Lamin

    2/15

    1

    I. IntroductionThe objective of this project is to read the datum of temperature into personal computer (PC) by

    using microcontroller PIC 18F6722.

    II. ComponentThis project is consist of :

    1. Personal Computer2. Microcontroller PIC 18F67223. Board AMI ELECTRONIQUE Type E1416 Carte SD4. SD card5. Serial Cable RS 232

    Sensor LM35 PIC 18F6722 RS 232

    PC

    Figure 1.Schema in this system

    Flowchart of this project

    Start

    Sensor

    Main program

    Usart.c

    Usart.h

    Output

    End

    Figure 2.Flowchart in this system

  • 7/28/2019 Compte Rendu Henna, Nurcahyono, Lamin

    3/15

    2

    III. TheoryIII.1 Thermal Sensor

    The LM35 series are precision integrated-circuit temperature sensors, whose output voltage is

    linearly proportional to the Celsius (Centigrade) temperature. The LM35 does not require any external

    calibration or trimming to provide typical accuracies of 14C at room temperature and 34C over afull 55 to +150C temperature range. Low cost is assured by trimming and calibration at the wafer

    level.

    The LM35s 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.1C in still air.

    The LM35 is rated to operate over a 55 to +150C temperature range, while the LM35C is rated

    for a 40 to +110C 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. As we show you in figure 3 below. [1]

    Figure 3, Thermal Sensor LM35

    III.2 Microchip PIC 18F6722

    Figure 4.Microchip PIC 18F6722

    PIC is a family of modified Harvard architecture microcontrollers made by Microchip

    Technology,it is derived from the PIC1650originally developed by General Instrument's

    Microelectronics Division. The name PIC initially referred to "Peripheral Interface Controller".

    We can se the outlook of microchip PIC 18F6722 as in the figure 4 above. [2]

    PICs are popular with both industrial developers and hobbyists alike due to their low cost, wide

    availability, large user base, extensive collection of application notes, availability of low cost or

    free development tools, and serial programming (and re-programming with flash memory)

    capability[3].

  • 7/28/2019 Compte Rendu Henna, Nurcahyono, Lamin

    4/15

    3

    In this project we use PIC 18F6722. This microcontroller is ideal for large low power

    (nanoWatt) and connectivity applications that benefit from the availability of four serial ports:

    double synchronous serial ports (I2C and SPI) and double asynchronous (LIN capable) serial

    ports. Large amounts of RAM memory for buffering and FLASH program memory make it ideal

    for instrumentation panels, TCP/IP enabled embedded applications as well as metering and

    industrial control and monitoring applications. While operating up to 40 MHz, it is also backward

    software and hardware compatible with the PIC18F6722.

    Before we build software to run the program, first we should have to know the basic

    initialization interrupt register for microcontroller PIC18F6722. In this project we use 1 important

    initialization interrupt register such as : INTCON Registersand 1 important timer

    controlTIMER0 MODULE. Also we use the serial I/O modules in microcontroller PIC 18F6722

    is USART.

    The PIC18FXX2 devices have multiple interrupt sources and an interrupt priority feature that

    allows each interrupt source to be assigned a high priority level or a low priority level. The high

    priority interrupt vector is at 000008h and the low priority interrupt victories at 000018h. High

    priority interrupt events will override any low priority interrupts that may be in progress.

    Each interrupt source, except INT0, has three bits to control its operation. The functions of

    these bits are:

    Flag bit to indicate that an interrupt event occurred

    Enable bit that allows program execution to branch to the interrupt vector address when the

    flag bit is set

    Priority bit to select high priority or low priority

    III.2.1 INTCON

    The INTCON registers are readable and writableregisters which contain various enable,

    priority and flagbits. Interrupt flag bits are set when an interruptcondition occurs, regardless of the

    state ofits corresponding enable bit or the globalinterrupt enable bit. User software shouldensure

    the appropriate interrupt flag bitsare clear prior to enabling an interrupt.This feature allows for

    software polling.

  • 7/28/2019 Compte Rendu Henna, Nurcahyono, Lamin

    5/15

    4

    III.2.2 TIMER0 MODULE

    The Timer0 module incorporates the following features:

    Software selectable operation as a timer orcounter in both 8-bit or 16-bit modes

    Readable and writable registers

    Dedicated 8-bit, software programmableprescaler

    Selectable clock source (internal or external)

    Edge select for external clock

    Interrupt-on-overflow

    The T0CON register (Register 12-1) controls allaspects of the modules operation, including

    theprescale selection. It is both readable and writable.

  • 7/28/2019 Compte Rendu Henna, Nurcahyono, Lamin

    6/15

    5

    III.3 Recommended Standard 232 (RS 232)

    It is independent channels that isestablished for two-way (full-duplex) serial communications.

    The RS232 signals are represented by voltage levels with respect to a system common (power /

    logic ground). RS232 data is bi-polar +3 to +12 volts indicates an "ON or 0-state (SPACE)

    condition" while data bipolar is -3 to -12 volts indicates an "OFF" 1-state (MARK) condition.[4]

    To explain eachfunction of DB9 RS232 in this communication using serial port we can show

    in figure 5. [5]

    Figure 5.Schema of DB9 connector of RS 232

  • 7/28/2019 Compte Rendu Henna, Nurcahyono, Lamin

    7/15

    6

    III.4 ADDRESSABLE UNIVERSAL SYNCHRONOUS ASYNCHRONOUS RECEIVER

    TRANSMITTER (USART)

    USART stands for Universal Synchronous Asynchronous Receiver Transmitter. It issometimes

    called the Serial Communications Interface or SCI.Synchronous operation uses a clock and data

    line while there is no separate clockaccompanying the data for Asynchronous transmission.Sincethere is no clock signal in asynchronous operation, one pin can be used fortransmission and

    another pin can be used for reception [6].

    Both transmission andreception can occur at the same time this is known as full duplex

    operation.Transmission and reception can be independently enabled. However, when the serialport

    is enabled, the USART will control both pins and one cannot be used forgeneral purpose I/O when

    the other is being used for transmission or reception.The USART is most commonly used in the

    asynchronous mode.

    In this presentationwe will deal exclusively with asynchronous operation.The most common

    use of the USART in asynchronous mode is to communicate to aPC serial port using the RS-232

    protocol.

    In order to configure pins RC6/TX/CK and RC7/RX/DTas the Universal Synchronous

    Asynchronous ReceiverTransmitter:

    bit SPEN (RCSTA) must be set (= 1),

    bit TRISC must be cleared (= 0), and

    bit TRISC must be set (=1).

    Register 16-1 shows the Transmit Status and Control. Register (TXSTA) and Register 16-2

    shows the. Receive Status and Control Register (RCSTA). The standart USART to set this

    microchip base on the datasheet IC PIC 18F6722 as we well as we show you in this datasheet table

    of USART below :

  • 7/28/2019 Compte Rendu Henna, Nurcahyono, Lamin

    8/15

    7

    III. 5 Analog-to-Digital converter (ADC) in PIC 18F6722

    The Analog-to-Digital (A/D) converter module has12 inputs for the 64-pin devices and 16 for

    the 80-pindevices. This module allows conversion of an analoginput signal to a corresponding 10-

    bit digital number.

    The module has five registers:

    A/D Result High Register (ADRESH) A/D Result Low Register (ADRESL)

    A/D Control Register 0 (ADCON0)

    A/D Control Register 1 (ADCON1)

    A/D Control Register 2 (ADCON2)

    The ADCON0 register, shown in Register 21-1,controls the operation of the A/D module.

    TheADCON1 register, shown in Register 21-2, configuresthe functions of the port pins. The

    ADCON2 register,shown in Register 21-3, configures the A/D clocksource, programmed

    acquisition time and justification [7].

  • 7/28/2019 Compte Rendu Henna, Nurcahyono, Lamin

    9/15

    8

    IVSource Program

    IV.1 USART.H

    This program define all of he function which are used in the system, including the open

    connection function of serial RS 232, also read and write function of the serial connector. In this

    term we will write the output of the sensor LM35 to the hyperterminal as a result measurement oftemperature.

    #i f ndef USART_H#def i ne USART_H

    #i ncl ude "p18f 6722. h"/ / decl ar e f unct i on of open connect i onvoi dUSARTI ni t ( ) ;

    / / decl ar e f unt ci on of wr i t e mode byt evoi dwr i t e_byt e( char ) ;

    / / decl ar e f unt ci on of wr i t e mode st r i ngvoi dwr i t e_st r i ng( const char *) ;

    / / decl ar e f unt ci on of wr i t e mode i nt egervoi dwr i t e_i nt ( i nt , unsi gned char ) ;

    / / decl ar e f unt ci on of r eadunsi gned char r ead_byt e( ) ;

    #endi f

    IV.2 USART.C

    In this program usar t . c file contains all of the functions that used in this usartcommunication. The voi d USARTI ni t ( ) is a function for initializing the usart.

    voi d wr i t e_byt e ( ) is a function to write the ouput from sensor to the hyperterminalin mode byte. There are another function of write in this program, but in different mode of writefunction, such as mode write string andinteger.

    The last function is void read_byte ( ), this function are used for read the input from

    hyperterminal (through serial connection) than redirect the input as task for microcontroller.

    #i ncl ude "p18f 6722. h"

    #i ncl ude "usar t . h"/ / open connect i on t o seri al vi a USART

    voi d USARTI ni t ( ){/ / Baud Rat e = 57600 Bi t s per SecondSPBRG1=86;

    / / TXSTA REGTXSTA1bi t s. TXEN=1;TXSTA1bi t s. BRGH=1;/ / TXSTA1bi t s. SYNC=0;

    / / RCSTARCSTA1bi t s. SPEN=1;

  • 7/28/2019 Compte Rendu Henna, Nurcahyono, Lamin

    10/15

    9

    RCSTA1bi t s. CREN=1; / / Enabl e Recei ver ( RX)

    / / BAUDCONBAUDCON1bi t s. BRG16=1;

    }

    / / wr i t e out put of ser i al t o the hyper t er mi nal mode bytevoi dwr i t e_byt e( char ch){/ / Wai t f or TXREG Buf f er t o become avai l abl ewhi l e( ! PI R1bi t s. TX1I F) ;

    / / Wr i t e dat aTXREG1=ch;}

    / / wr i t e out put of ser i al t o t he hyper t er mi nal mode st r i ngvoi dwr i t e_st r i ng( const char *st r )

    {whi l e( ( *str ) ! =' \ 0' ){

    / / Wai t f or TXREG Buf f er t o become avai l abl ewhi l e( ! PI R1bi t s. TX1I F) ;

    / / Wr i t e dat aTXREG1=( *st r ) ;

    / / Next got o charst r ++;

    }}

    / / wr i t e out put of ser i al t o the hyper t er mi nal mode i nt egervoi dwr i t e_i nt ( i nt val , unsi gned char f i el d_l engt h){char st r [ 5] ={0, 0, 0, 0, 0};i nt i =4, j =0;

    i f ( val 5)

    whi l e( st r [ j ] ==0) j ++;el se

    j =5- f i el d_l ength;

    f or ( i =j ; i

  • 7/28/2019 Compte Rendu Henna, Nurcahyono, Lamin

    11/15

    10

    }

    / / Read f unct i on - - > Read t he i nput of ser i al f r om hyper t er mi nalunsi gned char r ead_byt e(){whi l e( ! PI R1bi t s. RCI F); / / Wai t f or a byt e

    r et urn RCREG1;}

    IV.3 MAIN.C

    This is the main program of the system, several function which defined and developed in

    usart.h andusart.c are executed here. First, to get the output from sensor temperature, we should

    initialized ADC (Analog Digital Converter). Then, with the function void ACDInit ( ) the

    configuration of microcontroller to get the data from the sensor are established. The function of

    USARTInit is important too, this function activate Serial Connection.

    The process of getting data output from sensor and write this data to the hyperterminal, areinitiated in this main program. So, several variable character and integer are needed for completed the

    process.

    #i ncl ude "p18f 6722. h"#i ncl ude #i ncl ude "usar t . h"

    unsi gned char word[] ="Temper atur e : " ;unsi gnedi nt adcval ; / / ADC Val ueunsi gned char kar , kar 1;

    / / f unct i on t o i ni t i al i ze ADCvoi d ADCI ni t ( ){ADCON2=0x0F;ADCON0=0x00; / / Sel ect ADC Channel / / Vol t age Ref er ence Conf i gur at i on bi t s 00, Vr ef + = AVDD, Vr ef - = AVSSADCON1=0x00;

    }

    / / Funct i on t o Read gi ven ADC channel i n order t o read t he out put ofsensorunsi gnedi ntADCRead( )

    {unsi gned char dat ;ADCON0bi t s. ADON=1;ADCON0bi t s. GO_DONE=1; / / St ar t conver si onwhi l e( ADCON0bi t s. GO_DONE) ; / / wai t f or t he conver si on t o f i ni sh/ / PI R1bi t s. ADI F=0;

    ADCON0bi t s. ADON=0; / / swi t ch of f adcdat =ADRESH;r et ur ndat ;}

    / / del ay par amat r evoi ddel ay_ms( i nt val ){i nt i ;f or ( i =0; i

  • 7/28/2019 Compte Rendu Henna, Nurcahyono, Lamin

    12/15

    11

    }

    / / - - - - - - Mai n Program- - - - - - - - - / /voi d mai n( ){chari , var ;

    / / I ni t i al i ze t he USARTUSARTI ni t ( ) ;ADCI ni t ( ) ;

    TRI SAbi t s. TRI SA0 = 1;TRI SB=0x00;

    f or ( i =0; i

  • 7/28/2019 Compte Rendu Henna, Nurcahyono, Lamin

    13/15

    12

    VI. 4 Schema proteus of this system

    In figure 6 we provide the full schema of the system that consist of :

    1. Sensor LM352. Microcontroller PIC18F67223. Connector RS2324. LED5. Power and Ground Modul

    Figure 6. Schema Proteus of The System

    The output temperature reading from hyperterminal has been represented in figure 7 below .

    The temperature is relevant to the output of sensor LM35 which is sent by microcontroller through

    RS232.

    Figure 7 Output Hyperterminal

  • 7/28/2019 Compte Rendu Henna, Nurcahyono, Lamin

    14/15

    13

    V. Conclusion

    1. Base on the Figure 7. Output hyperterminal, we can make a conclusion that thecommunication between the sensor and personal computer can be establised using

    microcontroller trough serial connection.

    2. However, the system is running well, but actually there is a dificulty to match the sensorand the microcontroller (syncronization between sensor and microcontroller). It is very

    complex setting.

    3. This system will completely perfect if we can add with SD card system store. But becausethe complexity of syncronization between microcontroller and SD card, so we cant add

    this system with SD card instantly.

  • 7/28/2019 Compte Rendu Henna, Nurcahyono, Lamin

    15/15

    14

    [1] www.8051microcontrollers.com

    [2] Datasheet microchip IC PIC 18FXX2

    [3] http://en.wikipedia.org/wiki/PIC_microcontroller

    [4] RS232 Data Interface a Tutorial on Data Interface and cables.

    [5] http://www.arcelect.com/rs232.htm

    [6] http://www.eti.pg.gda.pl/katedry/ksg/dydaktyka/dla_studentow//usart.pdf

    [7] Datasheet PIC18F8722 Family