# Gas station without pumps

## 2015 June 3

### Crude theremin

On Monday I again had 2 lectures: one in Banana Slug Genomics on the Burrows-Wheeler Transform and FM index, and one in applied electronics finishing up the EKG preparation and starting into optional material.

The BWT and FM-index lecture was a bit rough though I had prepped on the material for a fair amount of time over the weekend.  I think that the written presentations I’d used to prep from (which included the Li and Durbin paper on BWA) were better than my lecture, so I ended up pointing the students to them as well, hoping that my lecture would at least make them more willing to click through and read the paper.

In the electronics class, I provided some feedback on the lab reports (reminding students once again how to figure out the DC bias resistor for an electret microphone).  Over the weekend I had finally caught up on the grading, so of course Monday saw a huge stack of redone work being turned in—I did the prelab grading Monday night, but I did not have the heart to start on the redone work last night or tonight.

After the feedback, and questions from the class on the EKG lab, I gave the EKG demo (which had worked fine before cycling up the hill).  Needless to say, it did not work when I hooked everything up in front of a live audience.  But I turned this into a teachable moment by explaining what I thought the problem was (bad electrode connections, because touching the reference wire produced a change in the output), and getting out three new electrodes, adding a a little electrode gel, sticking them on next to the ones I was already wearing, and moving the clips over.  Luckily, that was the problem, so I was able to demonstrate debugging, even with no lab equipment.

The EKG demo concluded the required material for the course, and so I asked students for suggestions on what I should cover next.  I suggested the electronics of the nanopore and nanopipette labs, and asked them for other ideas. One student wanted me to explain how theremins work, and a couple of others agreed that would be an interesting topic.  So I finished Monday’s lecture on the nanopore electronics (basically telling them it was just a transimpedance amplifier, but engineered for high gain and very low noise, and talking a bit about the copper boxes around the stations to reduce capacitive coupling), and told them I’d try to talk about theremins on Wednesday.

Tuesday’s lab went fairly smoothly, but I was kept busy helping students debug their designs—most often the problem was miswiring, but some students had electrodes that weren’t making good contact.  I had on a set of working electrodes, so that we could swap the leads to my electrodes to see if the problem was the electrodes or their boards.  A lot of the students had a lot more 60Hz noise pick up (even with my electrodes) than I was getting, and I could not always determine why. In some cases it was simply long wires on the breadboard.  They’ll be soldering up their EKGs on Thursday, and the wiring should be much more compact there.

Tuesday night I read up on a bunch of analog circuits relevant to Theremin design, and in today’s class I presented

• a block diagram for a theremin (two oscillators—one with an antenna, a mixer, and a low-pass filter to pass only the difference frequency)
• I showed them a rather crude theremin that they could implement from what they already knew: two relaxation oscillators using Schmitt triggers, an XOR gate, and an RC low-pass filter. (Only the XOR gate was new to them.)
• I then talked about mixers, presenting a ring modulator (which they probably didn’t understand, as we’ve not done transformers except in passing), a simple two-resistors plus a diode non-linear mixer, and a synchronous decoder using a switch to change an op amp gain from +1 to –1.  I mentioned a couple of Wikipedia articles they could look up for other mixer designs (Gilbert Cell and frequency mixer).
• I then introduced the notion of a sine-wave oscillator as a loop with gain exactly 1 and a phase change of 2πn for some integer n.
• The first oscillator I showed them was a Wien oscillator using an op amp, for which I derived that at $\omega RC = 1$ the phase change of the positive feedback was 0 and the gain was 1/3, so we could set the positive gain to 3 to satisfy the requirements.  I mentioned the first Hewlett-Packard oscillator, and the trick of using an incandescent light bulb to control the gain and avoid clipping.  I showed them a plot of the amplitude and phase change for the feedback circuit, using gnuplot functions that they are familiar with from their own modeling.
• Next I showed them an LC tank circuit, and derived the infinite impedance resonance $\omega^2 LC = 1$.
• I then got to a Colpitts oscillator, showing them a possible circuit using an op amp, and how to model it as cascaded voltage dividers using gnuplot.  I showed them that the phase change of the feedback was 180° and that the phase change moved away from 180° very fast.  I was running out of time, so I briefly mentioned the Hartley oscillator and the Clapp oscillator, but didn’t really go into them.

On Friday, I plan to cover one-transistor amplifiers (common emitter with emitter degeneration and common collector—I probably won’t do common base), as those seem to be popular in theremin designs.

Tonight, since I was not willing to face grading, I decided to try out the crude relaxation oscillator Theremin.  Here is the circuit I ended up with (not including the bypass capacitors):

I used the potentiometer on the second oscillator to do crude pitch matching for the two oscillators, just looking at the period on an oscilloscope. The emitter-follower amplifier was used to get enough current to drive the loudspeaker.

The crude theremin only sort-of works.  I could get high-pitched theremin-like noises from it, but when the difference frequency dropped to 500Hz, the two oscillators phase-locked and the speaker went silent (often with very irritating on-off stuttering). The phase lock occurred even though the oscillators were on different chips at opposite ends of the breadboard, and I had 10µF ceramic bypass capacitors on each Schmitt trigger package and a 470µF electrolytic on the middle of the power bus.  Everything was powered to 5V with the USB power from my MacBook Pro.

I also often got 60Hz modulation of the signal, often as a on/off square wave, when the frequency difference was close to the point where the oscillators phase locked.

I’m not sure how the oscillators are getting coupled so that they phase lock when the difference frequency is small, so I’m not sure how to fix the problem.  The 60Hz sensitivity is almost inherent in the relaxation oscillator design, since the thresholds for the hysteresis on the Schmitt trigger remain fixed, but the hand near the antenna couples in 60Hz interference.  I suppose that over the summer I should try building a theremin with Colpitts oscillators or Clapp oscillators, to see if that works any better.

## 2015 May 29

### Two lectures: Jellyfish and EKG

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

I gave two lectures today: the first in Banana Slug Genomics on the k-mer counting program Jellyfish, the second in my Applied Electronics course on 2-op-amp instrumentation amps and EKGs.

The Jellyfish lecture went reasonably smoothly.  I rather like the program, because it is very old school.  It uses clever bit-hacking techniques to minimize memory usage in a straight-forward hash-table approach to kmer counting, rather than sophisticated and inscrutable data structures. It also take advantage of the CAS instruction (compare and save) to do lock-free parallel updates to the hash table. It is a computer engineering solution to kmer counting, rather than a computer science one.

The electronics lecture also went fairly well. I presented the internals of the instrumentation amp that they have been using:

The 2-op-amp instrumentation amp has a fairly simple design that is easy to remember.

In class we derived the gain equation by using three ideas:

• Negative feedback amplifiers keep the op-amp inputs at the same voltage, so V1=Vin+ and V3=Vin–.
• Kirchhoff’s current law ensures that all the currents out of V1 sum to 0, and all the ones into V1 sum to 0.
• R1=R4 and R2=R3.

We can write down the two current-law equations, and add them to cancel the terms involving V2.  That leaves us with an equation that can be rearranged to get the gain equation $V_{out}-V_{ref} = R_{1}\left(1/R_{1} + 1/R_{2} + 2 R_{gain}\right)$.  The students will have to build their own instrumentation amp as part of the EKG circuit for next week’s lab.  They won’t be able to match the resistors as exactly as the INA126P’s laser-trimmed resistors, but their op-amps have higher input impedance and rail-to-rail output, so the resulting instrumentation will be fine for them.  They can’t use much gain in it anyway, since the input ±1mV EKG signal can have as much as 200–300mV DC bias, so that they can’t use a large gain in the first stage without risking saturation of the amplifier.

After the instrumentation amp, I talked a bit about action potentials and ion channels and tried to give them an idea of how a wave moving through the heart gives rise to a voltage dipole, which is what we actually measure.  I still don’t have a crystal-clear view of that in my head that I can present on a chalkboard.  Perhaps I should look around for a video to point the students to.

I had originally planned to demo the EKG in class today, so I put on electrodes after my morning shower, but I decided to test the EKG boards I had before going in to work, and none of them functioned.  Since all of them had worked in the past, I attributed this to a failure of the electrodes, but I had no time to debug in the morning.  When I got home, I decided to try to debug the circuit.  Needless to say, when I hooked up the leads to the electrodes, the circuit worked just fine:

