AN2648 Application note Increasing the resolution of analog temperature sensors Introduction For a recent trade show, a demonstration board was required to display ST's new low-cost temperature sensor, the STLM20. The idea was to connect it to a basic microcontroller with on-board analog-to-digital converter (ADC) and display the temperature on seven-segment LEDs. Any user would be able to affect the temperature by applying his finger directly to the sensor and then watch the display change as a result. The goal was to keep things simple and use the ADC converter on the micro thus avoiding the expense and engineering effort of using an external ADC. Using the STLM20 temperature sensor with low-cost microcontrollers The design flow used for the demonstration board can be applied in many applications. This document describes how any user can implement a temperature sensor design using the LM20 and a low-cost microcontroller with integral A-D converter. Figure 1. STLM20 demonstration board 200mm / ~8 144mm / 5.7 34mm / 1.34 280mm / ~11 December 2007 Rev 1 1/15 www.st.com STLM20 temperature-to-output transfer function 1 AN2648 STLM20 temperature-to-output transfer function Upon examining the temperature sensor's output characteristics, several issues become apparent. The STLM20 is a voltage output device with a 2nd order transfer function: V0 = (−3.88 × 10 −6 × T 2 ) + (−1.15 ×10 −2 × T ) + 1.8639 V This is rather unwieldy math for a simple 8-bit micro, but a linear approximation is available which matches the curve very closely. As shown in Figure 2, the dashed blue line is a very good fit to the pink parabola of the 2nd order equation above, and has the following equation: Equation 1 V0 = (−0.01169 V/°C) × T + 1.8663 V This is much more manageable for coding in assembly language without a math package. In this figure, the reader will note that the curve deviates only slightly from the line at the extreme ends. In the middle, they are almost indistinguishable. Figure 2. STLM20 transfer function 2.5 2.3 Output voltage, VO , (V) 2.1 1.9 2nd Order Linear 1.7 1.5 1.3 1.1 0.9 0.7 0.5 -60 -40 -20 0 20 40 60 80 100 Temperature, T (˚C) ai13986 2/15 AN2648 STLM20 temperature-to-output transfer function The second issue arises with the output voltage range. The micro's ADC performs ratiometric conversion on the input using VCC and ground as the upper and lower references, respectively. That means that when the input voltage equals VCC, the 8-bit ADC's output will be 255 (FFHEX), and when the input is ground, the output will be 0 (00HEX). Any voltage in the range VCC to ground is converted proportionally according to the following relationship: ADC output (dec) = (VIN /VCC ) × 255 For this application, the nominal VCC is 5 V, so this equation becomes: ADC output (dec) = (VIN /5) × 255 = VIN × 51 Referring to Figure 3, while the ADC can accept inputs over the full range 0 to 5 V, the temperature sensor output will vary over a much smaller range, between 0.87 and 2.33 volts across the temperature range –40° to +85°C. STLM20 output voltage range 5 Output voltage, VO (V) Figure 3. 4.5 4 3.5 3 2.5 STLM20 full range, linear, ind temp 2 Available voltage range 1.5 STLM20 output voltage range 1 0.5 0 -60 -40 -20 0 20 40 60 80 100 Temperature, T (˚ C) ai13987 This amounts to using only 1.46 V of the available 5 V range. Furthermore, in the intended demonstration board application, the necessary temperature range was approximately room temperature –15°/+25°, or 10° to 50°C. For this target temperature range, the voltage range is 1.28 to 1.75 V, an interval of less than 0.5 V, less than one tenth the available 5 V range. This is depicted in Figure 4. 3/15 STLM20 temperature-to-output transfer function Figure 4. AN2648 Application temperature and voltage ranges 5 4.5 4 Output voltage, VO (V) 3.5 3 2.5 Temperature range of interest 2 1.5 Used voltage range of application 1 STLM20 full temperature range 0.5 Available voltage range 0 - 60 - 40 -20 0 20 40 60 80 100 Temperature, T (˚C) ai13988 In Equation 1, the slope is –11.69 mV per °C. For the 8-bit ADC, the step size is 5 V/255 steps or 0.019608 V/step. Comparing this to the slope, we get: 0.019608 V/step = − 1.677318 °C/step − 0 .0 1169 V/ °C This means that, with the temperature sensor connected directly to the ADC, the resolution is only 1.68°C/step. The smallest temperature increment the ADC can resolve is 1.68°C. This is very coarse resolution. 4/15 AN2648 STLM20 temperature-to-output transfer function Given that the expected voltage range is less than 0.5 V, it should be possible to amplify the STLM20 output signal so that is uses more of the available voltage range. A 10x amplification should be possible without exceeding the available 5 V range. Furthermore, a positive slope is more intuitive to the user, so inverting it would be helpful, too. Hence, a gain of –10 should be used. Multiplying equation 1 by –10, we get the curve as shown at the bottom in Figure 5. Figure 5. Application transfer function after gain, inversion and offset 5.5 3.5 1.5 -50 -30 -0.5 -10 10 30 50 70 90 -2.5 Voltage (V) -4.5 +17.5 x –10 -6.5 -8.5 -10.5 -12.5 -14.5 < 5V -16.5 -18.5 Temperature, T (˚C) ai13989 The result has positive slope and spans from –17.5 to –12.8, an interval of about 4.7 V, much closer to the available 5 V range. 5/15 STLM20 temperature-to-output transfer function AN2648 With an offset of approximately +17.5 V the curve is moved back into the range 0-5 V to give the transfer function shown as the light blue line in Figure 5. So how is this done? What circuit will perform this transformation without adding intolerable cost to the system? It turns out that a difference amplifier can be used to add gain and offset, and can do the inversion as well. And it requires only one op-amp to implement. An additional op-amp is used as a voltage follower out of the temperature sensor to prevent output loading from affecting the STLM20's output level. The net amplifier requirement then is a dual op-amp. A voltage reference is also required to provide the offset level going into the difference amp. The overall circuit is shown in Figure 6. The STLM20 output voltage, V0, appears identically at the first op-amp output. That then drives the inverting input of the difference amp with a gain of –50k/5k = –10. This translates the curve from a voltage range of 1.28 V to 1.75 V to a range of –12.8 V to –17.5 V so an offset of about +17.5 V must be applied. The 1.7676 V reference sees a gain of 10 (R4/R3 = ~50k/5k = 10) on the op-amp's non-inverting input. Thus, 17.676 volts is added back into the translation. With this gain and offset, the original curve, which had an interval of less than 0.5 V and a negative slope, is transformed to one which spans close to 5 V and has a positive slope as illustrated by the light blue line in Figure 5. Figure 6. STLM20 with gain and offset circuit VCC VCC 0.1uF 0.1uF T VO = VO 0.1uF STLM20 LMV358 VCC R3 50k V1 R1 5k VOUT V2 5k R2 LMV358 1.7676V 0.1uF R4 50k 0.1uF TS431 ai13990 6/15 AN2648 STLM20 temperature-to-output transfer function Equation 2 is the basic difference amplifier equation. Equation 2 VOUT = V2 ( R3 + R1) R4 V1 ⋅ R3 − (R4 + R2) R1 R1 If R1 = R2 and R3 = R4, then it reduces to: VOUT = (V2 − V1 ) R3 R1 However, obtaining perfectly identical resistors is nearly impossible. Thus, the more complex expression of Equation 2 is used. Starting with Equation 1 on page 2, for Figure 6, we have: VO = −0.01169 ⋅ T + 1.8663 V In Figure 6, V1 is driven by V0, so Equation 2 becomes: VOUT = V2 ( R3 + R1) R4 VO ⋅ R3 − (R4 + R2) R1 R1 Substituting the expression for V0 into this, we get: VOUT = V2 ⋅ ( R3 + R1) R4 ( − 0.01169 ⋅ T + 1.8663) ⋅ R3 − (R4 + R2) R1 R1 VOUT = V2 ⋅ ( R3 + R1) R4 R3 R3 + 0.01169 ⋅ ⋅ T − 1.8663 ⋅ (R4 + R2) R1 R1 R1 7/15 STLM20 temperature-to-output transfer function AN2648 Equation 3 VOUT = V2 ⋅ ( R3 + R1) R4 R3 R3 − 1.8663 ⋅ + 0.01169 ⋅ ⋅T (R4 + R2) R1 R1 R1 The ADC inside the microprocessor is shown in Figure 7. Figure 7. ADC in microprocessor VOUT VCC = 5V VADC A/D 8-bit CPU I/O MEM MICROCONTROLLER ai13991 For the ADC output, we have the following, where INT means the integer portion of the expression: ⎡ 255 ⎤ VADC = INT ⎢ VOUT ⎥ ⎣ VCC ⎦ Substituting Equation 3, we get: ⎡ 255 ⎛ ( R3 + R1) R4 R3 R3 ⎜⎜ V2 ⋅ VADC = INT ⎢ − 1.8663 ⋅ + 0.01169 ⋅ ⋅T (R4 + R2) R1 R1 R1 ⎣ VCC ⎝ Rearranging, and ignoring the integer notation for now, we get: VADC ⋅ 8/15 VCC ( R3 + R1) R4 R3 R3 = V2 ⋅ − 1.8663 ⋅ + 0.01169 ⋅ ⋅T 255 (R4 + R2) R1 R1 R1 ⎞⎤ ⎟⎟⎥ ⎠⎦ AN2648 STLM20 temperature-to-output transfer function To get the measured temperature, TMEASA, we must solve for T above: VADC ⋅ VADC ⋅ VCC ( R3 + R1) R4 R3 R3 − V2 ⋅ + 1.8663 ⋅ = 0.01169 ⋅ ⋅T 255 (R4 + R2) R1 R1 R1 VCC R1 ( R3 + R1) R4 R1 R3 R1 R3 R1 ⋅ − V2 ⋅ ⋅ + 1.8663 ⋅ ⋅ = 0.01169 ⋅ ⋅ ⋅T 255 R3 (R4 + R2)R1 R3 R1 R3 R1 R3 VADC ⋅ VCC R1 ( R3 + R1) R4 ⋅ − V2 ⋅ + 1.8663 = 0.01169 ⋅ T 255 R3 (R4 + R2) R3 Equation 4 TMEASA = T = VADC ⋅ VCC R1 ( R3 + R1) R4 1 1.8663 1 ⋅ ⋅ − V2 ⋅ ⋅ + 255 R3 0.01169 (R4 + R2) R3 0.01169 0.01169 This has the form: Equation 4b TMEASA = VADC ⋅ K S + K O But, rather than using this equation, it is better to filter the temperature, to average multiple samples together for display. This has two benefits. It smoothes the changes resulting in a displayed value which updates more gradually. And it increases the effective resolution of the sensor. By adding two more bits, this essentially makes the A/D appear to have 10-bit resolution. So, we use a modified version of the previous math, but sum four consecutive samples together: ⎡ 255 ⎤ VADC = INT ⎢ VOUT ⎥ ⎣ VCC ⎦ ⎡ 255 ⎛ ( R3 + R1) R4 R3 R3 ⎜⎜ V2 ⋅ VADC = INT ⎢ − 1.8663 ⋅ + 0.01169 ⋅ ⋅T (R4 + R2) R1 R1 R1 ⎣ VCC ⎝ ⎞⎤ ⎟⎟⎥ ⎠⎦ 9/15 STLM20 temperature-to-output transfer function AN2648 VSUM4 = 4 samples of VADC, range 0 to 1020. ⎡ 255 ⎛ ( R3 + R1) R4 R3 R3 ⎜⎜ V2 ⋅ VSUM4 = 4 ⋅ INT ⎢ − 1.8663 ⋅ + 0.01169 ⋅ ⋅T (R4 + R2) R1 R1 R1 ⎣ VCC ⎝ ⎞⎤ ⎟⎟⎥ ⎠⎦ Rearranging and ignoring the integer operator, we get: VSUM4 ⋅ VCC ( R3 + R1) R4 R3 R3 = V2 ⋅ − 1.8663 ⋅ + 0.01169 ⋅ ⋅T 1020 (R4 + R2) R1 R1 R1 VSUM4 ⋅ VCC ( R3 + R1) R4 R3 R3 − V2 ⋅ + 1.8663 ⋅ = 0.01169 ⋅ ⋅T 1020 (R4 + R2) R1 R1 R1 VSUM4 ⋅ VCC R1 R3 R1 ( R3 + R1) R4 R1 R3 R1 ⋅ − V2 ⋅ ⋅ + 1.8663 ⋅ ⋅ = 0.01169 ⋅ ⋅ ⋅T 1020 R3 (R4 + R2) R1 R3 R1 R3 R1 R3 VSUM4 ⋅ VCC R1 ( R3 + R1) R4 ⋅ − V2 ⋅ + 1.8663 = 0.01169 ⋅ T (R4 + R2) R3 1020 R3 Equation 5 TMEAS4 = T = VSUM4 ⋅ VCC R1 ( R3 + R1) R4 1 1.8663 1 ⋅ ⋅ − V2 ⋅ ⋅ + 1020 R3 0.01169 (R4 + R2) R3 0.01169 0.01169 This is a linear equation and has the form: Equation 5b TMEAS4 = VSUM4 ⋅ K S /4 + K O 10/15 AN2648 STLM20 temperature-to-output transfer function Notice that the upper limit for the sum of four samples is 1020 (4 x 255) and not 1023 as might be inferred for a 10-bit number. The actual values of KS/4 and KO depend on the four resistors in the difference amp, the voltage reference output and VCC. In the case of the temperature sensor demonstration board, we have these values: R1 = 5107 Ω R2 = 5105 Ω R3 = 50850 Ω R4 = 50850 Ω VCC = 4.9058 V V2 = VREF = 1.7676 V For KS, we insert these values into Equation 4 and get this for a single sample: TMEASA = T = VADC ⋅ VCC R1 1 ( R3 + R1) R4 1 1.8663 ⋅ ⋅ − V2 ⋅ ⋅ + 255 R3 0.01169 (R4 + R2) R3 0.01169 0.01169 TMEASA = VADC ⋅ 0.16528 + 8.43771 Thus, for Equation 4b, KS = 0.16528 and KO = 8.43771. Therefore, KS/4 = 0.04132. Substituting this into Equation 5b, we get: TMEAS4 = 0.04132 ⋅ VSUM4 + 8.43771 This gives the four-sample average of the temperature. However, more processing is still required to get it into a form suitable for implementing in a simple processor. Since the processor is an 8-bit, integer machine, multiplication by a real number - in this case a fraction - is difficult and requires lots of math software. Instead of doing such complicated math, it's easier to first multiply by 1000, then later divide by 1000. So, Equation 5b becomes: 1000 ⋅ TMEAS4 = 41⋅ VSUM4 + 8438 11/15 STLM20 temperature-to-output transfer function AN2648 Since the numbers are strictly integers, some truncation error has occurred. Running error analysis on the calculated results shows an average error of –0.21°C, so as a final adjustment, an additional 0.2(x1000) is added to get this equation: 1000 ⋅ TMEAS4 = 41 ⋅ VSUM4 + 8438 + 200 = 41⋅ VSUM4 + 8638 The above equation is then implemented in the software. The final step is dividing the result by 1000 and writing it to the demonstration board's display. The overall solution looks like this (Figure 8): Figure 8. Overall solution VCC STLM20 VO = –11.69mV / ˚C × T + 1.8663V slope is 0.01169 V/˚C VOUT = TEMPERATURE TO VOLTAGE V2 ( R3 + R1) R4 VO •R3 (R4 + R2) R1 R1 = V2 • ( R3 + R1) R4 R3 R3 1.8663 • + 0.01169 • • T (R4 + R2) R1 R1 R1 VOUT = 0.1164 • T – 0.9821 V1 R1 V2 R2 VADC = INT VADC • R3 VOUT 1.7676V 255 VOUT VCC VCC R1 ( R3 + R1) R4 V2 • + 1.8663 = 0.01169• T • 255 R3 (R4 + R2) R3 TMEASA = T = VADC • VCC R1 1 ( R3 + R1) R4 1 1.8663 • • • + V2 • 255 R3 0.01169 (R4 + R2)R3 0.01169 0.01169 TMEASA = VADC • 0.165284 + 8.437709 VREF R4 VCC = T = VSUM4 • 0.041321 + 8.437709 4.9058V MEAS4 41 8438 + 1000 A/D 8-bit CPU 1000 I/O MEM MICROCONTROLLER ai13992 Thus, for the minor expense of a voltage reference and dual op-amp, the resolution has been improved from 1.677°C per ADC step to better than 0.1°C steps on the display. 12/15 AN2648 2 Summary Summary The STLM20 is very accurate over a wide temperature range and has a nearly linear output which spans the voltage range 2.33 down to 0.87 volts over the corresponding temperature range –40° to +85°C. While it can be directly connected to an 8-bit A-D converter such as those often found integrated into low-cost microcontrollers, the resolution may be too coarse for some applications, amounting to –1.677°C per A-D step. For applications requiring higher resolution, users can use an op-amp and a voltage reference to add gain and offset to the STLM20 output. This has the effect of increasing the resolution over the temperature range of interest while avoiding the need for a more expensive, higher resolution A-D converter. Using averages of four samples also increases the effective resolution. The final result is that users can achieve resolution as fine as 0.1°C with the STLM20. 13/15 Revision history 3 AN2648 Revision history Table 1. 14/15 Document revision history Date Revision 20-Dec-2007 1 Changes Initial release. AN2648 Please Read Carefully: Information in this document is provided solely in connection with ST products. STMicroelectronics NV and its subsidiaries (“ST”) reserve the right to make changes, corrections, modifications or improvements, to this document, and the products and services described herein at any time, without notice. All ST products are sold pursuant to ST’s terms and conditions of sale. Purchasers are solely responsible for the choice, selection and use of the ST products and services described herein, and ST assumes no liability whatsoever relating to the choice, selection or use of the ST products and services described herein. No license, express or implied, by estoppel or otherwise, to any intellectual property rights is granted under this document. If any part of this document refers to any third party products or services it shall not be deemed a license grant by ST for the use of such third party products or services, or any intellectual property contained therein or considered as a warranty covering the use in any manner whatsoever of such third party products or services or any intellectual property contained therein. UNLESS OTHERWISE SET FORTH IN ST’S TERMS AND CONDITIONS OF SALE ST DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY WITH RESPECT TO THE USE AND/OR SALE OF ST PRODUCTS INCLUDING WITHOUT LIMITATION IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE (AND THEIR EQUIVALENTS UNDER THE LAWS OF ANY JURISDICTION), OR INFRINGEMENT OF ANY PATENT, COPYRIGHT OR OTHER INTELLECTUAL PROPERTY RIGHT. UNLESS EXPRESSLY APPROVED IN WRITING BY AN AUTHORIZED ST REPRESENTATIVE, ST PRODUCTS ARE NOT RECOMMENDED, AUTHORIZED OR WARRANTED FOR USE IN MILITARY, AIR CRAFT, SPACE, LIFE SAVING, OR LIFE SUSTAINING APPLICATIONS, NOR IN PRODUCTS OR SYSTEMS WHERE FAILURE OR MALFUNCTION MAY RESULT IN PERSONAL INJURY, DEATH, OR SEVERE PROPERTY OR ENVIRONMENTAL DAMAGE. ST PRODUCTS WHICH ARE NOT SPECIFIED AS "AUTOMOTIVE GRADE" MAY ONLY BE USED IN AUTOMOTIVE APPLICATIONS AT USER’S OWN RISK. Resale of ST products with provisions different from the statements and/or technical features set forth in this document shall immediately void any warranty granted by ST for the ST product or service described herein and shall not create or extend in any manner whatsoever, any liability of ST. ST and the ST logo are trademarks or registered trademarks of ST in various countries. Information in this document supersedes and replaces all information previously supplied. The ST logo is a registered trademark of STMicroelectronics. All other names are the property of their respective owners. © 2007 STMicroelectronics - All rights reserved STMicroelectronics group of companies Australia - Belgium - Brazil - Canada - China - Czech Republic - Finland - France - Germany - Hong Kong - India - Israel - Italy - Japan Malaysia - Malta - Morocco - Singapore - Spain - Sweden - Switzerland - United Kingdom - United States of America www.st.com 15/15

- Similar pages