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

Posted: 7/12/2012 4:33:05 PM

From: Northern NJ, USA

Joined: 2/17/2012

"... I have just spent most of the last 2 days trying to get my head arround the Digital Filter Block in the PSoC - this is a mini processor contained in PSoC 3 and 5 parts (not the main processor, but entirely seperate one), a sort of DSP block with its own assembler, ALU, registers etc.."  - FredM

A DSP coprocessor block makes a lot of sense.  You really want two separate small memories feeding an ALU and have the result stored in yet a third small memory, with a calculation on each clock.  Speed it up by pipelining the crap out of it, because branches perhaps won't even be implemented.  With the I/O bottleneck, regular processor architectures generally can't keep a DSP ALU happy.

"Have been trying to implement a pair of BP filters for vocal formants, but got out of my (and the experts at Cypress) depth because I want to manipulate the coefficients in real time - the "component" container does not cover this type of application, so I need to get inside the DFB and deal with it for what it is - a partially re-configurable processor."

I find it easier to build my own stuff in an FPGA than to figure out how to solve my problems using complex constructs designed by others.

"...And I am well out of my depth, rapidly retreating back to analogue which I know and trust!"

Luckily I took several controls classes in college, include a couple of digital ones, so this stuff doesn't feel too alien to me.  You can do a heck of a lot by:

1. Take the diagram of your topology and substitute z^-1 for all single clock delays (registers).

2. Look at each node in the topology and make a simple equation that represents the signal at that point.

3. Combine these simple equations and use a bit of algebra to solve for output/input.  This gives you the difference equations you can use to implement the topology in digital logic.

4. Substitute z = e^(jw), where w = 2*pi*F, and F = Fresponse/Fsample and graph the response in Excel.

Spreadsheets are really the key to understanding this stuff, something they didn't teach me in college (they were too busy showing us the math / closed form solutions to everything).  Small C programs that kick out wav files are helpful too.

Posted: 7/12/2012 5:21:46 PM

From: Theremin Motherland

Joined: 11/13/2005

FredM>> trying to get my head arround the Digital Filter Block

Fred, why do you need a digital filter, while PSoC has analog (pseudo) blocks  for filtering such as BPF?

Posted: 7/13/2012 12:21:34 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

"Fred, why do you need a digital filter, while PSoC has analog (pseudo) blocks  for filtering such as BPF?"- Ilya

Couple of reasons..

1.) I want to use the analogue blocks (particularly the SC blocks) for other analogue functions - even with the biggest PSoCs analogue resources are limited.. The DFB is a spare resource on the PSoC - Its there, does not consume anything which could be used for some other purpose, I am not using the DMA for anything, so can assign this exclusively for use by the DFB (although this is not essential - the DMA is powerful enough to handle multiple operations without hassle - I may use it for other operations as well), and the DFB has 2 "channels" each capable of implementing complex filters, so it seemed ideal for my application.

2.) My volume antenna is, in fact, an antenna "array", which detects hand position and provides X,Y and Z 'vectors' - (Z is the vertical, or 'volume' component) - I want to use X and Y to select the formant - effectively use X to tune the first formant, Y to select the 2nd formant.. Then hopefully compute other formants from X and Y and program filters (bandpass) using this data.

The idea is that the player can move their hand in the 'volume' field and actually get the theremin to sing recognisable vowels - I have an analogue prototype of this, but the formants are not particularly strong.. Having heard the EH "Talking Machine" I can now hear what is possible using DSP, and just want to explore this a bit (as I have time on my hands).

But - It looks like real-time manipulation of the coefficients is a lot heavier than I had imagined.. The EH-TM has selectable vowels, but does not vary these in real time - I could do this now (simply load up a different set of coefficients when the user selects a different vowel) - but 'morphing' between vowels in real-time (without any audio glitching) may be beyond reach at this time (certainly seems beyond my reach!) - so I think I need to be looking at more elaborate analogue filters... Unless I really master DSP and  used the DFB assembler to write my own filter code and configure a new DFB "BPF component" with simpler controll over frequency.

I had thought about splitting off the functions into two seperate PSoCs - but there actually is little point.. The analogue filter implementations in the PSoC are actually inferior to what one can achieve with off-chip circuitry. There are some analogue functions where the PSoC can do things which would require quite complex off-chip circuitry to implement, but analogue filters are not one of these..

So, if I dont use the DFB, there is no point in adding another PSoC to implement the filters in its analogue blocks.

ps .. The analogue blocks in the PSoC are not "pseudo" - they are real analogue hardware, and run without any digital processing - one only needs 'digital interference' with them during configuration (the blocks are like components which are not connected together - configuration connects or 'wires' the circuit - putting resistors and capacitors etc into the circuit, setting component parameters, routing the interconects to other blocks / pins etc) once configured, the block runs without needing 'help' unless one wants to change something (configuration) in real time.

The S/C blocks are "mixed signal" (although implemented as analogue UM's) - they rely on switching capacitors at high frequency to achieve variable time constants (or other functions such as S+H or heterodyning), so, in as sense they could be regarded as "pseudo analogue" - The filters are implemented using S/C blocks, and for control over parameters such as cut-off frequency in real time, one needs to control the switched capacitor operation (change the switching frequency or ratio using a 'digital' signal derived from a digital block component such as a PWM ) - IMO, these filters are not well suited to variable operation, and I dont like how they sound when their frequency is varied.. one is limited to the resolution and concequential quantising of the mechanism employed to switch the capacitors in the block - a 10 bit PWM is the largest one can 'fit' if keeping latency tollerable, and even if one adds jitter the quality is not acceptable to me.

I should just say that the above comments relate to the S/C block in PSoC 1, I have not yet played with this block on the new (PSoC 3+5) parts, but I believe the S/C is the same (or close) and do not think I will change my opinion - Switched capacitor filters never sound good to me, no matter how they are implemented - even the best S/C filter IC's sound, IMO, crap.. I think this may be why one doesnt see them in any respectable musical instrument.

Fred.

BTW, I am an "official" Cypress PSoC consultant (Cypros).. But I have no particular "loyalty" to Cypress and earned my accreditation on PSoC 1 - I am new to 3+5. I had a big disagreement with Cypress when they tried to move PSoC 1 design over to their "Express" software (which was completely unusable) - eventually they abandoned "Express" for PSoC 1, and re-introduced "Designer" - But by this time they had lost many customers and Cypros (including me). The new "Creator" software is a completely different animal , and is damn good (as is PSoC Designer for the PSoC 1) - So I am now willing to spend time updating my knowledge to retain my Cypros accreditation.

The original "Express" was intended to provide a completely graphical "code free" programming environment - one patched pre-designed "components" together, and the software "wrote" the entire system - One was supposed to edit or modify the generated code to tailor the system for what one wanted.. Alas, thats not how I (or most serious designers) work - The code produced was slow, wastefull, incomprehensible, and somtimes just assenine - Modyfying this crap took far longer than writing ones own code - but the way the system was thrown together made doing this nearly impossible. PSoC designer was a great piece of software which allowed one to develop PSoCs without trouble - but upgrading this software was abandoned. They realized their error eventually, and dumped the original "Express" concept.

Posted: 7/13/2012 5:59:31 AM

From: Theremin Motherland

Joined: 11/13/2005

FredM>> so, in as sense they could be regarded as "pseudo analogue

The SCB is sampling input signal so I mean this fact. At least two of formant filters are possible on analog array of PSoC and I played it a few yers ago.

Back to your XYZ control -- I afraid it will be so difficult (read "impossible") for musician on coordinating that the fate of such control will be a fate of terpsitone.

Posted: 7/13/2012 8:37:27 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

"Back to your XYZ control -- I afraid it will be so difficult (read "impossible") for musician on coordinating that the fate of such control will be a fate of terpsitone." - Ilya

I did make the mistake on my "Epsilon" of combining pitch (X axis) Volume (Z axis) and filter / effects on the Y axis.. Combining Pitch with any other control for one hand is unplayable - I found this out the hard way.

However, IMO (and from limited expierience with my prototypes) I believe it possible to play formants with the volume hand while playing pitch with the other..

Formants are an extremely natural function - its not like one needs to look at some chart, you simply move your hand forward,backwardsand side-side and the formant changes. Many years ago I played with a joystick controlled analogue formant filter where the pitch was controlled by a rotary controller - This design was not mine - it was designed as a 'toy' for children with "disorders" such as cerebal palsy and lesser problems like autism - some of these children were able to perform simple communication with this device wheras their verbal communication was unintelligable.

I may be wrong - but I believe that after a few hours of playing formants in a 'space field' the brain might naturally integrate this (as in, program the vowel positions) and theremin singing will not be much more difficult than using the volume antenna to control volume.

"The SCB is sampling input signal so I mean this fact. At least two of formant filters are possible on analog array of PSoC and I played it a few yers ago."

Yes - two BPF's are available using PSoC SCB's... BUT THEY SOUND CRAP! (IMNSHO)

What the hell is the point in me giving long answers when people ask questions, if they dont bloody read what I write !?

Fred.

Posted: 7/13/2012 2:42:53 PM

From: Northern NJ, USA

Joined: 2/17/2012

I've taken a quick look at the PSoC data sheet (CY8C54): the AD / DA converter resolutions are kind of low, the processor seems overly complex, there are too few programmable logic blocks and they're very old school (PLA? - I want LUTs & FFs), and switched capacitor stuff doesn't really interest me.

Their MachXO is a thing of beauty and I've used it in place of a complex CPLD on several boards.  I wish they would have put some multipliers in the XO2, but they put in a bunch of hardened peripherals instead.

Their tool sets could use some work though - I particularly didn't like the license expiring every year or so.

Posted: 7/13/2012 3:27:54 PM

From: Northern NJ, USA

Joined: 2/17/2012

Fred, what do you think of the inverse nature of the volume control (hand closer to the antenna = quieter volume) and the control of formants?

When introducing another axis or two of control to the left hand, it seems like a closer = louder implementation would work better.

Posted: 7/13/2012 7:05:53 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

"When introducing another axis or two of control to the left hand, it seems like a closer = louder implementation would work better." - Dewster

Gave me a lot of headaches, this question! - With Epsilon, I made closer = louder.. But this was mainly because I was controlling pitch and volume, and because the sensing distance on Epsilon was only about 20cm.

With my EJS (Ether Joy Stick) I have tried both, and come down on the side of the conventional further = louder. The reason for this is that the sensing field is conical, as one gets closer, ones X-Y movement field reduces, and accuracy concequentially reduces - one really wants this to occur as the volume gets lower rather than when it gets louder!

Also, as one gets really close, there are some problems resolving the axis - The operation of the EJS is based on 4 antenna pads, one pair for the X axis and one for the Y.. Each pair is summed to derive total capacitance, then the difference is computed (all analogue - there is a small analogue computer performing squaring and other functions) , and the result scaled (based on the sum) - This way the axis retain their vectors regardless of "volume" distance. When close to the antenna "array" the sum / difference function becomes error prone, because capacitance distribution tends be 'clumped' on one antenna in a pair, unless ones hand is close to the centre of the "array".

I could probably have sorted out this 'clumping' quite easily by having a more complex array (as in, shaping the pads and getting them to 'lap' into each other) - but I was in a panic to complete the unit for HO-2011, and my 4 triangular antenna (well, actually, a small circular pizza base with aluminium foil stuck on it, sliced into 4 pieces) worked adequately.

Fred.

ps.. One little thing I discovered, which again convinced me of Lev's genius, was that I got interaction between the EJS (which was set in the top of the theremin, 60cm from the pitch antenna - yeah, it was a long theremin!) and the pitch.. At first I looked for electronic coupling, then noticed that when I was only using the EJS for volume, I never had the problem...

The reason is simple and obvious - 'X' movements are reletive to the pitch antenna, Z movements are on the same plane as the pitch antenna - so X alters the capacitance seen by the pitch antenna, but Z (Volume) doesnt!

Lev's design overcame this potential problem brilliantly .. I think that the same problem will occur when one has two horizontal antenna (as some theremins have).

I had planned to make the EJS a seperate unit (and will if I ever get back to it) - but thought I could save time by building a composite unit, as I need the reference oscillator (from the pitch circuits) to drive the EJS (this eliminates any possibility of ghost tones) and running this HF signal to a seperate EJS was, I deemed, too much hassle as I was in a panic ... About the time I realised my mistake was when I keeled over, LOL.

Posted: 7/14/2012 12:19:52 PM

From: Northern NJ, USA

Joined: 2/17/2012

Fred, thank you so much for such an in-depth response!

Great insight into the conical shape of the field and where the most control is the most useful.  Shading, or lapping, the volume antenna elements seems very desirable then.

I wasn't planning on X-Y-Z response, only Y-Z for the reason you describe: unwanted interaction with the pitch antenna.

The processor is coming along, no major bugs in simulation yet, still tweaking the opcodes.

Posted: 7/15/2012 12:05:25 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

Errr ...

Vanished into the ether!  -- Problem in hyperspace - too much of it!

Now this is real weird! I can edit the last posting, but I cannot see it unless I edit it!

Going to try pasting it here.. If it pastes, I will delete the last (blank?) posting.

taken a quick look at the PSoC data sheet (CY8C54): the AD / DA converter resolutions are kind of low,

One can get 20 bit A/D on the more expensive parts. D/A's are low - but there is a block which can output to external serial D/A under DMA control.. The on-chip D/A's are only really useful for other functions (not audio).

the processor seems overly complex,

Its a standard ARM processor on PSoC 5, and standard 8051 core on PSoC 3

there are too few programmable logic blocks and they're very old school (PLA? - I want LUTs & FFs)

There are LUTs and FFs - The "blocks" concept is a hangover from PSoC 1 days - The fitter creates the "blocks" in the CPLD but one can create your own stuff using schematic or verilog entry, package them (if you wish) as "components" and the fitter will pack far more into the device than one is led to believe.

and switched capacitor stuff doesn't really interest me.

Its only of interest to analogue nerds like me! LOL - The S/C is extremely difficult to configure for anything except the standard pre-packaged ' components' - it was my speciality on PSoC 1, and I actually developed a simulation model for it.. I worked with Cypress and a company producing co-simulation software (simulating processor and peripheral components - bith digital and analogue) for several months, before some idiot director there stopped real development projects and went for his "Express" concept.

Their MachXO is a thing of beauty

MachXO is a thing of beauty - but its Lattice not Cypress! I used their Mach 4 parts extensively.

Their tool sets could use some work though - I particularly didn't like the license expiring every year or so.

Agreed - But, again, this is Lattice not Cypress. Cypress did other nasty sneaky things with their development software - I had a perfectly working PSoC Designer which I depended on (and was working on projects for clients) and the upgrade removed my working "Designer" and installed the unworkable "Express" toolkit.

PSoC is not everyones 'cup of tea' - The low cost PSoC 1's are, IMO, fantastic parts - cheap enough that you can splatter them all over any mixed signal board almost as if they were logic (they are cheaper than a 22V10 GAL).. The new PSoC's are on the expensive side IMO. Stupid thing is that their cheapest PSoC 3 DK costs the same price as buying the processor on this DK - and the board is packed with other expensive chips and bits (like an accelerometer!)

Fred