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

Discussion in 'Embedded Systems and Microcontrollers' started by kris_maher, Aug 20, 2009.

  1. kris_maher

    Thread Starter Active Member

    Apr 24, 2009

    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: Aug 20, 2009
  2. kris_maher

    Thread Starter Active Member

    Apr 24, 2009
    Also the chip uses a 10-bit ADC and I will perform 100 samples before performing the distance calculation.
  3. beenthere

    Retired Moderator

    Apr 20, 2004
    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.
  4. jpanhalt

    AAC Fanatic!

    Jan 18, 2008
    The wavelength is about 9 mm. How are you going to tell phase shifts of 360°, 720°, etc. apart?

  5. rjenkins

    AAC Fanatic!

    Nov 6, 2005
    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.
  6. Dragonblight

    Active Member

    Aug 19, 2009
    Jenkis is right- you should send a pulse and then wait for the echo- it's standard radar/sonar principles.