Issue
113 December 1999
Being
Cool is Easy
A
Temperature-Sensing Control Device
THE
LCD
The
LCD is an Optrex DMC16207 2-line by 16-character display.
The device operates with either a 4- or 8-bit bidirectional
parallel data interface and three control lines. The
X-10 temperature sensor initializes the LCD to its 4-bit
mode. Only seven microcontroller I/O lines are required
in 4-bit mode instead of 11, which would be required
in 8-bit mode. An external 10 kW potentiometer controls
LCD contrast.
The
LCD accepts 8-bit ASCII data and control characters.
In 4-bit mode, two consecutive output operations are
necessary to transfer each ASCII or control character
to the display. The four data lines are bidirectional
and are also used to read busy status from the LCD.
The
LCD is not necessary to the operation of the X-10 temperature
sensor. It can be eliminated with no other modification
to the hardware or software. When present, the LCD displays
the selected house code at power-on, current local temperature
(alternating between Fahrenheit and Celsius), received
requests, and transmitted responses.
The
local temperature is displayed on the first line of
the LCD and the second line is displayed on the selected
House Code or the X-10 controller query and transmitted
responses.
The
selected House Code is displayed for about 60 s following
power-on. A query received from the X-10 controller
and the response transmitted by the X-10 temperature
sensor are displayed for about 120 s. The second line
is blanked after the specified time period has elapsed.
The LCD is controlled by the foreground software component.
The
LCD was also invaluable during debug of the X-10 temperature
sensor software. I used the second line of the display
to output information to help troubleshoot problems.
TEMPERATURE
SENSOR
The
DS1820 1-Wire digital thermometer from Dallas Semiconductor
is available in both a PR35 (3-pin) and a 16-pin SSOP
package. The DS1820 provides a 9-bit digital value that
represents the devices temperature in 0.5°C increments
over a 55°C to +125°C range.
I
used the PR35 package for the X-10 temperature sensor.
There are three connections with either package: power,
ground, and data in/out. An unusual feature of the device
is that the power connection is optional. The power
and ground pins can be tied together to operate the
device in its parasite power mode.
In
this mode, which I use in the X-10 temperature sensor,
the DS1820 steals power from the data in/out pin when
its high. The data in/out line is wired to the
16C73A Port A bit 0 (RA0) pin.
The
DS1820 temperature conversion cycle requires 500 ms.
During this time, up to 1 mA is required and the data
in/out pin must be held high by the PIC. The 4.7-kW
pull-up resistor, used when reading from the DS1820,
will not supply sufficient current during the conversion.
The X-10 temperature sensor software performs the DS1820
read temperature sequence shown in Table 2.
Reset
device, check device present response
Send skip
ROM command
Send convert
T command
Delay 500 milliseconds (while holding data in/out
high)
Reset device, check device present response
Send skip
ROM command
Send read
scratchpad command
Read scratch pad (8-bytes plus one CRC byte) |
| Table
2The temperature sensor uses 3 of the 6
DS1820 commands to read the temperature. The skip
ROM command is used to select the device in a
single-device configuration. |
The
sequence begins with a device reset performed by pulling
the data in/out line low for 720 µs (minimum 480 µs,
maximum 960 µs). The DS1820 responds with a "device
present" indication 15 to 60 µs following the release
of the data in/out line. The DS1820 pulls the data in/out
line low for 60 to 240 µs.
The
X-10 temperature sensor software checks for the "device
present" response. If no device is detected, a
software flag is set to indicate that a temperature
reading is not available, and the remainder of the read
temperature sequence is skipped.
The
sensor uses three of the six DS1820 commands. Each command
consists of 8-bits, which are written serially a bit
at a time. The bit write timing is illustrated in Figure
4. To write a one, the PIC drives the data in/out line
low for at least 1 µs and then drives the line high.
|

(Click
here to enlarge)
|
Figure
4 Command bytes are written to and data bytes
are read from the DS1820 a bit at a time. Each bit
read or write slot takes 60 µs with at least 1 µs
between slots. |
The
DS1820 samples the data in/out line between 15 and 45
µs after the PIC first drives it low. To write a zero,
the PIC drives the data in/out line low and keeps it
low for at least 60 µs. The PIC drives the data in/out
line high for at least 1 µs between bits.
Each
DS1820 has a unique serial number in built-in ROM that
enables several devices to be wired together on the
same 1-wire bus. A match ROM command identifies the
serial number of the selected device.
The
X-10 temperature sensor uses the DS1820 in a single-drop
configuration. The skip ROM command is used to select
the device in a single-drop configuration. It works
like the match ROM command without needing to provide
the serial number.
The
convert T command instructs the DS1820 to begin a temperature
conversion cycle. The conversion requires a maximum
of 500 ms during which the data in/out pin must be held
high when using the parasite power mode.
The
temperature conversion is read from the DS1820s
scratchpad memory by the last four steps in the sequence.
The DS1820 sends one CRC byte following the eight bytes
of scratchpad memory. This byte can be used to validate
the data transfer.
The
sensor software reads these nine bytes, one bit at a
time. The software saves the first two bytes, which
contain the 9-bit temperature value. The remaining six
bytes and the CRC value are discarded. The DS1820 datasheet
further details the reset, read, and write cycles, and
has information pertaining to additional features, including
the content of the remaining scratchpad memory locations.
The
bit-read timing is also illustrated in Figure 4. To
read each bit, the PIC first drives the data in/out
line low for at least 1 µs and then puts the RA0 pin
in the high-impedance mode.
The
DS1820 will drive the data in/out line low to output
a zero or put it in a high-impedance mode to output
a one. The pull-up resistor causes the data in/out line
to go high when its in the high-impedance mode.
The PIC samples RA0 15 µs from the time it drives the
line low.