Introduction

Object ranging is essential in many types of systems.  
One of the most popular ranging techniques is ultra-
sonic ranging.  Ultrasonic ranging is used in a wide vari-
ety of applications including:

	Auto focus cameras

	Motion detection

	Robotics guidance

	Proximity sensing

	Object ranging

This application note describes a method of interfacing 
PIC16CXX microcontrollers to the Polaroid 6500 Rang-
ing Module.  This implementation uses a minimum of 
microcontroller resources, a CCP module and two I/O 
pins.  The two major components of the system are:

	Microcontroller

	Polaroid 6500 Ranging Module

The microcontroller performs the intelligence and arith-
metic functions for ultrasonic ranging, while the 
Polaroid 6500 Ranging Module performs the ultrasonic 
signal transmissions and echo detection.

Theory of Operation

Ultrasonic ranging entails transmitting a sound wave 
and measuring the time that it takes for the sound wave 
to reflect off of an object and back to the origin.  The 
reflection time is proportional to the distance that the 
object is from the source.  In this implementation, the 
sound wave is transmitted and received from the same 
transducer.  Therefore, a blanking interval is required 
between signal transmission and reception to eliminate 
false echoes, i.e., a transmitted signal being detected 
as its own echo.

Circuit Configuration

In this implementation, a PIC16C74 is connected to the 
ranging module as shown in Figure 1.  The RE0 and 
RE1 I/O pins are configured as digital outputs and are 
tied to INIT and BINH, respectively.  The CCP1 pin is 
configured as a digital input and is tied to ECHO 
through a pull-up resistor. The pull-up resistor is 
needed since the ECHO signal is an open-collector out-
put.  The CCP1 pin is configured for capture mode 
(CCP1CON). Figure 2 shows the timing relationship for 
VDD and the three signal lines (INIT, BINH, and ECHO).  

Note:	The ranging module requires 5.0 millisec-
onds to stabilize during power-up.

FIGURE 1:	Ranging module interface

FIGURE 2:	Timing diagram OF RANGING MODULE CONTROL LINES

The PIC16C74 is configured to use one of its internal 
timers, Timer1, in capture mode to measure the time 
between signal transmission and echo detection.  The 
PIC16C74 initiates a ranging cycle by first clearing 
Timer1.  Timer1 is then enabled and INIT is immedi-
ately asserted on the ranging module.  When INIT is 
asserted, the ranging module transmits a series of 16 
pulses on the transducer at 49.4 kHz.  The transmitted 
pulses reflect off the object and are received back at the 
transducer.

Since, the transducer is used for both transmitting and 
receiving sound waves, a blanking interval is needed to 
ensure that the transmitted signal has decayed on the 
transducer.  The transducer must be "clean" in order not 
to receive the false echoes.  In normal operation, the 
ranging module has a blanking interval of 2.38 millisec-
onds, which corresponds to a minimum detection dis-
tance of approximately 17 inches.  However, the BINH 
(blank inhibit) signal can be manipulated to reduce the 
blanking time on the transducer to allow for object rang-
ing as close as 6 inches.

In this implementation, the PIC16C74 asserts the BINH 
signal approximately 0.9 milliseconds after signal trans-
mission.  This enables the transducer to receive reflec-
tions off objects at a distance of  6 inches.  The ranging 
module asserts the ECHO signal when a valid reflec-
tion has been detected.  The PIC16C74 uses the 
ECHO signal to trigger a capture of the Timer1 value.  
The capture register contains the 16-bit value repre-
senting the elapsed time between signal transmission 
and echo detection.  The PIC16C74 then calculates 
object distance based on the Timer1 value, microcon-
troller clock speed, and the velocity of sound in the 
atmosphere.  	The basic equation for calculating dis-
tance is given below:

	Distance (inches) = TECHO time / 147.9 microseconds

Note:	The minimum high and low time for INIT is 
100 milliseconds, as seen in Figure 2.

	Design Considerations

There are several design considerations which must be 
taken into account and are listed below.

The absolute measuring distance supported by the 
ranging module is 6 inches to 35 feet with an accuracy 
of +/- 1%.

The distance output from the ranging module can be 
averaged over time to filter distance calculations.

In some applications, the gain of the receiver amplifier 
may be too low or too high and may need to be 
adjusted.  For example, if the transducer is mounted in 
a cylinder, the gain may need to be lowered to reduce 
false echoes within the cylinder.  In this case, R1 may 
be replaced with a 20K Ohm potentiometer to tweak the 
gain of the receiver amplifier to reduce false echoes.

In order for the Polaroid 6500 ranging module to oper-
ate properly, the power supply must be capable of han-
dling high current transients (2.5 A) during the transmit 
pulse.  The instantaneous drain on the power supply 
can be mitigated by installing a storage capacitor 
across the power lines at the ranging module.  A value 
of 500 microfarads is recommended.

A 200 millisecond interval is recommended  between 
ranging cycles (refer to Figure 2) to allow the trans-
ducer to clear.

The ECHO line requires a pull-up resistor (4.7K Ohm 
was used in this application).

There must be a common ground between the 
PIC16C74 circuitry and the ranging module.

Some applications may not need the resources of the 
higher end PIC16CXX devices. It is still possible to do 
this application using a device that does not contain a 
CCP module (for ECHO timing). The capture  function 
can be implemented in firmware. The effect of a firm-
ware implementation is that the resolution of the ECHO 
time would be 3 Tcy cycles versus 1 Tcy cycle for the 
CCP module.  Also, the firmware implementation would 
not allow other tasks to be performed while the capture 
function was occurring.

Refer to Appendix A for general ranging module speci-
fications.

Appendix A: Polaroid Module 
Specifications

Note:		This appendix contains general specifica-
tions from the Polaroid Ultrasonic Ranging 
System Manual.  Please refer to the cur-
rent Polaroid Ultrasonic Ranging System 
Manual for current information regarding 
ranging module design considerations.

Design Considerations in 
Ultrasonics

Range: (with user custom designed processing elec-
tronics)

Farther

a)	Use an acoustic horn to "focus" the sound (nar-
rowing the beamwidth).

b)	Use two transducers  1 receiver and 1 transmit-
ter  facing each other.

c)	Lower the transmitting frequency (which will 
decrease the attenuation in air).

Closer

a)	Use a shorter transmit signal (such as four 
cycles).

a)	Use two transducers  one to transmit, one to 
receive (eliminates waiting for damping time).

Resolution

a)	Above all, know the target and range well, and 
design a system with them in  mind.

b)	Use a higher transmit frequency.

c)	Look at phase differences of a given cycle of the 
transmitted signal and received echo (as 
opposed to using and integration technique).

d)	Increase the clock frequency of the timer.

Accuracy: (again, you must have a well defined target)

Temperature Compensate

a)	Use a second small target, as a reference, at a 
known distance in the ranging path (such as a 
1/4" rod several feet away), process both ech-
oes, then normalize the second distance with 
respect to the first, since t1/d1 = t2/d2.

b)	Incorporate a temperature sensing integrated 
circuit to drive a VCO to do the distance interval 
clocking.

c)	To increase sensitivity of detection circuit 
change the value of c4 from 3300pf to 1000pf on 
the 6500 Series Ranging Module.

Beam Width:

Increase

a)	Use an acoustic lens (to disperse the signal).

b)	Decrease the transmitting frequency.

c)	Use several transducers to span an area.

Decrease

a)	Use an acoustic horn (to focus the sound).

b)	Increase the transmitting frequency.



TABLE 1:	Recommended Operating conditions

MIN.

MAX.

UNIT

Supply Voltage, VCC

4.5

6.8

V

High-level input voltage, VIH

BINH, INIT

2.1

V

Low-level input voltage, VIL

BINH, INIT

0.6

V

ECHO and OSC output voltage

6.8

V

Delay time, power up to INIT high

5

ms

Recycle period

80

ms

Operating free-air temperature, TA

0

40

C



TABLE 2:	Electrical characteristics over recommended ranges of supply 
voltage and operating free-air temperature (unless otherwise 
noted)

Parameter

Test Conditions

MIN

TYP

MAX

UNIT

Input current

BINH, INIT

V1 = 2.1V

1

mA

High-level output current, IOH

ECHO, OSC

VOH = 5.5V

100

mA

Low-level output voltage, VOL

ECHO, OSC

IOL = 1.6 mA

0.4

V

Transducer bias voltage

TA = 25C

200

V

Transducer output voltage (peak-to-peak)

TA = 25C

400

V

Number of cycles for XDCR output to reach 400V

C= 500 pF

7

Internal blanking interval

2.38*

ms

Frequency during 16-pulse trans-
mit period

OSC output

49.4*

kHz

XMIT output

49.4*

Frequency after 16 pulse transmit 
period

OSC output

93.3*

kHz

XMIT output

0

Supply current, ICC

During transmit period

2000

mA

After transmit period

100

* These typical values apply for a 420 kHz ceramic resonator.

Appendix B: Firmware Listing

MPASM 01.02 Released      XDCR.ASM   11-14-1994  9:29:15                 PAGE  1

LOC  OBJECT CODE     LINE SOURCE TEXT

  VALUE



		     	0001 ;  XDCR.ASM 

		     	0002 ; 

		     	0003 ;  This routine continually executes ranging cycles in the 

		     	0004 ;  following order: 

		     	0005 ; 

		     	0006 ;     1) Timers and Flags are cleared 

		     	0007 ;     2) Ranging Cycle Executes 

		     	0008 ;     3) Distance is Calculated (to 0.5 inch) 

		     	0009 ;     4) HW is re-initialized for next cycle 

		     	0010 ; 

		     	0011 ;  The processor uses a 4MHz oscillator, so all timing 

		     	0012 ;  calculations are referenced to that.  The calculated 

		     	0013 ;  distance is a 16-bit result in the ACCbHI:ACCbLO registers. 

		     	0014 ; 

		     	0015  

		     	0016         LIST P=16C74, F=INHX8M 

		     	0017 ; 

		     	0029  

		     	0030 ;******************  

		     	0031 ; Bank 0 Registers 

		     	0032 ;****************** 

		     	0033 ; 

		     	 0034 ;  TMR1 is off, Prescaler is 1 for a capture timeout of 65 msec 

0000 0190		     	0035    clrf    T1CON 

			0036 ;  Set to capture on every rising edge 

0001 3005				0037    	movlw   0x05 

0002 0097				0038    	movwf   CCP1CON 

		     	0039 ;  Clear the Ports 

0003 0185     0040    	clrf    PORT_A 

0004 0186     0041					clrf    PORT_B 

0005 0187     0042					clrf    PORT_C 

0006 0188     0043					clrf    PORT_D 

0007 0189     0044					clrf    PORT_E 

				0045 ; 

		     	0046 ;******************  

		     	0047 ; Bank 1 Registers 

		     	0048 ;****************** 

		     	0049 ; 

0008 1683			0050    bsf     STATUS,RP0      ; Set RP0 

			0051 ; 			Port A is Digital, Port E is Digital 

0009 3007			0052    movlw   0x07 

000A 009F			0053    		movwf   ADCON1 

		     	0054 ;  Configure CCP1 (RC2) as an input, and all other ports  

		     	0055 ;  as Outputs, (RE0 = INIT, RE1 = BINH) 

000B 0185			0056		clrf    TRIS_A 

000C 0186   	  0057				clrf    TRIS_B 

000D 3004			0058		movlw   0x04 

000E 0087			0059   		movwf   TRIS_C 

000F 0188			0060   		clrf    TRIS_D 

0010 0189			0061   		clrf    TRIS_E 

0011 1283			0062   		bcf     STATUS,RP0      ; Clear RP0 

0012			0063 Xdcr 

		     	0064 ; 



MPASM 01.02 Released      XDCR.ASM   11-14-1994  9:29:15                 PAGE  2

LOC  OBJECT CODE     LINE SOURCE TEXT

  VALUE

			0065 ;  Initialize Timers and Flags 

			0066 ; 

0012 1010		     	0067    		bcf     T1CON,0         ; Disable TMR1 

0013 018C			0068		clrf    PIR1            ; Clear Timer1 Overflow Flag & Timer1 Capture Flag 

0014 018E		 0069				clrf    TMR1L           ; Clear TMR1L 

0015 018F			0070		clrf    TMR1H           ; Clear TMR1H 

0016 0195			0071		clrf    CCPR1L          ; Clear CCPR1L 

0017 0196			0072		clrf    CCPR1H          ; Clear CCPR1H 

0018 1409			0073		bsf     PORT_E,0        ; Set INIT High on Ranging Module 

0019 1410			0074		bsf     T1CON,0         ; Enable TMR1 

001A 21F3			0075		call    DEL_9           ; Delay 0.9 msec for transducer to stabilize 

001B 1489			0076		bsf     PORT_E,1        ; Enable Transducer to Receive (BINH) 

001C     			0077 		chk_t1 

001C 190C			0078		btfsc   PIR1,2          ; Check for Capture 

001D 2822			0079		goto    chk_done        ; Jump if Capture 

001E 1C0C			0080		btfss   PIR1,0          ; Check for TMR1 Overflow 

001F 281C			0081		goto    chk_t1          ; Loop if nothing happened 

0020 1010			0082		bcf     T1CON,0         ; Turn off TMR1 

0021 2833			0083		goto    ovr_flo         ; Capture event did not occur 

0022			0084		chk_done 

		    	0085 ; 

		    0086 ; Calculate distance to 0.5 inch resolution 

		    	0087 ; 

0022 1010			0088		bcf     T1CON,0         ; Turn off TMR1 

0023 0815			0089		movf    CCPR1L,W        ; Move LSB into W 

0024 00A2 			0090		movwf   ACCbLO          ; Move LSB into ACCbLO 

0025 0816			0091		movf    CCPR1H,W        ; Move MSB into W 

0026 00A3			0092		movwf   ACCbHI          ; Move MSB into ACCbHI 

0027 304A			0093		movlw   0x4A            ; Move 75usec/0.50in into W 

0028 00A0			0094		movwf   ACCaLO          ; Move LSB into ACCaLO 

0029 01A1			0095		clrf    ACCaHI          ; Clear MSB (ACCaHI) 

002A 208F			0096 		call    D_divF          ; Call 16-bit/8-bit routine  

			0097								  ; which is described in 

			0098                               ; Application Note 544 

002B 3025  			0099		movlw   0x25            ; Check remainder to see if 

002C 0224			0100		subwf   ACCcLO,W        ; we should round up... 

002D 1803  			0101		btfsc   STATUS,CARRY    ; If Remainder < (0.5 * Divisor), skip 

002E 0AA2			0102		incf    ACCbLO,F        ; Round up 

002F 1903  			0103		btfsc   STATUS,Z        ; Check low byte for wrap around 

0030 0AA3  			0104		incf    ACCbHI,F        ; If LSB wrapped, increment high byte 

0031 1D03 			0105		btfss   STATUS,Z        ; Check high byte for wrap around 

0032 2835			0106		goto    done            ; High byte didn't wrap 

0033       			0107		ovr_flo 

0033 01A2			0108		clrf    ACCbLO 

0034 01A3  			0109		clrf    ACCbHI 

0035       			0110 		done 

0035 21FD			0111  		call    DEL_100         ; Wait 100 msec before clearing HW. 

0036 1009 			0112 		bcf     PORT_E,0        ; Disable INIT 

0037 1089  			0113 	bcf     PORT_E,1        ; Disable BINH 

0038 21FD			0114  		call    DEL_100         ; Wait 100 msec before enabling HW.  

0039 2812  			0115 		goto    Xdcr 

			0116  

			0120  

MPASM 01.02 Released      XDCR.ASM   11-14-1994  9:29:15                 PAGE  3

LOC  OBJECT CODE     LINE SOURCE TEXT

  VALUE

			0149  

			0150 		end 

			0151  

MEMORY USAGE MAP ('X' = Used,  '-' = Unused)

0000 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXX------

0040 : ---------------- ---------------- ---------------- ----------------

All other memory blocks unused.

Errors   :    0

Warnings :    0

Messages :    0


AN597
 Implementing Ultrasonic Ranging
BINH

INIT

ECHO
TRANSMIT
POLAROID 6500 RANGING MODULE
RE1

RE0

CCP1
PIC16C74
TRANSDUCER
Author:	Robert Schreiber

	Logic Products Division


Parameter

Number

Symbol

Characteristic

Min

Typ

Max

Units

1

Tpu

Ranging Module Stabilization Time

5.0





ms

2

TBINH

Blank Inhibit Time

0.9

2.38



ms

3

TECHO

Echo Time









4

TINIT_H

High Time for INIT

100





ms

5

TINIT_L

Low Time for INIT

100





ms

VDD

INIT

BINH

ECHO
