Gas station without pumps

2019 May 22

Interaction between bias resistor and active high-pass filter

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

In grading the preamplifier lab, I made a mistake when correcting a number of student papers.  Students who had used a bias resistor rather than a transimpedance amplifier to convert the microphone’s current output to voltage had not taken into consideration the interaction between the bias resistor and the input impedance of the next stage, which was usually an active high-pass filter.  In grading, I overcorrected the student work, changing both the i-to-v gain and the first-stage gain, when the correct action would have been to change either one, leaving the other alone.

Schematic of bias resistor and active high-pass filter. The input is the current I_in.

The passband gain for the circuit is R_b\frac{R_f}{R_b + R_i} = (R_b || R_i) \frac{R_f}{R_i}. The first version corrects the gain of the filter, while the second version corrects the gain of the current-to-voltage conversion. In my grading, I mistakenly applied the correction twice getting (R_b || R_i) \frac{R_f}{R_b + R_i}.

There are two ways to get to the correct answer: using Thévenin equivalence and from first principles.

If we replace the current input and R_b with a Thévenin equivalent, whose AC voltage is the AC component of I R_b and whose resistance is R_b, then we get a simple active high-pass filter with passband gain \frac{R_f}{R_i + R_b} for a total passband gain of R_b\frac{R_f}{R_b + R_i} and a corner frequency of \frac{1}{2 \pi (R_i+R_b) C_1}.

For those who don’t quite trust themselves to do Thévenin equivalence, we can use first principles to reason about the various currents in the schematic. The negative-feedback loop holds the op amp’s negative input to V_{ref}, and the input node has a voltage, so we get
V_{input} = V_{dd} - I_b R_b = V_{ref}-I_f \frac{j\omega R_i C_1 + 1}{j \omega C_1}
which we can rearrange to get
I_b = \frac{V_{dd} - V_{ref}}{R_b} + I_f \frac{j \omega R_i C_1 + 1}{j\omega R_b C_1}.
Because I = I_b + I_f, we get
I= \frac{V_{dd} - V_{ref}}{R_b} + I_f \frac{j \omega R_i C_1 + 1}{j\omega R_b C_1} + I_f
and can solve for I_f to get
I_f = (I- \frac{V_{dd} - V_{ref}}{R_b}) \frac{j\omega R_b C_1}{1+j\omega(R_b+R_i)C_1}.

Finally, because V_{out}-V_{ref} = I_f R_f, we get
V_{out}-V_{ref} = R_f (I- \frac{V_{dd} - V_{ref}}{R_b}) \frac{j\omega R_b C_1}{1+j\omega(R_b+R_i)C_1}.

Our transimpedance gain (including the DC offsets for input current and output voltage) is
\frac{V_{out}-V_{ref}}{I- \frac{V_{dd} - V_{ref}}{R_b}} = R_f \frac{j\omega R_b C_1}{1+j\omega(R_b+R_i)C_1}.
At DC, this has the appropriate gain of 0, and for high frequencies (in the passband), the gain is approximately \frac{R_f R_b}{R_b + R_i}, as claimed earlier. The corner frequency, where the real and imaginary parts of the denominator match is at \omega = \frac{1}{(R_b+R_i)C_1}.

2014 May 14

Mixed topics in lecture

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

Today’s lecture was a mish-mash of different topics.

