AN75511 PSoC® 3 / PSoC 5LP – Temperature Measurement with a Thermocouple Author: Praveen Sekar and Todd Dust Associated Project: Yes Associated Part Family: All PSoC 3 and PSoC 5LP parts Software Version: PSoC Creator™ 2.1 SP1 and higher Related Application Notes: AN70698, AN66477, AN60590 If you have a question, or need help with this application note, contact the author at [email protected] AN75511 explains the theory of temperature measurement with a thermocouple, and then shows how to do so with a single PSoC® 3 or PSoC 5LP – no need for external ADCs or amplifiers. To make it easy to calculate temperature from the ADC readings, PSoC Creator provides a thermocouple Component. Three example projects are included to demonstrate operation with low and high accuracy and resolution. Contents Introduction Introduction ....................................................................... 1 Thermocouples – Theory of Operation .............................. 2 Thermoelectric Effect ................................................... 2 Cold Junction Compensation........................................ 4 Measuring Thermo-emf ................................................ 4 Practical Thermocouple Measurements ....................... 5 Thermocouple Temperature Measurement with PSoC ..... 5 Hardware Used - CY8CKIT-025 EBK ........................... 5 PSoC Creator Schematic Description .......................... 6 Thermocouple - Voltage to Temperature Conversion ... 8 Firmware Flow .............................................................. 9 Performance Ranges ................................................. 10 Thermocouple Voltage Measurement Error................ 11 Cold Junction Compensation Voltage Error................ 11 Voltage to Temperature Conversion Error .................. 12 Summary ......................................................................... 13 Appendix A: Calibrating for Gain Drift.............................. 14 Worldwide Sales and Design Support ............................. 18 Temperature is one of the most common and frequently measured environmental variables. Temperature measurement is typically done using one of four sensors: thermocouple, thermistor, diode, or resistance temperature detector (RTD). The primary criteria for choosing a sensor are cost, accuracy, and temperature range. Table 1 on page 2 offers a comparison of four different types of sensors. www.cypress.com Document No. 001-75511 Rev. *C 1 ® PSoC 3 / PSoC 5LP – Temperature Measurement with a Thermocouple Table 1: Comparison of Temperature Sensors Parameter RTD Thermocouple Thermistor Diode Temperature range (0 °C) –200 to +850 –250 to +2350 –100 to +300 –50 to +150 Sensitivity at 25 °C 0.387 Ω/°C 40 µV/°C (K-type) 416 Ω/°C 250 µV /°C Accuracy High Medium to High Medium Low Linearity Good Fair Poor Good Typical cost (US $) $3–$80 $3–$15 $0.2–$10 <$0.2 Typical distance of sensing Surface mount for on-board temperature <100 meters Surface mount for on-board temperature On-board temperature Leaded for <1 meter 3- and 4-wire up to a few hundred meters Resource requirement Excitation current, amplifier, ADC, reference resistor Amplifier, ADC, voltage reference, and another temperature sensor for cold junction Excitation current, ADC, reference resistor Excitation current, amplifier, ADC Response time Slow Fast Fast Slow Computational complexity (best possible accuracy) High Very high Very high Medium Cypress Application Note AN70698 AN75511 AN66477 AN60590 Thermocouples have the largest temperature measurement range and are one of the most rugged temperature sensors making them the first choice for use in industrial and corrosive environment. This application note focuses on the K-Type thermocouple, which is a commonly thermocouple type. is called the cold junction or reference junction, and the voltage developed is called thermo-emf. Figure 1(a). Thermocouple – Seebeck Effect Metal 1 Junction 1 (Hot) Thermocouples – Theory of Operation Junction 2 Metal 2 Metal 2 Thermoelectric Effect www.cypress.com Figure 1(b). Thermocouple –Seebeck Effect Metal1 Junction 1 (Hot) Document No. 001-75511 Rev. *C Junction 2 Metal2 Metal2 - V + In 1821, Seebeck, an Estonian-German physicist discovered that when two dissimilar metals are connected, as shown in Figure 1(a), and one of the junctions is heated, there is a continuous flow of current through the loop. When the loop is broken and the voltage is measured (see Figure 1(b)), the measured voltage is directly related to the temperature difference between the two junctions. This phenomenon where a voltage is produced because of the heating of the junction of two metallic conductors is called thermoelectric effect or Seebeck effect. The junction where heat is applied is called the hot or measurement junction. The other junction 2 ® PSoC 3 / PSoC 5LP – Temperature Measurement with a Thermocouple The thermo-emf depends on the following: Metals used at the junction The absolute value of the cold junction temperature; that is, the thermo-emf produced for hot junction temperature of 100 °C and cold junction temperature of 0 °C will be different from the thermo-emf produced for hot junction temperature of 800 °C and cold junction temperature of 700 °C even though the temperature difference in both cases is 100 °C. The temperature difference between the (measurement) and cold (reference) junctions thermocouples differ in their temperature range of operation and sensitivities (voltage change per unit change in temperature, V/°C). Two major standards, IEC EN 60584-2 and ASTM E230, govern the thermocouple tolerance. The tolerance specifies the maximum error due to replacing one thermocouple with another of the same type. hot Some of the popular thermocouple types, their metal combination, temperature ranges, sensitivities, and their tolerances according to ASTM standard are listed in Table 2. As shown in Table 2, ASTM establishes two thermocouple tolerance standards, standard and special. Tolerance standards are not defined in the whole temperature range. Depending on the types of metals used, thermocouples can be classified into multiple types. The types of Table 2. Thermocouple Types Thermocouple Type Metal Content in Positive Leg Metal Content in Negative Leg Temp Range (°C) Sensitivity at 25 °C (µV/°C) Tolerance (ASTM) Temp Range (°C) Standard Special B 70.4% Platinum (Pt), 29.6% Rhodium (Rh) 93.9% Pt, 6.1% Rh 0–1820 0 800–1700 0.5% E 90% Nickel (Ni), 10% Chromium (Cr) 55% Copper (Cu), 45% Ni -270–1000 61 -200–0 1.7 °C or 1% 0–900 1.7 °C or 0.5% 1°C or 0.4% J 99.5% Iron (Fe) 55% Cu, 45% Ni -210–1200 52 0–750 2.2 °C or 0.75% 1.1 °C or 0.4% K 90% Ni, 10% Cr 95% Ni, 5% Various elements -270–1372 41 -200–0 2.2 °C or 2% 0–1250 2.2 °C or 0.75% 95.5% Ni, 4.4% Si -270–1300 -270–0 2.2 °C or 2% 0–1300 2.2 °C or 0.75% 1.1 °C or 0.4% N 84.4% Ni, 14.2% Cr, 1.4% Silicon 26 1.1 °C or 0.4% R 87% Pt, 13% Rh 100% Pt -50–1768 6 0–1450 1.5 °C or 0.25% 0.6 °C or 0.1% S 90% Pt, 10% Rh 100% Pt -50–1768 6 0–1450 1.5 °C or 0.25% 0.6 °C or 0.1% T 100% Cu 55% Cu, 45% Ni -270–400 41 -200–0 1 °C or 1.5% 0–350 1 °C or 0.75% www.cypress.com Document No. 001-75511 Rev. *C 0.5 °C or 0.4% 3 ® PSoC 3 / PSoC 5LP – Temperature Measurement with a Thermocouple The National Institute of Standards and Technology (NIST) provide the thermo-emf versus hot junction temperature data for all thermocouple types for cold junction at 0 °C. Cold junction temperature of 0 °C is chosen as reference because the thermo-emf is 0 V at 0 °C. The sensitivity of a K-type thermocouple can be found from the NIST table and is approximately 40 μV/°C for temperatures > -100 °C. The NIST tables and coefficients can be found here. Figure 2. K-type Thermocouple with Cold Junction at 0 °C Chromel Junction 1 (Hot) + - V1 V2 = 0 + Alumel Junction 2 (0°C) Alumel Chromel Junction 1 (Hot) + - V1 V2 + Alumel Alumel V =V1 - V2 If we find the cold junction temperature, the voltage V2 can be calculated from the NIST table. Therefore, in cases where the cold junction is not at 0 °C, the cold junction temperature has to be measured and the thermo-emf corresponding to that temperature has to be added to the thermocouple voltage. This procedure is called cold junction compensation. A thermistor, RTD, diode, or IC-based sensor can be used for cold junction temperature measurement. (Remember that one of these cold junction temperature measurement sensors cannot substitute a thermocouple as they cannot be used for measuring very high temperatures or used in corrosive or rugged environment). Measuring Thermo-emf + V =V1 Figure 3. Thermo-emf versus Temperature for K-type Thermocouple (Cold Junction at 0 °C) Thermo-emf has to be measured with an ADC by connecting the input leads of the ADC to the thermocouple as shown in Figure 5. Figure 5. Measuring Thermo-emf 60 Chromel 50 Thermoemf in mV Junction 2 (ambient temperature) + An ice bath usually provides the 0°C reference temperature. NIST provides a table as well as polynomial coefficients to convert thermo-emf to temperature and vice versa. Figure 2 shows a K-type thermocouple heated at one junction and maintained at 0 °C in the other junction and Figure 3 shows the thermo-emf versus hot junction temperature graph for a K-type thermocouple for cold junction at 0 °C. Figure 4. Cold Junction not at 0 °C Junction 1 (Hot) 40 30 20 10 0 + - V1 V2 + Alumel Alumel Junction 3 +V3 - V4 + Junction 4 Copper -10 -300 0 300 600 900 Temperature in °C By measuring the thermo-emf using an ADC, we can easily determine the temperature. However, there is one catch; the cold junction has to be maintained at 0 °C to use the NIST tables. It is impractical to provide an ice bath and in most cases the cold junction will be at ambient temperature. + V =V1 - V2 + V3 - V4 - Copper 1200 Cold Junction Compensation Junction 2 (ambient temperature) The input (copper) leads of the ADC form two more junctions (thermocouples) (copper-alumel) adding two more voltages, V3 and V4 to the equation. V3 and V4 are in opposite directions and they will have the same magnitude as long as both junctions are at the same temperature. Hence we need to ensure that the two inputs into the ADC are at the same temperature so that the thermo-emf remains unchanged. If the cold junction temperature is not equal to 0 °C, the cold junction will also develop a thermo-emf, V2, as shown in Figure 4, reducing the measured voltage, V. To properly measure the hot junction temperature, the cold junction voltage, V2, has to be added to the final voltage, V. www.cypress.com Document No. 001-75511 Rev. *C 4 ® PSoC 3 / PSoC 5LP – Temperature Measurement with a Thermocouple Practical Thermocouple Measurements In practical thermocouple measurements, the two metals are joined at the junction and the junctions at the open-ends (junctions 2 and 3) form the cold junction as shown in Figure 6. It can be shown that the circuits in Figure 5 on page 4 and Figure 6 are equivalent. The voltage V measured by the circuits in Figure 5 and Figure 6 are equal as long as the temperatures of junctions 3 and 3 are equal in Figure 5 and temperatures of junctions 2 and 3 are equal in Figure 6. The Isothermal Block is a key piece of thermocouple design. This block ensures that the ADC inputs are at the same temperature, and it also ensures that the cold (reference) junction sensor is also at that same temperature. Care should be taken to design an isothermal block that sufficiently keeps the temperature the same. Often times this involves limiting air flow over the isothermal block. projects are explained in detail in Performance Ranges section. Hardware Used - CY8CKIT-025 EBK The CY8CKIT-025 PSoC precision analog temperature sensor EBK is used in the example project. This EBK provides four temperature sensors — thermocouple, thermistor, RTD, and diode. In addition, interface slots let you plug in your own thermocouple, thermistor, RTD, and diode. The EBK can be connected to the CY8CKIT-001 PSoC Development Kit (DVK), CY8CKIT-030 DVK, or the CY8CKIT-050 DVK. Figure 7 shows the kit. For more details on the kit, go to www.cypress.com/go/Cy8CKIT-025. Figure 7. PSoC Precision Analog Temperature Sensor EBK Figure 6. Practical Thermocouple Isothermal Block Chromel Copper Junction 2 Junction 1 (Hot) + - V1 + V Junction 3 Alumel Copper Reference Junction temperature sensor Figure 8. Thermocouple Section of the EBK Measuring temperature using a practical thermocouple involves the following steps: 1. Measure thermocouple voltage (VTC) 2. Measure cold/reference junction temperature (Tref) 3. Convert the cold junction temperature to compensation voltage (Vref) 4. Add the cold junction compensation voltage to the thermocouple voltage (V = VTC + Vref ) 5. Convert the voltage to temperature. Thermocouple Temperature Measurement with PSoC This application note has three example projects (TC_HighEnd, TC_MidEnd, and TC_LowEnd) that showcase thermocouple temperature measurement using PSoC. The projects display thermocouple temperature on an LCD. The signal chain for all the projects is the same. This section describes the mid-end thermocouple (TC_MidEnd) project in detail. Differences between the www.cypress.com Figure 8 shows the thermocouple portion of the kit. A K-type thermocouple connector is provided. The cold junction sensor, DS600 IC, is placed very close to the cold junction terminals. Silk marked U1 shows the position of IC on the board. Ideally an isothermal connection should be provided between the cold junction sensor and the cold junction terminals as shown in Figure 6. This requires a material with very good thermal conductivity providing a thermal connection between the thermal pad of the IC and the cold junction terminals. In cases where this is not possible, we can have the cold junction sensor placed very close to the cold junction terminals as it has been done in CY8CKIT-025. The temperature difference between the cold junction terminals and the IC is expected to be around 0.5 °C in this case. Note that the thermistor, RTD, or diode on board can also be used for cold junction temperature measurement. The kit project gives you the option of using thermistor for cold junction compensation. Similarly you can also use RTD or Document No. 001-75511 Rev. *C 5 ® PSoC 3 / PSoC 5LP – Temperature Measurement with a Thermocouple diode for cold junction temperature measurement. Cypress application notes 'AN66477 - Temperature measurement with a thermistor', 'AN70698 - Temperature measurement with an RTD', and 'AN60590 - Diode temperature measurement' explain thermistor, RTD, and diode temperature measurements with PSoC in detail. However, these temperature sensors (RTD, Thermistor, and Diode) are farther from the cold junction than the IC and the temperature difference between the cold junction and these sensors will be higher if there is airflow. With no significant airflow, the temperature difference between the cold junction terminals and the other sensors is expected to be less than 1 °C. details on different ways to measure offset. Offset in this case is measured using ADC channel four see Figure 9. Filtering the Thermocouple Output The thermocouple output is filtered using a software IIR filter to reduce the noise and improve the noise free temperature resolution. The Temperature Resolution section in page 10 explains the ADC configuration and the filter used in the project in detail. PSoC Creator Schematic Description Figure 9 shows the thermocouple measurement circuit (PSoC Creator schematic). The circuit has a five-channel ADC, the Thermocouple Component described on page 8, and a character LCD. The five ADC channels and their purpose are listed in Table 3. Table 3. Five ADC Channels Channel Connection Measurement 0 Thermocouple Thermo-emf 1 IC voltage output Cold junction temperature 2 Thermistor voltage Cold junction temperature 3 Thermistor ref Cold junction temperature 4 Short Offset As shown in Table 3, both a thermistor and IC are used for measuring cold junction temperature. A switch is used in the project to select between the two cold junction sensors. Make sure the cold junction sensor is isothermal with the cold junction. Additional resistors are used around thermocouple to add a small 15 mV bias to the negative lead of the thermocouple. This has been done to ensure that the voltage at both ADC terminals is positive at the most negative temperature. For example, at -270 °C the thermocouple gives an output voltage of -6.458 mV and by having the 15 mV bias voltage, we ensure PSoC pins see a positive voltage. These resistors have been populated on the CY8CKIT-025. Offset Cancellation K-type thermocouple has a typical sensitivity of around 40 µV/°C. Even a 40 µV offset results in 1 °C temperature error. Hence it is important to eliminate offset. Offset cancellation is done by correlated double sampling (CDS). CDS is a technique where the offset is measured and subtracted after every voltage reading. CDS also removes offset drift and reduces low frequency noise but also reduces the ADC sample rate by 50 percent. Offset can be measured in a number of ways. See AN66444 - PSoC® 3 and PSoC 5LP Correlated Double Sampling for www.cypress.com Document No. 001-75511 Rev. *C 6 ® PSoC 3 / PSoC 5LP – Temperature Measurement with a Thermocouple Figure 9(a). Thermocouple Measurement Circuit Figure 9(b). Thermocouple Measurement Circuit www.cypress.com Document No. 001-75511 Rev. *C 7 ® PSoC 3 / PSoC 5LP – Temperature Measurement with a Thermocouple Thermocouple measurement circuit (Figure 9) is used to measure thermocouple voltage (VTC) and cold junction temperature (Tref). The APIs provided by the thermocouple component are used to obtain cold junction compensation voltage (Vref) and the actual temperature. The details of the thermocouple component are discussed in the following section. The component configuration dialog, used to enter the thermocouple type and user parameters is shown in Figure 11. Figure 11. Thermocouple Component Configuration Dialog Thermocouple - Voltage to Temperature Conversion The steps to compute the thermocouple temperature involves conversion of cold junction temperature to equivalent cold junction compensation voltage and converting the thermo-emf to temperature. NIST provides both polynomial coefficients and tables for voltage to temperature conversion and vice versa. The NIST tables and coefficients can be found here. L U T ve r s u s P o l y n o m i a l For the same accuracy, using lookup table (LUT) is both memory and computation intensive compared to using polynomials. Table 4 shows a comparison between the accuracy and number of CPU cycles (approximate) taken for computing temperature using polynomial (ninth order) and a look up table (80 elements) for a K-Type thermocouple. Table 4. Accuracy versus Number of CPU Cycles Accuracy No of CPU cycles 80 element LUT + piecewise linear approximation <0.2 °C 8000 Polynomial <0.07 °C 5000 (best case) One polynomial does not fit the whole temperature range. Multiple polynomials should be used in different temperature ranges to get good accuracy. A PSoC Creator component is provided to you for simplifying these conversions. Thermocouple Component The thermocouple component provided with this application note simplifies voltage to temperature conversion and vice versa by providing the two APIs given below. int32 Thermocouple_1_GetTemperature(int32 voltage) int32 Thermocouple_1_GetVoltage(int32 temperature) Choose the thermocouple type and the calculation error budget. The component will automatically choose the best polynomial (among NIST standard polynomial ,7th order and th 5 order polynomials) for the chosen error budget. The configuration dialog will display a graph showing temperature calculation error versus temperature. This is the error due to polynomial approximation and the associated arithmetic. The maximum calculation error in the whole temperature range is also displayed. Figure 11 shows that the maximum temperature calculation error caused by the component for K-type thermocouple is -0.07 °C. On building the project, the component generates the following APIs. It is assumed that the thermocouple is named Thermocouple_1. int32 Thermocouple_1_GetTemperature(int32 voltage) int32 Thermocouple_1_GetVoltage(int32 temperature) After measuring the cold junction temperature, use the Thermocouple_1_GetVoltage ()API to obtain the cold junction compensation voltage. This API takes cold junction temperature as input (in 1/100th of °C) and returns cold junction compensation voltage (in microvolts). The following figure shows the thermocouple component symbol. Figure 10. Thermocouple Component Symbol www.cypress.com Document No. 001-75511 Rev. *C 8 ® PSoC 3 / PSoC 5LP – Temperature Measurement with a Thermocouple After you have the final thermo-emf (VTC + Vref), use the Thermocouple_1_GetTemperature () API to obtain temperature. This API takes thermo-emf (in microvolts) as input and returns temperature (in 1/100th of °C). The following code snippet shows how the two APIs are used: void main() { int32 coldJnTemp, tcColdJnuVolt, tcHotJnuVolt, tcuVolt, tcTemp ; /* Measure cold junction temperature. The function MeasureColdJnSensorTemp() returns cold junction temperature */ coldJnTemp = MeasureColdJnSensorTemp(); /* ColdJunctionTempTomVolt() API is used to convert temp to microvolts */ tcColdJnuVolt = Thermocouple _1_GetVoltage (coldJnTemp); /* FindHotJnmVolt() API finds the hot junction voltage in millivolts */ tcHotJnuVolt = FindHotJnuVolt(); /* Add cold junction compensation voltage to hot junction voltage */ tcuVolt = tcColdJnuVolt + tcHotJnuVolt; /* mVoltToTemp() API is used for converting thermo emf to temperature */ tcTemp = Thermocouple_1_GetTemperature (tcuVolt); } The datasheet associated with the component gives more details on the thermocouple component implementation and the number of CPU cycles taken by the APIs for different orders of the polynomial. Temperature error depends on several factors apart from voltage to temperature conversion error. The thermocouple customizer shows only the error due to voltage to temperature conversion and does not take the other errors into account. If your required accuracy is 2 °C, make sure the thermo-emf to temperature conversion error is less than one-tenth of the total error budget to accommodate other errors. The other errors are discussed in Temperature Accuracy section. Firmware Flow The firmware flow for mid and low-end project is given in the flow chart below. Firmware flowchart for high-end project is given in appendix. An interrupt is triggered when a switch is pressed (see Figure 9 (b) on page 7). A flag is toggled in the interrupt service routine (ISR) changing the cold junction temperature source between IC and thermistor. The APIs generated by the thermocouple component are used for converting thermocouple voltage to temperature and vice versa. Figure 12. Firmware Flow Start Y Is flag = 1? N Use thermistor to measure Cold Junction(CJ) temperature Use IC to measure Cold Junction(CJ) temperature Convert CJ temperature to CJ compensation voltage. Read Hot Junction voltage, perform CDS and filter Add Hot junction voltage to CJ compensation voltage Convert sum voltage to temperature(T) The thermocouple component is available in Thermal management section of the component catalog. Is Hot jn Voltage < - 10mV ? Y Display broken thermocouple alert N END www.cypress.com Document No. 001-75511 Rev. *C 9 ® PSoC 3 / PSoC 5LP – Temperature Measurement with a Thermocouple Broken Thermocouple If the thermocouple wire breaks, the small negative bias we apply to the negative terminal of the thermocouple connector (see Figure 9 (a) on page 6) takes the ADC voltage to a large negative value. Checking the thermocouple output voltage for a large negative value (<10 mV) helps us to detect a broken thermocouple connection. The project associated with the application note detects a broken thermocouple connection and displays a broken alert in the LCD if the thermocouple is broken. Testing the Project 1. Plug the CY8CKIT-025 PSoC precision analog temperature sensor EBK to PORT E of PSoC 3 Development Kit (DVK) CY8CKIT-030 or PSoC 5 Development Kit (DVK) CY8CKIT-050. 2. Build the attached project and program PSoC device 3. The LCD displays thermocouple temperature and cold junction temperature 4. Press SW2 on the DVK to toggle the cold junction temperature source between thermistor and IC Multiple Thermocouples You can use multiple thermocouples in your design. The number of thermocouples that you can use is limited only by the number of GPIOs (input/output terminals) available in PSoC. If you are using multiple thermocouples of the same type, one thermocouple component will be sufficient and the APIs generated by that component can be reused for all the thermocouples. If you are using multiple thermocouples in your project and have more than one thermocouple type, one component per type should be used in your project. For instance, if your project has three K-type thermocouples, two J-type thermocouples, and one T-type thermocouple, you need to use three thermocouple components, one for each type (J, K, and T). Performance Ranges Thermocouple based temperature sensing market can be categorized into three segments based on performance specifications: High-end, mid-end, and low-end market segments. Table 5 gives the classification. Table 5. Thermocouple Performance Ranges Market segment Resolution* (°C) Accuracy* (°C) High 0.01 0.1% Mid 0.1 0.2 – 0.5% Low >0.1°C >0.5 °C Temperature Resolution In this section, we’ll see how PSoC 3 and PSoC 5LP can be used to address all the three segments. High End A resolution of 0.01 °C in -200 °C to 1370 °C temperature range requires minimum 157000 levels (18-bits). Temperature range -200 °C to 1370 °C corresponds to voltage range -5.891 mV to 54.88 mV. Temperature resolution of 0.01 °C corresponds to voltage resolution of 400 nV (sensitivity = 40 μV/°C). The ADC should have 400 nV voltage resolution and a minimum of 18-bits. Using the ADC in +/-0.064 V range and 20-bit resolution gives a voltage resolution of 122 nV. But, the noise-free voltage resolution is much higher than the theoretical resolution. The 20-bit ADC used in +/-0.064 V range gives a 0.01 °C resolution with a few flickering digits. A firmware IIR filter (See AN2099) is added to stabilize the reading to 0.01 °C resolution The firmware IIR filter used has an attenuation factor of 64. From AN2099 table 1, we see that the temperature settling time (0.1%) would be 441 cycles. For the project (TC_HighEnd) attached to this application note, the cycle time is about 50 ms resulting in a temperature settling time of 22 s. The IIR filter has a feed forward term that ensures that the temperature settles to within 2 °C in 50 ms. That is, if the source temperature changes from 50 °C to 150 °C, the temperature shown by PSoC will reach 148 °C in 50 ms and 149.9 °C in 22 s. Mid End A resolution of 0.1 °C in -200 °C to 1370 °C temperature range requires minimum 15700 levels (14-bits). Temperature resolution of 0.1 °C corresponds to voltage resolution of 4 uV (sensitivity = 40 μV/°C). The ADC should have 4 uV voltage resolution and a minimum of 14-bits. Using the ADC in +/-1.024 V range and 16-bit resolution gives a voltage resolution of 3.125 uV. A firmware IIR filter (See AN2099) is added to stabilize the reading to 0.1 °C resolution. The firmware IIR filter used has an attenuation factor of 32. From AN2099 table 1, we see that the temperature settling time (0.1%) would be 219 cycles. For the project (TC_MidEnd) attached to this application note, the cycle time is about 50 ms resulting in a temperature settling time of 10 s. The IIR filter has a feed forward term that ensures that the temperature settles to within 2 °C in 50 ms. That is, if the source temperature changes from 50 °C to 150 °C, the temperature shown by PSoC will reach 148 °C in 50 ms and 149.9 °C in 10 s. * Resolution is generally specified only for temperatures >-100 °C. Accuracy doesn’t include the sensor accuracy and is usually specified with a fixed offset such as, 0.1% or 1°C whichever is greater Accuracy is also specified at a specific operating temperature such at 25 °C +/- 3 °C. www.cypress.com Document No. 001-75511 Rev. *C 10 ® PSoC 3 / PSoC 5LP – Temperature Measurement with a Thermocouple Low End Generally low-end thermocouple temperature sensing devices have a resolution of 1 °C. A resolution of 1 °C in -200 °C to 1370 °C temperature range requires minimum 1570 levels (11-bits). Resolution of 1 °C corresponds to voltage resolution of 40 uV (sensitivity = 40 μV/°C). The ADC should have 40 uV resolution and a minimum of 11bits. Using the ADC in +/-0.064 V range and 12-bit resolution gives a voltage resolution of 31 uV. A firmware IIR filter (See AN2099) is added to stabilize the reading to 1 °C resolution. A 16-bit ADC or higher can be used without a firmware filter. But using 12-bit ADC allows the usage of lower cost PSoC devices. T e m p e r a t u r e Ac c u r a c y Thermocouple temperature accuracy can be calculated by calculating the effect of the individual errors that occur during measurement and conversion. To understand the different errors consider the equation used, thermocouple component API, to obtain the final temperature: Th = Thermocouple_1_mVoltToTemp(VTC+Vref) Equation 1 where Th is the thermocouple temperature; VTC is the thermocouple voltage measured; Vref is the cold junction compensation voltage; Thermocouple_1_mVoltToTemp() function performs the voltage to temperature conversion. Vref = Thermocouple_1_ColdJunctionTempTomVolt(Tref) Equation 2 where Tref is the cold junction temperature. A temperature error can result from one of the factors: 1. Measured thermocouple voltage, VTC. 2. Cold junction compensation voltage, Vref 3. Voltage to temperature conversion Each of the factors is discussed in detail in the following section. Thermocouple Voltage Measurement Error Thermocouple voltage measurement error is primarily due to ADC offset error, gain error, and INL error. Offset Error The ADC offset error leads to incorrect thermocouple voltage measurement. Offset cancellation is done by correlated double sampling (CDS) as explained in Offset Cancellation in page 6. Gain Error The ADC gain error also leads to incorrect thermocouple voltage measurement. PSoC 3 or PSoC 5LP delta sigma ADC is factory calibrated for gain error in a subset of ADC configurations. It is calibrated to 0.2% gain error in +/1.024 V range. This 0.2% gain error also includes the ADC www.cypress.com reference error. AN68403 – Analog signal chain calibration lists the factory calibrated ADC configurations and explains how to perform calibration on uncalibrated ADC ranges. 0.2% gain error results in 0.2% error in the measured voltage. The error due to 0.2% gain error at various temperatures is shown in Table 6. If the ambient temperature (temperature of the PSoC device) is different from 25 °C, ADC gain drift causes additional error. PSoC 3 or PSoC 5LP delta sigma ADC has a gain drift of 50 ppm/°C. It will be 2000 ppm or 0.2% for an ambient temperature of 65 °C or -15 °C. Table 6 again shows the error due to 0.2% gain drift at 65 °C. Table 6. Temperature Error Caused by Gain Error / Drift Thermocouple Temperature (°C) Error due to 0.2% Gain Error or Gain Drift (°C) -250 -3 -100 0.2 0 0 100 0.2 250 0.5 500 0.95 1000 1.9 1300 3 AD C I N L The INL of an ADC at any point is the difference between the ideal ADC count and the actual ADC count at that point after gain and offset corrections have been done. The datasheet specifies the maximum INL of all points across Process, Voltage, and Temperature (PVT). PSoC 3 ADC has an INL of +/-32 LSb in ±1.024 V mode; 32LSb corresponds to 64 μV for 20-bit resolution and ±1.024 V range. This error of 64 μV corresponds to temperature error of 1.5 °C (for temperatures > -100 °C). Note that these are worst-case errors. We have used the worst-case INL across PVT and used it for error calculation. This is a pessimistic approach and is done to indicate the worst-case limits due to INL. Practically, the error due to INL will be much lower. For a typical INL of around 4 LSb, the temperature error due to INL will be <0.2 °C (for temperatures > -100 °C). Cold Junction Compensation Voltage Error Error in cold junction compensation voltage is due to the error in the measured cold junction temperature or error in temperature to voltage conversion. The Thermocouple_1_ColdJunctionTempTomVolt() function ensures almost zero error because of temperature to voltage conversion. The cold junction temperature error depends on the sensor used for cold junction compensation. A 1 °C error in cold Document No. 001-75511 Rev. *C 11 ® PSoC 3 / PSoC 5LP – Temperature Measurement with a Thermocouple junction temperature causes approximately the same error in the measured hot junction temperature for temperatures > -100 °C (1 ± 0.2 °C). Error Source Maximum Error value at 500°C (K-Type) Maximum Error Value at 100 °C (K-type) Maximum Error Value at 500°C (K-Type) Calibrated Gain drift (Ambient temp = 25 °C) 0 °C 0 °C 0°C Gain drift (Ambient temp = 65 °C) 0.95 °C 0.2 °C As good as the external reference drift ADC INL** 1.5 °C 1.5 °C 1.5°C Error due to cold junction temperature error Same as cold junction temperature error Same as cold junction temperature error Same as cold junction temperature error Error due to Thermocouple tolerance (Special) 1.1°C 1.1 °C 1.1 °C Voltage to temperature conversion error 0.05 °C 0.05 °C 0.05 °C Voltage to Temperature Conversion Error Voltage to temperature conversion error is due to the polynomial approximation error or the LUT approximation error. Thermocouple_1_mVoltToTemp () API ensures that this error is less than 0.05 °C in most cases. All K-type thermocouples do not follow the NIST thermo-emf versus temperature data accurately. Thermocouple tolerances provided by two major standards IEC EN 605842 and ASTM E230 are given in Table 2. Table 7 gives the temperature error due to various components at 500 °C and 100 °C. As seen from the table, thermocouple tolerance is the biggest source of error. Table 7 lists all possible error sources for a K-Type thermocouple. Column 3 shows the error with a one-time gain calibration performed and reference drift calibration performed. High End To achieve 0.1% accuracy, we have to perform a onetime gain calibration (PSoC is factory calibrated for 0.2% accuracy only in the +/-1.024 V range). The project, TC_HighEnd, allows the user to perform one-time calibration and store the calibration constant in EEPROM. With ambient temperature, PSoC gain error drifts at 50 ppm/°C (This includes ADC and Reference). While this is good for most high-end application, there may be a few applications that require better temperature performance. For such application, we can use an external reference and calibrate the gain drift. Appendix A: Calibrating for Gain Drift explains this procedure and also provides the flowchart for the high end project. Mid and Low End For Mid and low end applications, PSoC can directly be used without any calibration. The projects (TC_MidEnd, TC_LowEnd) associated with the application note demonstrate that. Table 7. List of all Possible Errors in Thermocouple Temperature Measurement at 500 °C and 100 °C Error Source Maximum Error value at 500°C (K-Type) Maximum Error Value at 100 °C (K-type) Maximum Error Value at 500°C (K-Type) Calibrated Offset Error/drift* 0 °C 0 °C 0°C Gain Error 0.95 °C 0.2 °C As good as the calibration source www.cypress.com * The assumption is that CDS measurements are being done. ** The ADC INL error indicates the worst case limit. The actual temperature error will be much lower than 1.5 °C depending on the INL at that point. For a typical INL of around 4 LSb, the temperature error due to INL will be <0.2 °C. Temperature Test Temperature test results performed on the TC_MidEnd project at different temperatures is given Table 8. The temperature measured by thermocouple is compared to the temperature displayed by a standard thermometer (accuracy ±0.5 °C). A precision temperature forcing system (air flow) is used to set various temperatures. The accuracy results are shown in Table 8. Column 1 shows the temperature set on the temperature forcing system, column 2 shows the temperature displayed by the standard thermometer, column 3 shows the thermocouple temperature, and column 4 shows the temperature error. The temperature test performed on high-end project is given in appendix. Document No. 001-75511 Rev. *C 12 ® PSoC 3 / PSoC 5LP – Temperature Measurement with a Thermocouple Table 8. Accuracy Test Simulated Thermo-emf (mV) Expected Temperature (°C) Obtained Temperature (°C) Error (°C) 3.663 89.5 89.4 0.1 Temperature Source (°C) Standard Thermometer (°C) Thermocouple (°C) Temperature Error (°C) -40 -39.5 -39.7 0.2 4.712 114.9 114.9 0 -20 -19.5 -19.5 0 9.582 235.9 235.8 0.1 0 -0.2 -0.7 0.5 19.58 475 4.9 0.1 25 24.8 25.2 -0.4 28.76 691.2 691.0 0.2 40 39.4 39.6 -0.2 39.54 955.7 955.4 0.3 60 59.1 59 0.1 49.816 1227 1226.6 0.4 80 78.9 78.7 0.2 100 98.8 98.2 0.6 120 118.8 118.2 0.6 As seen from Table 8, the temperature error is <1 °C in -40 °C to 120 °C. Thermocouple Signal Chain Test Temperature test includes the temperature error caused by the thermocouple tolerance too. As shown in Table 7, the thermocouple tolerance is the biggest error of all. We can test the accuracy of the signal chain by feeding a millivolt source input to the thermocouple connectors and noting down the resultant thermocouple temperature shown by PSoC. The mV source voltage is then measured with a multimeter and the expected temperature is calculated from the measured voltage using NIST tables. The cold junction temperature is forced to 0 °C while performing this test. Table 9 shows the signal chain accuracy results for a sample board. Summary Thermocouples are the sensors of choice in industrial environment and for measuring temperatures >850 °C. Thermocouples require high-resolution ADC, and require another temperature sensor for measuring cold junction temperature. PSoC 3 or PSoC 5LP delta-sigma ADC and the thermocouple component make it easy to measure thermocouple temperature accurately. About the Author Name: Praveen Sekar Title: Applications Engineer Background: Praveen holds a Bachelors degree in Electronics and Communication from the College of Engineering, Guindy, Chennai. He focuses on analog modules in PSoC. Contact: [email protected] Table 9. Signal Chain Accuracy Results Simulated Thermo-emf (mV) Expected Temperature (°C) Obtained Temperature (°C) Error (°C) -4.695 -141 -141.1 0.1 -3.666 -103.7 -103.7 0 -2.575 -69.6 -69.5 -0.1 -1.741 -45.9 -45.7 -0.2 -0.654 -16.8 -16.7 -0.1 0 0 0 0 0.666 16.7 16.7 0 1.754 43.5 43.4 0.1 2.58 63.5 63.5 0 www.cypress.com Document No. 001-75511 Rev. *C 13 ® PSoC 3 / PSoC 5LP – Temperature Measurement with a Thermocouple Appendix A: Calibrating for Gain Drift To meet the performance of high-end temperature controllers a onetime calibration is required. In some cases a temperature calibration is also required. The project (TC_HighEnd) performs both calibrations. Figure 14 provides the firmware flowchart of the project. This has the same flow as that of the earlier projects except for two additional steps, 1. Onetime calibration 2. Check ambient temperature and perform gain calibration In TC_HighEnd project, gain drift calibration is performed if the ambient temperature changes by 5 °C. The condition for performing temperature calibration can be changed to periodically doing it based on a timer interrupt or a combination of temperature or time or always or whatever is desired. One Time Calibration The one time calibration first asks for 0v to be applied to the thermocouple input. The best way to do this is to short the two inputs of the thermocouple connector together. Since the negative input of the thermocouple is biased at 15 mV we can do this with the assurance that the value won’t float. Next the one time calibration asks for a full scale input. The ADC is configured for +/-64 mV. So supply an accurate calibration voltage of less than 64 mV. This calibration voltage should be applied across the thermocouple inputs. We also need to change the define FULL_SCALE to match the value of your calibration reference. This define is defined in main.h. If for example your calibration voltage is 63.209 mV then change the define to the following: /* Calibration input in microvolts */ #define FULL_SCALE 63209 After you have completed the zero and full scale calibration the system reads the Gain Drift Calibration reference. If you don’t wish to calibrate for gain drift remove the code from the project. Gain Drift Calibration The internal reference drift is 20 ppm/°C. We can calibrate the gain drift out using the following procedure. 1. Using a 1.024 V external reference (LM4140), generate ~50 mV voltage using a low tempco resistor divider (10 ppm/°C). We generate 50 mV to calibrate the +/-0.064 V range, which is used for the thermocouple 2. Measure the generated 50 mV (Vr) immediately after production cal at room temperature 3. Store the value of Vr in EEPROM 4. Whenever the temperature increases by 5 °C, measure the 50 mV reference (Vt) and compute Vr/Vt. The cold junction sensor can be used to measure the internal board temperature. (The condition in step 3 can be anything, such as whenever the temperature increases by 1 °C or at periodic time duration based on a timer interval or always) 5. Multiply all subsequent ADC readings by Vr/Vt Calculations Let’s use 1 k and 20 k resistances to generate the reference voltage of ~50 mV Vr = 1.024 * R1/(R1+R2) = 48.7 mV For the worst case tempco error, consider a temperature of +/-60 °C from room temperature. For 10 ppm/°C (0.001%) resistor, the worst case error at 60 °C deviation from room temperature is 0.06% The worst case voltage reference error happens when the tempco is 10 ppm/°C for R1 and -10 ppm/°C for R2. At 60 °C, the worst case reference drift = 0.11% With 10 ppm/°C resistors, we’ll be able to achieve 0.11% gain drift with temperature. With 5 ppm/°C resistors, we’ll be able to achieve 0.057% gain drift with temperature. Using Projects with Development Kits The projects TC_MidEnd and TC_LowEnd work directly on CY8CKIT-030 PSoC 3 development kit and CY8CKIT050 PSoC 5LP development kit. To use the TC_HighEnd project with PSoC 3 and PSoC 5LP development kits follow these steps. Gain drift with temperature has two parts to it. 1. ADC reference gain drift 2. ADC modulator gain drift The total gain drift (ADC reference + modulator) is characterized at 50 ppm/°C when using internal reference. www.cypress.com Document No. 001-75511 Rev. *C 14 ® PSoC 3 / PSoC 5LP – Temperature Measurement with a Thermocouple Figure 13. Development Kits LM4140 5 ppm/°C resistors on prototyping space feeding ~49 mV to port 0_7 • Populate LM4140 (3 ppm/°C) reference on CY8CKIT-030 (position U6). Populate R34 (0 Ω), C24 (1 uF) and R37 (0 Ω) on CY8CKIT-030. Now, the 1.024 V reference is available on pin 3[2]. It can be used as external reference as well. • In the prototyping space, add a resistor divider from pin 3[2] to ground to reduce 1.024 V down to 48.7 mV. Choose R1 = 20 k (0.1%, 5ppm/°C drift) and R2 = 1 k (0.1%, 5 ppm/°C drift) • Connect the 48.7 mV input to pin 0_7. Test Results Table 10. Sample Test Results after Calibrating PSoC 3 Device with Agilent 34411A Input Voltage (uV) Expected Temperature (°C) Actual Temperature (°C) Error (%) 54527 1361.43 1361.4 -0.002 45083 1099.05 1098.99 -0.006 32438 779.64 779.63 -0.001 23539 567.92 567.96 0.008 9140 224.95 224.97 0.009 2230 55.04 55.06 0.037 912 22.8 22.15 -2.859 0 0 0.12 NAN www.cypress.com Document No. 001-75511 Rev. *C 15 ® PSoC 3 / PSoC 5LP – Temperature Measurement with a Thermocouple Figure 14. TC_HighEnd Project Flowchart Start Calibrate? N Y Perform one time offset and gain calibration and store gain and offset calibration constants in EEPROM Update offset and gain calibration constants from EEPROM Has cold jn temp changed by 5C ? Y Update gain calibration N Is flag = 1? Y N Use IC to measure Cold Junction(CJ) temperature Use thermistor to measure Cold Junction(CJ) temperature Convert CJ temperature to CJ compensation voltage. Read Hot Junction voltage, perform CDS, calibration and filter Add Hot junction voltage to CJ compensation voltage Convert sum voltage to temperature(T) Is Hot jn Voltage < 10mV ? Y Display broken thermocouple alert N END www.cypress.com Document No. 001-75511 Rev. *C 16 ® PSoC 3 / PSoC 5LP – Temperature Measurement with a Thermocouple Document History Document Title: AN75511 - PSoC® 3 / PSoC 5LP – Temperature Measurement with a Thermocouple Document Number: 001-75511 Revision ECN Orig. of Change Submission Date Description of Change ** 3571217 PFZ 04/03/2012 New application note *A 3811884 PFZ 11/26/2012 Updated title to “PSoC 3 and PSoC 5LP – Temperature Measurement with a Thermocouple”. ® Updated Associated Part Family as “All PSoC 3 and PSoC 5LP parts”. Updated Related Application Notes as “AN75511, AN66477, AN60590”. Updated Introduction. Updated Thermocouple Temperature Measurement with PSoC (Updated PSoC Creator Schematic Description (Updated Table 3, updated Figure 9), updated Thermocouple - Voltage to Temperature Conversion (Updated LUT versus Polynomial (Updated Table 4), updated Thermocouple Component (Updated Figure 10 and Figure 11)), updated Performance Ranges (Updated Temperature Resolution (description)), updated Voltage to Temperature Conversion Error (Updated Table 7)). Removed Appendix. Replaced PSoC 5 with PSoC 5LP in all instances across the document. *B 3993370 TDU 05/07/2013 *C 4153444 TDU 10/10/2013 Updated Voltage to Temperature Conversion Error (description (Added Three Performance Projects namely High, Mid, Low)). Added Appendix A: Calibrating for Gain Drift. www.cypress.com Updated attached Associated Project. Document No. 001-75511 Rev. *C 17 ® PSoC 3 / PSoC 5LP – Temperature Measurement with a Thermocouple 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 cypress.com/go/plc 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. 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, 2012-2013. 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-75511 Rev. *C 18