With 480Hz sampling, a moderate amount of capacitively coupled 60Hz interference can be seen.

A bandpass filter and pair of notch filters remove the DC offset and most of the 60Hz and 120Hz interference.

The only explanation that I’ve come up with (and the one my wife came up with without knowing any electronics), is that I was sweaty by the end of the day. If the electrodes had dried up a bit, then they might not have been very conductive. The sweat may have reduced my skin resistance and the resistance of the electrodes, giving a stronger signal (and a better Vref connection for the third electrode). I can anticipate this problem for Monday’s demo, by putting a dab of electrode gel on the electrodes before attaching them. The disposable electrodes aren’t supposed to need electrode gel, but it is a simple solution. I bought a tube of electrode gel earlier this year precisely in anticipation of needing it for dried-out electrodes.

## 2015 March 18

### Freshman design projects moderately successful

I just finished grading this year’s freshman design projects. I think that the projects were more successful this year than last year, in part because I kept the students focussed on electronics and programming (for which they had lab access and which I could help them debug), and in part because the projects were somewhat less ambitious.

There were two groups doing EKGs and 4 groups doing blood pressure meters.  Both EKG groups managed to demonstrate their projects working, as did one of the blood-pressure groups.  (I’m being fairly generous here about what “working” means—they had to get their electronics to work, capture the data, and plot the waveforms, but further interpretation or software was not required.)  The other three blood pressure groups did not manage to demonstrate their projects, but one of them managed to plot waveforms for the pressure measurements (without getting their high-pass filter and amplifier working for the pulse measurements).

Some things I learned for next year:

• Tell the students what op amp to get.  A number of students picked op amps that turned out to be rather old-fashioned ones with very low input impedance (as low as 2MΩ), rather limited output ranges, and external nulling circuits. The cheap MCP6002 or MCP6004 chips would have worked better at lower cost.  In fact, I gave one group that seemed to have a good schematic (but couldn’t get their circuit to work) an MCP6002 chip, which they wired in place of the op amp they had been using, and their circuit worked immediately.  I would have done the same for other groups, but the others with poorly chosen op amps were about a week behind and did not have circuits that were that close to being functional.
• Warn students sooner not to use FedEx.  My son’s and my experience with FedEx this year has been that they are ludicrously slow. At least one group was burned by a ridiculously long delivery time, having ordered with FedEx delivery just hours before I warned the class about them.  (The US Post Office is faster and cheaper for lightweight electronics orders from Digi-Key.)
• Students who never ask questions in class probably don’t understand much that is going on—all the groups that successfully demonstrated their projects had at least one active participant in class.
• Students who fail to turn in their progress report are almost certainly not going to complete the project on time—I need to be more assertive in getting them moving and demanding that they show me their schematics.  Almost everyone had errors in their schematics on their first design (and one of the successful groups went through 4 incorrect designs before getting to one that worked).  Students that are afraid to show me incorrect or incomplete work don’t get the feedback they need to correct the problems—I need to normalize errors more and insist on seeing stuff, even if it is wrong.
• The MXP5050DP pressure sensors are very easy for students to use, though a bit pricey at $16 each. The built-in amplifier makes doing pressure measurements with an Arduino fairly trivial (hook up the three wires of the sensor to A0, +5V, and GND). They were a good choice for the freshman design seminar, though I’ll continue to use MPX2053DP sensors without an integrated amplifier for the applied circuits class—that assignment is intended to get students to design with an instrumentation amp and to understand a bit about strain gauges. • Get the students to plot stuff earlier in the quarter. One group tried installing gnuplot on a Mac in the lab in the last few hours, which did not go well for them. They did eventually find a plotting program that they could install and run, but then did not have time to run the data they collected through the filtering program I’d written for the class. Their signals were pretty clean, though, and the plots they produced were good even with just the RC high-pass filter in their amplifier, without digital filtering. • The students seemed (for the most part) pretty excited about the projects—even those whose projects didn’t quite work seem to have gotten a lot out of the lab times. I should look in a couple of years to see how many have stuck with engineering majors (I suspect that some might switch to computer science or computer engineering, rather than sticking with bioengineering, but that’s ok). ## 2014 July 18 ### How to sell a widget SparkFun has a tutorial on how to sell “widgets” through them at How to Sell Your Widget on SparkFun – Learn.SFE: Have an awesome electronic widget that you want to get to market? Great! We are always listening for new ideas from our customers and the community. We get many inquires on this topic, so read this tutorial carefully to keep your product pitch from getting lost in the shuffle. We’re lucky, here at SparkFun, to have an amazingly creative and talented group of customers. Not only can they identify gaps in the catalogs of electronics suppliers, they can create a gizmo that fills that hole. But, going beyond a prototype or even a limited-quantity production run, often the hardest task in getting your world-altering product out there is producing, marketing, and/or selling it to the masses. That’s where we come into the picture. The advice there is seems fairly reasonable. They offer a choice of two models: make it yourself and have them sell for you, or have them make it and pay you royalties. They tell you how to pitch products to them and how to design for them to be able to manufacture stuff. Most of the stuff they sell is PCB boards, so they give quite a bit of advice about PCB design to fit their pipeline—they use Eagle, but ‘All parts are placed on a 0.005″ grid. If possible, use a .05″ grid.’ That must get irritating with modern parts that are convenient round metric numbers, not mils. They also want version numbers in the bottom copper, which is reasonable for some designs, but not all. They also encourage people to use their Eagle libraries, but my son and I have found their pad layouts to be very sloppy (putting silkscreen over SMD layers, getting the keep-out areas off by a little bit, not fixing the fonts on the “>NAME” and “>VALUE” labels to meet their own requirements, and so forth). Still, it is good that they put out their design rules and provide clear guidelines to new designers. I’ve thought a few times about putting out some of my designs through SparkFun or Adafruit Industries—perhaps an improved version of the blinky EKG as a kit. SparkFun now sells EKG electrodes and snap leads for them, and even have a heart-rate monitor board (based on the AD8232 chip) and the “BITalino” biomedical board, so I suspect that they are interested in the market. The BITalino is outrageously expensive and their EKG electrodes are about 3 times the price of buying them at Amazon, but the AD8232 chip actually looks like a nice one for building an EKG front-end and reasonably priced, so I’m not sure they’d have much interest in a through-hole part kit for do-it-yourself EKG that isn’t quite as good, unless it could be sold very cheaply or as an educational product (which is what the blinky EKG is aimed at, anyway). I have some other ideas for products that I might be marketable, but I don’t know whether I have the time to refine them to the point of pitching them to SparkFun. I can justify some time spent on doing electronics as a hobby, some as necessary learning for teaching my applied electronics course for bioengineers, and some as engineering-for-manufacture experience (something I never had any instruction in, despite my years as an engineering professor). But when the electronics work starts cutting into the time I need to spend on writing my book, teaching my classes, or doing collaborative research with other faculty, then I have to draw the line. I’ve also got a lot of administrative responsibilities now (undergrad director and faculty adviser for two BS degrees, Program Chair for bioengineering, and Vice Chair for the Biomolecular Engineering Department), so writing time and research time have gotten doubly precious. I do have one project this summer that I’m going to try to get fabricated for me—it is all SMD parts, including some that are hard to solder by hand (pads under the chips), so I don’t want to do it myself. The project also calls for a lot of identical boards (20 to 50 of them), so a prototyping house seems like the way to go. I’m looking currently at Smart Prototyping to do the PC board fabrication and assembly—they may not be the cheapest, but they have a comprehensible pricing scheme on their website, and they replied within 12 hours of my request for a quote. They also have a nearly turnkey system—I send them the Gerber files and the Bill of Materials (BOM), and they’ll make the boards, buy the parts, and assemble the boards. They’ll even test them for an additional charge, though these boards are simple enough that I can test them myself at about 5 seconds a board, so their testing would not be worthwhile unless they guaranteed their assembly (which none of the prototype houses can afford to do with untested designs). I also considered Elecrow, which has a similar service, but their pricing information on the web page is rather vague: “For BGA or IC with pads under IC, The quotation will be a little higher.” and “We will give a discount for the PCB assembly service according the some factors (assembly time,Hard or Easy to assemble or requirements etc.).” I prefer sites that have clear pricing even if it is slightly higher, so that there are no surprises. I suppose I could ask Elecrow for a quote and see if they respond as promptly as Smart Prototyping did. Incidentally, my design does not follow all SparkFun’s guidelines—for one thing, I placed parts on a 0.5mm grid, not a 0.005″ gird, and the board is not rectangular. Still, if the design I’m working on turns out well, I might pitch it to them, as I see some potential for it appealing to the open-source hardware market, and the violations of their design guidelines made good sense for this application. Note: I’m deliberately not saying what the design is—I’ll reveal it once I’ve gotten a working prototype, when I’ve decided whether I want to commercialize it or not. ## 2014 July 6 ### Battery connectors Filed under: Uncategorized — gasstationwithoutpumps @ 02:32 Tags: , , , , , , , , I spent a little time today working on my book, but I got side tracked into a different project for the day: designing a super-cheap coin-cell battery connector. I’ve used coin-cell battery holders before, like on the blinky EKG board, where I used a BH800S for 2 20mm CR2032 lithium cells. That battery holder is fairly large and costs over$1—even in 1000s it costs 70¢ a piece. So I was trying to come up with a way to make a dirt cheap coin-cell holder.

