Gas station without pumps

2015 July 5

Pullup vs. transimpedance amplifier

Filed under: Circuits course — gasstationwithoutpumps @ 16:08
Tags: , , ,

I have used both pull-up resistors and transimpedance amplifiers to read light signals from phototransistors and photodiodes (see Colorimeter design—weird behavior and Optical pulse monitor with little electronics, for example, though any of the posts tagged phototransistor or transimpedance amplifier may be relevant), so I decided to do a post about what the difference is in terms of performance.

Test setup for comparing pullup resistor and transimpedance amplifier.  The Arduino board outputs a pulse train with two different pulse widths (approx 65µs and 125µs).

Test setup for comparing pullup resistor and transimpedance amplifier. The Arduino board outputs a pulse train with two different pulse widths (approx 65µs and 125µs).

Obviously, a pull-up resistor is simpler and cheaper—it is hard to get much simpler or cheaper than a single resistor—so why ever use a transimpedance amplifier with a phototransistor?

I believe that the answer comes down to speed.

With a pullup resistor, you have a common-emitter amplifier—the photocurrent generated at the base-collector junction becomes the base-emitter current, which controls the collector-emitter current, and the voltage swing at the output is the change in the collector current times the resistance of the load resistor. As you increase the load resistor, you get more voltage swing. But there is a fly in the ointment—the Miller capacitance between the base and the collector, which serves as a negative feedback loop limiting the slew rate of the output.  I’ve looked at that feedback loop before in More on nFET Miller plateau, for example, but the analysis here is slightly different.

Phototransistor with pullup resistor, showing the Miller capacitance (collector-base capacitance) that provides a negative feedback loop.

Phototransistor with pullup resistor, showing the Miller capacitance (collector-base capacitance) that provides a negative feedback loop.

The current through the capacitor from the collector to the base is C \frac{dV_{C}}{dt}, assuming that the base voltage is roughly constant.   We end up with a differential equation:

I_{CE} = \beta I_{BE} = \beta \left( I_{photo} + C \frac{dV_{C}}{dt} \right)

V_{C} = V_{cc} - R I_{CE} = V_{cc} - \beta R I_{photo} - \beta RC \frac{dV_{C}}{dt}

In response to a step change in  the photocurrent, the voltage does an exponential decay towards the endpoint  V_{cc} -\beta R I_{photo} with a time constant of \beta RC.  If we choose a large R to get a large voltage swing, then we end up with a slow rise and fall time.  At high frequencies, we end up with a considerable loss of signal—we have a low-pass filter with corner frequency \frac{1}{2 \pi \beta R C}.

We can speed up the transitions by using a  transimpedance amplifier, which eliminates the change in voltage of the collector, holding it at the same voltage as the positive reference input. The photocurrent still has to charge and discharge the base-collector capacitor C, but there is no longer the pesky multiplication by \beta, the current gain of the transistor, so our bandwidth is  theoretically \beta times higher than with the pullup resistor.

Of course, the slew rate of the output of the transimpedance amplifier is  also limited by the amplifier characteristics. Using an MCP6004 op amp (which has a 600mV/µs slew rate, and 1MHz gain-bandwidth product) and  feedback resistor of 3kΩ to get the same low-frequency gain as with a 3kΩ pull-up resistor, we get much faster rise and fall times than with the pullup resistor:

The top, green trace is using the transimpedance amplifier, while the bottom, yellow trace is from the pullup resistor.  Both are at 100mV/division and 50µs/division, but the DC offsets are different.

The top, green trace is using the transimpedance amplifier, while the bottom, yellow trace is from the pullup resistor. Both are at 100mV/division and 50µs/division, but the DC offsets are different.

I see about 5 times faster edges with the transimpedance amplifier, but I expected a bigger improvement than that—the current gain on NPN transistors is usually in the hundreds. I have a fairly large VCE (2.5V for the transimpedance amplifier and 4.5V—4.7V for the pullup), so the transistor should be well into the saturation region.

If I have a stronger input signal (by lining up the LED and phototransistor better), I get much sharper edges from the transimpedance amplifier:

Again with 3kΩ pullup or transimpedance amplifier, but with a stronger light input.  The vertical scale is now 1V/div, but the horizontal is still 50µS/div.

Again with 3kΩ pullup or transimpedance amplifier, but with a stronger light input. The vertical scale is now 1V/div, but the horizontal is still 50µS/div.

The fast edges for the large signal may be an illusion—the op amp output is hitting the 5V rail and clipping. That saturation also explains why the low-going pulses are shorter than they should be. So maybe the rise and fall for the larger pulses is still slow. I changed the resistors to 1kΩ, which should speed up the rise and fall and avoid clipping for the strong signals:

With 1kΩ pull-up and transimpedance resistors and a strong input signal, the ratio of the transition times looks about how I expected with a 1V/div, 50µs/div trace.

With 1kΩ pull-up and transimpedance resistors and a strong input signal, the ratio of the transition times looks about how I expected with a 1V/div, 50µs/div trace.

I think that the ringing on the rising edge is due to the slew rate of op amp not being fast enough to keep up with the phototransistor and the negative input of the op amp dropping a bit below the positive one.  There is such a triangular blip, about 50mV and lasting about 10µs.  There is a similar upward blip on the downward transitions of the op-amp output, but those don’t seem to cause any any overshoot.

So I think I understand most of what is going on here, but why is the rise/fall time so slow for small inputs?

2015 May 21

Pulse monitor lab part 2 and power-amp lecture

Filed under: Circuits course — gasstationwithoutpumps @ 22:18
Tags: , , ,

Wednesday’s lecture covered a reasonable amount.  I went over PWM again, stressing the key concept: that the relevant value is the average value of the output. I showed the derivation of the average value from the high value, low value, and duty cycle.  I introduced nMOS (and, to a lesser extent, pMOS) field-effect transistors, and showed how they worked as switches, which is the only way we’ll use them.  I introduced both nMOS low-side switches and cMOS output stages, and talked about shoot-through current.

I did not get to comparators, open-collector outputs, and how to create PWM signals from a comparator and a triangle-wave generator, which is the meat of tomorrow’s lecture.

I spent over 9 hours in the lab again today, because I’ve promised the students that I’ll be in the lab 5 p.m.–7 p.m Tuesdays and Thursdays for the rest of the quarter, but the students were done with this week’s lab by 6 p.m.  I think all but one or two of the groups got working pulse monitors.  Debugging was difficult today.  The most common problems were

  • Wires in the wrong holes on the breadboards—usually an off-by-one error.
  • Phototransistor connected up backwards. Students kept thinking in terms of “long lead” and “short lead” and somewhat arbitrarily assigned a positive and negative meaning to them, without going back to the datasheet to see which was the collector and which the emitter.  This was difficult for me to debug, because the phototransistors had wires soldered on and were covered with electrical tape, so I could not see the original wire length nor the flat on the package, and had to trust the students’ claims about which wire was which.  In one case the problem was only debugged after I connected my LED and phototransistor (where I knew the color coding I’d used) to the student’s circuit and saw that the circuit was working.
  • Centering the high-pass filter and second stage of the amplifier at 0V, even though we were using a single-sided power supply, so they needed to make a virtual ground.
  • Swapping the wiring of the LED and the phototransistor.
  • Insufficient gain in the second stage.
  • Difficulty getting appropriate amounts of pressure on the finger to get a good pulse fluctuation.

The students having the most trouble had not prepared a schematic to work from or had very sloppy un-color-coded wiring, or both.  I’ll have to remind students that taking a half hour at the beginning to set things up carefully can save hours of debugging—too many want to dive in and wire up stuff without a clear idea what they are going to do, just hoping that it will somehow get fixed by the group tutor or me debugging their work. I refuse to do debugging for a group without a schematic, and in some cases I gave students some properly colored wire and asked them to rewire the circuit so that it could be debugged.

