TOF / TDC approach looks attractive but requires expensive ICs.
Probably, better theremin sensors implementation for Teensy 4.0 + Teensy SGTL5000 Audio Adaptor platform should use as much internal hardware as possible.
For pitch antenna, as much sensitivity as possible is required to have good enough resolutions at hand distances up to 80-90cm.
Internal timer resolution is only 150MHz, ADC has only 12bits. But there is another ADC available on platform, with dual channels, at least 16 bit resolution, sample rate 44100/48000 Hz, with ability to capture data via DMA w/o CPU load for every sample. It's Audio Adaptor Line In ADC. Probably, STGL is able to provide even more bits per sample.
Line In is capacitive decoupled, so only alternating voltage can be measured, in audible range, 50..20000Hz.
Proposed pitch sensor implementation:
* LC oscillator on NPN provides clean sine wave with amplitude near 3V for far hand distance, dumped a bit (how much?) when hand approaches antenna.
* MCU generates two synchronous 50% duty cycle 90 degrees phase shift reference clocks, with frequency 500-1000Hz higher than max oscillator frequency.
* 2 Analog switches + LP filters + opamp buffer implement heterodyne (osc sine passed to both switch inputs, ref frequency signals are connected to switch control inputs, and outputs are passed to lowpass filters with 20KHz cutoff frequency). OpAmp probably could be useful as input and/or output buffer(s).
* Two channels of heterodyne output have clean sine wave with PI/2 phase shift. Frequency should be 100-1000Hz for hand far from antenna, and 8000-15000 for hand near antenna. Amplitude of signals passed to LineIn probably should be reduced to standard LineIn range (1V?)
* Amplitudes of output signals will be probably slightly different due to components precision. So, MCU should measure amplitudes of both channels during calibration to compensate. 0 level will be probably good enough.
* MCU will get sampled values from Audio Adaptor via I2S input using DMA by frames (default frame size in Teensy Audio Library looks too big but may be reduced). Another approach - to use per sample IRQ and read sampled values / write generated signal w/o DMA for every sample.
* Two phase shifted samples s1, s2 give us high precision heterodyne signal phase using atan2(s1, s2). Difference of phase between two samples provides signal frequency. Precision of single sample phase value depends on signal amplitude and 1/2 of max amp will be about 14 bits. Averaging would increase precision.
* Measured frequency should be converted to note frequency according to calibration values and selected note range for usage in Synthesizer.
It's very close to classic analog theremins, but sensor output is quadrant, and frequency will not be used directly for playback, but instead will be converted to output range.
For volume antenna it's enough to have good resolution for distances up to 40-50 cm.
Proposed Volume sensor implementation:
* MCU generates reference frequency close to LC resonance.
* Reference frequency passed to LC, phase shift between input and output is detected with XOR to produce PWM.
* PWM signal duty cycle is converted to voltage using LP filter.
* 12 bit ADC will be used to read sensor output voltage
* MCU may read result of previous measure and start new measure in audio frame or sample IRQ
* ADC value non-linearity is close to C_hand = A*atan(B*frequency_difference_from_resonant)
* C_hand then should be converted to linear hand distance, and then to volume multiplier
Since there are two ADC modules in Teensy 4.0, one may be reserved for Volume sensor, while second can be used for reading analog signals from pots / pedals.
Proposed sensors hardware looks simple and sensitive enough for me.
Reading of sensors doesn't require big CPU resources (e.g. unlike SPI connected sensor).
Low latency (no DMA, per-sample IRQ, latency = 1..2 samples) implementation is possible if 0.5..2ms frame looks too long.
Occupied pins for Pitch sensor:
2 PWM output pins - reference frequency for heterodyne
2 Line In channels from Audio Adaptor, no MCU pins used
Pins for Volume sensor:
1 PWM pin for reference frequency generatin
1 analog input pin for reading of PWM LP output