Gas station without pumps

2012 June 24

Temperature lab, part 3: voltage divider

In Temperature lab, part2, I carefully measured the resistance vs. temperature curve for the Vishay BC Components NTCLE413E2103F520L thermistor, finding that either my thermometer was badly miscalibrated, or the manufacturer’s data sheet was misleading.  I got a resistance of 9.7kΩ (not 10kΩ±1%) at 25° C and a B-value of 3174°K, not 3435°K±1%.  A big part of the discrepancy is that I calibrated over a different temperature range, and the measured values deviated most from the manufacturer’s spec at low temperatures.

Actually, the manufacturer’s data sheet is not as bad as all that.  They give specs for the ratio of the resistance at various temperatures to the resistance at 25° C, and their numbers do not fall along a simple A e^{B/T} curve.  The report the B-value as a 2-point fit for T=25° C and T=85° C, but they also report resistance values every 5° C from –40° C to 105° C.  One can compute the B-value for any pair:

R(T_1) = Ae^{B/T_1}

R(T_2) = Ae^{B/T_2}

R(T_1)/R(T_2) = e^{B/T_1-B/T_2}

\ln \left( R(T_1)/R(T_2)\right) = B(1/T_1-1/T_2)

B = \frac{\ln \left( R(T_1)/R(T_2)\right)}{1/T_1-1/T_2}

But even if I use their calibration data down to 0° C, I don’t get as small a B-value as I get from my measurements. My calibration curve does not fit their spec, even if I look at the table, rather than the simple B-value model (though the table is closer to my measurements, it doesn’t match).

How big a difference would if make if I used their Ae^{B/T} curve rather than mine?  At R=6685Ω, we get the same temperature either way (96.446° F).  At the resistance they claim for 0° C (27348Ω), their B-value model would give 33.90° F and mine would give 29.37° F.  At the resistance I measured for 0° C (25.5kΩ), their model would give 36.67° F, while mine gives 32.32° F (which is closer than the measurement error I had on temperatures).  So it looks like relying blindly on their B-value model introduces an error of over 4° F at low temperature, but in a digital thermometer for human body temperature, one would get nearly the same result with either calibration.

Voltage divider

The second part of the lab was to use the calibration curve to design a circuit to convert the resistance variation into a voltage variation that is nearly linear with temperature, at least over a small range.  The simplest circuit to convert a resistance to a voltage is a voltage divider, which just requires a voltage source and another resistor.

A simple voltage divider for converting the thermistor resistance to a voltage. Because I want the output voltage to increase with temperature, but the resistance R(T) decreases with temperature, I put the thermistor on the top branch and fixed resistance on the lower branch.
Circuit drawn with the Circuit Lab editor.

The formula for the output voltage is simple: V_{out} = V_{dd} R_1/(R_1+R(T)), where we are approximating R(T) \approx A e^{B/T} for temperature T in Kelvin. We’d like the voltage to be as linear as possible, which means we want the second derivative of Vout with respect to T to be zero. Obviously, we can’t do that for all values of T, but we might be able to do it for a particular value of T, and to have a small second derivative in that neighborhood.

We can take the derivatives by hand (or use a tool like Maple or Mathematica):
\frac{d V_{out}}{d T} = V_{dd} \frac{R_1 B R(T)}{(R_1+R(T))^2 T^2}
\frac{d^2 V_{out}}{d T^2} = V_{dd} \frac{R_1 B R(T) (R_1(B+2T)-R(T)(B-2T))}{(R_1+R(T))^3 T^4}
The second derivative is 0 if R_1(B+2T)-R(T)(B-2T)=0, that is if R_1 = R(T) \frac{B-2T}{B+2T}.

We can use this formula to set the value for any temperature, for example, if we want linearity around 98.6° F (310.15° K), we can set the series resistor to 4323.64Ω.

