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

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.

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.

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.

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: , , ,

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.

2014 February 9

I-vs-V plots for base-emitter diodes

Filed under: Circuits course,Data acquisition — gasstationwithoutpumps @ 22:44
Tags: , , ,

Earlier today I posted a voltage-versus-current curve for a 1N5817 Schottky diode, to confirm the theoretical formula V = V_{T} \ln \left ( 1+ \frac{I_{C}}{I_{S}}\right), where IS is the saturation current of the diode:

1N5817-I-V

Fitting over a wide range of currents is more robust than fitting over the narrower range that I can get with just one value for R2.
There is quantization error still on the voltages, but the overlapping current ranges give good data for most of the range. VT is now 26.1mV and IS is 0.91µA.

I also said that I should characterize the base-emitter junction of a PNP and an NPN transistor this way also, for setting the appropriate resistances for the log amplifier in the loudness circuit.  I did that this evening for the S9012 PNP and S9013 NPN transistors:

Base-emitter diode for the S9012 PNP transistor (collector and base connected together).

Base-emitter diode for the S9012 PNP transistor (collector and base connected together). VT is 25.3mV and ISO is 13.4fA.

Characteristics for the base-emitter diode of the S9013 NPN transistor (collector and base connected together).

Characteristics for the base-emitter diode of the S9013 NPN transistor (collector and base connected together). VT is 25.5mV and ISO is 8.85fA.

For both transistors, the region where the logarithmic fit is good is from about 0.5µA to about 50mA (maybe only 35mA for the NPN transistor). That gives about a 100dB working range for a log amplifier, if the largest current corresponds to 50mA. Of course, the op amps that are driving the input of the log amplifier don’t have that much drive capability, and we are probably limited to about 20mA—only a 90dB dynamic range on the log amplifier.

2014 February 8

More on loudness circuits

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

My son got interested in a loudness circuit again, and we tried coming up with one that that would take few components. We decided on having a 3-stage system: a preamp to get voltage up, a peak (or trough) detector with low-pass filter to extract the envelope, and a log amplifier to convert to a dB scale. We were planning to use a Schottky diode, rather than a precision rectifier for the peak detector.

Block diagram for loudness sensor using peak detector.

Block diagram for loudness sensor using peak detector.

The gain of the first stage was set by looking at the sensitivity of the SPU0410HR5H‐PB silicon microphone and the maximum loudness that the system should be able to record. The mic has -42±3dB sensitivity referenced to 1V/Pa.  That means it has 7.94mV/Pa.  The loudest sound for the mic should be the sound level at a rock concert, approximately 120dB referenced to 20µPa—that is 20Pa.  So the microphone should have an AC output of about 160mV.  Because he is planning to work with a 3.3V power supply, a gain of 10 should just keep the signal within the rails.

    Here is the loudness circuit, before the component values have been determined.

Here is the loudness circuit, before the component values have been determined.

To get a gain of 10 (actually –10), we need R2=10*R1.  The R1 C1 time constant determines the cutoff for the high-pass DC-blocking filter.  A reasonable cutoff frequency is 10–20Hz, giving an RC time constant of  8–16msec.  Picking a cheap value for C1 (0.1µF),  gives us R1≈100kΩ and R2≈1MΩ.

The peak finder is just a Schottky diode charging C2 through R3, with R4 slowly discharging it.  Because the signal does not spend a long time at the peak, we want R3≪R4, so that we can catch the peaks. We also want a moderately rapid attack (to catch percussive sounds quickly) and a fairly slow decay, so that low-pitched sounds do not appear as fluctuating loudness.  We also want R4 to be sized so that the log amplifier has a good dynamic range.  We probably want to keep the currents through Q1 to between 0.2µA and 2mA, which suggests R4≈1kΩ, and R3≈47Ω.  To make the R4*C2 time constant around 0.1 sec, C2 would have to be 100µF, which costs about 50¢, so it may be cheaper to put in another op amp to separate the peak detector from the log amplifier, using a smaller C and larger R for the peak detector, followed by an op amp, then the low resistance for the log amplifier.

Modified loudness circuit with unity-gain buffer to separate peak detector from log amplifier.

Modified loudness circuit with unity-gain buffer to separate peak detector from log amplifier.

Now we can make C2 be a reasonable size (say 0.1µF) and scale R3 and R4 to match (say 100kΩ for R4, to get a discharge time constant 0f 10msec, and 1kΩ for R3, to get a charge time constant of 100µsec).  This also limits the current drawn from U1 to 1.65mA (well less than the 15mA short-circuit current).

R5 can now be made fairly small (say 470Ω) to give us a large dynamic range on the amplifier.  If Q1 is an NPN transistor with characteristics like the S9013 transistor that I tested when I was playing with log amplifiers, then the output should range from Vref-0.65v up to almost Vref, which at 3mV/dB gives a range of over 200dB (which we certainly won’t get—the log amp may be good to 80 or 90dB.  If the ADC has 10-bit resolution on a full-scale range of Vref, then the steps are about 0.55dB (a 12-bit ADC would have steps of about 0.14dB).

Note that the log amplifier provides V_{BE} = V_{T} \ln \left ( 1+ \frac{I_{C}}{I_{SO}}\right), where IC is the collector current, ISO is the saturation current of the base-emitter diode, and VT is the thermal voltage V_{T} = \frac{k_{B} T}{q} \approx 26 mV at 300º K.  I should be able to estimate VT and ISO from the log amplifier measurements I made earlier. (I get VT =25.6mV and ISO=7.9E-15A for S9013.)

Along the way, I realized that I had never plotted a voltage-versus-current curve for the Schottky diodes, to confirm the theoretical formula V = V_{T} \ln \left ( 1+ \frac{I_{C}}{I_{S}}\right), where IS is the saturation current of the diode.

I did those measurements this morning, using a 1N5817 Schottky diode, a series resistor, a series potentiometer, and an Arduino (Leonardo) board.  I measured the voltage across the resistor (to get current) and across the diode.

The voltage does fit nicely to the log of current, with IS=1.32µA and VT=27.1 mV. Given the quantization noise in the voltage measurement, these seem like a pretty good fit to theory.

The voltage does fit nicely to the log of current, with IS=1.32µA and VT=27.1 mV. Given the quantization noise in the voltage measurement, these seem like a pretty good fit to theory. (click to embiggen)

When my son gets the Data Logger working with the KL25Z boards, I’ll probably want to redo these measurements with higher precision. Note that both VT and IS depend on temperature, and I did not measure the temperature (probably around 18ºC). IS normally doubles for every 10ºC temperature rise, so any measuring device relying on these characteristics would need to have temperature compensation or calibration to correct for temperature.  In any event the IS values for the Schottky diodes are much larger than for the base-emitter junctions, so voltage drop across the diode is much smaller for a given current—which is why we use Schottky diodes!

2013 July 16

Precision rectifier

Filed under: Circuits course,Data acquisition — gasstationwithoutpumps @ 11:36
Tags: , , , , , ,

The log amplifier that I’ve spent the last several days understanding (posts a, b, c) is not the only non-linear circuit needed for a loudness detector.  We also need to convert the audio input signal into a slowly changing amplitude signal that we can take the logarithm of.  As I discussed in the first post on log amps, I had rejected true-RMS converter chips as too expensive for the application (though the original application has gone away), and decided to try a rectifier and low-pass filter.

[Incidentally, my son is now looking at a different processor chip, the KL25 from Freescale (an ARM Cortex chip), which has a 16-bit ADC that is much faster than the ATMega’s, so the entire loudness-detector could be done in software, except for a one-op-amp preamplifier.  With a  16-bit ADC, we can get almost 90dB of range without needing a log amplifier. We’re planning to order a development board that is compatible with Arduino shields (but has lots more I/O pins available) and that has an accelerometer on the board.  Amazingly, the development board is only $13, about half the price of an Arduino.]

A single diode does not work for our rectifier needs in the loudness circuit, because diodes don’t turn on until the voltage across them is at least a “diode drop” (about 0.7v for silicon diodes and 0.45v for Schottky diodes).  However, the simple circuit for the log amplifier is also the circuit for a precision rectifier:

This circuit is both a log amplifier and a precision rectifier.  If Vb is set to a constant voltage, then Vout1-Vb varies as log(Vb-a).  Vout2 is max(Va,Vb).

This circuit is both a log amplifier and a precision rectifier. If Vb is set to a constant voltage, then Vout1 varies as log(Vb–Va). Vout2 is max(Va,Vb). 
The diode can be connected in the opposite direction, to get Vout2=min(Va,Vb) and Vout1 varying with log(Va–Vb).

The log-amplifier circuit I used in the previous posts had a transistor in place of the diode, so that the crucial voltage that was being exponentiated was referenced to the bias voltage, rather than the input. We also needed a compensation capacitor in parallel with the transistor to prevent oscillation in the negative feedback loop.

For the precision rectifier, we swap the inputs, so that Va is the signal input and Vb is a constant threshold voltage for the rectifier. We do not need (or want) the compensation capacitor, as that would cause the circuit to act as a unity gain amplifier at high frequency, rather than as a rectifier.

Because I did not happen to have any diodes, but had plenty of transistors, I experimented with the rectifier circuit using diode-connected bipolar transistors (collector and base connected together). Because the output of the rectifier is not directly driven by an op amp, I used unity-gain buffers to isolate the test circuitry (Arduino analog inputs or BitScope oscilloscope) from the amplifier:

Test circuit for low-speed testing of precision rectifier circuit.

Test circuit for low-speed testing of precision rectifier circuit. Here the NPN transistor is used as a diode, in the opposite direction as in the first schematic, so Vout should be min(Vin, Vbias)

My initial test setup did not have the unity-gain buffer for Vin, but I found that one of my Arduino analog input pins was quite low impedance and was discharging my capacitor. Switching to a different pin helped, but I eventually decided to avoid that kluge and use a unity-gain buffer instead.

I tried several different values for R2. The most predictable effect of changing the value is a change in the range over which the rectifier operates. Clipping occurs because the output of the op amp is limited to be between the rails of the power supply. The feedback transistor is conducting when the rectifier is following the input, so the op amp output has to be substantially lower than Vout.  The function implemented is max(Vclip, min(Va,Vbias)).  Vclip should go down as R2 is increased (at about 60mV for each factor of 10 in resistance—the same shift as in the log amplifier).

Here are a couple of plots of Vout vs. Vin for the S9018 transistor:

With a 1kΩ resistor, the clipping voltage is fairly high, and we have a somewhat limited range for the rectifier.

(click to embiggen) With a 1kΩ resistor, the clipping voltage is fairly high, and we have a somewhat limited range for the rectifier.  The offset voltage for the rectifier between the output and the input is much less than the resolution of the Arduino ADC (about 5mV).

With a 10kΩ resistor, the clipping voltage is lower, giving us more range for the rectifier.

(click to embiggen) With a 10kΩ resistor, the clipping voltage is lower, giving us more range for the rectifier.

Using a PNP transistor instead of an NPN has the effect of reversing the diode and producing Vout=min(Vclip, max(Vin, Vbias)):

With an S9012 PNP transistor and a 10kΩ resistor, we get clipping at the high end.

(click to embiggen) With an S9012 PNP transistor and a 1kΩ resistor, we get clipping at the high end.

With a 10kΩ resistor we get a larger range.

(click to embiggen) With a 10kΩ resistor we get a larger range.

So why not go for a very large resistor and maximize the range? From a DC perspective this looks like a win (though it is hard to see in the limit how Vbias would affect the result if the resistance went to infinity).  Of course, the problem is with high-frequency response.  Consider the difference between the S9018 NPN transistor with a 1kΩ resistor and a 330kΩ resistor:

S9018-330kohm-1kHz

(click to embiggen) With an S9018 NPN transistor and a 330kΩ resistor at 1kHz. Note the overshoot when the rectifier shuts off.

Fairly clean signal with a S9018 NPN transistor and a 10kΩ resistor at 1kHz.

(click to embiggen) Fairly clean signal with a S9018 NPN transistor and a 10kΩ resistor at 1kHz.

With a 1kΩ resistor, there is very little overshoot as the rectifier turns off.

(click to embiggen) With a 1kΩ resistor, there is very little overshoot as the rectifier turns off, but we can see a bit of a problem when the rectifier turns back on.

There is a problem with the rectifier turning on slowly, because Vout has to move all the way from the top rail down to the bias voltage, and the op amp has a slew-rate limitation. This phenomenon can be seen more clearly at a higher frequency:

The S9018 NPN transistor with a 10kΩ resistor and a 15kHz input signal.  The overshoot as the rectifier turns off is about 50mV, and the turn-on delay is about 8µsec.  The turn-on delay does not vary much with the input resistance, unlike the turn-off overshoot.

(click to embiggen) The S9018 NPN transistor with a 10kΩ resistor and a 15kHz input signal. The overshoot as the rectifier turns off is about 50mV, and the turn-on delay is about 8µsec. The turn-on delay does not vary much with the input resistance, unlike the turn-off overshoot.

I believe that the overshoot as the rectifier turns off is due to capacitance, as adding a small feedback capacitor in parallel with the diode increases the overshoot substantially:

With a 33pF capacitor in parallel with the diode (an S9018 NPN transistor), a 10kΩ resistor,  and a 15kHz input, the overshoot goes up to about 290mV from 50mV without the capacitor.

(click to embiggen) With a 33pF capacitor in parallel with the diode (an S9018 NPN transistor), a 10kΩ resistor, and a 15kHz input, the overshoot goes up to about 290mV from 50mV without the capacitor. The turn-on delay is masked somewhat by the high-frequency feedback.

Note: the S9018 has the best high-frequency response (if you consider 15kHZ high frequency) of any of the transistors I looked, probably because it has the lowest capacitance. For example, with a 10kΩ resistor the S9013 NPN has 120mV of overshoot at 15kHz, instead of only 50mV, and the S9012 PNP has -180mV. With a 1kΩ resistor, I can’t measure the overshoot on any of these three transistors. So the limited range with a 1kΩ resistor is compensated for by the much cleaner turn-off behavior.  I should be able to get better range by using a fast-response Schottky diode instead of diode-connected transistor.

Of course, the turn-on behavior is a bigger problem and one that can’t be fixed by playing with the resistor or the diode, because the problem is with the large voltage swing needed from the op amp in order to turn on. There are standard solutions that limit the voltage swing, but I think I’ll leave that for a later blog post.

« Previous PageNext Page »

%d bloggers like this: