A) Echo Time Measurement

On my Robot 2 there were two Atmel AT91SAM7X processor. One processor continuously collected and processed the sonar data and the other processor controller the motors and used the data from the sonar processor to identify paths around objects.

The sonar processor pulsed the transmitter and then was put into a tight loop checking the digital outputs from the two receivers. In this loop each receiver’s signal is checked for a rising edge and falling edge. When either edge is detected the echo time is saved. Once the Max Range is reached each rising edge is converted to distance and the time from the rising edge to the falling edge is converted to pulse width. The receiver data was sample once every 10uS which is equivalent to a distance resolution of about 0.5”. The processor’s internal memory was large enough to hold echo data up to about 20 feet away.

After all of the echo data is converted to distance and pulse width the distance data from the two receivers is checked for echoes that are close enough in time to be from the same object. When two echoes are found that appear to be from the same object it is used to calculate the X and Y coordinates of the object. The X and Y coordinates along with the pulse width are used to build an image of the area in front of the Robot.

The accuracy and resolution of the distance reading are primarily related to the sample rate. It is important that the sample rate be fast enough to accurately detect rising edge of the echo pulse without adding substantial delays. The Atmel processor I used was actually fast enough to sample at 200KHz and for a while that was what I used. But at a sample rate of 200KHz there was not enough time to perform edge detection in the echo loop. At 200KHz the Atmel processor could only read the inputs from the two receivers and save it to memory. The consumed much more memory because each sample had to be saved. The memory limitations end up limiting the sonar’s range. At 200KHz the range was limited to about ten feet. When I slowed the sample rate down to 100KHz I was able to detect the echo’s rising edge and only store information for echo pulse which dramatically reduce the memory requirement.

Echo time can easily be converted to distance by dividing the echo time in uS by two to get the time to the object and divide that by 93.8 to convert it to inches. However, I found the receivers added a small delay which adds a small offset to the distance reading. Therefore I use a linear equation to more accurately convert echo time to inches. The equation I used was:

Distance in inches = ( Count * 0.0070613 ) – 1.9

B) Echo Width

The pulse width of an echo is related to a number of factors, such as the size of the object, how close the object is to the sonar, the physical shape of the object and the object’s material. With the comparator’s limit set very high to eliminate noise on the detected signal, I have had some success using the pulse width to determine the size of the objects. But at best these are just estimates.

Another factor that affects the pulse width of a retuned echo is transducer ringing. Ultrasonic transducers are resonate devices and like other resonate devices, such as a bell, once energy is applied they tend to ring. When I ran tests with a transmitter and receiver about two inches apart, I found that even though the transmit pulse was only two cycles the total width of the signal coming out of the receiver was about 100 cycles or an echo pulse width of about 2.0mS. When a strong signal hits the receiver the signal coming out of the receiver is a dampened sine wave and can ring for 30 to 100 cycles even when the transmit signal is only a couple cycles. Since the ringing is a dampened sine wave the amplitude rapidly decays. The impact of this ringing can be minimize by adjusting the level of the comparator’s limit.

C) Auto Gain
I learned early on how important it was to be able to change the receiver’s gain on the fly. The amplitude of an echo from an object a couple feet away is considerably larger than the echo from an object ten feet away. If the gain is fixed at a high enough level to detect objects at ten feet, signals from objects a few feet away can easily saturate the receiver’s second stage which will result in missed echoes. In my receiver circuits there are three selectable gains between stage 1 and stage 2, off, low gain and high gain. In the first 200uS after the transmitter is pulsed the receiver can pick up the signal directly from the nearby transmitter. The amplitude of this signal is very large and can easily saturate the second stage amplifier. To prevent saturation immediately after pulsing the transmitter the receiver gain is set to “off” for the first 200uS. After 200uS the receiver gain is set to low gain and stays in low gain for the next 8mS. At 8mS the gain is set to high gain. 8mS is equivalent to an object distance of about 48”. My next sonar board will have at least three gain steps for each receiver instead of just two.

This is an example of amplitudes from the output of the first stage from echoes off a wall at 14” and 57” away.

Table 1

D) Transmitter Cycles

In general increasing the number of transmit cycles increases the amplitude and the width of the echo, but decreases the resolution of the sonar. The number of cycles determines the transmit pulse width and has a direct effect on the width of the returned echo signal. If two objects are within a few inches of each other and the transmit pulse is eight cycles or more the two echoes will overlap and the two objects will appear to be one large object.

The following table gives the pulse width of a transmit signal of 5, 8 and 10 cycles. The “Minimum object separation distance” is minimum distance between object that will be detected. If the separation is less than the “Minimum object separation distance” the two object will appear to be one object.

Table 2
Cycles Pulse Period Minimum object separation Distance
5 125uS 1.3”
8 200US 2.1”
10 250uS 2.6”

The number of transmitter cycles will also affect false echoes immediately after the transmitter is pulsed. As the number of transmit cycles increases the length of this false echo will also increase which will affectively increase the minimum range of the sonar.

However, reducing the number of transmit cycles also reduces the amplitude of the echo signal which makes it more difficult to detect echoes from distant object. Eight cycles seems to be a good choice to maximize the amplitude of the echo without a large loss of resolution. However, in my system I linked the number of transmit cycles to the sonar’s maximum range. If the maximum range is only 48”, which it is on the side sonar, the number of transmit cycles is set to five. This increases the resolution of the side sonar. If the maximum range is 100” the number of transmit cycles is increased to ten to increase the amplitude of echoes from distant objects.

E) Setting the Comparator’s Limit

As I described in the receiver section each of the four receivers has comparator on the output with an adjustable limit. This limit is generated by four 14 bit DACs which are set up by the firmware prior to pulsing the sonar. In my sonar system I have several automatic modes of operation. In these auto modes the sonar is pulsed every 100mS but data is only sent to the robot’s central processor every 500mS. The echo data from the pulses that are not sent to the robot’s central processor are used to adjust the comparators’ limits. If a receiver does not receive any echoes the limit is reduced until it receives at least one echo. If a receiver picks up more than five echoes the limit is increased until only five echoes are received. This is very effective at eliminating noise without eliminating valid echoes.

I believe a better way of doing this which I did not include in my design is to change the comparator’s limit while listening for echoes. Pulse the transmitter with the limit set at a very high level and with time ramp the limit down. This could be done either with a faster DAC or with an RC network generating a ramp.

F) Pulsing Sonar and Sending Data

If you are using the sonar to map out objects in a room how fast the sonar is pulsed is not real important, however if the purpose of the sonar is to prevent your robot from colliding with objects as is speeds across a room the sonar pulse rate becomes important.

If your robot is traveling at the rate of 6 mph and the sonar is puled twice a second the robot will travel almost 4’ between pulses. The sonar pulse rate can be increase by limiting the sonar maximum range. This not only reduced the time the sonar waits for echoes, but it will also reduce the number of echoes which also reduces the communication time.

Table 4 lists the time it takes to pulse a binocular sonar system and send the data to the central processor. This is assuming a communications baud rate of 115,200 with both echo distance and pulse width returned.

Table 3

G) False Echoes at Start
The following description of false echoes is not directly related to my Sonar 2’s firmware, but does have an impact my Sonar 3’s hardware and firmware. Therefore I felt it was important to include it in this section.

The two receivers on my front sonar are separated by twelve inches and the front transmitter is centered between the two front receivers. The side receivers and transmitters are separated by about two inches. All of the transducers are mounted to circuit boards which are solidly mounted to aluminum channel.

The receiver will always pick up some sound directly from the transmitter which results in a false echoes shortly after the transmitter is pulsed. The amplitude and timing of this false echo depends on how close the receiver is to the transmitter. If the receiver is mounted very close, an inch or two, from the transmitter transducer the magnitude of this false echo will be high and have wide pulse width. This false echo can easily obliterate real echoes within 1mS to 2mS after the transmitter is pulsed which will limit the minimum range to 10” to 13”.

These are the false echo measurements I initially measured from my side and front sonar.

Table 4

I found a number of things can contribute to the magnitude and length of this false echoes. Certainly the biggest contributor is sound passing through the air from the transmitter to the receiver, however sound passing through the bracket that the transmitter and receiver are mounted to can also contribute to this false echo. If the bracket is made of aluminum the sound will travel much slower and show up on the receiver output long after the signal traveling through air reaches the receiver. This can cause the false echo to be much longer.

Also due to the resonant effect of the transducers which I discussed earlier the width of the signal coming out of the receiver can be 50 times longer than the transmit signal. After a number of tests I found this was the main reason the false echoes were over 2mS long when the transmit signal was only 40uS long.