Expected voltage curve using a voltage divider with series resistor optimized for 98.6° F. Note that the curve is fairly linear from about 70° F to about 130° F (where the red non-linear curve and the green linear approximation at 98.6° F are quite close.

Of course, commercially available resistors don’t come in values like 4323.64Ω, so in doing a design one has to pick an available resistor, using the EIA table of standard resistor values.  A 4.7kΩ resistor looks pretty close, which would be color code yellow-violet-red.  Too bad that I don’t have one.  I do have a 5.1kΩ resistor, which would be optimal for linearizing at 90.06° F.  We should, of course, ask students to do the resistor selection for a different temperature than the one we use in an example, and they should be using their own B-value.

Testing the voltage divider

I set up the voltage divider on a breadboard.  Because I knew my wall wart had a huge ripple, I added a low-pass RC filter consisting of a 100Ω resistor and a 470µF electrolytic capacitor.  This slightly complicates the analysis of the voltage output, since the Vdd voltage is itself dependent on a voltage divider.

Low-pass filter to clean up the output of the wall wart. With the low-pass filter in place, we can model the power supply as a 5.166V source and 100Ω series resistor.

Here is what the low-pass filter looks like on the breadboard. The red and black wires from the bottom come from the connector to the wall wart. The 100Ω resistor runs vertically up the center, and the electrolytic capacitor connects across to the ground. The red clip lead is from the multimeter and is set up for measuring the voltage at the output of the filter.

Here is the full breadboard, showing the RC filter, the series resistor, the leads to the thermistor (the red and yellow lines with the crimp-on connectors), and the clip leads to the multimeter (the red and black alligator clips). I’ve found it very handy to have a number of double-sided header pins to make easy connection points on the breadboard for clip leads.

Here is the setup used for testing. The thermistor and thermometer are in the ceramic-cup water bath, with the thermometer held to keep the bulb in contact with the thermistor. You can see that the least-significant digit of the LCD display is a bit hard to read—applying some pressure to the display often makes it readable. Clip leads are essential to doing this experiment—holding the multimeter probes to test points would be a major hassle.

I only made 21 measurements of voltage, since I was not going to be fitting a model to the data, but just using the model I fit from the resistance measurements.

Plot of measured and theoretical voltage vs. temperature for the thermistor. The non-linear theoretical curve seems to be a pretty good fit (though it was not fit on this data, but on the previous series of resistance measurements).

The range of the voltages with the series resistor (from about 0.85v at freezing to 4.15v at boiling) is fairly reasonable for direct conversion to digital for the Arduino 10-bit ADC. In the middle of the range, the slope is about 0.0233 V/°F, which would give a resolution of about 0.2°F for Arduino readings.  (Of course, with the Arduino, we would not need the low-pass filter, and Vdd would be a well-regulated 5v, so this calibration curve would have to be redone.)  Even if we use the computational power of the Arduino to correct the non-linearity of the voltage curve, it is still useful to select the series resistor for the temperature we are most interested in, since that point gets the largest slope and hence the highest temperature resolution for fixed-size steps in voltage quantization.


A lot of thermistor circuits on the web have a resistor in parallel with the thermistor, as well as the one in series. I wondered what the effect of this extra resistor was.

Circuit with resistor in parallel with the thermistor, as well as in series.

I tried analyzing this circuit also, using the same brute-force approach of computing the second derivative of the voltage and setting it to zero.  I got a result that surprised me initially:  the second derivative is zero if R_e(B+2T)-R(T)(B-2T)=0, where R_e is the resistance one would get for putting the series and parallel resistors in parallel. This is exactly the same condition as before, but with R_e replacing the series resistor R_1.

After I thought about this for a while, I realized that I should have been able to get there directly. If you think of the circuit as connecting the thermistor to a voltage divider consisting of R2 and R1, then you can replace the ground and that voltage divider by the Thévenin equivalent, which would be a voltage source with voltage V_{dd}\frac{R_1}{R_1+R_2} and a series resistor consisting of  R1 and R2 in parallel: \frac{R_1 R_2}{R_1 + R_2}.  The only reason to put in a parallel resistor would be to restrict the voltage range (which might be useful if the output were to be amplified, but is not useful if the output is going directly into an analog-to-digital converter whose full-scale range is 0 to Vdd).

2012 June 23

Failures of the CS10K process

Filed under: Uncategorized — gasstationwithoutpumps @ 23:21
Tags: , ,

There is an excellent discussion of the failures of the CS10K and AP CS Principles efforts to get more high schools teaching computer science in Ben Chun’s blog post: What is the CS Education ask? « And Yet It Moves.

He points out

  • Most of the discussion is happening behind an ACM paywall, where most of the people who have to implement the process have no access.
  • No plausible mechanism for reaching the goals of CS10K (10,000 high schools teaching some AP-level computer science class) has yet been described.  He’s not even addressing the problem of where the teachers will come from—there is first the problem of convincing schools that offering the courses would be valuable and convincing students that they should take them.

His writeup is more detailed, going over some of the not-that-feasible alternatives that have been proposed in California. I think that he has really nailed a couple of the major problems with the CS10K initiative.  We can’t even get campuses of the University of California to include CS courses in general education (except, sometimes, as an alternative to math). How are we going to convince high schools, which have a much more formulaic and rigid approach to curriculum design?

If you are at all interested in CS education, go read Ben’s post.  It is worth the time.

Temperature lab, part2

The thermistors that I ordered (see More musings on circuits course: temperature lab and Buying parts for circuits course) arrived today, about 2.1 days after I ordered them.  So I’ll try playing with them today, and see whether I can do the lab I’m thinking of for the students.

My son is still working on the Arduino data logger.  The Arduino code has been done for a while, but he’s been working on the Python front end.  He’s decided to do two front ends: a minimal one with no GUI and a fancy one using PyGUI.  He’s run into some problems (like PyGUI not supporting autoscrolling in TextEditor components), but everything seems to be solvable at this point.  He had a GUI interface working, but decided he needed to refactor his code to have a proper API for the datalogger, so that the user interface and the datalogger core code were as independent as possible with a documented interface between them—he’s teaching himself a lot about software engineering for this project, which is the first one for which he has had an external client.

The action plan for testing out a temperature measurement lab that I posted in More musings on circuits course: temperature lab was

  • Get some thermistors and some thermometer probe sheaths and see if I can make adequate temporary waterproofing for pennies per student.  I’ll probably have to solder on wires to lengthen the leads.
  • Try calibrating thermistors using a multimeter, cups of hot and cold water, and an accurate thermometer.
  • Try reading the thermistor using a voltage divider and the Arduino ADC.  Plot the temperature and Arduino reading over a wide temperature range (say, as a cup of boiling water cools).
  • Try linearizing the thermistor readings  using a parallel resistor and voltage divider.
  • Try designing an amplifier to read the thermistor with much lower current through it (and so less self-heating).

I’ve got three types of thermistors (all 10kΩ nominal resistance at 25° C), none of which are intended for immersion:

  • Vishay BC Components NTCLE100E3103JB0 a very cheap (23.5¢ each in quantities of 10) with B-value 3977°K).  There is high variation in the resistance (±5%), but low variation in the B-value (±0.75%).  These are glass-bead thermistors with 2cm uninsulated leads, so will need waterproofing. I bought 10 of these, but am hoping that I don’t need them.
  • Vishay BC Components NTCLE413E2103F520L (34.9¢ each in quantities of 10) has 4cm leads and is epoxy coated, but with the warning “Not intended for fluid immersed applications or continuous contact with water.”  It has B-value 3435°K, both resistance and B-value ±1%.  I plan to find out today if it is waterproof enough for the relatively short duration of the labs. I bought 10 of these also, and have the highest hopes for these being the ones we use in the lab.
  • Murata Electronics North America NXFT15XH103FA2B100 (66¢ each in quantities of 10) with B-value 3431°K, both resistance and B-value ±1%. The 9.5cm leads make these likely to be the easiest to use with thermometer probe covers, but they are more expensive.  I bought 4 @ 87¢, so as to keep the cost per thermistor type below $3.50. Note: the specs give different B-values depending which pair of temperatures used—I’ll have to look to see if they have specs for higher-order models of the resistance as a function of temperature.

The setup at 110°F, showing 4.60kΩ as the resistance.

I’ll try the epoxy-coated ones with the 4cm leads first. The first step is calibrating one with an ohmmeter. I used clip leads to connect a cheap multimeter to the thermistor, then dunked the thermistor in a glass of warm water with a thermometer (note: we’ll need to get some thermometers for this lab). The thermometer I used is a pasteurizing thermometer that I’ve had for years—it is, unfortunately, calibrated in Fahrenheit, not Celsius. Of course, we ideally want temperature in Kelvin.

I put a table of the measurements on a separate page, to avoid cluttering up the post with a table of 28 measurements.

I don’t expect many of the students will have the patience to make 28 measurements, but if we provide some different hot water sources (water boiled in a teakettle and ice water in a thermos), they should be able to make 10 measurements across a wide range of temperatures. I stopped at 28 measurements, because the alligator clip broke the wire and I didn’t feel like stripping more of the insulation and reconnecting.

I tried to fit the Steinhart-Hart equation {1 \over T} = A + B \ln(R) + C (\ln(R))^3 to the data, where R is the resistance in Ω and T is the temperature in degrees Kelvin. But gnuplot got as good a fit using just A and B as using the third order fit, with T = 1/( 5.01E-4 + 3.11E-4 \ln(R)) providing an excellent fit.

