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

Posted: 7/29/2014 5:17:25 PM
dewster

From: Northern NJ, USA

Joined: 2/17/2012

Was just poking around eBay today and ended up bidding on and winning one of these ($3.59, free shipping from China!):

http://www.ebay.com/itm/Digital-Optical-Toslink-or-SPDIF-Coax-to-Analog-L-R-RCA-Audio-Converter-Adapter-/191234669182

This might be the easiest, simplest, and least expensive solution for getting high quality audio out on my digital Theremin.  Generate SPDIF in the FPGA, run it and 5V power over to this box, and it's game over.  Too bad it doesn't have a headphone output, though line level can often drive headphones.

Posted: 7/29/2014 5:56:06 PM
FredM

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

Makes a great deal of sense! - Digital Theremin with digital (optical / SPDIF or whatever) output .. Supply a DAC to those who want one, studios etc often have desks with digital input... No risk of HF on analogue audio outputs, no ground loop problems particularly if optical.

And no real problem for those who want analogue audio from their theremin - provided you leave enough space in the box to fit one of these if required!

Fred.

$3.59 inclusive! Couldn't buy the box and connectors for that!  - Even the $9 "buy now" price is ok, and would probably drop to $5 if you bought 10+

Posted: 7/29/2014 6:34:33 PM
Touchless

From: Tucson, AZ USA

Joined: 2/26/2011

Dewster you stole these. I get mine from Amazon for ~$20 a set. I have a couple of tube theremins that I use them exclusively to give electrical isolation through a Toslink cable to the follow-up theremin equipment. They also give me a predictable theremin output load for the best audio results. I am learning.

T

Posted: 8/3/2014 2:38:11 PM
dewster

From: Northern NJ, USA

Joined: 2/17/2012

Been working on the digital heterodyning & period measurement portion of the design.  It looks like this:

  NCO => XOR => LPF => LPF => LPF => HPF => period count => LPF => period measure

The MSB of the NCO and external LC oscillator are mixed in the XOR stage.  The XOR result is "gained up" by simply assigning a large positive / negative value to it depending on whether it is a 1 or 0.

A cascade of three identical first order low pass filters follow, all with an RC time constant of 2^6.  For Fs=160MHz, this gives a -3dB point of:

  Fc = -ln(1-1/RC)*Fs/(2*pi) = 401kHz

A first order high pass filter follows this and has the same RC of 2^6 and hence the same cutoff.  Theoretically the filtering order isn't important, but I positioned here at the end for numeric reasons, and only the sign of the result is used, so sticking it at the end means the full HPF output doesn't need to be registered.  The elimination of DC and the suppression of low frequency content is necessary for good thresholding.

What's surprising to me is that this chain of filters works so well (in my limited simulation) for difference frequency edge detection over a wide range of input frequencies.  A 2:1 input frequency range from the 2.5MHz LC oscillator can mix down to 1.3MHz : 20kHz; or 65:1 range feeding the filters.  (In practice, a 2:1 LC frequency change shouldn't happen unless the antenna is firmly grasped by the player.  Touching the antenna with a fingertip gives around 15% frequency change on my setup.  Pinching the antenna between two fingertips gives around 40% frequency change.  Note that the antenna I'm using has a layer of heatshrink tubing covering it.)  This is essentially a digital implementation of the analog circuitry found on the Open.Theremin (and I'm rather curious as to how it responds to a grasped pitch antenna?).

Next is the "period count" component which counts both rise-to-rise and fall-to-fall edges in terms of system clocks, and sends these counts to a low pass filter.  The RC here is 2^4 but the cutoff is variable because it depends on how fast the filter gets the period counts.  Longer periods clock the filter more slowly and give a lower cutoff point, which works out nicely for far field SNR.  For a nominal far field heterodyne of 50kHz, the filter will update at a Fs=100kHz rate (since we are getting two period measurements per cycle).  This yields a cutoff of:

  Fc = -ln(1-1/RC)*Fs/(2*pi) = 1.03kHz

The LPF is also used to blend the rise-to-rise and fall-to-fall periods, and the following "period measure" component only uses every other sample from the filter to get us back to a (far field) 50kHz sample rate.  If the samples come at a rate higher than 100kHz then the logic in this component adds the period counts together until 2^n samples are obtained at <100kHz rate, whereupon the sum and the number of samples are output.  This is another low pass filter (an adjustable comb filter actually) because it performs an integrate and dump action.  I need this so that the processor interrupt rate is guaranteed to be below 100kHz, which should give 200 or so instructions minimum for the thread to operate on the data.  The integrate and dump action shouldn't kick in until the hand is somewhere around the near field (@ ~200mm if my other simulations are to be believed) and hopefully the transitions will go unnoticed.  The sum being 2^n samples is easily handled by the processor: a simple right shift will align the sum for further filtering and processing in software (no time consuming division needed).  I feel that it is probably best to keep the sample rate comfortably above ultrasonic.

If the integrate and dump mechanism generates audible artifacting then I could simply feed the filtered period counts directly to the processor and dedicate one thread to pitch data acquisition.  20MHz / 1.3MHz = 15 cycles minimum, which is probably sufficient to respond to the interrupt and toss the sample into a simple software LPF, to be further processed by a separate thread at a lower rate.

I have written and verified SystemVerilog code for the above and am anxious to bolt it onto the register set of the latest version of Hive, but unfortunately this will have to wait until after summer vacation.

[EDIT] Offset heterodyning with period measurement as described above requires one further numerical "adjustment" to yield a working pitch number.  If, say, the NCO is set ~50kHz higher than the LC oscillator frequency with the hand @ the null point in far field, then we get 50kHz difference frequency.  As the hand approaches the antenna the frequency difference increases, much as a traditional Theremin but without the null.  From a period perspective the 50kHz period count is large, and this count decreases as the hand approaches.  So we pick a number that is around the value of that of the period count when the hand at the null point (160MHz/50kHz = 3200) and subtract the period count from this to get a pitch number that goes from ~0 @ null and increases as the hand approaches the antenna.  From there we can do other things like take log2 and then linearize, offset, multiply, send to a "tuner"; then do exp2 and feed this to the sound generating section of SW/HW.

SV code: http://www.mediafire.com/download/vki8q8l3szhocoy/diff_period_sv_2014-08-03.zip

Posted: 8/3/2014 10:32:01 PM
FredM

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

WOW!

If this works as well as it sounds like its going to, then you have a digital system like no other.. Real exciting.

Oh, BTW, I am thinking on a different line to you.. ;-)  .. I am thinking in terms of this being a DFE (Digital Front End) for an analogue theremin, LOL ;-)

If you can (as it seems clear you can) numerically heterodyne, filter and process the positional data at high resolution and low latency, then this should be easily to output directly as voltage, capable of directly driving CV synths (1V/Octave) or any CV modules (including my CV theremin ;-).

Oh, I know - utter blasphemy! ;-) ... But having both digital (wave-table or whatever) output AND having the ability to slave analogue directly to tracking the positional data, particularly if one of these analogue voices was a true heterodyning theremin, well, IMO, it would cover the full spectrum of possible users needs or idiosyncrasies.

If the front-end is good, has stability and linearity and adjustable span and low latency, high resolution and acceptable low quantization, then everything needed has been achieved for a universal "controller" or "front end" - And sure, a good digital voice with this will make almost everyone happy..

But the digital theremin market will be quite cluttered quite soon - There is nothing available at this time for the high-end analogue "true theremin" seekers - The reason for this is simple - they are comparatively few, the cost of development and technical difficulty with the standard AFE (and the fact that adding features like adjustable span complicates thing further) has made it uneconomic to develop for this market - most people trying to do this have sunk before they got product to market.

What you have done may hold the key to satisfying everyone.

Fred.

Posted: 8/4/2014 3:01:51 PM
dewster

From: Northern NJ, USA

Joined: 2/17/2012

"If you can (as it seems clear you can) numerically heterodyne, filter and process the positional data at high resolution and low latency, then this should be easily to output directly as voltage, capable of directly driving CV synths (1V/Octave) or any CV modules (including my CV theremin ;-)."  - FredM

That is totally doable, but unfortunately I'm not aware of any ready-made FPGA board with decent D/A.  A 2nd order Delta Sigma modulator in FPGA logic with analog (LC) 3rd order LPF would likely work, though that might spatter the area with RF.

"But the digital theremin market will be quite cluttered quite soon - There is nothing available at this time for the high-end analogue "true theremin" seekers - The reason for this is simple - they are comparatively few, the cost of development and technical difficulty with the standard AFE (and the fact that adding features like adjustable span complicates thing further) has made it uneconomic to develop for this market - most people trying to do this have sunk before they got product to market."

I agree.  Bob M. seems to have spent a large chunk of his life designing Theremins, but most don't have near that kind of time to devote to a product with so many nuances and so little chance for monetary profit, and as a result many of the digital products have been somewhat disappointing.

Posted: 8/4/2014 8:48:10 PM
FredM

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

"That is totally doable, but unfortunately I'm not aware of any ready-made FPGA board with decent D/A.  A 2nd order Delta Sigma modulator in FPGA logic with analog (LC) 3rd order LPF would likely work, though that might spatter the area with RF." - Dewster

How about I2C or SPI into one of the many dual 14 or 16 bit DAC's ? .. In fact, all one would need is a serial port and external DAC board for those who wanted it - one really doesnt want to go compounding possible problems by splattering any RF though ;-)

Parts like the AD5563 (16 bit dual) clock in at about £5 one off - One can get quad 16 bit Dacs so could even output your audio and CV's with one of these.. Or even just a pair of those boxes shown above - one for audio one for control signals (CV's)

But all that is an aside - easily added after you have a full digital theremin up and running - Sorry I mentioned the above really, its the kind of distraction you dont even need to think about right now! ;-).. Its just that the idea of a DFE hadn't occurred to me until your prior post and I got real excited by the idea! ;-)

Fred.

Posted: 8/4/2014 9:21:56 PM
dewster

From: Northern NJ, USA

Joined: 2/17/2012

"How about I2C or SPI into one of the many dual 14 or 16 bit DAC's?" - FredM

I've actually got some older code for a SPI interface from back when the digital Theremin project was on the Xilinx demo board (which had SPI ADC and DAC).  But, truth be told, I guess I'm trying to avoid any complex PCB layout.  The displays and rotary encoders and other assorted flotsam seem doable with double sided cheeser fab, not sure I want to be soldering tiny surface mount ICs and the like.  This project is rather constrained with the need to keep manufacturing costs and complexity to a minimum, but maybe I'm not thinking big enough and making it harder than it should be?  Buying the FPGA on a board with regulators, 50MHz xtal, and configuration memory seems like a good move, and plugging / cabling this into oscillator boards and control display boards is my current cunning (?) plan.  You have a lot more experience with manufacturing so I'd be very interested in your take on this.

Sorry I mentioned the above really, its the kind of distraction you dont even need to think about right now! ;-).

No, it's an interesting idea.

Posted: 8/5/2014 8:22:00 PM
FredM

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

"Buying the FPGA on a board with regulators, 50MHz xtal, and configuration memory seems like a good move, and plugging / cabling this into oscillator boards and control display boards is my current cunning (?) plan.  You have a lot more experience with manufacturing so I'd be very interested in your take on this." - Dewster

Re: Manufacturing..

If you can get boards that have all the needed functions, in a format that is suitable, and these clock in at less than 4 times the price you think you could produce the board for if you had PCB's designed/Fabricated/Populated, and you are at early stage / small runs (<= 10) then I would absolutely buy the boards in.

It gets much more difficult to decide your 'route' if you need to produce any extra / "external" boards for other functions, because as soon as you need to produce any PCB / PWB, the cost of these is directly proportional to their area and quantity - a small run of small boards is likely to cost only a fraction less than the same quantity of larger boards capable of having all the circuitry on it.

With your design, you will need at least an external AFE, IMO, this is a board which has an advantage in being away from digital stuff anyway - If you make the AFE so that it includes both pitch and volume 'antenna' circuits, or the same board can be populated for either function.

If you need some other external functions, I would build there's onto the same PCB assembly as the AFE boards (increase their size) in a way that they can be detached from the AFE.

A little known fact (trick of the trade ;-) - The cheapest way to get boards is buying them on fixed size 'batch' deals - with these deals one selects one of the vendors offered sizes and can have a batch of single boards equal to or less than this size (no discount if boards are smaller)..

Most typical sizes / prices are in the order of:(double sided PTH FR4)

5cm*5cm* 10 boards = $25 = 25cm2 = $2.50/board = $0.10 /sq cm

10cm*10cm * 10 boards = $30 = 100cm2 = $3.00/board = $0.03 /sq cm

20cm*10cm * 10 boards = $44 = 200cm2 = $4.40/board = $0.022 /sq cm

But the catch is that only one 'design' is usually permitted on these boards, they are sized to fit the spare capacity on the large production runs for other boards - some manufacturers will reject a gerber if it looks like you have multiple separate 'boards' in the design even if you cut these boards out yourself.. They may try to double the price and say its a 'panel'.

However, if you take care on the layout to make the fact that there are more than one 'board' on the design (in particular, dont outline the individual boards or functions!) non-obvious, and separate the 'boards' with "breadboard" areas from one end to the other having 5 rows, and run a few lines (power, inputs, outputs, pot connections etc) to this area, you then have the ability to easily snap the boards apart in the center of these 'breadboards' and have your connection points taken care of!

For example, using 20cm*10cm  board, you could have a couple of 8cm*5cm (10cm*5cm - "breadboard") AFE boards, and a 8cm*10cm for other needed functions, and not risking a big sum of money -

When you want to go to reasonable quantities the whole picture changes - you can easily get down to 0.15c / cm2 and have exactly what you want (separate boards etc on a panel) - and IMO this is the point at which designing your own digital board (or copying your dev board and customizing it) and could probably get the SMD fitted by the Chinese manufacturer (or the whole panel assembled) for minimal extra cost.

If you can achieve whats needed using available boards, and produce a tidy affordale, sell-able product in this way, then, at this time I think your plan is the most sensible. IMO, the cost / complexity of designing and constructing a SMD FPGA board, even if one could squeeze this onto 'spare'  PCB which costs nothing, IMO its probably not worth doing.

On my desk I have some expensive circular (30cm dia) 3mm thick FR4 boards for a capacitive rotary sensor I designed - One side of the stator assembly is packed full of electronics, including analogue capacitance sensing and 3 FPGA's.(safety critical, so 3 sensor arrays are duplicated)  I designed and prototyped the original analogue side 3 years ago, it was shunted about and passed to a team for 'digitization' - I told them how to implement this but everything I specified was ignored.. they redesigned the analogue and simulated the system, analogue and FPGAs, but never prototyped the bloody thing - Built a batch and nothing worked.. I have been waiting for royalties and was told the sensor wasn't going into production because "it didn't work" - After about a year of argument I have finally managed to get their design and boards to look at - My client spent £120k on the crap on my desk, believed that I had given him a lousy design so hasn't thrown more work my way - and everything that was done was based on wrongly implemented analogue. I have a pile of useless hardware on my desk the cost of which could have cleared my debts and mortgage!

I have seen more wastage of PCB's (and personally probably quarter of the money I have wasted was this way) than any other component - It is extremely tempting, particularly with a complex design, to think that if you commit to a good PCB you will advance the development and make life easier.. Then when you look at the price of a couple of prototype boards, it makes sense to order 10+ or if overconfident, 25+... The difference in total cost is so marginal.

It would be sensible if the project was 'stable' and not subject to the whims of marketing or management or clients - but perhaps 50% of prototype boards ordered by the companies I have worked for arrived after design was changed or the project dropped or whatever, and were never even populated - my last employer wasted £30k in one year on boards which were rushed through on 2 day turn-around and at least 10 were always ordered, and they were sent direct for SMD assembly, and went straight into the trash because in the 5 days some directors had changed their minds.. This company went to the wall and was the worst I have seen in my career, but not that much worse than many others...

Fred.

Posted: 8/8/2014 1:59:29 AM
dewster

From: Northern NJ, USA

Joined: 2/17/2012

"If you can achieve whats needed using available boards, and produce a tidy affordale, sell-able product in this way, then, at this time I think your plan is the most sensible."  - FredM

Fred, thank you so much for your in-depth reply!   I saved it in my Theremin files to refer back to when board time comes.  You're helping feel that I'm doing the right thing.  (I too have seen many PWBs wasted, mostly I think due to the artificial/arbitrary schedules of big business - never enough time to do it right in the first place, all the time in the world to fix things later when the customer complains about the crappy product.)

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