Searching \ for 'Distance measuring using 16C74-driven sonar' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/devices.htm?key=16C
Search entire site for: 'Distance measuring using 16C74-driven sonar'.

Truncated match.
PICList Thread
'Distance measuring using 16C74-driven sonar'
1997\05\27@002109 by Steve Hardy

flavicon
face
I have recently made a PIC-powered sonar, and thought I might share the
experience.  Of course, there are commercial units (e.g. Polaroid),
but then I didn't have one of these in my junk-box...

The requirement was to measure the distance of a person from a fixed
point every 1/10 second, to an accuracy of about 100mm, with a range of
300-1400mm.  Not particularly demanding specs, but turned out to be
fairly challenging since I was limited to a pair of cheap ultrasonic
(40Khz) Tx/Rx transducers and a single 5V supply.

The idea of sonar is to send out a pulse of sound, then measure how
long it takes for the receiver to pick up the pulse reflected from an
object.  Since the speed of sound is about 334 m/s, and the total
distance the sound travels is twice the distance between the Tx/Rx unit
and the object, there is a delay of about 6 ms per metre of distance.
The wavelength of 40KHz sound is about 8.35mm, which sets a lower limit
to the distance resolution.

The Tx/Rx units disperse the sound over a large solid angle, since the
physical size of the transducers is about one wavelength.  This needs
to be concentrated into a narrower beam, using parabolic reflectors,
otherwise there may be false readings from objects on either side of
the object which is being measured.  I use reflectors with a diameter
of 50mm (on both Tx and Rx) machined from aluminium bar stock.
Reflectors from a small headlight are also very good.  Surface accuracy
only needs to be within 2mm.  The half-intensity angle is reduced to
about 10 degrees with 50mm reflectors.

The Tx unit is driven with a 40KHz square wave, capacitively coupled
from the PIC PWM output pin.  Actually, I had another restraint in that
the other PWM output needed to run simultaneously, but at 20KHz.  Since
the 16C74 only has one timebase for both PWMs (unfortunately!) I
'solved' the problem by sending 20KHz at 25% duty cycle to the sonar
Tx.  This works because there is still sufficient energy in the second
harmonic (40KHz) to operate the Tx.  The Tx unit rings like a gong for
several hundred cycles after setting the drive to high impedance.  This
can be quickly damped out by leaving the output either high or low (low
impedance) rather than tri-stated.

The Tx unit could be driven with a higher voltage (up to about +/- 20V)
which would increase the operating range, but this was found not to be
necessary in this case.

To activate the Tx unit, the PWM is set up and turned on.  The number
of cycles to output is determined by polling the PWM output line and
counting the number of times it goes high.  After the required number
of pulses (about 10-20) the PWM is turned off.  This is done every 1/10
second and forms the first stage of the sonar 'cycle'.

The Rx unit is amplified by a 2-stage common emitter amp.  The gain of
each stage is set to about 40.  The output of the final stage is
rectified and smoothed with a low pass filter made of a 330pF cap in
parallel with a 1M resistor.  This feeds directly into an analogue
input.  The PIC's ADC module can now measure the envelope of the
incoming pulse.  Although I used discrete BC548 transistors in this
design, I have found that 74C04 CMOS inverters make reasonable 'rail-
to-rail' amplifiers so long as you don't use more than two of the
inverters in linear mode in the same package.

After sending the transmit signal, the ADC unit takes samples every
204.8us -- this is a convenient number when operating with a 10MHz
clock.  A total of 92 samples is taken, with the results loaded into
the bank 1 registers.  Each sample represents an increment of about
34mm.  When all samples have been acquired, they are scanned for the
highest value.  This is assumed to be the pulse reflected from the
object, and the distance of the object can be deduced from the sample
number.

Taking the peak value of the receiver envelope seems to be
satisfactory, although I also tried using the maximum rate of rise of
the envelope.  The latter is more prone to noise spikes, but is more
accurate.  More sophisticated analysis could determine other conditions
such as multiple objects, or averaging of several samples could be
used to reduce the effect of noise.

This application happens to have several sources of interference.
Since the gain of the receiver is quite high, it also picks up noise
coupled from a high power 7-segment display and the other PWM output
(which eventually drives a large DC motor in the vicinity.
Fortunately, both of these noise sources are driven by the same PIC
device and hence are strongly correlated with respect to the sonar
cycle.  Although I have not actually needed to do this, it would be
entirely possible to mask out this noise by subtracting it from the
sonar samples.  This is done by performing a 'dry run' where the Tx
unit is muted.  The samples obtained are then subtracted from the
'real' samples taken on the next sonar cycle.

Initially, I wanted to make use of the capture facility to time the
return pulse.  Unfortunately, this wasn't practical since the capture
event could only be generated when the envelope reached a particular
threshold level.  This was too prone to false readings.  Also, fairly
complicated external logic was required since the PWM output pin is
also the capture input pin -- there needed to be a way to direct the
appropriate signals through the one overloaded pin.

There is a large difference between the strongest and weakest received
pulses, because the received intensity drops of as the square of the
distance (at least, and possibly as the fourth power for relatively
small objects).  It is this which limits the operating range.


Regards,
SJH
Canberra, Australia

1997\05\27@010249 by tjaart

flavicon
face
Steve Hardy wrote:
>
> I have recently made a PIC-powered sonar, and thought I might share the
> experience.  Of course, there are commercial units (e.g. Polaroid),
> but then I didn't have one of these in my junk-box...

Thanks for sharing this, it was truly informative. :)

Have you considered using a *primitive* adaptive filter? Say, for
instance, you transmit sixteen cycles. In your RX amplifier, you
set an AGC to keep the duty cycle of the incoming data at around 50%
(The duty cycle that you transmitted). Shift the incoming data into
two bytes of RAM. Compare (XOR) the databytes with the pattern you
transmitted (in this case 10101010 10101010). This will give you a
score of 1 - 16. At the point of highest score, the measurement is
complete.

Using a pseudo random pattern will give better results with the
correlation though.

This will mean that you can get away without the A/D, and that you
should be able to lock onto the carrier phase itself. Using the
longest code you can given your 10Mhz clockrate, the correlation
should reject most noise sources.

If you decide to give it a try, please let us know how it turned out.

--
Friendly Regards

Tjaart van der Walt
spam_OUTtjaartTakeThisOuTspamwasp.co.za
_____________________________________________________________
| Another sun-deprived R&D Engineer slaving away in a dungeon |
|             WASP International  http://wasp.co.za           |
|             GSM and GPS value-added applications            |
|  Voice : +27-(0)11-622-8686   |   Fax : +27-(0)11-622-8973  |
|_____________________________________________________________|

1997\05\27@012945 by Steve Hardy

flavicon
face
> From: Tjaart van der Walt <.....tjaartKILLspamspam@spam@wasp.co.za>
> Have you considered using a *primitive* adaptive filter? Say, for
> instance, you transmit sixteen cycles. In your RX amplifier, you
> set an AGC to keep the duty cycle of the incoming data at around 50%
> (The duty cycle that you transmitted). Shift the incoming data into
> two bytes of RAM. Compare (XOR) the databytes with the pattern you
> transmitted (in this case 10101010 10101010). This will give you a
> score of 1 - 16. At the point of highest score, the measurement is
> complete.
>
> Using a pseudo random pattern will give better results with the
> correlation though.
>
> This will mean that you can get away without the A/D, and that you
> should be able to lock onto the carrier phase itself. Using the
> longest code you can given your 10Mhz clockrate, the correlation
> should reject most noise sources.
>
> If you decide to give it a try, please let us know how it turned out.

This may work with other transducer types, however these units strongly
resonate at 40KHz and nothing else.  Their bandwidth is very limited
(+/- 100Hz) and thus it would be very difficult to make use of any
finer level modulation of the signal, since the 200Hz bandwidth translates
to a very poor distance resolution.  Also, the Tx is very close to the
Rx owing to physical constrains - the Rx picks up the initial transmission
which is much higher intensity than the reflected pulse.  This would
tend to swamp the desired signal (unless an appropriate delay line and
subtractor was used to cancel this source).

I have actually used something similar to your suggestion, but in the
field of IR communication.  In this case the transmitter sent out a
32-bit pattern (4 of the bits being '1', the rest zero) repetitively.
The receiver could tune into the pattern being transmitted, even if other
transmitters were in the vicinity (so long as the other transmitters
used a different 32-bit code).

Regards,
SJH
Canberra, Australia

1997\05\28@013653 by Dmitry Kiryashov

flavicon
face
Steve Hardy wrote:

{Quote hidden}

Hello Steve .

I think there are another solution to measure distance with ultrasonic
Tx/Rx and PIC .

Define ACF ( AutoCorrellation Function ) as:
---
         M-1
Bn(X1,X2)=Sum X[i]*X[i-n] ;
         i=0

where M size of X vector , n is delay(shift distance) ,
X1[0..M-1] , X2[0..M-1] , X1[i=>M] always =0 , X2[i=>M] always =0 too .
---

Let X[]= (0,0,0,1,1,1,0,0,0) ; M=9

n=0 , B0 = 0*0 + 0*0 + 0*0 + 1*1 + 1*1 + 1*1 + 0*0 + 0*0 + 0*0 = 3 ;
n=1 , B1 = 0*0 + 0*0 + 0*1 + 1*1 + 1*1 + 1*0 + 0*0 + 0*0 + 0*0 = 2 ;
n=2 , B2 = 1 ;
n=3 , B3 = 0 ;
n>3 , Bn = 0 ;

At 50 .. 60 years Barker codes was discovered . I've hear only about
Barker codes with following positions quantity: 2,3,4,5,7,11,13

2: It's trivial case ;)
3: (1,1,-1)                             ACF=(3,0,-1)
4: (1,1,1,-1) or (1,1,-1,1)             ACF=(4,1,0,-1) or (4,-1,0,1)
5: (1,1,1,-1,1)                         ACF=(5,0,1,0,1)
7: (1,1,1,-1,-1,1,-1)                   ACF=(7,0,-1,0,-1,0,-1)
11:(1,1,1,-1,-1,-1,1,-1,-1,1,-1)        ACF=(11,0,-1,0,-1,0,-1,0,-1,0,-1)
13:(1,1,1,1,1,-1,-1,1,1,-1,1,-1,1)      ACF=(13,0,1,0,1,0,1,0,1,0,1,0,1)

Size of Burker code result to measure precision.

Send_Packet(Barker[k],0,0,0,0,0,...)
Recv_Packet(x,x,x,...,x,x,Barker[k])

So you send/receive signal with Barker modulation and search maximum of
ACF(Send_Packet,Recv_Packet). If you know n (in Bn ACF function) you can
measure distance .

WBR Dmitry.

P.S. Any additional information see at textbook about radiolocation .

1997\05\29@025129 by Mal Goris

flavicon
face
Dmitry Kiryashov writes:

[big barker code snip]

>
> So you send/receive signal with Barker modulation and search maximum of
> ACF(Send_Packet,Recv_Packet). If you know n (in Bn ACF function) you can
> measure distance .
>
> WBR Dmitry.
>
> P.S. Any additional information see at textbook about radiolocation .
>

This is essentially what is done in RADAR systems, too. Ideally, and
for best time/distance resolution, you would like to transmit an
impulse. But because of bandwidth and peak power constraints you
can't. So instead, you transmit a signal whose autocorrelation
function is an impulse. In RADAR the transmitted signal is a chirp (FM
modulation) and with a digital modulation scheme you can use the
Barker codes that Dmitry describes. After the cross-correlation of
received signal with transmitted signal all you have is an easily
identifiable peak corresponding to the reception of the return
signal. There is more than one Barker code for a given number of
symbols and separate devices can operate near each other if they use
different Barker codes. This system has good noise immunity too. This
is all very similar to spread-spectrum modulation or code-division
multiplexing. Longer Barker codes are better but require more
computing for the cross correlation and take longer to transmit, so
you have to be sure you will finish transmitting before the reflection
returns.

Mal Goris
--
http://www.nfra.nl/~mgoris/

1997\05\29@034600 by tjaart

flavicon
face
Mal Goris wrote:
>
> This is essentially what is done in RADAR systems, too. Ideally, and
> for best time/distance resolution, you would like to transmit an
> impulse. But because of bandwidth and peak power constraints you
> can't. So instead, you transmit a signal whose autocorrelation
> function is an impulse. In RADAR the transmitted signal is a chirp (FM
> modulation) and with a digital modulation scheme you can use the
> Barker codes that Dmitry describes. After the cross-correlation of
> received signal with transmitted signal all you have is an easily
> identifiable peak corresponding to the reception of the return
> signal. There is more than one Barker code for a given number of
> symbols and separate devices can operate near each other if they use
> different Barker codes. This system has good noise immunity too. This
> is all very similar to spread-spectrum modulation or code-division
> multiplexing. Longer Barker codes are better but require more
> computing for the cross correlation and take longer to transmit, so
> you have to be sure you will finish transmitting before the reflection
> returns.
>

GPS uses 1023 bit Gold codes. What are the differences between Barker
and Gold codes?

--
Friendly Regards

Tjaart van der Walt
tjaartspamKILLspamwasp.co.za
_____________________________________________________________
| Another sun-deprived R&D Engineer slaving away in a dungeon |
|             WASP International  http://wasp.co.za           |
|             GSM and GPS value-added applications            |
|  Voice : +27-(0)11-622-8686   |   Fax : +27-(0)11-622-8973  |
|_____________________________________________________________|

1997\05\29@051820 by Dmitry Kiryashov

flavicon
face
Mal Goris wrote:

> There is more than one Barker code for a given number of symbols and separate
devices
> can operate near each other if they use different Barker codes. This system
has good
> noise immunity too. This is all very similar to spread-spectrum modulation or
> code-division multiplexing. Longer Barker codes are better but require more
> computing for the cross correlation and take longer to transmit, so you have
to be
> sure you will finish transmitting before the reflection returns.
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Why not possible to transmitte and receive Barker's sequency at one time
?
In simplest case Barker's sequency consist from "1"(+1) and "0"(-1) so
computing cross--corelation easy execute by XORing Send_Barker[] with
Recv_Barker[] bit to bit and sum resulting bit sum . The main difficulty
is time step choicing resulting from what distance measure precision
needed.

I would like to see any additional information about Barker codes longer
than 13 digit . If this topic not interesting in PICLIST welcome private
email .

WBR Dmitry.

1997\05\30@110015 by Mal Goris

flavicon
face
Tjaart van der Walt writes:
> GPS uses 1023 bit Gold codes. What are the differences between Barker
> and Gold codes?

I don't know! But I don't think Gold codes would be used in the same
way that a spreading (Barker) code is used as I described before. If
you spread a digital signal with an N-bit spreading code then the
bandwidth of the signal becomes N times what it was. 1023-bit
spreading codes would be too excessive for consumer
communications. More likely, although I really don't know for sure, it
is something to do with encoding for error correction.

Dmitry Kiryashov writes:
> Why not possible to transmitte and receive Barker's sequency at one time
> ?

Because the Barker code repeats itself, it is only pseudorandom, not
truly random.

Mal Goris
--
http://www.nfra.nl/~mgoris/

More... (looser matching)
- Last day of these posts
- In 1997 , 1998 only
- Today
- New search...