12
© 2005 Microchip Technology Inc. DS00988A-page 1 AN988 INTRODUCTION The MCP9800 is a digital CMOS silicon temperature sensor that provides an accurate digital temperature measurement. Data is converted from an internal diode temperature-sensing element to a digital format that can be directly interfaced to a PICmicro ® microcontroller unit (MCU). The MCP9800 sensor offers many system-level advantages, including the integration of the sensor and signal-conditioning circuitry in a small Integrated Circuit (IC) package. The MCP9800 also has a One-shot Conversion mode that performs a single temperature measurement and then goes into power-saving Shutdown mode. The One- shot Conversion mode makes this sensor a good choice for power-critical, portable applications. The MCP9800 digital temperature sensor is especially suited for embedded systems due to its I 2 C™ interface, which serves to provide an industry standard method of interface to a microcontroller. This application note will discuss system integration, firmware implementation and Printed Circuit Board (PCB) layout techniques for using the MCP9800 in an embedded system. The techniques for integrating the MCP9800 into an embedded systems environment will be demonstrated by using the PICkit™ 1 Flash Starter Kit and a MCP9800 PICtail™ daughter board. The MCP9800 PICtail daughter board plugs into the PICkit 1 Flash Starter Kit expansion header J3, as shown in Figure 1. The MCP9800 demonstration is designed to measure and display temperature using the on-board 7-segment LED display. Gerber files for the PCB, source code and a hex file to program a PIC16F684 are included in the companion zip file, 00059R1.zip. FIGURE 1: Block Diagram of the MCP9800 Digital Temperature Sensor Demonstration. Author: Ezana Haile and Jim Lepkowski Microchip Technology Inc. V DD PICmicro ® Flash I 2 C Interface SPI™ GND MCU PICkit™ 1 Flash Starter Kit PC USB J3 2 +5V J2 2 SPI Interface I 2 C™ Alert Indicator MCP9800 PICtail™ Demo Board MCP9800 Thermal Sensor PIC16F737 Display Controller 7-Segment display PIC16F684 Interface Interface Interfacing the MCP9800 I 2 C Digital Temperature Sensor to a PICmicro ® Microcontroller

00988a

Embed Size (px)

Citation preview

Page 1: 00988a

AN988Interfacing the MCP9800 I2C™ Digital Temperature Sensor

to a PICmicro® Microcontroller

INTRODUCTION

The MCP9800 is a digital CMOS silicon temperaturesensor that provides an accurate digital temperaturemeasurement. Data is converted from an internaldiode temperature-sensing element to a digital formatthat can be directly interfaced to a PICmicro®

microcontroller unit (MCU). The MCP9800 sensoroffers many system-level advantages, including theintegration of the sensor and signal-conditioningcircuitry in a small Integrated Circuit (IC) package. TheMCP9800 also has a One-shot Conversion mode thatperforms a single temperature measurement and thengoes into power-saving Shutdown mode. The One-shot Conversion mode makes this sensor a goodchoice for power-critical, portable applications.

The MCP9800 digital temperature sensor is especiallysuited for embedded systems due to its I2C™ interface,which serves to provide an industry standard method ofinterface to a microcontroller. This application note willdiscuss system integration, firmware implementationand Printed Circuit Board (PCB) layout techniques forusing the MCP9800 in an embedded system.

The techniques for integrating the MCP9800 into anembedded systems environment will be demonstratedby using the PICkit™ 1 Flash Starter Kit and aMCP9800 PICtail™ daughter board. The MCP9800PICtail daughter board plugs into the PICkit 1 FlashStarter Kit expansion header J3, as shown in Figure 1.The MCP9800 demonstration is designed to measureand display temperature using the on-board 7-segmentLED display.

Gerber files for the PCB, source code and a hex file toprogram a PIC16F684 are included in the companionzip file, 00059R1.zip.

FIGURE 1: Block Diagram of the MCP9800 Digital Temperature Sensor Demonstration.

Author: Ezana Haile and Jim LepkowskiMicrochip Technology Inc.

VDD

PICmicro®

Flash

I2C Interface

SPI™

GND

MCU

PICkit™ 1 Flash Starter Kit

PCUSB

J32

+5V

J2

2SPI Interface

I2C™

Alert Indicator

MCP9800 PICtail™ Demo Board

MCP9800ThermalSensor

PIC16F737Display Controller

7-Segment display

PIC16F684

Interface

Interface

© 2005 Microchip Technology Inc. DS00988A-page 1

Page 2: 00988a

AN988

MCP9800 FUNCTIONAL DESCRIPTION

The MCP9800 consists of an internal diodetemperature sensor, a user selectable 9-12-bit sigmadelta Analog-to-Digital Converter (ADC), digitalregisters and a I2C communication port. Figure 2provides a simplified block diagram of the MCP9800. Aschematic of the MCP9800 to PICmicro MCU interfaceis shown in Figure 3.

FIGURE 2: Functional Block Diagram.

FIGURE 3: MCP9800 to PICmicro® MCU Interface.

Temperature Data Format

Temperature data is represented by a 9-12-bit two’scomplement word with a resolution of 0.15°C per bit to0.0025°C per bit. The temperature data is stored in thetemperature registers in a two’s complement format, asshown in Table 1.

TABLE 1: TEMPERATURE REGISTER

Refer to the MCP9800 data sheet, “2-Wire AccuracyTemperature Sensor” (DS21909), for more informationregarding the serial interface.

Resolution

9-Bit10-Bit11-Bit12-Bit

Temperature

THYST

TSET

Register

Register

Register

RegisterPointer

I2C™/SMBusInterface

ConfigurationRegister

ΣΔ ADC

Band-GapTemperature

Sensor

One-Shot

Shutdown

Fault Queue

Alert Polarity

Alert Comp/Int

SDA

SCK

I/O

SDA

SCK

ALERT

MCP9800

0.1 µF

VDD

GND

VDD

PICmicro®

MCU

Example using a 10-bit data:

Temperature = 41.5°C

MSb Temperature Register = 00101001b

= 25 + 23 + 20

= 32 + 8 + 1 = 41

LSb Temperature Register = 10000000b = 2-1

= 0.5

D7 D6 D5 D4 D3 D2 D1 D0Address/ Register

Sign 26 25 24 23 23 21 20 02HTemp. MSb

2-1 2-2 0 0 0 0 0 0 01HTemp. LSb

DS00988A-page 2 © 2005 Microchip Technology Inc.

Page 3: 00988a

AN988

REGISTERS

The MCP9800 family has four registers that are user-accessible. These registers are specified as the ambi-ent temperature register, the Temperature Limit-set(TSET) register, the Temperature Hysteresis (THYST)register and device Configuration registers.

The Ambient Temperature register is a read-onlyregister and is used to access the ambient temperaturedata. The data from the ADC is loaded in parallel in theregister. The TSET and THYST registers are read/writeregisters that provide user-programmable temperaturelimits. If the ambient temperature drifts beyond theprogrammed limits, the MCP9800 outputs an alertsignal using the ALERT pin (refer to “ALERT OutputConfiguration”). The device Configuration registerprovides access for the user to configure theMCP9800’s various features. These registers aredescribed in further detail in the following sections.

FIGURE 4: Register Block Diagram.

The registers are accessed by sending a registerpointer to the MCP9800 using the SPI™ interface. Thisis an 8-bit pointer. However, the two Least Significantbits (LSb) are used as pointers and all other bits needto be cleared <0>. This device has additional registersthat are reserved for test and calibration. If theseregisters are accessed, the device may not performaccording to specification. Refer to the MCP9800 datasheet for detailed information.

ALERT OutputControl Logic

ALERTOutput

Resolution

Temperature

THYST

TSET

Register

Register

Register

ConfigurationRegister

One-shot

Shutdown

Fault Queue

Alert Polarity

Alert Comp/Int

© 2005 Microchip Technology Inc. DS00988A-page 3

Page 4: 00988a

AN988

APPLICATIONS INFORMATION

The MCP9800 does not require any additionalcomponents in order to measure temperature, thoughit is recommended that a decoupling capacitor (a high-frequency ceramic capacitor should be used) of 0.1 µFto 1 µF be provided between the VDD and GND pins.The capacitor should be located as close as possible tothe IC power pins in order to provide effective noiseprotection to the sensor.

The MCP9800 measures temperature by monitoringthe voltage of a diode located on the IC die. The IC pinsof the MCP9800 provide a low-impedance thermal pathbetween the die and the PCB, allowing the MCP9800to effectively monitor the temperature of the PCB. Thethermal path between the ambient air is not as efficientbecause the plastic IC housing package functions as athermal insulator. Thus, the ambient air temperature(assuming that a large temperature gradient existsbetween the air and PCB) has only a small effect on thetemperature measured by the MCP9800.

A potential for self-heating errors can exist if theMCP9800 I2C interface communication lines areheavily loaded. Typically, the self-heating error isnegligible because of the relatively small currentconsumption of the MCP9800. A temperature accuracy

error will result from self-heating if the I2C communica-tion pins sink/source the maximum current specified forthe MCP9800. Therefore, to maximize the temperatureaccuracy, the output loading of the I2C inteface signalsshould be minimized.

MCP9800 PICtail™ DAUGHTER BOARD

The MCP9800 PICtail daughter board is plugged intothe PICkit 1 Flash Starter Kit via expansion header J3.Figure 5 shows the MCP9800 PICtail daughter boardplugged into the PICkit 1 Flash Starter Kit. For moreinformation on the PICkit 1 Flash Starter Kit, refer to the“PICkit™ 1 Flash Starter Kit User’s Guide” (DS40051).

The MCP9800 PICtail daughter board consists of aMCP9800 temperature sensor and a bypass capacitor.The bypass capacitor (C1) is used to provide noiseimmunity on the +5 VDC power supply. In addition, thisdemo board has a 7-segment LED temperature displaycircuit. Figure 6 shows a schematic of the board.

Refer to the “MCP9800 Thermal Sensor PICtail™Demo Board User’s Guide” (DS51528) for furtherdetails.

FIGURE 5: MCP9800 PICtail™ Daughter Board and PICkit™ 1 Flash Starter Kit.

PICkit™ 1 Flash Starter Kit

USB Cable

ExpansionHeader (J3)

Insert PIC16F684

Potentiometer RP1

Push-Button Switch SW1

MCP9800 PICtail™ Demo Board

DS00988A-page 4 © 2005 Microchip Technology Inc.

Page 5: 00988a

AN988

FIGURE 6: MCP9800 PICtail™ Daughter Board Schematic.

1

4

5

2

RC1

RC0

RC5

GND

13

10

11

4

14

PICkit™ 1Flash Starter Kit

+5V

SDA

U1

J3 J2

13

10

11

4

14

SCL

RC36 6

15

14

21

SCL

U2

SDA

VDD

VDD

VDD6

MCP9800 PICtail™ Daughter Board

MCP9800

PIC16F737

© 2005 Microchip Technology Inc. DS00988A-page 5

Page 6: 00988a

AN988

MCP9800 INTERFACE FIRMWARE

A block diagram of the firmware flow is shown in the Figure 7.

FIGURE 7: Block Diagram of the Firmware.

Initially, the position of the RP1 potentiometer isdetermined using an ADC. This data is used to set theALERT output limit and hysteresis. Temperature datais then obtained from the MCP9800. If the PCrequests temperature data, the raw temperature datais transmitted using the USB cable. Refer to the“MCP9800 Thermal Sensor PICtail™ Demo BoardUser’s Guide” (DS51528), for further detail. The SW1switch position is determined to select the measure-ment unit as degree Celsius or Fahrenheit. Once theunit conversion is completed, data is transmitted fordisplay using the 7-segment display.

Initialization

Obtaining Temperature

Value

Transmitting Temperature for

Display

Converting Temperature to Desired Units

TSET and THYST Programming

Raw Data Reporting

RP1TSET/THYST

Raw Temperature Scaled Temperature

Converted Temperature

BCD Temperature

TA

SW1

DS00988A-page 6 © 2005 Microchip Technology Inc.

Page 7: 00988a

AN988

Figure 8 shows the flow diagram that describes thetemperature unit conversion.

FIGURE 8: Temperature Unit Conversion Flow Diagram.

The temperature data from the MCP9800 is checkedfor positive or negative reading. If the temperature isbelow 0°C, the reading is converted to the two'scompliment. Then, based on the position of the SW1switch, the unit-conversion is followed as shown above.

The SPI interface is used to transmit the temperaturedata to the 7-segment display driver PICmicro MCU(PIC16F72). This PICmicro MCU receives temperaturedata from the PICkit 1 Flash Starter Kit and displays iton the 7-segment display. The display requires refresh-ing, therefore, this MCU continuously displays thereceived temperature data. The flow diagram is shownin Figure 9.

FIGURE 9: Display Flow Diagram.

SIGN is positive

SIGN is negativeTwo's complement

TEMP

Multiply TEMP by 9

Divide TEMP by 5Add 32*256 to

TEMPSign-extend value

into third byteConvert to

Fahrenheit?

Y

N

TEMP MSb set?

N

Y

Initialization

Display RefreshReceive Display DIgits

Display Digits

© 2005 Microchip Technology Inc. DS00988A-page 7

Page 8: 00988a

AN988

The SPI interface routine protocol for the 7-segmentdisplay driver is designed to function as a generic toolto display any data. The protocol is described in the“MCP9800 Thermal Sensor PICtail™ Demo BoardUser’s Guide” (DS51528). The flow diagram inFigure 10 shows the firmware structure for the serialinterface.

FIGURE 10: Firmware Structure for the Serial Interface.

Is SIGN negative?

Send next digit as dash

Send next digit as 100's digit

Is 100's digit 0?

Is 10's digit 0?Send next digit as

10's digit

Send next digit as 1's digit with decimal point

Are we trying to send the first

digit?

Send next digit as blank

Are more digits available?

Are more digits available?

Send next digit as 10th's digit

Send next digit as 100th's digit

N

N

N

N

N N

Y

Y

Y

Y

Y Y

DS00988A-page 8 © 2005 Microchip Technology Inc.

Page 9: 00988a

AN988

CONCLUSION

The MCP9800 digital temperature sensor PICtail™daughter board demonstrates the ease of integrating adigital output IC temperature sensor to a PICmicro®

microcontroller. The MCP9800 is a CMOS silicon digitaltemperature sensor that provides many system-leveladvantages, including the integration of the sensor andthe signal-conditioning circuitry in a small IC package.This provides for easy system integration andminimizes the required PCB space, component countand design time.

BIBLIOGRAPHY

1. AN871 “Solving Thermal MeasurementProblems Using the MCP9800 and TC77 DigitalSilicon Temperature Sensors”, DS00871,Lepkowski, J., Microchip Technology Inc., 2003

2. “PICkit™ 1 Flash Starter Kit User’s Guide”,DS40051, Microchip Technology Inc, 2003

3. MCP9800 Data Sheet, “2-Wire AccuracyTemperature Sensor”, DS21909,Microchip Technology Inc., 2004

4. “MCP9800 Thermal Sensor PICtail™ DemoBoard User’s Guide”, DS51528, Microchip Technology Inc., 2005.