One student was unable to get a pulse reading from his finger on anyone’s circuit (including mine).  I don’t know what the difficulty was—he attributed it to too much caffeine today, so that he could not hold his finger steady in the block.  I suspect that he might have been pressing down too hard and squeezing the blood out of his finger.  One student even managed to get a pulse  reading through fingernail polish (she was wearing a red polish, which apparently was transparent enough to still work).

I had set up my transimpedance amplifier (which has adjustable gain from 66MΩ on up) with an oscilloscope for students to see what a good signal looked like.  There is a lot of 60Hz noise capacitively coupled in, but I was getting a 0.5V pulse signal with only about 200mV of interference.  I probably want to lower the corner frequency for the low-pass filter, to reduce the 60Hz signal further (one group that had miscomputed their corner frequency had very low interference, but their signal was also attenuated too much—I think that a reasonable compromise position can be found).  Even groups with very high 60Hz interference were able to get clean signals by sampling at a multiple of 1/60th of a second (20Hz or 30Hz, for example)—the aliasing eliminates the 60Hz signal, turning it into a DC offset.  The only ones who ran into trouble with 60Hz interference were ones who had the gain set so high that the 60Hz interference caused clipping, obscuring the pulse waveform added to the interference.

I expected this lab to be a little easier for students than it turned out to be, but I think that several students who had been having trouble with some of the concepts (like the virtual ground) were now getting the idea.  I hope so, as most of what they did in this lab will be directly applicable to the EKG lab in the last week of classes.

2015 May 19

Pulse monitor lecture and lab

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

I didn’t get a blog post up for last Friday’s lecture, because I spent the weekend alternately socializing with my in-laws and grading. Monday night was spent grading and working on the next chapter of the book, and most of today (Tuesday) was spent working on the book.

Last Friday was the one day I talked about pulse monitors, photodiodes, phototransistors, and transimpedance amplifiers.  It was a rather packed lecture, but seemed to go all right.

Monday’s lecture started out OK, answering questions about the homework exercises the students were about to turn in, but then fell apart when I tried to cover real power and pulse-width modulation.  Both presentations seemed too vague to me—having neither mathematical rigor nor clear exposition.  The written presentation I wrote for the book is much better than the lecture, which is a bit unusual for me.  I think I need to start getting more sleep, if my presentations have deteriorated to that level.

The prelabs I graded Monday night indicated to me that many students can’t follow a long chain of computations for computing signal levels, even when the chain is broken down into single steps for them.  The problem was estimating how much photocurrent we would get from an LED shining through a finger, starting from the power into the LED, figuring out how much light that would produce, how much would be absorbed by hemoglobin, how much scattered, how much collected by the phototransistor, and how much photocurrent the transistor would produce.  Some students managed to get about 80% of the steps, but a lot got only parts of one step right.

Today’s lab (the first half of the optical pulse monitor lab) took too long, because the students wasted a lot of lab time trying to redo the prelab computations that they had messed up over the weekend, rather than moving on to measuring the photocurrent as I had asked in the lab.  Only a few of the groups got as far as I thought they should have in the first half of the lab: getting their transimpedance amplifiers working and showing a pulse-rate fluctuation. They’ll be set up for adding a high-pass filter and second gain stage on Thursday, and recording pulse waveforms to pass through the digital filter script I provided them.

I spent a long time in the lab today, since I promised the students a 5–7 p.m. lab time for make-up or redone labs. I ended up in the lab from before 10 a.m. to after 7:30 p.m., and I expect to do that every Tuesday and Thursday for the rest of the quarter (2 and a half more weeks). I spent the time when I wasn’t helping students working on revising the class-D power amp chapter of the book, so that I could release the new draft of the book to the class—they’ll have to start work on the design of the class-D amplifier before they have quite finished the pulse monitor, or they won’t have enough time—there is no class next Monday for answering questions.

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 12

Lecture for pulse monitor

Filed under: Circuits course — gasstationwithoutpumps @ 19:27
Tags: , , ,

Today’s class started with handing back the audio-amp lab reports, which spanned a much wider range than usual. Everyone had an ok design, but some students explained it well, while others had numbers that appeared by magic or with completely incoherent explanations. Although I could have predicted a couple of the worst reports, the group that did the best was not the one I expected.  I’m quite pleased that they did such a good job, as I was not sure I was getting through to them—it made up for my disappointment at the relatively poor performance of a couple of the groups I had expected better of.

I pointed out to the students that there was no “correct” answer to most design problems, and that being able to explain how they came up with the design was at least as important as the design they came up with.  If some spec changed, an engineer would want to be able to modify the design without having to do the whole thing over from scratch.  (I didn’t say it, but I think that some of the groups that couldn’t explain their work would not be able to redo their designs from scratch, even if none of the specs changed.)

The multistep problems in last week’s lab and this week’s are difficult just because they have so many chained steps, though each individual step is pretty easy. I suspect that many of the students have never worked multistep problems before and are shutting down the moment they don’t have a predefined protocol to follow.

I asked how many people had done the prelab for tomorrow’s lab (as I had requested they do over the weekend). As expected, no one. I asked how many had attempted it—only about a third of the class. I asked where they were getting stuck—on the first step, figuring out how much light came out of the LED. Rather than going on and doing the rest of the chain of computations symbolically, they just gave up, so that they had nothing done, rather than an almost complete problem solved, with just one hole in it to be filled.

My lecture for most of the remaining hour consisted of explaining to them almost exactly the same thing that was in their lab handout. Luckily, I was expecting this inability or unwillingness of students to learn from written material, because I saw it last year also (though not on this lab, since this lab is all new).  I would really love it if students would read things and at least try to do the assigned homework before class and come in with specific questions, rather than expecting to get everything in lectures for the first time. But I’ve resigned myself to students having less than zero initiative about learning new things.

Today had been scheduled for photodiodes and phototransistors, but we only got to those topics for the last 15 minutes of class, as I spent the first 55 minutes patiently going over what they needed to do to convert candelas to lumens to watts for the LEDs, to estimate how much light is absorbed or scattered in a finger, to estimate how much of the remaining light makes it to the sensor, and to compute how much current one would then see in the sensor. I didn’t do the computations for them (which seems to be what they expect—too much scaffolding in their other classes?), but I’m hoping that they can now read the homework assignment.

Despite my warnings that they would need to have the prelab done before lab starts tomorrow, or they are likely to run out of time for this lab, I’m betting that only one group will have gotten as far as a schematic, and that most of the class will again waste most of the lab time doing their prelab homework.  I’ve not figured out a way to break them of this, but I’ll need to get better at getting students to work outside lab, or I won’t be able to handle  two lab sections next year.

I am going to suggest that they write up half their lab report before Wednesday’s class, so that they can uncover the places where they can’t reconstruct their thinking before the final report is due on Friday, while there is still time to ask questions and modify the design.

On Wednesday, I plan to talk about the second stage of the amplifier for the pulse monitor, adding gain for 0.2Hz–30Hz but blocking DC.  But figuring out how much gain they need requires them to have completed the first stage of the amplifier on Tuesday, and looking at the output with an AC-coupled oscilloscope, to see and measure the small fluctuation caused by opacity changes in the finger. I’m not sure that all groups will get that far, having not started on the design over the weekend as I told them to.

The class ended after a very brief and informal presentation of how a diode works, what causes photocurrent, and why the phototransistor has 100–1000× the current of a photodiode.

Sorry if I seem to be too much of a curmudgeon today—I’m very tired and even entirely expected behavior from the students was depressing.  This isn’t even a “students-nowadays” complaint, as I remember having the same sort of disappointment about students being unwilling or unable to read assignments when I started as a professor 32 years ago. Perhaps there is some Shangri-La somewhere, where most students do the assigned reading and struggle to understand it before class rather than waiting to be spoonfed, but I’ve never taught there.


Next Page »

The Rubric Theme. Create a free website or blog at


Get every new post delivered to your Inbox.

Join 315 other followers

%d bloggers like this: