Sie sind auf Seite 1von 19

Build Your Own Ultrasonic Rangefinder: Part A

By Eric Rogers for majolsurf.net

Abstract:

While there are plenty of Ultrasonic Range finder modules available on the market, few if any provide a full range image of the echo complex, merely providing the range to the closest target. Moreover, most lack a true analog representation of the return echo, i.e. echo range and amplitude. The following project provides all of the above, can be modified to meet the users exact needs, and is relatively inexpensive.

Part A of this project will have you building both the analog and digital parts of the rangefinder and program the controllers to have a fully functional ranger. While the true analog data and echo complex returns will be available to the user, this Part A will only deal with ranging to the closest object and display it via a VT100 terminal emulator (Windows XP). Part B will demonstrate the representation of the full target complex. Use the Quick Start below for a fast immersion into the project, or read the How It Works section for in-depth details of the project.

Quick Start:
Parts List: (1) Arduino (1) Kemani or Amani 64 CPLD Kit (1) Maxbotix-UT Ultrasonic Transducer (2) OpAmp Modules BOB-09816 (2) 0.1uF Ceramic Capacitors (1) 4.7k Resistor (1) Breadboard

www.arduino.cc www.majolsurf.net www.sparkfun.com www.sparkfun.com

Project Code:
Arduino:http://majolsurf.net/projects/Amani64/cc/100826%20Ultrasonic%20Ranger/100826%20SonicTX.zip Kemani/Amani64:http://majolsurf.net/projects/Amani64/cc/100826%20Ultrasonic%20Ranger/100826%20ArdRanger.zip

Schematics: Kemani/Analog Front End

System Block Diagram

Instructions: 1. Construct the circuit seen in the Kemani/Analog Front End schematic.
If you are using an Amani64 instead of the Kemani, you only need to build the analog portion of the circuit and connect the transmit line (pin 41 on the Kemani) to an Amani Dock of choice, as well as the receive line (Kemani pin 21).

2.

Connect the TX_TRIGGER line to Arduino pin 4. Connect RANGE_PWM to Arduino pin 9. Connect the GND line of the breadboard to the GND connection on the Arduino. (Ppower, GND)
If you are using an Amani64 instead of the Kemani, simply seat the Amani on the Arduino. Define your Amani TX_TRIGGER and RANGE_PWM pins to match the Arduino signals. Amani pin 33 = Arduino pin 4, Amani pin 40 = Arduino pin 10. Be sure to make this change from pin 9 to 10 in the Arduino code.

3.

Connect an external DC power source to power jack J6 of your Kemani or Amani64.


Technically you may power your Kemani or Amani64 from you Arduino. If you choose this option I highly advise that you do not rely on USB power alone as you are driving an analog stage. The Kemani, being a 5V core device can be powered from the 5V port of the Arduino. The Amani64 receives Arduino power via the JP2 setting.

4.

Load SonicTX.pof into the Kemani/Amani CPLD via the JTAG ISP of choice.
The USBoomer JTAG ISP development kit is currently under Beta Test and available at www.majolsurf.net 8/16/10

5. 6. 7.

Connect your Arduino to your computer via USB. Upload the ArdRanger code to your Arduino. Do not start the Serial Monitor. Load the VT100 Terminal Emulator. Select the COM Port your Arduino uses. Select 9600bps. Initiate serial connection. Observe the Range Values in the Arduino Ultrasonic Ranger window. They will most likely not reflect an accurate measurement as the gain stages must be adjusted.
If using Windows XP, use the HyperTerminal application found in Start > All Programs > Accessories > Communications. Initiate the connection by pressing the Call icon or selecting Call from the Call Menu.

8.

We will now calibrate the analog section to detect your ceiling.

A. Start in a room with a standard ceiling that is flat and is up to 10 feet above your workbench. Estimate the range from your sensor to the ceiling. B. Adjust the potentiometers of the OpAmp modules all the way clockwise, which sets minimum gain.

C. Observe the range readout to be 34 feet, 10 inches. (10.65 meters). This indicates nothing is being detected.
This reflects the maximum detection range of the timing circuitry aboard the Kemani and does not necessarily represent the detection range of the analog circuit.