The inspiration came from the little LED lights that “glovers” use inside their gloves. They are powered by two CR1620 batteries (that means a 16mm diameter and 2.0mm thickness for the battery). Because the lights have to be made very cheaply, they don’t use an expensive holder, but put the negative side of the batteries directly against a large copper pad on the PC board. The batteries are held in place by the positive contact, which is a piece of springy metal pressing the battery against the board—and each manufacturer seems to have a slightly different variant on how the clip is made.

Unfortunately, I was unable to find any suppliers who sold the little clips—though I found several companies that make battery contacts, it seems that most are custom orders.

My first thought was to bend a little clip out of some stainless steel wire I have sitting around (not the 1/8″ welding rod, but 18-gauge 1.02362mm wire). That’s about the same thickness as a paperclip (which is made out of either 18-gauge or 19-gauge wire), but the stainless steel is stiffer and less fatigue-prone than paperclips. I was a little worried about whether stainless steel was solderable, so I looked it up on Wikipedia, which has an article of solderability. Sure enough, stainless steel is very hard to solder (the chromium oxides have to be removed, and that takes some really nasty fluxes that you don’t want near your electronics). So scratch that idea.

I spent some time looking around the web at what materials do get used for battery contacts—it seems there are three main ones: music wire, phosphor bronze, and beryllium copper, roughly in order of price. Music wire is steel wire, which gets nickel plated for making electrical connections. It is cheap, stiff, and easily formed, but its conductivity is not so great, though the nickel plating helps with that. The nickel oxides that form require a sliding contact to scrape off to make good electrical connection. Phosphor bronze is a better conductor, but may need plating to avoid galvanic corrosion with the nickel-plated battery surfaces. Most of the contacts I saw on the glover lights seemed to have been stamped out of phosphor bronze. Beryllium copper is a premium material (used in military and medical devices), as it has a really good ratio of yield strength to Young’s modulus, so it can be cycled many times without failing, but also has good conductivity.

Since I don’t have metal stamping machinery in my house, but I do have pliers and vise-grips, I decided to see if I could design a clip out of wire. It is possible to order small quantities of nickel-plated music wire on the web. For example, pianoparts.com sells several different sizes, from 0.1524mm diameter to 0.6604mm diameter. I may even be able to get some locally at a music store.

My first design was entirely seat-of-the-pants guessing:

First clip design, using 19-gauge wire, with two 1mm holes in PC board to accept the wire. This design is intended for two CR1620 batteries.

The idea was to have a large sliding contact that made it fairly easy to slide the batteries in, but then held them snugly. Having a rounded contact on the clip avoids scratching the batteries but can (I hope) provide a fair amount of normal force to hold the batteries in place. But how much force is needed?

I had a very hard time finding specifications on how hard batteries should be held by their contacts. Eventually I found a data sheet for a coin battery holder that specified “Spring pressure: 50g min. initial contact force at positive and negative terminals”. Aside from referring to force as pressure and then using units of mass, this data sheet gave me a clear indication that I wanted at least 0.5N of force on my contacts.