© 2005 Microchip Technology Inc. DS00988A-page 9

Page 10: 00988a

AN988

NOTES:

DS00988A-page 10 © 2005 Microchip Technology Inc.

Page 11: 00988a

Note the following details of the code protection feature on Microchip devices:

• Microchip products meet the specification contained in their particular Microchip Data Sheet.

• Microchip believes that its family of products is one of the most secure families of its kind on the market today, when used in the intended manner and under normal conditions.

• There are dishonest and possibly illegal methods used to breach the code protection feature. All of these methods, to our knowledge, require using the Microchip products in a manner outside the operating specifications contained in Microchip’s Data Sheets. Most likely, the person doing so is engaged in theft of intellectual property.

• Microchip is willing to work with the customer who is concerned about the integrity of their code.

• Neither Microchip nor any other semiconductor manufacturer can guarantee the security of their code. Code protection does not mean that we are guaranteeing the product as “unbreakable.”

Code protection is constantly evolving. We at Microchip are committed to continuously improving the code protection features of ourproducts. Attempts to break Microchip’s code protection feature may be a violation of the Digital Millennium Copyright Act. If such actsallow unauthorized access to your software or other copyrighted work, you may have a right to sue for relief under that Act.

Information contained in this publication regarding deviceapplications and the like is provided only for your convenienceand may be superseded by updates. It is your responsibility toensure that your application meets with your specifications.MICROCHIP MAKES NO REPRESENTATIONS OR WAR-RANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED,WRITTEN OR ORAL, STATUTORY OR OTHERWISE,RELATED TO THE INFORMATION, INCLUDING BUT NOTLIMITED TO ITS CONDITION, QUALITY, PERFORMANCE,MERCHANTABILITY OR FITNESS FOR PURPOSE.Microchip disclaims all liability arising from this information andits use. Use of Microchip’s products as critical components inlife support systems is not authorized except with expresswritten approval by Microchip. No licenses are conveyed,implicitly or otherwise, under any Microchip intellectual propertyrights.

© 2005 Microchip Technology Inc.

Trademarks

The Microchip name and logo, the Microchip logo, Accuron, dsPIC, KEELOQ, microID, MPLAB, PIC, PICmicro, PICSTART, PRO MATE, PowerSmart, rfPIC, and SmartShunt are registered trademarks of Microchip Technology Incorporated in the U.S.A. and other countries.

AmpLab, FilterLab, Migratable Memory, MXDEV, MXLAB, PICMASTER, SEEVAL, SmartSensor and The Embedded Control Solutions Company are registered trademarks of Microchip Technology Incorporated in the U.S.A.

Analog-for-the-Digital Age, Application Maestro, dsPICDEM, dsPICDEM.net, dsPICworks, ECAN, ECONOMONITOR, FanSense, FlexROM, fuzzyLAB, In-Circuit Serial Programming, ICSP, ICEPIC, Linear Active Thermistor, MPASM, MPLIB, MPLINK, MPSIM, PICkit, PICDEM, PICDEM.net, PICLAB, PICtail, PowerCal, PowerInfo, PowerMate, PowerTool, rfLAB, rfPICDEM, Select Mode, Smart Serial, SmartTel, Total Endurance and WiperLock are trademarks of Microchip Technology Incorporated in the U.S.A. and other countries.

SQTP is a service mark of Microchip Technology Incorporated in the U.S.A.

All other trademarks mentioned herein are property of their respective companies.

© 2005, Microchip Technology Incorporated, Printed in the U.S.A., All Rights Reserved.

Printed on recycled paper.

DS00988A-page 11

Microchip received ISO/TS-16949:2002 quality system certification for its worldwide headquarters, design and wafer fabrication facilities in Chandler and Tempe, Arizona and Mountain View, California in October 2003. The Company’s quality system processes and procedures are for its PICmicro® 8-bit MCUs, KEELOQ® code hopping devices, Serial EEPROMs, microperipherals, nonvolatile memory and analog products. In addition, Microchip’s quality system for the design and manufacture of development systems is ISO 9001:2000 certified.

Page 12: 00988a

DS00988A-page 12 © 2005 Microchip Technology Inc.

AMERICASCorporate Office2355 West Chandler Blvd.Chandler, AZ 85224-6199Tel: 480-792-7200 Fax: 480-792-7277Technical Support: http://support.microchip.comWeb Address: www.microchip.com

AtlantaAlpharetta, GA Tel: 770-640-0034 Fax: 770-640-0307

BostonWestborough, MA Tel: 774-760-0087 Fax: 774-760-0088

ChicagoItasca, IL Tel: 630-285-0071 Fax: 630-285-0075

DallasAddison, TX Tel: 972-818-7423 Fax: 972-818-2924

DetroitFarmington Hills, MI Tel: 248-538-2250Fax: 248-538-2260

KokomoKokomo, IN Tel: 765-864-8360Fax: 765-864-8387

Los AngelesMission Viejo, CA Tel: 949-462-9523 Fax: 949-462-9608

San JoseMountain View, CA Tel: 650-215-1444Fax: 650-961-0286

TorontoMississauga, Ontario, CanadaTel: 905-673-0699 Fax: 905-673-6509

ASIA/PACIFICAustralia - SydneyTel: 61-2-9868-6733 Fax: 61-2-9868-6755

China - BeijingTel: 86-10-8528-2100 Fax: 86-10-8528-2104

China - ChengduTel: 86-28-8676-6200 Fax: 86-28-8676-6599

China - FuzhouTel: 86-591-8750-3506 Fax: 86-591-8750-3521

China - Hong Kong SARTel: 852-2401-1200 Fax: 852-2401-3431

China - ShanghaiTel: 86-21-5407-5533 Fax: 86-21-5407-5066China - ShenyangTel: 86-24-2334-2829Fax: 86-24-2334-2393

China - ShenzhenTel: 86-755-8203-2660 Fax: 86-755-8203-1760

China - ShundeTel: 86-757-2839-5507 Fax: 86-757-2839-5571

China - QingdaoTel: 86-532-502-7355 Fax: 86-532-502-7205

ASIA/PACIFICIndia - BangaloreTel: 91-80-2229-0061 Fax: 91-80-2229-0062

India - New DelhiTel: 91-11-5160-8631Fax: 91-11-5160-8632

Japan - KanagawaTel: 81-45-471- 6166 Fax: 81-45-471-6122

Korea - SeoulTel: 82-2-554-7200 Fax: 82-2-558-5932 or 82-2-558-5934

Malaysia - PenangTel:011-604-646-8870Fax:011-604-646-5086

Philippines - ManilaTel: 011-632-634-9065Fax: 011-632-634-9069

SingaporeTel: 65-6334-8870 Fax: 65-6334-8850

Taiwan - KaohsiungTel: 886-7-536-4818Fax: 886-7-536-4803

Taiwan - TaipeiTel: 886-2-2500-6610 Fax: 886-2-2508-0102

Taiwan - HsinchuTel: 886-3-572-9526Fax: 886-3-572-6459

EUROPEAustria - WeisTel: 43-7242-2244-399Fax: 43-7242-2244-393Denmark - BallerupTel: 45-4450-2828 Fax: 45-4485-2829

France - MassyTel: 33-1-69-53-63-20 Fax: 33-1-69-30-90-79

Germany - IsmaningTel: 49-89-627-144-0 Fax: 49-89-627-144-44

Italy - Milan Tel: 39-0331-742611 Fax: 39-0331-466781

Netherlands - DrunenTel: 31-416-690399 Fax: 31-416-690340

England - BerkshireTel: 44-118-921-5869Fax: 44-118-921-5820

WORLDWIDE SALES AND SERVICE

04/20/05