# Gas station without pumps

## 2016 June 25

### Pulse monitor with log-transimpedance amplifier

Filed under: Uncategorized — gasstationwithoutpumps @ 02:04
Tags: , , , ,

I’ve been planning since the Santa Cruz Mini Maker Faire to wire up an optical pulse monitor with a log-transimpedance amplifier as the first stage, so that I could use the pulse monitor in full sun or in a dimly lit room, with a dim green LED or with a bright infrared LED. The idea is to make the output of the first stage proportional to the log of the photocurrent, rather than to the photocurrent, then use a band-pass filter to get rid of the DC component and any 60Hz fluctuation, leaving only the fluctuation due to the pulse.

This pulse signal should be independent of the overall light level but on the absorbance of the finger, because
$\log(I) = c + \log(\mbox{transmitted}) = c+ \log(\mbox{illumination}) + \log(\mbox{transmitted}/\mbox{illumination}$, for some constant $c$. If the illumination is constant or has only high-frequency components, then the bandpass filter will eliminate both $c$ and $\log(\mbox{illumination})$, leaving only the absorbance $\log(\mbox{transmitted}/\mbox{illumination})$.

I deliberately did not start working on it until I had finished my grading for the quarter, so only got it built last week, just before going to Montreal for a family reunion of my wife’s family. So I’m only now getting around to blogging about it.

To make the log-transimpedance amplifier, I need a component where the voltage is proportional to the log of the current.  For this I used a diode-connected PNP transistor:

The base-to-emitter diode has a current that is exponential in the voltage, and the collector-to-emitter current is proportional to the base-to-emitter current, at least until the transistor approaches saturation (which starts around 10mA).

The A1015 PNP transistor has a voltage proportional to the log of current, with about 60mV/decade. I did not use a unity-gain buffer when measuring the voltage and current, connecting the Teensy ADC channels A10 and A11 directly to the emitter and base+collector of the transistor. Measurements at less than 5µA were difficult, because the high impedance of the sense resistor made the ADC measurements inaccurate.

I tried a pulse monitor using the A1015 PNP transistor as the log-impedance element, and it worked ok, but I can do better, I think, using an IR LED as the log-impedance element:

The WP710A10F3C IR LED has a low forward voltage, and can be used from 100nA to 30mA, given that we don’t need high accuracy on the log function. We get about 105mV/decade, so it is more sensitive than the A1015 transistor. Note: I did use a unity-gain butter for these measurements, which allowed me to get down to about 50nA—still much higher than the photocurrents I observed in very low light.

The IR LED has a wide range over which the voltage is the logarithm of the current, or $\frac{dV}{dI} \approx 241mV/I$. For 10nA, the equivalent gain is about 24MΩ, and for 1µA, the gain is about 240kΩ. For 10pA (about the smallest current I’ve observed for operating the pulse monitor in very dim light), the equivalent gain is 24GΩ.

This amplifier uses only 3 op amps: a log-transimpedance stage with an IR LED as the impedance and two bandpass inverting amplifiers.

The 330pF capacitor in parallel with the log-impedance is very important—without it I get very short glitches which the next two stages lengthen into long glitches in the passband of the filters.  Making the capacitor larger reduces the glitches, but makes the corner frequency of the effective low-pass filter too low when light levels are very low, and the signal is attenuated.  Any smaller, and the glitches don’t get adequately removed.

I have tested the pulse monitor over a wide range of light levels, with a DC output of the first stage from 234mV to 1.033V, corresponding to photocurrents of 11pA to 463µA, a range of 42 million (7.6 decades). At very low light levels, the signal tends to be buried in 60Hz interference, but if I ground myself, it is still usable.

In very low light, the capacitive coupling of 60Hz noise buries the signal, but the bandpass filters help recover it.

At high light levels, it is easy to get clean signals, as the 60Hz interference is swamped out by the large photocurrent.

Note that the voltage swing is almost independent of the overall light level, as it depends only on the percentage fluctuation in opacity of the finger, which depends mainly on how much pressure is applied. If you get the pressure on the finger close to the mean arterial pressure (so that the finger throbs), you can get quite a large change in opacity—I’ve computed changes of 17% in opacity.

## 2016 May 11

### Don’t put pulse monitor first

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

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 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).

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.

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.

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.

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.

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.

Next Page »

Blog at WordPress.com.