Fitting the first two terms of the Steinhart-Hart model for thermistor behavior.


Simple Arrhenius fit for the data. When I fit the equation R= A e^{B/T}, which is the equation most often used in thermistor specs, I get A=0.24Ω and B=3157°K, which is not that close to the spec (10kΩ @ 25°C, B=3435±35°K, so A=0.0992Ω). Note that the spec curve fits the data quite well for warm temperatures, but deviates badly for cold ones.

There could be systematic problems with either my temperature readings or my resistance readings. The multimeter is more suspect than the thermometer, but the readings would have to be off by 500Ω to get that sort of error in the B-value. The numbers look particularly bad around 110°F. I think I need to get some new batteries for my other other cheap multimeter (which I think is a bit better) and see if it gives more reasonable results.

Wait a minute! I have an old Fluke 8060A multimeter (between 26 and 30 years old) that has a bit of a wonky LCD display, and a blown fuse on the 10A input, but is otherwise still probably my most accurate meter. If its batteries aren’t dead, I may be able to use it to get better measurements.

I tried measuring some known resistors, to see if the meters are way off. I tried an 11.8kΩ ±1% resistor: Fluke meter says 11.77Ω and the suspect multimeter says 11.67kΩ, while for a 732Ω±1% resistor, the Fluke meter says 731.1Ω, while the suspect meter says 718Ω. So the suspect meter appears to be reading 1–2% low, while the Fluke meter is within the accuracy of the resistors. So I boiled up some more water and tried another series of readings (the 63 readings are in a table on a separate page to avoid clutter here.)

Note that there are three runs of data: cooling down from boiling, cooling down from hot tap water, and cooling with ice from room temperature. I found it easiest to do this work on the counter in the bathroom, where I could easily adjust the temperature by pouring out some water and adding more hot or cold water. I was also very careful to make sure that the bulb of the thermometer was in contact with the thermistor while making the measurement, so that they were as nearly the same temperature as I could make them.

Let’s see what sort of fit we can get with this data.

The second data set, with 63 data points, is much cleaner than the first data set, and is well fit by a simple 2-parameter model (leaving out the third term of the Steinhart-Hart equation. Because it is hard to read the thermometer to better than 0.5°F, the fit is really quite good.

The data once again does not match the specified B-value of 3435°K±1%, but B=3174°K, though the curves are quite close for warmer temperatures.

The data sheet reports the 3435°K B-value as a B25/85 measurement, that is, it is based on values at 25°C (77°F) and 85°C (185°F).  If we just fit over that range, we can get the B-value up to 3236°K, which is still a long way short of the specified B-value.

Since I now trust that the resistance measurements are fairly good, the large error in the B-value has to be either from the thermometer or the thermistor. Because I don’t have a more accurate thermometer, and I’m not inclined to get one, I’m a bit stuck at this point in determining whether the thermistor meets the spec or not.

Doing a large number of measurements like this took far too long for the first part of a lab.  A lot of the time was spent waiting for the temperature of the water bath to change (or trying to make change by adding water or ice). We’ll probably have to ask for just 5 or 6 values, perhaps providing them with 5 or 6 water baths in thermoses that they can run their thermistors through one after another, to get the measurements rapidly. We will need some decent thermometers, capable of reading to ±0.2°C, if they aren’t too expensive.

Tomorrow I’ll try doing the electronics part of the lab, adding series and parallel resistors and measuring the voltage with the Arduino.

Speakers and function generator

Filed under: Circuits course — gasstationwithoutpumps @ 12:54
Tags: , , , , , ,

In a previous comment, I had remarked on the difficulty I was having finding cheap loudspeakers.  I did a little more searching today, and found a good source: Parts Express.  I’ve bought stuff from them before, and they seem to be a reliable supplier.  They currently have a couple of small speakers for $2 each:

Even better, we could get a pair of 3″ 4Ω speakers in cabinets for 99¢, which could be used as is or cannibalized for parts.  All these deals are special offers, and so may not be available when we need to run the class, and probably can’t be purchased with University purchase orders.  I certainly wouldn’t want to be the one having to deal with the University purchasing system to get them.

But if we wanted audio output for any of the labs, we could afford to use loudspeakers.

When I complained about my function generator having died, Mylène suggested a kit generator.  I looked at the Elenco FG-500K Function Generator Kit she suggested, and read the PDF manual for the kit. The manual reminds me a lot of the HeathKit manuals that I grew up with, though with a bit less explanation of how things work.  I might get one just for the nostalgia value of building a kit like that again.

The function generator itself seems almost as functional as the much larger bench generator that died on me. The only feature that seems to be lacking is a frequency-modulation FM input, which I don’t expect to use much anyway. It uses the Exar XR-2206 chip, which does have FM capability (with a current input), but the circuit doesn’t use that capability.  It looks possible to add FM input, if needed, since the FSK input and the second timing resistor input are currently unused and hooking them up for FM would not be difficult.

The XR-2206 is supposed to run off 12V (10V to 26V, according to the data sheet), but is being run off a 9V battery. I wonder how much this under-voltage affects the behavior of the function generator. The function generator can be run off an external power supply, and the electrolytic capacitors are 16V capacitors so running off a 12V supply should work, if there are problems with a 9v supply.  I would want to change the jack they use for power, though, from a earphone jack to a barrel that matches one of my wall warts (probably the same size as is used for the Arduino, a 5.5mm/2.1mm center-positive barrel). I wish that power barrel connectors were more standardized—every wall wart I have seems to use a different connector, and there is no relationship between the voltages and the connectors. (Actually, 5.5mm/2.1mm seems to be the most common—I have 3 wall warts with that connector, each with a different voltage.)

They also push the high-frequency spec a bit to get 1MHz (which is the typical spec for the upper limit, but the min spec is only 0.5MHz)—their smallest timing capacitor is 820pF, while the spec suggests a minimum of 1000pF.  They don’t push the lower end, going down to 1Hz, while the spec claims the chip can go down to 0.01Hz.  The Elenco design switches the timing capacitor (100µF, 10µF, 1µF, 0.1µF, 0.01µF, 820pF) and uses a potentiometer to vary the timing resistor from 620Ω to 10620Ω.  Since the XR-2206 chip produces an output frequency at 1/(RC), the lowest frequency range should be 0.94Hz to 16.1Hz, and each switch up should provide a factor of 10 increase, except for the last one, which is 115kHz to 1.97MHz.  I wonder why they didn’t use a 1000pF capacitor to stay in spec—I might substitute a part there, if I get the kit.


2012 June 22

Oscilloscope practice lab

My thermistors and op amps were shipped yesterday morning, but did not come in today’s mail.  I hope to get them tomorrow. In the meantime, I’ve had a good conversation with Mylène in the comments on my previous posts.  She had some suggestions which are probably worth following up on:

  • Do a stethoscope project for one of the labs, which would require simple audio amplification.
  • Start student familiarization with the test equipment by having them use the multimeters to measure other multimeters.  What is the resistance of a multimeter that is measuring voltage?  of one that is measuring current? what current or voltage is used for the resistance measurement?
  • Start oscilloscope familiarity by looking at the output of power supplies. What ripple can you see on the voltage output of a benchtop supply? of a cheap wall wart?  This requires the students to learn the difference between DC and AC input coupling for oscilloscopes.
  • On the first day that students are using oscilloscopes, have them try looking at the output of a microphone.  Most already have some idea about what sound should look like as a time-varying signal, and it is fun for them to play with different sounds (singing vowels, clapping, playing music or test tones from their phones, … ).

Since my thermistors weren’t here, but I did have an electret microphone that I bought some time ago, I decided to try the oscilloscope labs.

The first thing I had to do was to adjust the scope probes to match the input impedance of the scope, using the square-wave calibration output.  I seem to need to do this every time I use the scope, even though I never change the leads. Perhaps I’m just impatient and don’t give the scope enough time to warm up, since I sometimes have to readjust the scope probes after using the scope for a while.  I assume that Steve has a handout on how to adjust the scope probes and why it is needed.  If not, we need to either find a good tutorial for the students on the web, or write one.

The first thing I should have done after adjusting the scope probes was to look at the wall wart output using AC coupling on the scope, to see how much ripple there is.  In fact, I did not do this until much later.

Ripple on the wall wart power supply with no load. The vertical scale is 20mv/division, so the ripple is about 40mV peak-to-peak.

If I filter the power supply with a simple RC low-pass filter (33kΩ and 470µF, for a 15.5 second time constant), the 100Hz ripple goes away (and it does seem to be 100Hz, not 60Hz—the trace is not steady if I use the 60Hz “line” trigger instead of the internal trigger).

Even after filtering, I’m still left with some high-frequency noise, decaying 23MHz bursts that seem to be somewhat irregularly spaced (I can’t seem to get a steady enough trigger to capture a second burst in a stable position, but they seem to be over 10µsec apart).  I assume that this is some sort of ringing in the input of the scope, as it is present even with the wall wart unplugged, and with the scope probe not connected to it. It gets bigger if I put a long loop of wire between the scope probe and the scope ground, but adding bypass capacitors seems to have little effect.   This signal is about 7mV peak-to-peak with the scope probe on the breadboard at the output of the RC circuit with or without the wall wart plugged into AC power.  Disconnecting the wall wart using the DC barrel plug reduced this high-frequency noise to about 2mV peak-to-peak, so I suspect that the wires connected to the scope probe make a difference.   The noise happens on both channels and seems to be the same on both.

The back of the electret mic. It looks just like the drawings of the CUI Inc part number CMA-4544PF-W, which is the cheapest microphone at DigiKey, so I assumed that it was that part.

I had bought the electret microphone without any spec sheet, and it is completely unlabeled. To figure out how to use it I had to guess and do a little web searching. I don’t remember where I got it (not DigiKey, since I don’t have their inventory label for it), so I pretended it was the cheapest mic from Digikey, the CUI Inc CMA-4544PF-W. While I was writing up this post, I remembered that I probably bought it from Sparkfun, as their electret microphone. But they give the spec sheet for the Knowles Acoustic MD9745APZ-F, which has very similar specs. But the pictures on the Sparkfun website and in the Knowles data sheet don’t match as well as the pictures in the CUI data sheet, so I think I have a CUI microphone, though not necessarily the one whose data sheet I used.

Circuit copied from the CUI CMA-4544PF-W datasheet. I used a 4.7kΩ resistor for the load, though the datasheet suggests 2.2kΩ—I didn’t have a 2.2kΩ resistor handy. I also used 0.56µF capacitor instead of a 1µF capacitor—again, using what I had on hand.

An electret microphone does not produce any electricity—you need to power it from a power supply using a series resistor.  The circuits shown in data sheets are all fairly similar.

With this circuit I had no trouble getting a good signal from the mic. My first attempts had just connected the wall wart power supply directly to +VS, but that produced a fairly large ripple signal (which lead me to look at the wall wart ripple directly with the scope).  Adding an RC filter with a fairly large resistor and capacitor (33kΩ and 470µF, for a 15.5 second time constant) cleaned up the power supply and no ripple was visible in the output.  The output of the electret microphone varied depending on how loud a sound was produced, but easily got 60mV peak-to-peak for a vowel sound and 150mV peak-to-peak for clapping.

A trace of rough vowel sound.

One interesting thing I observed is that I can get quite a large pulse just by moving my hand toward and away from the microphone, with pulses about 100msec wide. So it looks like the mic can go down to 10Hz, and possibly lower.

We would need an amplifier to use this as a stethoscope. Crude attempts (pressing the mic against my chest) were not very promising. I did not see any signal that seemed correlated with my heartbeat.

« Previous PageNext Page »

%d bloggers like this: