# Gas station without pumps

## 2013 September 3

### Towards automatic measurement of conductivity of saline solution

I’ve been thinking about a more automatic way to measure the conductivity of a saline solution than what I reported in Better measurement of conductivity of saline solution and Conductivity of saline solution.  The original lab is suitable for the circuits class, because it measures with sine waves and models the impedance of the electrodes, but it requires a sine-wave oscillator and an AC voltmeter that can handle high frequencies—neither of which makes for a low-cost device.

I was thinking that one could make a fairly simple device using the Freedom KL25Z board and a few extra components:

Bias circuit and load resistor for making a conductivity meter.

The idea is a simple one—instead of using a sine wave to drive the electrodes, use a square wave directly from the KL25Z. Connect the other electrode through a series resistor to a voltage centered between the two square-wave values, and use the 16-bit analog-to-digital converter to read the signal between the resistor and the electrodes just before changing the square-wave value.

With a low frequency square-wave, the electrodes will act like a resistor, but much of the resistance will come from the insulating film on the electrode, rather than the solution. At high frequencies, the capacitance of the insulating file will not have time to charge and discharge, and the resistance of the electrodes will depend mainly on the conductivity of the solution. At high enough frequencies, the output waveform will look like a triangle wave, rather than a square wave, and the amplitude of the signal will be proportional to $\frac{R_{3}}{R_{S}+R_{3}}$, where R3 is the pull-down resistor in the diagram, and RS is the resistance of the solution. That means that $R_{S} \propto R_{3}(1/A - 1)$, and the conductance can be computed as the inverse of resistance. The measured value depends, of course, on the size and spacing of the electrodes, so one would have to calibrate with a known conductivity solution to get the proper scaling.

I looked at the speed of the analog-to-digital converter on the KL25Z board, and they claim that they can get 16-bit conversion (though only with 12-bit accuracy, really) at 460k samples/sec—though I’ve not figured out the settings that really permit that. Higher accuracy is possible by averaging successive samples (which there is hardware support for), up to about 14.5 effective bits (averaging 32 differential samples, at a maximum rate of about 7.2kHz). By doing the averaging in software instead of hardware, we could run with a square-wave input up to about 90kHz (single-ended 16-bit samples at 180k samples/second seems to be fairly easy to set up). I think that is likely to be fast enough for all but the highest ionic concentrations, even using a very polarizable electrode like the 316L stainless steel ones we used for the Applied Circuits lab. One could check this by sweeping the frequency up, and seeing whether the estimate for RS converges.

I’ve not tried building and testing this idea yet, because the Arduino boards have too slow and too low-resolution A-to-D converters, and my son is hogging the Freedom KL25Z board for his light glove prototype. (I guess I need to get another copy of the board).

I don’t think I’ll be using this design in the Applied Circuits course (it is not suitable for teaching about modeling with linear components), but it might be a useful design for the freshman design seminar, or even for doing a titration lab in my son’s AP chem class. I understand that a standard lab is to titrate barium hydroxide with sulfuric acid, since the two reactants have conductive ions, but the barium sulfate precipitates out and the solution is essentially non-conductive when the two are perfectly balanced. The conductivity should form a nice “V” plot as sulfuric acid is added to a barium hydroxide solution—the units don’t even matter, since we just want to know what amount of sulfuric acid need to be added to attain the minimum, not what the conductivity is at the minimum.

To make a useful conductivity meter for something like AP chem, I’d need a much smaller probe that the pair of electrodes I used in the Applied Circuits class. I think I could make a decent probe out of a piece of stainless steel tubing and a piece of the 316L welding rod, if I could come up with a good way to hold them together concentrically, make sure they were always immersed to the same depth, and keep any wires to the rod and tube out of the solution. This might be a good problem for the freshman design seminar.

## 2013 July 31

### Microphone sensitivity exercise

Filed under: Circuits course — gasstationwithoutpumps @ 13:46
Tags: , , , ,

I’ve been thinking a bit about improving the microphone lab for the Applied Circuits course.  Last year, I had the students measure DC current vs. voltage for an electret microphone and then look at the microphone outputs on the oscilloscope (see Mic modeling lab rethought).  I still want to do those parts, but I’d like to add some more reading of the datasheet, so that students have a better understanding of how they will compute gain later in the quarter.

