EE 476: Laboratory 6

Digital Thermometer with fan

Introduction.

You will build a digital thermometer which displays temperature on a LCD display and controls a fan with user-selectable turn-on temperature.


Procedure:

The LM34 temperature sensor produces a voltage output of 10 mV/degree F. You will need to perfrom an analog-to-digital conversion using the mcu to read the voltage. There are various ways of designing an A-to-D converter. You are free to use any scheme you like. I will describe a scheme here which uses just a few external parts. The full description is in Atmel Application Note AVR-401, but note that the pin definitions for the comparator inputs on the 8515 are different as shown below.

The transistor (2N3906) is used as a constant-current source. The two resistors connected to PB1 and PB0 form a voltage divider which is used as a reference voltage to calibrate the system. I used Rin=100k, the two resistors froming the voltage divider Rref1=Rref2=1k, the capacitor was 0.47 microfarad and the transistor base resistor was 510k.

The measurement procedure is:

  1. Turn off the transistor (base at 5 volts) and use PB2 as an output to drive the capacitor to ground.
  2. Wait a few millseconds for the cap to discharge.
  3. Turn on the voltage divider by setting PB1 and PB0 to outputs and setting one of them to 5 volts and the other to ground, implying a reference voltage, Vref, of about 2.5 volts (you will need to measure your exact voltage).
  4. Turn on the transistor (base to ground), make PB2 an input, and start a timer.
  5. When the comparator changes state, read the timer and call it Tref.
  6. Turn off the transistor (base at 5 volts) and use PB2 as an output to drive the capacitor to ground.
  7. Wait a few millseconds for the cap to discharge.
  8. Turn off the voltage divider by setting PB1 and PB0 to inputs. The voltage applied to PB3 is now the unknown input voltage, Vin.
  9. Turn on the transistor (base to ground), make PB2 an input, and start a timer.
  10. When the comparator changes state, read the timer and call it Tin.
  11. Calculate Vin = Vref * Tin / Tref

The cool thing about this procedure is that it is completely insensitive to the exact values of all the components except the two resistors which set Vref (you will have to measure Vref each time you set up the circuit). A short C program implements the procedure. The following table compares actual Vin with measured voltage. This procedure seems to be fairly accurate, but may need to have a small constant voltage subtracted. There also seems to be a large error above Vin = 4 volts.

Actual Vin
Measured Vin
1.99
2.02 to 2.04
1.00
1.04 to 1.05
.509
.56 to .57
.001
.07 to .08
2.49
2.52 to 2.54
2.98
3.01 to 3.03
3.50
3.56 to 3.59
3.98
4.07 to 4.10
4.48
4.60 to 4.63

 

You will need to drive a fan from the mcu. Fans usually have magnetic motors which can cause nasty inductive spikes to wipe out the transistors in the mcu port. The circuit shown in one of last year's final projects is fairly safe. The diode placed across the motor shorts out spikes when the motor is turned off.


Assignment

Write a program and construct a circuit which will

You will demo all the features above to your TA.

Your written lab report should include:


Copyright Cornell University December 2000