CSE466 SP’00 QUIZ #1

4/19/2000

Open Book/Notes

50 Minutes

 

One can measure temperature using an 8051, a thermister, and a capacitor as shown in the circuit below. P1.1 is used to charge and discharge the capacitor while P3.2 is used to measure the time it takes to do so. The thermister is a temperature sensitive resistor whose value changes by 200W for each a 1°C change in temperature.  The thermister value is 10KW at 20°C.

 

 

 

 

 

 

 

C

 
 

 

 

 

 

 


A: To determine temperature (the value of the resistor), should you measure the charge or discharge time of the capacitor?  Explain.

 

 

We should measure temperature during the discharge cycle because the weak pullup on the P1.1 pin will dominate the charging time. Also, the pullup on the P3.2 pin would affect the charging time of the capacitor as well, but it would have little affect on the discharge time.

 

 

 

B: Write C51 program that measures temperature according to your answer to A. Your program should keep a global variable called ‘temperature’ up to date. Don’t worry about converting to centigrade; all you need is a relative number to represent temperature. You may use interrupts but it is not required.  However, you must use a timer to measure time (not a software counter).  Document your code!

 

unsigned int temperature;

void main (void)

       TMOD = 0x01;  //set timer 0 to 16 bit mode

       TR0 = 1 ;           //enable timer (free running counter)

       While (1) {     

             P1.1 = 1;

             while(!P2.3);

             wait(AWHILE);

             P1.1 = 0; 

             TH0 = TL0 = 0;                                   // if just finished charging, clear counter

             while(P2.3);

             temperature = (TH0<<8) + TL0;       // else update temp

}


C: Choose C so that the measured time differs by approximately 2ms as temperature goes from 10°C to 30°C. Show your work and state any assumptions/approximations that you make.

 

We care about the voltage level at which the input will be read as 0 instead of a 1. The data sheet says that this voltage is never lower than .2Vcc -.1 which is .9V. But it could be higher! Let’s assume that, in the worst case, its at .4Vcc (how convenient). Assuming that we start discharging very close to 5V the RC is the time it will take to discharge to about .4Vcc.

 

Using the 200ohms/degree formula we get

 

t(30) – t(10) ~ 2ms = R30C – R10C

so 2ms/(R30-R10) = C

R30 = 10K + 2K = 12K

R10 = 10K – 2K = 8K

So C = 2ms/4K = .5uF

 

If you assumed a lower threshold you would have come up with a smaller capacitor.

 

 

 

 

 

 

 

 

 

D. List at least two possible sources of error in this measurement.

 

The only errors that we should be concerned about are the ones that vary from instance to instance of our design. Anything that throws of our measurement in a consistent way can be compensated for in software. For example, actual thermisters are non-linear (vary less at extreme temperature ranges than in the center). This can easily be accounted for in software. But the fact that one thermister might have a slightly different T/R curve than another cannot easily be accounted for in SW. This is  the kind of error that we have to be concerned about. So here is the top three:

 

  1. Thermister Tolerance
  2. Capacitor Tolerance
  3. The biggie: Threshold variation from processor to processor. The data sheet leaves the manufacturer with a very broad range of voltages that can either be 1 or 0: .2Vcc-.1 all the way up to. 7Vcc. If we were to use this method for temperature measurement, we would have to calibrate each system separately and either change the C value to get the right time or change the SW to match. Neither of which is a good thing to do in a mass-produced and supported system. 
  4. Here is another: the variation in pull up strength at the pin will impact the charge/discharge time of the capacitor, affecting your temperature measurement. Can you suggest a solution for that problem?

 

One rule of systems design is that you can’t count on things that are not spelled out in the data sheet, even if you measure and test them!