A digital theremin built with off-the-shelf components

Posted: 12/15/2020 10:43:43 PM
Channel Road Amps

From: Lopez Island, WA

Joined: 11/25/2014

I recently finished building a digital theremin that has worked out very well.  Some of you might be interested in an article I wrote that describes it in detail.  It includes a recording of my rather poor playing on the instrument.  I am not including a link for the reason explained below, but you can find the article by going to channelroadamps and looking in the "ARTICLES" section.  I hope some of you will find it interesting.

I originally tried to post about this four days ago, with a link to the article.  My post went into moderation where it has been stuck ever since.  I haven't had any success contacting a moderator to resolve this problem.  Very frustrating.  I'll be surprised if this post appears, but I'm giving it another shot.

Posted: 12/16/2020 12:38:18 AM
pitts8rh

From: Minnesota USA

Joined: 11/27/2015

Does this work for you?

http://www.channelroadamps.com/articles/digital_theremin/

It looks like a nice write up.  I haven't read it yet but I will say that your aluminum foil simulation hand is the most sophisticated that I have seen yet!

Posted: 12/16/2020 1:45:42 AM
Channel Road Amps

From: Lopez Island, WA

Joined: 11/25/2014

Thanks, pitts8rh.  I was hoping somebody would be able to post the actual link to the article.  I think I ran into problems because I had been absent from the forum for about five years.

I'm glad you liked the artificial hand!  What worked best, though, was the ultrasonic ranging unit.

Posted: 12/16/2020 3:08:51 PM
dewster

From: Northern NJ, USA

Joined: 2/17/2012

Nice write-up John, thank you for that!  Sorry to hear about your posting trouble, I've been stuck in TW "moderation hell" a couple of times so I know how frustrating that can be.

I think everyone starts out investigating commercial offerings for resonant coils, capacitance detection, etc. only to come up mostly empty.  Solutions have to work over relatively large distances, provide detailed measurement values, and be responsive, which is a tough combination, and makes the Theremin a rather unique component target.

Using a digital PLL with an inductive phase detection scheme makes a ton of sense as it automatically keeps the coil at the resonance point, giving you quite high voltage at the antennas - have you measured the antenna voltage swings (I imagine they are in the hundreds of volts peak-to-peak)?  The PLL acts as a phase noise low pass filter and so has an inherent bandwidth - have you calculated / measured this?  (I'm just being curious here, not trying to needle you.)

"Solving" linearity directly in software once you get numbers pouring in to the processor is quite a luxury as it completely sidesteps all the half-baked series antenna coil hassles of analog Theremins, and allows you to adjust the sensitivity independent of the linearity.  Your hand capacitance data collection technique is quite novel!

Your pitch and volume inductors look very nice, have you had any issues with interaction between the two oscillators?  How about processing audio in bulk at 1kHz, any issues there?

Thanks again for posting this here!

Posted: 12/16/2020 5:14:45 PM
ILYA

From: Theremin Motherland

Joined: 11/13/2005

dewster,
do you have a feeling that John' theremin is another implementation of your way (omitting, of course, details and the synth part)?

John,
quite interesting article, it would be interesting to learn the mathematical background too!

Your ultrasonic technique is superb, but I see some problem. Yes, you can determine the hand position precisely, but  what about the position of the body? Its influence is of the same order as the position of the hand. 

Posted: 12/16/2020 5:45:20 PM
Channel Road Amps

From: Lopez Island, WA

Joined: 11/25/2014

Thanks for your comments, Dewster!

I have not tried to measure the antenna voltage swings.  I'm not sure how to go about doing that.  It seems like even a 10X scope probe would load and disturb the circuit too much to get a meaningful reading.  Is there a trick to it?  I did try holding a small neon bulb near the antenna, including touching one lead to it while I held the other lead.  But except for a brief flash that was probably from static electricity, it didn't glow.  The RLC circuit is being driven by a signal of only 2.9 volts P-P, so it's quite a bit less than what you'd see in a traditional vacuum tube theremin.

Using the circuit parameters derived from the curve fitting to the measured phase response, I think it should be possible to calculate the (theoretical) voltage swing at the antenna.  I'll see if I can do that later.


The PLL acts as a phase noise low pass filter and so has an inherent bandwidth - have you calculated / measured this?  (I'm just being curious here, not trying to needle you.)


No needling assumed!  I'm thrilled that you're interested.  I have not calculated or measured the PLL response, and I'll be the first to admit that I have a lot to learn about PLL theory.  This was my first experience with a PLL (hardware or software), and beginner's luck probably played a big role.  I just found something that worked and stuck with it.

There is one aspect of the PLL that might be a little bit uncommon.  On each iteration through a PLL loop, it starts with an error measurement (phase difference from the desired 90 degrees in this case) and then derives a correction (to the oscillator frequency in this case) to reduce the error.  (You understand that, of course.)  To derive the correction, the software uses the known characteristics of the RLC circuit to calculate how far from resonance the frequency must have been to yield the measured error.  In other words, it's not just a semi-blind correction like in a typical PID controller, but it incorporates knowledge of the circuit being controlled.  I'm sure that's been done many times before, but it's probably more feasible in a theremin than it is in many other applications.

"Solving" linearity directly in software once you get numbers pouring in to the processor is quite a luxury as it completely sidesteps all the half-baked series antenna coil hassles of analog Theremins, and allows you to adjust the sensitivity independent of the linearity.

Yes!  That's what I love about the digital approach.  No more finicky tuning issues.

Your hand capacitance data collection technique is quite novel!

Thanks, I have to admit I'm kind of proud of that. 

Your pitch and volume inductors look very nice, have you had any issues with interaction between the two oscillators?

At first I had a small issue with interaction, but it is solved now.  When the software does its self-calibration, it scans each oscillator over a fairly wide range of frequency to find the "resting" resonant frequency of each RLC circuit.  This is done simultaneously for the pitch and volume circuits.  Initially, the scanning ranges of the oscillators were too large, so they overlapped.  That is, the scan for the pitch antenna also covered the resonant frequency of the volume antenna, and vice versa.  There was enough interaction to confuse the scans.  But after I narrowed the scan ranges so they didn't overlap anymore, there was no problem at all with interaction.


How about processing audio in bulk at 1kHz, any issues there?

Nope, no issues there at all.  The DMA capabilities of the STM32 MCUs are fantastic.  The samples go out to the DAC like clockwork.  The DMA engine has the capability to produce an interrupt when a DMA transfer is half finished, so the software can refill the first half of the sample buffer while the second half is still transferring.  I've been really impressed with that chip.


John

Posted: 12/16/2020 5:58:05 PM
Channel Road Amps

From: Lopez Island, WA

Joined: 11/25/2014

Ilya,

do you have a feeling that John' theremin is another implementation of your way (omitting, of course, details and the synth part)?

No doubt that is true, and I hope it didn't seem that I was claiming originality for any of my work.  The article was just intended as a report on a fairly successful implementation.

Your ultrasonic technique is superb, but I see some problem. Yes, you can determine the hand position precisely, but  what about the position of the body? Its influence is of the same order as the position of the hand.

Agreed.  When I took the measurements, I tried to position my body in the same place as when I play the instrument.  I don't think it's possible to measure something like this perfectly, but it did produce pretty good results in terms of playability.

John

Posted: 12/16/2020 6:51:59 PM
dewster

From: Northern NJ, USA

Joined: 2/17/2012

"I have not tried to measure the antenna voltage swings.  I'm not sure how to go about doing that.  It seems like even a 10X scope probe would load and disturb the circuit too much to get a meaningful reading.  Is there a trick to it?"  - Channel Road Amps

Get a somewhat thin wire (jumper wire, wire wrap wire, coil wire, etc. it doesn't have to be super thin) 2 or 3 feet long and run it away from the Theremin and over to a capacitive divider consisting of 1pF in series with a 1000pF to ground.  Measure the voltage across the 1000pF with your 10x scope probe, multiply by 1000.  If the coil drive doesn't have significant resistance, I'm thinking you'll see ~300Vpp (given your 2.9Vpp drive, and your coil Q is likely ~100).

"There is one aspect of the PLL that might be a little bit uncommon.  On each iteration through a PLL loop, it starts with an error measurement (phase difference from the desired 90 degrees in this case) and then derives a correction (to the oscillator frequency in this case) to reduce the error.  (You understand that, of course.)  To derive the correction, the software uses the known characteristics of the RLC circuit to calculate how far from resonance the frequency must have been to yield the measured error.  In other words, it's not just a semi-blind correction like in a typical PID controller, but it incorporates knowledge of the circuit being controlled.  I'm sure that's been done many times before, but it's probably more feasible in a theremin than it is in many other applications."

From that, it's clear you understand that the coil has a phase gain that is extremely non-linear near resonance.  At resonance the gain is Q/pi, but it falls off quite precipitously to either side.  PLL loop gain directly sets the bandwidth of the PLL, so when the PLL is significantly unlocked and therefore off of the LC resonance, the reduced LC phase gain will cause the PLL bandwidth to plummet.  The system can be treated as linear if the PLL bandwidth is sufficient because lock will be more or less maintained, though it can cause the initial lock at startup to take longer than necessary.  But it could be an issue if the locked PLL bandwidth is too low, as it could then be forced off of resonance during normal play.  It sounds like you are aware of and actively compensating for this non-linearity, so the PLL bandwidth is less critical.

If the PLL has too much loop gain the bandwidth will be unnecessarily wide, and instability can result.  I think 100 to 200Hz or so is a good target here.

"Initially, the scanning ranges of the oscillators were too large, so they overlapped.  That is, the scan for the pitch antenna also covered the resonant frequency of the volume antenna, and vice versa.  There was enough interaction to confuse the scans.  But after I narrowed the scan ranges so they didn't overlap anymore, there was no problem at all with interaction."

It seems that 2:1 coil values can play rather nice together, placing the frequencies at 1:sqrt(2).  This is what the Theremini does (and I do in the D-Lev).

"No doubt that is true, and I hope it didn't seem that I was claiming originality for any of my work.  The article was just intended as a report on a fairly successful implementation."

Oh lord no.  The only thing I believe I can claim any credit for is the linearity correction formula I finally stumbled across.  The rest is a rehash of other people's ideas and some elbow grease.

John, have you tried for reduced sensitivity of the pitch field?  Normally it's around 1 octave for open/closed hand.  I personally find 1/3 octave more playable, but this isn't a general feature on most Theremins, so I feel rather alone in discussing the subject.

Posted: 12/18/2020 2:14:11 AM
Channel Road Amps

From: Lopez Island, WA

Joined: 11/25/2014

Dewster, your last post quadrupled my understanding of PLL theory, so thank you for that.  I have never quite understood what the units are for the loop gain.  Suppose the loop gain is -2, and I measure a phase error of +10 degrees.  Does that mean I would apply a frequency correction that would change the phase error by -20 degrees, to -10?  (If so, it would be unstable, of course.)  Or am I misunderstanding the concept?

Thanks for explaining the trick for measuring the voltage swing.  I assume you use a thin wire so that it doesn't act so much as an extension of the antenna.  I think the smallest capacitors I have currently are 22 pF, but I'll get some smaller ones next time I order parts.  Is it possible to make a 1 pF leaded capacitor that is really 1 pF in practice?


John, have you tried for reduced sensitivity of the pitch field?  Normally it's around 1 octave for open/closed hand.  I personally find 1/3 octave more playable, but this isn't a general feature on most Theremins, so I feel rather alone in discussing the subject.

The pitch field can be stretched or shrunk by the leftmost knob.  I am trying to follow Carolina Eyck's theremin method, so the default makes one octave correspond to the change from her low note position (closed hand, tipped back) to her high note position (open hand).  (This has required me to unlearn my original playing technique, unfortunately.)  By turning the knob, you can stretch or shrink the pitch field in increments of ¼ inch per octave, while keeping it linear.


The 2:1 ratio of inductors sounds about right to me.  I wasn't able to get them that far apart because I started with a pitch coil I had already made long before, and there wasn't room in the cabinet for a much larger volume coil.  But the volume antenna has more intrinsic capacitance than the pitch antenna, so it all worked out OK.  The pitch circuit resonates at around 438 kHz and the volume circuit at around 356 kHz, when nobody is standing near the instrument.

John

Posted: 12/18/2020 7:40:02 AM
Buggins

From: Porto, Portugal

Joined: 3/16/2017

What are the benefits from PLL?
Any oscillator is internally PLL which tracks constant phase for excitation signal.
Probably, measure of phase shift is just easy measurable by low resolution timer (difference between excitation signal frequency and LC resonant frequency is zoomed in with LC Q as phase shift). 
Frequency of excitation signal is being updated slowly by soft PLL while oscillator reacts on C change instantly.
With averaging, direct measuring of oscillator frequency (with timer capture + dma) is possible on modern MCUs.

John, do you see 60Hz main hum noise in sensor data? What is a hand to antenna distance for which main hum becomes visible?

You must be logged in to post a reply. Please log in or register for a new account.