I found another battery holder manufacturer that gave a tiny graph in one of their advertising blurbs that showed a range of 100g–250g (again using units of mass). This suggests 1N-2.5N of contact force.

Another way of getting at the force needed is to look at how much friction is needed to hold the batteries in place and what the coefficient of friction is for nickel-on-nickel sliding. The most violently I would shake something is how fast I can shake my fingertips with a loose wrist—about 4Hz with an peak-to-peak amplitude of 22cm, which would be a peak acceleration of about 70 m/s^2. Two CR1620 cells weigh about 2.5±0.1g (based on different estimates from the web), so the force they need to resist is only about 0.2N. Nickel-on-nickel friction can have a coefficient as low as 0.53 (from the Engineering Toolbox), so I’d want a normal force of at least 0.4N. That’s in the same ballpark as the information I got from the battery holder specs.

So how stiff does the wire have to be? I specified a 0.2mm deflection, so I’d need at least 2N/mm as the spring constant for the contact, and I might want as high as 10N/mm for a really firm hold on the batteries.

So how should I compute the stiffness of the contact? I’ve never done mechanical engineering, and never had a statics class, but I can Google formulas like any one else—I found a formula for the bending of a cantilever loaded at the end:
$\frac{F}{d} = \frac{3 E I}{L^{3}}$, where F is force, d is deflection, E is Young’s modulus, I is “area moment of inertia”, and L is the length of the beam. More Googling got me the area moment of inertia of a circular beam of radius r as $\frac{\pi}{4} r^{4}$. So if I use the 0.912mm wire with an 8mm beam I have
F/d = 200E-6 mm E.

More Googling got me some typical values of Young’s modulus:

material E [MPa = N/(mm)^2]
phosphor bronze 120E3
beryllium copper 135E3
music wire 207E3

If I used 19-gauge phosphor bronze, I’d have about 24N/mm, which is way more than my highest desired value of 10N/mm. Working backwards from 2–10N/mm what wire gauge would I need? I get a diameter of 0.403mm to 0.603mm, which would be #6 (0.4064mm), #7 (0.4572mm), #8 (0.5080mm), #9 (0.5588mm), or #10 (0.6096mm), on the pianoparts.com site. I noticed that battery contact maker in Georgia claims to stock 0.5mm and 0.6mm music wire for making battery contacts, though they first give the sizes as 0.020″ and 0.024″, so I think that these are actually 0.5080mm and 0.6096mm (#8 and #10) music wire.

It seems that using #8 (0.020″, 0.5080mm) nickel-plated music wire would be an appropriate material for making the contacts. Note that the loop design actually results in two cantilevers, each with a stiffness of about 4N/mm, resulting in a retention force of about 1.6N. The design could be tweaked to get different contact forces, by changing how much deflection is needed to accommodate the batteries.

How much tweaking might be needed?  I found the official specs for battery sizes (with tolerances) in IEC standard 60086 part 2: The thickness for a 1620 is 1.8mm–2mm, the diameter is 15.7mm–16mm, and the negative contact must be at least 5mm in diameter.  The standard also calls for them to take an average of 675 hours to discharge down to 2v through a 30kΩ resistor (that’s about 56mAH, if the voltage drops linearly, 67mAH if the voltage drops suddenly at the end of the discharge time).  If the batteries can legally be as thin as 1.8mm, then to get a displacement of 0.2mm, I’d need the zero-point for the contacts to be only 3.4mm from the PC board, not 3.8mm, and full thickness batteries would provide a displacement of 0.6mm, and a retention force of about 4.8N.

If I were to do a clip for a single CR2032 battery, I’d need to have a zero-point 2.8mm from the board, to provide 0.2mm of displacement for the minimum 3.0mm battery thickness.

So now all I need to do is get some music wire and see if I can bend it by hand precisely enough to make prototype clips.  I’d probably change the spacing between the holes to be 0.3″ (7.62mm), so that I could test the clip on one of my existing PC boards.

Update 2014 July 6: I need to put an insulator on the verticals (heat shrink tubing?), or the top battery will be shorted out, since the side of the lower battery is exposed.

Next Page »

Create a free website or blog at WordPress.com.