Measuring Temperature with an NTC Thermistor — Voltage Divider and ADC Lookup Table

Introduction

When I updated the firmware for a packaging sealer, I used the temperature reading in several parts of the machine. The sealer displays the temperature at the end of each cycle. In temperature-control mode, it uses the reading to decide when to stop heating. During repeated cycles, it monitors heat buildup and adjusts the waiting time before the next cycle.

The sensor I used is a 100 kΩ NTC thermistor sold for use in 3D printers. As the thermistor’s resistance changes, so does the output voltage of the voltage divider. The microcontroller reads that voltage through its ADC. In the sealer firmware, I converted the ADC code to temperature using a lookup table prepared in advance.

This article covers how an NTC thermistor works, how to calculate temperature from resistance, and how I implemented the voltage divider and lookup table in the sealer.

NTC Thermistor Principles and Characteristics

Why does resistance decrease as temperature rises?

NTC stands for negative temperature coefficient. NTC thermistors used for temperature sensing are commonly made from semiconducting metal-oxide ceramics. As the material heats up, electrical conduction increases and its resistance falls. Murata, Operating Principles of Thermistors

The resistance change is nonlinear. A 1 °C change at a low temperature produces a different change in resistance from a 1 °C change at a higher temperature. To convert resistance to temperature, we use an equation or a table that represents the sensor’s resistance–temperature characteristic. Murata, Basic Characteristics of NTC Thermistors

What should you look for in a datasheet?

Parameter What to check
R25 The nominal resistance at 25 °C. A thermistor with R25 = 100 kΩ has a nominal resistance of 100 kΩ at that temperature.
Beta value A parameter calculated from the resistance at two temperatures. A designation such as B25/85 identifies the two temperatures used.
Resistance and Beta tolerances Sensors with the same part number can differ from the nominal resistance–temperature curve. Variations in R25 and Beta both affect the calculated temperature.
Operating temperature range The specified range under stated operating conditions. For a wired assembly, also check the ratings of the cable and insulation.
Dissipation factor and thermal time constant The dissipation factor helps estimate self-heating from the measurement current. The thermal time constant describes how quickly the sensor responds to a temperature change. Check the test conditions for both values.

The Vishay NTCLE100E3 datasheet shows how a manufacturer specifies R25, B25/85, their tolerances, and the resistance at different temperatures. Vishay, NTCLE100E3 Datasheet · TDK Electronics, NTC Thermistors — General Technical Information

According to the seller’s specifications, the thermistor I used in the sealer has a nominal resistance of 100 kΩ at 25 °C, a B25/50 value of 3950 K (±1%), and a 1 m cable. B25/50 is based on the resistance at 25 °C and 50 °C.

The image below shows the type of thermistor used in the sealer.

Why are NTC thermistors still useful?

The temperature range that matters depends on the equipment. In a heater controller, detecting a small change near the target temperature can be more important than achieving uniform sensitivity across the full range from ambient to maximum temperature. An NTC thermistor offers a large resistance change with temperature, and a fixed resistor and a microcontroller ADC are enough to build a basic measurement circuit. Texas Instruments, Monitoring NTC Thermistor Circuit With Single-Ended ADC

NTC thermistors also come in packages suited to different measurement points. A surface-mount thermistor can sit near a power device on a PCB, while a wired sensor can reach a point away from the board. Common applications include monitoring battery temperature during charging, monitoring inverter power devices, and controlling appliance temperature. Over a wide range, sensitivity varies with temperature, and sensor tolerances and mounting conditions affect accuracy. Murata, Thermistor Applications

From Divider Voltage to Temperature

Connecting the NTC voltage divider to the ADC

The diagram below shows the sealer’s temperature-sensing circuit.

I connected the NTC thermistor on the 3.3 V side and the fixed resistor R13 (10 kΩ, 1%) on the ground side. The temperature-sense signal at the junction of the two resistors goes from pin 2 of P2 to pin 9 of P1.

Position Connection in the sealer
Upper leg 3.3 V to the temperature-sense node through the NTC thermistor
Divider node Temperature-sense voltage VADC
Lower leg Temperature-sense node to ground through R13

Assuming the ADC input has a negligible effect on the divider voltage, the output is given by

VADC = VEXC × R13 / (RNTC + R13)

VEXC is the voltage applied to the divider. As the temperature rises, RNTC falls and the ADC input voltage rises. Rearranging the equation gives the thermistor resistance.

RNTC = R13 × (VEXC / VADC − 1)

When the two resistances are equal, the divider output is half the supply voltage. At that point, a given small fractional change in thermistor resistance produces the largest voltage change. A 10 kΩ fixed resistor can therefore be a suitable choice for a thermistor rated at 100 kΩ at room temperature if its resistance is near 10 kΩ in the higher temperature range of interest. Also check the ADC input voltage at both ends of that range. Analog Devices, CN0545

Using the same voltage source for the divider and the ADC reference is called ratiometric measurement. If the supply voltage changes, the divider output and ADC reference change together. Ideally, the ADC code then depends on the resistance ratio. The schematic shows a 3.3 V divider supply, and the ADC initialization comment identifies AVCC as the ADC reference. The worked example assumes both use the same 3.3 V source. Texas Instruments, SBAA338A

