# Gas station without pumps

## 2014 May 15

### Very long time in the lab

Filed under: Circuits course — gasstationwithoutpumps @ 23:43
Tags: , , , ,

I spent 7 ½ hours in the circuits lab today, helping students finish their optical pulse monitors.  One group finished on time, and a couple of others finished with only an extra hour, another group gave up (taking the project home to see if they could finish there), and one student went to a meeting, but came back before I had left, so I stayed until she had finished also. Everyone got the first stage working, and were able to see pulse signals with a 2–10mV amplitude (on top of 100–200mV DC and about 20mV 60Hz noise). All but the group that took the project home got the second stage working and able to record clear pulse signals on the PteroDAQ software (though some had the gain a bit too high and got clipping).

I don’t think that this lab needed to take as long as it did for the students, and I’ve been thinking about ways to get them to do it much quicker next year.

• The first thing to do is to separate the electronics from the scaling of the light signal.  Their math is too slow to put it on the critical path to getting the lab done.  Instead, I’ll make the analysis of the size of the signal they ought to see be done after a more tinkering approach to design has been done.
• The next thing to do is to require that a schematic for the first stage be turned in on Monday, so they work on it over the weekend.  They’ll have to come up with a guess at the initial resistor size, but I can give them a rough estimate (within a factor of 10, say) of the current to expect from the phototransistor.
• I can also teach active RC filtering a little sooner, so that I can have them design the low-pass filter to reduce 60Hz interference in their first design.

The 60Hz noise is a much bigger problem in the circuits lab than at home—probably because of all the fluorescent lights and benchtop equipment. It was reduced enough by a single RC low-pass filter that it did not saturate the second stage, and it was well removed by synchronous sampling (so I’m glad the PteroDAQ software allows specifying sampling frequency and not just period—it is easier for students to enter 30Hz than 33.333msec (which was not a period the old software supported, anyway—they would have had to go to 50msec).

One problem that some students encountered today that I had not anticipated is that some fingernail polish is opaque to the 627nm LED light we were using.  I don’t normally wear fingernail polish, so it had never occurred to me that designing the fingertip sensors to shine through the fingernail might be a bad choice in some circumstances.  I suppose that this is yet another reason why we need a diversity of engineers—unrealized assumptions of one subculture may be obvious problems in another.

I don’t know what I’ll do about the fingernail-polish problem next year (this year the student just scraped one fingernail clean and got the circuit to work). I suppose I could simply announce that fingernail polish may be opaque, so students may wish to keep one finger clear on lab day. I could let students discover the problem on their own (or with a little guidance from me), as happened this year. Or I could try to design a different way to mount the LED and phototransistor.

One problem with the setup I used this year is that to get a good signal you need to apply enough pressure to your finger to be between the systolic and diastolic pressures.  That can be difficult to do, though with a bit of practice I got pretty good at it today, as I helped students debug their circuits. It would be good to have a simple adjustable spring clip that would hold the two optoelectronics components and apply the appropriate pressure (around 80mm Hg, 10kPa, or 1.5psi).  The reason my first attempt at an ear clip was such a failure was that it squeezed too hard and cut off all circulation—if I had made a clip that squeezed with only 10kPa, it might have worked fine.

Over the summer I might play around with different designs for mounting the optoelectronics, to avoid the fingernail-polish problem and to get a more controllable squeeze for whatever part of the body the light is shining through.

Tomorrow I’ll have to cover strain gauges, Wheatstone bridges, and instrumentation amplifiers.  I checked today that I can still derive the gain equations for both 2-op-amp and 3-op-amp instrumentation amps. I’ll assign students to do their block diagrams, schematics, and layout for the pressure sensor amplifier to turn in on Monday, so that they’ll be able to start lab promptly on Tuesday.  With any luck, Thursday can be a catch-up day for any labs that needed to be redone with a little more data.

## 2014 May 14

### Phototransistor lab

Filed under: Circuits course — gasstationwithoutpumps @ 00:15
Tags: , , , ,

Once again, no one came to lab today with their prelab homework done. There was a lot to do again this week, as they needed to figure out how much light was emitted by an LED, how much of that would get through a finger, and how much photocurrent that would induce in a phototransistor. The models they are using are pretty crude, but should be able to get within a factor of 10 of the right amount of current. I provided much more scaffolding in the handout, even doing some of the computations for them, but it doesn’t seem to have helped any.  I need to come up with some way to get students to actually do the prelab calculations—maybe collecting them as homework on Mondays?

They also had to do some quick checks to make sure that they could get an LED to light up with the amount  of current they designed for, and that the phototransistor and photodiode provided roughly expected currents in room light (and that shadowing the photodetector resulted in a change of current). A lot of the students still had serious problems with debugging (like not being able to figure out that they had put the LED in the wrong way around).

I did show the students the trick of looking at IR emitters with a digital camera to see them light up blue, but the trick did not work with one of the student’s cameras (an iPhone, don’t know which model), which apparently has an IR-blocking filter for its camera.

Only one group got as far as building their transimpedance amplifier, and then only by extending the lab to 4.5 hours instead of 3.  I suspect I’m going to have a late night on Thursday this week as well shepherding the rest of the groups through both the first-stage and second-stage of the amplifier.

I found one serious error in my handout for the lab, giving myself a REDO for the lab—the transimpedance amplifier had the + and – inputs swapped! The problem arose because I always put the – input on top, but SchemeIt puts it on the bottom, and I forgot to flip the component before wiring it up. I have already redone the handout, fixing that figure.

Tomorrow’s lecture class is supposed to be on filtering and amplifying the output of the first stage, but with only one group having finished the first stage and observed the output on the scope, this may be a difficult task to explain.  I’ll probably have to give them some numbers computed from my results, which were that I got about a 2–9nA pulse-based signal on top of a 100–150nA DC signal.

One important observation that my son made tonight was that the big pulse signals only came when I pressed my finger down with a pressure between my systolic and diastolic blood pressure.  I knew that there was a sweet spot, where I could feel my pulse, but I had not stopped to think what caused that.  Both feeling the pulse and the large change in blood volume come from stopping the flow during diastole, but allowing blood through during systole.

## 2014 May 10

### Second op amp lecture

Today’s lecture was the second one on op amps, after their audio amp lab.  I had 3 topics I wanted to cover: virtual grounds, transimpedance amplifiers, and gain-bandwidth product.  The gain-bandwidth product doesn’t really fit with the others, but they had just learned about voltage and current limitations in the audio-amp lab, and the only signals they use all quarter of high enough frequency for the gain-bandwidth product to matter are the audio signals—the heartbeat and breath pressure signals are very low frequency (DC to 20Hz bandwidth).

Before getting to the electronics part of the content, I did talk a little about the reasons I gave them such a long multi-step computation for the prelab last week, where they had to work through 8 or 9 steps to come up with the desired gain.  I explained that I knew they could do single-step problems, but that the quiz showed that they were having trouble putting their knowledge together to do two-step problems, so by giving them practice with long multistep problems, I was hoping to make two-step and three-step problems seem simple. Next week’s optical pulse monitor lab will again require a lot of steps, mostly in figuring out how much light gets through a finger.  This sort of computation (how big a physical signal is, how sensitive a sensor is, and how much gain is needed to observe and record the signal) is fundamental to the sensor interfacing that is the heart of the course, so I’m not apologizing to the students for the complexity of the task.

I started with virtual grounds, pointing out that next week’s lab would be powered off the KL25Z processor boards, which provide only 2 voltages: 3.3v and ground, so that they don’t have a symmetric power supply.  I drew a schematic for a non-inverting amplifier (gain 11, though that was irrelevant), with a 1.65v “virtual ground”, then we talked about how to get a 1.65v source.  I took the time to tell them about the existence of low-dropout voltage regulators, (LDOs)  and that those chips were how the KL25Z board produced 3.3v from the 5v power that came over the USB line.  I also told them that the LDO chips were capable of sourcing current, but not really capable of sinking current.  (I’m actually not sure whether they are incapable of sinking current—it would be possible to design a chip capable of both, with a small voltage change between the two directions of current flow to avoid excessive flow-through current.  I don’t think that chips normally have that capability, though.) I also told them that they did not have an LDO ship in their parts kits,  and challenged them to come up with another way to generate 1.65v from 3.3v.

Deer-in-the-headlights look.

After a fairly long wait, I asked them if they could produce 1.65v if they did not need to draw any current from it.

Deer-in-the-headlights look.

After a lot of random guessing, someone finally guessed “voltage divider”.  (I’ve told them almost every week that we have three concepts in the class: voltage dividers, complex impedance, and negative-feedback op amps, and they’ve been guessing voltage divider for almost every circuit question for 6 weeks, so I was surprised at how hard it was for them to see when a voltage divider would actually be appropriate.)  Once that guess was made, they quickly came up with two equal resistances.  I then showed them why sourcing or sinking current would cause the voltage to vary (by showing mismatched currents through the two resistors—I don’t know whether any of them got it though, as they seem to still be almost incapable of mapping any sort of math to the phenomena the math models).  I challenged them then to come up with a way to provide the same voltage but allow current to be drawn.  This took less time than before, with a student deciding that an amplifier was needed and remembering the unity-gain buffer from last week.

I was expecting students to have more trouble with the unity-gain buffer than with the voltage divider, because they’ve been using voltage dividers for 6 weeks, and this is the first time they’ve needed a unity-gain buffer. But it seems that recency trumps repetition in student thought—they are so inured to cram-and-forget learning strategies fostered by “unit-based” course organization that each new idea displaces all previous ones.

Almost all the useful ideas came from one student, though most of the class was participating. I’m worried that only that student is learning the material, and that I’m not reaching the rest.  (His group is usually the first to finish in lab also, no matter whom he is partnered with.)

After we had a virtual ground circuit consisting of a voltage divider and unity-gain buffer (and I reminded them of how the unity gain buffer worked), I pointed out that this virtual ground circuit was limited in the amount of current it could source or sink by the current capabilities of the op amp, which they had already encountered in seeing the difference in their audio amplifier outputs between having the 8Ω loudspeaker and not having it as a load.  For the MCP6004 chips they are using, with a 3.3v power supply, the current limit is about 15mA.

I also introduced them to another sort of voltage reference, using a Zener diode in place of the lower resistor in the voltage divider.  I think that this was a mistake though, as I may have confused them by giving them too much information.

After the virtual ground, I switched to talking about gain-bandwidth product.  I pointed out that the gain they had been getting was limited by the voltage rails and current limitations of the op amp, but that there was another limitation that affected the audio amplifier: a built-in low-pass filter that limited the open-loop gain.  I explained that the filter was there to prevent high-frequency oscillation due to stray parasitic feedback, but I did not even attempt to explain phase changes and oscillation—we’re sticking with amplitude for almost all analysis in this course, as their understanding of complex numbers is shaky enough that even that is stressing their skills.  I plotted the gain vs frequency on a log-log scale, which looks exactly like the low-pass RC filters they have seen already (at least in the range of frequencies they’ll use—there is usually a second-order effect with a steeper rolloff at frequencies above where the gain is less than 1).  I pointed out that the sloping line was proportional to 1/f, so that the gain times the frequency was constant (the gain-bandwidth product). For the MCP6004 chips, the gain-bandwidth product is 1MHz.

The gain of a negative-feedback amplifier is limited by the open-loop gain, so at 20kHz, their amplifiers could not produce a gain higher than 50.  I explained then the notion of multistage amplifiers, where each stage provides part of the gain (and possibly other functions, like filtering, level changing, or current-to-voltage conversion) as a way around the gain-bandwidth-product limitation.

We then switched to transimpedance amplifiers.  I first broke down the word into “trans-” and “impedance”, and explained that the “trans-” prefix here meant output/input (so opposite sides of the amplifier).  Since these are bioengineers, they are used to the “trans-” prefix from chemistry.  I asked them for the definition of impedance, and got the voltage/current definition from them after a few false starts.  So a transimpedance amplifier is one that provides a voltage output from a current input, and its gain is expressed in Ω (that is, volts/amps).

I pointed out that the pullup resistor in the microphone circuit that they had been using was a current-to-voltage converter, but that the voltage across the microphone varied with the current.  The microphone needs a nearly constant DC voltage across it, but the current fluctuations (around 1µA) were small compared to the DC current (around 200µA), so the voltage across the mic was nearly constant.  The devices they’ll be using next week (photodiodes and phototransistors) have essentially 0 current in the dark, so the signal is not a small fluctuation on a large DC current.  If we want to keep a nearly constant voltage across a photodiode or phototransistor, we can’t use a simple pullup.

So the transimpedance amplifier is needed not just to convert current to voltage, but to hold the bias voltage constant as the current changes.

I then tried to get the students to develop the transimpedance amplifier design from an op amp using the design goals. I started by asking them about the inputs of the op amp, trying to get them to remember that the negative-feedback circuits tried to bring the negative input to the same voltage as the positive input.  They’ve not had enough practice with op amps yet to have that useful rule of thumb easily recalled, so we ended up deriving it again.I started with asking them about what a bare op amp did.  It took a while before someone could come up with amplification of the difference between the two inputs.  I asked them what the gain was (looking for answers like “a lot” or “the open-loop gain”), but again got deer-in-the-headlight looks.  I ended up feeding them the answer to this one, as I ran out of Socratic questions to lead them to a good answer, and their guessing started getting wild.

I then asked them what keeping the output well within the power rails implied about inputs.  This took a while, but eventually one student realized that the difference has to be the output divided by the open-loop gain. (And yes, it was the same student.) So I was able to point out that a very large open-loop gain meant a very small difference in the input voltages, and that one could use as a rule of thumb that the inputs to an op amp in a negative feedback circuit was at the same voltage.

This got the student to the point where they figured out that the bias voltage could be put on the positive input and the current input whose voltage needed to be controlled on the negative input, but then they stalled again.  I pointed out that op amps were designed to have essentially no current through the input pins (about 1pA for the MCP6004 chips at room temperature), so the current on the input had to come from somewhere.  I don’t remember now whether a student suggested a connection to Vout or whether I gave them a resistor to Vout as a solution.

I then tried to get the students to figure out the behavior of the transimpedance amplifier from the current through the resistor.  They needed to realize two things:

• That the voltage drop across the resistor was Vout-Vm
• That the current through the resistor was the same as the current through the input port.

It took them a long time to get each of these—they kept wanting to make the voltage drop be just Vout. Physics classes do not seem to be doing a good job of getting across that notion that voltage is always a difference between two nodes in the circuit and I haven’t been able to make that an automatic response yet after 6 weeks—that must be a harder concept than I would have thought.

Even after they finally got the voltage drop right (yes, it was the same student), no one could come up with the idea that the current had to be the same as the current through the input.  I finally had to give it to them, pointing out the hint on the board—I’d drawn both currents with arrows on the board and had labeled them both “I”.  I reminded them of Kirchhoff’s Current Law, and pointed out that since no current flowed through the op-amp any current through the input port had to also be flowing through the resistor.

We then had the final formula: $V_{out} = V_{p} + R I$, and I could point out that the gain of the transimpedance amplifier was just the feedback impedance, R.  Since we were out of time at this point, I just mentioned two applications of transimpedance amplifiers they might have heard of—the nanopore lab and the nanopipette lab (where many bioengineers do their senior theses) both use very high gain transimpedance amplifiers (patch-clamp amplifiers) to measure currents in the 1–100pA range.

On Monday I’ll have to go over photodiodes and phototransistors, and probably repeat the transimpedance amplifier with a photodiode or phototransistor as the current source. I did direct them to do the prelab homework over the weekend, since we can’t afford to waste the entire Tuesday lab time doing the prelab as they did this week.  I’ll ask them on Monday about what results they got and where they bogged down in the computation—I expect that most of them will not have completed the prelab assignment, but I’ll be very disappointed if none of them have tried it.

## 2014 May 9

### Low-power audio amp lab completed

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

Everyone finished their audio amps yesterday and got them working, and most finished on time, though one group took a bit longer than the rest, so I was in the lab for 5 hours instead of 3. They did not keep careful notes of how they did the prelab, and could not reconstruct their thoughts, so they were very confused about why the amplifier was clipping with the loudspeaker in place, but not when it wasn’t.  I think that they eventually figured it out, with somewhat heavier hinting than I usually like to use (I was getting tired).

Each group had a different design, as they chose slightly different voltages for the power supply, hooked up the mic with either the full power supply or half the power supply for DC bias, used different pullup resistors for biasing the mic, used different combinations of R and C for their high-pass filter, and had different target gains.  I think I should point out in class how small changes in somewhat arbitrary design choices can result in rather different designs—all of which are correct.

One problem I had not anticipated, but ought to have, is that a lot students initially chose to use small resistors and large capacitors for their high-pass filters, but the filter is in parallel with the bias resistor for the microphone for AC, so if it has a low impedance, the I-to-V conversion results in a small AC signal.  This problem was noticed when one group was confused about why their AC signal was so much lower than they had expected.  It took me a while helping them debug to figure out what was going on (I generally don’t use electrolytic capacitors unless I need to, so I’d never set up a DC-blocking filter with a low impedance).  In next year’s handout, I’ll have to put in a bit more information about the need to have the RC filter be a fairly high impedance compared to the DC bias resistor, perhaps even including it in the sensitivity computation.  After seeing the problem, I did warn each group about the problem, and they all had to redo their RC filters, as they’d all chosen large C and small R.

A number of groups also used very small resistors for their feedback loops, until I suggested that using much of the current capabilities of the op amp to drive the feedback network was not leaving them much to drive the speaker.

I’ll also have to outline the steps of the sensitivity and gain computation more carefully next year, as students were not able to do it on their own without guidance.  Almost everyone ended up with too high a gain empirically, getting clipping at the loudspeaker with fairly modest sound input, but I didn’t see mistakes in their computation, and the op amps were clipping at about the expected current limit. Perhaps the input sounds were louder than we had allowed for—certainly the signal generators driving loudspeakers that we were using as sound sources were much louder than 60dBA at 1kHz, which is what the circuits were designed around.  Students did observe that without the loudspeaker the amplifiers produced nice-looking sine waves, but that adding the loudspeaker produced the clipping—some turned up the input sound to the point where they could observe the voltage clipping without the loudspeaker.  I should add a request for testing the amplifier with and without the loudspeaker next year.

Everyone did get enough gain from their amplifiers to hear sound from their loudspeakers and to get feedback squeal if they put the loudspeaker near the mic.  Not even the quickest group had the time to add a volume control or tone control circuit, so I’ll probably cut that from next year’s lab, though I’ll probably have them do adjustable gain for the class-D amplifier in 3 weeks, if only to save our ears from high-volume feedback squeal.  I’ve been wondering whether I should include a traditional large potentiometer (and not just an 18-turn trimpot) in the kits next year, so that students can have a more easily (if less precisely) adjustable resistor.  They are only about 70¢ for cheap ones, and they would make adding a gain control easier.

Students are getting fairly good at using the Tektronix TDS3054 digital oscilloscopes for making measurements, but everyone once in a while the scopes seem to get wedged in a weird mode where they don’t respond to some of the knobs (like setting the low pass filter) and the only way out we’ve found is to run “autoset”, and then reset a number of the parameters from there.  Although the scopes have some nice features, the user interface is still one of the worst I’ve encountered, with deeply layered menus covering the screen and buttons that cycle through different modes.

Measuring anything about the amplifiers was difficult, because the ambient noise in the room, particularly of other groups talking, made fairly large uncontrolled input signals.

One thing I did not expect, and still don’t have an explanation for, is that for all the groups the output seems to have been centered a little high when the loudspeaker was in the circuit, so that the op amp was at or near saturation at +150mV output even when there was no sound input.  With the gains the students were using, that would have resulted from the input voltage being around 0.1–1mV too high, which seems to be too much for any of the explanations I’ve thought of.  I did not observe this in my testing at home, but I don’t have a ±3v power supply at home, so I did not have exactly the same circuits as the students.

One group had a 50kHz triangle-wave oscillation for a while, but it went away while we were attempting to debug it, so I never found a satisfactory explanation.

## 2014 May 7

### Quiz corrections

Filed under: Circuits course — gasstationwithoutpumps @ 20:36
Tags: , , , , , ,

As I reported last week, students did poorly on the first quiz, which came as no surprise to me.  I had the students redo the quizzes as homework, allowing collaborative work (as long as they acknowledged the collaboration in writing).  They turned in the homework on Monday, a week after the quiz, and I returned them today.  No one aced the redo, with the top score being still only 25/33 (which would have been an A on the first pass, on a redo maybe a B+).

A lot of the students still seem to be having trouble with complex numbers—they got the formulas right when working symbolically, but then the exact same question with numbers instead of letters (which could be done by just plugging into the formulas) came out with real numbers when complex impedances were asked for.  Also, a lot of sanity checked were skipped (several people reported a battery as doubling in voltage when hooked up to a resistor, for example).

These students are not major mathphobes (they’ve all passed a couple of calculus classes and most have done more math past that), but they don’t seem to have any sense for reasoning with or about math—they just want to plug in and grind, even on simple problems like ratios in voltage dividers. This class has almost no memory work (I gave them a one-page handout at the beginning of the year with all the math and physics I was expecting them to memorize), but relies heavily on their being able to recognize how to apply those few facts.  This often requires subdividing a problem, like recognizing that a Wheatstone bridge is the difference between two voltage dividers, or that a 10× oscilloscope probe is a voltage divider with R||C circuits for each of the two impedances.

I spent the entire class today working through each problem in the quiz, to make sure that everyone in the class could understand the solution, and (more importantly) see that they did actually have enough knowledge and math skill to do the questions. Some of the students were feeling overwhelmed on the quiz, because they are not used to doing anything more than 1-step pattern matching for problems, and some of the quiz problems required two steps.  None of the quiz problems were as hard as the prelab they had to do this week, which involved 8 or more steps to get the resistor values to set the gain of the amplifier:

1. Determine the pressure level of 60dB sound in Pa.
2. Determine the sensitivity of the microphone in A/Pa:
1. Convert -44dB from spec sheet to a ratio
2. Get V/Pa sensitivity for microphone for circuit on spec sheet
3. Convert to A/Pa given resistance of I-to-V conversion resistor on spec sheet.
3. Determine voltages needed for op amp power supply.
4. Determine I-to-V resistor needed to bias microphone in saturation region.
5. Convert A/Pa sensitivity, RMS pressure level, and I-to-V resistor to RMS voltage out of microphone.
6. Determine corner frequency and R, C values for DC-blocking filter.
7. Determine maximum output voltage range of the amplifier as the most limiting of
1. Voltage range of op amp outputs
2. Power limits of loudspeaker (10W)
3. Current limit of op amp (which is a function of the power-supply voltage) into 8Ω loudspeaker
8. Determine max gain as ratio of RMS voltage into op amp and RMS voltage out of op amp (I’m allowing them to be a bit sloppy about RMS voltage vs amplitude, since we are not looking just at sine waves—the amplitude of a symmetric square wave is the same as the RMS voltage.)
9. Choose resistor values to give the desired gain.

I’m hoping that pushing them go through these multi-step designs in the lab will give them more practice at decomposing problems into smaller pieces, so that two-step problems on a quiz no longer seem daunting, but routine.

I’m going to be giving them another quiz in about a week, covering op-amp basics and the amplitude response of RC filters.  I’ve got to figure out the best time to do this—possibly a week from Friday, after they’ve done another op-amp lab (using a phototransistor to make a pulse monitor, using this handout).  I think I’ll reorder the labs after that, doing the pressure sensor instrumentation amp lab, then the class D power amp, then the EKG.

Next Page »