# Let's Design and Build a (mostly) Digital Theremin!

Posted: 12/13/2012 7:52:37 PM

From: Northern NJ, USA

Joined: 2/17/2012

More thoughts on the pitch side DPLL:

It's really a DLL (delay locked loop) with the ability to free-run, because the frequency of the output is always that of the input (but delayed 90 degrees when locked).  In simulation and in reality it works better using just the integrated phase error term and without a proportional phase error term (fed to the loop filter).  This is an unstable topology for a true PLL.

XOR phase detection is bit multiplication.  XOR phase detectors only work correctly over a +/- 90 degree range, outside of which they give the wrong answer.  While out walking today I thought of a way to extend the phase range to a full +/- 180 degrees.  If the NCO is constructed so that it also has both in-phase and quadrature outputs (trivial) then these can be independently XOR mixed with the tank quadrature signal, with these two results XORed and fed to the loop filter.  This gives something highly similar to a Costas loop which is used extensively in communications for demodulation purposes.

So phase lock should happen over a wider range.  And perhaps as or more importantly there is 2x the opportunity to dither the NCO accumulator and therefore statistically expose this value to the outside world more frequently, increasing the precision of this value (when averaged over a given period of time).

It's great coming back to DPLLs after several years break because my thoughts have had time to settle (as well as go completely missing!) so I can approach them with a somewhat fresh viewpoint.  Books and papers on the subject are often simultaneously too seat-of-the-pants and too theoretical - it's really more control theory than anything else.  Here's a nice paper I found recently that approaches PLLs from that angle.  In it the author states "The experts in PLLs tend to be electrical engineers with hardware design backgrounds" which I guess is why the books on them tend to be hodgepodges of circuit topologies, light math to calculate various figures of merit, and rules-of-thumb.  Of all the courses I took in college, control theory has probably helped me more than anything else.

Posted: 12/13/2012 11:06:56 PM

From: Eastleigh, Hampshire, U.K. ................................... Fred Mundell. ................................... Electronics Engineer. (Primarily Analogue) .. CV Synths 1974-1980 .. Theremin developer 2007 to present .. soon to be Developing / Trading as WaveCrafter.com . ...................................

Joined: 12/7/2007

"Books and papers on the subject are often simultaneously too seat-of-the-pants and too theoretical" - Dewster

Yeah - The above is so true for much which is written about electronics and engineering in general .. Go through chapters where its all bl**dy obvious and elementary, then a sudden jump to a sea of maths, with no "bridge" to get you from one to the other.

I wasted some money buying a book "Excel Scientific and Engineering Cookbook" by O Reilly - which gives one tantilising pointers to using VB, but doesnt even show a simple Macro developed using VB. Few authors manage to take a subject and work through from "starter" (or whatever level it starts at) to as advanced as the book goes, without making "unbridged" jumps from one level to the next.. One of the best authors (and best books) I have found is Crenshaw with his "Maths Toolkit for Real-Time Programming" - He manages to take one from the simplest fundamental algorythms (square root for example) right through numeric calculus and dynamic simulation... Oh, (for me anyway) its tough going at times, but there are no gaps or jumps - everything can be understood if you understand what came before.

Fred.

Posted: 12/14/2012 8:30:02 PM

From: Northern NJ, USA

Joined: 2/17/2012

Fred, thanks for that book title, I'll definitely check it out.

Oops, Costas loop seems to require low pass filtering before the final multiplication, and even then it seems like it might lock on 180 out of phase half the time.  I'm still thinking about this but it doesn't seem to be going anywhere fast.

Got the LC meter in the mail today!  Checked all 10 of the Bourns 6310 chokes I bought a while back, all were within +/- 0.5mH or so (1%).  Two were open due to the way Mouser ships them all banging together in a bag.  They're quite fragile, Bourns should put some heatshrink over them or something. Checked out my home made inductance substitution boxes I use for speaker building, the higher ranges read a little low, but that's probably due to the high test frequency (which you can read by pressing the momentary "Func" button).  It would be nice to be able to set that.

Tried a couple of 10pF caps, some 1uF speaker xover caps, and a couple of large non-polar electrolytics and the meter seems to read them fine too. You *have* to calibrate it whenever you change ranges, and in the "large C" range it takes a while to even acknowledge you're pressing the "Zero" button.

There's some kind of large extraneous cutout in the faceplate plastic behind the decal that you can feel when you press on it, and the clear plastic covering the LCD is thin and a little smudgy looking, but for <\$40 shipped I probably shouldn't be complaining.  Nice to finally have a way to test all my coils and caps!

I bet a good Theremin designer could build the best LC tester in the world!

Posted: 12/14/2012 9:39:06 PM

From: Eastleigh, Hampshire, U.K. ................................... Fred Mundell. ................................... Electronics Engineer. (Primarily Analogue) .. CV Synths 1974-1980 .. Theremin developer 2007 to present .. soon to be Developing / Trading as WaveCrafter.com . ...................................

Joined: 12/7/2007

"I bet a good Theremin designer could build the best LC tester in the world!" - Dewster

I doubt it! ;-) .. The disciplines of theremin and instrumentation designs do have some overlap - but not much I think... Theremin designers (even the best) tend, I think, to be "sloppier" than what is required for professional test equipment design - and our area of focus is really quite narrow when it comes to determining capacitance / inductance / resonance.. Sure, we may be able to design the best tester for tiny capacitances - but one which can take a 1pF and resolve this to 10fF AND take a 10uF and resolve this to 10nF, and compute series inductance and resistance - not me! ;-)

When I look at whats inside my tiny Atlas LCR, I marvel - this was designed + built before custom ICs were available to do the job, and it is beautifully engineered, reliable and accurate. Looking at some of the really high-end pieces of kit they are crammed full of SMT analogue at the front end (complete with shielding boxes and inductors configured into the PCB) all controlled by a DSP and sometimes a seperate MCU for user / remote interfacing.

I think that "the best LC tester in the world" could only come about as a product developed by a highly competent team, which would need at least one "theremin type engineer" in it, but lots of other engineers and consultants.... But I think that almost every complex project or instrument (particularly where accurate analogue signals must be acquired and subsequently digitally processed) these days is beyond the ability of any individual to fully develop - or at least beyond their ability to engineer to "best in the world" standard.

Perhaps this is one of the things that makes the theremin so atractive to the likes of us - It is still possible, I believe, for an individual or small team of individuals who have imagination, dedication and reasonable competence, to engineer the best theremin in the world.. Even if we couldnt knock together an LCR tester which matched a \$100 Chinese import.

"thanks for that book title, I'll definitely check it out" -

Bear in mind that I am a complete maths dyslexic.. The book helped me because I can follow code a lot more easily than I can follow large formulae - so I can (with much sweat) actually see the required operations and why... If you can read an equasion, can manipulate an equasion, and understand whats being done from looking at an equasion, then this book may not be nearly so useful to you!

The book never really helped me with anything other than comprehending the operations - I still cannot manually manipulate anything complex - in fact, when I see a multi level formula with loads of symbols (even if I understand these) I have a mental blur - no matter what I do - write it out, whatever.. Its only when I can code it in C or lower level, or construct it in an excel (or multiple excel) cells, that I start to feel any competence with the maths at all.

Posted: 12/14/2012 10:35:10 PM

From: Northern NJ, USA

Joined: 2/17/2012

"But I think that almost every complex project or instrument (particularly where accurate analogue signals must be acquired and subsequently digitally processed) these days is beyond the ability of any individual to fully develop - or at least beyond their ability to engineer to "best in the world" standard."  - FredM

You're right, I was kind of exaggerating.  But I bet I could build something better than this LC meter for around \$100.  Better for Theremin use anyway.  Have the test frequency range be somewhat settable so that you're measuring the component in the ballpark of where it will be operating in circuit, and have an SRF test for inductors.

Fred have you seen Numerical Recipes in C? Chock full of stuff, I've got the older version.  Hacker's Delight by Henry S. Warren, Jr. is really interesting as well.

Posted: 12/15/2012 1:27:10 AM

From: Eastleigh, Hampshire, U.K. ................................... Fred Mundell. ................................... Electronics Engineer. (Primarily Analogue) .. CV Synths 1974-1980 .. Theremin developer 2007 to present .. soon to be Developing / Trading as WaveCrafter.com . ...................................

Joined: 12/7/2007

Hi Dewster -

Yes, I have Numerical Recipes in C - A great book, but at times it does make assumptions which 'disable' me from making best use of it, I will look into "Hackers Delight" , thanks.

A big part of me just wants to leave the maths - I have been through this struggle many, many times - Paid for private tuition when my inadequacies really became a problem, thought I was doing ok - but never got things right (My last big job, designing the RT control system for commutating a 36 phase in-wheel motor, was maths intensive - I was assigned a mathematician to work with me - but he couldnt make it work.. I ended up using mixed analogue and digital with nothing more complex than sine tables..) I want to be able to master maths because, to be honest, I feel stupidly ignorant.. There are many people who are obviously not as bright as me but who can run rings 'round me on maths - So I shouldnt have this problem.... :_(

"Better for Theremin use anyway"

Agreed! - There are lots of simple bits of kit which could be really useful for theremin designers / engineers, for which one cannot obtain affordable available equipment. Accurate measurement of small capacitances, and basic testing of inductors for SRF etc (perhaps even radiated fields) - a box with 2 inputs that shows which inputs frequency is > than the other, and low cost FET 'scope probes - these are the sort of items which are within grasp.

Fred.

Posted: 12/15/2012 4:50:28 AM

From: Northern NJ, USA

Joined: 2/17/2012

"... basic testing of inductors for SRF..."  - FredM

I would have been all over the Mastech MS5308 if it had SRF.  I mean SRF, come on, it's pretty basic and important thing to know about an inductor.  Maybe one can calculate it from the phase angle or something but I want a direct readout.  This cheapie <\$40 meter probably could do it if they removed the resonant capacitor and gave the oscillator enough range.

Don't beat yourself up over math (I probably know just enough to get me in trouble, and it's only after I have a pretty good feeling about what's really going on via simulation and a lot of thought).  In life it's always basic concepts first and math later, but they tend to teach it backwards because professors have to publish, and it is a pretty weird thing that much of nature can be described by a handful of simple formulae.  Both experimentation and formalism have their place, neither could exist without the other, but most discoveries happen by accident in the lab and all else proceeds from there.

I wish to god I'd taken more communications courses in college, but my first two classes were taught by math profs who couldn't relate the fundamentals to me ("look at this formula for stationarity") which almost completely turned me off to the whole thing (much like my devices class - ugh).  Nothing at all wrong with generalizing and math, but there's a time and a place.  Not sure how I feel about a purely hands on engineering curriculum either.  There's got to be a balance, and the concepts are often quite simple.  I guess one of the big problems with teaching/learning EE is it's so broad and diverse, not enough time really to even properly expose undergrads to the variety of stuff going on.

Posted: 12/19/2012 2:19:46 PM

From: Eastleigh, Hampshire, U.K. ................................... Fred Mundell. ................................... Electronics Engineer. (Primarily Analogue) .. CV Synths 1974-1980 .. Theremin developer 2007 to present .. soon to be Developing / Trading as WaveCrafter.com . ...................................

Joined: 12/7/2007

"I've got the older version.  Hacker's Delight by Henry S. Warren, Jr. is really interesting as well."- Dewster

I bought a 2nd hand (2007) copy of "Hackers Delight" which arrived yesterday - Many thanks for the reccomendation Dewster - I would never even have looked at a book with that title when looking for maths computing.. It is GREAT! - Just been browsing it, and I can go to any page and understand (after a little work sometimes) everything on the page - (Almost) No incomprehensible formulae or mysterious  symbols which look like they came off some Egyptian tomb! - And when I do come across these, the code unravels it in a way that "explanations" have never done for me.

And all sorts of mathematical mysteries I have struggled with for years now make sense (or at least are starting to make sense).

Thank you!

Fred.

Posted: 12/19/2012 2:53:41 PM

From: In between the Pitch and Volume hand ~ New England

Joined: 12/17/2010

awwwwwwwwwwwww... Peace between people, makes my theremin sing. :)

Posted: 12/19/2012 7:32:23 PM

From: Northern NJ, USA

Joined: 2/17/2012

"I bought a 2nd hand (2007) copy of "Hackers Delight" which arrived yesterday"  - FredM

Glad you are finding it useful Fred!  A lot of short and sweet stuff in there.  It's interesting that the implementation of operations such as division and mod aren't universally agreed upon in processors or high level languages.  Basic arithmetic is surprisingly complex at the lowest level.

I also own and have read the two Hennessy & Patterson texts on computer architecture and was expecting more in the way of what to include / exclude in a RISC instruction set, but they write about branch prediction, TLBs, very specific examples of pipelining, and other things that don't interest me much.

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