I didn't find easy way to get timer resolution better than 150MHz on Teensy 4.0.
After simulation, I see that measurement of oscillator frequency on Teensy 4.0 would not give enough precision (at list w/o significant averaging == latency). Sensor sensitivity is one of main reasons why FPGA is usefult for digital theremin design.
But I'm going to try another solution - phase shift based sensor.
Reference clock is passed to LC tank input, L output is phase shifted depending on difference between ref clock frequency and LC resonant frequency.
When LC resonance matches, phase shift is PI/4. If does not match, shift is moving to 0 or PI/2, proportional to tan(x). Frequencies near resonance have good sensitivity (bigger phase shift), far from resonance phase shifts are being "compressed". Compression depends on LC tank Q.
Reference frequency and LC Q should be tuned to have good sensitivity for hand distances far from antenna.
Phase shift between LC tank input and output is being converted to PWM signal using XOR (74AC86). Frequency of PWM will be Fref*2, duty cycle = 50% when LC resonant = Fref, Fref, >50% if LC resonant frequency is lower than Fref.
According to LTSpice model, we can have 0.5..1pF antenna C change range as ~50% of output values range, while "compressing" other 1-2pF corresponding to closer hand distances to smaller output range.
LTSpice model may be found on Github
PWM should be filtered by LP filter (sallen-key 3rd order filter on rail-to-rail opamp with Fcut=10000Hz seems to be ok).
Simulation results (for different C_hand 0 pF.. 4pF with step 0.1pF) for R1=150 Ohm
There are artifacts due to FSHIFT exceeding 0..3.3V range - visible on output values near edges.
Tuned version: R2=470K between antenna and ground added, R1=100. Now output values are properly distributed and provide correct values even far from center.
Voltage on ANTENNA
Output value of LP filter can be measured by MCU ACD.
Teensy 4.0 has 2-channel 12-bit 1Msps ACD , able to measure two inputs (muxed from 10 available pins) simultaneously.
Fref may be generated on any pin using PWM or timer as divided 150MHz/div. Resulting step of possible frequencies is smooth enough to be able tuning Fref to match close enough to LC resonance (should be a bit lower than LC freq for hand far from antenna).
According to simulation, C_hand and voltage from filter have tan() relation.
Let's assume that effective LP output for all hand distances will vary in range 0.25Vcc..0.75Vcc - it gives us 11 bits of data.
Teensy 4.0 ACD has hardware averaging capabilities - it can make N measures, and sum them (N can be 4,8,16,32).
This gives us additional 5 bits of data for single x32 averaging measure - 16 bits in total.
It's possible to do this measure several times per sample (introduced latency is < Fsample). Additional averaging may give even more data bits (introducing some latency).
I'm checking capabilities of Teensy 4.0 audio interface.
Already checked that 24 bits instead of 16 and 48KHz instead of 44100 is possible.
It looks like it's possible to have I2S output one sample per interrupt (instead of DMA transfer of audio data frames). CPU speed is high enough to consider interrupt cost as acceptable (e.g. if it's <1%).
If it's possible - even oldtemecula could not say his usual speech about latency.
So, sensor would require only 4 pins from Teensy 4.0 MCU - 2 for pitch and volume reference frequency, and 2 ACD inputs.