PDA

View Full Version : [posted] (yet another) MIDI to CV Converter!



elkayem
12-29-2017, 12:16 AM
I'm sure this project has been done countless time, but this one is mine, and comes in a nifty 3D printed case!

12427

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:

12428 12429 12430 12431 1243412432 12433

oddson
01-02-2018, 04:32 PM
// 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?

Theremingenieur
01-02-2018, 07:41 PM
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.

elkayem
01-03-2018, 01:05 AM
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.


// 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

elkayem
01-03-2018, 02:22 AM
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.

Theremingenieur
01-03-2018, 03:29 AM
Middle C = 0.000V is not an official convention, but an unofficial standard introduced by R. Moog in the middle of the 1990ies.

elkayem
01-03-2018, 04:50 AM
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?

Theremingenieur
01-03-2018, 05:19 AM
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

oddson
01-03-2018, 12:01 PM
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.

elkayem
01-03-2018, 01:13 PM
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

Oh WOW! Now you’ve got me excited. Your design is exactly what I was hoping for! Now I have my next project. Off to Mouser and eBay to procure some parts...

elkayem
01-03-2018, 03:17 PM
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...

Nantonos
01-06-2018, 03:51 PM
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.

elkayem
01-06-2018, 08:21 PM
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.

12536

MickMad
03-21-2018, 11:56 AM
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?

elkayem
03-21-2018, 03:48 PM
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.

MickMad
03-21-2018, 04:27 PM
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

Robin
06-15-2018, 05:02 PM
This project went up on the blog today. :)
https://www.pjrc.com/midi-to-control-voltage-converter/

wvanderveeb
11-07-2018, 04:54 PM
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/ProductDetail/Texas-Instruments/CD74HC4050E?qs=sGAEpiMZZMuiiWkaIwCK2YBcf8bvyFlO1ME M6vV9G6A%3d
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

wvanderveeb
11-08-2018, 04:57 AM
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
11-10-2018, 04:37 AM
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/ProductDetail/Texas-Instruments/CD74HC4050E?qs=sGAEpiMZZMuiiWkaIwCK2YBcf8bvyFlO1ME M6vV9G6A%3d
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

elkayem
11-10-2018, 04:38 AM
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!

wvanderveeb
11-11-2018, 12:46 AM
@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 ^_^

elkayem
11-21-2018, 03:57 AM
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.

Orhema
11-17-2019, 12:00 AM
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

Orhema
11-17-2019, 12:02 AM
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

elkayem
11-17-2019, 02:31 PM
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

I am glad this project looks useful to you. I used the Teensy 2.0 in this project because I wanted the 5V outputs on the gate and trigger, and the 2.0 is more than enough to get the job done. Of course you could use a 3.3V board like the 4.0 if you wished, but my recommendation would be to stick with the 2.0 since the extra horsepower of a 32-bit board is not needed for this project. Also, if you are using my PCB design, the pinout is for the 2.0 and would not be compatible with the 4.0. Otherwise you would need to breadboard the circuit.

If you're interested (and in the US), I could send out one of my PCBs to you at cost. I have a few extras lying around. You would need to source the components from Digikey or Mouser.

Orhema
11-17-2019, 11:33 PM
Thank you for your advice. Will there be a way to convert the 3.3v out to 5v

elkayem
11-18-2019, 12:03 AM
Thank you for your advice. Will there be a way to convert the 3.3v out to 5v

There are a number of different ways to convert 3.3v logic to 5v. The first question to ask is whether you even need to convert. This depends on the synthesizer you intend to drive. It is possible that 3.3v logic will be sufficient. For example, even if the input is 5v TTL logic, it will register high at 2v so can be driven by a 3.3v output. Alternatively, your synthesizer may require 12v logic. Some do.

I suggest you take a look at this link (https://hackaday.com/2016/12/05/taking-it-to-another-level-making-3-3v-and-5v-logic-communicate-with-level-shifters/) for more info on logic conversion.

Orhema
11-18-2019, 01:12 AM
Thank you that makes sense. I know some synthesizers are +/-5V and others are +/-10V. I am guessing since mine is a +/-5V It would require a 5V level conversion

Orhema
11-21-2019, 11:20 PM
Please what pins on the 2.0 did you use for the gates. Also can the gate be used to control external ADSRs

fisico
01-02-2020, 09:53 AM
Hi elkayem,
Is there a way to add portamento/glide to the midi cv interface? I think it is a very important function.
The Portamento amount could be controlled with the rotary encoder.

oddson
01-03-2020, 03:24 AM
Analog portamento is typically a lowpass filter (with a very low cutoff) or slew limiter to retard the voltage shift on note changes.

It can be done fairly easly in either digital or analog domains.

craigyb
03-07-2020, 09:09 AM
Nice project, do you think it would be possible to expand it to 6 note polyphonic, I have a teensy 3.5 available for the extra pins etc.

I don't need the pitchbend as that is handled elsewhere, but Pitch, velocity and gate for 6 notes would be awesome, looking at the code it seems fairly easy to expand it but maybe the 2.0 would not cope with 6 notes.

Also I would like to use MIDI (5 pin) and not USB MIDI for the input, again I think this is possible with additional circuitry for the MIDI in and code changes.

oddson
03-07-2020, 04:06 PM
I'm nearly certain the T2.0 would handle three more outs.

The challenge in extending this application isn't only from the coding but also from the analog circuit.

This is fairly advanced stuff so are you capable on both sides?

craigyb
03-07-2020, 05:06 PM
Thanks for the reply, much appreciated.

I can probably build it ok, analogue and digital circuits are not a problem for me, I've been in IT for over 40 years mainly in hardware. I would say add three more DACs to the circuit and the MIDI in with onto Isolator.

Coding is another matter, its not my strong point, but I have built and coded a 64 way analogue/digital MUX for reading pots and switches into my programmer project. Got it reading stuff, so I'm familiar with some parts of the coding.

I see you are using MCP4822 DACs, I have 10 of them on order and most of the rest of the parts in my spares bin so it should not be too hard to build a board very quickly with the hardware an have a go at modifying the code.

craigyb
04-09-2020, 08:02 AM
Looking at this project a bit more in depth, it is 3 channels monphonic, where as I'm looking for a Polyphonic MIDI to CV converter, maybe too much required to convert it to 6 channels poly with 5 pin DIN midi.

craigyb
04-10-2020, 12:02 PM
Having spent part of the day looking at this again, the Teensy 2.0 is not capable of supporting 6 DAC's with 6 gates and MIDI input, simply not enough pins to connect everything. So I migrated the code as much as I could to a Teensy 3.5 and added 3 more channels and 5 pin DIN midi in using a 6N137. In principle it's all working, menus are functional and just fits 8 lines of the menu (Title/options/Return) for Pitch, Gate and Scaling. I've got all the GATE outputs working as required and just finished adding some DAC's and testing the CV outputs, all looks OK.

19637

I'm happy to publish my changes and a schematic with the permission of the original code owner of course, its not my work after all.

I just need to work out how to make this polyphonic now instead of 6 mono CV's.

Any help appreciated