Gas station without pumps

2016 August 18

Ultrasonic rangefinder tests with tiny loudspeaker

Filed under: Data acquisition,freshman design seminar — gasstationwithoutpumps @ 23:31
Tags: , ,

I’m still working on doing the ultrasonic rangefinder project  (In More testing for ultrasonic rangefinder, I gave a digital filter and showed it working with a non-resonant electret microphone and amplifier and pings from a Maxbotix rangefinder.  In Ultrasonic rangefinders arrived, I looked at generating good 40kHz pings while listening to the direct sound with a microphone and amplifier. In Ultrasonic rangefinder without amplifier, I tried seeing if we could use the transducers without an amplifier. In Ultrasonic rangefinder with loudspeaker, I tried using a midrange loudspeaker to generate the pings (but was limited to about 20kHz.)

For the past couple of days I’ve been working with a tiny (10mm) loudspeaker, to see if I could get to higher frequencies without a resonant transducer, so that I could play with doing spread-spectrum pings that can be deconvolved to get more precise and more accurate measurements of echoes. I expected the 8Ω loudspeaker to be much less efficient than a resonant transmitter, but beyond that I had few preconceived notions of how well it would work.

Here is the front of the CDM-10008 10mm loudspeaker.

Here is the front of the CDM-10008 10mm loudspeaker.

Here is the back of the loudspeaker, with the two solder points visible on the bottom.

Here is the back of the loudspeaker, with the two solder points visible on the bottom.

Soldering the leads on was more difficult than I expected. I started out putting the loudspeaker face down on the bench and approaching it with the wire and soldering iron, but the loudspeaker jumped off the bench and stuck to the iron—I’d forgotten that the soldering iron tip really does contain iron, and that the magnet for the tiny loudspeaker is unshielded. After sticking the loudspeaker into a Panavise board holder, I had no trouble soldering on the leads.

Here is the loudspeaker with wires soldered on, and a female header with some double-ended male header pins to make it easier to attach to a breadboard.

Here is the loudspeaker with wires soldered on, and a female header with some double-ended male header pins to make it easier to attach to a breadboard.

The first thing to do (after checking that the leads weren’t shorted) was to measure the impedance as a function of frequency, using a voltmeter, a 100Ω series resistor, and a function generator. I was working at home, so I used a Fluke 8060A multimeter that I bought used on e-bay (which replaced my old 8060A that had failed). Unfortunately, the “new” meter is not much better, as the different voltage ranges seem to have radically different calibration. I used one range consistently for the loudspeaker voltage, and another consistently for the resistor voltage, so the shape of the curve should be ok (up to 300kHz), but |Z| may need to be shifted up or down by as much as 20%.

The resonant peak at 1340Hz is consistent with the datasheet, which specifies 1200Hz with a range from 960Hz to 1440Hz. They specify the power output for the speaker in the range around the resonant peak, which gives an exaggerated view of the response elsewhere.

The resonant peak at 1340Hz is consistent with the datasheet, which specifies 1200Hz with a range from 960Hz to 1440Hz. They specify the power output for the speaker in the range around the resonant peak, which gives an exaggerated view of the response elsewhere.

I tried driving the loudspeaker directly from pins 16 and 17 of the Teensy LC, which I had configured for high drive, with the setup() routine containing


I also put a 10Ω resistor in series with the 8Ω loudspeaker, to limit the current demanded of the I/O pins (though still far more than they are supposed to deliver). With this setup I got about ±1.6V between the pins, ±860mV across the resistor (so ±86mA), and ±670mV across the loudspeaker. The loudspeaker voltages showed spikes, but the resistor voltages were fairly clean square waves, even with 100kHz square waves.

I then made an amplifier for the electret microphone, keeping the gain per stage low to avoid the 1MHz gain-bandwidth limit of the MCP6004 op amps. With a gain of only 10 per stage, I should have a bandwidth close to 100kHz.

Here is the schematic for my test fixture. I looked at the microphone and speaker signals with both my Bitscope oscilloscope and at the microphone signals with the Teensy ADC.

Here is the schematic for my test fixture. I looked at the microphone and speaker signals with both my Bitscope oscilloscope and at the microphone signals with the Teensy ADC.

I started out looking a some complicated pulse patterns that I had designed to have high energy in the 20kHz–50kHz range, but a low autocorrelation other than at 0s. These pulse patterns should be good for the spread-spectrum tests I wanted to make. I was disappointed, however, in not being able to see the patterns in the recordings from the microphone, so I switched to a simpler stimulus—a single short pulse.

Short pulses seemed to trigger a resonance in the loudspeaker at about 9.4kHz, though short pulses resulted in an initial higher frequency mode being excited.

Short pulses seemed to trigger a resonance in the loudspeaker at about 9.4kHz, though short pulses resulted in an initial higher frequency mode being excited.

Each of the plots were made by averaging about 3 dozen traces recorded by the Teensy, to reduce noise. I found that I had to unplug the power supply from the laptop that was providing the USB power, as I otherwise got a lot of 90kHz noise.

I don’t see any resonance around 9.4kHz in the impedance plot, though I admit not looking for narrow resonance peaks in that range. I was a little worried that it might be related to the high-pass filters in the amplifiers which had a corner frequency near there, so I redid the tests with different filters, changing the 330pF to 680pF, so lowering the corner frequency to 4590Hz. The impulse response is much the same:

The signal is a little stronger with the high-pass having a lower corner frequency, but otherwise not changed much.

The signal is a little stronger with the high-pass having a lower corner frequency, but otherwise not changed much.

Note: the signal visible before the sound arrives is probably due to electrical noise from the loudspeaker coupled through the power supply,as it appears as the pulse is shut off.

Unfortunately, this little loudspeaker does not seem to be usable for the spread-spectrum sound production that I had hoped for, as the 9.4kHz ringing is definitely going to corrupt any high-frequency waveform I try to impose.

The ringing the loudspeaker is larger than for the ultrasonic transducer, so we’re actually getting more sound, but the transducer takes much less current, and I’ve not attempted to compare efficiencies.  Both ring for 1–1.5ms, which is too long for what I wanted to do.

2016 March 13

Ultrasonic transmitter pulse shaping

Filed under: freshman design seminar — gasstationwithoutpumps @ 18:45
Tags: , ,

In Ultrasonic rangefinder with loudspeaker, I suggested that non-resonant transducers should be able to “get cleaner deconvolution of the echoes” and last week I wrote a program to try to design a ping that would do that.

  • I wanted the ping to have limited bandwidth (say 20kH–50kHz), so that I did not have to have a transducer that responded to very high frequencies, and so that the ping would not be audible to humans.
  • I wanted the ping to use only {–1, 0, 1} as values, so that it could be easily created with digital outputs from a microcontroller.
  • I wanted a fairly short duration for the ping, so that I could send it, then dedicate the microcontroller to listening for the echo.
  • I wanted the autocorrelation of the ping to have no large peaks after the maximum at τ=0, so that cross-correlating the sent ping with return echo would have (mostly) a single peak for each echo.  The sampling rate for the transmission should be the same as for the receiving, so that cross-correlation is easily computed.

The standard resonant transmitter/receiver with a 40kHz burst does fine on the bandwidth criterion and on the 3-value excitation, and ok on the ping duration.  That is, the ping can be triggered with a short excitation by the microcontroller, but the acoustic signal actually lasts much longer than the excitation signal. The autocorrelation criterion is completely missed, though, as there are strong autocorrelation peaks every 25µs.

I wrote a simple Python program to test the criteria for different excitation waveforms. The waveforms were expressed as patterns of {+1, –1} at 200kHz, which I know is achievable as a sampling rate.  If I can figure out how to set up DMA transfer from the analog-to-digital converter on the Teensy 3.1, then I should be able to use 240kHz, which would be better for comparison with a 40kHz resonant system, since I could then include a 40kHz symmetric ping (repeating 3 high, 3 low) for comparison.

To limit the duration of the ping, I looked only at ones that were exactly 2n samples long (16, 32, or 64, corresponding to 80µs, 160µs or 320µs).

I also looked at the FFT of the ping, and measured the energy within the passband (20kHz–50kHz).

I took the autocorrelation of the ping (by direct computation, rather than using iFFT(|FFT(ping)|2) ), and looked at the magnitude of the largest peak other than the one at τ=0.  The autocorrelation was scaled so that the 0-peak had magnitude 1.

Simple pings (like 5 periods of a 33.33kHz square wave) perform very well by the band-pass measure, but poorly by the autocorrelation measure (shifting over by one period results in a correlation peak that is 4/5 as big as the peak at 0).

I tried a few hand-designed pings, with very bad autocorrelation results, so I switched to making random pings, starting with +1 and having equal numbers of +1 and –1 (to avoid a DC component to the ping, which would have produced an audible click). I then did iterative improvement by swapping random pairs of values in the ping, checking an objective function that was a linear combination of the autocorrelation peak and the bandpass energy.  I found several good solutions this way, with different tradeoffs of energy outside the desired band and the size of the autocorrelation peak.  Changing the boundaries of the band also results in different solutions.  Here are few examples for 20kHz–50kHz, with a 160µs burst:

 [ 1., 1., 1., 1.,-1.,-1.,-1., 1., 1.,-1.,-1., 1., 1.,-1.,-1., 1., 1., 1.,
  -1.,-1.,-1.,-1., 1., 1., 1.,-1.,-1., 1., 1.,-1.,-1.,-1.]
#  bpe= 0.44538406194
#  max autocorrelate= 0.28125

 [ 1., 1.,-1.,-1., 1.,-1.,-1., 1., 1., 1.,-1.,-1., 1., 1.,-1.,-1., 1., 1.,
  -1.,-1., 1., 1., 1.,-1.,-1.,-1., 1., 1., 1.,-1.,-1.,-1.]
#  bpe= 0.41363760532
#  max autocorrelate= 0.1875

 [ 1., 1., 1.,-1.,-1., 1.,-1.,-1., 1., 1., 1.,-1.,-1., 1.,-1.,-1.,-1., 1.,
   1., 1.,-1.,-1.,-1., 1., 1., 1.,-1.,-1., 1., 1.,-1.,-1.]
#   bpe= 0.405535884864
#   max autocorrelate= 0.15625

Once I get a speaker that can produce some output up to 50kHz, I’ll try seeing what the signal looks like for these spread-spectrum pings.  I suspect that the low-pass filtering of the speaker and the microphone will result in a ping that looks very little like the excitation waveform, and that I’ll have to work a bit on coming up with a different strategy for producing a ping that I can cheaply deconvolve.

Ultrasonic transmitter impedance

Filed under: freshman design seminar — gasstationwithoutpumps @ 13:00
Tags: , ,

Continuing the series  Ultrasonic rangefinder project , More testing for ultrasonic rangefinderUltrasonic rangefinders arrivedUltrasonic rangefinder without amplifier, and Ultrasonic rangefinder with loudspeaker I tried measuring the (magnitude of) impedance of the transmitter in the same way that I measured loudspeakers.  That is, I put the transmitter in series with a resistor, and drove the pair from a function generator, measuring the voltages across the transmitter and the resistor simultaneously with a pair of voltmeters.  I did this in the circuits lab, so that I could use the high-quality multimeters and function generators there—I no longer have a multimeter at home that is good at high frequencies.

I did not have my laptop handy while I was making the measurements, so I recorded them on paper and typed them up later.  It would have been good to have plotted the data as I collected it, so that I could get more points in  regions where there was rapid variation in impedance.  I’ll probably have to go back to the lab later this week and collect another data set, with much finer spacing between 30kHz and 70kHz.

The transmitter behaves like a capacitor of 1.76nF at low frequency, and 1.36nF at high frequency. Near the resonance, things get complicated. Unlike the inductive loudspeaker, where impedance goes up at the resonance, the capacitive transmitter has decreased impedance at the resonance. [Update:2016 March 15, fixed the capacitance from µF to nF.]

I used a 100Ω series resistor, arbitrarily chosen.  In retrospect it would have been better to use a 2.2kΩ resistor, to more closely match the impedance of the transmitter in the region of interest between 30kHz and 70kHz.

There isn’t a single resonance at 40kHz, like I expected, but three resonances (maybe more), around 39.2kHz, 42kHz, and 55KHz.  There seems to be an antiresonance around 43 kHz.  The multiple resonant frequencies are probably due to different vibration modes, and may account for some of the difficulty in getting a short burst produced by the transmitter—even if I can cancel one mode, there is another mode still being somewhat excited.

The first resonance is around 39.2kHz, which is probably in spec (not that these cheap transmitters have data sheets that I can access—more expensive ones are generally 40kHz±1kHz for the resonance).  At the resonant frequency, the impedance is about 610Ω, so a ±3.3V swing would require ±5.4mA.  (Note: since my measurements were not very closely spaced here, I may have missed the peak, which could be as low as 500Ω.)

The digital output pins of the Teensy 3.1 board I’m using for the rangefinder are only specified to 2mA (except a couple of high-drive pins, which I’m not using).  Using inverters with 5V power to drive the transmitter would need  8.2mA, but the inverters I have are only specified to 4mA, so I might want to use two or even three in parallel for each pin of the transmitter.

Of course, the measurements I made were for steady-state frequency response, not the response for starting the transmitter moving from being motionless—there may well be a different impedance that is relevant then (I suspect that more current may be needed when the transmitter isn’t already moving at the resonant frequency).

2016 February 17

Ultrasonic rangefinder with loudspeaker

Filed under: Data acquisition,freshman design seminar — gasstationwithoutpumps @ 23:29
Tags: , ,

Continuing the series Ultrasonic rangefinder project , More testing for ultrasonic rangefinderUltrasonic rangefinders arrived, and Ultrasonic rangefinder without amplifier, I tried today to look at creating pings with a non-resonant transmitter: a cheap, mid-range 8Ω loudspeaker that I’d used for the applied electronics class.  It was a buyout special from Parts Express, and so is no longer available.  There is an analysis of this speaker (or another one like it) in Better model for loudspeaker.

I was curious whether I’d be able to get it to produce sound at 40kHz, so I hooked it up to a pair of output pins of the Teensy 3.1 and used the microphone and preamplifier to listen to it with the Teensy, as in Ultrasonic rangefinders arrived.  The results were disappointing (as I expected).  The loudspeaker made an audible click, but the waveform showed no evidence of 40kHz signal, even with 10 cycles of excitation. I got echos, but they were of the click rather than of a ping, and were essentially independent of how many cycles of excitation I provided.

I then tested the loudspeaker and microphone combination with my FG085 function generator, and saw that the amplitude of the response varied enormously with frequency (and that some of the largest responses were ones I couldn’t hear—my deafness does not seem to be uniform in the higher frequencies).  There are zeroes around 21750Hz and 28500Hz, and no signal above 31750Hz.  The microphone and preamp were still working at 40kHz, so the problem is with the loudspeaker, not the mic or preamp.

I should probably get a cheap little speaker that is rated to 20kHz, and see whether it can actually go to 40kHz.  Digikey has some $1 and $2 speakers that look suitable, except that they seem to be designed to be pressed against a PC board with a spring, which might make them hard to connect to a breadboard.  For about $3, I could get one with pins, but the high-frequency response seems not as good.

I could also try making a pinger at 20kHz, instead of 40kHz, and see whether I can get decent pulse shapes with the existing speaker.

I managed to get a 20kHz ping recorded from the loudspeaker, but I had trouble getting a clean ping, as there was always echo off the floor, my hand, or the tabletop (whatever was supporting the loudspeaker) producing another burst very soon after the first one, interfering with it. I tried separating the mic and loudspeaker to record the direct wave (without much echo), but that was still unclean. I think I need to have a good baffle to make a clean pulse, and a directional mike would be better than the omnidirectional one I currently have.

Here is a sample recording with the loudspeaker putting out 5 cycles (10 half cycles) at 20kHz and a bounce off the bottom of my table.  The messiness of the return echo is partly interference from bounces off the floor behind the mic and speaker, and partly the unevenness of the bottom surface of the table (which is made of aluminum slats).

The burst begins almost exactly when I would expect it to, but it is not as clean as I would like to see.

The burst begins almost exactly when I would expect it to, but it is not as clean as I would like to see.

I think that with non-resonant transducers I could get cleaner deconvolution of the echoes, but first I have to find a way to reduce the multi-path problem (perhaps with a directional mike and a baffled speaker?).

2015 May 5

First op-amp lab was quick

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

On Monday I provided a little feedback on the design reports for the electrode lab.  The big issues were

  • Students not reporting the models they were fitting to the data.
  • Students not reporting the parameters of the fits after doing the fitting.
  • Students choosing overly complicated models (like R+(R||C) for data showing constant impedance)
  • Students not modeling important phenomena (like the (R||C) input impedance of the voltmeters)

Little issues included

  • Using “due to the fact that” rather than “because”
  • Omitting leading zeros before a decimal point.  Numbers should never start with punctuation.

After that brief intro, I worked with the students to develop a block diagram for an audio amplifier using the electret microphone and loudspeaker that they had already characterized.  This had been part of their homework, but I expected them not to have really grasped the point of a block diagram.

Another thing I went over in class, because I’d seen problems with it in previous reports and prelabs ,was reminding students that V=IR is not a ritual magic incantation. Reciting it doesn’t make solutions to problems right, if it is just randomly applied.  I reminded them that the voltage has to be across the resistor that the current is through—picking random voltages or currents in the circuit is meaningless.  I showed them an example taken from the prelab they were turning in at the end of class.

When I did the grading for the prelab homework Monday night, I saw that many of the students managed to copy the block diagram we had done in class, but none had appropriately labeled the signals between the blocks.  I think I need to provide some more and better examples in the book.  (Ah, I see I already have marginal notes to myself to add a couple in Chapter 2.)

The V=IR error was very common, mostly with V was taken to be the power supply voltage, rather than the voltage across the resistor that biases the microphone.

Students also had a lot of trouble with computing the AC voltage of the signal out of the microphone, based on the loudness of the sound input and the sensitivity of the microphone. I knew this was a difficult assignment, but I thought that it would be relatively easy, because they had supposedly already created a worksheet for themselves as part of Lab 4 (the microphone lab).  Either they forgot everything they learned there, or they never really got the idea of the worksheet they created.  One student asked in class on Monday, quite reasonably, for a worked example.  I’m going to have to come up with one that doesn’t just do all the work for them—I know these students can fill out worksheets, but what I need to get them to do is to solve problems when the steps aren’t all set out for them.

The afternoon lab section (many of them working together) did much better on the prelab than the morning section—the difference between the sections has been noticeable from the beginning, but it seems to be getting bigger, not smaller.  For some reason the descaffolding is working better with the smaller section.  Individuals in the morning lab are doing quite well, but there are more floundering students in that section, and I don’t know how to get them back on track.

Even though the morning lab is struggling more than the afternoon lab, I think that both are doing better than previous year’s classes at this point of the quarter.  With only one or two exceptions, everyone in both lab sections got their op amp circuit designed, wired, and demonstrated within the 3-hour class period.  That means that Thursday’s lab can be a tinkering lab for most of the students, where they can try various ways of improving the design:

  • Switching from a symmetric dual power supply to a single power supply.
  • Paralleling two op-amp chips to get twice the current capability.
  • Adding a potentiometer for variable gain.
  • Adding a unity-gain buffer to separate the loudspeaker driver from the gain amplifier.
  • Adding a tone-control circuit, like the Baxandall tone control on  They can’t use exactly that circuit, as they have only 10kΩ potentiometers, not 100kΩ ones.  The idea can be adapted, or the students could do simple treble-cut or bass-cut circuits.
  • Using a loudspeaker as a microphone. I think that should work, as I get about a 500µV signal from my loudspeaker when I talk into it.  The don’t need any DC bias for the loudspeaker mic, and they may even be able to eliminate their high-pass filter, as the loudspeaker mic can be set up to have its output already centered at 0V.

I’ll talk about some of these possibilities in class tomorrow (plus stroking the students a bit about getting the lab done quickly). I attribute he good performance on the lab to them having put in more time on the prelabs, even if they didn’t get the answers to the questions exactly right.  Thinking about the design ahead of time (and getting a little feedback) goes a long way toward clearing up confusion they have had.

There are 4 more amplifier labs coming:

  • Instrumentation amps with a strain-gauge pressure sensor (measuring breath pressure and blood pressure using an arm cuff).  Will need to be 2-stage, since the INA126PA chips we are using aren’t rail-to-rail amplifiers.
  • Transimpedance amplifier fora photodiode to measure pulse.  This will also need to be multistage, since the first stage will have to have limited gain to avoid saturation.  After high-pass filtering much more gain will be needed.
  • Class-D power amplifier.  This is always the toughest lab of the year.  Even small mistakes can result in shoot-through current that gets the FETs hot enough to melt the breadboards (I have two breadboards that I’ve melted holes in).
  • EKG using only op amps (making their own 2-op-amp instrumentation amp, plus high-pass filtering and a second gain stage.  They’ll be using all 4 of the op amps in the quad op amp package for this amplifier.

I’m about a week behind on grading redone assignments—weekends are spent grading design reports, Monday nights grading prelabs, weekends plus Tuesdays adding to the book a chapter ahead of the students, and I squeeze in the redone assignments Wednesday or Thursday night, if I don’t crash too early.

« Previous PageNext Page »

%d bloggers like this: