APPLICATION NOTE 105
Application Note 105
High Resolution Temperature Measurement
with Dallas Direct–to–Digital
Temperature Sensors
INTRODUCTION
This application note describes the principle of opera-
tion of Dallas Semiconductor’s line of direct–to–digital
temperature sensors, and outlines a method of achiev-
ing high (<0.05°C) resolution with these devices. An
example C code listing is given for use with the DS1620.
before the gate period is over, the temperature register,
which is also preset to the –55°C value, is incremented,
indicating that the temperature is higher than –55°C.
At the same time, the counter is then preset with a value
determined by the slope accumulator circuitry. This cir-
cuitry is needed to compensate for the parabolic behav-
ior of the oscillators over temperature. The counter is
then clocked again until it reaches zero. If the gate
period is still not finished, then this process repeats.
The slope accumulator is used to compensate for the
nonlinear behavior of the oscillators over temperature,
yielding a high resolution temperature measurement
(0.5°C for almost all the products). This is done by
changing the number of counts necessary for the
counter to go through for each incremental degree in
temperature. To obtain the desired resolution, there-
fore, both the value of the counter and the number of
counts per degree C (the value of the slope accumula-
tor) at a given temperature must be known.
DIRECT–TO–DIGITAL TEMPERATURE
SENSOR PRINCIPLE OF OPERATION
The Dallas Direct–to–Digital Temperature Sensors
measure temperature through the use of an onboard
proprietary temperature measurement technique. A
block diagram of the temperature measurement cir-
cuitry is shown in Figure 1.
Each temperature sensor measures temperature by
counting the number of clock cycles that an oscillator
with a low temperature coefficient goes through during a
gate period determined by a high temperature coeffi-
cient oscillator. The counter is preset with a base count
that corresponds to –55°C. If the counter reaches zero
TEMPERATURE MEASUREMENT CIRCUITRY
Figure 1
SLOPE ACCUMULATOR
PRESET
COMPARE
LOW TEMPERATURE
COEFFICIENT OSCILLATOR
COUNTER
PRESET
SET/CLEAR
LSB
=0
INC
TEMPERATURE REGISTER
HIGH TEMPERATURE
COEFFICIENT OSCILLATOR
COUNTER
=0
STOP
030998 1/19
APPLICATION NOTE 105
INCREASING TEMPERATURE RESOLUTION
Most of Dallas’ direct–to–digital temperature sensors
provide 0.5°C resolution directly. This is accomplished
by the device determining whether to set or clear the
least significant bit (LSB), based on the actual tempera-
ture. The device attempts to keep errors within
1
/
2
LSB,
by quantizing different readings into the LSB step size.
For example, a part which is ramping up in temperature
from 25°C to +26°C, or down in temperature from –10°C
to –11°C, would exhibit this behavior:
ACTUAL
TEMPERATURE
25
25.1
25.2
25.3
25.4
25.5
25.6
25.7
25.8
25.9
26
–10
–10.1
–10.2
–10.3
–10.4
–10.5
–10.6
–10.7
–10.8
–10.9
–11
SET/CLEAR
LSB
Clear
Clear
Clear
Set
Set
Set
Set
Set
Clear
Clear
Clear
Clear
Clear
Clear
Set
Set
Set
Set
Set
Clear
Clear
Clear
DIRECT
READING
25
25
25
25.5
25.5
25.5
25.5
25.5
26
26
26
–10
–10
–10
–10.5
–10.5
–10.5
–10.5
–10.5
–11
–11
–11
calculations to achieve higher resolutions, this rounding
factor must be taken into account.
With the exception of devices intended for battery man-
agement (DS2434 and DS2435), the temperature sen-
sors can measure temperature over the range of –55°C
to +125°C in 0.5°C increments. For Fahrenheit usage, a
lookup table or conversion factor must be used.
Higher resolutions may be obtained by reading the tem-
perature and truncating the least significant bit from the
read value. From the example above, it should be
apparent that this must be done on the raw, 9–bit num-
ber, in two’s–complement arithmetic, in order for the
correct reading to result. After the truncation, the num-
ber can then be converted into a signed integer. This
value is referred to below as temp_read. The value left
in the counter can then be read by issuing a special
command protocol to the sensor. This value is the count
remaining (count_remain) after the gate period has
ceased. Reading the value of the slope accumulator (by
using another command protocol or set of protocols, as
outlined below) yields the number of counts per degree
C (count_per_degree) at that temperature. Once these
parameters are all known, the actual temperature can
be calculated from the following equation:
TEMPERATURE=temp_read–
1
/
2
LSB+(count_per_degree–count_remain)
count_per_degree
A simple routine in C, called CalcHiResTemp, is given in
the listing of Figure 7.
PROCEDURES FOR READING COUNTER
VALUES AND CALCULATING HIGH
RESOLUTION TEMPERATURE READINGS
The following is a list of procedures for performing high
resolution temperature readings from various digital
thermometers. For all parts, conversions must be done
in oneshot mode (if applicable). XXh refers to the proto-
col to send to the part; if two protocols are listed together
(e.g., 84h A0h), both protocols should be sent in the
given order, without resetting the part between proto-
cols. A variable name XXX is designated as “named
XXX.”
This example shows then that every reading is rounded
up (in absolute value) by
1
/
2
LSB. For most parts, this is
0.25°C. This is important to remember, since in doing
030998 2/19
APPLICATION NOTE 105
NOTE:
The high–resolution temperature equation is slightly dif-
ferent for the DS1821 as compared to the DS1620,
DS1623, DS1625, DS2434, and DS2435.
DS1620, DS1623, and DS1625:
1. Issue Start Convert protocol (EEh).
2. When conversion is finished, read 9–bit temperature
value (AAh).
3. Truncate half–degree bit from reading.
4. Convert truncated value from 2’s complement to
signed integer (named temp_read).
5. Read 9–bit counter
count_remain).
7. Read 9–bit counter
count_per_degree).
value
(A0h;
named
DS2434 and DS2435:
1. Issue Start Convert protocol (D2h).
2. When conversion is finished, read 8–bit temperature
value (B2h 61h).
3. Convert temperature value from 2’s complement to
signed integer (named temp_read).
4. Read 9–bit counter value (84h A0h; named
count_remain).
5. Send undocumented Load Counter protocol (84h
41h).
6. Read 9–bit counter value (84h A0h; named
count_per_degree).
7. Calculate high–resolution temperature using the
high resolution temperature equation given in the
previous section.
1
/
2
LSB = 0.25.
6. Send undocumented Load Counter protocol (41h).
value
(A0h;
named
EXAMPLE C CODE
The following example is a simple exerciser for the
DS1620 from an IBM–PC compatible computer. It reads
temperature and displays it in both the normal 0.5°C
resolution and in high resolution. The DS1620 is inter-
faced to the parallel port of the PC using the circuit
shown in Figure 2, which is the schematic of the
DS1620K demo kit.
The hardware for the DS1620K demo kit “steals” power
from a parallel port using D1, D2, D3, and C3. Not all PC
parallel ports are able to supply sufficient current to
make this hardware work, so be advised that if this cir-
cuit does not work, try connecting a +5V power source
to the +5V line in this circuit and try again. R1 and C1
serve to filter the CLK line and prevent negative under-
shoots. Likewise, C2 helps prevent negative under-
shoot on the DQ line.
The code is written in an attempt to make it easy to adapt
to any of the digital temperature sensors. All that need
be done to use it with other devices is to change the
command header file to account for the protocols and
resolution of the device being used, and change the files
which manipulate the hardware interface to the device
to account for either 1, 2 or 3–wire interfaces.
8. Calculate high–resolution temperature using the
high resolution temperature equation given in the
previous section.
1
/
2
LSB = 0.25.
DS1621, DS1624, and DS1820:
The procedure to find the high resolution temperature
parameters and the calculation to use are given in the
respective product data sheets for these products.
Note that since the DS1624 already provides a 13–bit
number with 0.03125°C resolution, no further proces-
sing is possible to achieve any higher temperature reso-
lution.
DS1821:
1. Issue Start Convert protocol (EEh).
2. When conversion is finished, read 8–bit temperature
value (AAh).
3. Convert value from 2’s complement to signed inte-
ger (named temp_read).
4. Read 9–bit counter
count_remain).
6. Read 9–bit counter
count_per_degree).
value
(A0h;
named
5. Send undocumented Load Counter protocol (41h).
value
(A0h;
named
7. Calculate high–resolution temperature using the
high resolution temperature equation given in the
previous section. Note that for the DS1821, 1/2LSB
= 0.5.
030998 3/19
APPLICATION NOTE 105
DS1620K HARDWARE SCHEMATIC
Figure 2
J1
DB25 MALE
13
25
12
24
11
23
10
22
9
21
8
20
7
19
6
18
5
17
4
16
3
15
2
14
1
+5V
D1
D2
D3
R1 220
U1 DS1620
1 DQ
VDD
2 CLK/CONV
TH
3 RST
TL
4
GND
TCOM
C2
390
µF
8
7
6
5
C3
10
µF
GND
DATA4
SEL IN
DATA3
C1
390 pF
030998 4/19
APPLICATION NOTE 105
THREEWIR.H C CODE LISTING
Figure 3
/* THREEWIR.H
This file defines the method for setting the 3–wire interface lines from an IBM–PC
compatible computer. The interface is through the parallel port. The parallel
port lines used are as follows:
/SELIN
Data4
Data3
GND
pin
pin
pin
pin
17
5
4
18
DQ
CLK
/RST
GND
The inportb, outportb, and delay functions are defined in most PC–based C compil-
ers in dos.h
*/
#include <dos.h>
#define
#define
#define
#define
#define
#define
#define
CLK_HI
CLK_LOW
RSTB_HI
RSTB_LOW
DQ_HI
DQ_LOW
READ_BACK
p_data|= 0x08; outportb(p_addr,p_data);
p_data&=~0x08; outportb(p_addr,p_data);
p_data|= 0x04; outportb(p_addr,p_data);
p_data&=~0x04; outportb(p_addr,p_data);
outportb(p_addr+2,0x02); delay(1);
outportb(p_addr+2,0x0A); delay(1);
–((inportb(p_addr+2) & 0x08) >> 3)+1
delay(1);
delay(1);
delay(1);
delay(1);
#define p_addr peek(0,0x0408) /* Finds the address of the parallel port
*/
char
p_data = 0xFF;
030998 5/19