# Gas station without pumps

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

## 2013 July 7

### 2-op-amp instrumentation amp

Filed under: Circuits course — gasstationwithoutpumps @ 20:50
Tags: , , , , , , , ,

Last summer, I tried building an instrumentation amp using the MCP6002 op amps and external discrete resistors, and ended up with an amplifier that had terrible common-mode rejection, which is why I decided to use the INA126P instrumentation amp chip for the Blinky EKG boards and for the instrumentation amp protoboards.

I think I’d like to revisit that idea though, to see if I can make a cheaper Blinky EKG.  If I put together a Blinky EKG kit with the current design, the parts would cost about $9.30 (buying quantities of 100). The mist expensive single part is the instrumentation amp at$2.44.  If I could get the 2-op amp instrumentation amp to work using discrete components, I might be able to save most of that.  Replacing them MCP6002 dual op amp with an MCP6004 quad op amp and 4 more resistors would cost about 22¢ rather than $2.44, bring the parts cost down to around$7.07.

I could also reduce the price by using surface-mount devices (SMDs) instead of through-hole components. An instrumentation amp like the INA826 ($1.34 in 100s) would be a good choice if I went with SMDs. But if I used SMDs, the Blinky EKG would probably have to be a finished product rather than a kit, which would add substantial manufacturing costs, especially for things like a case, which could be omitted in a kit. The idea of a blinky board is to be an easy soldering project for beginners, so I’m not sure that a pre-assembled blinky EKG has much appeal for me (which is not to say there is no market for it, just that I’m not particularly interested in designing for that market). I looked at my old post and realized that I had miscomputed the gain for the differential signal, and never computed the gain for the common-mode signal. If the resistors are perfectly matched, the common-mode gain is 0, but without the laser trimming that makes the instrumentation amp chips so expensive, we’re not going to get perfect matching. The classic approach of adding trimpots takes up too much space and ends up costing almost as much as using an instrumentation amp chip. So the rest of this post is dedicated to better understanding the 2-op-amp instrumentation amp. I drew a schematic of a possible design, in order to have names for the parts and signals. Schematic drawn with SchemeIt and captured as a screenshot. The native exports into PNG and PDF formats were useless, because SchemeIt messed up the Unicode character Ω. I also had to do this as a 24-bit PNG, because WordPress.com seems to mess up 8-bit PNGs (they look fine when editing, but not in the Preview.) To analyze the circuit assuming ideal op amps (so the voltage difference between the two inputs of the op amp is 0), we need to look at the current through each resistor: $I_{1} = (V_{out} - V_{p}) /R_{1}$ $I_{2} = (V_{p} - V_{mid}) /R_{2}$ $I_{3} = (V_{mid} - V_{m}) /R_{3}$ $I_{4} = (V_{m} - V_{ref}) /R_{4}$ $I_{gain} = (V_{p} - V_{m}) /R_{gain}$ We also have that $I_{1} = I_{2}+ I_{gain}$ and $I_{4} = I_{3} + I_{gain}$, by Kirchhoff’s current law. We can add to get $I_{1} + I_{4} = I_{2} + I_{3} + 2 I_{gain}$, which can be expressed as $(V_{out} - V_{p}) /R_{1} + (V_{m} - V_{ref}) /R_{4} =$ $(V_{p} - V_{mid}) /R_{2} + (V_{mid} - V_{m}) /R_{3} + 2 (V_{p} - V_{m}) /R_{gain}$ If $R_{1}=R_{4}$ and $R_{2}=R_{3}$, then we can multiply both sides by $R_{1}$ to get $V_{out}-V_{ref} - (V_{p}-V_{m}) = R_{1} (V_{p}-V_{m}) (1/R_{2} +2 /R_{gain})$, or $\frac{V_{out}-V_{ref}}{V_{p}-V_{m}} = 1+ R_{1}/R_{2} + 2 R_{1}/R_{gain}$. For the values in the schematic above the differential gain is 6.6 + 112kΩ/Rgain. To look at common-mode gain, it is best to solve the pair of equations for the currents I1 and I4. Being lazy, I used maple to do the algebra: solve( { (vout-vp)/r1= (vp-vmid)/r2 + (vp-vm)/rgain, (vm-vref)/r4=(vmid-vm)/r3+(vp-vm)/rgain, \ vor=vout-vref}, {vout,vor,vmid}); simplify(taylor(subs(vp=vcomm+vdiff/2+vref, vm=vcomm-vdiff/2+vref, rhs(%[3])),vdiff));  which produced vcomm (-r2 r4 + r1 r3) - ---------------------- + r2 r4 2 r1 rgain r4 + r2 rgain r4 + 2 r1 r2 r4 + 2 r1 r4 r3 + r1 r3 rgain ------------------------------------------------------------------- vdiff 2 r2 rgain r4  that is, $V_{out}-V_{ref} = V_{common} \left(1- \frac{R_{1} R_{3}}{R_{2}R_{4}}\right) + V_{diff} \frac{R_{1}}{R_{2}}\left(1 +\frac{R_{2}}{2 R_{1}} + \frac{R_{2}}{R_{gain}} + \frac{R_{3}}{R_{gain}} + \frac{R_{3}}{2 R_{4}}\right)$, where $V_{diff} = V_{p}-V_{m}$, and $V_{common} = \frac{V_{p}+V_{m}}{2} - V_{ref}$ We can check for some copying errors by simplifying with $R_{1}=R_{4}$ and $R_{2}=R_{3}$, where we get a common-mode gain of 0, and differential gain of $\frac{R_{1}}{R_{2}} + 1 + \frac{2 R_{1}}{R_{gain}}$. Note that the common-mode gain is independent of the value of Rgain, and depends only on the matching of the other resistors. If R1 and R3 are 1% low, and R2 and R4 are 1% high, then the common-mode gain is 0.039. If R1 and R3 are 1% high, and R2 and R4 are 1% low, then the common-mode gain is –0.041. If you prefer thinking in decibels, the common-mode rejection with 1% tolerance resistors could be as poor as 27.8dB (compared to 80dB to 90dB for an INA126P chip). 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. ## 2012 November 23 ### Pressure sensor boards arrived The breakout boards for the MPX2053DP pressure sensors arrived today. They would have arrived two days ago, but I was at work and no one here heard the postman come—the packages have to be signed for, so I had to go down to the post office to day to get the package. I placed the order with ITEAD on 2012 Oct 29, they sent me e-mail saying they had shipped it on 2012 Nov 7, and it arrived 2012 Nov 23, for a total delay of 25 days. I plan to order more sets of PC boards from them this weekend: another order of the pressure-sensor boards, a revised instrumentation amp prototyping board, and a hysteresis oscillator board. If I order on 2012 Nov 24, I may get them by Dec 21, even without a special order. MPX2053DP on the breakout board. I assembled one MPX2053DP breakout board. It turns out that the leads are just barely long enough to reach the PC board, if you bend them at 90° right where they change size. That is where I had planned the bend when I laid out the board, so I’m glad it worked. The M3 machine screws do a fine job of holding the sensor in place, making soldering easy. I’ll use metal M3 screws for the sensors I assemble for the lab, rather than nylon ones. I’m using a different screw terminal than before. This one has a 0.1″ pitch, which is convenient for matching up with dual-inline packages and is more compact than the 3.5mm pitch screw terminals I was using before (I got a bunch of 3.5mm and 5.0mm pitch screw terminals in the ITEAD order, very cheap, but I’ll probably not be using them for new designs, unless I need heavier wires than the 0.1″ screw terminals will take). One minor problem with the new terminals is that you need a 1.5mm jeweler’s screwdriver—a 2.5mm screwdriver is too wide. Luckily I have a smaller one, and the set I was planning to include in the student toolkit has not only 1.5mm, but several smaller ones. I tested the pressure sensor with the amplifier I had wired up for the MPX2300DT-1 sensor, and noticed that it was very easy to peg the sensor at either extreme—I’ve got the gain set too high for this sensor. Note that the MPX2053 has a response of 8E-08 Vdd/P, while the MPX2300 has a response of 3.75E-8 Vdd/P, where Vdd is the supply voltage to the sensor, and P is the pressure in Pascals. So the MPX2053DP needs only half as much gain. I also noticed that the INS126 instrumentation amplifier does not have rail-to-rail output. I saw it going from 0.355 V to Vdd-0.7 V, though the spec only claims linearity from 0.8V to Vdd-0.75V typically. I should probably turn the gain down by a factor of 10 in the instrumentation amp and use a second-stage op amp with a gain between 2 and 4 to get a rail-to-rail signal. That will require unsoldering the gain resistor and wiring up a couple more resistors for the second-stage op amp. I think I’ll do it in 2 steps: first adjusting the instrumentation amp gain by replacing Rgain and seeing what range of voltage I get from my breath pressure, then adding a second stage amplifier to bring that to full scale. I think I’ll try a first-stage gain of 102.6 (instead of 1072), which should give me a response of 8.205E-6 Vdd/P, and a full scale reading of 121.88 kPa, or 119Pa/count. With that resistor in place, I’m not pegging the output at either end, and I’m using a little over ¼ of the available range. A second-stage gain of 2 should be safe, but 3 may occasionally hit the stop. Perhaps I should aim for 50Pa/count, which would need a gain of about 2.38. The best way to do this with a non-inverting op amp using standard resistors would use (11.5+15.8)/11.5 for a gain of 2.3739 (about 0.004% lower than I want). I wrote a little Python program which can find the best approximation to any ratio using standard 1% resistor values—I didn’t try them all by hand! Unfortunately, I have the standard 10% series (though with 1% resistors), so I need to try something like (47+33)/33, for 2.4242, a 3.2% error. My gain would then be 102.56*2.4242=248.63, for a full-scale reading of 50.275kPa, or 49.1Pa/count. It would be reasonable to use 33kΩ and 47kΩ. Using just the instrumentation amp (single stage), the lowest pressure I recorded was –19.2 kPa (–2.79psi) and the highest was 15.1kPa (2.19 psi). Using a handheld vacuum pump, I found that the low-pressure stop was about -390mm Hg (-52kPa), but that is with a most-likely inaccurate cheap dial gauge. The clipping when the vacuum pump goes beyond that is at -392 counts (-46.64kPa, if the specs and the gain computations are to be believed). After I soldered in resistors and wires for the second stage, it bottoms out at -25.24kPa (-3.66psi), with zeros. I looked at the first-stage output on one Arduino channel and the second stage output on another, and fit a straight line to the untruncated part using gnuplot. If we fit stage2=g*(stage1-m)+m, we get a gain g=2.4351 and a midpoint offset m=511.677. The total gain is thus about 249.74, for a full-scale reading of 50.05 kPa, or 48.88 Pa/count. The midpoint is not exactly at ambient pressure: it is about 300Pa below ambient pressure. The spec calls for an offset that is <2.5% of the full-scale reading, and what I’m seeing is less than 1%, so I suspect that the offset is in the sensor, not in my circuitry. Doing another run blowing into the tube and sucking on it, the highest pressure I could manage was about 17.3kPa (2.51psi). The lowest pressure I could get by mouth was about -16.6kPa (-2.41psi). It would probably be a good idea to calibrate the sensor with a water column, but I still need to think that through a bit more—I don’t want a flood. ### Other items in the package In the same delivery from ITEAD, I got an assortment of 25 different capacitor values (10 of each). These turn out to all have a 0.1″ (or 2.5mm) lead spacing, so I need to redesign the hysteresis oscillator board for that spacing (rather than the 0.2″ spacing I had used in the design). I had thought that there was about equal chances of 0.1″ or 0.2″ spacing, so I was not going to send out the new PC boards until I’d gotten the capacitors and checked. The assortment comes nicely sorted in 25 tiny zipper-seal bags, but the bags aren’t labeled, so the first thing I did was to get out a Sharpie and a magnifying glass so that I could read the labels on the capacitors and label the bags. I can’t order the capacitors for the students until Dec 14 (as students may still be registering for the course), so they will probably need to be ordered with express shipping. Also in the same delivery was an assortment of 11 different bipolar transistors, 10 of each. If we were doing anything in the class with bipolars, the price is pretty good (6.2¢ each), but now that I’ve decided we’ll use FETs for the power amplifier output, there won’t be any need for bipolar transistors. I’ve not found a comparably cheap collection of FETs. ## 2012 October 23 ### Rethinking the pressure sensor lab I’ve had several posts now relating to building a shaker table and putting together a pressure sensor lab project for the circuits course: I’m beginning to think that this lab, as I originally envisioned it, is both too much work to set up and too much work for the students. It was also beginning to look like a major spill hazard (much more so than the thermistor lab or the electrode characterization lab). I want to back off now and see whether there is a lab that fits better into the course and is less trouble both for me and for the students. Let’s look at the different parts of the lab, and see which are the most important—discarding the parts that are more trouble than they are worth. • Building an audio amplifier (op amp plus one discrete transistor) to drive shaker table. • Building an instrumentation amplifier with gain in the range 500–2000 to read strain-gauge bridge pressure sensor. • Calibrating pressure sensor with a water column. • Inducing pressure waves in water with shaker table, and measuring with pressure sensor. • Making measurements at two ends of a flexible hose to try to characterize water in hose using the hydraulic analogy. I like the idea of having students build an audio amplifier. In fact, we were planning a simple amplifier in an earlier lab, so extending it to drive more current than the op amp chip can source is a good one. But we don’t need to build a shaker table for that—we can buy cheap 4Ω or 8Ω speakers and have them build amplifiers for the speakers. I definitely like the idea of having the students learn about strain gauges and build an instrumentation amplifier for them. The$5 MPX2300DT1 pressure sensor is a good example of a strain-gauge bridge (with temperature compensation).  We could go with the uncompensated MPX53DP for $7.80, the$8 MPXV53GC7U or the \$11 temperature compensated MPX2053DP.  I rather like the sturdier “unibody” packaging for the differential pressure sensors (the DP suffix), and we could attach a hose to them directly, since they have barbed ports (which look like they are designed for 3/16″ ID tubing).  I’d still want a breakout board with screw terminals for the sensor, but assembling it would be easier, since the sensor can be soldered as a through-hole component and  screwed to the PC board, eliminating the gluing I needed for the MPX2300DT1.