Pre-lab assignments not getting done.
I asked the students for advice on how to get them (or next year’s class) to do the pre-lab assignments before coming to lab, rather than wasting lab hours doing homework that doesn’t need the fancy lab equipment. I told them some ideas I had had, and how everything I’d tried so far had not worked. The only idea they thought might work was requiring that pre-lab assignments be turned in the day before the lab, so that they would prioritize the work. I’ll have to look to see if that is feasible for any of the labs left this year.
Answer getting
I talked again about the “answer-getting” mindset, and how it wasn’t an appropriate one for engineers. The problems they’ll face in industry are open-ended ones, where there isn’t a single unique answer—no one is going to be giving them multiple-choice tests. They’ll have to come up with designs, justify their design choices, and document them well enough that someone else can maintain things after they get hit by a beer truck.
Subdividing problems
I told them that I was deliberately giving them long multi-step design problems so that they could get used to subdividing problems and tackling them a little a time. I had noticed that some of them were stopping as soon as they got to a subproblem they didn’t know how to handle, rather than leaving a symbolic value for the result and solving the other subproblems. It is a lot easier to fill in one hole in a long computation than to have to do the whole thing from scratch each time.
Engineering by design or by tinkering
There are two different styles of engineering: one which uses careful modeling and calculation to try to get a design that works correctly first time, and one that consists of making quick reasonable guesses, trying them out, and adjusting the design to correct problems. I confessed that as a hobbyist, I generally prefer design by tinkering, but most modern electronics does not lend itself to tinkering, because the parts are too small for hand soldering, so one needs to go through a more expensive PC board design and pick-and-place assembly to build a prototype. I did, accidentally, tell them a lie—I said that the MCP6004 quad op-amp chip they are using is available in a 2mm by 3mm package, but that package is for the 8-pin MCP6002 dual op-amp chip, and the smallest for the MCP6004 is 4mm by 6.4mm (substantially larger than 2 MCP6002 chips!). This week’s lab was intended to be a compromise between the two design styles, with Tuesday being engineering by design for the first stage and today and Thursday being tinkering to correct the problems of the first stage, but only one group got to the point on Tuesday of having a partly functional design that could be tweaked.
Results from stage 1
I had a student whose group had gotten stage 1 working in lab yesterday talk about what he and his partner had seen on the scope. He mentioned the voltage going very high when there was no finger blocking the light (and we talked a bit about saturation, pointing out the similarity to the loudspeaker lab, where they observed clipping from either voltage or current saturation—I even managed to tie in the chemical concept of saturated solutions). He talked about how the voltage dropped to Vref+100mV with a finger blocking the light. He mentioned the large 60Hz noise on top of this DC signal, and the tiny voltage that may have been from the pulse. I gave the students some ballpark figures for the sorts of currents that they might see from their phototransistor (based on both what the first group saw and what I had seen at home): about 90–150nA DC and about 2–10nA for the pulse.
Gain of first stage
We talked about ways to increase the gain of the first stage and the desirability of making it as big as possible without saturating at the top rail. One subject that came up (in response to a student question) was increasing the headroom by dropping the reference voltage for the transimpedance amplifier. That brought up the other constraint on that voltage—biasing the phototransistor. The spec sheet gave a VCE saturation voltage of 0.8v, and I suggested that they stay above that voltage (though I suspect that the design might work down to 0.7v since their currents are so small—something I should probably experiment with).
Need for filtering
I asked the students how to get rid of the DC bias, and by this point they all know that a high-pass filter was needed. We then discussed what sort of frequency range a heart rate might be (several were pretty clueless about this), but we eventually got to 30bm–240pbm, or 0.5Hz to 4Hz. I suggested that they might want a wider bandwidth, particularly on high end, to see the shape of the pulse as well. I talked about the need for a low-pass filter to reduce the 60Hz signal.
Synchronous sampling
With a little too much prompting, I managed to get them to come up with the idea of sampling at 60Hz, so that the 60Hz noise would be sampled at the same point on the waveform on each cycle and so be less of a problem. I also showed them that 30Hz or 20Hz would work just as well.
Active filters
Finally we got to what I had intended as today’s topic: modifying the transimpedance amplifier to include a low-pass filter. I showed them the transimpedance amplifier circuit again, and reminded them that the feedback did not need to be a simple resistor but could be a complex impedance. We drew the Bode plot for the desired gain of the amplifier using a 1/f (6dB/octave) rolloff, and I asked them how to design a complex impedance with that magnitude. They fairly quickly came up with the idea of using a resistor and capacitor, but at first they wanted to put them in series. We computed what the plot for that would be, and they decided to try parallel instead. Success! But almost out of time for the day, without talking about multi-stage filters or putting complex impedance in both arms of a voltage divider in the feedback loop for a bandpass filter.
Gnuplot boilerplate
I did give them a quick look at the boilerplate gnuplot script I wrote for them, that allows them to create models and test them out quickly with gnuplot, but I did not have time to work through an extended example of modifying the script for more complicated circuits, and I doubt that any of them will take the trouble to try it on their own.

I did not get a chance to tell them about the pressure on the finger being optimally between the systolic and diastolic blood pressure, but there should be time in lab for that tomorrow. By grasping the edge of a table lightly and gradually increasing the grip force, one can slowly increase the pressure until the finger throbs with the pulse—that is the amount of pressure you want to put on the fingertip.

I expect that I’ll be in the lab quite late with the students tomorrow, getting them to build their stage 1, tweak the feedback resistor (and capacitor) until the circuit has reasonable gain, then design and build their second stage. I’m betting that no one will have thought about what they need for the second stage, and most still won’t have a schematic even for the first stage.

On Friday, I’ll introduce instrumentation amps and strain gauges, for next week’s instrumentation amp lab. Monday will have to be class D amplifier design concepts, because Wed will be the quiz, and there is no Monday the week after next (Memorial Day), so we’ll have to develop class-D block diagram on Friday next week.

2013 July 10

Some failed designs

For the past couple of days I’ve been exploring variations on the Blinky EKG project, looking at alternative approaches.

For example, I looked at the possibility of eliminating the most expensive part (the instrumentation amp), and decided that building my own instrumentation amp out of op amps and discrete resistors was unlikely to be reliable.  I discovered (after doing calculations for 2-op-amp and 3-op-amp designs) that 1% tolerance on the resistors would produce poor common-mode rejection. In Common-mode noise in EKG, I reported measurements of the common-mode noise with a fairly short twisted-pair connection to the EKG electrodes (close to a best-case scenario).  I concluded that the common-mode noise was way too large for using unmatched resistors to be a reasonable design, and using an integrated instrumentation amp is still a good choice.

Yesterday,  I tried turning the question around? Could I eliminate the op-amp chip?  Currently, I’m using the op amp for two things: to provide a unity-gain buffer to make the reference voltage source between the power rails, and to do second-stage amplification after a high-pass filter removes the DC offset. To eliminate the op-amp chip, I need to replace both these functions.

Replacing the unity-gain buffer seems fairly easy—I could use a low-drop-out linear regulator to generate the reference voltage instead of a voltage divider and unity-gain buffer, which would be somewhat smaller and cheaper (11¢ rather than 25¢ in 100s).  I didn’t have an LDO linear regulator at home, so I tried using a TL431ILP voltage reference instead.  Unfortunately, it provides very little current, and was unable to maintain the desired voltage when hooked up to the reference voltage input of the instrumentation amp.  I believe that a part like the LM317L would work fine, though, and I may want to test that at some point.

Removing the second-stage amplifier is more problematic.  I can set the gain of the instrumentation amp up to 2000 or 2500 easily, but any DC component in the input differential signal results in saturating the amplifier (with a 6v output range, and a 1mV AC signal, we’d need the DC bias to be less than 1mV also to avoid hitting the power rails).  I tried putting high-pass filters in front of the instrumentation amp, but with the long time constants needed to avoid filtering out the EKG signal, the filters never settled to within 1mV of each other, and the instrumentation amplifier always saturated.

So I need to keep the first-stage gain small enough to avoid saturation, which means I need a second-stage amplifier.  I could use a single op amp for the second stage and a low-drop-out regulator for the reference voltage, which would produce a cleaner output signal (since my voltage-divider-plus-unity-gain-buffer reference introduces noise from the power lines).  The MCP6001 single op amp is only 18¢ in 100s (rather than 25¢ for the MCP6002 dual op-amp), but the MCP6001 is only available as a surface-mount component, which I think is inappropriate for a first soldering project.  The MCP6001 + LM317L would cost about 4¢ more than the MCP6002.

I considered redesigning the Blinky EKG to use the LM317L voltage regulator and the MCP6002, even though half the MCP6002 would be unused, but the LM317L needs a 1.5mA load to maintain regulation, and that seems like a lot for a battery operated device—more than the op amp or the instrumentation amp use (though less than the LED when it is lit).  Even using a TL431ILPR voltage reference (10¢ in 100s) and the unity-gain buffer would only need 1mA, and would save one resistor.  There are lower-current voltage references, like the LM385, but they cost a lot more (42¢ in 100s).

The non-rechargeable CR2032 batteries I’ve been using for the Blinky EKG have about a 225 mAh capacity, and cost about 19¢ in 100s (but the design needs 2, so 39¢).  I could probably get about a 100-hour life with the present Blinky EKG design—I need to measure the current and the duty cycle of the LED to get a better estimate.

The Blinky EKG weighs about 20g (not counting the wires to the electrodes), which is a bit heavy for a pendant or brooch. Most of the weight is in the batteries, but a lighter battery would give up a lot of running time.   The smaller batteries also cost a lot more, probably because Digikey only buys them in quantities around 10,000 rather than in the millions. (From other suppliers CR2032 batteries cost about 60¢ in 100s, not under 20¢).

It has been good to fool around with the Blinky EKG design, as it has gotten me to think a bit about design issues other than the first can-I-get-it-to-work one.  I rarely get my students past that point in their thinking, and I’m not sure how I would do so, as there is always so much time pressure to cover new stuff, that they get very little time to tinker with designs.

 

2013 July 8

Common-mode noise in EKG

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

In 2-op-amp instrumentation amp, I said

I’ll have to make some measurements later this week to see how large the common-mode noise on the EKG signals really is. Of course, it is likely to be highly variable, depending on the electrodes and the wiring to them, but ball-park estimates would be useful.

If the AC common-mode voltage is ±200mV and we have worst-case resistor values, then we would have a ±8mV common-mode output from the instrumentation amp. With the lowest differential amplification (6.6 at Rgain=∞), a 1mV EKG signal would be smaller than the common-mode noise. Such a large common-mode voltage would easily justify the expense of the instrumentation amp chip.  (Note: large DC common-mode voltages don’t matter, as the DC-blocking capacitor I used after the instrumentation amp can eliminate them.)

If the AC common-mode voltage is only ±1 mV, then the Blinky EKG could probably work even with very poor common-mode rejection in the instrumentation amp, and building it out of op amps and discrete resistors is feasible.

So today I tried measuring the common-mode signal.  As it turns out, I had built an EKG amplifier on the protoboard that had a split Rgain resistor (two 12kΩ resistors in series).  The node between the 2 resistors should be at (Vp+Vm)/2, the common-mode voltage.  That node was fed to a unity-gain buffer, so I tried measuring the AC common-mode voltage.

I did this with two different tools: my Fluke 8060A multimeter (which measures RMS voltage) and my BitScope Pocket Analyzer, which can measure peak-to-peak voltage.  With the multimeter, I saw about 20–35 mV RMS, and with the BitScope I saw 90–130 mV peak-to-peak (depending on where my arms were relative to the wires to the electrodes).

Trace of common mode noise recorded by the BitScope Pocket Analyzer, at 20mV/division.  Sorry about the black background—the manufacturers are promising a white background as an option in some future release of the software.  Maybe they'll add some labels for the x and y tick marks at the same time!

Trace of common mode noise recorded by the BitScope Pocket Analyzer, at 20mV/division. The fundamental frequency of the noise is 60Hz.
Sorry about the black background—the manufacturers are promising a white background as an option in some future release of the software. Maybe they’ll add some labels for the x and y tick marks at the same time!

If I take the leads off the electrodes and clip them all together, then the common-mode noise drops below the level that the BitScope can measure (its noise floor is about 10mV). The multimeter also has trouble, reporting values from 0.05mV to 1.5mV. If I put a 3.3MΩ resistor between the two signal leads, and connect one of them to the Vref lead, then the multimeter reports about 13–20 mV RMS and the BitScope around 80–90 mV peak-to-peak.

The common-mode problems are definitely coming from the wiring to the electrodes.  With 130mV peak-to-peak common-mode voltage and a common-mode gain of 0.02 or 0.04, we’d have 2.6–5.2 mV of common-mode noise at the output of an instrumentation amp made with discrete resistors and op amps.  If the gain of the amplifier were around 6.6, we’d have a peak-to-peak signal of about 6.6 mV for the EKG signal, and the details of that signal would be buried in common-mode noise.

If we got lucky with the resistor values and they matched better than the specs claim (which is actually fairly likely), then the Blinky EKG would sort-of work with discrete op amps—as long as the 60Hz noise is no worse that what I saw.  Many people are likely to be in electromagnetically noisier locations than my room, so the common-mode noise is likely to be much higher sometimes, and even with lucky matching of the resistors the common-mode signal is likely to swamp the real signal.

Thus I have confirmed that an integrated instrumentation amp is needed for the Blinky EKG, and there is no point trying to design one using discrete resistors and op amps.

3-op-amp instrumentation amp

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

Yesterday in 2-op-amp instrumentation amp, I worked through the analysis of the differential gain and common-mode gain for an instrumentation amp made from two op amps.  There is a classic design of an instrumentation amp made from 3 op amps, and I was wondering how it compared in performance.  Both instrumentation amp designs are available as fairly low cost integrated circuits, but the ones with better common-mode rejection seem to use the 3-op-amp design.  Is there are reason for that?

3-op-amp instrumentation amp.  Schematic drawn with SchemeIt (using PNG export, since I have no special characters).

3-op-amp instrumentation amp. Schematic drawn with SchemeIt (using PNG export rather than a screenshot, since I have no special characters).

The 3-op-amp instrumentation amplifier consists of two separately analyzable parts. The first stage consists of two op amps that provide high-impedance inputs and amplify the differential signal without changing the common-mode signal. The second stage is a differential amplifier that zeros out the common-mode signal and provides unity gain on the differential signal.

We can analyze the first stage by setting the currents through the resistors equal:
(V_{a} - V_{m}) /R_{1} = (V_{p}-V_{b})/R_{2} = (V_{p} - V_{m})/R_{gain}.
If we solve this for Va and Vb, we get
V_{a} = V_{m} - \frac{R_{1}}{R_{gain}} (V_{p} - V_{m})
V_{b} = V_{p} + \frac{R_{2}}{R_{gain}} (V_{p} - V_{m})

If we define V_{comm} = \frac{V_{p} + V_{m}}{2} - V_{ref} and \Delta V= V_{p}-V_{m}, we can rewrite the output of the first stage as
V_{a} = V_{comm} + V_{ref} - (\frac{1}{2} +\frac{R_{1}}{R_{gain}}) \Delta V
V_{b} = V_{comm} + V_{ref} + (\frac{1}{2} +\frac{R_{2}}{R_{gain}}) \Delta V

The differential output of the first stage depends only on the differential input:
V_{b}-V_{a} = (1+ \frac{R_{1}+R_{2}}{R_{gain}}) \Delta V

It may seem strange that I defined the common voltage so that I have an extra Vref floating around in the formula, but that simplifies out in the analysis of the second stage (which would not be the case if I had defined Vcomm as the just the average of Vp and Vm).

The differential amplifier that is the second stage can be described in terms of the two voltage dividers:
\frac{R_{4} V_{out} + R_{3} V_{a}}{R_{3} + R_{4}} = \frac{R_{5} V_{ref} + R_{6}V_{b}}{R_{5}+R_{6}}.
Solving this for Vout gives us
V_{out} =\frac{V_{ref} R_{5} (R_{3}+R_{4}) + V_{b} R_{6} (R_{3}+R_{4}) - V_{a} R_{3} (R_{5}+R_{6})}{R_4 (R_{5}+R_{6})}

If we substitute in the values of Va and Vb (and use Maple plus some hand algebra), we can simplify to

V_{out} - V_{ref} = \frac{1}{R_4 (R_{5}+R_{6})}\left((R_{4} R_{6} - R_{3}R_{5}) V_{comm} + \left(\frac{1}{2}(R_{3}R_{5} + R_{4}R_{6}) + R_{3}R_{6} + \frac{1}{R_{gain}}(R_{1}R_{3}(R_{5}+R_{6}) + R_{2}R_{6}(R_{3}+R_{4}))\right) \Delta V\right).

At R3=R4 and R5=R6, we can simplify to

V_{out} - V_{ref} = \frac{1}{2 R_{3}R_{5}} \left(0 V_{comm} + \left(2 R_{3}R_{5} + \frac{2 R_{3} R_{5} (R_{1}+R_{2})}{R_{gain}}\right)\Delta V\right),

which is V_{out} - V_{ref} = \left(1+ \frac{R_{1}+R_{2}}{R_{gain}}\right)\Delta V.  (Note: this result does not require that R1=R2 nor that R4=R5, though instrumentation amps are usually designed with those additional constraints, perhaps to maximize the range of acceptable input values, which this ideal-op-amp analysis ignores.)

The worst-case common-mode gain with 1% errors in the resistors would be with R4 and R6 high, and R3 and R5 low, giving a gain of 0.02 (or vice versa, for a common-mode gain of –0.02).  Comparing this to the 2-op-amp design’s common-mode gain of 0.04, we see that we gain a factor of 2 (6dB) in common-mode rejection by using an extra op amp.

Next Page »

%d bloggers like this: