Thursday, November 1, 2012

Digital Theremin (PIC12F1840)

Since the homebrew power supply is complete, and that, in turn, completed the Remote Controlled AC Outlet project, it's time to turn to something new and different - something that doesn't involve LEDs or relays.

I used to own a Theremin from Big Briar (it is now Moog Music Inc. and their Etherwave Theremin products are here) - it was a kit that I put together and it was _very_ cool. If you don't know what a Theremin is - have you ever seen a monster or sci-fi flick where there was weird, warble-y, ethereal music playing? _That_ is a Theremin. It's the only music instrument you play without actually touching it. Sound strange? It is - and it's damn fun to play with.

I found a video on YouTube that has Leonid Theremin playing the instrument he invented:



I found a design for a theremin using a couple of HEX converters (CD4069UBE), but I was never able to get it to work. I'm using a HCF4069UBE instead of the CD4069UBE, so that may have something to do with it. You can find that project here.

Anyway - I've decided to gut the old electronics from the original project and replace it with new electronics based on the PIC12F1840. That PIC has A/Ds, a DAC, capacitive sensing, PWM, and other goodies that can be used to implement this design. This should be interesting, educational, --- and fun!


The original project. I like the box and antenna, but I'm going to
scrap the electronics and replace them with a PIC12F1840 based board.



Rear view of the project, you can see the old electronics inside,
which are going bye-bye.

It always starts with the PIC. And a 6-pin header (for programming
the PIC). And a chunk of perfboard.

And, if you look at the back side of the board, blue wires. These
wire up the PIC to the header so that it can be programmed using
the PICKIT3. Next step is to connect the PICKIT3 and make sure
that the PIC can communicate and be programmed.

And - it works! Not very exciting yet as there are no blinky
lights in this project. But, I can communicate with and program the
PIC, so the ICSP is wired correctly. Next step, start figuring out the design.

I know I will need the DAC output to drive the speaker. So RA0 is assigned. There needs to be two antennas, one which control the pitch and the other controls the volume. In the original Theremin, the circuit relies on changing inductance as your hands change proximity to the antennae. But in this PIC design, we will use a couple of capacitive sense pins for that purpose, which I hope works. So that will consume two more pins, RA1 and RA2. Power and ground are needed, so that's pins 1 and 8, respectively. I need a zero pitch adjustment, so that will be into to the A/D. That will consume a pin, and let's say RA4.

Let's see what we have so far:
(format: pin#. PINname - PICfunc (DESIGNfunc))
  1. PWR - Power (+5V)
  2. RA5 - unassigned
  3. RA4 - A/D (zero pitch)
  4. RA3 - unassigned
  5. RA2 - CPS2 (volume antenna)
  6. RA1 - CPS1 (pitch antenna)
  7. RA0 - DACOUT (speaker)
  8. GND - Ground (ground)

A pair of speakers that I salvaged from somewhere.
I have lots of stuff hanging around in boxes in the MadLab.

An amplifier chip that was salvaged from an old TV set.
It should work okay and it has 2 channels @ 5 watts each,
so it should be loud enough.
The back side of my ugly amplifier board.

The amplifier board with the speakers attached.

I made a header connector on the PIC board that has +5V, GND,
left and right channel out (which are the same signal), and volume
control in. For right now, if I leave volume control unconnected to
anything, the amplifier will be at max volume.

*CAUTION* TURN DOWN YOUR SPEAKERS
BEFORE YOU PLAY THIS VIDEO!
Yeah, I think the amplifier and speakers work.

The datasheet for the AN7522N 2 channel 5 watt amplifier is here.

I've got the DACOUT working - finally. It's kind of a bear to get set up correctly. So now I can generate various waveforms - Sine, square, triangle and sawtooth. So that means that RA3, which is a dedicated input, will become a pushbutton that selects the various waveforms. And I think have a volume adjust on another pin, which will have to be the only unassigned one left, RA5 - another A/D.

The PIC pin list, revised:
(format: pin#. PINname - PICfunc (DESIGNfunc))
  1. x PWR - Power (+5V)
  2.   RA5 - A/D? (volume offset pot)
  3.   RA4 - A/D3 (pitch adjust pot)
  4. x RA3 - GPI (waveform select pushbutton)
  5.   RA2 - CPS2 (volume antenna)
  6.   RA1 - CPS1 (pitch antenna)
  7. x RA0 - DACOUT (speaker)
  8. x GND - Ground (ground)
The little 'x' means the pin function is fixed and can't be changed.


Uh oh. RA5 isn't an A/D. Let me think about this.

While I was thinking about RA5, I mounted the speakers onto the case faceplate and also wired in a volume control / on/off switch. So, since I have a volume control that uses the volume pin on the amplifier, I don't need another A/D. RA5 issue resolved!

I've been playing with the code to generate a triangle waveform, and came up with some code that cycles the frequency up and down. Here's a video:

More fun than an old hack should be allowed to have...

Digital Theremin (PIC12F1840) V1.00 Schematic


More to come as I make progress.

1 comment:

  1. I'm having trouble with DACOUT on a project of mine using the 12F1840. Will you be publishing your source code?

    ReplyDelete