I’m currently leaning towards a simpler (and cheaper) setup—eliminating the shaker table, the ¾” PVC plug, and the PVC water reservoir, and just having an MPX2053DP (or even MPX53DP) pressure sensor on a breakout board.  This would discard the hydraulic analogy part of the lab, but students would still build an instrumentation amplifier, characterize the pressure with a water column (easily measured as the height of water in clear tubing), and use the pressure sensor to measure breath pressure (inhalation and exhalation).

The maximum pressure of human breath is about 25kPa or 100″ H2O, so the ±50kPa range of the differential sensor should be plenty. The MPX2053 sensor is spec’ed at 800µV/kPa with a 10V power supply, so with a 5V supply it would provide 400µV/kPa.  We probably want a 0–5V output for a -25kPa to +25kPa input, so an amplifier gain of 250 is called for.  That’s a bit less touchy than the gain of 1000 I  used with the MPX2300DT1, but will still be good warmup for the EKG amplifier (which needs higher gain and has to use two stages to avoid saturating from small DC offsets in the first stage).

The uncompensated MPX53DP is spec’ed at 1.2mV/kPa at 3v (2mV/kPa at 5V), so less gain would be needed for the uncompensated part.  If you don’t need temperature correction, then the cheaper part gives you greater sensitivity. I’ll have to think about which would be pedagogically more useful—currently I lean towards the temperature-compensated part, as a concept that they should learn and because it forces them to make a higher gain amplifier.

Building the instrumentation amp and making breath pressure measurements should only take one 3-hour lab period, rather than two, so if I go with this design, I’ll need to come up with another lab.  Perhaps a second audio amplifier lab, with an output transistor and some filtering would be a good lab to insert I have to decide whether that should be a soldering lab or a breadboard lab.  I think that the two instrumentation labs (pressure sensor and EKG) should be done by soldering on a PC board, but I’m not sure the instrumentation amps should be their first soldering projects.

« Previous PageNext Page »