Serial Eight Output, Six Input, Eight 12-bit A/D

with Four Runs to Multiple DS18S20, DS18B20, DS1822 Temperature Sensors

and DS2438 Temperature and A/D Sensors and DS2423 Dual 32-bit Counters on each Run

IO Module #136

Peter H. Anderson
915 Holland Road, Bel Air, MD 21014,

Ordering Information.


The IOM #136 is an assembled unit that is controlled by a PC COM port or similar (9600 baud, 8 data bits, no parity and no flow control). The intent is to provide access to real world inputs, outputs, 12-bit A/Ds, temperature measurement and counters which you may customize to meet your specific applications.

The IOM #136 uses only the Tx, Rx and GRD terminals on the serial port. If you do not have a COM Port, consider a USB to RS232 converter.

The module provides eight addressable TTL level outputs (15 mA source and sink) which may be used to operate LEDs, transistors or FETs which in turn may operate mechanical or solid state relays.

It also provides for the reading of six TTL level inputs.

In addition, it provides eight 12-bit analog to digital converters and two voltage references. In performing measurements, each A/D may be configured with any of five configurations specifying Vref+ and Vref-. The voltage reference outputs are nominally 2.048 and 4.096 VDC.

Access to the eight outputs, six inputs, eight 12-bit A/Ds and the two voltage references are available at holes adjacent to the processor.

Further, the unit provides the capability of measuring the temperatures on each of various Dallas 1-Wire devices on up to four twisted pairs. In theory, up to 256 1-wire sensors may be accommodated on each twisted pair. However, the limiting factor is the capacitance and my suggestion is up to sixteen devices on a maximum of 200 feet on each twisted pair run. Note that the hardware has been wired for these four runs runs which are avilable at the screw type terminals.

The Dallas sensors which may be accommodated are the DS18S20 (or the older DS1820 in a PR35 package), DS18B20 and DS1822 temperature sensors, the DS2438Z temperature sensor and 10-bit A/D converter, and the DS2423 dual 32-bit counter.

The printed circuit board is an Olimex PIC-P40C-20MHz prototyping board which has been modified.

The module includes a female DB9 connector, RS232 level shift circuitry (MAX232), an on-board 5 VDC supply (7805), a Microchip PIC processor and associated 20 MHz crystal. All of this is fully assembled.

An 8-hole screw type connector is provided for the twisted pair runs to the mutltiple DS18S20s operating in the parasitic power mode. A separate 4-hole screw type connector provides two grounds, a courtesy 5 VDC output (200 mA) and a reset lead. Momentarily ground to reset the processor. The user may use unused binding posts and add similar binding posts for their particular application.

The unit is mounted on four 0.5 inch nylon hex standoffs (#4-40 screws).

An activity LED is provided which winks briefly about every ten seconds to indicate the unit is alive and it also rapidly flashes a number of times on receipt of a command from the interfacing PC or similar. This is intended as a diagnostic tool.

One DS18S20 temperature sensor is provided. Additional DS18S20, DS18B20, DS2438 and DS2450 sensors may be purchased separately. Currently I do not stock the DS2423 dual counter, but will do so if there is a demand.

The unit includes a coaxial power connector which will accommodate a 9 - 12VDC (2.5mm ID x 5.5mm OD female center positive) wall power unit and compatible 120 VAC wall power unit.

A six foot DB9M to DB9F through serial cable is also included.

Again, please note that this module provides eight addressable outputs, six addressable inputs, eight addressable 12-bit A/D converters and two voltage reference sources. All of these functions are available at the solder pads near the processor. It is left to the user to add additional circuitry as required for their specific application. In addition, the module provides for four twisted pair runs to multiple Dallas 1_wire devices on each run. These have been wired to the terminal block.



The intent in designing modules such as this is to involve my undergraduate students in meaningful design experiences, while at the same time providing useful low cost products for hobbyists and tinkerers.

In the spirit of this activity, I don't want people buying items that do not work for them or do not meat their expectations. Thus, this unit may be returned at any time for a full credit.

Detailed Description - Command Format

All commands other than those associated with A/D measurements consist of two characters, the first indicating the operation and the second, a digit, indicating the specific output, input, or temperature run. Operations are;

	Hx	' output high
	Lx 	' output low
	Sx	' read output status

	Ix	' read input

	Dx	' read from Dallas 1-W devices.
	Tx  ' read temperature on Dallas 1-W devices having temperature measurement capability.
		' (DS18S20, DS18B20, DS1822 and DS2438)
	Vx	' read voltages on Dallas devices having voltage measurment capability (DS2438).
	Cx	' read counters on Dallas devices having counter capability (DS2423).
where x is a digit.

For A/D measurements, the format of the command is the letter 'A' followed by two digits;

The first digit identifies the specific A/D and the second specifies the configuration of Vref+ and Vref- which are to be used in performing the A/D conversion.

On receipt of any command, the processor rapidly flashes the activity LED. All valid commands are echoed followed by a new line followed by the results of the command. If the command is not valid, the processor returns an error message.


The outputs are identified as 1, 2, 3 through 8. Each may be independently operated by issuing either an "H" (High) or "L" (Low) command. Note that a 0 brings all outputs high or low.

For example;

	H1		' high on output 1
	H3		' high on output 2
	L1		' low on output 1
	H4		' high on output 4
	L0		' brings all outputs low
	H0		' bring all outputs high
The processor echoes the command followed by a new line and provides the state of the addressed output (or outputs). For example in response to H3, the processor echoes the command followed by the state of the output;
	3 1
In the case of the H0 and L0 commands, the state of all outputs are returned.
	1 1
	2 1
	3 1
	8 1
This may appear a bit ridiculous. However, I tried to be consistent with all functions and with the other commands.

In addition, the state of an output or all outputs may be determined by issuing the "S" (status) command.

	S1	' read state of output 1
	S0	' read state of all outputs
The processor echoes the command followed by the state or states of the addressed output(s).
	1 0	' output 1 is at zero
With the S0 command, the state of all eight outputs are returned.
	1 1
	2 1
	3 0
	4 1
	8 0


The state of the inputs may similarly be determined using the "I" (input) command.

	I1	' read input 1
	I4	' read input 4
	I0	' read all 0 inputs.
The processor echoes the command followed by the state of the input or inputs;
	1 1
With the I0 command, the state of all six inputs are returned.
	1 1
	2 1
	3 0
	6 0

A/D Measurements

A 12-bit A/D conversion is performed using the "A" (analog) command;

	A17	' perform an A/D conversion on A/D channel 1
where the first digit specifies the channel, 1 - 8.

The second digit (0. 2, 4, 6 or 7) specifies the voltage reference configuration;

	Vref_H      Vref_L

0	Vdd         Vss
2	4.096       2.048
4	4.096       GRD
6	Vdd         2.048
7	2.048       Vss
Thus, A17 performs an A/D conversion on channel 1 using 2.048 and GRD for the high and low voltage references.

The processor echoes the command followed by the A/D reading or readings in decimal (0-4095).

	1 567
The voltage for each of the above configurations is calculated as follows. I assume Vdd is 5.00 and Vss is GRD.
0	5.0 / 4096 * adval
2   (4.096 - 2.048) / 4096 * adval  + 2.048
4	4.096 / 4096 * adval
6	(5.0 - 2.048) / 4096 * adval + 2.048
7   2.048 / 4096 * adval

When the first digit is 0, A/D conversions are performed on all channels, 1 - 8 using the specified configuration. Thus;

performs A/D conversions on channels 1 - 8 using 4.096 and GRD for the high and low voltage references.

Dallas 1-W Measurements

Data measurements on any of the four Dallas "runs" may be performed using the "D" command.

	D2	' perform temperature and A/D measurements on all Dallas 1-W devices found on run 2.
	D0	' perform temperature and A/D measurements on all Dallas 1-W devices found on all runs.
The processor echoes the command followed measurements.
   3 00 10 6A0B 24.12
   3 01 10 9DD7 24.12
   3 02 28 DB9C 24.12
   3 03 22 5BFC 24.43
   3 04 26 09CE 23.81 0.17 5.03
   3 05 1D C827 00000000 00000000
Note that in this example, six devices were found on run 3. As each was found, it was assigned a sequential number in the range of 00 - FF. The third field is the device code; DS18S20 - 10, DS18B20 - 28, DS1822 - 22, and DS2438 - 26, and DS2423 - 1D) followed by a 16-bit serial number. Note that the device code and the serial number has been assigned by Dallas. The last fields are the data.

Thus, in the example, two DS18S20 devices (code 10) were found and the temperatures were both 24.12 degrees C. One DS18B20 (code 28) and one DS1822 (code 22) were also found. One DS2438 (code 26) was found and the temperature is displayed, followed by V_ad and V_dd with two places after the decimal point. One DS2423 (code 1D) was found and the values of the two 32-bit counters is displayed in hexadecimal format.

If no sensor is found on the designated run, the command is echoed, but no other data is returned.

With the "D0" command, data measurements are performed on all of the four runs.

   1 00 10 0C26 27.81
   1 01 10 0AD7 26.93
   2 00 10 9DD7 23.06
   2 01 10 BD53 23.00
   3 00 28 DB9C 23.00
   3 01 22 5BFC 23.37
   3 02 26 09CE 26.12 0.09 5.03
   4 00 1D C827 00000000 00000000
Note that in this case, two sensors were found on "run" 1 and two on "run" 2, three on "run" 3 and one on "run" 4.

(The order in which devices are found is a bit like an telephone directory arranged with the last names spelled in reverse. Thus, 0x28 is 0010_1000, 0x22 is 0010_0010 and 0x28 is 0010_1000. Reversed, these are 0001_0010, 0100_0100 and 0001_0100. Thus, 0x28 is found before 0x22 and 0x22.)

The time to measure a temperature is nominally one second. Other measurements require less than 100 ms.

Voltage measurements on any of the eight "runs" may be performed using the "V" command.

	V2	' perform voltage measurements on all Dallas 1-W devices found on run 2 which have
	    ' voltage measurement capability; DS2438.
	V0	' perform  voltage measurements on all Dallas 1-W devices found on all runs.
The processor echoes the command followed measurements.
    2 06 26 09CE 0.09 5.03
As each device is found, the IOM #136 determines if the device is a DS2438 and if so, performs the A/D measurements and displays the voltages. Note that there is a gap in the sequential numbering as a number of devices not having A/D converters were found. Note that the temperature associated with the DS2438 (Code 26) is not displayed.

Temperature measurements on any of the four Dallas "runs" may be performed using the "T" command.

	T2	' perform temperature measurements on all Dallas 1-W devices found on run 2 which have
	    ' temperature measurement capability; DS18S20, DS18B20, DS1822 and DS2438
	T0	' perform  temperature measurements on all Dallas 1-W devices found on all runs.
The processor echoes the command followed measurements.
   2 00 10 0C26 27.81
   2 01 10 0AD7 26.93
   2 02 10 9DD7 23.06
   2 03 10 BD53 23.00
   2 04 28 DB9C 23.00
   2 05 22 5BFC 23.37
   2 06 26 09CE 26.12
As each device is found, the IOM #136 determines if the device is a DS18S20, DS18B20, DS1822 or DS2438, and if so, performs the temperature measurement. Note that the voltages associated with the DS2438 (Code 26) are not displayed.

Counter measurements on any of the four "runs" may be performed using the "C" command.

	C2	' perform counter measurements on all DS2423 devices on run 2.
	C0	' perform counter measurements on all DS2423 devices found on all runs.
The processor echoes the command, followed by the two 32-bit results.
   4 00 1D C827 00000000 00000000

Note that if you modify your system, the sequential number in the second field associated with a particular sensor is simply a running number which is assigned as each device is found. The order that each device is found is in no way related to its physical location on the twisted pair rail. This will probably change if you modify your configuration. Modifying your system may be inadvertent. If you rely on this sequential number and the beagle eats the sensor in the living room, you might actually be measuring the temperature in the freezer and believe it to be that in the living room. This is, of course, an extreme case, but hopefully it drives home the idea of using the serial number in field four to specifically identify which measurement is associated with each physical sensor.

If there is a communications error performing a measurement, the value -88.88 (or in the case of the DS2450; -8.888) is displayed. If this occurs frequently, it is a red flag that there is too much cable on the run. Too much cable (actually, the capacitance associated with the cable) will cause intermittent communication problems with all devices on the run, and not simply those sensors which are most distant from the IOM #136 unit.

The range of the temperatures at which operation is assured for the DS18S20, DS18B20, DS1822 and DS2438 is -40 to 85 degrees C. The unit provides a resolution of 0.03125 degrees C for the DS18S20 and DS2438 and 0.0625 resolution for the DS18B20 and DS1822. Please refer to the data sheets at Dallas Semiconductor for absolute accuracy over the full temperature range. (Note that the DS1822 is functionally the same as the DS18B20. In fact, the DS1822 was designed as an economy version of the DS18B20 at some sacrifice in accuracy. However, I have found the inferior DS1822 costs just about the same as the DS18B20).

The DS2438 A/D converter is a ten bit A/D and the device uses an internal band gap reference such that the readings are reported in VDC over the range of 0.0 to 10.23 VDC. The resolution is 10 mV.

The DS18S20, DS18B20 and DS1822 operate in the parasitic power mode. That is, the power required to operate the sensor is obtained from the signal line. Thus, only the DQ and GRD leads are connected to these devices.

However, with DS2438, a power source in the range of 2.5 to 10.0 VDC capable of providing 100 uA is required at Vdd. This may be locally supplied, or a source of +5 VDC may be run from the IOM #136 unit. In some situations, you may have a local voltage source having a low internal impedance and in the range of 2.5 to 10.0 VDC that you wish to measure and this may be used to supply Vdd. In this case, the DS2438 is actually performing two useful 10-bit A/D conversions, one on Vad and the other on Vdd.

Note that as the DS2438 uses internal bandgap references, the accuracy of the voltage used as power does not affect the accuracy of the measurement.

A power source in the range of 2.8 to 6.0 VDC is required for the DS2423 dual counter. It is suggested that +5 VDC be run from the IOM #136 unit.

I have seen arrangements which use diodes and filter capacitors to derive the Vdd from the DQ signal line. I hesitate to suggest this is good design as even the 0.1 mA required for the DS2438 drops the voltage on the DQ lead by a full 0.5 VDC. What is worse is using this technique to also power a remote MPX4115 pressure sensor of an HIH-3610 relative humidity sensor. Dallas used this technique with a humidity module which I see is still available from a firm in Mexico. Terrible design. Add one of these units on a run and there is a good chance of being unable to communicate with any of the other devices on the run.

In today's world, we have inexpensive CAT 5 low capacitance cable with four twisted pairs. Use one pair for DQ and GRD for all devices on the run. Use another pair to provide power at Vdd for the DS2438, DS2450 and DS2423. Add a 0.01 to 0.1 ceramic capacitor between Vdd and GRD at the device. Notes.