AN1333 Use and Calibration of the Internal Temperature Indicator Author: USING THE TEMPERATURE INDICATOR Jonathan Dillon Microchip Technology Inc. INTRODUCTION Many PIC16 family devices include an internal temperature indicator. These devices include the PIC16F72X device family, PIC16F1XXX device family, and the PIC12F1XXX device family. The temperature indicator is internally connected to the input multiplexer of the ADC (Figure 1). Refer to the specific device data sheet for more details. FIGURE 1: TEMPERATURE INDICATOR VDD Enable Mode Temperature Indicator VDD ADC These devices incorporate an internal circuit which produces a variable output voltage with temperature using internal transistor junction threshold voltages. The indicator can be used to measure the device temperature between -40°C and +85°C. The circuit must be calibrated by the user to provide accurate results, as the equation coefficients will vary between devices. FIGURE 2: The control bits for enabling the temperature indicator and selecting its mode of operation should be detailed in the device’s data sheet in the temperature indicator chapter. The indicator uses the temperature coefficient of a transistor junction threshold voltage (Vt) to produce a voltage which is temperature dependent. The High-Range mode increases the number of junctions which gives a greater response to temperature changes. The Low-Range mode uses fewer junctions, which allows use of the temperature indicating circuit over a wider device operating voltage range (see Figure 3). The variation in Vt with temperature, measured on a single sample device, was found to be: EQUATION 1: Vt VOLTAGE VS. TEMPERATURE V t = 0.659 – Temperature C + 40 * (0.00132) EXAMPLE DATA ON DIODE FORWARD VOLTAGE VS. TEMPERATURE OBSERVED WITH A SINGLE SAMPLE PIC16F1937 DEVICE 2010-2013 Microchip Technology Inc. DS00001333B-page 1 AN1333 FIGURE 3: VDD VDD Vt Vt Vt Vt Vt VDD VDD Vt n ADC Vtemp Vtemp Operation above 3.6V Operation below 3.6V The output equations for the two modes of operation: • Low range Vtemp = VDD – 2*Vt • High range Vtemp = VDD – 4*Vt Where: Vtemp is the analog voltage output by the indicator The ADC’s transfer function can be found in Equation 2. The conversion result is dependent on the supply voltage to the Analog-to-Digital Converter’s voltage reference and, for this document, the positive reference is the supply voltage, while the negative reference is the ground. EQUATION 2: V temp n ADC Result = -------------- * (2 – 1 V DD VDD is the positive voltage supplied to the device Vt is the threshold voltage for the transistors which is dependent on the device fabrication process Using Equation 1 with the operational modes of the indicator we have Equation 3. Care needs to be taken in selecting a mode, since Vt may be as high as 0.75V at low temperatures, while the minimum VDD of some devices can be as low as 1.8V. For low-voltage operation, the low range is necessary, as Vtemp can only be a positive voltage. High mode is the preferred mode of operation when the supply voltage allows its use due to its greater temperature response increasing the temperature resolution. Low Mode Vtemp = VDD - 2Vt Vtemp = VDD - 4Vt Note: VSS VSS High Mode n ADC Where: n = number of bits of ADC resolution (8 or 10 bits) During operation, the supply voltage can be determined by performing an Analog-to-Digital conversion of the Fixed Voltage Reference. However, if VDD is regulated or an external reference is connected to the ADC, the calculations can be simplified, since it can be assumed to be constant. The voltage, Vtemp, is measured using the internal Analog-to-Digital Converter (ADC) and is internally connected to the analog channel select MUX. Refer to the ADC chapter of the device data sheet to determine the input channel. The mode selection and temperature indicator enable are documented in the temperature indicator chapter of the data sheet. When selecting the temperature indicator of the channel select MUX, sufficient time must be allowed for the ADC to acquire the voltage before conversion is started. DS00001333B-page 2 2010-2013 Microchip Technology Inc. AN1333 EQUATION 3: VTEMP VOLTAGE FROM SERIES OF SAMPLED DIODES AS GIVEN IN Equation 1 V temp = V DD – mode * [0.659 – Temperature C + 40 * 0.00132 Where: High-Range mode = 4 Low-Range mode = 2 Combining Equation 2 and Equation 3 to relate the ADC conversion of the temperature indicator circuit’s output voltage to the temperature: EQUATION 4: RE-ARRANGING TO CALCULATE ADC RESULT USING EXAMPLE COEFFICIENTS: V DD – mode * [0.659 – Temperature C + 40 * 0.00132 n ADC Result = ------------------------------------------------------------------------------------------------------------------------------------------------------------- * (2 – 1 V DD EQUATION 5: RE-ARRANGING EQUATION 4 TO CALCULATE TEMPERATURE ADC Result V DD 0.659 – -------------- 1 – -------------------------- n mode (2 – 1 Temperature C = ---------------------------------------------------------------------------- – 40 0.00132 Note: Equation 5 uses example coefficients determined from a sample device. See Calibration section for how to calculate these coefficients for your device. As the temperature varies, the ADC result of conversion of the temperature indicator channel will change linearly as seen in Figure 4, provided the supply voltage does not change. Depending on the application, the Analog-to-Digital Converter result can be either compared directly against specific trip points, or used to determine the actual temperature by calculation, a look-up table or a combination of both. 2010-2013 Microchip Technology Inc. DS00001333B-page 3 AN1333 FIGURE 4: EXAMPLE OF ADC RESULT (DECIMAL) VS. TEMPERATURE (REGULATED SUPPLY VOLTAGE) FOR A CALIBRATED DEVICE (°C) DS00001333B-page 4 2010-2013 Microchip Technology Inc. AN1333 CALIBRATION The temperature indicator requires calibration to achieve greater accuracy due to variations in offset and in slope between devices. The indicator is dependent on the device’s transistor voltage threshold, Vt, which will vary within production allowances. Calibration of the temperature indicator can be performed during production of the target application by two methods: allow the device to reach temperature. Errors in the forced temperature or measured temperature will result in reduced temperature accuracy at all temperatures. The degree of calibration required is dependent on the application, where some applications do not require precise temperature, thus single-point calibration is suitable and faster to perform. It also avoids requiring equipment to vary temperature. For more accurate temperature measurements, the two-point calibration method is recommended. SINGLE-POINT CALIBRATION Calibration is performed at a single temperature and the variation of slope is assumed to be relatively stable between devices. This method calibrates purely for the offset, which typically has greater variation between devices. TWO-POINT CALIBRATION Calibration is performed at two temperatures from which we can determine the offset and slope. As a result, this method is more accurate, but requires two distinctively different temperatures. Note: The voltage from the temperature indicator is dependent on the supply voltage to the device, which makes calibration easiest when the voltage is regulated. For unregulated supplies the voltage must also be calculated from an A/D conversion of the internal Fixed Voltage Reference. The techniques of using a Fixed Voltage Reference to determine VDD can be found in application note AN1072, “Measuring VDD Using the 0.6V Reference.” For both of the above methods, the temperatures can be either forced (held to a specific value) or measured at calibration time via an external measurement. Forced temperatures simplify the calculations required during calibration, but are more difficult from a production view point and time may be required to TEMPERATURE DATA FROM 12 SAMPLE DEVICES ADC result FIGURE 5: Temperature 2010-2013 Microchip Technology Inc. DS00001333B-page 5 AN1333 SINGLE-POINT CALIBRATION Testing of a limited number of sample devices as seen in Figure 5 shows a relatively constant response in Vtemp with changes in temperature, however, there is a greater variation in offsets between devices. Single-point calibration corrects for this variation in offset, but does not allow for the variation in temperature response slope between devices. For this calibration, we need to have an ideal ADC result value for either our forced temperature or otherwise at the measured temperature. The change in Vt by temperature varies between devices and, as a result, single-point calibration may only be accurate at the calibration temperature, and error will increase as it moves further from the calibration temperature (see Figure 6). The bow tie shape of the plotted ADC results due to the possible variation in temperature response. If the temperature is measured, the calculation required to get the ideal ADC result value is given in Equation 3, otherwise, for forced temperatures, the result can be compared to a constant ideal result for that temperature. Ideally, the temperature is in the middle of the operating range seen by the application, as this centers the bow tie and minimizes temperature error over the applications operating range. For applications which only need to know a certain temperature, such as a temperature limit, the best accuracy results can be achieved by calibrating at that temperature. Consequently, for this device the calibration value would be 7. Store this in the nonvolatile program or data EEPROM memory within the device for use when taking temperature measurements. Single-point calibration assumes that all devices have a similar slope, however, as the temperature moves further from the calibration temperature, the greater the potential error as seen in Figure 6. When taking measurements, the ADC result is modified by the calibration value to adjust for the offset. EQUATION 7: Calibrated result = ADC result – calibration value EQUATION 8: Temperature = (ADC result – calibration value)K The ADC conversion results may have a dynamic range approaching 8 bits for some combinations of mode and voltage and, as a result, it is recommended to maintain the two-byte ADC result data type. For higher voltage operation, the dynamic range of the ADC result between -40°C to +85°C is small enough that it could be scaled down to an 8-bit number. With a sample PIC16F1937 device under the following conditions: • powered at 5V • high-range 4Vt operation • 25°C forced temperature The Analog-to-Digital conversion gives a result of 561 decimal. Typical A/D conversion result at 25°C is calculated as 554 decimal using Equation 3. For single-point calibration, the difference between the conversion result and the ideal A/D conversion result value is the calibration value. Thus: EQUATION 6: Ideal – measured = calibration value 554 – 561 = 7 DS00001333B-page 6 2010-2013 Microchip Technology Inc. AN1333 FIGURE 6: SINGLE TEMPERATURE CALIBRATION Typical Max Slope Min Slope Calibration Temperature TWO-POINT CALIBRATION Two-point calibration measures the temperature responsivity of that device, as well as the offset. As a result, it offers increased temperature accuracy by overcoming the assumption of single-point calibration, that all devices have the same temperature response. FIGURE 7: Two-point calibration requires two distinctively different temperatures across the applications temperature range. As with single-point calibration, these temperatures can either be forced or measured, though forced temperatures again simplify the required calculations. TWO-POINT CALIBRATION (°C) For unregulated supply voltages, designers must calculate the temperature responsivity of the diode, which requires additional steps. EQUATION 9: ADC Result calibrated = A + (B * ADC Result) 2010-2013 Microchip Technology Inc. Calibration is required to determine A and B, which modifies the ADC result for the variation in diode Vt and temperature response. The ideal ADC result for each calibration temperature can be stored as a constant if the temperature is forced to known levels, otherwise the ideal must be calculated if it is measured externally during calibration. The calibrated result can then be used in Equation 5 to calculate the temperature. DS00001333B-page 7 AN1333 EQUATION 10: A = (Ideal @ T1 – Ideal @ T2)/(Actual @ T1 – Actual @ T2) B = Actual @ T1 - (A * Ideal @ T1) Where: T1 calibration temperature 1 T2 calibration temperature 2 This two-point calibration significantly reduces the effect of variations in temperature response of the diodes, but is dependent on being able to accurately calculate the responsivity. SINGLE-POINT CALIBRATION FOR UNREGULATED VOLTAGES For regulated voltages, the calibration can be simplified down to an adjustment to the ADC result. For unregulated supplies, the calibration is also a function of VDD causing a change in the ADC result, and the Vt temperature offset must be calculated. This requires that VDD be known along with the calibration temperature and ADC result. From Equation 3, substituting for the Vt offset: The Vt offset can be calculated by performing a single ADC conversion at a known temperature and voltage. For unregulated applications, the supply voltage can be determined from a conversion of the internal Fixed Voltage Reference or by supplying a known voltage during calibration. When measuring the temperature the supply voltage must also be calculated and the Vt offset from the calibration used. During calibration, is calculated and stored in nonvolatile memory for use during operation. The results of the A/D conversion are inserted into Equation 11 along with the supply voltage to give the operating temperature. EQUATION 11: ADCResult V DD – ---------- * 1 – --------------------------- 4 1023 Temperature = ----------------------------------------------------------------- – 40 0.00132 EQUATION 12: V DD – 4 * [ – Temperature C + 40 * 0.0132 ADCResult = -------------------------------------------------------------------------------------------------------------------------------------- * 1023 V DD Re-arranging: EQUATION 13: V DD ADC Result = ---------- * 1 – --------------------------+ Temperature C + 40 * 0.00132 4 1023 TWO-POINT CALIBRATION FOR UNREGULATED VOLTAGES For unregulated supply, such as direct connection to a battery, we need to calculate VDD once or twice, if it varies between the two calibration temperatures, such as reduced battery voltage with temperatures. From the operation of the temperature indicator we have the following: EQUATION 14: Vtemp = V DD – 4 * – Temperature C + 40 V temp n ADC Result = -------------- * (2 – 1 V DD ADC Result V temp = --------------------------- * V DD 1023 DS00001333B-page 8 Where, for two-point calibration with an unregulated voltage, we need to calculate alpha () and beta (). Re-arranging the equations and calibrating at two temperatures (Equation 15): Key points to consider: • The results are most accurate between the calibration temperatures. • The calibration temperatures need to be suitably far apart to allow an accurate calculation of the slope given the ADC resolution. Calibration temperatures around 20% and 80% of the operating temperature range are recommended. • Any error in calibration temperature or voltage significantly increases the error of the readings due to the inaccurate slope and offset. • Regulated voltage, calibration performed at 20°C and 60°C. 2010-2013 Microchip Technology Inc. AN1333 Temperature error will be minimized at the calibration temperatures as shown Figure 8 for a sample batch of devices, where the maximum temperature error between the calibration temperatures is 5°C. EQUATION 15: ADC Result1 ADC Result2 V 1 * Temp 2 + 40 * 1 – ----------------------------- – V 2 * Temp 1 + 40 * 1 – ----------------------------- 1023 1023 = --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------4 * Temp2 – Temp 1 1 V 1 – V2 + ------------ * V 2 * ADC Result2 – V 1 * ADC Result1 1023 = ---------------------------------------------------------------------------------------------------------------------------------------------4 * Temp 2 – Temp 1 Where: Temp1, Temp2 calibration temperatures V1, V2 VDD voltage at Temp1 and Temp2 ADCresult1, ADCresult2 A/D Convertor result at Temp1 and Temp2 EQUATION 16: ADC Result V DD – ---------- * 1 – --------------------------- 4 1023 Temperature C = ----------------------------------------------------------------- – 40 FIGURE 8: ABS TEMPERATURE ERROR Abs temp error 12 Absolute Error °C 10 8 C ° r o rr E 6 e t u l o s b 4 A 2 0 -40 -30 -20 -10 0 2010-2013 Microchip Technology Inc. 10 20 25 30 40 Temperature (°C) 50 60 70 80 85 DS00001333B-page 9 AN1333 CONCLUSION The on-board temperature indicator can be used to measure the device temperature, which will correspond to the temperature in its environment with some delay. The indicator is measured using the ADC and can be used uncalibrated for coarse temperature measurements. For more precise temperature measurements, calibration is required to account for device parameter variation. Depending on the application, calibration measurements at one or two temperatures may be required. Since the ADC results are dependent on its provided references, the fixed references need to be supplied either by using the on-board fixed references, or by using a regulated supply. Otherwise, the device supply voltage must be calculated using the Fixed Voltage Reference. DS00001333B-page 10 2010-2013 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 provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer’s risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights. Trademarks The Microchip name and logo, the Microchip logo, dsPIC, FlashFlex, KEELOQ, KEELOQ logo, MPLAB, PIC, PICmicro, PICSTART, PIC32 logo, rfPIC, SST, SST Logo, SuperFlash and UNI/O are registered trademarks of Microchip Technology Incorporated in the U.S.A. and other countries. FilterLab, Hampshire, HI-TECH C, Linear Active Thermistor, MTP, SEEVAL and The Embedded Control Solutions Company are registered trademarks of Microchip Technology Incorporated in the U.S.A. Silicon Storage Technology is a registered trademark of Microchip Technology Inc. in other countries. Analog-for-the-Digital Age, Application Maestro, BodyCom, chipKIT, chipKIT logo, CodeGuard, dsPICDEM, dsPICDEM.net, dsPICworks, dsSPEAK, ECAN, ECONOMONITOR, FanSense, HI-TIDE, In-Circuit Serial Programming, ICSP, Mindi, MiWi, MPASM, MPF, MPLAB Certified logo, MPLIB, MPLINK, mTouch, Omniscient Code Generation, PICC, PICC-18, PICDEM, PICDEM.net, PICkit, PICtail, REAL ICE, rfLAB, Select Mode, SQI, Serial Quad I/O, Total Endurance, TSHARC, UniWinDriver, WiperLock, ZENA and Z-Scale 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. GestIC and ULPP are registered trademarks of Microchip Technology Germany II GmbH & Co. KG, a subsidiary of Microchip Technology Inc., in other countries. All other trademarks mentioned herein are property of their respective companies. © 2010-2013, Microchip Technology Incorporated, Printed in the U.S.A., All Rights Reserved. Printed on recycled paper. ISBN: 9781620775851 QUALITY MANAGEMENT SYSTEM CERTIFIED BY DNV == ISO/TS 16949 == 2010-2013 Microchip Technology Inc. Microchip received ISO/TS-16949:2009 certification for its worldwide headquarters, design and wafer fabrication facilities in Chandler and Tempe, Arizona; Gresham, Oregon and design centers in California and India. The Company’s quality system processes and procedures are for its PIC® MCUs and dsPIC® DSCs, 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. DS00001333B-page 11 Worldwide Sales and Service AMERICAS ASIA/PACIFIC ASIA/PACIFIC EUROPE Corporate Office 2355 West Chandler Blvd. Chandler, AZ 85224-6199 Tel: 480-792-7200 Fax: 480-792-7277 Technical Support: http://www.microchip.com/ support Web Address: www.microchip.com Asia Pacific Office Suites 3707-14, 37th Floor Tower 6, The Gateway Harbour City, Kowloon Hong Kong Tel: 852-2401-1200 Fax: 852-2401-3431 India - Bangalore Tel: 91-80-3090-4444 Fax: 91-80-3090-4123 Austria - Wels Tel: 43-7242-2244-39 Fax: 43-7242-2244-393 Denmark - Copenhagen Tel: 45-4450-2828 Fax: 45-4485-2829 Atlanta Duluth, GA Tel: 678-957-9614 Fax: 678-957-1455 Boston Westborough, MA Tel: 774-760-0087 Fax: 774-760-0088 Chicago Itasca, IL Tel: 630-285-0071 Fax: 630-285-0075 Cleveland Independence, OH Tel: 216-447-0464 Fax: 216-447-0643 Dallas Addison, TX Tel: 972-818-7423 Fax: 972-818-2924 Detroit Farmington Hills, MI Tel: 248-538-2250 Fax: 248-538-2260 Indianapolis Noblesville, IN Tel: 317-773-8323 Fax: 317-773-5453 Los Angeles Mission Viejo, CA Tel: 949-462-9523 Fax: 949-462-9608 Santa Clara Santa Clara, CA Tel: 408-961-6444 Fax: 408-961-6445 Toronto Mississauga, Ontario, Canada Tel: 905-673-0699 Fax: 905-673-6509 Australia - Sydney Tel: 61-2-9868-6733 Fax: 61-2-9868-6755 China - Beijing Tel: 86-10-8569-7000 Fax: 86-10-8528-2104 China - Chengdu Tel: 86-28-8665-5511 Fax: 86-28-8665-7889 China - Chongqing Tel: 86-23-8980-9588 Fax: 86-23-8980-9500 China - Hangzhou Tel: 86-571-2819-3187 Fax: 86-571-2819-3189 China - Hong Kong SAR Tel: 852-2943-5100 Fax: 852-2401-3431 China - Nanjing Tel: 86-25-8473-2460 Fax: 86-25-8473-2470 China - Qingdao Tel: 86-532-8502-7355 Fax: 86-532-8502-7205 China - Shanghai Tel: 86-21-5407-5533 Fax: 86-21-5407-5066 China - Shenyang Tel: 86-24-2334-2829 Fax: 86-24-2334-2393 China - Shenzhen Tel: 86-755-8864-2200 Fax: 86-755-8203-1760 China - Wuhan Tel: 86-27-5980-5300 Fax: 86-27-5980-5118 China - Xian Tel: 86-29-8833-7252 Fax: 86-29-8833-7256 France - Paris Tel: 33-1-69-53-63-20 Fax: 33-1-69-30-90-79 India - Pune Tel: 91-20-3019-1500 Japan - Osaka Tel: 81-6-6152-7160 Fax: 81-6-6152-9310 Germany - Munich Tel: 49-89-627-144-0 Fax: 49-89-627-144-44 Japan - Tokyo Tel: 81-3-6880- 3770 Fax: 81-3-6880-3771 Italy - Milan Tel: 39-0331-742611 Fax: 39-0331-466781 Korea - Daegu Tel: 82-53-744-4301 Fax: 82-53-744-4302 Netherlands - Drunen Tel: 31-416-690399 Fax: 31-416-690340 Korea - Seoul Tel: 82-2-554-7200 Fax: 82-2-558-5932 or 82-2-558-5934 Spain - Madrid Tel: 34-91-708-08-90 Fax: 34-91-708-08-91 Malaysia - Kuala Lumpur Tel: 60-3-6201-9857 Fax: 60-3-6201-9859 UK - Wokingham Tel: 44-118-921-5869 Fax: 44-118-921-5820 Malaysia - Penang Tel: 60-4-227-8870 Fax: 60-4-227-4068 Philippines - Manila Tel: 63-2-634-9065 Fax: 63-2-634-9069 Singapore Tel: 65-6334-8870 Fax: 65-6334-8850 Taiwan - Hsin Chu Tel: 886-3-5778-366 Fax: 886-3-5770-955 Taiwan - Kaohsiung Tel: 886-7-213-7828 Fax: 886-7-330-9305 Taiwan - Taipei Tel: 886-2-2508-8600 Fax: 886-2-2508-0102 Thailand - Bangkok Tel: 66-2-694-1351 Fax: 66-2-694-1350 China - Xiamen Tel: 86-592-2388138 Fax: 86-592-2388130 China - Zhuhai Tel: 86-756-3210040 Fax: 86-756-3210049 DS00001333B-page 12 India - New Delhi Tel: 91-11-4160-8631 Fax: 91-11-4160-8632 08/20/13 2010-2013 Microchip Technology Inc.