NEW DATABASE - 350 MILLION DATASHEETS FROM 8500 MANUFACTURERS
AVR122 - Datasheet Archive
temperature reference Features 8-bit Microcontrollers · Two-point and one-point calibration · Compensating the ADC
AVR122 AVR122: Calibration of the AVR's internal temperature reference Features 8-bit Microcontrollers · Two-point and one-point calibration · Compensating the ADC output values 1 Introduction Application Note This application note describes how to calibrate and compensate the temperature measurements from the ATtiny25/45/85. It can also be used on other AVR® microcontrollers with internal temperature sensors. The temperature measurement is based on an on-chip temperature sensor that is coupled to a single ended ADC channel. The sensor is a diode that produces a temperature dependent voltage. This voltage is measured with the ADC. The voltage has a linear relationship to temperature and the result has approximately a 1 LSB/°C correlation to temperature. The diode voltage is highly linear, but due to process variations the temperature sensor output voltage varies from one chip to another. Also, the internal voltage reference used as the ADC reference voltage varies with temperature. The typical accuracy of temperature measurements over the full temperature range of the AVR is +/- 10°C after offset calibration and compensation. Figure 1-1. ADC output error in ADC Noise Reduction Mode, two-point calibrated. Rev. 8108A-AVR-02/08 2 Calibration The results from temperature measurements have offset and gain errors. The internal temperature reference can be corrected for these errors by making calibration measurements at one or two known temperatures and adjusting the output values. This can result in very precise temperature measurements, sometimes as accurate as +/- 2°C. 2.1 Two-Point Calibration To make the temperature measurements as accurate as possible, two calibration points are needed. The first calibration point, ADCT1, is the output from the ADC at the first calibration temperature, T1. This application note uses room temperature (25°C) as this first calibration temperature. The second calibration point, ADCT2, is the output at the second calibration temperature, T2. The second temperature should be chosen a little higher than the temperature range of interest. The output from the ADC is given in LSBs or K, so the calibration values ADCT1 and ADCT2 have to be converted to °C. This is done by subtracting 273 from the values. 2.1.1 Calibration Step ADCT1 and ADCT2 define a straight line. A straight line that intersects the points (h,k) and (p,q) is represented by Equation 2-1. The output (y) is the temperature output from the ADC, while the input (x) is the actual temperature. Equation 2-1. Straight line. y-k = q-k ( x - h) p-h An ideal output from the ADC is a straight line defined by Equation 2-2. Equation 2-2. Ideal output. 2 y=x AVR122 AVR122 8108A-AVR-02/08 AVR122 AVR122 Figure 2-1. ADC and ideal output. The solid line in Figure 2-1 is an arbitrary ADC characteristic, while the dashed line represents the ideal result from the temperature measurement. The line defined by our two calibration points has the following equation: Equation 2-3. Line defined by the calibration points. y - ADC T 1 = ADC T 2 - ADC T 1 ( x - T1 ) T2 - T1 Figure 2-2. ADC output with line defined by calibration points. 3 8108A-AVR-02/08 The offset error is the distance between the origin of coordinates and the point where the line defined by the two calibration points intersects the y-axis. It's found by setting x = 0 in Equation 2-3. Equation 2-4. Offset error. Toffset = ADC T 2 - ADC T 1 ( -T1 ) + ADC T 1 T2 - T1 Figure 2-3. ADC output with offset error removed. It is necessary to find a gain factor k to apply to the ADC output values after the offset error has been removed. To find this factor, the following equation is used: Equation 2-5. Gain factor. k= T2 ADC T 2 - Toffset 2.1.2 Compensation The k value from Equation 2-5 is unchanged if substituting T2 with T1 and ADCT2 with ADCT1. Compensation can now be done by removing the offset and gain errors from the ADC values. This is accomplished by applying the following formula on the output values: Equation 2-6. Compensation equation. T = (T ADC - Toffset ) k TADC is the output from the ADC converted to °C by subtracting 273 from the ADC value. 4 AVR122 AVR122 8108A-AVR-02/08 AVR122 AVR122 Figure 2-4. ADC output with offset and gain errors removed. 2.1.3 Calibration Range To achieve better accuracy the calibration range can be narrowed. In other words, to obtain better accuracy more calibration points are needed. In the previous discussion it was assumed that the ADC characteristic is approximately linear between the calibration points. This is not necessarily the case. The characteristic is often approximately piecewise linear before and after some temperature. Choosing the calibration points wisely could result in increased accuracy after the compensation step. 2.2 One-Point Calibration If just one calibration point is available, the calibration can be done in one of two ways. An offset error can be removed from the ADC output values to obtain a rough compensation. Both the ADC value at T1 (room temperature) and at T2 can be used to find this offset error. Note that this kind of calibration/compensation could result in larger errors in the measurements. Let us for example assume that the ADC output has a negative error in the low end of the temperature scale, and that the error turns positive above a given temperature, around 50°C. If the calibration point is at 25°C and the temperatures of interest are above 50°C, compensation using only offset removal would result in larger measuring errors for the temperatures of interest. The second type of one-point calibration is to assume that the output from the ADC is approximately linear and that the error is primarily a gain error. The calibration point is used to calculate the gain factor, when assuming zero offset. This kind of calibration and compensation suffers from the same problems as offset calibration. The advantage of one-point calibration compared to two-point calibration is the fact that only one accurate calibration temperature is needed. Also, the compensation itself is simpler because the formula applied on the output values is less complicated. 5 8108A-AVR-02/08 3 Accuracy Without compensation the maximum error can be approximately +/-10°C, where the biggest deviations from the ideal value occur at the temperature extremes. Two-point calibration and compensation gives the best results, but still, one-point calibration can result in satisfactory temperature readings if the temperatures of interest lie close to the calibration point. The following data come from measurements made on the ATtiny45. Figure 3-1. ADC output error at 1MHz CPU frequency, 3.3V. 7 6 5 4 ADC Output Error (°C) 3 2 1 - 1MHZ - Active - 3,3 1 - 1MHZ - ADCnr - 3,3 1 125 120 115 110 105 95 100 90 85 80 75 70 65 60 55 50 45 40 35 30 25 20 15 5 10 0 -5 -10 -15 -20 -25 -30 -35 -40 0 -1 -2 -3 -4 Temperature (°C) 6 AVR122 AVR122 8108A-AVR-02/08 AVR122 AVR122 Figure 3-2. ADC output error at 8MHz CPU frequency, 3.3V. 8 6 4 125 120 115 110 105 95 100 90 85 80 75 70 65 60 55 50 45 40 35 30 25 20 15 5 10 0 -5 -10 -15 -20 -25 -30 -35 0 -40 ADC Output Error (°C) 2 1 - 8MHz - Active - 3,3 1 - 8MHz - ADCnr - 3,3 -2 -4 -6 -8 -10 Temperature (°C) Figure 3-1 and 3-2 show the ADC conversion error of an arbitrary device at 1MHz and at 8MHz CPU frequency. Each point in the graph represents the average of thousand consecutive temperature measurements. In both graphs, the line with squares represents readings in ADC Noise Reduction Mode, while the line with diamonds represents the readings in active mode. As seen, the measurement errors at a high CPU frequency are larger if the measurements are carried out in active mode compared to ADC Noise Reduction Mode. At a low CPU frequency the differences are small. 3.1 One-point calibration and compensation If one-point calibration is the only option, compensation should be avoided when the temperatures of interest are far from the calibration point (>20°C). Most devices benefit from the use of offset compensation, and for some devices it may even suffice. However, for other devices one-point calibration can result in larger errors. If one-point calibration is used, the operation window of the temperature sensor with +/1°C accuracy is no more than 20-30°C. 7 8108A-AVR-02/08 Figure 3-3. ADC output error in ADC Noise Reduction Mode, 1MHz, 3.3V, offset compensated. 6 4 90 95 10 0 10 5 11 0 11 5 12 0 12 5 75 80 85 65 70 55 60 40 45 50 30 35 20 25 5 10 15 0 -5 -1 0 -2 0 -1 5 -3 0 -2 5 0 -4 0 -3 5 ADC Error (LSB) 2 -2 -4 -6 Temperature (°C) Figure 3-3 shows the results from measurements carried out on three different devices in ADC Noise Reduction Mode. In this figure simple offset calibration and compensation has been applied. The ADC reading of the temperature sensor at 25°C is used as the calibration point. The chart shows high, low and average data. The dot gives the average value, while the top of the individual lines give the largest value and the bottom give the lowest. As the figure shows, on these devices this kind of compensation gave good results over a wide temperature range. If +/-1°C was required, the compensation gave satisfactory results from 20°C to 55°C. Applying only gain compensation on the same readings gives the following results: 8 AVR122 AVR122 8108A-AVR-02/08 AVR122 AVR122 Figure 3-4. ADC output error in ADC Noise Reduction Mode, 1MHz, 3.3V, gain compensated. 8 6 2 90 95 10 0 10 5 11 0 11 5 12 0 12 5 75 80 85 65 70 55 60 40 45 50 30 35 20 25 5 10 15 0 -5 -1 5 -1 0 -2 0 -2 5 -3 0 -3 5 0 -4 0 ADC error (LSB) 4 -2 -4 -6 Temperature (°C) If one-point calibration/compensation is used or if no compensation is applied, entering ADC Noise Reduction Mode before the conversion starts is necessary to obtain good results. ADC Noise Reduction Mode works well, but at low CPU frequencies the advantage over active mode is quite small. At 8MHz however, the ADC Noise Reduction Mode is essential. 9 8108A-AVR-02/08 3.2 Two-point calibration/compensation Figure 3-5. ADC output error in ADC Noise Reduction Mode, 1MHz, 3.3V, two-point compensated. 4 3 2 90 95 10 0 10 5 11 0 11 5 12 0 12 5 75 80 85 65 70 55 60 40 45 50 30 35 20 25 5 10 15 0 -5 -1 0 -2 0 -1 5 -3 0 -2 5 0 -4 0 -3 5 ADC Error (LSB) 1 -1 -2 -3 -4 Temperature (°C) Figure 3-5 shows the same results as Figure 3-3 and 3-4, but with two-point calibration and compensation. The first calibration temperature is 25°C and the second is 85°C. If +/-1°C accuracy is required, the temperatures where the results are satisfactory range from 5°C to 95°C with three exceptions. The errors at the temperature extremes are much smaller, and the compensation gives +/-3°C accuracy over the whole temperature range. 10 AVR122 AVR122 8108A-AVR-02/08 AVR122 AVR122 Figure 3-6. ADC output error, ADC Noise Reduction Mode, 1MHz, 3.3V, no compensation. 10 8 6 2 1 - 1MHZ - ADCnr - 3,3 2 - 1MHZ - ADCnr - 3,3 3 - 1MHZ - ADCnr - 3,3 125 120 115 110 105 95 100 90 85 80 75 70 65 60 55 50 45 40 35 30 25 20 15 5 10 0 -5 -10 -15 -20 -25 -30 -35 0 -40 ADC Output Error (°C) 4 -2 -4 -6 -8 Temperature (°C) As seen in Figure 3-6, the curve of the ADC characteristic of these devices is approximately piecewise linear. Figure 3-7. ADC output error in active mode, 8MHz, 3.3V, two-point compensated. 4 3 2 90 95 10 0 10 5 11 0 11 5 12 0 12 5 80 85 70 75 60 65 50 55 40 45 30 35 20 25 10 15 5 0 -5 -1 0 -2 0 -1 5 -3 0 -2 5 0 -4 0 -3 5 ADC Error (LSB) 1 -1 -2 -3 -4 Temperature (°C) 11 8108A-AVR-02/08 It is possible that making the measurements at a high CPU frequency and in active mode actually makes the results more correct, if subsequent two-point calibration and compensation is applied. Figure 3-7 illustrates this. Here, the measurements are carried out in active mode at 8MHz CPU frequency. If +/-1°C accuracy is needed, this approach results in satisfactory readings between the calibration points (25°C and 85°C) with no exceptions, in contrast to the measurements in Figure 3-5 where three values had an error larger than +/-1°C. If the second calibration point isn't accurate, two-point calibration may actually make the results worse. Let's say the second calibration point is +/-5°C accurate. If T2 is 5°C above the actual value at 85°C, two-point calibration/compensation would result in the following results: Figure 3-8. Two-point compensated with T2 5°C above ideal value. 6 4 90 95 10 0 10 5 11 0 11 5 12 0 12 5 75 80 85 65 70 55 60 40 45 50 30 35 20 25 5 10 15 0 -5 -1 0 -2 0 -1 5 -3 0 -2 5 0 -4 0 -3 5 Output Error (LSB) 2 -2 -4 -6 Temperature (°C) If T2 is 5°C smaller than the target temperature of 85°C, the results of the compensation would be like this: 12 AVR122 AVR122 8108A-AVR-02/08 AVR122 AVR122 Figure 3-9. Two-point compensated with T2 5°C below ideal value. 15 5 90 95 10 0 10 5 11 0 11 5 12 0 12 5 80 85 70 75 60 65 50 55 40 45 30 35 20 25 5 10 15 0 -5 -1 0 -2 0 -1 5 -3 0 -2 5 0 -4 0 -3 5 Output Error (LSB) 10 -5 -10 Temperature (°C) Figure 3-8 and 3-9 shows that if one or both of the calibration temperatures are not accurate, there is no sense in using two-point calibration and compensation. With only one accurate calibration temperature, one-point calibration and compensation gives the best results. 4 Summary The recommended CPU frequency is 1MHz, or alternatively the recommended mode of operation is ADC Noise Reduction Mode. This ensures good results from the temperature readings. Two-point calibration/compensation relies on accurate calibration points. If the ADC value at T2 is only accurate to within +/-5°C, two-point calibration will only make the results less correct. However, when calibration points are accurate, two-point calibration/compensation gives good results over the whole temperature range. Without accurate measurements at the second calibration point, one-point calibration is the best way to compensate the temperature readings. Offset removal using room temperature as reference gives +/-5°C accuracy from -30°C to 100°C and +/-3°C accuracy between 0°C and 85°C, all typical data for one-point calibration at room temperature for the ATtiny45. Gain error removal gives similar accuracy. 13 8108A-AVR-02/08 Disclaimer Headquarters International Atmel Corporation 2325 Orchard Parkway San Jose, CA 95131 USA Tel: 1(408) 441-0311 Fax: 1(408) 487-2600 Atmel Asia Room 1219 Chinachem Golden Plaza 77 Mody Road Tsimshatsui East Kowloon Hong Kong Tel: (852) 2721-9778 Fax: (852) 2722-1369 Atmel Europe Le Krebs 8, Rue Jean-Pierre Timbaud BP 309 78054 Saint-Quentin-enYvelines Cedex France Tel: (33) 1-30-60-70-00 Fax: (33) 1-30-60-71-11 Atmel Japan 9F, Tonetsu Shinkawa Bldg. 1-24-8 Shinkawa Chuo-ku, Tokyo 104-0033 Japan Tel: (81) 3-3523-3551 Fax: (81) 3-3523-7581 Technical Support avr@atmel.com Sales Contact www.atmel.com/contacts Product Contact Web Site www.atmel.com Literature Request www.atmel.com/literature Disclaimer: The information in this document is provided in connection with Atmel products. No license, express or implied, by estoppel or otherwise, to any intellectual property right is granted by this document or in connection with the sale of Atmel products. EXCEPT AS SET FORTH IN ATMEL'S TERMS AND CONDITIONS OF SALE LOCATED ON ATMEL'S WEB SITE, ATMEL® ASSUMES NO LIABILITY WHATSOEVER AND DISCLAIMS ANY EXPRESS, IMPLIED OR STATUTORY WARRANTY RELATING TO ITS PRODUCTS INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, CONSEQUENTIAL, PUNITIVE, SPECIAL OR INCIDENTAL DAMAGES (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF PROFITS, BUSINESS INTERRUPTION, OR LOSS OF INFORMATION) ARISING OUT OF THE USE OR INABILITY TO USE THIS DOCUMENT, EVEN IF ATMEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. Atmel makes no representations or warranties with respect to the accuracy or completeness of the contents of this document and reserves the right to make changes to specifications and product descriptions at any time without notice. Atmel does not make any commitment to update the information contained herein. Unless specifically provided otherwise, Atmel products are not suitable for, and shall not be used in, automotive applications. Atmel's products are not intended, authorized, or warranted for use as components in applications intended to support or sustain life. © 2008 Atmel Corporation. All rights reserved. Atmel®, logo and combinations thereof, AVR® and others, are the registered trademarks or trademarks of Atmel Corporation or its subsidiaries. Other terms and product names may be trademarks of others. 8108A-AVR-02/08