Converting resistance to temperature

The Beta equation

The Beta equation uses a reference resistance R0, a reference temperature T0, and the Beta value B. When R0 is R25, T0 is 298.15 K.

T = [1/T0 + (1/B) × ln(RNTC/R0)]−1

Here, ln is the natural logarithm and T is in kelvins. Subtract 273.15 to obtain degrees Celsius. The equation approximates the resistance–temperature curve with a single Beta value. Over a wide temperature range, you can estimate the approximation error by comparing the calculated values with the manufacturer’s resistance–temperature data across the range of interest. Analog Devices, CN0545

The Steinhart–Hart equation

The three-coefficient Steinhart–Hart equation represents the resistance–temperature curve as

1/T = A + BSH × ln(RNTC) + C × [ln(RNTC)]3

BSH is the B coefficient in the Steinhart–Hart equation. The three coefficients are fitted to the sensor’s resistance–temperature data. Use the same resistance unit that was used to derive the coefficients. With coefficients fitted to the sensor and the temperature range of interest, the equation can approximate the curve more closely than a single Beta value. Analog Devices, CN0545

I referred to the following online calculator while working on the sealer.

Stanford Research Systems, Thermistor Calculator v1.1

I entered three points from the resistance–temperature table for the thermistor used in the sealer. The values were 254,800 Ω at 5 °C, 100,000 Ω at 25 °C, and 43,780 Ω at 45 °C.

The resistance–temperature table is available as a download.

NTC-3950-100K R-T Table

Worked example with a 10-bit ADC

Suppose the same divider circuit as the one in the sealer produces an ADC code of 512. This example assumes an ideal 10-bit ADC with the divider supply and ADC reference sharing the same 3.3 V source. The output codes range from 0 to 1023. Here, the voltage ratio is approximated using 1024 steps. Texas Instruments, SNOAA12

Calculation step Result
ADC code → divider ratio 512/1024 = 0.5
Divider ratio → ADC input voltage 3.3 V × 0.5 = 1.65 V
Divider ratio → NTC resistance 10 kΩ × (1/0.5 − 1) = 10 kΩ
NTC resistance → temperature With R0 = 100 kΩ and B = 3950 K, the Beta equation gives approximately 87.7 °C.

This example uses the divider resistor from the sealer schematic and the nominal sensor values from the listing. The result applies the B25/50 value above the two temperatures used to derive it. Analog Devices, CN0545

For the same resistance of 10 kΩ, the online calculator returns 87.7197 °C with the Beta model and 87.7598 °C with the Steinhart–Hart model. The Steinhart–Hart result extrapolates beyond the three input temperatures of 5 °C, 25 °C, and 45 °C. Both values are model estimates. Measurement accuracy can be checked against a reference thermometer.

Building a temperature lookup table

In the sealer firmware, I stored the ADC codes corresponding to a series of temperatures. At runtime, the measured code is used to locate the relevant interval in the array without evaluating a logarithm for each reading.

The following code shows the ADC-to-temperature table used in the sealer firmware.

To build this type of table, work backward from temperature to ADC code.

  1. Choose the temperature range and interval. The sealer table covers 0 to 200 °C in 5 °C steps.
  2. Find the NTC resistance at each temperature. Use the manufacturer’s resistance–temperature data when available, or estimate resistance with the Beta equation if you know the nominal R25 and B values.
  3. Convert each resistance to an ADC code. Calculate the divider voltage, then apply the ADC reference voltage and resolution.
  4. Store the ADC codes in temperature order. With evenly spaced temperatures, the array only needs to store the codes. In the sealer, multiplying the zero-based array index by 5 gives the temperature in degrees Celsius.

These entries come from ADC_Temp_Table[41] in the sealer firmware.

Array index Temperature Stored ADC code
0 0 °C 30
10 50 °C 223
16 80 °C 451
17 85 °C 490
18 90 °C 529
20 100 °C 603
30 150 °C 853
40 200 °C 952

The 0 to 200 °C span is the conversion range defined in the firmware.

An ADC code of 512 falls between 490 at 85 °C and 529 at 90 °C. This places the reading in the 85 to 90 °C interval. For a finer estimate, linear interpolation uses the actual code difference between the two entries.

t ≈ 85 + [(512 − 490) / (529 − 490)] × (90 − 85) ≈ 87.8 °C

The 87.8 °C result illustrates interpolation between two entries from the actual firmware table. The earlier 87.7 °C result comes directly from the Beta equation.

When should you use an equation or a lookup table?

With the equation method, the MCU converts each ADC code to NTC resistance and applies the Beta or Steinhart–Hart equation. With the lookup-table method, the firmware finds the interval that contains the measured ADC code and can interpolate between two entries if the application requires a finer estimate.

Consideration Equation method Lookup-table method
Work done by the MCU Calculate resistance and evaluate a natural logarithm Look up the code and interpolate if needed
Data stored Nominal sensor values or fitted coefficients ADC codes at selected temperatures. The sealer’s 41 16-bit entries occupy 82 bytes.
Conversion accuracy Depends on how well the equation and its coefficients fit the sensor Depends on the source data, table spacing, and lookup or interpolation method
Changes to the sensor or circuit Update the sensor coefficients and divider or ADC parameters Regenerate the table for the new sensor and circuit conditions

An equation is convenient when the sensor or circuit varies across product models. If several models use different NTC thermistors or divider resistors, the same conversion routine can use different parameters for each model. An equation also works well when the sampling interval gives the MCU enough time to evaluate the logarithm.

A lookup table is convenient when the sensor and divider are fixed and the runtime conversion needs to be simple. The MCU can look up the stored ADC codes and interpolate between nearby entries if needed. The table can also incorporate manufacturer resistance–temperature data or calibration data from the sensor in its installed position. Changes to the sensor or divider require a table generated for the new conditions.

A table generated from the Beta equation inherits the equation’s approximation error. Closer table spacing or interpolation can reduce the error between entries. The accuracy of the underlying sensor model still matters. Analog Devices, CN0545 · Texas Instruments, SNOAA12

The sealer uses a fixed sensor and divider, so I used a 41-entry ADC lookup table with 5 °C spacing for the temperature display. To decide when to stop heating, the firmware could compare the measured ADC code directly with the stored target code.

In the worked example, ADC code 512 gives about 87.7 °C with the Beta equation and about 87.8 °C by interpolating between two entries in the sealer table. The two results illustrate different conversions of the same input. To compare their measurement accuracy, use a reference thermometer at the same temperature.

Measurement Error and the Sealer Firmware

Where does the error come from, and how can it be reduced?

Even with a correct conversion, the displayed temperature can differ from the temperature of the object being measured. The appropriate improvement depends on where the difference arises.

Error source Effect and ways to reduce it
Thermistor and fixed-resistor tolerances Actual resistance can differ from the nominal value, changing the ADC code at a given temperature. Use a fixed resistor with a tighter tolerance and a lower temperature coefficient, or calibrate against a reference thermometer over the range of interest.
ADC quantization and input noise The temperature change represented by one ADC count varies across the range. Choose a divider resistor that gives enough ADC resolution where it matters. Averaging or filtering can reduce fluctuations, with a trade-off in response time.
Conversion error The Beta equation approximates the sensor curve, and table spacing can introduce additional error. Compare the conversion against the manufacturer’s resistance–temperature data, then choose the table spacing and interpolation method for the required accuracy.
Self-heating The divider current dissipates power in the thermistor and can raise its temperature. Check the power dissipated and the mounting conditions. If needed, reduce the measurement current or shorten the time the divider is powered.
Mounting and thermal response Poor thermal contact can increase the temperature difference or delay the response. Keep the sensor position and attachment consistent, and check its response during heating and cooling.

When comparing an NTC reading with a reference thermometer, pay attention to where each sensor measures. A reference probe pressed against a heated surface and an NTC mounted slightly away from it may register different temperatures. Comparing the readings after the temperature stabilizes and observing the response during heating and cooling helps identify the source of the difference. TDK Electronics, NTC Thermistors — General Technical Information · Texas Instruments, SBAA338A

How the MSP430-based sealer uses the temperature reading

I used MSP430FR5729 and MSP430FR5725 microcontrollers in the sealer. Both have a 10-bit SAR ADC. The init_ADC() function configures P1.5 as analog input A5 and enables 10-bit conversion and the ADC result interrupt. When a conversion completes, ADC10_ISR() reads ADC10MEM0 into ADC_Result and sets adc_valid to indicate that a new result is available. Texas Instruments, MSP430FR572x Datasheet

The following code initializes the MSP430 ADC.

The next excerpt shows the ADC interrupt service routine.

The firmware has two arrays for different tasks. ADC_Temp_Table[] supports conversion to degrees Celsius for the display. Target_Temp_High[] stores the heating thresholds for each operating level. For example, Target_Temp_High[1] is 223, which corresponds to 50 °C in the conversion table. Storing the threshold as an ADC code lets the controller compare it directly with the measured code when deciding whether to stop heating.

The same sensor input is used to monitor heat buildup during repeated cycles, adjust the waiting time, and detect overtemperature or sensor faults. If the thermistor circuit opens, R13 pulls the sensing node toward ground. If the thermistor terminals short together, the node rises toward 3.3 V. The expected ADC code range during normal operation and the component tolerances provide a basis for detecting these faults before converting the reading to a temperature.

Conclusion

An NTC thermistor offers high sensitivity in the temperature range of interest, and a fixed resistor and a microcontroller ADC are enough to build the sensing circuit. In the sealer, I used the same input for temperature display, heating control, cooling delay adjustment, and sensor fault monitoring. Storing temperature points as ADC codes let the firmware look up the displayed temperature and compare the measured code directly with a heating threshold.

Start by deciding where to measure, over what temperature range, and how quickly and accurately the reading needs to respond. Those requirements guide the choice of thermistor, divider resistor, and conversion method. Check the temperature error and response with the sensor in its actual mounting position to determine how the reading can be used for equipment control.

댓글 남기기