Gas station without pumps

2016 May 11

Don’t put pulse monitor first

Filed under: Circuits course — gasstationwithoutpumps @ 21:25
Tags: , , ,

In Revised microphone pre-amp lab too long I said,

I think that the soldering lab should not be the first op-amp lab, but I still like the idea of the students having to solder up their microphone preamps. So I’ll have to do a major reorganization of the book this summer, to move a different lab into the first position.

Currently, I’m thinking that the transimpedance amplifier and pulse monitor lab would be a good choice as the first op-amp lab.

After a rather rough start in the first half of the transimpedance-amplifier lab yesterday, I no longer think that is a good idea. The instrumentation-amp lab went much smoother, so may be a better first choice.  Among other advantages, the instrumentation-amp lab with the pressure sensors has no analog filtering and simpler sensor sensitivity calculations.  One disadvantage of moving away from the mic preamp is that the microphone and loudspeaker characterization in the first half of the class would be separated from the audio amplifier design in the second half—not a problem in a single quarter class, but potentially a bigger problem in a two-quarter sequence.

I’m not sure why the transimpedance amplifier lab went poorly yesterday, and I’m hoping the second half will go smoother tomorrow.  It may be that prelab was not a good match for the lab this time.  Or it may be that over a third of the class didn’t do the prelab this time.  (I’ve threatened the class with a quiz worth as much as a design report if they don’t shape up by next week—I’m carrying around enough redone reports to grade that I really don’t want to do more grading, but I’ll follow through on the threat if so many students continue slacking.)

It turns out that I had several errors in the draft of the book that the students were using for the prelab exercises for the optical pulse monitor.  I’d decided in the summer or fall to switch to a new 700nm LED, but I’d only updated about half the scaffolding for the sensor sensitivity, so there were still a number of things that were only accurate for a 623nm LED.  Also, I’d been using a datasheet for the WP3DP3BT that I’d gotten when I first started using the part, but Kingbright has improved their datasheet a lot between V3 (which I had) and V5 (the current one), so there is now a spectral sensitivity curve on the datasheet, and the spectral sensitivity is quite different from what I was expecting.

I’ve started editing the book to correct the errors, but even after I fixed everything, the estimates for the current from the phototransistor were about 5% of what students were measuring in the lab. The model I had created, which worked fairly well for the previous LEDs, does not seem to work for the longer wavelength of the new LED.

I’m considering simplifying the model by eliminating the modeling of scattering, to see how well that works.  I should check the model with at least 3 different LEDs: the current 700nm one, the shorter wavelength ones I used to use, and an IR emitter.  If I can get the estimates to be within a factor of 10 of measured values for all the LEDs I have, then the model is good enough to include in the book.

I might also want to consider switching phototransistors to one with a wider spectral sensitivity, so that the estimation is not thrown off as much by the filter that blocks so much of visible light.  That would allow me to try a green LED as well.

I’m still thinking about doing a log-transimpedance amplifier as the first stage (not for the class, just for a demo unit) so that the pulse monitor can work in varying light levels up to full sunlight.  The fluctuation in light from the pulse seems to be about 1%, which should be a variation of about 850µV out of the logarithmic amplifier (based on the 9.8mV/dB I measured in Logarithmic amplifier again).  That’s a somewhat smaller signal than I’ve been getting with well-chosen gain resistors, but it may be worth it to get greater independence from the overall light level.

2016 January 26

Phototransistor I-vs-V plots

Filed under: Data acquisition,freshman design seminar — gasstationwithoutpumps @ 15:47
Tags: , ,

I realized this week that I had never plotted I-vs-V curves for phototransistors, and the data sheets don’t usually include them, so I measured some today.

I put an LTR-4206 phototransistor in series with a 1kΩ resistor (so that voltage across the resistor was current in mA), and drove the pair with a slow triangle wave (3.2Vpp with 1.6V offset) from my FG085 function generator, using a 470µF capacitor in parallel with the function generator to smooth out the steps.

I illuminated the phototransistor with a narrow-beam 591nm LED (33-2UYC/H3/S400-A6) from about 0.5″ away.  The LED has a 68Ω current-limiting resistor to 3.3V, resulting in an IR voltage drop of 1.248V, for about 18.35mA.

I recorded the voltage across the 1kΩ resistor and across the resistor plus phototransistor using PteroDAQ on a TeensyLC.

I interposed a Brand 1.5ml cuvette full of water or a piece of white paper to get different light levels:

On the log current plot, one can see that it is important to have sufficient collector-emitter voltage to get into the saturation region of the curve—we need about 0.5V. I'd need to add a dark box for a colorimeter, as the ambient light in a dimly lit room is about 0.5% of the light through the cuvette, and would throw the measurements off.

On the log current plot, one can see that it is important to have sufficient collector-emitter voltage to get into the saturation region of the curve—we need about 0.5V.
I’d need to add a dark box for a colorimeter, as the ambient light in a dimly lit room is about 0.5% of the light through the cuvette, and would throw the measurements off.

On the linear plot of current, one can see that the saturation current is not really constant, but increases with voltage. A simple resistor to convert current to voltage would result in non-linear response, as the collector-emitter voltage would not be constant.

On the linear plot of current, one can see that the saturation current is not really constant, but increases with voltage. A simple resistor to convert current to voltage would result in non-linear response, as the collector-emitter voltage would not be constant.

Making a colorimeter with a phototransistor to get good linearity probably requires a transimpedance amplifier, rather than a simple resistor, but it looks like a 2.5mA current range for the amplifier would be adequate. With a 3.3V supply, the VCE could be set to 0.7V and the gain to 1kΩ, with the output in the range 0.7V–3.2V.

Interposing a piece of paper in the light path is good for aligning the LED and the phototransistor, as the beam pattern becomes quite clear. One of the biggest challenges in making a homemade colorimeter is ensuring that the LED and phototransistor don’t get jostled as the cuvettes are added or removed.

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.

Next Page »

The Rubric Theme. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

Join 342 other followers

%d bloggers like this: