Introduction: Another MIDI to CV Box ...
Another MIDI to CV box is a project I developed when a Korg MS10 knocked my door and took place in my studio. Being that my setup heavily relates on MIDI to automate and syncronize all the instruments, when I bought the MS10 the first problem I had to face was how to implement such control.
Korg MS20/10 are not the easiest synths to implement MIDI to: first of all, they rely on Hz/V control (linear correlation between the control voltage and note frequency), instead of oct/V (1V per octave); second, to trig a note you must send a negative gate signal and short the input to ground (S-Trig), not a +5 V signal (V-trig).
There are various commercial solutions to control such instruments nowadays (i.e. Arturia Beatstep Pro, Korg SQ-1, Kenton Solo) but I am a cheap bastard and even 100 euros are too much for a "not sounding" device :).
Here we are then: let me show you how to build a low budget MIDI to CV box to control/automate a pre-MIDI synth's pitch, gate, velocity and cutoff frequency with an external MIDI controller (Keyboard, DAW, sequencer or whatever).
"What about the new MS20 mini?"
As almost anyone know, the new MS20 is actually MIDI ready :IN with a 5 poles MIDI connector and IN/OUT with USB connector.
"So, if I have a MS20 mini this thing is useless!"
Well, no. Not really. MS20 mini keyboard is not velocity sensitive, so your note is played at a fixed half "64" volume (following the EG when applied to the VCA) even if you soft or hard press the keys. There's no way to overcome this with the MS10/20 vintage or mini keyboard, but with midi box and a velocity sensitive keyboard you are golden. In addition, the only MIDI channel MS20 mini responds to is channel 1. With this box you can overcome this limit too.
"What if I have a Oct/V synth?"
No problem! The code I wrote is compatble with Oct/V synthesizers (untested, but I am confident that will work out-of-the-box ;)).
Step 1: !! Note of Caution - Disclaimer !!
Your equipment is very valuable and should not be used to perform tests.
Toying with electricity can severely damage your equipment or harm yourself.
This project asks for electrolitic capacitors; these capacitors are polarized, meaning that they MUST be inserted with the right direction in the circuit (negative pin to ground); inverse installation of a polarized cap may lead to the explosion of the cap, with corrosive electrolite scatter. Pay attention!
I cannot be held responsible for damages to your equipment/hardware or even yourself coming from any of the software or schemes or informations or links I reported in this instructable.
You have been warned!
Step 2: Engineering the Hardware
Arduino comes handy when dealing with projects like this. The existence of a big Community and very good libraries that span almost every common task make it the right choice. Here the board will be programmed such that it will read incoming MIDI data and then will send appropriate voltages to drive:
- Pitch, by converting a pwm output into an analog voltage to drive the VCO via a digital to analog converter (DAC)
- Gate, directly from a digital out
- Velocity,by filtering a pwm output to drive the VCA with a simple RC filter
- Filter Cutoff Frequency,by filtering a pwm output to drive the VCF with a simple RC filter
Arduino is not capable of outputting directly steady voltages, but 0/+5 V pulses with various periods (PWM). We are in the need for digital to analog converters (DAC) for the pourpouse. RC filters are the easiest DAC I can think of. A RC filter is good enought for the voltage controlled amplifier and filter (VCA and VCF). The RC filters are tailored to result in a cutoff frequency < 20Hz (lowest audible frequency).
I made some test with low capacity non polarized capacitors, but I had not good results in RC design; this project then asks for polarized, electrolitic, capacitors (higher capacity than non polarized caps); these capacitors are polarized, meaning that they MUST be inserted with the right direction in the circuit (negative pin to ground); inverse polarization of a electrolitic cap may lead to the explosion of the cap, with corrosive electrolite scatter. Pay attention!
Unfortunately, we can't rely on a RC filter to drive the voltage controlled oscillator (VCO) since it would be not accurate enought (in Hz/V scale, on the lower end two adiacend semitones differ for less than 0.02V; in V/oct two adiacent semitones differ for 0.083 V); we are going to use an IC DAC (MPC4725) for this.
Limiting the drive voltage to 5V (the Arduino output voltage), the full 0 to 5V range is covered for velocity; the cutoff is half covered (-5V to +5V); the VCO range is partially covered being that in Hz/V a voltage of 8 V would be required to reach the 440 Hz A4. With a 5V output limit we can pitch the oscillator up to the C4 (middle C) frequency.
About velocity: there's the need for further testing on the filter components (R and C) to be used with velocity. With the 100uF and 1KOhm I used the velocity peak is reached someway slowly. I will toy with different values in the future. By now, you can use a very low sustain level on the ADSR and you will reach a good compromise.
Step 3: Components List
You are in the need for:
1X Arduino UNO (or nano)
1X MPC4725 DAC board
4X 1/8" or 1/4" mono connectors
1X MIDI connector
1X 6N138 optocoupler
1X 1N4148 diode
1X 220 ohm 1/4 W resistor
1X 470 ohm 1/4 W resistor
1X 10K ohm 1/4 W resistor
3X 1K ohm 1/4 W resistor
2X 100 uF capacitor
1X ABS box (at least 55 x 70 x 100 mm)
... and obviously breadboard or perfboard, solder iron, solder wire and cables (2 meters of 28 AWG should be enought).
I used a additional connector to supply power to my arduino; it's not necessary being possible to juice the microcontroller directly via the onboard mini USB connector.
Step 4: Connections
The MIDI IN circuit is simple and well described on the net. Take THIS excellent instructable on MIDI and Arduino by Amanda Gassaei, for instance. I made the nth schematic on the matter anyway.
Notice that i added a switch in the MIDI IN scheme (switch 1): this is necessary when uploading a new sketch to Arduino because the opto interfere with the RX line even without incoming midi messages. You must open the switch before uploading your sketch or the IDE will fail to upload the new sketch.
DAC, RF Filter, Synthesizer
Connection for DAC, RC filters and Synth (pitch, gate and velocity) are shown in the diagram on top. I took for reference a Korg MS20 patch panel, but I tested everything on a MS10 (remember that "cheap bastard" thing I told you? :) )
Step 5: The Software
I tried to keep the sketch as clear and "readable" as possible.
I worked on a simple calc sheet i found HERE to derive a Voltage Vs Note# curve and use directly the equation in the microcontroller. The equation is shown in the graph on top.
We are going to increase the pwm frequency of a Timer/Counter to reduce output voltages ripple (as easy as a line of code).
To keep the code responsive to incoming bytes, the code relay heavily on functions callbacks.
You are in the need for the Sparkfun's "Adafruit_MCP4725.h" and Forty Seven Effects/Francois Best's "MIDI.h" libraries to compile! (Many thanks to these persons: without their efforts this project would never be realized!).
I am not a coder in real life, so it is well likely that the sketch could be written in a better way. I am open to suggestions (I always learn something looking at coder's code ;))
Additional notes are written in the code below. Install the two libraries, open the attached code on your IDE, connect your board, select the type of board and upload.
Step 6: Troubleshooting
Even if the project is low level, there are tons of things that could go wrong. If you are experiencing issues while attempting to create your own MIDI to CV box, follow these steps:
1. Be sure that Arduino is correctly receiving MIDI messages
Check the output channel your keyboard or DAW or Sequencer is outputting MIDI messages to. Arduino is listening to channel 1 by default. Upload "TEST_MIDI_IN.ino" to read a incoming noteON message.
2. Double check your wirings
... or even better: triple check them! Keep your time for this.
3. Check the DAC address and output
The DAC could be set to receive data on a different address than the one i set in the sketch. Check the address by running "I2C_scanner.ino". If a "no device found" error happens, check your DAC wiring (SDA and SCL inputs are different on different Arduino boards!). If you have an oscillocope (even those 15 euros digital oscilloscopes are good enought... and fun to toy with!) you can check the output of your DAC by uploading the trianglewave generator example included with the DAC library installation.
Remember that when a optocoupler is connected to the RX input of your arduino board, you will not be able to upload a new sketch!! Place a switch (it could be a simple jumper) before the RX pin.
Most of these test sketches are not mine or at least based on existing online material.
This thing sounds out of tune to me!?
This is not a real issue: the equation derived for Hz/V control is "ideal". Some drift from the ideal behaviour can rise from the +5V you are supplying being not 5.000V, from the DAC and from the instrument itself. To solve you must act on your synth tune/fine tune potentiometer and "voilà" a perfectly tuned MIDI control ;)