3 Implementation

The functionality of the Core Independent Ultrasonic Distance Measurement application is centered around the Configurable Custom Logic (CCL) module. It enables input MUXing to two Lookup-Tables (LUTs) with configurable logic. In this application, one LUT is used to control the transmit line of the ultrasonic transducer, and the other is used to filter the receive line. "Time of flight" can be measured by feeding both LUT outputs into a sequential control block, specifically an SR latch. The result is that the output of the latch indicates "time of flight". This setup can be seen in the figure below.

Figure 3-1. Ultrasonic Distance Measurement using Configurable Custom Logic Peripheral
The corresponding timing functionality is depicted in the figure below. The first three lines correspond to control of the ultrasonic transducer transmit line:
  • Signal (1) is the output from timer/counter type A, which is set up to produce an approximate 40 kHz PWM
  • Signal (2) is a mask produced by timer counter type D, set up to be low when an ultrasonic burst should be emitted, and the rest of the time high
  • These two signals are the inputs to LUT1, the output of which (1 & !2) is connected to the transmit line of the ultrasonic transducer
The result is a specifically timed ultrasonic transmission at the PWM frequency. The initial edge of the output will also "reset" the SR latch, and start the timer/counter type D capture counter (the beginning of "time of flight").
The next three lines correspond to the control of the ultrasonic transducer receive line:
  • Signal (3) is a mask produced by timer counter type D, set up to be low when the receive line is enabled, and high when transmitting. The transmission will be picked up by the receive line of the ultrasonic transducer and needs to be masked because it will be erroneously detected as the reflected signal. It extends slightly past the transmission length to account for resonance. Because both masking signals (2 and 3) are produced by the same timer, they are synchronized and therefore the transmission is effectively masked from the receive line.
  • Signal (4) represents the activity on the receive line, after being processed by the analog comparator
  • These two signals are the inputs to LUT0, the output of which (!3 & 4) represents the filtered receive line, only containing pulse reflections
When the reflected signal is detected by the analog comparator, the first edge will "set" the SR latch, and timer counter type D capture will occur, thereby effectively measuring "time of flight" (SR Latch line in the figure).
Figure 3-2. Ultrasonic Distance Measurement Timing Diagram