Advanced Circuit Ultrasonic Range Sensing
This section was added after trying to decipher some strange fault conditions.
Having reviewed the previous analysis and delved deeper into signals at all stages and doing basic This section details with the electronics such items as
Previous Pages cover
Let us first look at basic timing of an ultrasonic echo and compare to the TX burst sent to the transducer.
Basic Signals on HC-SR04
Scope shot of signal timing
Picture Left is a scope screen shot showing the external and internal signals for this process, where -
- TRIG (Yellow) and ECHO (Magenta) are the signals between unit and micro,
- TX (Cyan) and TX- (Green) are the internal signals of the burst being sent.
Note The Echo pulse does not start till 202 µs after the start of sending. The start of sending is our
measurement reference point.
Back to top
Measurement Timings on HC-SR04
So now we take some actual measurements using a Digital Storage Oscilloscope, with 200 MHz bandwidth, and get -
Example Oscilloscope Screen Shots
Scope shot of Timing from Trigger pulse to Burst start
Scope shot of Timing for burst to start of Echo pulse
Timings from oscilloscope
||Start of Ultrasonic Transmit
||Width of Ultrasonic Transmit
||Start of Ultrasonic Transmit to start of measure
||Start of Wait for RX
So important things to note from these timings are
- There is a 2 µs delay between end of transmitted pulse train and start of echo. This is no doubt due to code delays in the
microprocessor running at 27 MHz, from exiting a loop to send the TX burst, then change the port pin, and any other software
- An acurrate measurement (at any distance) must be at least 202 µs after start of Echo
- Any detection must be after the 8th cycle of the RX signal (202 µs)
If we do not do the above the timings are wrong. This then raises issues with accuracy and minimum detection distances.
- at 20 ° C, round trip time of 202 µs is approximately equal to a distance of 3.5 cm.
- One cycle of 40 kHz Ultrasonic wave as a round trip time is equivalent to a distance of approximately 4 mm.
Back to top
The Received Echo
Back to top
How the Sensors Actually Work
Having thought about things for longer and not fully beleiving other peoples circuit descriptions, then remembering basic Newtonian physics
as well as fourier analysis and the like I would like to revisit the actual workings as in -
I have worked with many other peizo devices that had to deliver some power to stir liquids, in one case Guiness.
Right lets start
Ultrasonic transducers and Newtonian physics
Let us consider what an ultrasonic transducer is basically two metal plates either side a piece of peizo effect material which can be quartz,
ceramic or some other Suitable INSULATOR.
The two plates are each connected to an electrical terminal for connection to an electronic circuit.
The basic peizo effect, is two ways
- Driven - when an electrical signal is applied the peizo material either is compressed or expands, with no voltage applied or both
terminals at same voltage the peizo material is at rest. Often one plate is fixed and one allowed to move.
When driven with voltages at the resonant frequency for the material maximum power is used for movement of the material and not wasted.
The resonant frequency is determined by how the crystaline structure is made up (including orientation) dimensions of the device and the
Here is where the Newtonian physics comes in, when the voltages are applied even if the change in voltage is a fast rise time square
wave, the crystal has Mechanical INERTIA, so the movement is damped out into a sine wave type motion at the resonant frequency
Efficient power transfer would be achieved with driving the terminals with sine waveform.
In Ultrasonics work, when the material expands it pushes the plate away from the base increasing air pressure, and conversly when it
compresses it pulls the plate inwards reducing air pressure. These changes are what is transmitted pressure differences in air.
- NOT driven - when a peizo material is compressed or stretched it will PRODUCE an electrical voltage proportional to the amount
of movement. This is the principle of how vinyl record needles work.
When used for Ultrasonics receivers one of the plates is fixed and one allowed to move as air pressure increase on the plate the material
is compressed, and conversely when the air pressure reduces the material is expanded.
However in order to work efficiently the receiver needs to be excited by several cycles of the resonant frequency, at which point it
will self resonate and build in amplitude and eventually die away. This is also known as harmonic resonance. What is happening is the
magnitude of movement is perfectly in phase with the excitation intervals and like a playground swing at each end of the swing motion and
is in phase with excitation (push) moves the swing faster building up energy.
This can be seen be seen from scope shots of receiver with a close object (see Received Echo).
Those scope shots show the characteristic sound envelope of a musical not on a struck instrument like a piano, or plucked guitar, with
a sinusoidal looking Attack and Decay phase followed by classic Sustain and Release phases. Anyone who has worked with musical
synthesisers will be aware of these terms. the standard diagram for the volume envelope is
Volume Envelope For ADSR
The same effect can be seen with the making musical notes with partly filled wine glasses and running a moist finger around the rim of
the glass, but this works best with crystal glass. When ever you see this done the note will increase in voilume when the finger is
removed as energy is no longer being taken by the finger and the note persists for a noticeable time.
The voltage produced is reverse to what is used to transmit so with the inversion between compressed at one end and expanded at other and
opposite effect on voltage produced gives the same phase of signal at the other end.
For those who remember their fourier analysis
A square wave comprises of the base frequency sine wave and all the odd harmonics (frequencies) up to infinity in phase
So for 40 kHz square wave that is -
40 kHz + 120 kHz + 200 kHz + 280 kHz + 360 kHz + 440 kHz......
So when we consider the frequency response for a typical ultrasonic transducer when driven with sine waves, the response is down by 20 to 40
db within 10 kHz of the centre frequency. So from an electrical point of view the material acts like a very narrow band filter with very high
rolloff so even the third harmonic of 40 kHz which 120 kHz will not get through,let alone the rest.
Therefore we should treat all motions of Ultrasonic transducers as sine waves, Hence most efficient power transfer would be by being driven
with sine waves.
Most Ultrasonic receivers have some form of high(ish) performance bandpass filter when in reality considering the response of the receivers,
the real things we are trying to filter out are -
- Mains Hum and major harmonics
- Noise pickup in wiring, supply, the devices, etc
Considering the response of units is already been highly bandpassed from its mechanics, two simple RC filters between stages should do the
- Mains Hum and major harmonics
500 Hz to 1 kHz HIGH pass to remove mains hum even at 3 db/octave rolloff it will be 2 or more octaves down by the time we reaching
100/120Hz 2nd harmonic of most mains frequencies. If we use a 1 kHz HIGH pass it will over 3 octaves down by the time we reach 100/120
Hz which is 9 db down, which is 1/8th of incoming power at that frequency.
- Noise pickup in wiring, supply, the devices, etc.
80 kHz to 200 kHz LOW pass to remove noise as this will be several octaves before we get to system noise.
The real thing to do is reduce gains in each stage as the standard device used is a LM324 which has Gain Bandwidth product of 1 MHz, so along
with its clipping due to non rail to rail I/O means we get harmonic distortion, and when some stages have gains of 5 to 10, we get bandwidth
at those gains from 200 kHz down to 100 kHz. Thus introducing more distortion, clipping etc...
So why do we see many more 'echo' pulses when examining the onboard Signal
If you remember from Received Echo we looked at a scope trace showing the self-resonance oscillations of the receiver, so
we are NOT see more echos we are seeing the resonant self-oscillations of the receiver.
To get around this needs one of -
- Damping resistor across receiver terminals to drain the energy away quicker. Somewhere around 10k should be sufficient.
- Threshold signal (really squelch) to instead of changing the comparator threshold CLAMP the receiver terminal to GND to stop oscillations
Alternatively the receiver wired to mid rail remove the incoming AC coupling capacitor, then clamp the incoming signal to mid rail.
Do the units actually detect the correct phase or point to measure distance
This is highly dubious I looked at a working unit that could easily take multiple readings if there was 30 ms after each reading had completed.
I then checked things like -
- TX Burst to Echo timing of both phases
- Receiver pin against reported echo pulse
I got some interesting results
Basically the time from start of TX burst to setting ECHO high is 202 µs.
Looking at Echo point which was correctly going on a low phase (but NOT zero crossing) it appeared to be at wrong time as effectively it
SHOULD be triggering at 202 µs AFTER the first cycle starts and the unit is in self-resonance oscillation on the zero
crossing at the end of the eight cycle going negative.
Timings showed -
Back to top
Speed of Sound and Distances
Previous Pages cover
Interested in something similar contact sales.