[posted] (yet another) MIDI to CV Converter!

elkayem

Active member
I'm sure this project has been done countless time, but this one is mine, and comes in a nifty 3D printed case!

IMG_1630.JPG

It's a multi-channel USB MIDI to CV converter based on the Teensy 2.0, the perfect interface between your computer or iPad and an analog synthesizer. It can independently drive up to three oscillators with 1V/octave CV inputs. This device has the following features:
  • Three channel Note CV output (88 keys, 1V/octave, MIDI channels 1-3) using a 12-bit DAC
  • Configurable note priority for each channel (Top Note, Bottom Note, or Last Note Priority)
  • 5V Gate/Trigger outputs, where each channel can be independently configured to either output a gate (output high for entire length of time that note is on) or trigger (20 msec pulse each time a new note is initiated)
  • Velocity CV output (0 to 4V) for each channel
  • Pitch Bend CV output (0.5 +/- 0.5V), which can be configured for channel 1, 2, or 3
  • Control Change CV output (0 to 4V), which can be configured for channel 1, 2, or 3
  • OLED user interface, used for setting parameters and saving to EEPROM

I've posted the entire project on Github (code, STL files for 3D printed case, Eagle files for PCB) at: https://github.com/elkayem/usbMIDI2CV_MC

Here are a few more pics:

IMG_1631.JPG IMG_1623.JPG IMG_1639.JPG IMG_1622.JPG IMG_1619.JPGIMG_1627.JPG IMG_1628.JPG
 
Code:
//    noteMsg = 87 -> 4096 mV
// DAC output will be (4095/87) = 47.069 mV per note, and 564.9655 mV per octive
// Note that DAC output will need to be amplified by 1.77X for the standard 1V/octive

So you do this with fixed resistors in an op amps feedback path.

Doesn't this leave intonation dependant on the accuracy of the resistors with no adjustment in hardware or software to tune performance?
 
Normally, a "norm" pitch CV output should be internally adjustable with 10turn trim pots for offset and gain of the analog output stage, so that midi note 60 corresponds exactly 0.0000V, midi note 0 to -5.0000V, and midi note 127 to 5.5833V.

What I did several time ago on another MCU platform was using 2 14bit PWM outputs for pitch CV. 14bit allowed me to handle the note value and the corresponding cents. One output was fixed at 60 << 7 plus or minus a digital offset correction. The second output got the true CV. Both outputs were connected to a differential amplifier, followed by a 4th order active Sallen-Key filter with fine-tunable gain. Up to there, I used 3 of a quad op-amp, so that one was left over as a voltage follower buffer at the CV output.
 
So you do this with fixed resistors in an op amps feedback path.

Doesn't this leave intonation dependant on the accuracy of the resistors with no adjustment in hardware or software to tune performance?

Take a look just a little bit further in the code snippet you shared. You will clearly see that I do provide a means to tune in software. This is also detailed in the instructions I provided. I prefer to measure and tune this way and save on the trimpot in hardware.

Code:
// Rescale 88 notes to 4096 mV:
//    noteMsg = 0 -> 0 mV 
//    noteMsg = 87 -> 4096 mV
// DAC output will be (4095/87) = 47.069 mV per note, and 564.9655 mV per octive
// Note that DAC output will need to be amplified by 1.77X for the standard 1V/octive 
#define NOTE_SF_CH0 47.069f // Can set three scale factors independently based on as-measured values
#define NOTE_SF_CH1 47.069f
#define NOTE_SF_CH2 47.069f
 
Normally, a "norm" pitch CV output should be internally adjustable with 10turn trim pots for offset and gain of the analog output stage, so that midi note 60 corresponds exactly 0.0000V, midi note 0 to -5.0000V, and midi note 127 to 5.5833V.

What I did several time ago on another MCU platform was using 2 14bit PWM outputs for pitch CV. 14bit allowed me to handle the note value and the corresponding cents. One output was fixed at 60 << 7 plus or minus a digital offset correction. The second output got the true CV. Both outputs were connected to a differential amplifier, followed by a 4th order active Sallen-Key filter with fine-tunable gain. Up to there, I used 3 of a quad op-amp, so that one was left over as a voltage follower buffer at the CV output.

Thanks, very useful info! I wasn't aware there was a convention on middle C volt output. I am using only a single sided supply, and limited myself to the 88 notes on the keyboard with A0 (Note 21) = 0V and C8 (Note 108) = 7.25V. I really didn't need to produce negative CV voltages, as the coarse trim on my three VCOs go down to -9.5 V when I turn the coarse tuning knobs all the way to the left. I usually tune the VCO knobs so A4 on my keyboard outputs 440 Hz. My coarse knobs are sitting somewhere between 1/3 and 1/2 of full rotation when I do that.
 
Middle C = 0.000V is not an official convention, but an unofficial standard introduced by R. Moog in the middle of the 1990ies.
 
Middle C = 0.000V is not an official convention, but an unofficial standard introduced by R. Moog in the middle of the 1990ies.
Seems like something that should be standardized.

I can’t help noticing your username and the instrument you are playing in your photo. I would love to BUILD (not buy) a Theremin. There are numerous designs out there on the internets, I’m sure some better than others. Any advice?
 
I can’t help noticing your username and the instrument you are playing in your photo. I would love to BUILD (not buy) a Theremin. There are numerous designs out there on the internets, I’m sure some better than others. Any advice?

These beasts are difficult to build and to master, at least if you want to go beyond the first «*wooooooooeeeeeeeeooooo*» ;)

As a start and to familiarize with that technology, I recommend building a simple pitch-only Theremin first before moving over to more complex things. There is an easy to build circuit which I developed and published a few years ago here: http://thereminworld.com/Forums/T/29231/my-new-year-gift-to-tw-a-new-theremin-circuit
 
Take a look just a little bit further in the code snippet ....
Opps... I stuck the "or in software" phrase in as it occurred to me while typing. I meant to go back and check whether you had...

I had assumed a high voltage DAC to output modular-level voltages would be the obvious choice so I was surprised to see gain in your schematic especially with no trim pot.

But now I'm glad I asked as I've learned a bit from Th's reply.


...oh, very impressive build btw.
 
Last edited:
I had assumed a high voltage DAC to output modular-level voltages would be the obvious choice so I was surprised to see gain in your schematic especially with no trim pot.

I would have preferred to use a higher voltage DAC were it not for cost. The 12-bit, 2-channel MCP4822 is hard to beat at $3/chip from Mouser.

Your post has me thinking, maybe I should make the calibration adjustable in the UI and stored in EEPROM rather than hard-coded through a #define statement. It really only needs to be done once, so not a problem for me at compile time. But I can imagine it might be more of a pain if someone just wants to upload the hex file. An easy feature to add...
 
Normally, a "norm" pitch CV output should be internally adjustable with 10turn trim pots for offset and gain of the analog output stage, so that midi note 60 corresponds exactly 0.0000V, midi note 0 to -5.0000V, and midi note 127 to 5.5833V.

Unfortunately the voltage required for C4 on an as-shipped oscillator varies, as does the voltage output by many MIDI to CV units:
https://learningmodular.com/matching-octaves-in-your-modular/

It is also possible that pitchbend will take you outside that 10.66 octave voltage range.

In practice though most oscillators have a wide tuning range, and not being able to fully express a large pitchbend in the sub-bass or the only-teenagers-can-hear range is not a significant problem in practice.

I do agree though that longterm voltage stability for pitch CV is poorly addressed in most MIDI to CV products, which is where a custom Teensy-based solution can shine above the alternatives.
 
Oddson, you've inspired me to add the ability not only to configure the scale factor calibration at compile time, but through the user interface (and stored in EEPROM). My own build required calibration of only a few tenths of a percent. Even with 1% metal film resistors setting the gain, that's pretty good. Updated code pushed to Github.

IMG_1644.JPG
 
This is a really nice project. I am going to implement something similar for a project I'm working on, instead using the 3.6 and the internal DACs with a split supply powered mux and a S&H circuit to have more outputs (like 8) using the 2 DACs.

I was wondering though if you're having any ground loop issues in your project. In my design the device would be not powered by USB but from an external supply (ideally the supply of an eurorack system), but even if I'm not taking the VBUS from USB I should still connect the USB ground to my device's ground otherwise data communication would not be reliable, but that will make a ground loop (PC -> USB cable -> my device's ground -> eurorack supply ground).

How did you handle the grounds of the CV outs?
 
How did you handle the grounds of the CV outs?

I did not have any ground loop issues. I primarily use my iPad so don't need to worry about the USB ground. At least one ground is required for the CV out, and the others can be disconnected if there are issues. You might look into a USB ground loop isolator if you have issues.
 
I did not have any ground loop issues. I primarily use my iPad so don't need to worry about the USB ground. At least one ground is required for the CV out, and the others can be disconnected if there are issues. You might look into a USB ground loop isolator if you have issues.

I was thinking of adding a USB data lines isolator but current technology only allows for cheap USB isolation up to Full Speed rates (12 Mbps) while I would really like to be able to use the High Speed USB port on the Teensy in the future.

Anyway I took a look at your schematic for clarity, I'll just try to tie the USB ground to my signal ground and see what happens :) thanks for the feedback
 
This project is an awesome resource - I am looking at building my own midi to CV box and will probably be using much of the same code and hardware. Thank you so much for sharing!!

I am wondering about a few design choices, and I'm curious if anyone has insights:
1: This project uses a Teensy 2, even though there are more advanced versions of the Teensy available. Is this because the Teensy 2 uses 5v signals? Is it impractical/complicated to use a controller with 3.3v signals, such as the Teensy 3.6?
2: Are there limitations to driving the gate signals straight from the controller pins? Would there be any benefit to using a signal buffer chip like one of these? https://www.mouser.com/ProductDetai...=sGAEpiMZZMuiiWkaIwCK2YBcf8bvyFlO1MEM6vV9G6A=
The plan there would be to have multiple gate/trigger jacks driven off the same pin if possible. My aim is to scale the design up slightly to 4 channels so that I can drive a polyphonic analog synth with 4 different oscillators, while also having the flexibility to switch one or more channels over to monophonic mode (maybe with a portamento control, if I get real fancy with it). I am also considering adding DIN Midi connectors - all of which would be much easier on a Teensy 3.6 (unless of course the 5v logic signals are a necessity).

I am still a wide eyed amateur in the world of coding and circuit design, so I definitely appreciate the amazing info in this thread.
Best,
-Wes
 
Ah, one additional question I forgot to ask: I noticed the schematic shows a 4.7k resistor in series with a 3k resistor. Is there any particular reason why separate resistors should be used rather than a single 7.7k? My assumption is that this is to make use of more easily sourced resistor values, but I'm not sure.
Thanks!
 
Wes, I'm glad you found this useful! In response to your first question, yes I did choose the Teensy 2 because I wanted to use 5V logic. I see no reason you couldn't use a 3.3V board. You will still want to run the DAC off of 5V to get the full range output. And in response to your second question, it probably is preferable to use a buffer with the gate to protect the Teensy board. I've only put resistors on the gate outputs which offers some protection but I think your plan is better.

This project is an awesome resource - I am looking at building my own midi to CV box and will probably be using much of the same code and hardware. Thank you so much for sharing!!

I am wondering about a few design choices, and I'm curious if anyone has insights:
1: This project uses a Teensy 2, even though there are more advanced versions of the Teensy available. Is this because the Teensy 2 uses 5v signals? Is it impractical/complicated to use a controller with 3.3v signals, such as the Teensy 3.6?
2: Are there limitations to driving the gate signals straight from the controller pins? Would there be any benefit to using a signal buffer chip like one of these? https://www.mouser.com/ProductDetai...=sGAEpiMZZMuiiWkaIwCK2YBcf8bvyFlO1MEM6vV9G6A=
The plan there would be to have multiple gate/trigger jacks driven off the same pin if possible. My aim is to scale the design up slightly to 4 channels so that I can drive a polyphonic analog synth with 4 different oscillators, while also having the flexibility to switch one or more channels over to monophonic mode (maybe with a portamento control, if I get real fancy with it). I am also considering adding DIN Midi connectors - all of which would be much easier on a Teensy 3.6 (unless of course the 5v logic signals are a necessity).

I am still a wide eyed amateur in the world of coding and circuit design, so I definitely appreciate the amazing info in this thread.
Best,
-Wes
 
If you can find a 7.7k resistor, by all means use that! 4.7k and 3k are more common. Be sure to use metal film resistors which are more temperature stable.

Ah, one additional question I forgot to ask: I noticed the schematic shows a 4.7k resistor in series with a 3k resistor. Is there any particular reason why separate resistors should be used rather than a single 7.7k? My assumption is that this is to make use of more easily sourced resistor values, but I'm not sure.
Thanks!
 
@elkayem, thanks for weighing in! I'll probably just follow the recipe on my first attempt, but if I can make any meaningful tweaks I will certainly share!

Just a quick heads up - I noticed the schematic calls for a 7805TV power regulator, but I think it needs to be added to the bill of materials (unless folks are going to just use USB power). It's cool to see that technique of grabbing 5v from a eurorack supply, I will probably re-use that a bunch for other micro-controller modules ^_^
 
Just a quick heads up - I noticed the schematic calls for a 7805TV power regulator, but I think it needs to be added to the bill of materials (unless folks are going to just use USB power). It's cool to see that technique of grabbing 5v from a eurorack supply, I will probably re-use that a bunch for other micro-controller modules ^_^

Thanks for the tip! I will update the list of materials.
 
OMG , i FEEL LIKE CRYING FINALLY AN ANSWER TO MY PROBLEM( sorry for all caps). First, did you every complete this. Second I am a beginner in the diy world, and I was looking to build an analog synth, however didnt want to go the route of traditionsl matrix scanned keyboard for cv and gate due to time, finances and experience. so I will be using a midi controller such as the novation launchkeys. I wanted to know if I could use the teensy as a bridge between the Novation launchkey and my analog diy synth so as to use the launch key to provide CV, and gate/trigger signals to the analog modules. Thank you so much
 
Thank you so much for your work and providing it to others especially beginners like me. I want to knOW If I can use the teensy 4.0 in this project
 
Back
Top