MHz Speed Analog Reading + High Quality 40kHz Square Wave

Hi folks!

I have an idea for an optical alignment tool that requires a high-resolution distance sensor. I thought that maybe I could achieve this with ultrasound transducers, by looking at the travel time from a sender to a receiver. The idea is really straightforward, but the catch is that I would need to be sampling a 40kHz sine wave at a minimum of 3MHz for the resolution required. I just peeked around a bit, and got the impression that the fastest the Arduino can sample an analog signal is about 10kHz. I don't actually need the data streaming or in real time--I just need to send a pulse, time that really precisely, then look at the reaction it creates in a receiver (sampled at 3MHz), and send all that data to my Arduino or computer for processing. I've included an extremely scientific diagram to show this in visual form:

Can I do this with some external components that buffer the data and send it to the Arduino at a speed it can handle? Are there other electronic solutions I should be considering entirely?

10kHz is the limit with the Arduino unless you want to go off-piste, when higher speeds with lower resolutions are possible.
Comparators and zero-crossing detectors can be useful techniques for higher resolution ultrasonics, as can external high speed clocks.

Perhaps you should rethink your thread title?

Thanks AWOL--I just changed my title to make the analog read speed I'm looking for clearer. Off-piste has to do with changing the way the core clock frequency is divided, right? Can I get the three orders of magnitude increase I'm looking for by doing this? I don't need huge resolution on my reading (I think 8-bits would be plenty). I'm going to look up "comparators", "zero-crossing detectors" and external clocks now.

I'm still unclear where the clean 40MHz square wave comes in.
Is it something to do with the three orders of magnitude?
You divide the 40MHz by 1000?

I need a clean 40khz square wave to power the "sender" transducer. I had just assumed that I could do this by basically "blinking" one of my output pins at this frequency--but I realized earlier today that that didn't work at all. It looks like this might work: Arduino Playground - Timer1 but I still need to try it.

I noticed that some other people were suggested somehow getting the PWM to do this. Regardless, I assume this is a pretty trivial task compared to the high speed analog reading, so what I'm really trying to get a pulse on here is whether there is some reasonable technique I can use to sample an input at that frequency.

The three orders of magnitude I was referring to was from 10kHZ (the fastest stock analog read speed of the Arduino) to ~3MHz (the speed I need to sample my signal at). I guess that's technically closer to two orders of magnitude, to be precise.

I need a clean 40Mhz square wave to power the "sender" transducer

Even if an Arduino could generate a 40MHz square wave, "clean" or not, no ultrasonic transducer can respond to a frequency that high.

I don't need huge resolution on my reading (I think 8-bits would be plenty)

Could you at least try to make sense? Sampling a 40kHz sine wave at 40MHz or even 3MHz with 8-bit resolution is pointless.

Pete

no ultrasonic transducer can respond to a frequency that high.

I think medical ultrasound goes up to around 20MHz, but you're unlikely to want to afford one of those.

Whoops, just a mistype there supremo--I meant a 40kHz square wave--like in the diagram. I can't believe I missed that in the title.

I do stand by the 8-bit resolution being sufficient, though. My idea is to determine at what point the wave peaks, thus allowing me to be able to compare the peak of the square wave that created the sound to the peak of the corresponding sine wave in the receiver.

I've looked at the transducer receiver output on an oscilloscope, and it's a clean, symmetric sine wave, so I was thinking that I may even be able to deal with a lower sampling resolution (say 400kHz instead of 3MHz) if I could reconstruct the sine wave in code and calculate the location of the peak.

You are making things confusing by mixing 40 MegaHertz and 40 kiloHertz.
Arduino only runs at 16 MHz; sampling at 3 MHz is not possible without using an external highspeed ADC, and creating a 40 MHz source is also not possible without an external source.

This one might meet your needs
http://www.analog.com/static/imported-files/data_sheets/AD7276_7277_7278.pdf
if you run the SPI at a high rate.

Rigelation:
I thought that maybe I could achieve this with ultrasound transducers, by looking at the travel time from a sender to a receiver. The idea is really straightforward, but the catch is that I would need to be sampling a 40kHz sine wave at a minimum of 3MHz for the resolution required.

When working with ultrasound transducers, you need to amplify the received signal (using an op-amp) into the logic level range of your microcontroller/Arduino. You can then sample the signal digitally (edge detect) at 16Mhz. Speed of sound through air is about 343m/s and the theoretical resolution is then in the low micrometer range (343m / 16e6). It is not practical to build a device with such accuracy for a number of reasons, but sub-centimeter is within reach after calibration.

How do you account for amplitude changing with distance?

liudr:
How do you account for amplitude changing with distance?

You tune the amplifier so that at max range (minimum amplitude), your output is just above the digital-high threshold for your microcontroller. This set point wil be a trade off between range/sensitivity and noise immunity. Output swing will be limited by your choice of op-amp supply voltage.

With phase comparison, I can see displacement measurement of ± 8mm or so with good accuracy (with proper temperature, humidity and pressure/altitude compensation), but with commonly available piezo ultrasonic transducers with their resonances, relying on absolute amplitude will be trick.
Or so I imagine.

Hmm, I'm going to need to get to more like .1mm or better for my application. The reason I thought this might be feasible (and I could just be missing some simple factor that I'm not aware of, like variable response time in the crystal or something) is that I want to send the data to a processor and actually figure out where the peak is--so the idea rests around having a high speed analog reading of the pulse from the transmitting transducer. Is this possible? What I'm basically looking for I guess is a high speed oscilloscope circuit or chip that can read these values and then get them to my arduino.

Are you using the right wavelength for the right job? Sound waves at that frequency have wavelengths of 1cm, that limits your accuracy. Why don't you use interferometry? It measures about .1um? Is absolute distance important to you or is just the relative distance change important? What exactly is your length scale that you want 0.1mm or better resolution with?

When I said +/- 8mm, I meant the range of displacement measureable - with good timing, 0.1 mm accuracy within that range should be achievable.

You can demonstrate the effect very easily with a dual channel oscilloscope.
Trigger one channel off the continuous transmission of a 40kHz transducer, and then look at the phase relationship of the received signal on the other channel as you move either towards or away from the other.
You can do the same, but with longer wavelengths, with an audio signal generator, loudspeaker and microphone.