
       12 September 1993      MGJ


BEFORE YOU BEGIN
----------------

Obtain the National Semiconductor Linear Databook which discusses
their device part# LM331  "Precision Voltage-to-Frequency Converter".
{ You may be amused to learn that this chip was designed by
Robert A. Pease, who also writes a column in the electronics
trade magazines. } Read the Principles of Operation section of the
datasheet.

The LM331 is available mailorder from Digi-Key; at the moment it
sells for $5.90 in quantity one.



CIRCUIT OPERATION
-----------------

Print out the schematic, or draw it by hand.

Note that there is a 78L05 voltage regulator in the schematic.
It's in a TO-92 package and looks just like a transistor.
Having a voltage regulator lets you use practically ANY AC
adaptor, without worrying about its precise output voltage
or ripple.  Buy the cheapest AC adaptor you can find that puts
out 7V or more.  The one I happened to buy is marked "12V" but
in reality it puts out 16V.  No problem, the 78L05 cleans it
up and produces a smooth +5.0V for running the A-to-D.

The temperature sensor is an LM34 (from Digi-Key).  Purchase the
very cheapest grade of the chip they will sell you.  I happened to
get the "DZ" grade.  No problem -- you calibrate the entire
system including the sensor, and thereby obtain +/- 0.5
degree F accuracy.

The LM34's output voltage is 0.01v per degree Farenheit.  At
32 degrees F, it puts out 320mV, and at 150 degrees F it puts
out 1.500 volts.  This voltage is lowpass filtered to reduce
noise, and fed to the comparator input of the LM331, pin 7.

The LM331 is connected in its classic configuration, with
a set resistor Rs of 13K, a load resistor RL of 100K,
a load capacitor CL of 1.0uF (mylar), a timing resistor Rt
of 6.8k, and a timing capacitor Ct of 10,000pF (0.01uF).

Note that the output of the LM331 (at pin 3) is NOT a
50% duty cycle squarewave.  Therefore we feed it to a 74C74
flipflop which performs a divide-by-two function and
thereby restores the duty cycle to 50%.  This is important
since the audio input jack to the SPARCstation is capacitor
coupled inside the computer. The ingoing waveform should
be symmetric, so that our frequency-determining software
{which simply counts zero crossings} will be maximally robust.

The 50% output (at flipflop pin 5) is attenuated 100-to-1,
because the audio input circuits inside the SPARCstation are
tuned for microphone-level (1mV - 10mV) signals, not fullswing
5V digital pulses.


MECHANICAL CONNECTION
---------------------

Take the SPARC's audio cable with you to the place where you
buy parts.  You need a 1/8 inch (3.5 mm) miniature phone plug,
which plugs into the SPARC cable.  Try before you buy.

While you're there, buy a jack that mates to the plug on
your AC adaptor.


ABOUT RESISTORS
---------------

I recommend metal film resistors for the frequency determining
components around the LM331.  Digi-Key will sell you these.
Metal film resistors are much less temperature sensitive
than carbon resistors (such as are sold at Radio Shack).


ABOUT CAPACITORS
-----------------

Make sure to buy film capacitors for CT and CL in the LM331
circuit.  I used mylar for CL and polystyrene for CT.


CONSTRUCTION
------------

Build the circuit using whatever mounting platform you like.
I happened to plug mine together on a protoboard, and it
works fine.

I made a 4-foot-long twisted pair cable that goes from the
circuit board to a 1/8" phone jack, which plugs into the
SPARC audio cable.  I made a 3-conductor twisted cable 6 feet
long for the LM34 sensor, which gives a little freedom in
the placement of the sensor.


DEBUG
-----

After double checking your hookup and buzzing it out with
a VOM, apply power.  Verify that the 78L05 is producing
a 5.0 volt output.

Check the output voltage of the LM34.  In a typical
room it ought to be about 730mV (i.e. 73 degrees).

With an oscilloscope, look at pin 3 of the LM331.  You
should see a small-duty-cycle rectangular waveform,
swinging rail to rail.  Move the scope to the 74C74 output
pin.  This should show a perfect 50% duty cycle squarewave.

Plug it into your SPARCstation.  Fire up /usr/demo/SOUND/soundtool.
Adjust the record volume to 85 and the play volume to 20.
Click "Record" and 2 seconds later click "Stop".  Look at the
displayed waveshapes: are they full amplitude?  Do the waves
have monotonic rising and falling edges?   Play back the
sound and listen to it.  Not for any debugging value, just
because it's cool to "hear the temperature".


CALIBRATION
-----------

See the file "how_to_calibrate.txt".


OPERATION
---------

You can use this however you like; let your imagination run free.

I have supplied a simple Cshell ("csh") script that logs the
date and time, and the temperature, every 300 seconds (5 minutes).
This is just a crude beginning; undoubtedly you can think of
more clever and useful applications.  Such as:

     Air Conditioning Failure Alarm:  Connect an autodialer
        to your machine and have it phone the sysadmin if
        air temperature ever exceeds 90 degrees F (or whatever
        value frightens the poo out of you).

     Slope logger: Instead of logging T versus time, log the
        first derivative -- the rate of change of temperature --
        versus time.  In our building this showed the central
        A/C going bonkers every morning at 5AM.

etc.


           ---- Mark Johnson
