Last night, I decided to explore an idea that I have been formulating over the past several months, but haven't actually taken the time to explore. I had a thought that I could emulate a Lunetta circuit (a CMOS 40106 integrated circuit with a potentiometer and a capacitor to create an oscillator) using my FPGA and Verilog.
After all, the 40106 is simply a hex inverter (6 inverter circuits on one chip), so the code was this simple:
assign pin1 = ~pin0;
That simply set the value of pin 1 to be the opposite of pin 2 (inverted signal) at every clock cycle. I plugged in the capacitor and potentiometer according to the regular "Lunetta" arrangement (as seen in the schematic below), but it didn't work.
Replace the U1A IC in the schematic with the FPGA and you'll understand how I set it up.
I think I have a fundamental misunderstanding of the nature of CMOS and FPGA's. While you can emulate the functionality of an inverter chip using an FPGA, I don't think it's possible to emulate the physics of the chip itself. The Lunettas work off of the actual physical reaction and timings of the chip itself, not off of a clock cycle such as the one that the FPGA is running under. Emulating a physical feedback circuit will not render the same results when using an FPGA. I looked at the datasheet for the 40106 and saw that it has ~140ns delay. I'm not sure if I can emulate that kind of timing.
I enjoyed the few hours I spent hooking the circuit up and playing around, though, and it got me into Pulse Width Modulation and other audio generation techniques for FPGAs. I'll be exploring more about audio processing in the future, but I've put away the idea of emulating discreet components for their "out of band" uses.
It's fun to play around with this stuff, but when the theory gets too thick, I lose interest and move onto more playful aspects of the technology. I think it's why I have a cursory understanding of a lot of technology, but only a deep understanding of a limited number of topics (like C#, HTML, and other Web Development).
Acquire basic electronic components - I ordered a lot of passive components (capacitors, resistors, transistors, jumper wires, breadboard, etc.). I've found that the best place to start is Amazon.com, then head over to Mouser Electronics for the little stuff (in big quantities), then All Electronics as a last resort. Adafruit Industries is the best place to buy add-ons, full kits, and great peripherals for your electronic projects.
Install an operating system on the Raspberry Pi - I am using Raspbian
Configure the WiFi using the serial cable (I don't have a USB hub, so I only had a single USB port on the Pi. This meant that I couldn't install the WiFi adapter and a keyboard & mouse). Once I had the serial adapter, I used PuTTY (I'm on Windows) to connect to the command line and configured WiFi from there
Once WiFi was configured, I installed an RDP server so I could use the Remote Desktop client to log into the desktop on the Pi. I rarely use this, but it's nice to have a desktop from time-to-time.
Install mono (cross-platform .NET runtime) - I use the C# programming language at my day job, so I'm comfortable with it. The Raspberry Pi supports many different programming languages, so pick the one you are comfortable with.
Install monodevelop on the Pi - monodevelop is the IDE that runs on Linux for developing .NET applications. This was not required, but I wanted to see if it would work. It did, without any issues.
Once I had the .NET runtime (mono) installed on my Pi, I opened up Visual Studio 2015 Community edition on my Windows 10 machine, added the raspberry-sharp-io NuGet package, and developed a simple application that toggles pin 7 (turning it on) when it starts up, waits for the user to press the ENTER key, then toggles pin 7 again (turning it off).
static void Main(string args)
var led1 = ConnectorPin.P1Pin07.Output();
using (var connection = new GpioConnection(led1))
Console.WriteLine("Press [Enter] to quit");
Now I had to set up a circuit on my breadboard that controls a 40106 oscillator so that I can turn it on or off using C# and the Raspberry Pi.
Here is my schematic:
The Raspberry Pi is providing +5v that drives the 40106 and the 4093.
The oscillator (pins 1 and 2 of the 40106) is cycling at a fairly low frequency, as controlled by the 1M resistor and the 470nF capacitor (I haven't timed it as I don't have measuring equipment, though I will be able to write some with C# when I get into input pin management on the raspberry-sharp-io library).
I can now use this to control each individual oscillator on the 40106 independent of one another.
The key to making this work is the NAND gate (pins 1, 2, and 3 of the 4093). When combining the signals from the Raspberry Pi (Pin 7 in this case) and the output from the oscillator on pins 1 and 2, we can control the output on pin 3 of the NAND gate.
4093 Quad 2-input Schmitt trigger NAND Gate IC
40106 Hex Schmitt trigger IC (Logic Gates)
That means that when Pin 7 of the Pi goes high, it will raise pin 1 of the gate. Then, each time the 40106 oscillates (it is constantly oscillating as long as power is being sent to the IC), it will trigger pin 2 to go high, which causes the gate to go high on pin 3, thereby causing the transistor to pass +3v to the LED and lighting it up (I wanted to isolate the voltage of the LED from the +5v that's driving the oscillator and gate circuit as a proof of concept for managing components with different voltage requirements).
This schematic is actually bad design. I have a few errors (mostly due to using the transistor incorrectly, as well as using an NAND gate rather than an AND gate).
It seems to be working now, but I'm not sure if it's absolutely correct.
The frequency of the blinking is controlled by the oscillator (because pin 7 of the Pi is staying high based depending on whether or not the program is running). When the program stops running, pin 1 of the gate goes low and the gate remains closed, thereby stopping the blinking (oscillator output). Currently, the LED stays lit. I'm guessing this is caused by using a NAND gate rather than an AND gate.
The following video is similar to my first video about blinking an LED using C#, but this time, the blinking is the result of the oscillation of the 40106, not a timer built into the program. This program simply toggles pin 7 to the "On" position until the user presses the key and then toggles it off again. This video was created before I modified the schematic and removed the indicator LED.
A few weeks ago, I stumbled on a DIY synthesizer community based on synthesizers called "Lunettas" (after Stanley Lunetta, the guy who pioneered the process). I'll let you read about it if you're interested.
Basically, Lunettas are CMOS-based (usually) integrated circuits that are setup to generate clock frequencies within the range of human hearing. The circuits are created using very inexpensive chips containing "oscillators", very much like the more expensive Moog or Eurorack alternatives (one Lunetta CMOS with six oscillators costs less than $0.50 while a single simple Eurorack oscillator costs about $150). However, the sound from Eurorack modules is more "mature" and musical, while Lunettas tend to be a bit "beepy" and chaotic.
WARNING! Obnoxious beeping ahead!
I hope to change that by removing the annoying beeping sounds from the resulting output of my Lunetta device and replacing them with more musical results.
The possibilities are endless when you combine CMOS-based (along with some passive components to change clock frequencies driving the components) with a Raspberry Pi and software.
I have a lot of ideas, but every time I get a new Idea, I research the underlying theory and get caught up in the science of it all. The idea behind Lunettas is that they're supposed to be experimental and a way to just play around with circuitry to make cool sounds. I'm applying an enormous amount of brain energy thinking of ways to control the sounds based on theories like the General Theory of Generative Music (GTTM).
Honestly, I just need to sit down and play with these circuits before I can build my ultimate "smart" machine that "composes" its own music.
One of my biggest desires in life is to create a machine that can create art based on minor inputs from me and a little guidance along the way. I want it to "learn" how to listen to music, develop its own "tastes" and then create "music" based on what it has "learned". All of those words in quotes are because I'm not really trying to build a self-realizing AI, I just want to build a machine that creates art.