- February 11th, 2011
- Write comment
It’s been awhile since I’ve posted anything, but I’ve been working on several projects. I’ve just been feeling lazy about writing them up. I thought this one might be the most enjoyable and useful to people. I’m going to keep it short and sweet, so please comment if you have any questions.
This is a simple square wave synthesizer. It has a standard midi interface, so it could be used with a midi keyboard or another midi controller.
Here’s the BOM:
1x TI Launchpad or another MSP430
1x 280 ohm resistor (can use internal pull-up instead)
1x 220 ohm resistor
1x Sharp PC900V optoisolator
1x Speaker (I just bought one from RadioShack)
1x MIDI female jack
A midi cable and some kind of midi controller
You could probably get away with not using the optoisolator, but I felt like adhering to spec with the hardware. If you want to use another MSP430, be sure it has a USI and not a USCI, or you’ll have to rewrite some of the code. Also, the code expects to have the DCO calibrated for 16MHz. I think an approximation would work too, but if you’re too far off the midi clock will skew and the notes could be detuned as well.
The speaker gets hooked up to Launchpad ground and P1.2.
On the software side, the USI runs constantly and oversamples the midi data from the optoisolator. The oversampling is resolved with something like a state machine(?). I tried to use the USI properly, but I always seem to run into issues in using it with clockless serial. There’s probably a cleaner way to read the midi data, but it works, so I don’t mind. It’s all yours to fix!
Once we’re able to read the MIDI, it’s just a matter of properly adjusting the period of TimerA, the square wave sound generator, to get the proper note. The synth is monophonic, so some care is also taken to handle and store simultaneous on-notes.
Here’s the MIDI Synth main.c. This compiles on CCS.
By the way, you can use one optoisolator circuit to send data to multiple launchpads. Just assign each LP a different MIDI channel by changing this line of code:
#define MIDI_CHANNEL 0
So I hooked it up to my midi keyboard. That was OK. Then I downloaded some midi files and routed them through a USB – MIDI converter with Ableton Live. Now that gave me a warm, nerdy feeling inside.
Check it out: