Temperature, A/D and Digital I/O System
Peter H. Anderson
pha@phanderson.com, http://www.phanderson.com
915 Holland Road, Bel Air, MD 21014
Introduction.
This kit is the product of many efforts by many of my undergraduate electrical engineering
students at Morgan State University.
I try to have my students develop useful educational packages which help hobbyists do something
they would not otherwise be able to do. This effort has been made possible by a generous grant
from the XEROX Corporation.
If you are not entirely satisfied, please return it to the above address for a full refund. The idea
here is to foster tinkering, not to take someone's money for something that doesn't do the job for
them.
Overview.
The Temperature, A/D and Digital I/O System was designed to interface with a PC (or other
computer) COM port, a terminal, modem or terminal node controller (TNC) using an RS232
Interface, 9600 baud, 8 data bits, no parity. No flow control is provided.
When power is applied to the unit, it will automatically boot. A manual reset, the application of a
momentary ground on PIC terminal 1, is provided for possible use during debugging. However,
during normal operation, this manual reset should not be necessary.
Commands are issued by the PC (or similar) and the unit performs the directed action and returns
a result to the PC.
The unit provides for eight general purpose input and outputs. Any of these may be configured as
an output one, output zero or as an input (high impedance).
The unit provides eleven 12-bit A/D converter channels. On command, a single ended A/D
conversion is performed on the indicated channel and the result is returned to the PC.
Further, the unit provides the capability of interfacing with up to 256 DS1820 1-W temperature
devices. These are divided into four "runs" or "banks" and each bank may accommodate up to 64
DS1820 devices. Normally, all DS1820 devices are configured in the parasitic power mode. That
is, the power required by the DS1820's is derived from the data lead. Thus, a single pair (data and
ground) is run to each of up to 64 devices. Typically, each run should be limited to 200 feet.
Two of the runs or banks may be configured in an extended mode using P82B715 bidirectional
transceivers, one at the control unit and another at the distant cluster of DS1820's. Using this
technique, we have been able to reliably communicate over distances exceeding 1000 feet.
The unit provides the capability of performing a "search ROM" function so as to obtain the unique
64-bit serial number associated with each DS1820 on each run. These serial numbers are stored
in EEPROM and are subsequently used by the unit in addressing a specific DS1820. This
initialization process need only be performed when a DS1820 is either added or removed from the
system.
This is a kit of parts suitable for assembly on a solderless breadboard. You may wish to later
stabilize the assembly using wirewrap construction or etching a printed wiring board.
Specifications.
The following specifications are extracted from data sheets and are thought to be accurate. Note
that we simply do not have the development resources to verify all specifications.
You may wish to consult the actual data sheets;
PIC16C73A PIC - http://www.microchip.com
DS275 RS232 Transceiver - http://www.dalsemi.com
24LC16B EEPROM - http://www.microchip.com
TLC2543CN A/D - http://www.ti.com
DS1820 Temperature Sensor - http://www.dalsemi.com
P82B715 Range Extender - http://www.philips.com
The unit must be powered by a single +5 VDC capable of providing 50 mA plus the current
associated the the general purpose outputs with an accuracy of five percent. Note that a 7805T
regulator in a TO-220 package are more than adequate. This regulator is typically less than
$0.50.
The ambient temperature of the components comprising the control unit; DS275 transceiver,
PIC16C73A PIC, 24LC16B EEPROM, TLC2543CN A/D and P82B715 should be in the range of
0 to 70 degrees C. This is not considered to be unduly restrictive as the control unit is co-located
with the controlling PC or similar.
General Purpose IOs.
The eight general purpose outputs are capable of sourcing or sinking 25 mA. Note that all
outputs may be simultaneously sourcing or sinking this maximum.
When a GPIO is configured as an input the input leakage is less than 1 uA when the driving
voltage is in the range of 0 to 5 VDC. If the input voltage is greater than +5V or less than
ground, a means must be made to limit the current to 20 mA. (This discussion includes a
discussion of how this may be limited to less than 1 mA using a series limiting resistor).
A/D.
Total Unadjusted Error - 1.75 LSB.
Channel Leakage - 10 uA max. Thus, it is suggested that the source resistance of the interfacing
sensor be less than 1K. This may be easily realized using a single operational amplifier in a
voltage follower configuration.
V_ref Leakage 2.5 uA max.
To avoid damage to the TLC2543, input voltages should be in the range of -0.3 to 5.3 VDC.
The TI data sheet is extremely vague in describing the values of V_ref+ and V_ref-, simply
indicating they should be close to +5 and near ground, respectively. Whether a 2.5V precision
reference could be used as V_ref+ so as to achieve 4096 bands over the range of 0.0 to 2.5 VDC
or similarly use a 2.5 V reference as V_ref- so as to achieve 4096 bands over the range of 2.5 to
5.0 is an open question.
DS1820.
Accuracy.
0 to 70 degrees C +0.5, -0.5 degrees C
-55 to 0 +1.0, -2.0 degrees C
70 to 125 +2.0, -1.0 degrees C
Note. There have been a number of postings on http://www.deja.com noting that over time,
moisture can get into the device and cause a falsely low reading. I have not observed this, but
there have been enough posts to convince me this is a problem that users should be aware of.
Thus, in applications where moisture is present, use your imagination in sealing the DS1820.
Resolution.
0.03 degrees C
Maximum Distance from PC to DS275.RS232 transceiver.
12 Feet
Maximum Distance from Processor to Remote Sensors.
This is very hard to say. Our experience has been that when range extension is not used, we can
reliably communicate over 200 feet of very poor quality cable. With range extension, we can
reliably communicate over 1000 feet.
Note that if a cable run is extended to the point that the communication is unreliable it will impact
communication with all DS1820 devices on the same run.
Noise such as that generated by an arc welder or RF transmitter as might be encountered in an
amateur radio installation can present a problem as many of the standard techniques for reducing
such noise; series inductance and shunt capacitance, cannot be used as these techniques impact the
rise and fall time of the digital signals used in communicating with the DS1820. The best advise
we can give is to use twisted pair. Consider, however, that this situation is no different than a
computer network using CAT 5 cable.
Content of the Kit.
Please take a moment to familiarize yourself with content of the kit.
1 PIC16C73A PIC Processor, 28-pin DIP
1 4.0 MHz Ceramic Resonator, 3-pin SIP
1 SIP Resistor Network, 4.7K, 8-pin SIP
1 10K Resistor
1 LED with Integrated 330 Ohm Resistor
1 DS275 RS232 Transceiver, 8-pin DIP
1 TLC2543CN A/D, 20-pin DIP
1 24LC16B EEPROM, 8-pin DIP
4 330 Ohm for Series Limiting on Data Lead to DS1820s
10 330 Ohm for general use
10 10K Ohm for general use
10 0.047 uFd ceramic capacitor for noise filtering on A/D
10 100K Ohm for noise filtering on A/D
1 Logic Probe
Logic Probe.
A logic probe is provided to aid in the debugging process. Take a few moments to assemble it
and familiarize yourself with its operation. The LED is on when the probe is at a logic one, off
when at logic zero and dim when open. The LED provides a momentary flash when there is a
state change.
Replacement Parts.
If you accidentally burn out a component, please send me e-mail. In offering this package, we are
striving to make a few dollars to keep our development program going. However, there is no joy
in your heartache and if you should burn out the PIC, the replacement price will be the cost of the
PIC plus a $2.00 programming charge. But, please recognize this is for replacement parts and not
for folks striving to sidestep purchasing the entire package.
Theory of Operation.
I have attempted to weave the theory of operation of the unit in the following assembly section.
Additional sections are provided to elaborate on the use of the general purpose IOs and A/D. In
addition, a compendium of commands and responses is provided.
Assembly.
Overview (Figure #1).
Figure #1 provides a near complete schematic of the Temperature, Data Acquisition and Digital
IO unit. It is presented for understanding of the entire unit. Additional figures expand on this.
The processor is a PIC16C73A in a 28 pin DIP. Note the circuitry associated with the processor
is +5VDC on terminal 20, ground on terminal 10, a 4.0 MHz resonator and a 4.7K pullup resistor
to +5VDC on /MCLR (terminal 1).
Normally, it should not be necessary to reset the processor. Normally, the processor boots and
begins running when power is applied. However, it may be manually reset by momentarily
applying a ground at terminal 1.
Communication with a PC or similar is facilitated with a DS275 which converts R232 levels from
the PC to TTL and TTL from the PIC to RS232 levels for the PC. Note that the DS275 "steals"
the negative potential required for generating a RS232 logic one from the PC's TxD terminal.
This avoids multiple supplies or charge pumps and bulky capacitors used by the familiar
MAX232.
Eight general purpose IO leads are provided. These may individually configured as either outputs
in a logic one or zero state or as inputs. When in the input mode, no internal pull up resistors are
provided.
The 12-bit A/D converter is implemented using a Texas Instruments TLC2543CN in a 20-pin
DIP. The 11 analog inputs, V_ref+ and V_ref- are not shown in this figure.
Four PIC I/O leads are used for interfacing with DS1820 digital thermometers. Up to 64 DS1820
devices may be placed on each of these four bank leads, thus permitting up to 256 unique devices.
Normally, all DS1820s on all four of the banks must be operated in the parasitic power mode.
That is, only the signal lead and ground are run to each device of the devices within a bank. The
DS1820 is not powered by a remote +5 VDC source.
However, the design permits the use of P82B715 range extenders on banks 2 and 3. When these
extenders are used, the DS1820s on those banks must be powered with +5 VDC. The operation
of the PIC is somewhat different when using range extension and this option is selected by
grounding input RC4 on terminal 15.
The serial numbers of the DS1820's are saved in the 24LC16B (2048 X 8) EEPROM in an 8-pin
DIP. Each DS1820 is identified with a unique 64 bit (eight byte) address. Note that 256 devices
times eight bytes equals the capacity of the EEPROM.
Note there are seven 4.7K pullup resistors associated with the PIC16C73A; two for the I2C bus
associated with the 24LC16B EEPROM, four with the Dallas 1-W interface and one with
/MCLR. Note how these are all located on adjacent PIC terminals (terminals 1-7) which allows
for the use of a single seven resistor SIP network to implement all of these resistors.
There is one orphan on RC4 which didn't quite fit in the plan. This is implemented with a single
10K discrete resistor. There is no magic in this value, but 10K was selected over 4.7K to avoid
confusing the SIP network and this lone discrete resistor in this discussion.
Note there is a single LED on RC5. This is provided for testing.
PC Interface (Figure #2).
Figure #2 illustrates the basic processor, test LED and MAX232 level shifter plus the 7-resistor
SIP.
Locate the SIP resistor network such that terminal 1 of the SIP (marked with a dot or similar)
overhangs terminal 1 of the PIC by one place. That is, terminal 2 of the SIP is connected to
terminal 1 of the PIC.
Note that the 4.0 MHz resonator in a three pin SIP is symmetrical. Connect the center terminal to
ground and the two outer terminals to terminals 9 and 10 of the PIC.
Note that the test LED contains an internal 330 Ohm limiting resistor. It is connected directly
from PIC terminal 16 to ground.
Testing.
When completed, apply power and look for smoke. Hopefully, you don't see any.
Connect the unit to a PC or similar and configure a terminal emulator program. I use
"HyperTerm" which is a part of Windows 95. Configure as a "direct connection", 9600 baud, 8
data bits, no parity and one stop bit, no flow control.
When idle, verify PC lead TxD (term 7 on the DS275) is at an RS232 logic one. This is usually
less than -3.0 VDC. Verify RX, term 18 on the PIC is a TTL logic one (near +5 VDC).
Verify TX, term 17 on the PIC is at a TTL logic one. Verify terminal 5 on the DS275 is at an
RS232 logic one, less than -3 VDC.
When idle, the PIC is awaiting a command from the PC. This is implemented by continually
calling a routine to fetch a character with a timeout of nominally ten seconds. As a debugging
tool, the test LED is momentarily flashed (20 ms on) each time this fetch routine is called. Thus,
when idle, you should note a brief "blip" on the test LED about every ten seconds.
If this is occurring, the processor is running correctly. If not, check the power connections to the
PIC and the 4.0 MHz ceramic resonator.
From "HyperTerm", enter a "return". A prompt ">" should appear. If so, this verifies the PIC
and the RS232 communications including the DS275 is operational.
Note that when a string is received by the processor, the Test LED will rapidly flash a number of
times.
Note that the TEST LED is a simple "confidence tool". When idle, it will periodically flash one
time every 10 seconds to let you know the processor is running. When a string is received it will
flash rapidly a number of times. Further, when initializing the temperature system (discussed
below), the EEPROM is erased which takes about seven seconds. The LED blips occassionaly
during this time to assure you the processor is working. Whether you leave this Test LED in
during actual operation is your call.
If you do not receive a ">" in response to sending a "return", use the logic probe. Point A should
normally be at an RS232 logic one (less than -3.0 VDC) and the probe should be off. When you
send a character using HyperTerm you should see a state change (LED flash). Point B should
normally be at a TTL logic one (LED on). When you send a character, there will be a state
change and the probe LED should flash.
Similarly, when the PIC sends the ">", points C and D should cause the probe LED to briefly
flash.
General Purpose IO Leads (Figure #3).
Note that no additional circuitry is added in this figure.
From HyperTerm send the command;
S0
meaning to set GPIO 0 to a logic one. Verify GPIO 0 is near +5VDC using the logic probe.
The unit will respond to the PC with;
S0 1
Note that the format of the response is the command followed by the current state of the GPIO,
which is of course a 1. (Not terribly useful! This format was used to provide some commonality
between all commands associated with the unit).
From HyperTerm, send the "clear" command;
C0
The PIC will respond with;
C0 0
Use the logic probe to verify GPIO 0 is near ground.
Note that any of the eight GPIO leads may be similarly configured as an output logic one or zero
by sending either Sp or Cp where p is the IO pin in the range of 0 - 7.
If you send an invalid command, an "Invalid" message along with the string will be returned to the
PC.
Any of the eight inputs may be read using the R command;
R7
If a logic one is read (+5 VDC through 10K), the PIC will respond with;
R7 1
In the case of GPIO5, a logic zero (ground through 10K) is present. Thus in response to;
R5
The PIC will respond with;
R5 0
Tips on the use of the IO are contained in a separate discussion.
Eleven Channel 12-bit A/D (Figure #4).
Wire the TLC2543CN as illustrated in Figure #4.
Note that V_ref+ is connected to the nominal +5 VDC supply and V_ref- to ground. Thus, the
span of 0.0 to 5.0 is quantized into 4096 bands (0 - 4095). Thus, if 5.0 VDC is applied to an
analog input, the result should be reported as 4095. If ground is applied, the result should be
reported as 0. If 2.5 volts is applied, the result should be nominally 2048.
Note that the voltage present on an analog input is;
V_a_d = V_ref+ * band / 4096
Testing.
Attach test network "b" consisting of two 10K resistors in a voltage divider to analog input AIN0.
Using HyperTerm enter the command;
A0
The unit will respond;
A0 2048
(Note that it may not be exactly 2048).
Similarly, if network "a" is attached, the PIC will return close to 4095. If network c is attached
the PIC will return a value close to 0.
The format of the A command is;
Ach
where the channel is a single digit in the range of 0, 1, ... 9, A. Note that channel 10 is accessed
as;
AA
Note that the result is returned in decimal with leading zero suppression.
Additional notes on the use of the A/D are contained elsewhere.
Temperature Measurement (No Range Extension) - (Figures #5 and #6).
Figure #5 illustrates the wiring of the 24LC16B EEPROM and illustrates the connection of
DS1820 temperature sensors on four banks or runs. Figure #6 illustrates a typical configuration.
Note that all resistors identified with an asterisk are a part of the SIP resistor network which was
installed in Figure #2.
Note that the 24LC16B EEPROM is used to store the 64-bit serial number associated with each
of the DS1820's.
In the arrangement shown in Figure 5, all four of the banks are operated in the "parasitic mode".
That is, all of the DS1820's on a single pair (data and ground) are powered by the data lead.
Normally, this is the +5 VDC through the 4.7K pullup resistor.
However, when a DS1820 is performing a temperature conversion the DS1820 requires a bit
more current and the PIC brings the data lead to +5 VDC for several hundred milliseconds. (This
is known in the Dallas literature as "strong pullup". The purpose of the series 330 resistors is to
protect the PIC in case the data lead which may run several hundred feet is accidentally grounded.
Note that four banks are provided and this allows you to run up to four pairs to various areas of
your installation. Up to 64 devices may be accommodated on each pair.
There is no advantage to "balancing the load" by attempting to have an equal or near equal
number of DS1820 devices on each pair. Rather configure as it is convenient for you to wire.
For example, you may have a run to the attic with two sensors, a run throughout the house with
ten, a run to the basement to monitor the ambient temperature, water pipes and perhaps a freezer
and a run outside with one sensor. Or, you may have all sensors on the same run and none on the
other three.
The limiting factor in reliably communicating over a pair is the RC time constant where the
resistance is the 4.7K pullup and the capacitance is the capacitance of the cable plus that
associated with all of the DS1820 devices on the pair. This is dominated by the cable capacitance
and CAT 5 cable is suggested. We have reliably communicated over distances of 200 feet using
extremely poor cable.
Note that there is no disadvantage in operating the DS1820 devices in the parasitic mode. Again,
the limiting factor is capacitance and not the resistance of the cable. When making a temperature
measurement, the hard +5V provided by the PIC through the series 330 Ohm protection resistor
provides more than enough power for the DS1820.
One important point. If you stretch the cable too far, the ability of the PIC to communicate with
all of the devices on that pair will be impaired. That is, impaired performance will not be limited
to the most distant device.
Thus, if you have a choice between a single pair extending 250 feet and two shorter pairs, it is
suggested you go with the latter.
Testing.
Connect one DS1820 on the pair associated with Bank 0.
Don't get overwhelmed in the following discussion!
From HyperTerm, enter the initialize command;
I
This causes the PIC to first erase the EEPROM which takes some seven seconds. (The Test LED
will periodically flash to let you know the processor is alive). The PIC will then search for all
devices on all four of the banks. The assignment of all devices which are found are saved to
EEPROM and also returned to the PC in the following format;
T000 105ca42b 00000060
The form of this is
Tbdd xxxxxxxx yyyyyyyy
Where bdd is the bank (0 - 3), in this case, bank 0, and dd is the identity assigned by the PIC
beginning with 00 and extending through 3f. This is followed by two fields each consisting of 32
bits (8 hex digits) which is the manufacturer's serial number. Note that the DS1820 serial number
always begins with 10.
Assume you have three devices on Bank 0 and one on Bank 3. After sending the "I" command,
the following might be returned;
T000 105ca42b 00000060
T001 10c1df2b 00000086
T002 105de02b 000000a1
T300 107e212d 000000a8
You may then make a temperature measurement by sending the command;
T002
and the unit will respond with something like;
T002 22.34
where 22.34 is the temperature in degrees C and the other two fields is the 64-bit serial number.
If you attempt to make a temperature measurement on a device which does not exist, that is, it's
serial number is not present in EEPROM, the number -99.99 will be returned.
For example;
T003
will result in;
T003 -99.99
If you attempt to make a measurement on a device which does exist and there is an error in
calculating the cyclic redundancy code the unit will return -88.88.
T002
might result in;
T002 -88.88
Such an error might occasionally occur as the result of noise, say someone firing up an arc welder,
but if they occur more than occasionally, it is probably a sign the device has become disconnected
or that your cable run is too long.
Note that an initialization is required only when a DS1820 device is added or removed from the
unit. The serial numbers are stored in the 24LC16B EEPROM and thus they will be retained
indefinitely. Note, however, there is no harm in performing an initialization whenever you like.
The EEPROM can handle some 2,000,000 writes.
Note that you never have to directly use the manufacturer's serial number. However, assume you
have an existing installation and you know device 000 is in the basement freezer and 001 is
measuring the ambient temperature in the basement. You now add another sensor on the same
pair in the laundry room.
Note that you must initialize using the I command and unfortunately, the new device, depending
on its serial number, may be assigned the 001 identity. Thus, 000 is still in the freezer, 001 is now
in the laundry room and 002 is measuring the ambient basement temperature.
That is, the search algorithm assigns the identity based on the serial number and this will always
be the same if there is no change in the network. However, if you add a device on one bank, the
identity of the devices already on that bank may change depending on the serial number of the
added device. The undisturbed banks will remain the same.
Of course, the manufacturer's serial numbers will never change and thus the reason for returning
the serial numbers in response to the I command is to permit you to see determine the identity of
each device.
There are a number of ways of handling this.
If you have relatively few devices, the serial numbers may not be necessary. For example, assume
you install a new sensor in the laundry room and then initialize and then make measurements on
the three devices;
T000 -15.32
T001 27.45
T002 20.54
A bit of common sense suggests that 000 is the freezer and the laundry room is probably warmer
than the basement itself.
If you are a bit more organized, you might plug in each sensor, one at a time and use the I
command to determine its serial number. In most cases, the last two digits will be sufficient and
then keep a paper record of the location of each serial number. For example;
Freezer 60
Basement a1
Assume you are about to add the third sensor and you first determine its abbreviated serial
number; 86. You then install it in the laundry room and then perform the I command and observe;
T000 105ca42b 00000060
T001 10c1df2b 00000086
T002 105de02b 000000a1
Now, you can readily observe that the freezer is 000, the laundry room is 001 and the basement
ambient is 002.
All of this may appear confusing. In fact, it will probably take you less time to actually do it than
you have spent reading this and most certainly less time than it took me to write it.
Temperature Measurement (with Range Extension) (Figures #7, 8 and 9).
Figure #7 details the connection of P83B715 bidirectional current amplifiers on banks 2 and 3 so
as to extend the range up to 1000 feet or more. Figure #8 illustrates a typical configuration and
Figure #9 illustrates a number of techniques for providing +5 VDC at the remote location.
Banks 2 and 3 may be configured to interface with the Philips P82B715 range extenders by
grounding PIC terminal RC4.
Note that each P82B715 consists of two identical bidirectional transceivers. Thus, only one
P82B715 is required on the PIC side to accommodate both banks. However, in all likelihood, the
two distant ends will not be co-located and thus one P82B715 will be requred at each distant
point.
Although the P82B715 was developed for the Philips I2C bus, I have had good luck with the
Dallas 1-wire interface in reliably communicating over 1000 feet of very poor quality cable.
Note that when range extension is not used, the remote DS1820 is powered using the data line.
However, as noted above, when making a temperature measurement, more power is required and
thus the data line is lifted to a hard logic one for several hundred milliseconds.
However, when range extension is used, there is no way to supply this through the two P82B715
transceivers. Thus, when using range extension, the remote DS1820s and associated P82B715
must be supplied with a source of +5VDC. A number of arrangements for powering the remote
sensors are illustrated in Figure #9.
Command Summary.
All commands and responses are RS232 serial at 9600 baud, 8 data bits, no parity and one stop
bit (9600, 8, N, 1). All commands must be terminated with a "newline" (CR and LF). Responses
are terminated with a newline.
The sequence is for the PC to send a command and then receive a result and then a prompt. Note
that there is no buffer to permit the PC to send a batch of commands. The PIC is not listening
when it is performing a task.
No String.
If the PC sends only the a "newline", no action is performed. However, the PIC returns a prompt;
>
GPIO Set.
The PC sends a command of the form;
Sp
where p is the GPIO pin in the range of 0 to 7. For example;
S3
The PIC configures the specified pin to an output logic one and returns the command followed by
the state of the GPIO, which, of course, is always 1;
S3 1
GPIO Clear.
The PC sends a command of the form;
Cp
where p is the GPIO pin in the range of 0 to 7. For example;
C3
The PIC configures the specified pin to an output logic zero and returns the command followed
by the state of the GPIO, always 0;
C3 0
GPIO Read.
The PC sends the command of the form;
Rp
where p is the GPIO pin in the range of 0 to 7. For example;
R7
The PIC configures the specified pin as an input (high impedance) and responds with the
command followed by the state which was read, either 0 or 1. For example;
R7 0
A/D Measurement.
The PC sends the command of the form;
Ach
where ch is the channel in the range of 0-9 and "a". Note the hexadecimal "a" is used as the unit
provides 11-channels. For example;
A3
or AA
The PIC performs the A/D measurement and returns the command followed by the result in
decimal with leading zero suppression. Examples;
A3 4095
A3 205
A3 55
A3 0
Note that the PIC does not check whether the TLC2543 A/D is operational or present.
Initialization.
Initialization is only required to perform temperature measurements. It must be performed when
a DS1820 is added to or removed from the system. However, there is no harm in doing so at
other times. This may be useful in verifying which DS1820 devices are being detected by the PIC.
The PC sends the command;
I
The PIC erases the 24LC16B EEPROM and then performs a binary search on each of the four
banks and writes the manufacturers 64-bit serial numbers of all devices to EEPROM.
An example of a typical response;
T000 105ca42b 00000060
T001 10c1df2b 00000086
T002 105de02b 000000a1
T300 107e212d 000000a8
The form of the first field is;
Tbdd
where b is the bank (0 - 3) and dd is a two digit hexadecimal number in the range of 00 - 3F.
Note that the device number is assigned by the PIC, and is based on the serial number. Note that
two digit number is sequential and always begins at 00. That is, T000, T001, T002, etc.
The other two fields, each consisting of eight hexadecimal digits is the manufacturer's 64-bit serial
number. This may be used to determine the identity assigned to a specific DS1820.
If no devices are found on any bank, only a prompt (>) is sent to the PC.
Temperature Measurement.
The PC sends a command of the form;
Tbdd
where bdd is the three digit identity of the DS1820. For example;
T002
The PIC accesses the EEPROM to determine the 64-bit serial number of the identified device, and
then addresses the specified DS1820, performs a single temperature measurement and returns the
result to the PC. Examples;
T002 101.16
T002 23.33
T002 3.56
T002 0.32
T002 -0.33
T002 -5.66
T002 -27.44
Note the temperatures in degrees C are in decimal form with leading zero suppression and two
significant digits after the decimal point.
If the PC attempts to address a device and there is no entry for that device in the EEPROM, a
reading of -99.99 is returned. For example;
T005 -99.99
When performing the temperature measurement, the PIC uses an 8-bit cyclic redundancy check to
determine the integrity of the data. If this fails, a reading of -88.88 is returned. For example;
T002 -88.88
Note that on a CRC failure, the PIC does not automatically repeat the measurement sequence.
Constant CRC failures on the same device probably indicates that device has become
disconnected or is not functioning.
More than an occasional CRC error when accessing any of a number of DS1820's on the same run
probably indicates the cable run is too long.
Other.
All other strings are invalid. For example if the command xyz is sent, the PIC returns a message;
Invalid - "xyz"
Notes on General Purpose Inputs and Outputs.
Outputs.
See Figure #10.
When the PIC boots on power up, all GPIO terminals are configured as inputs. Thus all eight
GPIO terminals are in a high impedance state. They remain inputs until set or clear commands are
issued.
In some cases, a high impedance may be interpreted as a logic one. If the nature of your design is
such that a logic one causes an action, such as turning on a motor, it is critical to note that a
booting of the processor may cause the motor to unintentionally start.
One solution is to design such that an output logic zero forces the desired action.
Another approach is to use a pull down resistor such that when a GPIO lead is at a high
impedance, the pull down resistor appears to the interfacing circuitry as a logic zero. Figure #8
illustrates this technique in interfacing with TTL, CMOS, NPN transistors, a ULN2803 Octal
Darlington and a Solid State Relay.
Heavy and Inductive Loads.
When driving a heavy load, it is important to avoid heavy currents in the ground bus associated
with the PC, the PIC16C73A and the associated circuitry so as to avoid noise spikes that may
cause the PC or the PIC16C73A to behave erratically.
Figure #11 illustrates how such ground currents in the low level logic circuitry (PC, PIC and A/D)
may be reduced by running separate pairs for the +5VDC and ground associated with the PIC and
the power feed associated with the load.
Figure #11 also illustrates how an optoisolator may be used to completely isolate the logic ground
and the load ground. However, for safety reasons, the load ground should be tied to a frame
ground, such as the PC's chassis.
Inputs.
See Figure #12.
When using a GPIO as an input, it is a good design rule to provide a series limiting resistor. This
avoids potential damage to the PIC or the interfacing circuitry if the IO terminal is accidentally
configured as an output.
Figure #12 illustrates how TTL or CMOS, a SPST switch or a transistor may be interfaced with
the PIC. Note that in each case, there is a series limiting resistance of 10K.
It is interesting to note that the interfacing circuitry need not be TTL levels. Rather, if a series
limiting resistor is used, the voltage may be anything in the range of +5.0 to +12.0 Volts. PIC
inputs include a clipping diode to limit the voltage. However, be sure to use a series limiting
resistor to limit the current.
Notes on the Analog to Digital Converter.
Interpreting the A/D Results.
See Figure #13.
Note that with a 12-bit A/D there are 4096 quantizing bands over the expanse of V_ref- to
V_ref+ where V_ref- and V_ref+ are nominally 0.0 and 5.0 VDC. Note that each band is
nominally 1.2 mV.
Note that the voltage on a channel is calculated;
V_CH = band / 4096 * (V_ref+ minus V_ref-) + V_ref-
For example, if ban = 2048 and V_ref+ is 5.0 V and V_ref- is 0.0 VDC, then;
V_CH = 2048 / 4096.0 * 5.0 = 2.5 VDC
Note that V_ref+ may be the value of the nominal +5.0 Volt supply which powers the entire unit.
This may well be somewhat different than 5.00 VDC.
For example, the value of the output of a 7805 may be between 4.8 and 5.2 VDC from one device
to another. In addition, it may vary be as much as 100 mV if the line (7805 input) voltage were to
vary from 7.0 to 25.0 VDC. Add another 100 mV as the load on the output of the 7805 varies
between 5 and 500 mA. Add another 250 mV as the temperature of the 7805 varies from 25 to
100 degrees C. All of this can get a bit discouraging.
But, let's use some common sense. If you use a wall power unit on the input of the 7805, the
input voltage is going to be quite constant. If you are simply running this circuit and perhaps a
few other logic circuits with the 7805, the load current is small and quite constant and in all
probability, your ambient temperature is quite constant.
Thus, you might simply measure the output of the 7805 and modify your program for this specific
voltage reference value.
For example, assume you measure the output of the 7805 as 5.22 VDC.
V_CH = band / 4096.0 * 5.22
or V_CH = band * 1.2744e-3
Noise and Cabling Considerations.
As previously noted, in using a 12-bit analog to digital converter over the range of 0 to 5.0 VDC
means that each of the 4096 quantizing bands corresponds to nominally 1.25 mV which is quite
small. Note that if even 10 mV of noise is present on the input signal, the uncertainty of the
measurements may be up to eight quantizing levels and the user might have simply used a 9-bit
A/D to achieve the same accuracy. This really calls into question applications which use 14-bit or
even 16-bit A/D converters where each band is 300 or 75 uVolts. One wonders if the noise is not
entirely masking the accuracy the designers are striving for.
One technique for reducing the inaccuracy due to noise is to perform many measurements and
then average. That is, perform 100 measurements, sum the result and divide by 100. Of course,
this may or may not be practical in your application.
Another technique is to turn off as much circuitry as you can. Clearly, you can't turn off the PC
nor the PIC, but if you are using the GPIO bits to control such things as motors, heater coils, arc
welders and the like, try to structure your design to perform your analog measurements when
these devices are off. Here again, this may not be practical.
Input Termination.
Terminate the input of the A/D with as low a resistance as possible without loading down your
source. We have included 100K resistors for this purpose, but depending on your sensor's
impedance, you may be able to use 10K or even 1K.
Note a noise source coupling into a lead may be approximated as a voltage source in series with a
very high resistance R_coupling. The input resistance (R_in_AD) of the A/D is quite high.
Thus, in the absence of a terminating resistor, the noise is reduced by a factor of;
R_in_AD / (R_in_AD + R_coupling)
A terminating resistor R_term will cause the noise to be reduced by a factor of;
R_term / (R_term + R_coupling)
Thus, the improvement with the terminating resistor may be approximated as;
R_term / R_in_AD
For example, if R_in_AD is 5.0 Megs and R_term is 100K, the improvement is a factor of 50.
Shunt Capacitance.
Note that the series R_coupling and the shunt capacitance is a low pass filter and the higher the
capacitance the better. However, recognize that many capacitors, notably electrolytics are not
capacitors at frequencies much above audio. Disk ceramic capacitors are recommended as they
have excellent high frequency properties.
We have included a number 0.05 uFd disc ceramic capacitors in the kit.
Twisted Pair.
In many applications, the signal source may be located several hundred feet from the A/D
converter and thus the cable run is highly susceptible to all manner of noise.
Twisted pair cable is strongly recommended. Consider that for over 100 years the telephone
company has used twisted pair to carry analog voice conversations on the order of millivolts right
along side power lines carrying potentials of many kilo volts of commercial AC power and past all
manner of other troublesome noise sources; vapor lamps, arc welders and commercial radio
transmitters. It may not always work, but in general, it does.
The general idea is that the magnetic field associated with a noise source induces currents which
flow one way in one twist and the opposite way in the next loop and thus cancel one another.
Twisted pair is twisted pair. That is, in terms of noise immunity, there is no difference between
the least expensive twisted pair you might find at Radio Shack and the most expensive CAT5
cable you can buy. Of course, you might have a chat with some telephone or network people on
your job and go with CAT5.
If you do use cable which has multiple pairs, it is good practice to ground all unused conductors,
but only at one end.