Link here

Thermocouple Measurement Users Guide
One or two channels of temperature measurement over wide temperature ranges using Type B, E, J, K, N, R, S or T thermocouples with cold junction compensation and pre-coded thermocouple curve fitting for accurate temperature measurement.


This document describes how to use the Thermocouple Measurement Wildcard™. It provides an overview of the hardware and software for the Wildcard as well as a schematic.

The Thermocouple Measurement Wildcard is available in two configurations:

  • A single-channel version (Part# W-TCM-1) includes a board-mounted thermistor for very accurate cold junction compensation, delivering one temperature measurement channel accurate to ± 0.25 °C without the need for calibration.
  • A dual-channel version (Part# W-TCM-2) includes a board-mounted integrated circuit chip with jumper-selectable cold junction compensation for two thermocouples. This chip provides temperature measurement over wide ranges with cold junction compensation accurate to ± 4 °C, and ± 0.25 °C accuracy can be obtained with a single-point temperature calibration per channel.

The dual-channel version supports type E, J, K, R, S or T thermocouples; the single-channel version supports any kind of thermocouple. You can mix and match the Thermocouple Measurement Wildcard with any of the growing family of WildCards. The following sections provide detailed performance specifications and guide you through the Thermocouple Measurement Wildcard’s hardware and software.

 

Specifications

Thermocouple Measurement Wildcard Specifications
Channels: One (using PN W-TCM-1), or two (using PN W-TCM-2)
Accuracy
(set by cold junction compensation):
± 0.25 °C
(for W-TCM-1 uncalibrated; or W-TCM-2 with single-point calibrations).
For more details see accuracy section.
Temperature Ranges: Type B: +250 to +1820 °C
Type E: -270 to +660 °C
Type J: -210 to +870 °C
Type K: -250 to +1230 °C
Type N: -250 to +1300 °C
Type R: -50 to +1768 °C
Type S: -50 to +1768 °C
Type T: -250 to +400 °C
Analog to Digital Converter: dual channel, 16 bit accuracy, input range -56.25mV to +56.25mV, ~7 conversions/second
Wildcard Operating Temperature: 0 to +70 °C
Thermocouple Connections: Screw terminals
Current: 25 mA from 5V
Weight: 20 gram
Size : 2" x 2.5" x 0.365" (50.8mm x 63.5mm x 9.3mm)
 

Hardware

Overview

The Thermocouple Measurement Wildcard is designed to allow easy and accurate measurement of wide ranging temperatures. Thermocouple measurement is described in detail here: Using Thermocouples. Briefly, a thermocouple comprises two wires with dissimilar metals. It generates a small voltage that varies with temperature, offset by the "cold junction" potential that varies with the temperature present where the wires originate (in this case, at the Thermocouple Measurement Wildcard). Thermocouples can measure a wide range of temperatures. For example, the popular type K thermocouple can measure temperatures between -250 °C and +1200 °C. The thermocouple voltage is a nonlinear function of temperature. Accurate temperature measurement requires low-noise high-resolution (16-bit) acquisition of the thermocouple voltage, measurement of the cold junction temperature, proper compensation of the cold junction voltage, and applying an accurate curve-fit model to transform the compensated thermocouple voltage into a temperature. The Thermocouple Measurement Wildcard and its pre-coded software driver library perform these functions to simplify temperature measurement in your instrument control application.

The single channel version of the Thermocouple Measurement Wildcard (Part# W-TCM-1) uses a thermistor for cold junction temperature measurement. A thermistor is a resistive device whose resistance is a strong function of temperature. The single channel Wildcard includes a thermistor with ± 0.1 °C accuracy in a bridge circuit to enable high-accuracy measurement of the cold junction temperature (that is, at the screw terminal connection on the Wildcard). This method of cold junction compensation is far more accurate than the cold junction chip used on the dual channel version of the Wildcard. Any mention of thermistor in this documentation refers to the cold junction measurement thermistor.

The next section describes how to connect the Thermocouple Measurement Wildcard to a Mosaic controller and how to configure the Wildcard for proper operation.

 

Connecting To The Wildcard Bus of a Mosaic Controller

Wildcard Bus Loading
Installing the Thermocouple Wildcard places special limits on the combination of other Wildcards that may be installed. For detailed information, please see:
Wildcard Bus Loading Limits

To connect the Thermocouple Measurement Wildcard to the Wildcard Bus of a Mosaic controller, follow these simple steps:

With the power off, connect the Wildcard Bus on the Thermocouple Measurement Wildcard to Wildcard Port 0 or Wildcard Port 1 on your controller (these may also be called Module Port 0 or 1). The corner mounting holes on the Wildcard should line up with the standoffs on your controller.

The Wildcard Bus on the Thermocouple Measurement Wildcard is located opposite from the screw terminals.

The Wildcard Bus does not have keyed connectors!
Be careful when plugging in the Wildcard, taking special care to insert the Wildcard so that all pins are connected. The Mosaic controller and the Thermocouple Measurement Wildcard can be permanently damaged if the connection is done incorrectly.
 

Selecting the Wildcard Address

Once you have connected the Thermocouple Measurement Wildcard to the Mosaic controller or the Wildcard Carrier Board, you must set the address of the Wildcard by deciding which jumper shunts to install on J1 and J2.

The Wildcard Select Jumpers, labeled J1 and J2, select a 2-bit code that sets a unique address on the wildcard port of the Mosaic Controller. Each Wildcard port on the Mosaic controller accommodates up to 4 wildcards. Wildcard Port 0 on the Mosaic controller provides access to Wildcards 0-3 while Wildcard Port 1 provides access to Wildcards 4-7. Two Wildcards on the same port cannot have the same address (jumper settings). Table 1 shows the possible jumper settings and the corresponding addresses.

Table 1: Jumper Settings and Associated Addresses

Wildcard Port Wildcard Address Installed Jumper Shunts
0 0 None
1 J1
2 J2
3 J1 and J2
1 4 None
5 J1
6 J2
7 J1 and J2
Note that address 0 is not available on the QScreen or Handheld.
Use addresses 1 through 7 instead.
 

Connecting the thermocouple to the Wildcard

Each thermocouple has two wires, denoted + (positive) and - (negative). The polarity is important; the datasheet of the thermocouple that you select and purchase should indicate which wire is positive and which is negative. A thermocouple is attached to the Wildcard by means of a dual-screw-terminal connector. To insert a wire in the connector, use a small screw driver to loosen the screw which faces out from the board edge, insert the thermocouple wire into to the gap that has opened in the top of the connector, then tighten the screw to secure the wire. Repeat for the other thermocouple wire, observing the polarity as described below.

The single-channel configuration of the Thermocouple Measurement Wildcard (Part# W-TCM-1) has one dual-screw-terminal connector at the board edge, and the cold junction measurement thermistor is potted in the center of the terminal block between the two screws. On the screw terminal connector, the two screws face out from the edge of the board, and the thermocouple wires are inserted into the top of the connector. The silkscreen on the board has the label -TC1+ next to the screw terminal connector, where TC1 means thermocouple channel 1. The screw closest to this silkscreen label is the - (negative) side, and the other screw is the + (positive) side of the thermocouple. The thermocouple on a single-channel Thermouple Wildcard is designated as channel 1, so when the software routines are invoked, the channel parameter must be 1 for the single-channel configuration (for example, when calling the Thermo_Temperature and Thermo_Calc_Temperature functions).

The dual-channel configuration of the Thermocouple Measurement Wildcard (Part# W-TCM-2) has a four-position screw terminal block at the board edge. The silkscreen on the board has the label "-TC1+" next to the channel 1 screw terminal connector, where "TC1" means "thermocouple channel 1". The screw closest to this silkscreen label is the - (negative) side, and the next screw is the + (positive) side of the thermocouple. Looking at the screws of the screw terminals from the edge of the Wildcard, looking straight at the slotted screw heads, the channel 1 screw terminals are on the right, and the channel 2 screw terminals are on the left; the + connection of each thermocouple is made to the center two screws, and the - connection is made to the outer two screws. The channel 2 screw terminal is labeled "+TC2-" on the silkscreen; again, the outer screw closest to this silkscreen label is the - connection for thermocouple channel 2, and the next screw is the + connection for thermocouple channel 2. When calling software routines such as Thermo_Temperature and Thermo_Calc_Temperature, pass the proper channel parameter (1 or 2) to specify which thermocouple is being referenced.

As described in our Application Note Thermocouple Noise Filtering, though the Thermocouple Wildcard includes filtering capacitors, noise pickup in the thermocouple leads should be minimized by twisting the thermocouple leads together when possible (this requires the use of insulated thermocouple wire), and ideally the leads should be encased in a shielded cable with the shield grounded at only one side, near the Wildcard (the shield may be connected with a spade lug under a mounting screw at the corner of the Wildcard if convenient). Thermocouple signals are small (on the order of microvolts) so noise minimization is important.

 

Setting the thermocouple type jumpers on the dual-channel configuation

Hardware jumpers must be set to specify the types of the thermocouples on the dual-channel configuration of the Thermocouple Measurement Wildcard (W-TCM-2) so that cold junction compensation can be performed by an on-board chip called the LT1025 Micropower Thermocouple Cold Junction Compensator. Note that the single-channel version of the Wildcard uses a thermistor for cold junction compensation, and thus does not have any type selection jumpers.

The thermocouple channel 1 type selection jumpers are on H2 (Header 2) on the Wildcard, and the channel 2 type selection jumpers are on H4 (Header 4). These are adjacent to the screw terminals for their respective channels, and the silkscreen next to each header identifies the ordering of the jumpers. The type selection jumpers are arranged as shown by the following table.

Thermocouple Type Selection Header
Chan 1
Label
Type Pins Chan 2
Label
1:GND Ground 1 – 2 2:GND
1:E Type E 3 – 4 2:E
1:J Type J 5 – 6 2:J
1:K,T K or T 7 – 8 2:K,T
1:R,S R or S 9 – 10 2:R,S

Install a jumper cap on the appropriately labelled thermocouple type for each channel. For example, if the thermocouple on channel 1 is type J, install a jumper cap at H2 pins 5 and 6 (labelled 1:J). If the thermocouple on channel 2 is type K, install a jumper cap at H4 pins 7 and 8 (labelled 2:K,T). Note that some thermocouple types share one jumper setting, and also note that thermocouple types B and N are not supported by the LTC1025 cold junction compensation chip. If you wish to use a channel to measure a voltage instead of a temperature, install a jumper cap across the jumper pair labeled "GND" (pins 1 and 2 on H2 or H4).

 

Temperature measurement ranges by type

The pre-coded curve fit routines in the Thermocouple Measurement Wildcard driver can handle the following temperature ranges (in degrees Centigrade) for the specified thermistor types.

Thermocouple temperature ranges by type
Type    Minimum → Maximum °C
B +250 °C 1820 °C
E -270 °C 655 °C
J -210 °C 862 °C
K -250 °C 1200 °C
N -250 °C 1300 °C
R -50 °C 1768 °C
S -50 °C 1768 °C
T -250 °C 400 °C
 

Temperature measurement accuracy: Single-channel version

The single-channel version (Part# W-TCM-1) uses an accurate board-mounted thermistor adjacent to the thermocouple screw-terminal mount to measure the cold junction temperature. The cold junction compensation is performed mathematically by the pre-coded library of software routines. Without additional calibration, this yields an accuracy of ±0.25 °C. The cold junction thermistor itself has a specified accuracy of ±  0.1 °C, and other non-idealities and inherent noise contribute an additional ±0.1 °C error.

 

Temperature measurement accuracy: Dual-channel version

The dual-channel configuration of the Wildcard (W-TCM-2) uses the LTC1025 cold junction compensation chip to compensate the thermocouple measurement. The chip is located adjacent to the screw terminal connectors to minimize any thermal errors due to board layout. The LTC1025 introduces a measurement inaccuracy as summarized in the following table.

Cold junction temperature
25 °C 45 °C
Type Typical error Worst case error Typical error Worst case error
E 0.8 °C 2.3 °C 1.0 °C 3.5 °C
J 0.8 °C 2.3 °C 1.0 °C 3.5 °C
K 0.9 °C 2.4 °C 1.2 °C 3.7 °C
T 0.9 °C 2.4 °C 1.2 °C 3.7 °C
R 2.0 °C 3.5 °C 3.1 °C 5.6 °C
S 2.0 °C 3.5 °C 3.1 °C 5.6 °C

The accuracy can be greatly improved by use of a single-point temperature calibration for each temperature channel in use (channel 1 and channel 2). To perform the calibration, an accurate reference temperature is required. For example, a water bath could be used, and its temperature could be measured with a laboratory-grade mercury thermometer or NIST-traceable temperature measurement device. An inexpensive and easy, but less accurate, reference temperature can be obtained by freezing 1L of distilled water in a flexible container in a kitchen freezer, with a probe immersed in the center of the water at approximately 0 °C while ice forms.

To calibrate accurately, follow this procedure.

  1. Attach the thermocouple using the screw terminal, properly set the module jumpers and thermocouple type jumpers on the Wildcard, set the corresponding Wildcard address and thermocouple type constants in the software demo source code file, and compile and load the thermocouple software demo code as described in this document.
  2. Put the thermocouple into the water bath and measure the temperature (call it Tref) using the accurate thermometer or NIST-traceable temperature sensor.
  3. At your terminal, type Thermocouple_Demo to see the reported temperature measured by the Wildcard (call it Treported).
  4. Save Delta_T = Tref - Treported.
  5. In your runtime application software, add Delta_T to the measured temperature to calculate the calibrated temperature.

This calibrated runtime result will be fully accurate if the cold junction temperature (that is, the temperature of the Wildcard at the thermocouple attachment point) at runtime is the same as the cold junction temperature at calibration time. Note that the reference temperature Tref does not affect the accuracy of the calibration; rather, it is the difference between the cold junction temperature at the time of calibration versus the cold junction temperature at runtime that matters. To maximize the accuracy of the calibration, try to ensure that the temperature of the Thermocouple Wildcard at calibration time is similar to the operating temperature of the Wildcard during actual operation. For example, if the Wildcard will be operated in a closed instrument case, then the calibration should be performed with the Wildcard in the closed instrument case to maximize calibration accuracy.

If the cold junction temperature at runtime (call it Tcj) is different than the cold junction temperature at calibration time (call it Tcj_cal), the error on the calibrated temperature (after adding Delta_T) is bounded by
± Error_factor*(Tcj - Tcj_cal)
where the Error_factor is summarized by the following table.

Worst-case Error_factor after calibration
Type Error_factor
E 0.0099
J 0.0106
K 0.0123
T 0.0123
R 0.0462
S 0.0462


For example, if the calibration is performed at a cold junction temperature of 30 °C, while the runtime cold junction temperature is a full 10 °C higher at 40 °C, then for a type K thermocouple the error after a single-point calibration would be less than
± 10 * 0.0123 = ± 0.123 °C
This shows that a single-point calibration greatly increases the accuracy of the dual-channel Thermocouple Measurement Wildcard.

 

The 16-bit Analog to Digital Converter

The Analog to Digital Converter (ADC) chip on the Thermocouple Measurement Wildcard is the LTC2436-1 (datasheet). It is configured as a 16-bit (65536 count) converter with an input range from -56.25 millivolts (mV) to +56.25 mV. The ADC free-runs, automatically performing a conversion approximately every 150 milliseconds (ms). The converter ping-pongs between the two channels, alternately converting channel 1 then channel 2. Digital logic on the board captures the serial datastream coming from the chip into a pair of parallel 16-bit latches that can be read by the Mosaic controller. The ADC includes deep-notch digital filtering that discards noise at frequencies that are multiples of 50 and 60 Hertz, greatly reducing conversion noise due to powerline pickup. A flicker of ±2 counts will be observed due to inherent thermal noise in the ADC of up to 5 μV peak-to-peak.

The Thermo_Read function in the software library reads the data latches for a specified channel (1 or 2) and module number (0 through 7) and returns the latest new reading. If the specified channel's conversion result is present in the data latches, it is immediately read by the processor. If the specified channel's latched conversion result has already been read by the processor via a prior invocation of Thermo_Read, then the Thermo_Read waits and PAUSEs until the new data is present. Thermo_Read is a low-level function that is called by the higher level temperature measurement functions as explained in the next section.

In applications where a 16-bit Analog to Digital Conversion (ADC) is required covering a voltage range of -56.25 to +56.25 millivolts (mV), the Thermo_mV function can be invoked. For example, if the dual channel Thermocouple Measurement Wildcard is used, but only one temperature is being measured, the second channel can be used to measure millivolts with 16 bit resolution. If you wish to use a channel to measure a voltage instead of a temperature, install a jumper cap across the H1 jumper pair labeled "GND" (pins 1 and 2 of H2 or H4). Be sure to connect the input voltage to the negative ("-") terminal of the screw terminal header (outer screws), as each positive ("+") input is tied to ground at the screw terminal. Then simply pass to the Thermo_mV the channel number (1 or 2) and the modulenum parameter that matches the hardware settings of jumpers J1 and J2, and it returns a floating point millivolt reading in the range -56.25 to +56.25. If you are using the ADC to convert a voltage, the floating point result reported by Thermo_mV has negative polarity, so your application program must negate the result to compensate for this inversion. Thermo_mV calls the subsidiary functions Thermo_Read followed by Thermo_Counts_To_mV. Thermo_Read accepts a channel number (1 or 2) and modulenum (0 through 7) and returns an integer ADC count. Thermo_Counts_To_mV accepts the ADC count and returns the corresponding voltage as a floating point millivolt value. These functions are discussed in the next section.

 

Software

This section describes the software that enables you to control the Thermocouple Measurement Wildcard. It describes how to install the driver software, discusses the useful functions in the driver library, and presents a demonstration program that initializes the Wildcard and measures temperature in your instrumentation or automation application.

 

Installing the driver software

A package of pre-coded device driver functions is provided to make it easy to use the Thermocouple Measurement Wildcard. This code is available as a pre-compiled "kernel extension" library to C and Forth programmers.

Instructions for PDQ

Instructions for QED/Q-line

 

Overview of the thermocouple measurement driver library functions

The Thermocouple Measurement Wildcard driver code provides C language functions for initializing the hardware and acquiring cold junction compensated temperature measurements. The following functions and constants are available:

Functions Constants C Macros
Thermistor_Temperature THERMO_OVERFLOW_PLUS THERMISTOR_FAHRENHEIT
Thermo_Calc_Temperature THERMO_OVERFLOW_MINUS THERMO_CALC_FAHRENHEIT
Thermo_Cold_Junction_Model   THERMO_THERMO_TEMP_INVALID  
Thermo_Counts_To_mV THERMO_TIMEOUT
Thermo_Free THERMO_VMAX
Thermo_Grab THERMO_VMAX_TIMEOUT
Thermo_Init THERMO_VMIN
Thermistor_Model TYPE_B
Thermo_mV TYPE_E
Thermo_mV_To_Temperature TYPE_J THERMO_MV_TO_FAHRENHEIT
Thermo_New TYPE_K
Thermo_Read TYPE_N
Thermo_Status TYPE_R
Thermo_Temperature TYPE_S THERMO_FAHRENHEIT
Thermo_Try_To_Grab TYPE_T
Thermo_Wait_Til_New THERMO_CHANNEL_1 THERMO_DEGC_TO_DEGF
THERMO_CHANNEL_2 THERMO_DEGF_TO_DEGC

Many functions require parameters specifying the thermocouple type, the temperature channel number (1 or 2), and the Thermocouple Measurement Wildcard address (0 through 7). Be sure the address (aka module number) passed to the software functions corresponds to the actual hardware address jumper settings.

The Thermo_Temperature function is the highest level function in the driver library, and for many applications is the only function needed (after initialization via Thermo_Init) to acquire and compute temperature data. Thermo_Temperature acquires new data from the Wildcard's Analog to Digital Converter (ADC), runs accurate curve fits, and returns the cold junction compensated temperature as a floating point result in degrees  °C (Centigrade or Celcius).

 

Initializing the software drivers

Use Thermo_Init to initialize the software driver and the hardware on the Thermocouple Measurement Wildcard. This function should be called once after each powerup, restart or reset. Because each reading from the ADC takes about 150 milliseconds to acquire, the first reading from each channel may correspond to a voltage that was converted before the initialization was performed. In some applications, invoking the Thermo_Read function and discarding (ignoring) its return result for each channel (1 and 2) after calling Thermo_Init may be advisable.

The demo (demonstration) program below shows an example of how to use the Thermo_Init function.

 

High-level data acquisition and temperature measurement function

The Thermo_Temperature function is the highest level function in the driver library, and for many applications is the only function needed (after initialization via Thermo_Init) to acquire and compute temperature data. Thermo_Temperature acquires new data from the Wildcard's Analog to Digital Converter (ADC), runs accurate curve fits, and returns the cold junction compensated temperature as a floating point result in degrees C (Centigrade or Celcius). The function returns``THERMO_TEMP_INVALID`` (-10000. degrees) if valid ADC data cannot be acquired.

Thermo_Temperature waits (if necessary) for new ADC data, calling PAUSE to allow other tasks to run while waiting for the ADC to update. If new data (that is, data that has not yet been read by the processor) is available in the data latches, then this data is read immediately without the need to wait or PAUSE. The ADC outputs new data every 150 milliseconds (ms), ping-ponging between ADC channel 1 and channel 2. Consequently, if new data is not available in the data latches, the Thermo_Temperature routine may PAUSE up to 300 ms if the thermistor flag is true (single channel Wildcard), or up to 150 ms if the thermistor flag is false (dual channel Wildcard). The Thermo_Temperature function accepts parameters that specify the thermocouple type, channel number (1 or 2), a flag that is true for the single-channel version and false for the dual-channel version of the Wildcard, and the module number (0 - 7). These are described in turn.

The constants that specify the thermocouple type are TYPE_B, TYPE_E, TYPE_J, TYPE_K, TYPE_N, TYPE_R, TYPE_S, and TYPE_T; specify the type that corresponds to the thermocouple that you are using.

The channelnum parameter must be 1 if you have the single-channel version of the Wildcard (Part# WTCM-1). The channel number can be either 1 or 2 if you have the dual-channel version of the Wildcard (Part# WTCM-2). The channel 1 screw terminal connector is labeled TC1 on the Wildcard's silkscreen, and the channel 2 screw terminal connector is labeled TC2 on the silkscreen.

The thermistor_flag parameter passed to the Thermo_Temperature function is true for single-channel versions because these use a thermistor connected to channel 2 for cold junction temperature compensation. The thermistor_flag parameter is false for dual-channel versions of the Wildcard because this version of the Wildcard does not use a thermistor, but rather an onboard chip for cold junction compensation.

The modulenum parameter (0 through 7) must match to the hardware address jumper settings of J1 and J2 on the Wildcard.

The demonstration program below presents an example of how to use the Thermo_Temperature function to acquire and display accurate cold junction compensated temperature measurements over wide temperature ranges.

 

Temperature conversion and cold junction compensation function

The Thermo_Calc_Temperature function is useful in situations where the programmer wants to perform pre-filtering of the Analog to Digital Converter (ADC) readings, or to precisely control the timing of the temperature conversion process. Because the ADC parameters are acquired by other routines and passed to this function, Thermo_Calc_Temperature does not perform ADC coversions, wait or PAUSE. This function accepts a prior ADC reading from the thermocouple channel in millivolts, typically acquired via the Thermo_mV routine. Thermo_Calc_Temperature performs the millivolts-to-temperature conversion via a curve fit, and also applies cold junction compensation, returning the calculated temperature as a floating point value in degrees C (Centigrade or Celcius). If your application needs a function that both acquires the ADC readings and performs the temperature conversion, use the Thermo_Temperature library routine as described above.

The Thermo_Calc_Temperature function accepts parameters that specify the thermocouple type, thermocouple millivolt (mV) reading, thermistor ADC count, and thermistor flag. The function returns THERMO_TEMP_INVALID (-10000. degrees) if the thermocouple millivolt (mV) reading or the thermistor ADC count are invalid. The required input parameters are described in turn.

The constants that specify the thermocouple type are TYPE_B, TYPE_E, TYPE_J, TYPE_K, TYPE_N, TYPE_R, TYPE_S, and TYPE_T. The application program passes one of these constants to specify the type that corresponds to the thermocouple in use.

The thermocouple_mV input parameter is a voltage that has been acquired from the relevant ADC channel, typically via the Thermo_mV routine. If the single channel Wildcard is in use, the channel passed to Thermo_mV equals 1; if the dual channel Wildcard is in use, the channel number passed to Thermo_mV can equal either 1 or 2. If desired, the application program can acquire a number of readings using Thermo_mV, filter (or average) them, and pass the filtered reading to Thermo_Calc_Temperature resulting in a filtered temperature result.

The thermistor_count parameter passed to the Thermo_Calc_Temperature function can be any integer value if the dual channel Thermocouple Wildcard is in use; because this version does not use a thermistor, the thermistor_count is ignored. If the single channel Wildcard is in use, then the thermistor_count parameter is an ADC count acquired from channel 2, typically via the Thermo_Read function. This parameter represents the cold junction temperature that is measured by the on-board thermistor.

The thermistor_flag parameter is true for the single-channel version of the Wildcard because this uses a thermistor connected to channel 2 for cold junction temperature compensation. The thermistor_flag parameter is false for the dual-channel version of the Wildcard because this version of the Wildcard does not use a thermistor, but rather an onboard chip for cold junction compensation.

The Thermo_Calc_Temperature function returns THERMO_TEMP_INVALID (-10000. degrees C) if the input parameter thermocouple_mV equals THERMO_VMAX_TIMEOUT (as returned by Thermo_mV), or if the input parameter thermistor_count equals THERMO_TIMEOUT (0x7FFE). The calling function can test for a return value of THERMO_TEMP_INVALID to detect an invalid reading.

 

Other useful functions in the Thermocouple Wildcard library

The Thermo_Init function must be called at least once after each powerup, reset or restart. Pass it the module number parameter that matches the hardware settings of jumpers J1 and J2.

In applications where it is useful to measure the temperature of the single-channel version (Part# W-TCM-1) of the Wildcard board itself, the Thermistor_Temperature function can be invoked. Simply pass it the modulenum parameter that matches the hardware settings of jumpers J1 and J2, and it returns a floating point cold junction temperature in degrees C as measured by the on-board thermistor.

In applications where a 16-bit Analog to Digital Convertor (ADC) is required covering a voltage range of -56.25 to +56.25 millivolts (mV), the Thermo_mV function can be invoked. Simply pass it the channel number (1 or 2) and the modulenum parameter that matches the hardware settings of jumpers J1 and J2, and it returns a floating point millivolt reading in the range -56.25 to +56.25. For example, if the dual channel Thermocouple Measurement Wildcard is present, but only one temperature is being measured, the second channel can be used to measure millivolts with 16 bit resolution. Thermo_mV calls the subsidiary functions Thermo_Read followed by Thermo_Counts_To_mV. Thermo_Read accepts a channel number (1 or 2) and modulenum (0 through 7) and returns an integer ADC count. Thermo_Counts_To_mV accepts the ADC count and returns the corresponding voltage as a floating point millivolt value. Each of these functions may be called as needed by an application program.

See the Thermocouple Measurement Wildcard glossary for a full description of the available functions.

 

Demonstration program acquires and prints thermocouple temperatures

The following C and Forth code listings present the demonstration program for the Thermocouple Wildcard. The Thermocouple_Demo function calls Thermo_Wildcard_Init, a simple function that invokes Thermo_Init and then sets a flag that is true for the single channel version of the Wildcard, or false for the dual channel version. The Thermocouple_Demo function enters a loop that invokes the Thermo_Temperature described above, and prints the temperature(s) to the terminal. If the single channel version of the Wildcard is in use, one channel is measured and printed, and if the dual channel version is in use, both channels are measured and printed. The loop runs five times, printing temperatures once per second.

C Code for printing accurate temperature measurements

// This is a demonstration program for the Thermocouple Wildcard.
 
// Copyright 2013 Mosaic Industries, Inc.
//  Disclaimer: THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT ANY
//  WARRANTIES OR REPRESENTATIONS EXPRESS OR IMPLIED, INCLUDING, BUT NOT
//  LIMITED TO, ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS
//  FOR A PARTICULAR PURPOSE.
 
#include  <mosaic\allqed.h>    // include the standard library functions
 
#ifdef _MOSAIC_LITE
#error "The PDQ Board Lite does not support addressable Wildcards, so this demo is not applicable.  Go to Project -> Project Compiler Options and select the kernel version without the 'L' suffix to compile for the full PDQ Board."
#endif
 
#ifdef __GNUC__
#include <wtcm.h>
#else
#include "library.h"
#include "library.c"
#endif
 
 
 
// A value not used by any of the Thermocouple Wildcard constants.
#define INVALID_UCHAR '\xff'
 
 
 
unsigned char Get_User_Module_Num()
{
    unsigned char result;
 
    print( "\nEnter the module number of the Thermocouple Wildcard\n"   );
    print( "( With J1 and J2 *not* installed, the module number is 0\n" );
    print( "  if the Wildcard is installed on top of a QCard or on\n"   );
    print( "  Module Port 0 of a Docking Panel or PDQ Board ) [0-7]: "  );
 
    // Module numbers are 0 - 7, meaning only the lower three bits are used,
    // and all combinations of the lower three bits are valid module numbers.
    // ( The reason for this is the selection of Module Port 0 or 1, plus J1
    //   and J2 jumpers on each board, comprises three bits of information. )
    // This makes checking for valid module numbers very straightforward.
    do result = Key() - '0';
    while( result & '\xf8' );
 
    Emit( result + '0' );
    Emit( '\n' );
 
    return result;
}
 
 
 
unsigned char Get_User_Thcp_Channel( void )
{
    unsigned char result;
 
    print( "\nEnter 0 for single-channel Thermocouple Wildcard, or for the\n" );
    printf( "dual-channel version, enter %u for ch1, %u for ch2, %u for both: ",
            THERMO_CHANNEL_1, THERMO_CHANNEL_2, THERMO_CHANNEL_1 | THERMO_CHANNEL_2 );
 
    // Any combination of neither, one, or both of these flags is acceptable.
    do result = Key() - '0';
    while( result & ~( THERMO_CHANNEL_1 | THERMO_CHANNEL_2 ) );
 
    Emit( '0' + result );
    Emit( '\n' );
 
    return result;
}
 
 
 
unsigned char Get_User_Thcp_Type( unsigned char channel )
{
    unsigned char result;
 
    printf( "\nEnter channel %u thermocouple type [BEJKNRST]: ", channel );
 
    for( result = INVALID_UCHAR; result == INVALID_UCHAR;  )
    {
        channel = Key();  // Re-using this variable since it is only for prompt.
 
        if      ( channel == 'b' || channel == 'B' ) result = TYPE_B;
        else if ( channel == 'e' || channel == 'E' ) result = TYPE_E;
        else if ( channel == 'j' || channel == 'J' ) result = TYPE_J;
        else if ( channel == 'k' || channel == 'K' ) result = TYPE_K;
        else if ( channel == 'n' || channel == 'N' ) result = TYPE_N;
        else if ( channel == 'r' || channel == 'R' ) result = TYPE_R;
        else if ( channel == 's' || channel == 'S' ) result = TYPE_S;
        else if ( channel == 't' || channel == 'T' ) result = TYPE_T;
    }
 
    Emit( channel );
    Emit( '\n' );
 
    return result;
}
 
 
 
_Q void Thermocouple_Demo ( unsigned char thcp1_type, unsigned char thcp2_type,
                            unsigned char thcp_channel, unsigned char module_num )
{
    unsigned char i;
    float temperature1, temperature2;
 
    for( i = 0; i < 16; ++i )
    {
        // Any channel selection other than only channel 2 on the dual-channel version.
        if( thcp_channel != THERMO_CHANNEL_2 )
        {
            // thermistor_present is TRUE if zero was entered for thcp_channel.
            temperature1 = Thermo_Temperature( thcp1_type, THERMO_CHANNEL_1,
                                               !thcp_channel, module_num );
 
            if( temperature1 == THERMO_TEMP_INVALID )
                printf( "\nFailed to acquire channel %u temperature.\n", 1 );
            else
                printf( "    Channel %u temperature is: %.1f C\n", 1, temperature1 );
        }
 
        if( thcp_channel & THERMO_CHANNEL_2 )
        {
            temperature2 = Thermo_Temperature( thcp2_type, THERMO_CHANNEL_2,
                                               FALSE, module_num );
 
            if( temperature2 == THERMO_TEMP_INVALID )
                printf( "\nFailed to acquire channel %u temperature.\n", 2 );
            else
                printf( "    Channel %u temperature is: %.1f C\n", 2, temperature2 );
        }
    }
}
 
_Q void Thermocouple_Calculation_Demo (
    unsigned char thcp1_type, unsigned char thermistor_present, unsigned char module_num )
// Now obtain a temperature reading from channel 1 by performing each step explicitly,
// in order to demonstrate more low-level access to the Thermocouple Wildcard.
{
    int adc_count;
    float millivolts, temperature;
 
    // First obtain raw count from analog-to-digital converter.
    adc_count = Thermo_Read( THERMO_CHANNEL_1, module_num );
    printf( "\n    Thermocouple ADC count is: %d\n", adc_count );
 
    // These results would indicate an error, but we will continue with the calculation
    // anyway to demonstrate what the error responses of the other functions are.
    if( adc_count == THERMO_TIMEOUT        )
        print( "\nTimeout acquiring ADC count.\n" );
    if( adc_count == THERMO_OVERFLOW_PLUS  )
        print( "\nPositive overflow ADC count.\n" );
    if( adc_count == THERMO_OVERFLOW_MINUS )
        print( "\nNegative overflow ADC count.\n" );
 
    // Now convert the ADC reading to a voltage, which may or may not be
    // pre-compensated depending on whether the wildcard was manufactured
    // in the thermistor configuration or the dual-thermocouple configuration.
    millivolts = Thermo_Counts_To_mV( adc_count );
    printf( "\n    Thermocouple voltage (+/-0.005mV) is: %.3f mV\n", millivolts );
 
    // These are the possible error responses for voltage calculation.
    if( millivolts == THERMO_VMAX_TIMEOUT  )
        print( "\nVoltage calculation indicates timeout.\n" );
    if( millivolts == THERMO_VMAX          )
        print( "\nPositive overflow voltage calculation.\n" );
    if( millivolts == THERMO_VMIN          )
        print( "\nNegative overflow voltage calculation.\n" );
 
    // If the thermistor is not present, then the voltage is pre-compensated
    // in hardware, and can directly be converted into a temperature reading.
    // If the thermistor is present, the voltage is not pre-compensated.
    if( !thermistor_present )
    {
        temperature = Thermo_mV_To_Temperature( thcp1_type, millivolts );
        printf( "\n    Thermocouple temperature with on-board compensation is: %.1f degC\n",
                temperature );
        if( temperature == THERMO_TEMP_INVALID )
            print( "\nThermocouple temperature calculation indicates error.\n" );
    }
 
    // Now read the channel that has the thermistor, or would have it.
    adc_count = Thermo_Read( THERMO_CHANNEL_2, module_num );
 
    // This function can be used in place of Thermo_mV_To_Temperature to cover both cases:
    // If thermistor_present is TRUE (non-zero), then the adc_count from the thermistor
    // will be used to compensate the voltage measurement from the thermocouple.
    // If thermistor_present is FALSE (zero), then the adc_count is ignored, and the
    // voltage reading is assumed to have been pre-compensated in hardware.
    temperature = Thermo_Calc_Temperature( thcp1_type, millivolts, adc_count, thermistor_present );
    printf( "\n    Thermocouple temperature should match: %.1f degC\n", temperature );
 
    // Here we demonstrate manually applying the thermistor compensation.
    if( thermistor_present )
    {
        // If the thermistor is installed, then temperature at the board may be calculated
        // from the thermistor reading, or can be obtained in one step by calling:
        // float Thermistor_Temperature( int modulenum )
        temperature = Thermistor_Model( adc_count );
        printf( "\n    Thermistor ADC count is: %d\n", adc_count );
        printf( "\n    Thermistor temperature is: %.1f degC\n", temperature );
 
        if( temperature == THERMO_TEMP_INVALID )
        {
            print( "\nThermistor temperature calculation indicates error.\n" );
        }
        else if( millivolts != THERMO_VMAX_TIMEOUT )
        {
            // Here the thermistor compensation is performed in software.
            millivolts -= Thermo_Cold_Junction_Model( thcp1_type, temperature );
            printf( "\n    Thermistor-compensated thermocouple voltage is: %.3f mV\n",
                    millivolts );
 
            temperature = Thermo_mV_To_Temperature( thcp1_type, millivolts );
            printf( "\n    Thermistor-compensated thermocouple temperature is: %.1f degC\n",
                    temperature );
        }
    }
}
 
int main( void )
{
    unsigned char module_num, thcp_channel;
    unsigned char thcp1_type = INVALID_UCHAR, thcp2_type = INVALID_UCHAR;
 
    // Disable libc output buffering, which causes unexpected behavior on embedded systems.
    // If I/O buffering would benefit your application, see the Queued Serial demo.
    setbuf( stdout, NULL );
 
    module_num = Get_User_Module_Num();
    Thermo_Init( module_num );
    thcp_channel = Get_User_Thcp_Channel();
 
    if( thcp_channel & THERMO_CHANNEL_1 ) thcp1_type = Get_User_Thcp_Type( 1 );
    if( thcp_channel & THERMO_CHANNEL_2 ) thcp2_type = Get_User_Thcp_Type( 2 );
 
    Thermocouple_Demo( thcp1_type, thcp2_type, thcp_channel, module_num );
    Thermocouple_Calculation_Demo( thcp1_type, !thcp_channel, module_num );
 
    return 0;
}

Forth Code for printing accurate temperature measurements

ANEW THERMO_DEMO_CODE
DECIMAL \ Numbers are interpreted as decimal unless preceeded with "0x";
        \ if preceeded with "0x" they are interpreted as hexadecimal.
\ the memory map must be set up prior to loading this file
16 WIDTH !                       \ Prevent nonuniqueness
 
0 CONSTANT THERMO_MODULENUM    \ edit this to correspond to your hardware!
\ Modulenum 0 corresponds to a WildCard plugged into Module Port 0 with no jumpers set.
\ A WildCard with no jumpers plugged directly into a QCard is at Module Port 0.
 
TYPE_J CONSTANT THERMO_1_TYPE    \ edit this to correspond to your hardware!
TYPE_K CONSTANT THERMO_2_TYPE    \ edit this to correspond to your hardware!
\ NOTE: if you are using the on-board chip for cold junction compensation,
\    make sure to install the appropriate jumpers to select the thermocouple types
 
VARIABLE thermistor_present    \ must be set to TRUE or FALSE in Thermo_Wildcard_Init
                            \ to correspond to your hardware configuration
 
: Thermo_Wildcard_Init ( -- )
    THERMO_MODULENUM Thermo_Init \ one-time initialization
    TRUE thermistor_present !         \ set TRUE if you have a 1-thermocouple version
                                    \ using thermistor cold-junction compensation on channel 2
\  FALSE thermistor_present !        \ set FALSE if you have a 2-thermocouple version of the board
;
 
: Thermocouple_Demo  ( -- )
\ this routine prints the thermocouple temperature in degrees centigrade
\ to the terminal once every second for 5 seconds.
    BASE @ Locals{ &prior_base }
    DECIMAL    \ print in decimal  base
    Thermo_Wildcard_Init
    5 0        \ repeat 5 times
    DO
        THERMO_1_TYPE THERMO_CHANNEL_1 thermistor_present @ THERMO_MODULENUM
                                        ( thermocouple_type\channel_num\thermistor_flag\modulenum--)
        Thermo_Temperature     ( degrees_C_fp -- )
        CR ." TC1 temperature is: " F.    \ print thermocouple 1 result
        thermistor_present @ NOT    ( using_onboard_cold_jn_chip? -- )
        \ if using the on-board chip for cold junction compensation, print both channels
        IF
            THERMO_2_TYPE THERMO_CHANNEL_2 FALSE THERMO_MODULENUM
                                        ( thermocouple_type\channel_num\thermistor_flag\modulenum--)
            Thermo_Temperature     ( degrees_C_fp -- )
            ."       TC2 temperature is: " F.    \ print thermocouple 2 result
        ENDIF
        1000 0 DO 1000 MICROSEC.DELAY LOOP        \ wait 1 second
    LOOP
;
 

Using the demo code from C

Instructions for PDQ

Instructions for QED/Q-line

 

Using the demo code from Forth

Instructions for PDQ

Instructions for QED/Q-line

 

Glossary

Schematics and datasheets

For more detailed specifications for the input characteristics of the 16-bit A/D or the cold junction compensator IC, please consult the datasheets:

If you have any questions that can not be answered by the datasheets or the schematics, please feel free to contact Mosaic Industries.


See also →

 
This page is about: Accurate Thermocouple Measurement Data Acquisition, Cold Junction Compensation, Single or Dual Channel – Accurately measure temperatures over wide ranges using this thermocouple measurement board with on-board cold junction compensation. Connect one or two B type B, E type E, J type J, T type T, N type N, R type R, S type S, or K type K thermocouples. cold junction compensated, thermistor
 
 
Navigation