Sonarlike method detects fluid level
Figure 1 illustrates a simple, cost-effective method of measuring the height of fluid in a column by using ultrasonic waves. Two piezoelectric transducers generate and listen to the ultrasonic acoustical wave. First, the transmitter piezo element receives stimulation from a square wave that lasts three or four cycles. This technique produces the most efficient transfer of electrical energy to acoustical energy. The acoustical wave produced at the transmitter funnels down into the waveguide tube. The wave then concentrates at the tip of the funnel tube and disperses into the waveguide tube. Part of the wave, or "crosstalk," travels up toward the receiver. The other part travels down toward the fluid. The receiver detects and ignores the crosstalk component of the wave. Part of the crosstalk wave is absorbed in the reflection from the receiver, and the remaining energy propagates down toward the fluid. The receiver then listens to the wave that echoes off the surface of the fluid. The first of these waves that strikes the receiver is the component that has propagated toward the fluid. This component is the primary echo. The crosstalk wave arrives shortly thereafter with a reduction in amplitude; this wave constitutes the secondary echo.
The COP8 µC measures the time it takes to propagate a wave from an arbitrary point on the surface of the fluid to the receiver. You can choose any arbitrary point; the µC can offset, or compensate for, the point with the aid of external data. The mechanical system in Figure 1 has two major advantages. The first advantage is a cost savings in using two separate piezo elements. Piezo elements for only receivers and only transmitters are less expensive in the ensemble than a piezo element designed for both. The other advantage is the crude "mechanical diode" that the funnel tube forms. A high-intensity wave propagates from the tunnel, but the receiver recaptures only a small fraction of it. Figure 2 shows a typical wave- shape using Panasonic (www.panasonic.com) EFRTSB40KS and EFRRSB40KS piezo elements. Upon application of the chirp wave, the receiver immediately detects the crosstalk wave. After an interval, the receiver detects the primary echo, followed closely by the secondary echo.
Reducing the amplitude of the crosstalk wave is convenient (Figure 2 ). This reduction allows shorter waveguide tubes, increasing the versatility of the design. One simple way of reducing crosstalk is to adjust the receiver's distance from the funnel tip, thus moving the receiver to an antinode. Another possible adjustment is to reduce the length of the chirp. Figure 3 shows the acoustical waves after making the cited adjustments. In the circuit of Figure 4 , the COP8, IC1, pulses I/O port G5 at the piezo element's resonant frequency of approximately 40.3 kHz. This signal switches Q1 and energizes the series-LC tank circuit, which has the same resonant frequency as the piezo element. This tank circuit boosts the voltage across the piezo element from 5 to 25V p-p. The receiver then detects and discards the crosstalk wave. After a short interval, the crosstalk vanishes, and the COP8 begins listening to the output of the comparator and begins counting program cycles and, thus, time.
When the echo reaches the piezo receiver X1, IC2 amplifies the echo 1000 times. The amplified signal then routes to the LM111 comparator, IC3. The first echo component to reach the amplitude of the threshold set by R1 and R2 trips IC3 to a logic one, and the COP8 stops counting. Figure 5 illustrates this process. The COP8 starts listening at the rising edge of the trace labeled "COP8 Timed Interval," just after the crosstalk becomes silent. When the echo's amplitude crosses the comparator's trip voltage, the comparator's output switches high, and the COP8 stops timing. Armed with this timing data, converting the figures to a distance is trivial. One constraint is that the leading edge of the echo must occur after the disappearance of the crosstalk. This constraint demands an offset distance or an origin that meets the constraint. Assuming the constraint is satisfied, the distance is d=VAIR(t/2). The velocity of sound in air at room temperature is 345m/sec, or 0.345 mm/µsec. Solving for distance, d=0.172t mm, with t in microseconds.
If you apply this distance to the waveform in Figure 5 , the distance from the origin to the fluid's surface is 0.172 mm/µsec×(6750 µsec–4750 µsec)– =344 mm, or 13.54 in. The COP8 µC controls the fluid-level detector. Its first function in producing the waveform is to "chirp" the piezo transmitter. The µC uses its 16-bit programmable timer to perform this step. The timer's clock speed is the same as that of an instruction cycle, which is one-tenth of the oscillator speed (10 MHz). You set the appropriate timer control for PWM. This process produces a square wave of 40 kHz with 50% duty cycle. This figure represents the resonant frequency of the piezo elements (Figure 5). You should minimize the crosstalk because it is unusable for the measurement. The system should generate only three or four pulses to perform this step. More pulses create longer crosstalk and problems if the piezo receiver receives the crosstalk and primary echo at the same time. The timer in the µC starts and then experiences a short delay. During this delay, port G3 generates the square wave. The short delay limits the amount of pulses to the piezo transmitter.
While the waveform from the transmitter propagates down the tube, a delay ensures that the COP8 does not trigger during the crosstalk. The µC's timer characteristic then goes into input-capture mode. Because the LM111 has a common-emitter transistor output, the programming of port G2 uses the weak internal pullup, and then an interrupt occurs on a negative edge. At some predetermined time, the crosstalk is finished, and the timer starts and counts down until the interrupt occurs. When the negative edge arrives on the port pin, the results of the timer transfer to the upper and lower R1B. It remains on the port pin to convert the number in the R1B registers. Because the timer counts down, you need to subtract the number from the starting point to determine the actual time. The difference in fluid level determines whether you need a prescaler. Because the speed of the timer is 1 µsec, any value greater than 1 msec shows up as an over-range condition on the display. This example with a 2-ft change in fluid level uses a prescaler with a factor of four, meaning that the resolution decreases by a factor of four.
Once you determine the prescaler, you need to convert the data in the two 8-bit registers to a three-digit decimal equivalent for the three seven-segment LED displays. The conversion process is similar to counting. You set up three 8-bit registers and increment them each time the two 8-bit registers decrement. Consider the lower 8 bits of the hexadecimal number. Each time the lower 8-bit register reaches zero, the upper register decrements, and the lower bit begins at 0xFFh again. This process repeats until the hexadecimal registers equal zero. Each time a hexadecimal number decrements, a decimal-digit register increments. When the decimal-digit register reaches nine, the next decimal register increments, and so on. This operation produces three registers with a decimal-equivalent number.
The COP8 can then send the data to the display panel. You set the flags in the control register for microwire/plus serial I/O. This setting configures ports G4 and G5 as data out and clock, respectively. You configure ports G0 and G1 as output enable and strobe, respectively. You then use a look-up table to send the correct data to the display driver. The data loads into the serial-I/O register. The busy flag in the PSW register initiates the data transfer. The transfer continues at clock speed until all 8 bits complete the transfer. The process occurs for all three digits, starting with the least significant digit. Click here to download the assembly code for the COP8. You can find additional information about the COP8 at www.national.com/cop8.