The idea for the change in this lab occurred to me after discussing the loudness detector that my son wanted for his summer engineering project.  He needed to determine what gain to use to connect a silicon MEMS microphone (SPQ2410HR5H-PD) to an analog input pin of a KL25 chip.  He wanted to use the full 16-bit range of the A-to-D, without much clipping at the highest sound levels. Each bit provides an extra 6.021dB of range, so the 16-bit ADC should have a 96.3dB dynamic range.  The sound levels he is interested in are about 24dB to 120dB, so the gain needs to be set so that a 120dB sound pressure level corresponds to a full-scale signal.

He is running a 3.3v board, so his full-scale is 3.3v peak-to-peak, or 1.17v RMS (for a sine wave).  That conversion relies on understanding the difference between RMS voltage and amplitude of a sine wave, and between amplitude and peak-to-peak voltage. The full-scale voltage is 20 log10(1.17), or about 1.3dB(V).

Microphone sensitivity is usually specified in dB (V/Pa), which is 20 log10 (RMS voltage) with a 1 pascal RMS pressure wave (usually at 1kHz).  The microphone he plans to use is specified at –42±3dB (V/Pa), which is fairly typical of both silicon MEMS and electret microphones.The conversion between sound pressure levels and pascals is fairly simple: at 1kHz a 1Pa RMS pressure wave is a sound pressure level of about 94dB.

Scaling amplitude is equivalent to adding in the logarithmic scale of decibels, so for a sound pressure level of 120dB, the microphone output would be about 120–94–42±3=–16±3dB(V), but we want 1.3dB, so we need a gain of about 17.3dB, which would be about 7.4×. Using 10× (20dB gain) would limit his top sound pressure level to 117dB, and using 5× would allow him to go to 123dB.

One can do similar analysis to figure out how big a signal to expect at ordinary conversational sound pressure levels (around 60dB):  60–94–42=–76db(V).  That corresponds to about a 160µV RMS or 450µV peak-to-peak signal.

I tried checking this with my electret mic, which is spec’ed at –44±2dB, so I should expect 60–94–44±2=–78±2dB, or 125µV RMS and 350µV peak-to-peak. Note that the spec sheet measures the sensitivity with a 2.2kΩ load and 3v power supply, but we can increase the sensitivity by increasing the load resistance.  I’m seeing about a 1mV signal on my scope, so (given that I’m not measuring the loudness of my voice), that seems about right.

I’ll have to have students read about sound pressure level, loudness, and decibels for them to be able to understand how to read the spec sheet, so these calculations should be put between the microphone lab and the first amplifier lab.  I’ll have them measure peak-to-peak amplitude for speech, and we’ll compare it (after the lab) with the spec sheet.  This could be introduced as part of a bigger lesson on reading spec sheets—particularly how reading and understanding specs can save a lot of empirical testing.

## 2013 July 6

### Disseminating the applied circuits labs

Filed under: Circuits course — gasstationwithoutpumps @ 11:41
Tags: , , , , , ,

The post I just published about academic conferences lead me to thinking (again) about how I should disseminate my course design (or individual lab designs) for the Applied Circuits course.  I suppose I should write up a paper and submit it to a conference or some journal like the Journal of Engineering Education.

One problem is that my course designs are not education research—they are attempts to solve particular curricular problems by taking advantage of my strengths as a teacher.  Some of the course design generalizes to other teachers and other institutions with somewhat different curricular needs, but there is no controlled experiment to say that my course design is “better” than another is some predefined, measurable way.

I’m not sure where this sort of here-are-some-good-ideas-you-may-be-able-to-use course design work fits in academic publishing.  If I were teaching physics, I would probably submit to The Physics Teacher, but I don’t know what the closest equivalent is in engineering—particularly interdisciplinary stuff like teaching circuits to bioengineers.  There don’t seem to be good journals intended for disseminating instructional labs and curricular design. Maybe Advances in Engineering Education would be a better fit than Journal of Engineering Education, even if I don’t feel that my course design contains “significant, proven innovations in engineering education practice, especially those that are best presented through the creative use of multimedia.”

Of course, distilling down the 200–400 pages of notes on my circuits course that I’ve collected on this blog to a conference presentation or a journal article is a daunting task—one that I’ll probably keep putting off until it is so stale that even I’m not interested in it any more.  It might even be easier to turn the notes into a book than into an article, since I would not have to do 100-to-1 compression.

I’m not sure who the right audience for such a book would be—instructors trying to create a new course, students taking my course, hobbyists wanting to learn the material at home, … ? That is, should I be writing about a case study in course design, should I be trying to create a textbook for the course, or should I be trying to put together a self-study book that could accompany a kit of parts for people to learn electronics at home?

Again, the book project is big enough that I’d probably keep putting off indefinitely.  If I was sure there was an audience, I’d be more inclined to put in the effort to disseminate the material beyond this blog, though.

Another approach for disseminating the course materials would be to put together stand-alone kits for each lab (with detailed tutorials) that could be sold independently.  Releasing one lab at a time would be a more incremental effort than doing all 10 labs in one package, but would require some redesign, both for reduced expectations of lab equipment and to make the kits more modular.

I suspect that one could do most of the experiments of the circuits course for about $360 in lab equipment and tools, using something like the Velleman Lab2U unit (which PartsExpress sells for$210), a $40 multimeter, a$17 soldering station, an Arduino, and the $66 bag of tools and parts I put together for the course. The Lab2U is only a single power supply, so some of the projects that used a multiple supply would need to be redesigned—most notably the class-D power amp. Unfortunately,$360 is too big a chunk of money for anyone but a dedicated hobbyist, who quite likely already has most of the needed equipment.

Making the kits more modular might be difficult. For example, many of the labs require students to choose resistors and capacitors from a large set of possibilities, since their lab kit contained 10 each of 112 different resistors and 10 each of 25 different ceramic capacitors.  It is easy to justify the cost of those parts spread over 10 labs, but harder to provide that much selection for a single lab.  Perhaps one would have to sell a core kit (with breadboard, resistors, capacitors, …) to use with the Arduino and add-on kits for each lab.  The core kit would need to have some fundamental experiments (like RC time constants), so that it would be instructional even without add-ons.

I wonder if there is a market for such lab kits, and how I would find out if there were a market (without sinking months of my time and thousands of dollars). I wouldn’t want to assemble or market the resulting lab kits either, but would want to distribute them through a company like Sparkfun electronics, Adafruit Industries, or Seeedstudio, who have already set up the necessary business infrastructure.

I also wonder whether I’m capable of writing the tutorials at an introductory enough level to work for hobbyists, while still covering enough of the theory.  I’ve never cared for kits that have great assembly instructions, but treat the way the things works as too difficult for the purchaser of the kit.

Writing instructions that included the use of an oscilloscope or multimeter, when there are many different ones that the person may be trying to use, would be a very challenging task.  Oscilloscopes in particular have evolved to have many radically different user interfaces, some of which are very complicated.

Also, all my writing has been for well-educated people: college professors, university students chosen from the top 10% of high school students, my loyal blog readers, … .  Can I make my writing intelligible for an average, or slightly above average, high school student, without sounding condescending or patronizing?  From the rather unsuccessful attempts I’ve seen in kit instructions in the past, that is not an easy task.

## 2013 July 4

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

About the only thing I can think of is that there is too large a DC offset between the EKG electrodes, as the Blinky EKG uses a large gain on the first stage and a relatively small gain on the second stage.  The DC-blocking high-pass filter is after the first stage. The EKG built on the protoboard used a smaller first-stage gain and larger second stage gain, so wouldn’t saturate the first stage as easily.  (I’d learned more about EKG electrodes by the time I’d designed that circuit.) I could fix the gains by changing a few resistors on the EKG blinky board, which may be worth the pain of unsoldering and resoldering resistors.  That may be worth trying today.

I finally got a chance to test that this afternoon.  I replaced the 470Ω Rgain resistor on the instrumentation amp with a 12kΩ resistor, reducing the first-stage gain from 175.2 to 11.667.  With this change, I could see my heart beat with no problem, if I turned the second-stage gain all the way up to 111, as high as the trimpot would let me go.  This gain was not enough to light the LED, though, so I replaced the 1kΩ resistor below the trimpot with a 100Ω resistor, which allows the second-stage gain to be adjusted from 10.9 to 1101.  The combined gain is thus adjustable from 127.2 to 12845.

UPDATE: 2013 July 5.  I realized this afternoon that I would have been better off leaving the 1kΩ resistor alone, and changing the 100kΩ resistor above the trimpot from 100kΩ to 510kΩ, giving me a second-stage gain varying from 47.36 to 521, and a total gain of 552.6 to 6078.

