# Gas station without pumps

## 2012 June 30

I did some playing around with a simple op-amp amplifier to try to get an EKG signal, based on ideas like those in DIY ECG Machine On The Cheap, but I was unsuccessful in seeing anything other than 60Hz noise.  I decided that it would be worthwhile to try building an instrumentation amplifier.  Now, I can’t do as good a job at matching components as a laser-trimmed off-the-shelf instrumentation amp (like the TI INA126PA-ND, which costs $2.50 each in quantities of 10), but I’m more interested in concepts than high quality at the moment, and I have a bunch of MCP6002 op amp chips already. I decided to use the microphone input scaled down as my input source, as I can get a reliable signal from that. (The µV EKG signals are still eluding me.) I first tried thinking about instrumentation amplifiers from first principles: I knew that the input stages had to have no feedback to the input wires, and that the second stage had to do the differencing of the two inputs. I was having a hard time figuring out a reliable way to reject the common-mode noise and get just the differential signal, particularly at high gain. I finally broke down and read the Wikipedia article on instrumentation amplifiers. In that article, they give a classic design for a 3-op-amp instrumentation amplifier: I don’t have a particularly good assortment of resistors for my breadboard, but I managed to find enough pairs of resistors with nominally the same value to make a version of the circuit. I used a 10kΩ trimpot for the gain resistor, so I could adjust the gain. I initially set the trimpot to 2kΩ. Wikipedia reports the gain for this circuit as $\left(1+ \frac{2R_1}{R_{gain}}\right)\frac{R_3}{R_2}$, which matches my analysis of the circuit. Since I’m using single-power supply op amps, I also needed to make a bias voltage supply to act as “ground” for the feedback loop on the positive side of the differential amplifier. I’m wondering if we should have the students use a proper voltage reference (like the TI TL431ILP) instead of a voltage divider to get the bias voltage. The adjustable voltage references aren’t any more expensive (12.4¢ each in quantities of 10) than Zener diodes (12.6¢ each in quantities of 10). For an EKG circuit, the bias voltage would have to be connected to the body. Here is the final circuit as simulated and implemented: Microphone signal source and instrumentation amplifier. The signal source produces about a 140µV difference between Vin_plus and Vin_minus, which is nicely amplified. The amplifier appears to be working, amplifying the 140µV input to a 200mV signal (with a fair amount of noise added). Of course, with this signal source, I can’t really see whether the output is really a result of amplifying the differential signal, or a lesser gain amplification of the common-mode signal (since the differential signal is just 1/700th of the common-mode signal). The amplifier stops working if I set R_gain below about 1.8kΩ in this circuit. (I determined that by adjusting the potentiometer down to about 500Ω, seeing that the circuit produced no output, then gradually increasing the potentiometer until I got a signal again (albeit one that obviously had some clipping). If I want higher gain (which I probably do for an EKG), I’ll need to adjust the gain of the second stage, or add another stage. Hmm, if I swap the 24kΩ and 6.8kΩ resistors, I should be able to still set the trimpot to get about the same gain in the first stage and increase the gain in the second stage by a factor of 4. I might try that. Update: 2012 June 30 16:19, I tried that swap and couldn’t get the amplifier to work—the 10kΩ pot is probably not big enough. From a teaching standpoint, this instrumentation amplifier is relatively easy to construct and to understand, but for the students to test it reasonably we would need to use a signal source that has a low differential voltage and large common-mode signal. I think that the students would need a reliable source (not the rather iffy signal one gets from EKG, and not one cobbled together from a couple of benchtop signal generators). I might also want to try a 2-op-amp design, like the one used in the the TI INA126 instrumentation amp: Design for instrumentation amplifier used in the TI INA126 chip. Picture copied from data sheet MicroPOWER INSTRUMENTATION AMPLIFIER Single and Dual Versions SBOS062A – JANUARY 1996 – REVISED AUGUST 2005 I checked the gain for the 2 op-amp design using current flow equations for the two feedback inputs to the op amps, with R1 instead of 10kΩ and R2 instead of 40kΩ. It took me a while to fix all my typos, but I eventually got an old version (9.5) of Maple to agree with TI that the gain is $(R_1+R_2)/R_1 + 2 R_2/ R_G$. I’ll probably buy a couple of the INA126PA amplifiers to experiment with—using one with a gain of 1000 followed by an op amp to increase the gain more may be the only way I’ll get an EKG working. Update: 2012 June 30 16:20 I tried the 2-op amp instrumentation amp with feedback resistors of 24kΩ, 6.8kΩ, and R_G=330Ω, which should give a gain of about 150, but doesn’t seem to be. Hmm—removing the entire $V_{in-}$ part of the circuit, so that I just have an op amp with a 24kΩ feedback resistor, has essentially the same result. That is, I seem to be just doing a unity gain buffer of the $V_{in+}$ signal. That may have been all that was happening with the 3-op-amp instrumentation amplifier also. Time for some debugging! ## 2012 June 28 ### What sensors for circuits class? Filed under: Circuits course — gasstationwithoutpumps @ 22:33 Tags: , , , , What sensors are appropriate to use in a sensor-focused circuits class? I listed a bunch that I’ve been thinking about in Why teach circuits to bioengineers?, but in this post I want to focus a bit more on what criteria we should use for deciding which sensors to include or exclude. Some criteria: • Price. We want students to be able to buy a kit of parts for the course and take everything home with them when they are done. All sensors should be under$5 (ideally under $1) each in quantities of 10. • Variety of things sensed. I’d like for there to be at least 5 and preferably 8 or 9 different properties detected. • Variety of different electrical properties as sensor outputs (at least current, resistance, voltage, and capacitance, maybe also inductance or mutual inductance). • Some sensors should be rapidly varying (for oscilloscope output). • Some sensors should be slowly varying (for recording time course with Arduino). • Some sensors should require amplification. • Easy breadboarding. Students won’t have time to do a lot of soldering, particularly of SMD parts. We should do one or two labs where they do some soldering, but if we use SMD parts for other labs, we’ll need to design and assemble breakout boards for them. Device Senses Output Catalog Price Notes thermistor temperature resistance NTCLE413E2103F520L 35¢ non-linear, very sensitive, slowly time varying, no amplification needed RTD temperature resistance 480-2017-ND$1.94 slowly time varying, only 0.4% change/degree, similar to high-precision  (which cost over $10 each) temp sensor temperature voltage MCP9700-E/TO-ND 25¢ slowly time varying, not very accurate, linear, not much challenge for circuitry electret mic sound current 102-1721-ND 75¢ rapidly time varying, can be amplified or not potentiometer angle resistance 987-1277-ND 66¢ slowly time varying, hard to connect to mechanically? potentiometer angle resistance 3382H-1-252$2.23 slowly time varying, easier to incorporate into a goniometer?, lead in for servos
breathalyzer alcohol resistance 605-00011-ND $4.50 fun for students? needs humidity and temperature correction. pH probe pH voltage SeroSystems pH probe$21 Too expensive and needs temperature correction.
humidity sensor humidity capacitance 480-2903-ND $3.61 pressure air pressure voltage MPXM2053GS-ND$6.51
gel electrodes EKG voltage SilveRest 22¢ (cheaper without snap), very low voltages and 60Hz noise requires good amplifier, time varying
gel electrodes GSR resistance SilveRest 22¢ (cheaper without snap), slowly time varying
CdS photoresistor visible light resistance PDV-P8104-ND 80¢
ambient light sensor visible light current 1080-1019-ND 46¢
phototransistor IR light current 754-1468-ND 19¢
reflectance sensor reflectance current QRE1113-ND 83¢ LED + phototransistor in same package, 5mm sensing distance
IR emitter 754-1600-ND 19¢ IR emitter and red LED needed for pulse oximeter
red LED 660nm 754-1218-ND ? IR emitter and red LED needed for pulse oximeter
green LED 754-1591-ND green LED needed for simple pulse sensor
conductance cell salinity bulk conductance ? ? May require student design and construction. Cheap with Al foil, expensive with Ag/AgCl electrodes.
touch sensor touch capacitance ? ? May require student design and construction.  Al foil and plastic wrap?

Richard Hughey had an interesting idea for an air-flow sensor. Use one of the siren whistles for kids that cost about 50¢ each in quantity. They have a plastic turbine in them, and we could use an LED and light sensor (perhaps one of the reflectance sensors) to get a pulse stream from the turning of the turbine, timing the pulses with an Arduino.

I just noticed that I don’t have any switches, accelerometers, magnetic sensors, … on that list. A breath switch might be a useful sensor for those thinking of the rehabilitation concentration.  A tilt switch is also a reasonable option. A lot of the sensors I have looked at are too expensive for their value in the course, though it might be worth spending a little lecture time going over how they work.

## 2012 June 27

### Bioinformatics in AP Bio, lessons released

Filed under: Uncategorized — gasstationwithoutpumps @ 11:03
Tags: , , , ,

As those who have been reading my blog for a while know, I’ve been working with UCSC grad students to develop materials for bioinformatics lessons for high school biology classes.  I have a series of posts about Advanced Placement Biology courses and the AP Bio exam.

In a previous post about the project, I described our goals:

• The primary goal is to teach students biology, not computer science or bioinformatics.  The bioinformatics should be good support for the underlying biology lesson.
• Whatever we produce should be made available on the web (but putting any answer keys behind password protection, should we end up producing anything that needs a key).
• The students will present the lessons to the class (both to expose the high school students to college student role models and to give the grad students practice teaching), but the lessons should be teachable by non-bioinformaticians.  In particular, the high school teacher should be able to teach it himself next year.
• If things work out well, it might be worth presenting a paper explaining the project (and advertising the materials) at a high school biology teachers conference (perhaps an NABT conference?).

We have just released the two lessons we’ve developed so far: one on genetic diseases, the other on phyogenetic trees.

Each was tried at one school, in 3 sections of AP Bio (where AP bio is a required course for all students).  The lessons took one block each (just under 2 hours for a block), with some sections finishing everything with time to spare and others not quite finishing.  (Consistently the first section getting the lesson having trouble finishing and the third one having time to spare—I don’t know if the difference was in the speed of the initial presentation and our quickness in responding to problems or in the competence of the students.  There was more assistance available to the students for the first two sections, which were also the slower two.

The resources can be accessed directly from http://compbio.soe.ucsc.edu/binf-in-AP/  They are released under a Creative Commons attribution/share-alike license.

Other resources people should know about include

## 2012 June 26

### Why teach circuits to bioengineers?

Filed under: Circuits course — gasstationwithoutpumps @ 17:48
Tags: , , , ,

I’ve been posting quite a bit on the design of the labs for the new applied circuits course we are designing for bioengineering (and other) students,  but I’ve not yet clearly articulated why we require bioengineering students to take a circuits course. Without a clear justification, it could be just another arbitrary hoop for students to jump through—I’m sure many of the bioengineering majors see the current circuit theory class that way.

The justification for an electronics course for bioengineers can be summed up in one word: Sensors.

A sensor (in this context, anyway) is a device that converts some physical or chemical property of interest into an electrical parameter: a voltage, a current, a resistance, a capacitance, an inductance, … .  The purpose of an electronic circuit is to convert this electrical parameter into a numeric value that we can record on a computer or in a lab notebook (which often means going through a voltage or time representation).  There are, of course, other applications of electronics, but connecting to sensors is the one that matters for bioengineers.

It is very common in biological equipment these days to use a digital camera as a sensor, but the design of cameras and image processing software is outside the scope of this class. I think we want to concentrate on one-dimensional sensors that produce just a scalar value (or, more commonly, a value that varies as a function of time).

So in choosing labs, I want to focus on what sensors we are using and what processing we are doing in the electronics to get a numerical result at the end.  Perhaps the course should be titled something like “Introductory circuits with applications to sensors” rather than what we were considering earlier, “Circuits with applications to bioengineering”.

Let’s go through the labs I’ve been thinking about so far and see how they fit with this theme:

• Potentiometer-based goniometer for joint angle measurement.
• Linear resistance-based measurement.
• Useful for lead in to servo motors?
• Useful for control and feedback in robotics.
• Thermistor-based temperature measurement.
• Resistance-based sensor.
• Non-linear response curve.
• Use of voltage divider to linearize curve and convert to voltage output.
• Electret microphone.
• Measuring current and voltage while varying series resistor to determine whether current source or resistance model is better.
• Using series resistance (voltage divider) to convert current or resistance value to a voltage value, which can be viewed on scope.
• Amplifying signal to make large enough to record with analog-to-digital converter.
• Electrical field measurements in an electrophoresis gel.  This one doesn’t fit the new theme—I think that there may be several reasons for discarding this lab.
• Conductivity of saline solutions. Used for measuring ecosystems (like rivers).
• Useful for talking about conductivity of bulk materials.
• Requires thought about materials for electrodes.
• Skin conductance meter.
• Similar problems to conductivity of saline solution for measurement.
• Need recording of slowly time-varying signal.
• Do-it-yourself EKG
• Amplification of very weak signals (though not as weak as nanopipettes and nanopores)
• Can also be applied to other muscles (EMG) for control of robotics.
• Electrical noise
• May be too difficult to get good signals.
• Optical blood pulse detector
• Optical sensing very common in biosensors.
• About the simplest application of light sensing.
• Several different light sensors possible, with different circuits needed to convert to voltage.
• Pulse oximeter
• Expansion of optical pulse detector
• Uses two different light sources alternately.
• Gets into calibration questions.
• Breathalyzer
• Appears to be a resistance measurement.
• Relies on self heating.
• Should appeal to college students.
• Capacitance touch sensor.
• A different modality (not resistance, current, or voltage).
• Conversion to frequency instead of voltage.

It looks like I have enough labs here, but I don’t have any direct chemical detection (other than salinity by conductance). Also, I suspect that the EKG may be too difficult to get working, and skin conductance may vary too slowly, so we may need some other time-varying signals.

## 2012 June 25

### Op-amp lab

Since the thermistor lab seems to have worked fairly well (see More musings on circuits course: temperature lab, Buying parts for circuits course, Temperature lab, part2, and Temperature lab, part 3: voltage divider), I decided to try doing some op amp circuits today, to see how things worked.  I want to get to the point where I can build a simple EKG, to see if that is feasible for a first circuits course.

My playing with the op amps today reminded me why I always hated breadboards: the components are always coming loose, and I spent a lot of the time trying to figure out why things weren’t working as I expected—most of the time it was a resistor or wire not making good contact, though occasionally I had an off-by-one error in inserting a wire.

Building a op amp circuit with MCP6002 chips was a little harder than I expected—the single power supply means that you need to bias the inputs to be in the middle of the range, to avoid clipping.  My attempts to use the op amp to read EKG signals were a complete bust, so I went back to a simpler, stronger signal source: the electret microphone from the Oscilloscope practice lab.

I got amplification easily enough, but I had trouble with clipping.  After a while, I realized that the electret mic was not acting like it was a 2.2kΩ resistor, like I thought it ought to from the 2.2kΩ output impedance spec. I did a series of measurements putting a potentiometer in series with the electret mic and measuring the resistance of the potentiometer and the voltage across it (being careful to remove power before switching to resistance measurement). I then fit both a constant-resistance model and a constant current model to the data. I think that modeling the electret mic as a constant current source is a much better model than treating it as a resistor, for DC analysis.  This might be a useful exercise to have students do along with the oscilloscope practice lab, as multimeter practice.

The voltage across a resistor in series with the electret mic is much better modeled by treating the mic as a constant current source, rather than as a constant resistance.

Since the electret microphone behaves mostly like a current source, I wonder what the 2.2kΩ output impedance on the spec means. Are there any real electrical engineers reading this blog who can explain the output impedance of an electret microphone with an FET output stage?

If I want to have the output of the electret mic be in the middle of a 5.121v range (that is with a DC bias of 2.56v), I’d want a 13.8kΩ series resistor.  I tried using a 12kΩ pullup resistor, and it put the voltage a little above the mid-point, as expected.

My initial efforts to use this signal as the input to an op-amp amplifier worked fine with a unity-gain amplifier (output directly fed back to the negative input), but whenever I tried to set a reasonable gain with a voltage divider, I got serious clipping.  I finally realized that the voltage divider used for clipping had to have its bottom end tied to the center voltage, not ground (all the book examples use symmetric power supplies, so that ground is the center voltage).  I made a bias voltage supply by using a voltage divider and a unity-gain amplifier, and hooked up the feedback voltage divider to the bias supply, rather than to ground. That worked fine, and I could even use AC coupling on the amplifier input with a blocking capacitor, if I added a large resistor to the bias supply for the positive input pin.

Working amplifier circuit with bias supply and AC coupling for the input.
The circuit also works with DC coupling (removing R5 and replacing C1 with a wire).
Circuit drawn and simulated with Circuit Lab.

Once I got all the biasing issues straightened out, the op amp worked as expected (except when I jostled a wire or component loose). I did not measure the gain carefully, but it does appear to be about 6.7, as expected from the design.

Next Page »