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

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.

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

    CORE_PIN16_CONFIG |= PORT_PCR_DSE;
CORE_PIN17_CONFIG |= PORT_PCR_DSE;


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.

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.

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.

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 26

### Oscilloscope tutorial video

Filed under: Circuits course,freshman design seminar — gasstationwithoutpumps @ 23:08
Tags: ,

I’ve released an intro tutorial on using the digital oscilloscopes in the lab:

The tutorial is fairly short (12 minutes, 23 seconds), and so only covers the basics of using the oscilloscope, not the myriad of features that the scopes in the lab have.

Incidentally, it took us about 2 hours to shoot the video, 2 hours for me to edit it, 2.5 hours to render it, and 5 hours to upload it to youtube.  (I would have uploaded it to Vimeo, where I already had an account, but they limit non-paying customers to 500MB a day, and the 1080p video was 1.6GB—it’s not worth paying \$10 a month to upload one video.)

I’ll probably do more videos this summer, if students find this one useful, but since the production takes about 50 times the running time, don’t expect a lot of videos from me!

## 2016 March 15

### Ultrasonic transmitter impedance again

Filed under: freshman design seminar — gasstationwithoutpumps @ 23:28
Tags: ,

Today I had to wait several hours in the lab for the freshman design seminar students to finish their designs, demo them, and turn in reports.  Only the two LED cubes demoed their projects: the pulse monitor group had left their hardware in the lab last week by mistake, and it was gone; and the ultrasonic rangefinder group did not have the member with the software present—I’ll have to see if their report tells me how far they got.

Because I had to spend a lot of time in the lab today, I decided to redo the work mentioned in the post  Ultrasonic transmitter impedance. That is, I tried measuring the (magnitude of) impedance of the transmitter at different frequency ranges, by measuring the voltage across the transmitter and across a series 2.2kΩ resistor at different frequencies.  This time I had my laptop with me, and I plotted after every few measurements, so that I was careful to fill in frequencies whenever the impedance deviated from a simple capacitance.

The documented 40kHz resonance is around 39.78kHz, with another large resonance around 55.4kHz. There were also antiresonances and some minor other resonances.

The antiresonances around 42kHz and 56.5kHz are indicative of a coupled system—for the transmitter, the 39.78kHz, 42kHz, 55.4kHz, and 56.5kHz are probably different vibrational modes of the piezoelectric diaphragm.

Zooming in on the interesting region reveals some weird behavior in addition to the major resonances and antiresonances.

One interesting observation was that the weird dip at 59.3kHz had hysteresis—if I approached it from below, I got the dip and it continued to about 59.4kHz, but if I approached it from higher frequencies, I could extend the capacitive line all the way back to 59.3kHz.  I’ve no explanation for that yet.

I could probably do a better job of measuring at the extreme frequencies if my reference impedance were a 1nF or 2.2nF capacitor, since the voltage ratios would then be around 1 for most frequencies, and only being about a factor of 4 off at the resonances and antiresonances.  The 50Ω output impedance of the function generator would not really be a problem until we got over a MHz, since the corner frequency would be 3.8MHz with a 1nF load.  Of course, the capacitors I have are not very high precision, so I get more accurate measurements with resistors, even when the voltage ratios get fairly extreme.

I keep feeling that I should be able to use the magnitudes of the AC voltages to get the phase of the impedance (except for the sign), but all my attempts so far have resulted in mostly nonsense.  At the resonances and anti-resonances the impedance appears to be purely real (that is, the voltages add up to about the same value as the $\sqrt{a^2+b^2}$ for the low and high frequencies, where the transmitter is capacitive).

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

« Previous PageNext Page »