Sunday, April 22, 2012

Starting out with the DS18S20 Digital Thermometer

When I first started this project, the DS18S20 thermometer started out as a real winner.  Looking at some of its key features, how could it get much better?
  • Communicates over a simple 1-wire interface.  No waste of I/O ports
  • Multi-drop and individual addressing allows more than one device to share the same I/O pin
  • Cheap (my weak spot)
  •   ±0.5°C resolution
  • Digital communications means the devices can sit at the end of a long bus run w/o loss of accuracy
Look at how simple this device is to hook up to the circuit.

All that is needed is a standard 4.7KOhm resistor.  It only took about 5 minutes (thanks to the included libraries from the compiler) to start talking to the device.  In about 30 minutes, I was able to put together a simple program that would continuously read the temperature and send the data over RS232 to my PC.  The next step was to add a few sensors to the bus and see about addressing them individually.  <crash>  Turns out that my frugal nature of using a 15+ year old part bit me.  Each device is addressed via a 48bit number.  While keeping track of 1 or 2 of these nifty devices would not be a problem, any more than that and the C84 is out of RAM.  In all fairness, just about any reasonable microcontroller is going to quickly run out of RAM keeping a track at 6 bytes per device.  Secondly, I discovered that the firmware required to discover all the devices on the bus is not that small either.  By the time I extended the code to enumerate the bus, I used up almost 100% of my 1K of my EEPROM.  Fortunately, there are still an abundance of I/O pins on the device that have not been used.  So, for my design I am going to limit the number of DS18S20's to 5 (RA0-RA4).  If I really need to expand the number of temperature sensors, a simple solution of a MUX (151) and an analog switch (4066) would be where I would turn.  Using pins RA0-RA3 tied to a 74HC151, and the mux's outputs tied to 2 74HC4066's RA5 can be used for all the DQ lines (perfect since it needs a pullup anyway).  With that in place on the breadboard, the PIC can now easily address 8 thermometers w/o any complicated 1-wire coding.

The down side is that the project cost has just gone up by $2 as has the complexity of the board.  If I were going at this greenfield, I would be much better served putting the extra $2 into the PIC device I was going to use.  A $4 PIC would provide a few hundred bytes of RAM and about 8K of FLASH.  With a device that size, the issue of the firmware size and 6 byte device address storage would be removed and and there  would be no need for external components.  Oh well, glad I keep a drawer full of shoe horns.






No comments:

Post a Comment