We acquired some piezoelectric ultrasound sensors (a sender and two receivers), with an operating frequency around 40 kHz, and we designed and sized the proper transmitting and receiving circuits. Of course, we could not use any more the algorithm already devised to calculate the path difference according to the phase difference between the two signals. In fact, the signal wavelength at 40 kHz is less than 9 mm and therefore this would be the maximum distance detectable without ambiguity. Clearly such a size is not enough to build a keyboard!
The first solution we thought about was the most widely used in measurement systems based on ultrasounds, such as in car parking sensors: working with pulse packets.
This approach was suggested also by a document by Texas Instruments: the waveforms on the oscilloscope screen shown on page 5 in the document are analogous to those that we could then observe ourselves on our circuits. Yet the difference is that we were working with a transmitter and two receivers.
The transmitter, controlled by a PIC, sends a periodic signal: within the period, at first a packet containing a certain number of pulses is sent, then for the remaining time nothing is transmitted. In this way the 40 kHz signal is modulated by a square wave: the maximum distance that can be measured is no longer imposed by the duration of the 40 kHz period, but it is imposed by the duration of the period consisting of the pulses at 40 kHz and the following silence. Much greater distances can be detected and the real restriction is imposed by signal attenuation.
Therefore, the transmitter sends regular pulse packets, which are received at different time instants by the two receivers, placed in general at two different distances from the sender. By measuring the time difference between the instant when the n-th pulse of the packet reaches the first receiver and the instant when it reaches the second receiver, the path difference can be estimated and then, with the same trigonometric calculation developed before, the position of the transmitter along the keyboard.
After realizing the physical system, already from the observation of signals with an oscilloscope we noticed a serious problem.
The transmitter sent a train of 10 pulses, but at the receiver we could see up to 20 pulses. The pulse amplitude at the receiver was initially small, grew to a steady-state value and then slowly faded, so that the "silence" period was much shorter at the receiver. This of course happened because the piezoelectric sensors have their own dynamics and oscillations, once excited, cannot stop instantly.
So far, nothing strange and nothing problematic. We thought it was sufficient deciding a threshold amplitude and considering, for purposes of comparison between the two receivers, the first impulse of the train that exceeded that amplitude threshold. So we wrote the DSP program. Yet the values of path difference provided at the end of our processing were almost always wrong, at least for a period or its multiples. Why?
The two receivers are not only two phisical objects with their own dynamic, but they are two distinct physical objects, built to behave as closely as possible, but never really identical. Here is the problem. Each of the two receivers had its own dynamic and the two dynamics were different! The pulse amplitude evolution was always slightly different on the two channels. Because of this problem, when setting a threshold, often the n-th pulse on one channel was compared with the (n+k)-th pulse on the other channel, unfortunately with k non-zero...
It was impossible to cope with such a problem. Even by changing the threshold, there was no possibility to avoid frequent errors of at least one period in determining the path difference, errors which would impact even more significantly on the determination of the sender position.
The only option at that point was to change strategy again, to try to avoid that the different dynamics of the two ultrasonic receivers had so much influence. Since we noted, in our initial experiments, that there were no problems when working continuously, without packets, we sought a way to transmit continuously, but at the same time modulate the signal emitted by the transmitter, so that the maximum detectable distance could remain well above 9 mm.