AN940 PIC16F676 DS40051 AN871 DS00871 DS21743 ISO/TS-16949 11F-3 DK-2750 B505A - Datasheet Archive
Interfacing the TC72 SPITM Digital Temperature Sensor to a PICmicro® Microcontroller Author: Jim Lepkowski and Steve Bible
AN940 AN940 Interfacing the TC72 SPITM Digital Temperature Sensor to a PICmicro® Microcontroller Author: Jim Lepkowski and Steve Bible Microchip Technology Inc. INTRODUCTION The TC72 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 microcontroller. The TC72 sensor offers many system-level advantages, including the integration of the sensor and signalconditioning circuitry in a small integrated circuit (IC) package. The TC72 also has an One-shot Conversion mode, which 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 TC72 digital temperature sensor is especially suited for embedded systems due to its SPI interface, which serves to provide a straightforward and easy way to interface to a microcontroller. This application note will discuss system integration, firmware implementation and PCB layout techniques for using the TC72 in an embedded system. The techniques for integrating the TC72 into an embedded systems environment will be demonstrated by using the PICkitTM 1 FLASH Starter Kit and a TC72 PICtailTM daughter board. The TC72 PICtail daughter board plugs into the PICkit 1 FLASH Starter Kit expansion header J3, as shown in Figure 1. The TC72 demonstration is designed to measure and display temperature in binary coded decimal (BCD) with the PICkit 1 LEDs. Gerber files for the printed circuit board (PCB), source code and hex file to program a PIC16F676 PIC16F676 are included in the companion zip file, 00940.zip. PICkitTM 1 FLASH Starter Kit TC72 Temperature Sensor PICmicro® FLASH MCU Personal Computer J3 USB P1 4 SPITM Interface VDD GND SPITM Interface +5V TC72 PICtailTM Daughter Board LED Array Tens Digit D7 D6 D5 D4 Ones Digit D3 D2 D1 D0 Temperature Data FIGURE 1: Block Diagram of the TC72 Digital Temperature Sensor Demonstration. 2004 Microchip Technology Inc. DS00940A-page 1 AN940 AN940 TC72 FUNCTIONAL DESCRIPTION Temperature Data Format The TC72 consists of an internal diode temperature sensor, a 10-bit sigma delta analog-to-digital converter (ADC), digital registers and a SPI communication port. Figure 2 provides a simplified block diagram of the TC72. A schematic of the TC72 to PICmicro® MCU interface is shown in Figure 3. Temperature data is represented by a 10-bit two's complement word with a resolution of 0.25°C per bit. The temperature data is stored in the temperature registers in a two's complement format, as shown in Table 1. Example: Temperature = Manufacturer ID Register = 10000000b = 2-1 0.5 TABLE 1: TEMPERATURE REGISTER Address/ Register D7 Serial Port Interface CE SCK SDO SDI GND Control Register TC72 Block Diagram. D6 D5 D4 D3 D2 D1 D0 Sign 26 25 24 23 23 21 20 02H Temp. MSB 2-1 2-2 0 0 0 0 0 0 01H Temp. LSB Power-Up And Power-Down The TC72 is in the low-power consumption Shutdown mode at power-up. The Continuous Temperature Conversion mode is selected by performing a write operation to the control register. Serial Bus Interface VDD The serial interface consists of the Chip Enable (CE), Serial Clock (SCK), Serial Data Input (SDI) and Serial Data Output (SDO) signals. The serial interface is compatible with the SPI bus specification. 0.1 µF VDD PICmicro® MCU CE RA0 SCK SCK SDO SDI SDI SDO GND DS00940A-page 2 32 + 8 + 1 = 41 LSB Temperature Register Temperature Register FIGURE 3: Interface. 25 + 23 + 20 TC72 10-Bit Sigma Delta A/D Converter TC72 00101001b = FIGURE 2: 41.5°C = = Internal Diode Temperature Sensor = MSB Temperature Register VDD TC72 to PICmicro® MCU The CE input is used to select the TC72 when multiple devices are connected to the serial clock and data lines. The CE is active-high, and data is written to (or read from) the device when CE is equal to a logic-high voltage. The SCK input is disabled when CE is low. The rising edge of the CE line initiates a read or write operation, while the falling edge of CE completes a read or write operation. The SCK input is provided by the external microcontroller and is used to synchronize the data on the SDI and SDO lines. The SDI input writes data into the TC72's control register, while the SDO outputs the temperature data from the temperature register and the status of the shutdown bit of the control register. The TC72 has the capability to function with either an active-high or active-low SCK input. The software developed in this demo uses an active-high SCK signal (CP=0). Each data bit is transferred at each clock pulse, with the data bits being clocked in groups of eight bits, as shown in Figure 4. 2004 Microchip Technology Inc. AN940 AN940 The address byte is transferred first, followed by the data. A7, the MSb of the address, determines whether a read or write operation will occur. If A7 = `0', one or more read cycles will occur. Otherwise, if A7 = `1', one or more write cycles will occur. Data can be transferred either in a single byte or a multi-byte packet, as shown in Figure 4. In the 3-byte packet, the data sequence consists of the MSb and LSb temperature data, followed by the control register data. The multi-byte read feature is initiated by writing the highest address of the desired packet to registers. The TC72 will automatically send the register addressed and all of the lower address registers, as long as the Chip Enable pin is held active. Read Operation The temperature and control register data is outputted from the TC72 using the CE, SCK and SDO lines. Figure 4 shows a timing diagram of the read operation. Communication is initiated by the chip enable (CE) going high. The SDO line remains at the voltage level of the LSb bit that is outputted and goes to the tri-state level when the CE line goes to a logic-low level. Write Operation Data is clocked into the control register in order to enable the TC72's power-saving Shutdown mode. The write operation is shown in Figure 4 and is accomplished using the CE, SCK and SDI lines. 2004 Microchip Technology Inc. DS00940A-page 3 AN940 AN940 Single Byte Write Operation (CP=0, data shifted on rising edge of SCK, data clocked on falling edge of SCK, A7=1) CE SCK 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 A7=1 A 7 SDI A 6 A 5 A 4 A 3 A 2 A 1 A 0 D 7 D 6 D 5 D 4 D 3 D 2 D 1 MSb SDO D 0 LSb High Z Single Byte Read Operation (CP=0, data shifted on rising edge of SCK, data clocked on falling edge of SCK, A7=0) CE SCK 2 1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 A7=0 A 7 SDI A 6 A 5 A 4 A 3 SDO A 2 A 1 A 0 High Z D 7 D 0 MSb High Z LSb SPITM Multiple Byte Transfer CE SCK Write Operation (CP=0, data shifted on rising edge of SCK, data clocked on falling edge of SCK, A7=1) SDI Address Byte = 80hex A7 A0 Control Byte D7 D0 High Z SDO Read Operation (CP=0, data shifted on rising edge of SCK, data clocked on falling edge of SCK, A7=0) SDI Address Byte = 02hex A0 A7 SDO High Z FIGURE 4: DS00940A-page 4 MSB Temp. Byte D7 Control Byte LSB Temp. Byte D0 D7 D0 D7 D0 High Z Serial Interface Timing Diagrams (CP=0). 2004 Microchip Technology Inc. AN940 AN940 Internal Register Structure The TC72 registers are listed in Table 2. TABLE 2: REGISTERS FOR TC72 Read Address Control Write Address Bit 7 Bit 6 Bit 5 Bit 4 00hex Register 80hex 0 0 0 One-shot (OS) Bit Bit Bit 3 2 1 0 1 0 0 0 Bit 0 Value on POR/BOR Shutdown (SHDN) 05hex 0 LSB Temperature 01hex N/A T1 T0 0 0 0 00hex MSB Temperature 02hex N/A T9 T8 T7 T6 T5 T4 T3 T2 00hex Manufacturer ID 03hex N/A 0 1 0 1 0 0 54hex Control Register The control register is both a read and write register that is used to select either the Shutdown, Continuous Temperature Conversion or One-shot Conversion mode. The Continuous Temperature Conversion mode selection logic is shown in Table 3. The Continuous Temperature Conversion mode is selected by writing a `0' to the SHDN bit of the control register. The Continuous Temperature Conversion mode measures the temperature approximately every 150 ms and stores the data in the temperature registers. The automatic temperature-sampling operation is repeated indefinitely until the TC72 is placed in Shutdown mode by a write operation to the control register. The TC72 will remain in the Shutdown mode until the shutdown bit in the control register is reset. One-shot Conversion mode performs a single temperature measurement and returns to the power-saving Shutdown mode. This mode is especially useful for low-power applications. One-shot Conversion mode is selected by writing a `1' into bit 4 of the control register. Upon completion of the temperature conversion, the One-shot bit (OS) is reset to `0' (i.e., "off"). The user must set the One-shot bit to `1' to initiate another temperature conversion. TABLE 3: 1 0 Shutdown mode can be used to minimize the power consumption of the TC72 when active temperature monitoring is not required. Shutdown mode disables the temperature-conversion circuitry. However, the serial I/O communication port remains active. The shutdown (SHDN) bit is stored in bit 0 of the control register. If SHDN is equal to `1', the TC72 will go into the powersaving Shutdown mode. Temperature Register The temperature register is a read-only and contains a 10-bit two's complement representation of the temperature measurement. Bit 0 through bit 5 of the LSB temperature register are always set to a logic `0'. Manufacturer ID Register The manufacturer identification (ID) register is a readonly register used to identify the temperature sensor as a Microchip component. CONTROL REGISTER TEMPERATURE CONVERSION MODE SELECTION Operational Mode One-shot (OS) Bit 4 Shutdown (SHDN) Bit 0 Continuous Temperature Conversion 0 0 Shutdown 0 1 Continuous Temperature Conversion (One-shot Command is ignored if SHDN = `0') 1 0 One-shot 1 1 2004 Microchip Technology Inc. DS00940A-page 5 AN940 AN940 APPLICATIONS INFORMATION the relatively small current consumption of the TC72. A temperature accuracy error will result from self-heating if the SPI communication pins sink/source the maximum current specified for the TC72. Thus to maximize the temperature accuracy, the output loading of the SPI signals should be minimized. The TC72 does not require any additional components in order to measure temperature, though it is recommended that a decoupling capacitor of 0.1 µF to 1 µF be provided between the VDD and GND pins. A highfrequency ceramic capacitor should be used. The capacitor should be located as close as possible to the IC power pins in order to provide effective noise protection to the sensor. TC72 PICtailTM DAUGHTER BOARD The TC72 PICtail daughter board is plugged to the PICkit 1 FLASH Starter kit via expansion header J3. Figure 5 shows the TC72 PICtail daughter board plugged into the PICkit 1 FLASH Starter Kit. For more information on the PICkit 1 FLASH Starter Kit, refer to the "PICkitTM 1 FLASH Starter Kit User's Guide", DS40051 DS40051. The TC72 measures temperature by monitoring the voltage of a diode located on the IC die. The IC pins of the TC72 provide a low-impedance thermal path between the die and the PCB, allowing the TC72 to effectively monitor the temperature of the PCB board. The thermal path between the ambient air is not as efficient because the plastic IC housing package functions as a thermal insulator. Thus the ambient air temperature (assuming that a large temperature gradient exists between the air and PCB) has only a small effect on the temperature measured by the TC72. The TC72 PICtail daughter board consists of a TC72 temperature sensor and a bypass capacitor. The bypass capacitor C1 is used to provide noise immunity on the +5 VDC power supply. Figure 6 shows a schematic of the board, while Figure 7 provides a layout drawing of the PCB. A potential for self-heating errors can exist if the TC72 SPI interface communication lines are heavily loaded. Typically, the self-heating error is negligible because of Expansion Header (J3) U1 TC72 PICtailTM Daughter Board USB Cable LED D7 LED D0 Insert PIC16F676 PIC16F676 PICkitTM 1 FLASH Starter Kit FIGURE 5: TC72 PICtailTM Daughter Board and PICkitTM 1 FLASH Starter Kit. DS00940A-page 6 2004 Microchip Technology Inc. AN940 AN940 PICkitTM 1 FLASH Starter Kit +5V J3 13 TC72 PICtailTM Daughter Board P1 13 C1 0.1µF 8 VDD TC72 (MSOP-8) 2 CE 6 6 10 10 3 12 12 6 11 11 RC3 RC0 RC2 RC1 14 5 14 GND FIGURE 6: U1 SDI SDO GND 4 TC72 PICtailTM Daughter Board Schematic. Top Layer FIGURE 7: SCK Silk-screen Layer Bottom Layer TC72 PICtailTM Daughter Board PCB Layout. 2004 Microchip Technology Inc. DS00940A-page 7 AN940 AN940 TC72 Interface Software A flow diagram for the PICkit 1 software is given in Figure 8A. The TC72 thermal sensor is read by the PICmicro MCU. The value read from the TC72 is rightadjusted in the register as a 10-bit temperature value in degrees Celsius. The temperature value is tested for a negative temperature reading by checking the status of Bit 7 of the MSB of the temperature register. If the value is negative (T < 0°C), the state is saved in a flag bit and the value is two's complemented. The TC72's temperature register provides a temperature measurement in Celsius. An option in the software is provided to display the temperature in either Fahrenheit or Celsius by testing the status of the PICkit 1 SW1 push button switch. If SW1 is not pressed, the temperature value is converted to Fahrenheit. Otherwise, if the push button is pressed, the conversion routine is skipped and the data is displayed in Celsius. Finally, the temperature value is loaded into the LEDREG variable to be displayed on the LEDs by the DISPLAY subroutine. Fully-documented source code and a hex file ready to program into a PIC16F676 PIC16F676 is available in the companion zip file, 00940.zip. DS00940A-page 8 2004 Microchip Technology Inc. AN940 AN940 START Initialize PICmicro® MCU Right-Adjust TC72 Temperature Value Initialize Variables If temperature is negative, set sign_bit flag and 2's complement value C Tick Counter Expired? NO YES Is SW1 Pressed? Read Temperature from TC72 NO YES Multiply Temperature by 9 B Divide Results by 5 A FIGURE 8A: TC72 PICtailTM Program Flow Diagram. 2004 Microchip Technology Inc. DS00940A-page 9 AN940 AN940 ) A Add 32 B Round result to an integer Convert value to BCD Place value in LEDREG C FIGURE 8B: DS00940A-page 10 TC72 PICtailTM Flow Diagram (Cont.) 2004 Microchip Technology Inc. AN940 AN940 CONCLUSION BIBLIOGRAPHY The TC72 digital temperature sensor PICtailTM daughter board demonstrates the ease of integrating a digital output IC temperature sensor to a PICmicro® microcontroller. The TC72 is a CMOS silicon digital temperature sensor that provides many system level advantages, including the integration of the sensor and the signal conditioning circuitry in a small IC package. This provides for easy system integration and minimizes the required PCB space, component count and design time. 1. 2004 Microchip Technology Inc. 2. 3. AN871 AN871 - "Solving Thermal Measurement Problems Using the TC72 and TC77 Digital Silicon Temperature Sensors", DS00871 DS00871, Lepkowski, J., Microchip Technology Inc. PICkitTM 1 FLASH Starter Kit User's Guide, DS40051 DS40051, Microchip Technology Inc. TC72 Data Sheet, "Digital Temperature Sensor with SPITM Interface", DS21743 DS21743, Microchip Technology Inc. DS00940A-page 11 AN940 AN940 NOTES: DS00940A-page 12 2004 Microchip Technology Inc. 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 our products. Attempts to break Microchip's code protection feature may be a violation of the Digital Millennium Copyright Act. If such acts allow 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 device applications and the like is intended through suggestion only and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. No representation or warranty is given and no liability is assumed by Microchip Technology Incorporated with respect to the accuracy or use of such information, or infringement of patents or other intellectual property rights arising from such use or otherwise. Use of Microchip's products as critical components in life support systems is not authorized except with express written approval by Microchip. No licenses are conveyed, implicitly or otherwise, under any intellectual property rights. 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, 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, Migratable Memory, MPASM, MPLIB, MPLINK, MPSIM, PICkit, PICDEM, PICDEM.net, PICLAB, PICtail, PowerCal, PowerInfo, PowerMate, PowerTool, rfLAB, rfPICDEM, Select Mode, Smart Serial, SmartTel and Total Endurance 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. © 2004, Microchip Technology Incorporated, Printed in the U.S.A., All Rights Reserved. Printed on recycled paper. Microchip received ISO/TS-16949 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. 2004 Microchip Technology Inc. DS00940A-page 13 WORLDWIDE SALES AND SERVICE AMERICAS China - Beijing Korea Corporate Office Unit 706B Wan Tai Bei Hai Bldg. No. 6 Chaoyangmen Bei Str. Beijing, 100027, China Tel: 86-10-85282100 Fax: 86-10-85282104 168-1, Youngbo Bldg. 3 Floor Samsung-Dong, Kangnam-Ku Seoul, Korea 135-882 Tel: 82-2-554-7200 Fax: 82-2-558-5932 or 82-2-558-5934 China - Chengdu 200 Middle Road #07-02 Prime Centre Singapore, 188980 Tel: 65-6334-8870 Fax: 65-6334-8850 2355 West Chandler Blvd. Chandler, AZ 85224-6199 Tel: 480-792-7200 Fax: 480-792-7277 Technical Support: 480-792-7627 Web Address: www.microchip.com 3780 Mansell Road, Suite 130 Alpharetta, GA 30022 Tel: 770-640-0034 Fax: 770-640-0307 Rm. 2401-2402, 24th Floor, Ming Xing Financial Tower No. 88 TIDU Street Chengdu 610016, China Tel: 86-28-86766200 Fax: 86-28-86766599 Boston China - Fuzhou 2 Lan Drive, Suite 120 Westford, MA 01886 Tel: 978-692-3848 Fax: 978-692-3821 Unit 28F, World Trade Plaza No. 71 Wusi Road Fuzhou 350001, China Tel: 86-591-7503506 Fax: 86-591-7503521 Atlanta Chicago 333 Pierce Road, Suite 180 Itasca, IL 60143 Tel: 630-285-0071 Fax: 630-285-0075 Dallas 4570 Westgrove Drive, Suite 160 Addison, TX 75001 Tel: 972-818-7423 Fax: 972-818-2924 Detroit Tri-Atria Office Building 32255 Northwestern Highway, Suite 190 Farmington Hills, MI 48334 Tel: 248-538-2250 Fax: 248-538-2260 Kokomo 2767 S. Albright Road Kokomo, IN 46902 Tel: 765-864-8360 Fax: 765-864-8387 Los Angeles 18201 Von Karman, Suite 1090 Irvine, CA 92612 Tel: 949-263-1888 Fax: 949-263-1338 San Jose 1300 Terra Bella Avenue Mountain View, CA 94043 Tel: 650-215-1444 Fax: 650-961-0286 Toronto 6285 Northam Drive, Suite 108 Mississauga, Ontario L4V 1X5, Canada Tel: 905-673-0699 Fax: 905-673-6509 ASIA/PACIFIC Australia Suite 22, 41 Rawson Street Epping 2121, NSW Australia Tel: 61-2-9868-6733 Fax: 61-2-9868-6755 China - Hong Kong SAR Unit 901-6, Tower 2, Metroplaza 223 Hing Fong Road Kwai Fong, N.T., Hong Kong Tel: 852-2401-1200 Fax: 852-2401-3431 Singapore Taiwan Kaohsiung Branch 30F - 1 No. 8 Min Chuan 2nd Road Kaohsiung 806, Taiwan Tel: 886-7-536-4818 Fax: 886-7-536-4803 Taiwan Taiwan Branch 11F-3 11F-3, No. 207 Tung Hua North Road Taipei, 105, Taiwan Tel: 886-2-2717-7175 Fax: 886-2-2545-0139 EUROPE China - Shanghai Austria Room 701, Bldg. B Far East International Plaza No. 317 Xian Xia Road Shanghai, 200051 Tel: 86-21-6275-5700 Fax: 86-21-6275-5060 Durisolstrasse 2 A-4600 Wels Austria Tel: 43-7242-2244-399 Fax: 43-7242-2244-393 Denmark China - Shenzhen Regus Business Centre Lautrup hoj 1-3 Ballerup DK-2750 DK-2750 Denmark Tel: 45-4420-9895 Fax: 45-4420-9910 Rm. 1812, 18/F, Building A, United Plaza No. 5022 Binhe Road, Futian District Shenzhen 518033, China Tel: 86-755-82901380 Fax: 86-755-8295-1393 China - Shunde Room 401, Hongjian Building, No. 2 Fengxiangnan Road, Ronggui Town, Shunde District, Foshan City, Guangdong 528303, China Tel: 86-757-28395507 Fax: 86-757-28395571 China - Qingdao Rm. B505A B505A, Fullhope Plaza, No. 12 Hong Kong Central Rd. Qingdao 266071, China Tel: 86-532-5027355 Fax: 86-532-5027205 India Divyasree Chambers 1 Floor, Wing A (A3/A4) No. 11, O'Shaugnessey Road Bangalore, 560 025, India Tel: 91-80-22290061 Fax: 91-80-22290062 Japan Benex S-1 6F 3-18-20, Shinyokohama Kohoku-Ku, Yokohama-shi Kanagawa, 222-0033, Japan Tel: 81-45-471- 6166 Fax: 81-45-471-6122 France Parc d'Activite du Moulin de Massy 43 Rue du Saule Trapu Batiment A - ler Etage 91300 Massy, France Tel: 33-1-69-53-63-20 Fax: 33-1-69-30-90-79 Germany Steinheilstrasse 10 D-85737 D-85737 Ismaning, Germany Tel: 49-89-627-144-0 Fax: 49-89-627-144-44 Italy Via Quasimodo, 12 20025 Legnano (MI) Milan, Italy Tel: 39-0331-742611 Fax: 39-0331-466781 Netherlands Waegenburghtplein 4 NL-5152 NL-5152 JR, Drunen, Netherlands Tel: 31-416-690399 Fax: 31-416-690340 United Kingdom 505 Eskdale Road Winnersh Triangle Wokingham Berkshire, England RG41 5TU Tel: 44-118-921-5869 Fax: 44-118-921-5820 05/28/04 DS00940A-page 14 2004 Microchip Technology Inc.