AN2120 PSoC® 1 - Sensing - RTD Temperature Measurement Author: M Ganesh Raaja Associated Project: Yes Associated Part Family: CY8C27x43, CY8C29x66, CY8C24x23 Software Version: PSoC ® Designer™ 5.4 SP1 Related Application Notes: AN2017, AN2099 AN2120 describes the method to measure temperature using a PT100 RTD temperature sensor from –200 °C to 400 °C. Both 2-wire and 4-wire measurements can be performed using the method. Introduction Figure 2. Full RTD System with Linearized Output The general method used to derive temperature from a PT100 RTD temperature sensor is to make the sensor a part of a bridge and to measure the voltage developed by the bridge (Figure 1). Figure 1. Bridge Circuit With NO CALIBRATION and a single reference resistance, PSoC® can replace the setup in Figure 2 with leftover resources to implement a temperature indicator or controller. Step 1: Create a Lookup Table The differential voltage on the Sense Leads is an indication of the measured temperature. But this method is restricted to a very limited range of temperature due to the non-linearity exhibited both by the bridge and the PT100 sensor. When measuring wider temperature ranges using this method, error introduced due to the non-linearity of the sensor is very high. To overcome this problem, the setup shown in Figure 2 is used. A part of the developed voltage is fed back to the bridge excitation voltage for linearization. A1 is a differential amplifier stage, which amplifies the signal generated from the bridge and A3 is a buffer that drives the bridge with Excitation Voltage, VEX. Output of this buffer will depend on the part of the output signal from A1, which is fed to A3 by linearizing amplifier, A2. In this system, accuracy of +1 °C is achieved. But this involves precision op-amps and precise zero and span calibration. www.cypress.com Look at the PT100 Temperature charts in Table 1 and Table 2 in the Appendix. The coefficient of resistance is not the same throughout the range. It is 0.407 Ω/°C at –200°C and 0.368 Ω/°C at 400°C. The first step is to create a table with temperature coefficient for every 5 Ω increment in resistance. (This 5 Ω division can be a coarse one.) Then, create a lookup table in HEX for both positive and negative temperatures. This table is found in the Excel worksheet attached with the project. The fraction is multiplied by 1000 to get an integer number, for getting better accuracy without involving floating point math. So a scale of 0.368 Ω/°C is represented as 368 in the coefficient table. This is compensated in the equation that calculates the temperature. Document No. 001-31379 Rev. *E 1 ® PSoC 1 - Sensing - RTD Temperature Measurement Figure 4. 4-Wire RTD Measurement in PSoC Step 2: Measure Resistance 2-Wire RTD: The technique to measure resistance is explained in detail in Application Note AN2028 (Ohmmeter) and AN2017 (A Thermistor Based Thermometer, PSoC Style). The following is an excerpt from the same. V0 Rref PSoC V1 VREF+ Ra V2 Figure 3. Measuring Resistance the PSoC Way Rc PSoC Rt P0[5] P0[5] P0[7] P0[1] P0[6] PGA A = 0.97 ADC P0[3] Rd VREF+ V0 V3 Rb V1 PGA A = 0.97 P0[1] ADC In the above system, the resistive drop in Rc and Rd is negligible due to the high input impedance of the measurement system. Rt V2 VREF- V4 Rref VREF- P0[3] A potential divider is formed by a reference resistor and the RTD between Vref+ and Vref-. By measuring V0, V1 and V2 and applying Equation 1 Rt = Rref V − V2 × 1 − V V 1 0 As seen in the Equation 2, the output does not depend on the voltage drop across Ra (V1-V2) and Rb (V3-V4), hence, irrespective of the length and resistance of the connecting cable, the measured resistance is that of the RTD. Rt = Rref × Equation 1 the resistance of the RTD can be found with a resolution as good as 0.1 Ω. 4-Wire RTD: When the connection of the RTD to the measuring instrument is through long cables, the cable resistance also figures in the calculation and this introduces an error in the measurement. V2 − V3 V0 − V1 Equation 2 Step 3: Find Temperature Coefficient and Calculate Temperature First, divide the offset resistance by 5. The quotient gives the location of the coefficient in the lookup table. Once the coefficient is extracted from the table, the temperature is calculated by the formula: t = ΔR / α Equation 3 To cancel this error, a 4-wire RTD is used. Figure 4 shows how Figure 3 is modified to cancel the error introduced by the connecting cable. Where ∆R = Change in Resistance from the reference resistance α = Temperature Coefficient. www.cypress.com Document No. 001-31379 Rev. *E 2 ® PSoC 1 - Sensing - RTD Temperature Measurement The Project The project attached with the application note is for the 2-wire RTD system. This can be easily modified to implement the 4-wire system. The main function is MeasureRTD found in the main.c file: The following flowchart describes the logic of this function. Figure 5. Flowchart MeasureRTD Function Start Measure V0 (Vrefhi) Measure V1 (Vrtd) Measure V2 (Vreflo) Resistance = ((V1 – V2) / (V0 – V1)) * Rref Offset = Resistance - 100 Offset < 0? Set NEGATIVE Flag Set NEGATIVE Flag Coefficient Index = Offset / 5 Coefficient Index = Offset / 5 Coeff out of Range? Set RTD_SHORT Flag Set RTD_SHORT Flag Extract Coefficient Set RTD_OK Flag Coeff out of Range? Extract Coefficient Set RTD_OK Flag Calculate Temperature if RTD_OK Flag is set End www.cypress.com Document No. 001-31379 Rev. *E 3 ® PSoC 1 - Sensing - RTD Temperature Measurement Main The following operations are performed in the main program. Initialize all the resources Call the DisplayTemperature function to display the temperature or the Error status messages Call the MeasureRTD temperature function to measure Measure the cable resistance. During calculation, subtract this cable resistance from the measured resistance before extracting coefficient. Store this in the Flash using the E2PROM user module. The cable resistance may be measured and stored by a simple calibration process. Provide a switch on one of the ports. During Power On Reset (POR), sample this switch. If the switch is pressed, then measure the resistance and store it in the E2PROM. Following are some points to note in the project. To calibrate, short the connecting cable at the RTD end and power the PSoC with the switch pressed. The calibration is done. An LCD user module placed on Port2 is used to display the temperature on a 2x16 LCD display Calibration Though the reference resistance is 100, the value of REF_RESISTANCE is set to 1000 in main.c. This value gives a resolution of 0.1 Ω in the resistance measurement. If the reference resistance is highly accurate, no calibration is necessary. Use a 0.1% 100 ppm Metal Film Resistor for Rref. This resistance introduces a maximum of 0.3 Ω error in resistance measurement and a maximum of 1 °C error in temperature. As the resistance is measured with a resolution of 0.1 Ω, the offset resistance is divided by 50 to get the index of the coefficient. If the inconvenience of calibration is acceptable to get the most accurate measurement, a single-point calibration may be performed. The coefficient in the lookup table is multiplied by 1000 to get three decimal point accuracy without involving floating point math. This scale factor is compensated in the final equation. Input the resistance corresponding to 400 °C to the PSoC. Then trim the reference resistance until the output is exactly 400. This takes care of the entire range of measurement. The MeasureRTD function returns the value of temperature in integer format with a resolution of 0.1 degrees. For example a temperature of 85.4 will be returned as 854. This is to reduce the time taken for floating point operations. The DisplayTemperature function converts this integer into a floating point value with a resolution of 0.1 degrees. This is only for ease of displaying the result on the LCD. Actual applications can use only the integer value. Summary Some Points to Note Higher Accuracy with 2-Wire RTD 2-wire RTD is economical and easier to install than a 4-wire RTD because it requires fewer wires. There is a way to combine the economy of a 2-wire RTD system and get the accuracy of a 4-wire system by using the following procedure: www.cypress.com By using the flexible analog resources of the PSoC, an accurate temperature measurement can be performed using an RTD sensor. By selecting the reference resistance as 1K, 1K RTD is directly measured. For an RTD with different temperature coefficient, a new lookup table may be generated. About the Author Name: M Ganesh Raaja. Title: Applications Engr Principal Document No. 001-31379 Rev. *E 4 ® PSoC 1 - Sensing - RTD Temperature Measurement Appendix A Table 1. Positive Temperature Chart for PT100 °C +0°C (Ω) +1°C (Ω) +2°C (Ω) +3°C (Ω) +4°C (Ω) +5°C (Ω) +6°C (Ω) +7°C (Ω) +8°C (Ω) +9°C (Ω) °C 0 100.00 100.39 100.78 101.17 101.56 101.95 102.34 102.73 103.12 103.51 0 10 103.90 104.29 104.68 105.07 105.46 105.85 106.24 106.63 107.02 107.40 10 20 107.79 108.18 108.57 108.96 109.35 109.73 110.12 110.51 110.90 111.28 20 30 111.67 112.06 112.45 112.83 113.22 113.61 113.99 114.38 114.77 115.15 30 40 115.54 115.93 116.31 116.70 117.08 117.47 117.85 118.24 118.62 119.01 40 50 119.40 119.78 120.16 120.55 120.93 121.32 121.70 122.09 122.47 122.86 50 60 123.24 123.62 124.01 124.39 124.77 125.16 125.54 125.92 126.31 126.69 60 70 127.08 127.46 127.84 128.22 128.61 128.99 129.37 129.75 130.13 130.52 70 80 130.90 131.28 131.66 132.04 132.42 132.80 133.18 133.57 133.95 134.33 80 90 134.71 135.09 135.47 135.85 136.23 136.61 136.99 137.37 137.75 138.13 90 100 138.51 138.88 139.26 139.64 140.02 140.40 140.78 141.16 141.54 141.91 100 110 142.29 142.67 143.05 143.43 143.80 144.18 144.56 144.94 145.31 145.69 110 120 146.07 146.44 146.82 147.20 147.57 147.95 148.33 148.70 149.08 149.46 120 130 149.83 150.21 150.58 150.96 151.33 151.71 152.08 152.46 152.83 153.21 130 140 153.58 153.96 154.33 154.71 155.08 155.46 155.83 156.20 156.58 156.95 140 150 157.33 157.70 158.07 158.45 158.82 159.19 159.56 159.94 160.31 160.68 150 160 161.05 161.43 161.80 162.17 162.54 162.91 163.29 163.66 164.03 164.40 160 170 164.77 165.14 165.51 165.89 166.26 166.63 167.00 167.37 167.74 168.11 170 180 168.48 168.85 169.22 169.59 169.96 170.33 170.70 171.07 171.43 171.80 180 190 172.17 172.54 172.91 173.28 173.65 174.02 174.38 174.75 175.12 175.49 190 200 175.86 176.22 176.59 176.96 177.33 177.69 178.06 178.43 178.79 179.16 200 210 179.53 179.89 180.26 180.63 180.99 181.36 181.72 182.09 182.46 182.82 210 220 183.19 183.55 183.92 184.28 184.65 185.01 185.38 185.74 186.11 186.47 220 230 186.84 187.20 187.56 187.93 188.29 188.66 189.02 189.38 189.75 190.11 230 240 190.47 190.84 191.20 191.56 191.92 192.29 192.65 193.01 193.37 193.71 240 250 194.10 194.46 194.82 195.18 195.55 195.91 196.27 196.63 196.99 197.35 250 260 197.71 198.07 198.43 198.79 199.15 199.51 199.87 200.23 200.59 200.95 260 270 201.31 201.67 202.03 202.39 202.75 203.11 203.47 203.83 204.19 204.55 270 280 204.90 205.26 205.62 205.98 206.34 206.70 207.05 207.41 207.77 208.13 280 290 208.48 208.84 209.20 209.56 209.91 210.27 210.63 210.98 211.34 211.70 290 300 212.01 212.41 212.76 213.12 213.48 213.83 214.19 214.54 214.90 215.25 300 www.cypress.com Document No. 001-31379 Rev. *E 5 ® PSoC 1 - Sensing - RTD Temperature Measurement °C +0°C (Ω) +1°C (Ω) +2°C (Ω) +3°C (Ω) +4°C (Ω) +5°C (Ω) +6°C (Ω) +7°C (Ω) +8°C (Ω) +9°C (Ω) °C 310 215.61 215.96 216.32 216.67 217.03 217.38 217.74 218.09 218.44 218.80 310 320 219.15 219.51 219.86 220.21 220.57 220.92 221.27 221.63 221.98 222.33 320 330 222.68 223.04 223.39 223.74 224.09 224.45 224.80 225.15 225.50 225.85 330 340 226.21 226.56 226.91 227.26 227.61 227.96 228.31 228.66 229.02 229.37 340 350 229.72 230.07 230.42 230.77 231.12 231.47 231.82 232.17 232.52 232.87 350 360 233.21 233.56 233.91 234.26 234.61 234.96 235.31 235.66 236.00 236.35 360 370 236.70 237.05 237.40 237.74 238.09 238.44 238.79 239.13 239.48 239.83 370 380 240.18 240.52 240.87 241.22 241.56 241.91 242.26 242.60 242.95 243.29 380 390 243.64 243.99 244.33 244.68 245.02 245.37 245.71 246.06 246.40 246.75 390 400 247.09 400 Table 2. Negative Temperature Chart for PT100 °C -0°C(Ω) -1°C(Ω) -2°C(Ω) -3°C(Ω) -4°C(Ω) -5°C(Ω) -6°C(Ω) -7°C(Ω) -8°C(Ω) -9°C(Ω) °C -200 18.52 -190 22.83 22.40 21.97 21.54 21.11 20.68 20.25 19.82 19.38 18.95 -190 -180 27.10 26.67 26.24 25.82 25.39 24.97 24.54 24.11 23.68 23.25 -180 -170 31.34 30.91 30.49 30.07 29.64 29.22 28.80 28.37 27.95 27.52 -170 -160 35.54 35.12 34.70 34.28 33.86 33.44 33.02 32.60 32.18 31.76 -160 -150 39.72 31.31 38.89 38.47 38.05 37.64 37.22 36.80 36.38 35.96 -150 -140 43.88 43.46 43.05 42.63 42.22 41.80 41.39 40.97 40.56 40.14 -140 -130 48.00 47.59 47.18 46.77 46.36 45.94 45.53 45.12 44.70 44.29 -130 -120 52.11 51.70 51.29 50.88 50.47 50.06 49.65 49.24 48.83 48.42 -120 -110 56.19 55.79 55.38 54.97 54.56 54.15 53.75 53.34 52.93 52.52 -110 -100 60.26 59.85 59.44 59.04 58.63 58.23 57.82 57.41 57.01 56.60 -100 -90 64.30 63.90 63.49 63.09 62.68 62.28 61.88 61.47 61.07 60.66 -90 -80 68.33 67.92 67.52 67.12 66.72 66.31 65.91 65.51 65.11 64.70 -80 -70 72.33 71.93 71.53 71.13 70.73 70.33 69.93 69.53 69.13 68.73 -70 -60 76.33 75.93 75.53 75.13 74.73 74.33 73.93 73.53 73.13 72.73 -60 -50 80.31 79.91 79.51 79.11 78.72 78.32 77.92 77.52 77.12 76.73 -50 -40 84.27 83.87 83.48 83.08 82.69 82.29 81.89 81.50 81.10 80.70 -40 -30 88.22 87.83 87.43 87.04 86.64 86.25 85.85 85.46 85.06 84.67 -30 -20 92.16 91.77 91.37 90.98 90.59 90.19 89.80 89.40 89.01 88.62 -20 -10 96.09 95.69 95.30 94.91 94.52 94.12 93.73 93.34 92.95 92.55 -10 0 100.00 99.61 99.22 98.83 98.44 98.04 97.65 97.26 96.87 96.48 0 www.cypress.com -200 Document No. 001-31379 Rev. *E 6 ® PSoC 1 - Sensing - RTD Temperature Measurement Document History Document Title: AN2120 - PSoC® 1 - Sensing - RTD Temperature Measurement Document Number: 001-31379 Revision ECN Orig. of Change Submission Date Description of Change ** 1514403 JVY 09/27/2007 Re-catalogued application note. *A 3211654 PMAD / GRAA 03/31/2011 Upgraded the documentation Converted the project from assembly to C language Upgraded and tested the project with PSoC Designer 5.1 SP1 *B 3284600 PMAD / GRAA 06/16/2011 No change to spec. Updated the incorrect date mentioned on the footer of previous revision to meet CY standards. Removed the Application note number mentioned in the title. *C 4349106 PMAD 04/16/2014 Updated to new template. Completing Sunset Review. *D 4621873 ASRI 01/13/2015 ® Updated Software Version as “PSoC Designer™ 5.4” in page 1. Upgraded attached associated project with PSoC Designer 5.4. *E 4729422 DIMA 04/23/2015 ® Updated Software Version as “PSoC Designer™ 5.4 SP1” in page 1. Updated attached associated project with PSoC Designer 5.4 SP1. Completing Sunset Review. www.cypress.com Document No. 001-31379 Rev. *E 7 ® PSoC 1 - Sensing - RTD Temperature Measurement Worldwide Sales and Design Support Cypress maintains a worldwide network of offices, solution centers, manufacturer’s representatives, and distributors. To find the office closest to you, visit us at Cypress Locations. PSoC® Solutions Products Automotive cypress.com/go/automotive psoc.cypress.com/solutions Clocks & Buffers cypress.com/go/clocks PSoC 1 | PSoC 3 | PSoC 4 | PSoC 5LP Interface cypress.com/go/interface Lighting & Power Control cypress.com/go/powerpsoc Memory cypress.com/go/memory PSoC cypress.com/go/psoc Touch Sensing cypress.com/go/touch USB Controllers cypress.com/go/usb Wireless/RF cypress.com/go/wireless Cypress Developer Community Community | Forums | Blogs | Video | Training Technical Support cypress.com/go/support PSoC is a registered trademark of Cypress Semiconductor Corp. "Programmable System-on-Chip," PSoC Designer, PSoC Express, and enCoRe are trademarks of Cypress Semiconductor Corp. All other trademarks or registered trademarks referenced herein are the property of their respective owners. Cypress Semiconductor 198 Champion Court San Jose, CA 95134-1709 Phone Fax Website : 408-943-2600 : 408-943-4730 : www.cypress.com © Cypress Semiconductor Corporation, 2007-2015. The information contained herein is subject to change without notice. Cypress Semiconductor Corporation assumes no responsibility for the use of any circuitry other than circuitry embodied in a Cypress product. Nor does it convey or imply any license under patent or other rights. Cypress products are not warranted nor intended to be used for medical, life support, life saving, critical control or safety applications, unless pursuant to an express written agreement with Cypress. Furthermore, Cypress does not authorize its products for use as critical components in life-support systems where a malfunction or failure may reasonably be expected to result in significant injury to the user. The inclusion of Cypress products in life-support systems application implies that the manufacturer assumes all risk of such use and in doing so indemnifies Cypress against all charges. This Source Code (software and/or firmware) is owned by Cypress Semiconductor Corporation (Cypress) and is protected by and subject to worldwide patent protection (United States and foreign), United States copyright laws and international treaty provisions. Cypress hereby grants to licensee a personal, non-exclusive, non-transferable license to copy, use, modify, create derivative works of, and compile the Cypress Source Code and derivative works for the sole purpose of creating custom software and or firmware in support of licensee product to be used only in conjunction with a Cypress integrated circuit as specified in the applicable agreement. Any reproduction, modification, translation, compilation, or representation of this Source Code except as specified above is prohibited without the express written permission of Cypress. Disclaimer: CYPRESS MAKES NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, WITH REGARD TO THIS MATERIAL, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Cypress reserves the right to make changes without further notice to the materials described herein. Cypress does not assume any liability arising out of the application or use of any product or circuit described herein. Cypress does not authorize its products for use as critical components in life-support systems where a malfunction or failure may reasonably be expected to result in significant injury to the user. The inclusion of Cypress’ product in a life-support systems application implies that the manufacturer assumes all risk of such use and in doing so indemnifies Cypress against all charges. Use may be limited by and subject to the applicable Cypress software license agreement. www.cypress.com Document No. 001-31379 Rev. *E 8