At high gain, the LED is always on, and at low gain the LED is always off, but when the gain is around 2300, the LED blinks nicely and the waveform recorded with the Arduino data logger is good.

I believe that the problems I’ve been having with the Blinky EKG board have been the result of DC bias in the EKG electrodes saturating the first stage, so reducing the gain of the first stage and increasing the gain of the second stage was the right fix. I’ve been thinking of redesigning the blinky EKG board to be more decorative (so that it could be worn as a pin or a pendant)—if I do that, I’ll certainly change the gain.

### Blinky EKG hard to debug

Filed under: Circuits course — gasstationwithoutpumps @ 11:46
Tags: , , , , , , , ,

I’ve been having a frustrating couple of days trying to debug the Blinky EKG.  It worked when I first built it, but every time I’ve tried to demo it, the demo has failed, and I couldn’t get it working even at home on Tuesday.  I have another, very similar EKG circuit that I built on my instrumentation amp protoboard, which has worked fine every time I’ve tried to use it.

There are a few differences between the circuits (the blinky EKG is battery powered, for example, has an LED load on the final output, and has a trimpot for adjusting the gain of the second stage), but none that explain to me the difference in performance.

On Tuesday my experiments were limited to hooking up one or the other of the EKG boards and using an oscilloscope or Arduino data logger to observe the outputs or various internal signals.  Using the EKG board that worked convinced me that the EKG electrodes were providing a good 1mV signal (that had been a problem in the circuits course, as many students got EKG circuits that worked with electrodes on me, but no electrodes on themselves—we never figured out exactly why).  But I could not get anything from the blinky EKG—even the output of the instrumentation amp seemed to be constant.  I suspected that I had fried the amplifier chip, and was considering unsoldering it and putting in a new one.

Yesterday, I tried a different test, making an artificial input source, using resistors and my Elenco FG-500 function generator.

Test fixture for the EKG blinky board. Note that with a 10V peak-to-peak oscillator input, the output would be a differential signal of about 1.8mV peak-to-peak. The diagram was drawn with Digikey’s SchemeIt.

With this test fixture, I convinced myself that the Blinky EKG board was amplifying the differential input signal correctly, over a range of about 1Hz to 40Hz, as long as the resistor for setting the DC bias was under about 300kΩ. Even with a 3.3MΩ resistor, I could see the output signal, but there was a fair amount of 60Hz noise added to it.  The gain was adjustable with the trimpot, but was high enough at all settings that I should be able to see EKG signals at the output clearly with the Arduino data logger—the gain control is mainly to get the LED to blink appropriately.

One effect I should have anticipated, but did not, was that the bias voltage showed a large change every time the LED turned on. If I redo the EKG Blinky design, I’ll probably use a voltage reference (like the TL431ILP) rather than just a voltage divider for the input to the Vbias op amp, and the LED will not be powered from the Vbias line.

In any case, the Blinky EKG board seems to be working as intended as an amplifier, and I’m still a bit mystified why it is not working when connected to the EKG electrodes.  About the only thing I can think of is that there is too large a DC offset between the EKG electrodes, as the Blinky EKG uses a large gain on the first stage and a relatively small gain on the second stage.  The DC-blocking high-pass filter is after the first stage. The EKG built on the protoboard used a smaller first-stage gain and larger second stage gain, so wouldn’t saturate the first stage as easily.  (I’d learned more about EKG electrodes by the time I’d designed that circuit.) I could fix the gains by changing a few resistors on the EKG blinky board, which may be worth the pain of unsoldering and resoldering resistors.  That may be worth trying today.

Note: I’m starting to use DigiKey’s SchemeIt for schematic capture, rather than Circuit Lab. There are a lot more symbols available in SchemeIt, and the user interface is fairly similar.  SchemeIt does not have simulation capabilities, but CircuitLab’s never worked for me anyway. SchemeIt’s  drawing is a bit cruder—they’ve not taken care to make sure that wires and components line up perfectly in the PNG output, but is better than Eagle‘s.  Best of all, I know how DigiKey monetizes their schematic capture system: you can turn the Bill of Materials (BOM) into a DigiKey order with a couple of clicks, so I have no expectation that they will start charging for SchemeIt.  I may even use the ordering capability in the way they intend, since I order from DigiKey fairly frequently already.

Next Page »