Ultrasonic Distance measurement using Phase Shift Detection help (with atmega32)

Thread Starter

kris_maher

Joined Apr 24, 2009
90
Hi,

I'm building an Ultrasonic Rangefinder, it transmits a amplified square wave at 40KHz, and receives (via receiver circuit) a weakened sine wave which is then filtered, amplified and converted to a square wave again before being sent back to the microcontroller for processing.

I initially tried programming with via measuring the echo (delay) between the signals however perhaps it was my coding that might have had a glitch.

Anyway I've decided to check out "Phase Shift Detection" method for distance measurement. I would need to measure the phase difference between the square waves via sampling using ADC.

Just wondering if someone can point me in the right direction thanks since I've never done anything related to phase shift before (except only in engineering maths). Also the return signal would be 40KHz as well and also I'm not using any other hardware such for phase shifting, I'm expecting to do it all in software once the received signal is taken in by the micro. Oh and btw I'm using an external 16MHz crystal.

Thanks again,

PS: My code already transmits a continuous square wave via CTC mode using interrupts at 40KHz on timer 1.

PS2: I have this formula though which I've found from some research though I'm not sure if it's correct or not for my job.
Phase Shift = (2*pi*f*L) / C.

For C = speed of sound (taken as 340.29m/s), L = distance of object
 
Last edited:

beenthere

Joined Apr 20, 2004
15,819
Why would you want to use your ADC? If you generate the pulse train that drives the ultrasonic output, you have a timing reference already present. If the transmitted pulse starts a counter and the received echo turns the counter off, the magnitude of the count will indicate the duration of time between the transmitted pulse and the echo.

You can use the microprocessor to run the pulses into the counter, but an external oscillator might be more convenient to use.
 

rjenkins

Joined Nov 6, 2005
1,013
As jpanhalt says, the wavelength is very small.

Phase shift will give you the position within one wavelength, but not the integer number of wavelengths to the target.

You are far better off starting with a pulse, say 10 or 20 cycles transmit carrier, then listen for the return echo after a short dead time to allow the direct (local) signal to end.
 
Top