|

The
PSoC Range Finder is a simple, inexpensive ultrasonic
distance meter that requires only the PSoC device, two
40-kHz ultrasonic transducers, two resistors, and two
capacitors. Typical applications include positioning for
robotics, generic distance measurement, and liquid-level
measurement without contact.
The
main program first sets up the analog and digital blocks,
and then tests for JP1 to determine whether to initialize
Normal or Calibration mode. In the former, the software
continuously runs the transmitted ultrasonic burst (ping)
and, after a period of time, waits for a returned ultrasonic
signal (pong). The time between the start of a transmitted
burst and the start of a received burst is proportional
to the distance between the PSoC Range Finder and an obstacle.
Polling the comparator bus register, you can measure this
time and store it in a RAM location. Finally, the range
value is written to the LCD (if present) and sent to the
serial interface. Then, the PWM duty cycle is set to a
value proportional to the distance between the PSoC Range
Finder and the obstacle.
In
Calibration mode, the software is similar to Normal mode,
but the measured value is compared to a constant value
(50). The resultant offset is stored in an EEPROM nonvolatile
memory location and added to the range measured in Normal
mode. TimeBase_int is the interrupt subroutine for the
time base 8-bit counter. When Timer 1 is greater than
the value of a period of time (time is necessary to prevent
false echoes caused by the lateral receiving of a transmitted
40-kHz burst), the software tests the logic value of the
comparator. If a pong is received, Timer 1 is stored in
the RAM location "range" and the time base interrupt is
disabled, so the value stored in the range location represents
the measured distance. If the comparator output is equal
to zero, then a PGA_1 gain is dynamically incremented
in 16 steps to modify the corresponding gain register,
so the far echoes are amplified.
Fabio
Piana
Italy
fabiopia@tiscali.it
Abstract
|
Full entry &
software (620k)
|