Stamp
Figure 2. DS1620 High-Res Output.
everything is correct now. Finally, let’s put the temperature up in the Debug Terminal window:
Show_C:
DEBUG CRSRXY, 6, 2,
(tC.BIT15 * 13 + 32),
DEC (ABS tC / 10), “.”, DEC1 (ABS tC),
DegSym, CLREOL
Show_F:
DEBUG CRSRXY, 6, 3,
(tF.BIT15 * 13 + 32),
DEC (ABS tF / 10), “.”, DEC1 (ABS tF),
DegSym, CLREOL
Going Higher
To get high-resolution temperature from the DS1620,
we will proceed as before and then read two additional values: the count remaining and the slope. To do this, we will
add the following code after reading the temperature value:
HIGH DsRst
SHIFTOUT DsDQ, DsClk, LSBFIRST, [RdCntr]
SHIFTIN DsDQ, DsClk, LSBPRE, [cRem\9]
LOW DsRst
HIGH DsRst
SHIFTOUT DsDQ, DsClk, LSBFIRST, [RdSlope]
SHIFTIN DsDQ, DsClk, LSBPRE, [slope\9]
LOW DsRst
The first section reads the count register, the second
reads the slope accumulator. With these values, we can
calculate high resolution temperature with this equation:
tC – 0.25 + (slope – counts) / slope))
Note that tC in the equation above is the whole value
from the DS1620 – the half-bit is dropped (as this was
determined by estimation inside the DS1620). Here’s how
we implement the high-resolution calculation resolution in
PBASIC:
IF (sign = 0) THEN
tC = (tempIn / 2) * 100
tC = tC - 25 + (slope - cRem * 100 / slope)
tF = tC * 9 / 5 + 3200
ELSE
tC = (tempIn / 2) | $FF00 * 100
tC = tC - 25 + (slope - cRem * 100 / slope)
tF = 3200 - ((ABS tC) * 9 / 5)
ENDIF
This code starts by examining bit 15 of the value —
when bit 15 is one, the value is negative. From this bit,
we create a negative sign or space (when positive) to
precede the value. The rest is simple; we’ll divide
the [absolute] value by 10 for the whole portion, print a
decimal point, and then use DEC1 for the final digit to
display the tenths.
In order to deal with the 0.25 value in the equation, as
well as take advantage of the increased resolution offered,
everything is converted to hundredths. Other than that, you
can see that the calculation is quite straightforward and
with an adjustment to our display code (for hundredths),
the output we get looks like that in Figure 2.
A Little Help from a Friend
Figure 3. uM-FPU Connections.
F
o
r
E
l
e
c
t
r
o
n
i
c
s
NUTS & VOLTS
E
v
e
r
y
t
h
i
n
g
28
That was actually pretty easy, wasn’t it? What about
those times when we have a sensor that requires complex
calculations to convert its raw output to something we can
use? After I was satisfied with the hi-res version of the
DS1620 program, I took note of the Micromega
Corporation uM-FPU (V2.0) chip sitting on my desk. This
device — kindly sent to me by Cam Thompson — is a floating-point math coprocessor that is designed to assist
small micros like the BASIC Stamp. I’ve had the thing for
several months; I thought it was time to give it a whirl.
Following my own frequent advice, I cracked open
the uM-FPU docs and read through them. Holy smokes,
Batman, this little dude is a handful!. After my first read,
I thought my eyes were bleeding and my brain had
JULY 2005