Issue
150 January 2003
The
PSoC Range Finder
A
Simple Ultrasonic Distance Meter
by
Fabio Piana
Start
Micro Configuration The
Hardware
Practical Construction
Things To Consider
Sources and PDF
MICRO
CONFIGURATION
Several
PSoC microcontroller resources were used in this project.
I applied the following PSoC digital resources: five
8-bit counters, an 8-bit serial transmitter, two 8-bit
PWMs, and a digital inverter. I implemented the following
analog resources: one programmable gain amplifier (PGA),
two two-pole passband filters, a programmable threshold
comparator, and a reference multiplexer. In addition,
I used the EEPROM and LCD toolbox software modules.
Photo
2 is a screen shot of the PSoC Designer with the Device
Editor showing the placement of the PSoC’s digital and
analog resources. As you can see, a large number of
resources are required. All of the digital blocks and
several analog blocks are employed.
|

(Click
here to enlarge)
|
Photo
2—Note the placement of the PSoC’s resources. For
this application, all of the digital blocks are
required. |
The
software modules include the LCD toolbox user module
and a complete set of library routines that allows you
to write numbers and strings to a two-line LCD using
standard Hitachi HD44780 commands. An EEPROM emulation
library allows you to store important data in flash
memory space as if it were a physical EEPROM.
PRINCIPLES
The
transmission section is based on four digital blocks
allocated in the DBA00, DBA01, DBA02, and DBA03 blocks.
An 8-bit counter (called "TimeBase") provides a 17,240-Hz
time base frequency. Sound velocity depends on ambient
air temperature, which is calculated for an air temperature
value of 22°C:

where
T is equal to the air temperature (°C). So, for a middle
value of 22°C:

For
a round-trip ping, you have:

And
with a 24-MHz MCU clock:

An
8-bit counter (F40kHz) drives the ultrasonic transmitter
and a digital inverter (F40kHz_inv). The phase of the
voltage applied to the positive and negative terminals
of the sensor has been shifted 180°, so two times the
supply voltage is applied to the sensor.
The
40-kHz transmission enables an 8-bit counter (called
"Meter") that increments one step per centimeter. The
Meter clock input is TimeBase (17,240 Hz).
The
ultrasonic receiver’s negative terminal is connected
to the analog ground reference (AGND—pin 25, P02) provided
by RefMux_1, a reference multiplexer allocated in the
ACA03 block. The ultrasonic receiver’s positive terminal
is connected to an amplification chain based on a programmable
gain amplifier (PGA_1) and two two-pole passband filters
(BPF2_1 and BPF2_2). The first passband filter is designed
for a 40-kHz center frequency and a correspondent gain
of 33 dB. The second filter is also designed for a 40-kHz
center frequency, but it has a 10-dB passband gain.
Because of the discrete value of the capacitors integrated
in the switched-capacitor analog blocks, the real frequency
response is different from the nominal one.
Figure
2 shows the BPF2_1 and BPF2_2 frequency responses. The
BPF_2 output is sent to the programmable threshold comparator
(CMPPRG_1). When a 40-kHz signal is received, the CMPPRG_1
output is high logic level, so the software can read
it.
(Click
here to enlarge)
|
Figure
2a—This is the BPF2_1 frequency response graph.
b—The BSF2_2 frequency response graph is a little
different. For the filter design, I used the appropriate
Cypress filter design folder in Excel. |
There
are two different output devices in the output section:
an 8-bit pulse width modulator and an 8-bit serial transmitter.
In the former, the frequency of the rectangular signal
that’s available on the PWM output (P2.7, pin 5) is
approximately 780 Hz; its pulse width is proportional
to a measured distance value (5 µs per centimeter).
The latter is a standard TTL logic-level serial output.
Transmission parameters are 9600 bps, 8 data bits, 1
stop bit, and no parity bit. An 8-bit counter, Baud9600,
provides a 9600-Hz time base for the serial transmitter
block, SerialTX, with its output on P2.4 (pin 22). If
you need RS-232 interfacing, you can use an external
TTL-level RS-232 converter (e.g., the common, inexpensive
MAX232). This means that you can also interface the
RangeFinder to a PC or microcontroller-based system
with a standard RS-232 port.