【正文】
receive the ultrasonic reflected wave, the receiver circuit outputs a negative jump in the end of INT0 or INT1 interrupt request generates a signal, singlechip microputer in response to external interrupt request, the implementation of the external interrupt service subroutine, read the time difference, calculating the distance . Some of its source code is as follows: RECEIVE0: PUSH PSW PUSH ACC CLR EX0。 related external interrupt 0 MOV R7, TH0。 read the time value MOV R6, TL0 CLR C MOV A, R6 SUBB A, 0BBH。 calculate the time difference MOV 31H, A。 storage results MOV A, R7 SUBB A, 3CH MOV 30H, A SETB EX0。 open external interrupt 0 POP ACC POP PSW RETI For a flat target, a distance measurement consists of two phases: a coarse measurement and. a fine measurement:Step 1: Transmission of one pulse train to produce a simple ultrasonic wave.Step 2: Changing the gain of both echo amplifiers according to equation , until the echo is detected.Step 3: Detection of the amplitudes and zerocrossing times of both echoes.Step 4: Setting the gains of both echo amplifiers to normalize the output at, say 3 volts. Setting the period of the next pulses according to the : period of echoes. Setting the time window according to the data of step 2.Step 5: Sending two pulse trains to produce an interfered wave. Testing the zerocrossing times and amplitudes of the echoes. If phase inversion occurs in the echo, determine to otherwise calculate to by interpolation using the amplitudes near the trough. Derive t sub m1 and t sub m2 .Step 6: Calculation of the distance y using equation ., the ultrasonic ranging system software design Software is divided into two parts, the main program and interrupt service routine, shown in Figure 3 (a) (b) (c) below. Completion of the work of the main program is initialized, each sequence of ultrasonic transmitting and receiving control. Interrupt service routines from time to time to plete three of the rotation direction of ultrasonic launch, the main external interrupt service subroutine to read the value of pletion time, distance calculation, the results of the output and so on..System initialization after the start timer T1 starts counting from 0 to enter the main program to wait for the T1 overflow into the T1 interrupt service routine when the time is reached。 T1 interrupt service routine will start a new ultrasonic transmitting, the square wave will be generated in the pin at the same time open the timer T0 timing, in order to avoid the diffraction of the direct wave, the delay 1ms and then, after the INT0 interrupt Enable。 the INT0 interrupt to allow open, if thisoccurs when the low is representative of the received echo signal, the interrupt request to INT0 interrupt service routine, the INT0 interrupt service routine will stop the timer T0 timing, read the time value of T0 timer to the appropriate storage to receive a sign of success。 main program detects reception hallmarks of success, the temperature subroutine is called, collecting the ambient temperature when the ultrasonic ranging, and converted the accurate speed of sound stored in RAM storage unit。 SCM calls the distance calculationsubroutine to calculate, calculate the distance between the sensor to the target object。 since the main program calls the display subroutine to display。 after pletion of the first launch, receive, display, the system will delay 100ms reT1 set initial value againstart T1 to overflow into the next ranging. If the obstacle is too far beyond the range that T0 overflow has not yet received echo ERROR is displayed back to the main flow into a new round of tests. E. CONCLUSIONS Required measuring range of 30cm ~ 200cm objects inside the plane to do a number of measurements found that the maximum error is , and good reproducibility. Singlechip design can be seen on the ultrasonic ranging system has a hardware structure is simple, reliable, small features such as measurement error. Therefore, it can be used not only for mobile robot can be used in other detection systems. Thoughts: As for why the receiver do not have the transistor amplifier circuit, because the magnification well, CX20106 integrated amplifier, but also with automatic gain control level, magnification to 76dB, the center frequency is 38k to 40k, is exactly resonant ultrasonic sensors frequency