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

Posted: 9/5/2013 3:19:05 PM
dewster

From: Northern NJ, USA

Joined: 2/17/2012

Thanks ILYA!  I guess I'm still looking for a fast-dry brush-on lacquer of some sort.

Posted: 9/5/2013 8:55:02 PM
dewster

From: Northern NJ, USA

Joined: 2/17/2012

INITIAL PITCH ONLY TRIAL?

I'm trying to figure out what my next best move with the digital Theremin development is.  I'm currently looking at quantized sine wave stimulation of the tankless design (quickie spreadsheet here) and I want to change the processor once more, but it's getting to the point where I feel like I'm frittering around the edges and am in need of a deadline of some sort to give me a kick in the pants.

Along these lines I've been seriously contemplating a pitch-only prototype that might make the rounds to one or more Thereminists for their opinions.  It would likely have note spacing & note offset (& hopefully linearity) controls as well as a visual tuner.  The audio tone would likely be a simple filtered square wave, or perhaps square / triangle / ramp if I put some form of D/A on the output.

I'm a bit nervous about doing this as I don't want some bad aspect of it that might be easily remedied souring players to the digital approach, but I don't want to keep people from talking about it openly and honestly either.  I want to get as many features in there as I can so the feedback could be more comprehensive and useful - ideally the prototype would be close to a finished product, with software updates providing new features - but this goal seems to be keeping me in a state of near stasis.

One of course always wants to put one's best foot forward, so the notion of releasing a half-baked / limited prototype is kind of scary.  But maybe I need for this to happen so I can really push forward.

So, no promises, and it might take me another month or so to implement, but who's up for an initial pitch-only trial?  You would be required to receive the prototype, test it, communicate with me, and then send it on to another person (possibly in another country) - all of this in a reasonably timely manner.  I'm thinking you would pay postage out, but if that is onerous I could reimburse you.  I'll try to keep the prototype small and lightweight so the shipping costs will be minimized.

[EDIT] Whoa, not everyone all at once! :)

OK, I'll try this again when I have actual hardware to send out.

Posted: 9/25/2013 3:15:34 PM
dewster

From: Northern NJ, USA

Joined: 2/17/2012

Yesterday I bought some Sally Hansen "Insta-Dri" (R) clear fingernail polish - and it really does dry in about a minute.  It beats the cheap ~$1 stuff I was using to fix the coil ends, which was taking forever to dry.  >$5, ouch!  Those extra carcinogens don't come cheap.

Been hacking on Hive some more, hope to jebus this is the final pass.  The immediate byte value has been reduced to 6 bits, and all immediate jumps are now 6 bits as well so this is a unification of sorts.  No more unsigned comparisons.  The pow2 function is gone.  Now have a leading zero count operation, as well as an end-for-end swap.  All single operand functions use B as the input for an optional simultaneous move.  A boatload of aesthetic edits.  So it's a little cleaner, a little larger, and a little slower.  Top speed doesn't seem to be influenced very much by compiler directives, so the logic & registering are likely a good fit for the fabric as written.

Slow news day...

Posted: 10/14/2013 5:33:14 PM
dewster

From: Northern NJ, USA

Joined: 2/17/2012

Just popping up to whine a bit :-)

The Hive processor code is polished to a bright sheen but I'm holding off on posting this latest version until I can get a functional simulator constructed for it.  I'm finding myself spending inordinate amounts of time hunting down stupid bugs in fairly simple boot code, so a simulator seems called for to give me more visibility into what the heck is going on.

Like an idiot I've picked Excel in which to implement the simulator, which has two ways to do everything: the spreadsheet function way and the Visual Basic way, and more often than not it seems both ways are broken / unusable.  For instance, the dec2hex() spreadsheet function breaks if you give it a large 32 bit number, and the output text width is uncontrolled for negative numbers.  Similarly the Hex() VBA function breaks with a large inputs.  So I had to write my own function that should have been part of Excel/VBA from the get-go.  Also, the MOD operator breaks for large inputs and also gives what I consider to be incorrect output for negative numbers, so I had to roll my own function for what is very basic functionality yet again.

Then there's the trouble of implementing ALU functions that the processor in my PC can do natively with its own instruction set, but are inexplicably poorly implemented or outright missing or in Excel.  For instance, Excel logical functions like not, and, or, and xor can operate on numbers in a bit-by-bit manner, but the inputs must be limited to longs, and dealing with the sign in order to get the full 32 bit range is awkward.  And modulo operations (counters that roll over, etc.) which are bread and butter in the digital domain are trapped by VBA.  I find it incredibly ironic that higher level languages often hugely hinder access to the basic data types and manipulations supported by the hardware.

I get so weary fighting / coaxing Excel to do every little thing to solve the larger problem at hand.  Someone needs to make a spreadsheet tool explicitly for us engineering types.

Posted: 10/14/2013 11:17:32 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

"I get so weary fighting / coaxing Excel to do every little thing to solve the larger problem at hand.  Someone needs to make a spreadsheet tool explicitly for us engineering types." - Dewster

Amen to that!

I have bought books on using Excel for engineering / scientific work - but its limitations cannot be overcome unless one virtually re-writes everything using VB.. and even then, it falls over..

Its quite astounding to me that no one (or at least I dont know of any) has produced a scientific / engineering Excel "equivalent" .. it would (as a starter) be great to be able to enter numbers (and get results) in engineering format - f,p,n,u,k,M etc.. then, as you have highlighted, the limitations for logical functions and digital numeric representations make Excel useless in this area for any 'real' work, and often useless for even simple logic operations...

But I have used other (pre Windows) spreadsheets, and tried all the Windows spreadsheets, and Excel is still by far the most usable -

A spreadsheet for engineers and scientists - one which is as easy to use for general operations, but perhaps has discipline specific "templates", so you can choose catogories like mechanical, electronic, digital engineering or things like physics or even chemistry / biology, and be provided with a set of functions etc to cover that discipline..

Theres quite a lot of us "nerds" - a core Excel-like "engine" with the option to buy specific "templates" would, I think, be a profitable product... Or better still, if it could be open-source -

It really surprises me that no one has  filled this gap.

Fred.

 

Posted: 10/24/2013 4:17:10 PM
dewster

From: Northern NJ, USA

Joined: 2/17/2012

"... its limitations cannot be overcome unless one virtually re-writes everything using VB.. and even then, it falls over..."  - FredM

Oh, tell me about it!  During the fairly intense weeks it's taken me to write this Hive sim, I awoke each day fully expecting to discover some limitation in Excel that made the entire effort moot.  90% of the time when I decide to use one of the built-in functions I have to spend hours on-line scouring various fora, scrounging for similar VBA, which in the end doesn't work for one reason or the other.  The "forms" widgets are all lame / broken in one way or another, and the "controls" widgets inexplicably freeze up if you have more than one worksheet open at a time (ran across that yesterday and just about had a heart attack).

"It really surprises me that no one has  filled this gap."  - FredM

Me too.  I think what we really need is not so much a spreadsheet with all of the concomitant auto calc stuff going on and slowing things down, but an open, portable widget interface environment with good graphing (the logarithmic axis limits in Excel are restricted to powers of 10 which is really annoying) based on an underlying rational language (i.e. not VBA!).  Some day perhaps one of the Python offerings will work well for this.

Anyway, here's a screen shot of the Hive sim so far:

Clockwise from upper left, the State worksheet shows much of the main internal state and provides the user with control over execution with clear and interrupt inputs, and single stepping and run to break point buttons.  The small Registers worksheet shows the contents of the local register set, writes to it use a red font.  The Memory worksheet shows the contents of main memory.  Pressing the XLATE button on the State worksheet causes the program listing to be translated into machine code and deposited here, and again writes use a red font.  The Listing worksheet is for the entry of programs, and it has a very flexible addressing scheme.  The Opcodes worksheet is for reference when programming.  Finally the Stacks worksheet shows the contents and state of the stacks.  This is a sim of just one thread, but the other seven differ only by the ID number they read in the register set and which bits in the register set control their clearing and interrupt enabling.

Just roughly finished the register set this morning, I'll post a link to the file once I've tested the whole thing more thoroughly.

Posted: 11/4/2013 3:33:25 AM
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

Added after writing the following ->

Hi Dewster,

I missed the above post of yours .. Thats one impressive looking spreadsheet! ;-) Looks like you virtually re-wrote excel..

---> Now back to where I started...

I have been messing about with Altera FPGA's recently - and they are really quite a lot more powerful than the CPLD's I have worked with in the past..

A client supplied me with an expensive Cyclone 3 development kit, but its almost useless as one needs a microscope and expensive connectors and/or probes to get to anything..

So I ended up buying a EP2C5 Cyclone II Mini  Board http://www.leonheller.com/FPGA/FPGA.html complete with blaster for £16 (the boards cost about £12, and has pins 0.1" spaced that I can access.. and can be plugged into header sockets on a PCB or breadboard)

Even this little boards FPGA can do everything my client needs (and more) .. But thats not my major interest ;-) .. I have managed to implement an additive synthesis engine providing 24 harmonics, and only used a fraction of the chip.. Its not perfect (the 300MHz limit on this FPGA causes some errors - but my worst error at the 24th harmonic is 6.6 cent, other errors -  17th harmonic=5c, 19th and 15th=4.16c, 12th=3.45c, all others have zero error.. Oh, there will need to be a lot of filters on the outputs to get the harmonics pure and make their levels controllable, but its a start - I also implemented my waveshaping technology (a mixed signal heterodyning "mixer" which produces ramp, square and triangle wave outputs at the difference frequency - this was just a direct copy of the schematic I presented here ages ago - but its nice to ne able to do it without actually soldering anything! - Just draw the schematic and blow it into the chip ;-)

Ok - I am slowly getting into Verilog .. I sort of get on with it as its quite C like.. But I have a LONG way to go - I havent even started getting into any real stuff - just been drawing the stuff into the schematic editor, or using my ancient PALASM to generate the code which I then convert to Verilog.

This is all at a learning level - Until my new lab is set up, this gives me a chance to play with a simple plug-in breadboard, small 'scope, and use the FPGA to do things I cant otherwise do without a lot of components, etching PCB's etc..

The wierdest and most annoying thing is the price of these FPGA parts - They are SMD, so one needs a good PCB made if you want to use them - but the parts themselves are about £17 each, or 30 for £280 .... Put the board and FPGA costs together and it becomes expensive..

BUT - I can buy the FPGA on a board, with pins, Xtal oscillator, regulator, JTAG etc, free shipping from China, for £12 one-off or about £8 each if I bought 25+

Makes no sense - Cheaper to buy a board than to buy the chip on the board!

Fred.

Posted: 11/4/2013 3:12:59 PM
dewster

From: Northern NJ, USA

Joined: 2/17/2012

"So I ended up buying a EP2C5 Cyclone II Mini  Board..."  - FredM

FYI, the Lowest end Cyclone 4 board isn't that much more expensive and is superior in terms of logic top speed and block RAM resources.

"I have managed to implement an additive synthesis engine providing 24 harmonics, and only used a fraction of the chip.. Its not perfect (the 300MHz limit on this FPGA causes some errors - but my worst error at the 24th harmonic is 6.6 cent, other errors -  17th harmonic=5c, 19th and 15th=4.16c, 12th=3.45c, all others have zero error.. Oh, there will need to be a lot of filters on the outputs to get the harmonics pure and make their levels controllable, but its a start..."

Sounds very interesting!  Could you sum them together on-chip and use a single filter at the output?  You might use a simple (1st or 2nd order) digital filter before it goes off-chip.  You might be able to use oversampling techniques and a modulator to make the analog filter even simpler.

I believe audio D/A converters have this filtering built-in (just as audio A/D converters need low pass anti-aliasing filters, D/A converters need low pass interpolating reconstruction filters).

"...its nice to ne able to do it without actually soldering anything! - Just draw the schematic and blow it into the chip ;-)"

Yes, it's one of the cleanest development environments I've experienced.

"The wierdest and most annoying thing is the price of these FPGA parts..."

This is due to steep volume discounting from Altera.  When I worked for a large telecom we could piggy-back on purchase orders made by other departments and get FPGAs for almost nothing compared to the one-off street price.  We would sometimes pit Altera and Xilinx against each other in a price war cage match to the death - always a tense event.  IIRC one sales rep lost his job after offering way too low a price on a mid-sized FPGA (which we of course took).

I'd really like to add an appendix to the Hive design document which demonstrates the bread and butter techniques of digital design.  I like to draw vertical lines on a page that represent the registering, with the async logic in between, and with *_1, *_2, etc. signal naming in verilog (with *_i for inputs and *_o for outputs).  I usually find the need to draw waveforms on paper to get this step right, where a second set of vertical lines represent clock events (rise usually).  Simulation is absolutely necessary, and the simulator in Quartus II v9.1 is very nice once you get the hang of it.

I don't know how anyone codes anything of any complexity without these simple techniques.

Good luck, and if I can help you out in any way please let me know.  There aren't enough electronic music projects going on in the world.

Posted: 11/4/2013 4:36:19 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

"Could you sum them together on-chip and use a single filter at the output?  You might use a simple (1st or 2nd order) digital filter before it goes off-chip.  You might be able to use oversampling techniques and a modulator to make the analog filter even simpler." - Dewster

Sadly, I dont think I can do this.. I need at least 8 bits of level control for each harmonic (I am looking at implementing 10 bit resolution) - I havent implemented any of this yet, but am looking at having 24 PWM based DAC's and a CMOS analogue CO switch on each harmonic to take each of these harmonics and control their amplitude from their DACs.. This switch would also be acting as part of the filter, so I get a amplitude controlled sine out the other end..

I dont want to hog this thread talking about my latest deviation from what I should be doing .. LOL ;-) .... But on this thread its probably ok.. Weve gone from developing a digital theremin to developing a Cray-like processor in a FPGA, so "deviation" here seems to be the norm! ;-)

These harmonics will be up at HF (Fundamental is 150kHz) but all be fixed frequency (Xtal locked) - my plan is to have the FPGA interfaced to (or incorporating) some UI which allows one to set up a number of harmonically engineered waveforms, and store these as presets, with the ability to select more than one preset (and perhaps combine these as a storable "patch")..

With a monophonic instrument like the theremin, I would want to be able to morph from one waveform to another, as a function of frequency - using the complex waveforms as the reference oscillator, and using the variable oscillator to sample this waveform (which would itself be changing with frequency)

But I have far bigger plans - For a long time I have wanted the ability to have an analogue additive synthesiser - Audio VCO's who's waveforms could be adjusted on a harmonic level, both to set the waveform up, and to alter it dynamically under control of EG / LFO etc.. I developed (and patented) an "Analogue Function Duplicator"(AFD)  many years ago - This was used in some special large analogue computing systems - effectively it allowed a complex function (which was expensive to produce accurately) to be "duplicated" as many times as required by the system - each "duplicator" behaved like the "master" - and the "duplicators" were a tiny fraction of the cost of the "master" - I used this on a poly synth to duplicate a exponential "master" and the VCO's VCF's etc could all be linear, with a "duplicator" preceding the CV input.

A feasibility study (I met a synth enthusiast with some money, who is interested in entering the modular synth market at the high end) is now coming together for an additive analogue polysynth rack unit, using AFD's everywhere - for exponential conversion, and for producing additive waveforms from the VCO's... All the VCO's need to output is an accurate linear ramp waveform of fixed amplitude, this drives an AFD which has the complex HF (150kHz) waveform, and the output of the AFD is this waveform at the frequency of the incoming ramp.(and yes - its all analogue.. the ramp could be regarded as an address into a LUT - except that theres no LUT, only time - and "indexing" is entirely dependent on the instantanious voltage of the comparatively slow ramp against the fast reference waveform.. In fact, there is a ramp synchronous with the reference waveform generator, which is provided to all the AFD's .. the input to the AFD is compared against this fast ramp, and the reference is sampled when they are equal - this sample is the AFD output..)

On the theremin sensing side, I have just about abandoned my search for perfection ;-) .. I have a linear "continuum" type antenna which is easy to play (its capacitive with a non-linear sensing field of a couple of inches, but is extremely linear if one slides ones hand along it a constant distance from it <or actually touches it lightly> and one can modulate the pitch  by sliding along its length, changing how close the hand is to the antenna or the pressure applied if touching it, or by varying the contact area) .. It can be any length and span any range..) .. So there doesnt seem to be any point in trying to compensate for the inverse square law vs required exponential law when one uses distance as the variable (as with a conventional theremin) .. I am playing with a theremin EWI (electronic wind instrument) using this antenna in a tube, with a breath sensor to control the volume.. At present its a modified WII "Zapper" handle containing the theremin, with 50cm plastic pipe containing the special "antenna", and a nicorette inhalator with sensor built into it as the mouthpiece - I will be meeting some woodwind instrument builders in Oxford soon to (hopefully) get them to tidy things up - as I have no idea about "optimum" air flow resistance or anything else bout wind instruments, for that matter.. ;-)

Fred. 

"Good luck, and if I can help you out in any way please let me know."

Thanks Dewster - I am SURE that I will be needing your help! ;-) .. At the moment though I am not even sure enough about my direction to know what help I need! ;-)

Posted: 11/5/2013 4:55:30 AM
Explorer

Joined: 10/23/2013

Interesting reading!

I loved what I was able to do with my Kawai K5000R, but ultimately found that for monophonic wind synthesis I much preferred FM/iPD.

There was some interesting and inspiring work done back in the '80s on the NeXT platform, using genetic patch programming to home in on timbres, and using tools like P-Farm for the Yamaha 4-op and 6-op synths to get to voices which would respond in interesting ways to breath control. We also had rough conversion program to "translate" Yamaha patches for Casio use, although

Using that same idea, some friends of mine and I also used stacked Casio VZ synths as additive sound engines, also responding to incoming breath data to affect volume and timbre.

There weren't so many envelope points on the Yamaha and Casio gear as on the single K5000, obviously, but they were great for wind control.

I'm currently enjoying just running my simple theremins through gear like my GT-10, which I normally use as a monophonic guitar synth, or even just my Korg PX5D, but it will be interesting to see what you guys implement....

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