D. Begin adjusting the gain of the first stage by adjusting the potentiometer counterclockwise. Most likely you will rotate it to its full limit without detecting your ceiling.
Typically we do not crank the gain to patent pending in amplifiers as this typically puts the amplifier into compression. In later examples we will operate the amplifiers in their linear regions.

E. Slowly adjust the second gain stage potentiometer counter-clockwise and keep an eye on the range readout. Stop adjustment when you first see the range values change to your estimated value.
Most likely the values will switch back and forth between your ceiling range and 34 10. This is due to the amplified echo return amplitude is just now rising above the noise-floor.

F. Continue increasing the gain until your estimate ceiling range becomes a solid, regular reading. G. Test the range dynamics of your sensor by waving your hand between the sensor and the ceiling. The minimum detection range of this system is 1 foot 2 inches. (0.36 meters)
The minimum detection range is set by the Kemani/Amani code as it blanks the receiver during the transmit pulse and transmit artifacts.

H. If you increase the gain too high, you will begin to see range rabbits and eventually the ranger will default to the minimum range setting. Reduce the gain until satisfactory.
The rabbits are false return readings that most likely are triggered by the noise floor having been amplified over the detection threshold. The unit settles at the minimum-range reading as the gain drives the amplifier into compression thus spurious signals and noise trips the detection threshold immediately after the range timer starts.

9. Calibrate the metric accuracy of the rangefinder. In the Arduino code, you will find a constant defined as RANGE_BIAS. Adjusting this value adjusts the range offset typically caused by circuit timing delays. Place a detectable object a measured distance from the sensor and adjust the RANGE_BIAS constant to calibrate the range reading to the correct value.
RANGE_BIAS is measured in microseconds. Sound, traveling 343.2m/s, takes 74 microseconds to travel one inch. Be sure to account for round trip flight.

In order to make changes to the Arduino code and upload them, the serial connection to the VT100 emulator must be disconnected via the disconnect command.

10. If gain adjustments fail to create solid, constant range readings, try adjusting INTEGRATION_FACTOR in the Arduino code between 1 and 10.
INTEGRATION_FACTOR in this case simply averages the range readings. The usefulness of this constant will be seen in later examples as it will be used to integrate amplitude readings and increase the signal to noise ratio.

11. Experiment, tweak, have fun!

How It Works: Ultrasonic ranging is essentially the use of inaudible sound waves to illuminate a target and measure the time it takes for the echo to return. The speed of sound, depending on atmospheric conditions, is 343.2 m/s. The transmitted pulse is an ultrasonic tone, in our design, 40.82kHz, and lasts for a short duration, or pulse-length. The pulse length is kept short to quiet the system to allow the receivers to listen for the return echo. Transmitted pulse widths of an ultrasonic ranging system depends on design factors such as minimum-detectable range and the transmit amplifier circuitry. Some long-ranging systems incorporate transmitters that can sustain high signal amplification for only short periods of time Often in ultrasonic ranging applications, the transmitted pulses are mistakenly called a chirp. Chirps are actually linear modulated frequency (LFM) waveforms where the carrier frequency is increased or decreased proportionally over the pulse duration. The transmit waveforms in most ultrasonic ranging systems can be thought of as gated continuous-wave (GCW). GCW is a continuous waveform or tone that is gated or pulsed at a specific pulse repetition frequency (PRF). A typical ultrasonic rangefinder (UR) consists of three basic sections: sensor, analog, and digital back-end. Each of these can in turn be divided into additional subsystems. The sensor section performs the physics of the UR, emitting ultrasonic waveforms in specific beam patterns and converting physical echo energy into electrical representations. The analog section is divided into transmit and receive waveform amplifiers respectively designed to put as much transmit pulse energy into the atmosphere and amplify the return echo enough to be processed. The digital back-end performs this processing, as well as handles system timing, range-timing, waveform generation, receiver blanking, and even display functions. We will now describe these sections in detail in respect to the simple design in the Amani Project.

Sensor Section The heart of any UR is the sensor section, defined by one or two ultrasonic transducers which convert electrical energy to physical sounds waves and vice-versa. The transducer used in this project is the Maxbotix-UT, chosen for its performance versus cost. This unit operates at center frequency of 40kHz, can be driven up to 60V at 10% duty, and features a beam-width of 40 degrees and sensitivity up to -60dB. What does it all mean? It costs $5 at sparkfun.com so its perfect for home experiments.

http://www.maxbotix.com/uploads/MaxSonar-UT-Datasheet.pdf

Most UR systems are based on one or two ultrasonic transducers. Whether the UR uses one or two transducers depends on design factors such as range and sensitivity requirements, beam directivity and shape, and cost. Two-sensor systems are the easiest for the designer to work with, electrically. They tend to have minimal transmit/receive cross-talk, depending on the directivity and isolation of the transducers. They also allow the transmitter amplifier to be as powerful as needed without risk of damage to the receiver subsystem. Their limitation is in that narrow beam-width systems need transducer alignment in order to maximize transmit and receive beam-pattern interplay. Incorrect collimation can lead to false reading from targets not in the intended beam pattern. The benefit of a single-sensor section is that there is only one transducer beam-pattern inherent to the system. The user can be sure that transmit and echo pulses are following the same trajectory provided multipath effects are not present due to another objects proximity to the target. The single-sensor approach is desirable when narrow beam-widths are required. The problem, however, is that single-sensor systems induce the transmit pulse into the receiver as they share a common node. This creates the need to blank the receiver to avoid possible damage (depending on transmit power levels) as well as false range readings due to transmit pulse and transducer residuals. Single-sensor systems require short transmit pulse lengths in order to reduce receive blanking time thus allowing the receiver to amplify returns from targets closer in range. The longer the transmit pulse, even longer is the receiver blank time, which ultimately reduces the minimum detection range of the UR. Few hobbyist ultrasonic rangefinders incorporate physical receiver blanking. Physical blanking is the process in which a circuit that protects the analog receiver front-end from damage via high-energy transmitters. Often when these URs refer to receiver blanking, they are referring to the removal of the transmit pulse from the data stream in the digital section. Essentially the digital back-end ignores anything the receiver sees during the transmit time, and for a short period after, thus creating a virtual receiver blank. Targets within the transmit pulse time are not detected by the system.

The design presented in this project is a single sensor approach. This method was chosen for transducer directivity and design simplicity. Early experiments with a two-transducer approach used a weak receive gain stage, thus targets not directly down the middle were not being detected. The simplicity of the transmit section, described later, also allowed for the onetransducer approach as no damage to the receiver is possible. Moreover this approach is a good teaching tool for the blanking methods we will see later. This design can be easily modified to a two-sensor system. I encourage you to play with the design and attempt to incorporate a power amplifier transmit stage using a transducer separate from the receiver transducer. Next we will examine the black magic of the analog section.

Analog Section The analog section has a twofold purpose. The transmitter subsystem must amplify the transmit waveform effectively enough for the resulting sound wave to propagate some distance, to survive reflection loss, and to return to and be sensed by the transducer. Secondly and more critically the receiver portion must discern the faint return echo from background and system noise. While there are many sophisticated methods of amplifying transmit waveforms, this design does not incorporate a transmitter amplifier. The 3.3V peak to peak signal from the Kemanis CPLD was found sufficient enough to excite the transducer for this project. This is mainly due to the short sensing distances involved, 10 feet or less, and the emphasis put into the gain stages of the receiver. The design of this project allows for easy experimentation with a transmit amplifier stage. I suggest using a separate transmit transducer to reduce receiver crosstalk. A simple voltage transformer circuit or opamp with greater power rails would be a good start. Be sure to protect the Kemani output pin and be mindful of the 60V 10% duty of the ultrasonic transducer. The transmit pulse-width from the Kemani is about 300usec, the pulse repetition interval (PRI) set by the Arduino. A 10% duty of 300usec dictates a minimum PRI length of 3ms or maximum PRF of 333Hz. At 1.1ms per foot the maximum range at this PRF is about 3.3 feet before pulse ambiguity sets in. For hobbyist purposes slowing it down to 10Hz or below is quite sufficient. Below is a representation of the transmit waveform as seen at the positive terminal of the transducer (top trace). The bottom trace is the output of the receiver with no blanking or bandwidth limitation. We see in that the Kemani drives the transducer for about 300us and the transducer rings afterward making a total transmitted pulse-length of over 500us. The waveform generator produces a 40.8kHz square wave, which carries frequency components not inherent to a true sinusoid. The transducer transmits the in-band component, 40.8kHz, while attenuating those components residing out of band. The receive waveform, when not being driven into compression, is sinusoidal.

Examine the block diagram below for the system design for this project. Notice the transmit pulse generator connects directly to the single ultrasonic transducer with no amplification.

The magic of this rangefinder lies in the receiver analog system. Because there is no transmit amplifier stage, the best peak power the transmit pulse could hope for is 11mW. This ultrasonicwhisper will then suffer atmospheric attenuation and reflective scattering. The transducer and

receiver gain stage must discern the faint echo from background and system noise and present it intelligibly to the signal processor. Fortunately we are dealing with ultrasonic frequencies with a transducer bandwidth of 4kHz. Audible and ultrasonic noise outside this bandwidth, if present, are greatly attenuated and not detected. The transducer translates any signal between 38 and 42 kHz into an electrical representation and presents it to the analog receiver front end. The receiver subsystem features two gain stages based on Op Amp modules from sparkfun.com. Each module contains two gain-adjustable non-inverting amplifiers, the maximum gain of each being 10. The two modules together give us a potential total gain of 10,000, which is far from achievable due to system noise limiting the minimum detectable signal. The modules were chosen for their performance as well as convenience in use. There are far more sophisticated amplifier designs in existence however these are sufficient and greatly reduce prototype troubleshooting.

http://www.sparkfun.com/datasheets/BreakoutBoards/OpAmp_Breakout-v16.pdf
http://focus.ti.com/lit/ds/symlink/lmv324.pdf

These modules do not allow for adjustment of the positive terminal bias, thus the resulting output is limited to a DC bias of Vcc/2. This limits overall sensitivity as too much gain amplifies the noise-floor, averaging around the DC bias, above the detection threshold as determined by the CPLD input-high voltage. For the scope of this project this is acceptable, however if more gain is required, a tunable threshold detection stage must be added. Signals above the threshold would be relayed to the digital back-end while the noise-floor would be rejected.

This simple twin-stage receiver design does not offer frequency selectivity. It relies mostly on the bandwidth limiting of the ultrasonic transducer. If there was a second UR system transmitting anywhere within +/-2kHz off this systems transmit frequency of 40.8kHz, this receiver will detect the foreign signal. If multiple ultrasonic systems are to be used, they should be of different carrier frequencies and their receivers should incorporate frequency-selective filtration. Users are not limited to these OpAmp modules, which were chosen for convenience and fast prototyping. Try experimenting with your own amplifier designs. An oscilloscope is highly recommended for this effort. The following graphic demonstrates the transmit pulse as presented to the transducer (trace 1), the digital RCV_OUT signal with a target echo (trace 2), and the raw analog receiver (trace 3). Notice the transmit pulse has been blanked in the RCV_OUT signal. The transmit pulse in this display is compressed and scaled down. Notice the length of the transducer residuals are amplified by the receiver versus the length of the transmit pulse.

Now that we see how the analog section works, lets explore the workhorse of the system, the digital back-end.

Digital Back-End Recall the UR system block diagram. Notice that the digital portion of this design is divided into two major subsystems: the Transmit Waveform Generator and Receiver Subsystem (TWG/R) and the Timing and Display Subsystem (TAD). In this design the Kemani performs the TDW/R function while the Arduino handles TAD tasks. Let's examine each subsystem in detail.

Transmit Waveform Generator and Receiver As one would expect, the TWG/R performs two functions: forming the waveform to be transmitted based upon input pulse repetition interval (PRI) triggers and translating the analog receiver output into a format that can be processed by the TAD. In this design this subsystem resides in the Kemani CPLD-based breadboard key.

Let's first examine the transmit side of the TWG/R. The transmit process begins with the TX_TRIGGER signal from the TAD. This trigger determines when and how often the transmit waveform will be generated and passed to the transducer. The measure of transmit repetitions is called the pulse-repetition frequency (PRF). The inverse of PRF is the pulse-repetition interval, which can be described as the period that initiates the waveform transmission, starts the echo timer, and defines the maximum time allowable to receive the echo. The TX_TRIGGER starts a range-timer called PRI_COUNT. The PRI timer creates a timing reference for the entire length of the PRI. The trigger also sets the transmit pulse enable at time zero which is reset when pri_timer counts 300 microseconds. This transmit pulse enable determines the transmit pulse width. A logical AND allows a free-running 40.8kHz square-wave generator to present the waveform to the TWG/R TRANSMIT_PULSE output for the duration of the transmit pulse width.

On the receive side, the TWG/R translates the analog return into two formats readable by digital circuits: a pulse-width modulated signal representative of range, and a digital full-range image of the return echo complex. In the TWG/R block diagram, these signals are defined as RNG_PWM and RCV_OUT. The transmit pulse, amplified by the analog receiver, must be removed, or blanked, in order to prevent false range readings. The pri_count timer is passed from the transmit pulse generator to the blanking logic. The blanking logic essentially ignores any signal passed from the analog receiver between the start of the PRI and an adjustable time at which the transducer is believed to stop ringing after the transmit pulse.

In the image below, the top trace is the transmit pulse measured at the transducer positive lead. The middle trace is the RCV_OUT signal from the TWG/R. The bottom trace is the analog receiver output. There is no object detected. Notice that RCV_OUT is completely ignoring the transmit pulse that is passed by the receiver.

Notice the slight delay between the transmit pulse and the analog receiver's amplification of the transmit pulse. This is one example of why the RANGE_BIAS calibration is needed to achieve an accurate range reading. In the next example, the same setup is displayed except there is a return echo from a nearby object:

In the following image we see two detected objects, a strong return from a close target and a weaker echo from an object out-range. Again the transmit pulse is blanked.

Closer examination of the RCV_OUT signal we see the signal toggling multiple times during the return echo. These multiple transitions might be interpreted as multiple targets depending on the data processing system. To avoid this, we use a Schmitt trigger with a software-adjustable hold off time. Through adjustment we achieve a single pulse representing each return.

The RNG_PWM signal is a pulse of a varied pulse-length, the length representing the exact time between the transmit pulse and the first return echo. RNG_PWM can only represent the range of one object, the closest object to the transducer. A pulse-width modulation generator in the CPLD is started by the TX_TRIGGER and stopped by the leading edge of the target return. In the following photo we see a single target as represented by the RCV_OUT signal (trace 2) and RNG_PWM signal (trace 3).

Next we see two targets in the RCV_OUT trace. The first target is my hand within the transducer beam but not blocking it, the second echo is the ceiling. Notice RNG_PWM triggers on the closest target.

The Kemani CPLD code is available here:


http://majolsurf.net/projects/Amani64/cc/100826%20Ultrasonic%20Ranger/100826%20ArdRanger.zip

In the scope of this project only the RNG_PWM output is used. RCV_OUT will be used in later projects. Only two signals, TX_TRIGGER and RNG_PWM are needed to interface a data processor with the TWG/R. In this design that processor is the TAD.

Timing and Display Subsystem The TAD has four functions: start the PRI, measure the RNG_PWM signal, process data, and display the results. In this design the Arduino houses the TAD subsystem. The logic flow is visible in the following block diagram.

The PRI_START signal connects to the TX_TRIGGER input of the TWG/R subsystem. The Arduino starts the ping() function by setting this signal high and immediately starts the pulseIN function. This function measures the length of the RNG_PWM signal and returns the time in microseconds. The ping() function then applies RANGE_BIAS constant to this raw value. The RANGE_BIAS is a calibration value that is used to offset circuit delays to provide the best metric accuracy possible. The result is divided by two to account for the round trip flight of the pulse and echo. The data passes through an integration filter, which acts as an averaging function, if needed. I suggest leaving the integration factor set at 1. Next the adjusted range time goes through a series of calculations to display the data in feet, inches, meters, and centimeters. Finally the TAD sends VT100 terminal commands to the host PC for data display.

Summary The system presented in the project is the most basic of ultrasonic rangefinder designs. The most complexity is found in the TWG/R, which hopefully you find easy to implement with the Kemani or Amani64. This project is open to experimentation. I encourage you to with the code, add additional gain and detection circuitry, build a transmit amplifier, or whatever modification you see fit to improve system performance. Stay tuned for the next evolution in ultrasonic transducer design: the A-Scope Range Display.

Das könnte Ihnen auch gefallen