This is only a preview of the January 1997 issue of Silicon Chip. You can view 24 of the 96 pages in the full issue, including the advertisments. For full access, purchase the issue for $10.00 or subscribe for access to the latest issues. Items relevant to "Control Panel For Multiple Smoke Alarms; Pt.1":
Articles in this series:
Articles in this series:
Items relevant to "Build A Pink Noise Source":
Items relevant to "Computer Controlled Dual Power Supply; Pt.1":
Purchase a printed copy of this issue for $10.00. |
Digi-Temp automatically displays temperatures
on its own readout or on your PC. Up to eight
sensor temperatures are displayed at intervals of
one second.
Digi-Temp monitors
eight temperatures
This little device will monitor & display the
temperature at eight different locations at
1-second intervals. And you can use it to
log those temperatures into your computer
for air conditioning or process control. The
temperature range is from -50°C to 99.9°C.
By GRAHAM BLOWES
80 Silicon Chip
Digi-Temp is a self-contained temperature monitor which can be used
by itself or in conjunction with your
computer for control applications. In
concept, it is similar to those el-cheapo
indoor/outdoor temperature sensors
which are frequently adver
t ised.
Those units are thermistor based and
their accuracy seems quite variable,
which is to be expected; after all they
are cheap.
The accuracy of some units, would
you believe, is also affected by temperature! Digi-Temp has none of
those problems, being a purely digital
device. It can transmit the data from
each sensor to the Rain Brain sprinkler
controller (published in the January
1996 issue of SILICON CHIP) and to
your PC.
If data transmission is not needed, no problem! Just power it with
a 12VDC plugpack and you have a
standalone unit that can be used anywhere, as it has its own LED display.
It could be installed in your car or on
a bookshelf at home.
Digi-Temp is a no-frills project. It is
just a plastic box with a 4-digit readout. There is just one PC board which
fits snugly inside the box. There are no
switches to operate. You just plug it in
and it automatically cycles through
the temperatures at eight different
locations. There is also a 25-pin D
socket for connection to the serial port
of your computer.
The data transmission is an all
ASCII string which can be received
on a normal communications program, such as Telix or the Windows
terminal program. I have written a
simple Qbasic program that could
form the basis of a simple data logger
on your PC.
As can be seen from the block diagram in Fig.1, the DS1820 temperature
sensors simply connect onto a single
wire bus (plus supply lines) wherever
a device is needed.
Temperatures from -50°C to +99.9°C
can be displayed on this unit. The accuracy of each device is ±0.5°C with a
display resolution of 0.1°C. Best news
of all is that the unit does not require
calibration of any sort; just build it
and go!
Digi-Temp uses a Z86E08 micro
controller to communicate with the
DS1820 temperature sensors and with
external devices such as your PC and
the Rain Brain sprinkler controller
referred to earlier. The data transmitted from the DS1820 has a checksum attached to it, so any errors in
transmission are detected. The same
method of checksum verification is
used when the data is re-transmitted
to your PC.
The Rain Brain will ignore any
data where the CRC (cyclic redundancy check) is wrong, as will the
Qbasic program mentioned earlier.
Further, if the Z86E08 detects a CRC
error in any of the DS1820s, it flashes
the number of the offending sensor
for a few seconds, then resets itself
and interrogates the single wire bus
+V
G
Fig.1: block diagram for the Digi-Temp. Up to eight DS1820 temperature sensors
can be daisy-chained together.
This process is quite
tricky, so I recommend you
get a copy of the data sheet to
get the full picture. It is possible to identify 75 different
one-wire devices per second.
Dallas Semiconductor has
a web site at http://www.
dalsemi.com/
The DS1820 counts the
number of clock cycles that
an oscil
l ator with a low
temperature
coefficient goes
Fig.2: this is memory map for the DS1820
through during a period
digital temperature sensor.
determined by a high temperature coefficient oscilto re-establish contact with all the
lator. The low temperature
DS1820s connected.
coefficient means that it is unaffected
by temperature, whereas the high temDS1820 temperature sensors
perature coefficient oscillator varies
Made by Dallas Semiconductor according to the temperature around it.
Corporation, the DS1820s are clever
Once a temperature conversion
little beasties. Each device has its is completed, the device places the
own unique 64-bit ROM number.
resulting 16-bit, sign-extended two’s
The first eight bits form the family complement binary number (-55 to
code, the next 48 bits is a unique
+125) into the scratchpad RAM, ready
ID number, and the last eight bits is for the master to read it (when a ‘READ
the CRC checksum of the previous
SCRATCH’ command is issued). This
56 bits. The DS1820 has nine bytes number has a resolution of 0.5°C.
of scratchpad RAM plus two bytes Greater resolution can be obtained by
of EEPROM. The EEPROM bytes are performing the calculation shown in
linked to programmable alarm trip
equation 1 below.
points (upper and lower).
This calculation uses the values left
The device has a repertoire of 11 in the counters, once a conversion
commands, five of which are ROM has been completed. Fig.2 shows the
functions while the other six are MEM- memory map of the DS1820.
ORY functions. The most complex
Circuit details
command is called ROM SEARCH.
This process enables all the connected
Fig.3 shows the circuit diagram of
devices to be identified by a process
the Digi-Temp. IC1 is a Z86E08 microof elimination.
processor clocked by an 8MHz crystal
Equation 1
Temperature = temperature read - 0.25 + [(count per °C - count remain)/count per °C]
where temperature read = (16-bit number from temperature MSB and LSB)/2
January 1997 81
Fig.3: the Z86E08 programmed microprocessor is the heart of the circuit. It
interrogates each of the temperature sensors and displays their values on the
4-digit readout. It can also send the information to a PC via an RS232 port.
which is internally divided by two for
all internal timing. Both internal timers of the Z8 are used; one to multiplex
the 7-segment LED displays via Q3-Q6
at a 1kHz scan rate and the other for
general timing duties.
IC2 converts the BCD output of port
2 (bits 0 to 4) to the 7-segment code
for the LEDs.
Op amp IC4b and Q1 form a voltage-to-current converter. The input
voltage applied to pin 3 of IC4a will
cause an equivalent voltage to be
dropped across the 150Ω emitter resistor for Q1. Using this circuit means
a fixed amount of current is always
drawn from the supply, no matter
(theoretically) what the resist
ance
82 Silicon Chip
of the wires between the Rain Brain
and the Digi-Temp. This method also
allows minimal disturbance to the 5V
supply provided by the regulator, IC5.
Links LK2 and LK3 provide baud
rate selection, although in practice
9600 baud seems to work very well,
even over distances of 100 metres.
Link LK1 was intended to be used
when the Digi-Temp was operated
without the LED displays when connected to the Rain Brain controller.
This mode, however, is not used so it
can be left out (pin 8 high).
If the Digi-Temp is only to be used
to transmit data to a PC, then the LED
displays and associated hardware can
be left off the PC board.
R14 is the 4.7kΩ pull-up resistor
associated with the DS1820 sensors.
The sensors are open Drain, meaning
that if the internal FET of any of the
connected sensors is switched on, then
a logic 0 is presented to P27.
Software
Because there is only one wire for
both transmit and receive operations,
timing is critical. The timing is divided
into two main groups, ‘read’ slots and
‘write’ slots. Refer to Fig.4 for details
of these slots.
When IC1 comes out of RESET, port
pin P27 is configured as an output.
It sends a RESET pulse out to all the
DS1820s connected to the single wire
bus. The RESET signal is a logic 0
between 480µs and 960µs long. After
this, P27 is set as an input. All connect-
Above: all the components except for
the LED displays are mounted on this
side of the PC board. Note that the
final version differs slightly from the
unit shown here.
ed DS1820s respond simultaneously
with a presence signal. The presence
pulse is a logic 0 between 60µs and
240µs long.
IC1 then issues a ‘ROM SEARCH’
command. This process is the repetition of a three step routine: read a
bit, read the complement of the just
read bit, then write a bit back to the
sensor(s). IC1 performs this routine
on every bit of the DS1820 ROM.
After one complete pass (64 cycles),
IC1 knows the contents of the ROM
in one DS1820. The rest of the connected DS1820s are identified through
additional passes. The following is a
simplified version of an example in
the data sheet.
Say we have four devices with the
following ROM code segments:
ROM1 00110101...
ROM2 10101010...
ROM3 11110101...
ROM4 00010001...
The search process is as follows:
(1). IC1 issues a RESET to the
DS1820(s). All connected DS1820s
Fig.4: because there is only one wire for both transmit and receive
operations to the DS1820 sensors, timing is critical. The timing is divided
into two main groups, ‘read’ slots and ‘write’ slots, as shown here.
January 1997 83
Fig.5: this is the component overlay for the double-sided PC board. Note that
this board is slightly different from that shown in the photos.
respond with a simultaneous presence
pulse.
(2). IC1 issues the ROM SEARCH
command.
(3). IC1 reads a bit. Each DS1820
will place the value of the first bit
of its respective ROM code onto the
bus. ROM1 and ROM4 will place a 0
whereas ROM2 and ROM3 will place
a 1. As these devices are all ‘WIRE
ANDed’ the result will be a logic 0.
IC1 now reads another bit.
Seeing that this is the ROM SEARCH
command being executed, the DS-
1820s will now place on the bus the
complement of the ROM code bit
that was previously sent. ROM1 and
ROM4 will place a 1 whereas ROM2
and ROM3 will place a 0. The result,
again, will be logic 0. Each subsequent
‘dual read’ will result in one of the
following:
00 There are still DS1820s attached
which have conflicting bits in this
position.
01 All DS1820s still coupled have a
0 bit in this bit position.
10 All DS1820s still coupled have a
This photo shows the board removed and the
rectangular cutout in the case for the DB25 socket.
84 Silicon Chip
1 bit in this position.
11 There are no DS1820s attached to
the bus.
So far, IC1 has determined that some
DS1820s have a 0 as the first bit of
the ROM code whereas the rest have
a 1 in this position. You are probably
thinking, how can this be of any use!
Well, IC1 will now write a 0 back to
the DS1820s. This will cause all the
DS1820s with 1 as the first bit of the
ROM code to switch off, which in this
example are ROMs 2 and 3. IC1 could
write back a 1, which would cause
ROM1 and ROM4 to switch off.
Step 3 is repeated again. This time
the ‘dual read’ will result in 01, which
means that all DS1820s still connected
to the bus have a 0 bit in this position.
You can see that this is the case with
ROM1 and ROM4. IC1 writes back
a 0, which keeps ROM1 and ROM4
connected.
Step 3 is repeated again. This time
the ‘dual read’ will result in 00, which
means that this ROM code position
has a conflicting bit; ie, either ROM1
has a 0 and ROM4 has a 1 (or vice
versa). In this case, ROM4 has a 0. IC1
writes back a 0. This causes ROM1 to
switch off, leaving only ROM4 still
connected. Subsequent ‘dual reads’
will result in either 01 or 10 because
ROM4 is the only device left on the
bus.
Once 64 bits have been read,
the eight received bytes are passed
through a CRC calculator, which if
correct, will yield a zero. The whole
process is repeated for the other
DS1820s. To prevent reading
the same path over and over
again, the ‘pathway’ has to
be marked in much the same
way as if you were exploring
a maze.
Each time you come to a
fork (dual read = 00, meaning 0 or 1 in a bit position),
mark it, so that next time
you encounter this fork,
take the other path (ie, write
back a 1). This path is also
marked, so that next time
you encounter a fork where
both paths are marked,
back track to the previous
fork, where there is still an
unmarked path. As noted
earlier, it is tricky!
The ROM codes of all
the detected DS1820s are
stored in the internal RAM
The PC board is
mounted upside
down in the case with
the displays facing
upwards, as shown
in this photograph.
The 25-pin D socket
connects via a standard
RS232 cable to the
serial port of your
computer.
of the Z8 controller. A maximum of 64
bytes is set aside for this task, which
is enough for eight DS1820s. Once
all connected DS1820s have been detected, the number of devices found
is displayed on the lefthand digit of
the display.
After this, all DS1820s are RESET
and the MATCH ROM code is sent
to all DS1820s. This causes all the
DS1820s to ‘sniff’ the bus for their own
unique ROM code. The ROM code of
the first device is read from RAM and
sent out on the bus (note: all data is
least significant bit first). After this,
MEMORY COMMANDS are sent to
the addressed device. In this case,
the CONVERT T command tells the
DS1820 to read the temperature and
place it into its onboard scratchpad
RAM. This takes about 500ms.
Next, the READ SCRATCHPAD
PARTS LIST
1 plastic box, 120 x 65 x 39mm
1 PC board, 113 x 63mm
1 DB25 socket with rightangle
mounting
1 3.5mm stereo socket
1 3.5mm stereo jack plug
1 8MHz crystal
Semiconductors
1 Z86E08 programmed
microprocessor (IC1)
1 4511 BCD to 7-segment
decoder (IC2)
1 MAX232 RS232 transmitter
(IC3)
1 LM358 dual op amp (IC4)
1 7805 5V 3-terminal regulator
(IC5)
1 to 8 DS1820 digital
thermometers
6 BC548 NPN transistors (Q1-Q6)
4 FND500 common cathode
7-segment displays (H1 - H4)
1 red rectangular LED (H5)
1 1N4004 silicon diode (D1)
Capacitors
1 1000µF 16VW electrolytic
1 10µF 25VW tantalum
electrolytic
4 10µF 16VW electrolytic
1 0.1µF monolithic
2 22pF ceramic
Resistors
9 10kΩ
1 4.7kΩ
1 470Ω
8 180Ω
1 150Ω
Miscellaneous
Heatshrink tubing, IC sockets,
solder.
command is sent to the DS1820. This
causes the DS1820 to send the contents
to IC1. Note that all nine bytes are
sent, even if they are not necessarily
wanted. The ninth byte is a CRC of
the previous eight bytes sent. If a CRC
error is detected, then the number of
the offending sensor is flashed in the
LHS display. After five seconds, IC1
will RESET and start again.
The DS1820 has its own inbuilt CRC
generator. This really cuts down on the
ambiguity of any data read from the
sensors – if the CRC doesn’t match,
don’t display it. Simple! The same
circuit is implemented in software in
the Z8 and the Qbasic program. Data
is fed in, LSB first. The last byte sent
by the DS1820 is the CRC. The result,
once passed through the CRC routine,
will be zero if all bits are received
correctly.
This unit is designed to work unattended, therefore the Z8 watchdog
instruction (WDT) is used. Any spikes
that upset the Z86E08 will cause it to
RESET. The WDT instruction, once
enabled, has to be ‘refreshed’ every
10ms or so. It is set up in such a way,
that the micro will RESET if it is caught
in any loop longer than required.
Many programmers misuse the WDT
instruction, simply putting it in the
timer loop, where it will be ‘refreshed’,
regardless of whether the main loop
has crashed or not. A method I have
found that seems to work OK is to
January 1997 85
Fig.6: use this template to cut the rectangular hole for the DB25 socket and for
the display window in the lid of the case.
put the WDT instruction in a timer
routine, but within a loop that always
executes, but only if a variable in the
main loop is loaded with $FF at every
reasonable opportunity. The variable
is decremented towards zero in the
timer routine, and at the same time
executing the WDT instruction. If the
variable fails to be loaded with $FF
and hits zero, the WDT instruction
is bypassed, thereby resetting the
processor.
The Qbasic program written for this
project displays eight boxes on the
screen. As the data is received from
the Digi-Temp, the box associated with
the sensor number is updated. Each
box can be given a name (eg, inside,
outside, etc) which is saved to disc.
With a little effort, a good data logger
could easily be developed from this
program.
A disc containing the full source
code (in Z8 assembler) and the Qbasic PC program (Z8temp.BAS and
Z8temp.EXE) is available – see details
in “Where To Buy The Kit”.
Construction
All the circuitry for the Digi-Temp
86 Silicon Chip
is mounted on a small PC board measuring 113 x 60mm. This mounts the
DB25 socket and the 3.5mm stereo
socket so there is no wiring except for
the three wires which run away to the
sensors. The board has corner cutouts
so that it becomes a snug fit inside the
plastic case which measures 120 x 65
x 39mm.
Fig.5 shows the component overlay for the PC board. Note that it is a
double-sided board and the four LED
displays are mounted on one side,
while all the rest of the components
are mounted on the other. Another
point which should be made is that
the PC layout in Fig.5 differs from
that of the prototype board shown in
the photos.
Two rectangular cutouts need to
be made in the case, one as a clearance hole for the bracket of the DB25
connector and the other in the lid,
for the display window. This is then
fitted with a piece of red Perspex.
Templates for the two cutouts are
shown in Fig.6.
Assembly of the PC board is straightforward although there are a few points
to be noted. Resistors R1-R7 and R13
are all bunched together so be careful
with R13 as it is 470Ω not 180Ω! The
cathodes of the rectangular LED and
D1 are denoted by the square pad, as
are the positive legs of all electrolytic
capacitors. The 3-terminal regulator
IC5 is bolted to the PC board and the
copper pattern provides a degree of
heatsinking.
Rather than use removable links,
just solder wire straps in the LK2 and
LK3 positions, and leave LK1 open.
The DB25 socket, MAX232 and capacitors C5-C8 can be left off if the unit is
not going to be used with a PC.
The PC board sits snugly on the
ribs halfway down in the case, so
there is no need to use any mounting
hardware.
Actually, as only two wires are used
for the RS232 option, the DB25 socket
could be omitted and just two wires
run directly from the X2terminals on
the board to the PC. The LED displays
are mounted on lengths of socket strip
to bring them closer to the Perspex
window.
Solder a different coloured wire to
each leg of the sensor(s) and cover each
connection with a length of suitable
heatshrink, then cover the whole with
a larger piece.
I have found that encasing the
DS1820 completely in heatsh
rink
tends to insulate it too much, so it
is better to cover the sensor to about
halfway up its body, then shrink
it. Once this is done, smear some
silicone sealant thinly around the
protruding part of the sensor to waterproof it. If the unit is to be used
outdoors, don’t use the 3.5mm plug
and socket; solder the wires direct to
the PC board. A hole is drilled for the
power\data pair.
Temperature sensor setup
There is really no setup required
when the Digi-Temp is used as a
standalone unit. Just connect a 12VDC
plugpack and switch on. When it is
first switched on, the unit will display
the number of sensors found on the
lefthand side digit, then the unit will
then display the temperature of each
one, at one second intervals.
If you want the sensors in a particular order, you will have to temporarily connect them all, then switch on
the unit. Carefully remove a sensor
while the power is on (they are open
Drain, so will come to no harm). The
display will flash the number of the
Silicon Chip
BINDERS
These beautifully-made binders
will protect your copies of SILICON
CHIP. They feature heavy-board
covers & are made from a dis
tinctive 2-tone green vinyl. They
hold up to 14 issues & will look
great on your bookshelf.
High quality
Hold up to 14 issues
The temperature sensors are wired together using a
3-way cable. Two leads are for the power supply rails
(+5V and GND), while the third is the data line.
one removed. Repeat this process for
all the sensors. It is best to mark them
with the number so that you know
the order in which to permanently
connect them.
PC operation
The data format transmitted by the
Digi-Temp is set out below (the commas are not in the data but are included
here for clarity):
(CR),n,(sign),x,x,.,x,C,C
. = decimal point ($2E); and
C = ASCII HEX No.’s 0 to 9, A to F ($30
to $39, $41 to $46)
CC is the CRC of the previous data
(but not the CR). It has to be decoded
back to its binary equivalent before it
can be passed through the CRC routine
in the Qbasic program (and the Rain
Brain).
The reason that this is done is so that
an ordinary communications program
can read the output of the RBST2. If
the straight binary CRC was transmitted, it would cause all sorts of hash
to appear on the screen. For instance,
a binary $AB is transmitted as ASCII
SC
‘AB’ ($41,$42).
Where To Buy The Kit
Price: $A14.95 (includes postage
in Australia). NZ & PNG orders
please add $A5 each for postage.
Not available elsewhere.
Silicon Chip Publications
PO Box 139
Collaroy Beach 2097
Or fax (02) 9979 6503; or ring (02)
9979 5644 & quote your credit
card number.
Use this handy form
Enclosed is my cheque/money order for
$________ or please debit my
Bankcard Visa Mastercard
Parts for the Digi-Temp are available as follows:
Item
Programmed Z86E08 microprocessor
PC board
DS1820 temperature sensor
Z8 source code disc plus Qbasic program
Full kit (includes one DS1820)
Full kit (less RS232 parts)
SILICON CHIP logo printed in
gold-coloured lettering on spine
& cover
where CR = $0D;
n = sensor number 1 to 8 ($31 to $38);
sign = + or - ($2B or $2D);
x = ASCII digits 0 to 9 ($30 to $39);
80mm internal width
Card No:
Price
$18
$15
$11
$12
$75
$60
P&P
incl.
$2
incl.
incl.
$3
$3
Payment may be made by cheque or money order to Mantis Micro Products,
38 Garnet Street, Niddrie, Vic 3042. Phone/fax 03 9337 1917.
______________________________
Card Expiry Date ____/____
Signature ________________________
Name ___________________________
Address__________________________
__________________ P/code_______
January 1997 87
|