Gas station without pumps

2014 June 29

Soldered EKG from op amps

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

Today I decided to solder the EKG design from Instrumentation amp from op amps fine for EKG onto one of my instrumentation amp protoboards, leaving out the instrumentation amp chip—I wanted to see how much trouble it would be.  As it turned out, the build was fairly straightforward, but a little tedious. There are only dedicated spaces for 8 resistors on the board, but there are 9 resistors in the design I used, so one had to go elsewhere on the board.  I deliberately left out the low-pass filter on this implementation (eliminating one capacitor), which did not make a huge difference—I ended up with about 58µV peak-to-peak of 60Hz noise on my input signal (compared to about 40µV in the previous design with a capacitor for low-pass filtering), which is fairly small compared to the 870µV R spike or the 220µV T wave.  The 60Hz interference was large enough to interfere with the P wave and make it difficult to see whether or not there was a U wave.  Of course, these measurements were made in my bedroom/lab, which has a lot less 60Hz interference than the lab the students work in.  I’ll have to take the board into work and see how bad the interference is in that space.

Using a digital filter to remove the 60Hz noise reduced the 60Hz interference to under 100nV peak-to-peak (way lower than other noise components), producing very nice waveforms, even when sampling at 360 Hz.  I’ll probably want to include a digital filter Python script in the book so that people can see the cleaned up signals, even if there isn’t room in the course to design digital filters.

I still have to decide whether to have students do the EKG amplifier without the INA126P chip, using only op amps. Wiring up the bigger circuit takes time, and I’m not sure that 6 hours of lab will be enough time for students to debug their design and get it soldered—it took them long enough to solder the EKG with the INA126P chip, which has fewer components and fewer wires to route.  It took me quite a while to solder up the board, so it would probably take the students far too long.  Is the pedagogic value of designing and building a 2-op-amp instrumentation amp worth the time? I do want the students to end up with an EKG to take home, as it is a tangible artifact that can demo the function of.  I’m thinking that I could even drop the soldering of the pressure-sensor amp (since they don’t take home pressure sensors), and add soldering of the microphone pre-amp.  If I do that, I’ll probably want to redesign the protoboard again, making it an op-amp protoboard with no instrumentation amp slot, but with more resistor spaces.

Cutting one part that costs about $2.70 and the $1.90 thermometer might justify my switching back to the resistor assortment I used in Winter 2013:  1120 piece resistor assortment for $17.39 instead of 1280 piece resistor assortment (currently $10.65) without raising the lab fee.  Why would I want fewer resistors at a higher price? The 1120-piece assortment is 10 each of 112 values, while the 1280-piece assortment is 20 each of 64 values.  Also the 64 values don’t seem to be very repeatable from set to set, and some sets has duplicates (so only 62 or 63 different values).  The 112-value sets seem more reliably useful.  A hobbyist might be better off going one step further to the 3700-piece resistor assortment (25 each of 148 values), but I can’t justify the $31.48 price for my class. (The extra $14 would probably raise the lab fee.)

 

2014 June 26

Instrumentation amp from op amps fine for EKG

Filed under: Circuits course — gasstationwithoutpumps @ 22:55
Tags: , , , , ,

As I mentioned in Instrumentation amp from op amps still fails, I’ve been trying to decide whether to have students build an instrumentation amp out of op amps in the circuits course.  I decided that it wouldn’t work for the pressure-sensor lab, because of the large DC offset.  One could calibrate each amplifier, either in software (by recording a a few seconds of 0 pressure difference, and subtracting a constant fit to that region from the data) or in hardware, but I’d rather they had a more straightforward experience where the DC offset was small enough to be ignored.

I conjectured that instrumentation amp built from discrete op amps would work ok for the EKG lab, though, as the EKG already has to deal with much larger input voltage offsets due to differing electrode-skin contact.  So I added a second stage  with a gain of 81 to the instrumentation amp in the previous post with a gain of 19, to get a combined gain of 1539.  I put in the high-pass filter needed to eliminate the DC offset, and a low-pass filter to reduce noise slightly (and make aliasing less of a problem).  The corner frequency is a bit high (60Hz noise is not going to be reduced much), but that may allow a better view of the fast R spike in the EKG waveform.

    The EKG circuit has four modules: a virtual ground (here set to 0.5v), an instrumentation amp, a high-pass filter to eliminate DC bias, and a second-stage non-inverting amplifier with some low-pass filtering.

The EKG circuit has four modules: a virtual ground (here set to 0.5v), an instrumentation amp, a high-pass filter to eliminate DC bias, and a second-stage non-inverting amplifier with some low-pass filtering.

The amplifier worked surprisingly well. I did sometimes have trouble with 60Hz noise, but it did not seem to be any worse than the amplifier based on the INA126P. I can remove the noise by digital filtering, though I’ve only played with that by post-processing the data files, not by designing a notch filter to run in realtime on the KL25Z (something to do when I have more time).

Here are a few traces made with EKG circuit above, feeding into the PTE20-PTE21 differential input on the KL25Z board, recorded using PteroDAQ.

This is lead I, without filtering, showing a rather disturbingly large 60Hz noise signal.

This is lead I (LA–RA), without filtering, showing a rather disturbingly large 60Hz noise signal.

This is lead I (LA-RA), showing how the digital filter cleans up the signal. This was Bessel bandpass filtered to 0.3Hz to 100Hz, followed by notch 57Hz–63Hz, followed by notch 117Hz–123Hz. Each filter was a 5th-order Bessel filter, applied first forward in time then backward in time (using scipy's filtfilt function).

This is lead I (LA–RA), showing how the digital filter cleans up the signal. This was Bessel bandpass filtered to 0.3Hz to 100Hz, followed by notch 57Hz–63Hz, followed by notch 117Hz–123Hz. Each filter was a 5th-order Bessel filter, applied first forward in time then backward in time (using scipy’s filtfilt function).

This is lead II (LL-RA), which for some reason had rather low noise even without filtering.

This is lead II (LL–RA), which for some reason had rather low noise even without filtering.

I noticed that sampling at 360Hz allowed me to see a bit more of the structure of the S and T complex than I’ve seen previously, particularly in lead II, and I can even make out a little bump of a U wave just after the T wave.

I now have to decide whether to have students do the EKG amplifier without an INA126P chip, using only op amps. The design will be fairly heavily constrained, as they’ll need to get it all working on a single MCP6004 chip, but it will justify my spending a bit more time on how instrumentation amps work.

I may redesign the blinky EKG to use a single MCP6004 chip also, which would reduce the price of that substantially.

Instrumentation amp from op amps still fails

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

I’ve been trying to decide whether to have students build an instrumentation amp out of op amps in the circuits course.  Currently the INA126P instrumentation amp chip that I have them use is a black box to them, even though I include an explanation on the lab handout showing how it is internally a pair of op amps and 4 resistors:

Internally, the INS126P instrumentation amp is two op amps and 4 resistors.

Internally, the INS126P instrumentation amp is two op amps and 4 resistors.

I won’t repeat that presentation here (there’s a condensed, early version of it in a previous blog post).  I’ve not actually lectured on the 2-op-amp design before the instrumentation-amp lab, in class, though I did manage to talk about the 3-op-amp instrumentation amp this year (a waste of time, since they did not really process the ideas).

What I was interested in today was whether the pressure-sensor lab could be done entirely with op amps, rather than with the more expensive INA126P chip.

I decided to design an amplifier with a gain of around 200 and an output reference voltage around 0.5 v (based on a 3.3v supply), using the 2-op-amp design and MCP6004 op amps. Here is what I came up with:

This is the design I came up with and built.  It works, sort of.

This is the design I came up with and built. It works, sort of.

The amplifier amplifies and seems to have about the right gain, but there is a large DC offset on the output: about 0.24V, which translates to an input offset of about 1.2mV. I checked with a multimeter, and the negative-feedback voltages are indeed about that far apart, while the inputs from the pressure-sensor bridge are less than 40µV apart. The pressure sensor sensitivity is about 80µV/kPa/V, or 264µV/kPa with a 3.3V supply. If I use the pressure sensor with a blood-pressure cuff, I’ll want to go up to about 180mmHg or 24kPa, so the sensor output should be in the range 0–6.3mV. An offset of 1.2mV is huge!

If I remove Rgain from the circuit, the output offset drops to 20.88mV, which is 1.1mV referenced to the input (close to the 1.22mV measured at the negative feedback inputs).  Further removing R2 or R4 does not change the voltage difference between the negative-feedback inputs.  In fact removing all three of Rgain, R2, and R4, so that we have two unity-gain buffers (with 180kΩ and 10kΩ feedback resistors), still leaves the negative feedback points 1.22mV apart.  Each seems to be about 0.6mV from the corresponding positive input.

The problem is that the input offset voltage of the MCP6004 op amps is only guaranteed to be between –4.5mV and +4.5mV:  I’m lucky that the input offset voltage is under 1mV!  Even the INA126P instrumentation amps that we’ve been using have an input voltage offset of up to 250µV (150µV typical). One can obviously get better instrumentation amps, but the selection in through-hole parts is limited, and I’d have to go to an instrumentation amp costing $4.25  (LT1167CN8#PBF) instead of $2.68 to get the input offset voltage down to 20µV.

I’m going to have to rewrite the section of the book on instrumentation amps, to discuss (at least briefly) offset voltages.  I had originally thought that that the signals we were looking at were big enough that the offset voltages didn’t matter. For the INA126P, a 150µV offset would be about 0.6kPa, while the 1.22mV offset I was seeing in my homemade instrumentation amp would be about 4.6kPa.

I wonder also whether I can make an EKG circuit using this 2-op-amp instrumentation amp circuit.  The EKG already has to deal with potentially large input voltage offsets due to differing electrode-skin contacts.  In fact those offsets may be over100mV, far larger than the 1.2mV from the amplifier.  I’ll have to add another stage of amplification (after a high-pass filter), but that shouldn’t be a problem. I looked at this problem a year ago in 2-op-amp instrumentation amp and Common-mode noise in EKG, and concluded then that common-mode noise would be too large, but I’m tempted to try again, using the design here with gain 19 and a second stage with a gain of around 80 (for a combined gain around 1520), as last year I rejected the idea before actually building the circuit.

 

2014 June 22

Loudspeaker relaxation oscillator

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

Yesterday I played around a little with a hysteresis oscillator (relaxation oscillator) using a loudspeaker as the feedback device, rather than a resistor, as shown in the schematic below:

Hysteresis oscillator with loudspeaker for feedback.  Changing the value of C1 should produce different frequencies.

Hysteresis oscillator with loudspeaker for feedback. Changing the value of C1 should produce different frequencies. I used 3.3v from the KL25Z board as my power supply.

I was hoping that I could get the oscillator to resonate at a predictable frequency, based on the gain or the phase shift of the voltage divider consisting of the loudspeaker and the capacitor. Of course, a relaxation oscillator that relies on the hysteresis of a Schmitt trigger is emphatically not a linear circuit, and there is no reason to think that using a loudspeaker instead of a resistor for the feedback element will simplify anything.

I did have a few questions:

  • Would it oscillate? (I saw no reason it shouldn’t.)
  • At what frequency would it oscillate? Was there any relationship to the gain or phase shift of the loudspeaker and C1 voltage divider?
  • How stable was the frequency?
  • Would it be loud enough to hear on the loudspeaker?

Before even wiring up the circuit, I ran some gnuplot scripts with my model of the loudspeaker to see what the gain and phase of the voltage divider would be:

Gain from the voltage divider, with different C1 values.  Note that I've also added a line for an RC low-pass voltage divider, for comparison.

Gain from the voltage divider, with different C1 values. Note that I’ve also added a line for an RC low-pass voltage divider, for comparison.

Phase change from the voltage divider, with different C1 values. Again I've added a line for an RC low-pass voltage divider, for comparison.

Phase change from the voltage divider, with different C1 values. Again I’ve added a line for an RC low-pass voltage divider, for comparison.

Note that the loudspeaker+capacitor provides a bigger phase change at high frequency and a faster rolloff in gain than an RC filter would. I was hoping that the resonant peaks at high frequency might capture the oscillator and provide a moderately stable output.

To avoid load on the oscillator from a multimeter (used to measure frequency) or oscilloscope, I buffered the output with a couple more Schmitt triggers.

C1 frequency
electrolytic measured with Fluke 8060A
 470µF  27Hz
 220µF  50–55Hz
 47µF  265–285Hz
 33µF  375–406Hz
 4.7µF  3077–3401Hz
ceramic measured with Fluke 8060A
 4.7µF  2.56–2.66kHz
 0.1µF  116–122kHz
ceramic measured with Bitscope oscilloscope
 47nF  245kHz
 22nF  286kHz
 10nF  587kHz
 2.2nF  1.1MHz

The frequencies were not stable, but shifted unpredictably within a fairly wide range. The Fluke 8060A meter is not capable of frequency measurements above about 100kHz, so I used the FFT on the Bitscope USB oscilloscope for the higher frequencies. For the Bitscope measurements, I took whichever frequency seemed to come up most often—usually the lowest frequency.

The audio-range frequencies 27Hz to 3.4kHz were clearly audible on the loudspeaker (even annoying at the higher frequencies), and the fluctuations in frequency were audible also—they are not an artifact of the measuring equipment.

Looking at the input and output of the oscillating Schmitt trigger for a moderately large capacitor is instructive:

The green trace is the input to the Schmitt trigger—it seems to be a fairly clean triangle wave.  The yellow trace is the output—it jumps when the inverter switches, but the current limitation of the Schmitt trigger seems to keep it from being a square wave. C1 was 33µF here, and the timebase is 2ms/div.

The green trace is the input to the Schmitt trigger—it seems to be a fairly clean triangle wave.
The yellow trace is the output—it jumps when the inverter switches, but the current limitation of the Schmitt trigger seems to keep it from being a square wave.
C1 was 33µF here, and the timebase is 2ms/div.

The current limitation on the Schmitt trigger output seems to be the controlling factor here, so we should be modeling this as a current source and capacitor, with the feedback impedance being irrelevant until it gets large enough that the Schmitt trigger output is voltage-limited instead of current-limited.

I tested this by replacing the loudspeaker by a 22Ω resistor, and got a very similar result (though without the voltage spikes from switching the loudspeaker inductance):

The nearly constant difference between the input and the output (across the 22Ω resistor) indicates nearly constant current flow.

The nearly constant difference between the input and the output (across the 22Ω resistor) indicates nearly constant current flow.

If we look at the voltage across the resistor, we can measure the current:

The current through the 22Ω resistor is about ±18mA, though it isn't quite as constant as I had thought from the previous plot.  (This plot is 200mV/division, so about 9.11mA/division.)

The current through the 22Ω resistor is about ±18mA, though it isn’t quite as constant as I had thought from the previous plot. (This plot is 200mV/division, so about 9.11mA/division.)

With a 3.9Ω feedback resistor, I again see waveforms consistent with a ±18.5mA current limit (dropping gradually to ±15mA before it switches to the other phase). I can get the same triangle wave at the input if I use a wire for the feedback, with the output only a few mV different from the input (for a wire resistance equivalent to about 130mΩ). The period is about the same also, indicating that the current is what is determining the charging time of the capacitor, not the feedback resistor.

With a 200Ω feedback resistor, I see a little current limitation just as the output switches, but it becomes voltage-limited soon after. The period increases, as we would expect when the voltage limitation reduces the current.

So the loudspeaker in the feedback loop was not very interesting—it was behaving much like any other low-impedance feedback. At least, that is what is happening with low frequencies, where the loudspeaker is reasonably modeled as an 8Ω resistor.

With a 10nF capacitor and a 22Ω feedback resistor the oscillator oscillates at 1.27MHz, but with the loudspeaker only at 589kHz, so the loudspeaker is behaving more like a large impedance at these frequencies.  The output with the 22Ω resistor is a triangle wave, but with the loudspeaker is a square wave (with a little high frequency ringing).  I can’t see these frequencies well on the Bitscope oscilloscope, so I had to switch to my analog Kikusui COS5060 60MHz oscilloscope.  With 47Ω and no oscilloscope load, I get a frequency around 965kHz, with 22Ω around 1.13MHz, with 81Ω around 768kHz,  with 100Ω 687kHz, with 120Ω around 613kHz, with 150Ω around 526kHz, and with the loudspeaker around 590kHz.  So the loudspeaker is behaving like a 125–130Ω impedance around 590kHz, which is consistent with the measurements made of the loudspeaker impedance around that frequency. Similarly with a 3.3nF capacitor, I get 150Ω 1.23MHz, 180Ω 1.1MHz, 200Ω 1.03MHz, 220Ω 972 kHz, and loudspeaker 987kHz.  The output waveforms with the 220Ω or loudspeaker as feedback are fairly good square waves, so the oscillator feedback is voltage limited, not current limited.

So it looks like the simple analysis of the oscillator as being either a current-limited or a voltage limited output suffices for modeling the relaxation oscillator—the phase changes don’t seem to matter much, just how fast the capacitor charges or discharges, which depends mainly on the magnitude of the impedance.

Incidentally, the fluctuations in frequency for the oscillator occur with the resistors and the loudspeaker alike, and so don’t seem to be due to any physical or electrical properties of the loudspeaker.  They also occur with both electrolytic and ceramic capacitors.

2014 June 14

Zeroth draft of book done

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

My big project for the summer is to convert my lab handouts and a few of my blog posts into a textbook: Applied Circuits for Bioengineers.

The first task was to take the existing handouts (each a separate LaTeX file) and merge them into a single book-style LaTeX document, with title page, table of contents, chapters, index, and all the other front matter and back matter of a book. I’ve now done that, making a crude split into chapters of background and “Lab” chapters.

The results are not very book-like in terms of content, but I now have a framework to which to add the missing background material.  I expect to spend a few hours a day on the book all summer, and somewhat less time on it in fall and winter, so that a complete draft will be ready for the next time I teach the course in Spring 2015.

I’ve not figured out how I will distribute the book when I’m finished—I’ll certainly be giving the PDF for free to students who take my course, but I’ve not decided whether to self-publish the book, work with a professional textbook publisher, work with an electronics hobbyist company, or just dump the book for free on the Internet.  Each has its advantages and disadvantages.

I’m producing the book using LaTeX—there is a fair amount of math and a lot of figures (64 so far, and probably many more to come), so no other tool I have available is suitable for producing a book-length document of this complexity.

One LaTeX problem I’m running into is that I want the lab assignments to be chapter level objects, but separately numbered from the chapters.  Currently I have the ugly approach of making the labs  be names of chapters: Chapter 9: Lab 4: Electret Microphones, which I’m really not happy with.  But changing the running heads and the table of contents entries is a bit tricky, particularly since some places use just the chapter number, which would have to be replaced by a word plus number.  I’ll probably play with things like getting interleaved lab and chapter numbering when I get too tired of writing content.

There will be some rather tedious parts to the writing—like adding index entries, which I may try to bribe my son or some students to do.

This zeroth draft of the book is currently 186 pages, with about 160 pages of content.  I expect the book to grow to about 240 pages of content as  I add more stuff from my lectures.

Next Page »

The Rubric Theme. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

Join 266 other followers

%d bloggers like this: