Author |
Message |
elkayem
Joined: Jul 04, 2017 Posts: 33 Location: Santa Clara, CA
|
Posted: Fri Aug 11, 2017 2:19 pm Post subject:
Midi to CV design -- Soliciting advice |
 |
|
I am currently building the MFOS Ultimate and Ultimate Expander, and would like to add a Midi to CV controller to the box, so I can use my keyboard with it.
I am designing the Midi to CV out of an Arduino board, a few 12-bit DAC chips, op-amps, and other miscellaneous parts. The nice part is that I have quite a bit of flexibility on how I design it. However, I have no direct experience (yet) with analog synthesizers, so it is hard for me to judge what I will really need.
I was thinking I would include the following outputs:
* CV note output (top note, 1V/oct)
* Gate
* Trigger
* Pitch bend (using pitch wheel on my keyboard)
* Pedal
Are there any of the above that I should omit? Anything I haven't considered that I should add? As an alternative, I was also considering adding multiple CV note outputs so I could drive multiple VCOs, but I assume this means I would also want to add multple gates and/or triggers for each output.
Any tips? What features are key vs not useful? I'm sure there are plenty of others who have assembled similar things, so I'm also interested in any lessons learned. Last edited by elkayem on Fri Aug 11, 2017 5:18 pm; edited 1 time in total |
|
Back to top
|
|
 |
elkayem
Joined: Jul 04, 2017 Posts: 33 Location: Santa Clara, CA
|
Posted: Fri Aug 11, 2017 2:42 pm Post subject:
|
 |
|
I should add... I also am thinking about velocity as another CV output, for a total of four CV outputs: note, pitch bend, pedal, and velocity. Too many? |
|
Back to top
|
|
 |
JovianPyx

Joined: Nov 20, 2007 Posts: 1988 Location: West Red Spot, Jupiter
Audio files: 224
|
Posted: Fri Aug 11, 2017 4:05 pm Post subject:
|
 |
|
A dsPIC33F (Microchip) has multichannel 12 bit ADC built in. May be a better choice than Arduino. It can be programmed in C tho I like Assembly better. dsPIC is also a lot faster.
I would also consider something better than PWM for pitch CV output. Of all the CVs you want accurate, pitch CV is the one... _________________ FPGA, dsPIC and Fatman Synth Stuff
Time flies like a banana. Fruit flies when you're having fun. BTW, Do these genes make my ass look fat? corruptio optimi pessima
|
|
Back to top
|
|
 |
elkayem
Joined: Jul 04, 2017 Posts: 33 Location: Santa Clara, CA
|
Posted: Fri Aug 11, 2017 5:35 pm Post subject:
|
 |
|
Thanks for the tips, Jovian!
I've got a drawer full of Arduino Nanos. I love them and use them for everything. The dsPIC does look like a nice chip, I'll need to check it out.
I'm not using PWM for the analog control. Instead, I have two MCP4822s, which are dual-channel 12-bit DACs and communicate over SPI. I've written the code and breadboarded the circuit already, and can successfully control all four DAC outputs with my keyboard over MIDI. But we'll see if the DAC linearity is good enough for controlling my (under construction) synthesizer.
I think the point of no return is once I put together the panel with my selected outputs. I figure I can always rewrite the code, or put in better performance DACs or op amps, but the front panel will be more of a pain to switch around once I put it together. It's hard to know what I will really want until I have time to play with it. |
|
Back to top
|
|
 |
elmegil

Joined: Mar 20, 2012 Posts: 2179 Location: Chicago
Audio files: 16
|
Posted: Fri Aug 11, 2017 7:52 pm Post subject:
|
 |
|
I would definitely add velocity. |
|
Back to top
|
|
 |
Grumble

Joined: Nov 23, 2015 Posts: 1310 Location: Netherlands
Audio files: 30
|
Posted: Fri Aug 11, 2017 11:25 pm Post subject:
|
 |
|
you could also add a clock output that gives a clock pulse of which the repetition time may be set by a potentiometer (and CV), or have it be controlled by a midi clock signal coming from a drum computer or similar device. Very usefull for controlling a sequencer or adsr. _________________ my synth |
|
Back to top
|
|
 |
elkayem
Joined: Jul 04, 2017 Posts: 33 Location: Santa Clara, CA
|
Posted: Sat Aug 12, 2017 7:47 am Post subject:
|
 |
|
Nice idea, Grumble! My keyboard (Yamaha CP50) does a clock output over Midi that is tied to its metronome and drum machine. I can easily turn that into a pulse pattern.
I do notice that the Sound Lab Ultimate I am assembling has a Repeat Gate and Sample & Hold, which outputs a square wave and trigger with rate set by a potentiometer. I assume this is also what you were suggesting. |
|
Back to top
|
|
 |
Grumble

Joined: Nov 23, 2015 Posts: 1310 Location: Netherlands
Audio files: 30
|
Posted: Sat Aug 12, 2017 8:06 am Post subject:
|
 |
|
elkayem wrote: | I assume this is also what you were suggesting. |
Yup  _________________ my synth |
|
Back to top
|
|
 |
elkayem
Joined: Jul 04, 2017 Posts: 33 Location: Santa Clara, CA
|
Posted: Sun Oct 22, 2017 9:36 pm Post subject:
|
 |
|
Update: I've completed my MIDI to CV converter, and installed it into my Sound Lab Ultimate & Expander (still under development).
The outputs look great in my oscilloscope, though I haven't yet been able to try it in my yet-to-be-completed synth. Man oh man, that beast takes a lot of soldering! Maybe I'll have the full thing completed by the end of the year.
For anyone interested in building or improving upon the design, I've made the Arduino code and schematics available here:
https://github.com/elkayem/midi2cv
Of course suggestions for improvements are always welcome! |
|
Back to top
|
|
 |
elmegil

Joined: Mar 20, 2012 Posts: 2179 Location: Chicago
Audio files: 16
|
Posted: Sun Oct 22, 2017 10:57 pm Post subject:
|
 |
|
I would be inclined to suggest that you buffer the clock/trigger/gate.
You absolutely need protection resistors on the velocity and control and pitch bend, and probably would be best to buffer them as well. A 4822 is not a cheap little chip, and you're set to fry it when it's sending a high voltage and you patch it, when it will momentarily be shorted to ground.
Your LM324 has no output protection either; it's common to put at least a 330R in line with them, older circuits will typically use 1K. If you are concerned about drop in the note value, you can move the 330R inside the feedback loop (between pin 1 and the 7.7K resistor).
Speaking of the LM324, that's a quad op amp, and you're only using one? It would be trivial to buffer pitch bend, control, and velocity with the other three op amps. If you use another LM324 for clock, trigger & gate, remember that the unused op amp should be wired as a follower with a ground input (i.e. ground + input, connect - input to output). Letting them float will affect other op amps on the same die.
Where are you getting a 7.7K resistor?? Edit: ah, I see, you're combining a couple. Might be better to use a trimmer there, if you need some precision.
Edit 2: Ok, you're using bananas, so short to ground when patching shouldn't be an issue; however, it is still good practice to buffer and protect the outputs. |
|
Back to top
|
|
 |
elkayem
Joined: Jul 04, 2017 Posts: 33 Location: Santa Clara, CA
|
Posted: Mon Oct 23, 2017 8:45 am Post subject:
|
 |
|
Hi Elmegil,
Thanks for reviewing the schematic! I do appreciate the feedback.
Regarding buffering the clock/trigger/gate, my thinking was that the 300 ohm resistors would be sufficient to prevent excessive current draw. Each GPIO can source or sink 40 mA, and grounding one of these outputs with a 300 ohm resistor would draw 17 mA. (Thinking this over again, maybe I should use 1K resistors instead, in case I accidentally plug this into another output sitting at -12V!) Would there be any advantage to buffering these outputs rather than using a series resistor?
I purposely did not buffer the analog outputs of the DACs. According to the MCP4822 datasheet, the outputs are already buffered, and on p. 26 states that the MCP4822 "does not require any external output buffer
for most applications." I assume that means I am in the clear. Or are there other concerns?
I did think about putting an output resistor on the op-amp, but opted not to because I was concerned about the voltage drop. According to the LM324 datasheet (absolute maximum ratings), the op amp can have the output shorted to ground continuously, with max current limited to around 40 mA. However, your suggestion to put a 300 ohm resistor at the output of pin 1 before the 7.7K feedback is a great idea, and cheap insurance in case I have misunderstood the datasheet. I hadn't thought of that.
I agree using a quad op-amp was wasteful, and I hated doing that! I had a dozen of them on hand and didn't have any of the single op amps when I put this together, so I was just being lazy. I did not know that allowing the other op amps to float would affect the one I am using. Thank you for pointing that out! I will wire the unused ones as you suggest, unless I really should be buffering some of the other signals. |
|
Back to top
|
|
 |
JovianPyx

Joined: Nov 20, 2007 Posts: 1988 Location: West Red Spot, Jupiter
Audio files: 224
|
Posted: Mon Oct 23, 2017 9:04 am Post subject:
|
 |
|
Regarding buffers:
A buffer will protect the GPIO far better than a resistor. Your example of shorting to -12 through a resistor can still damage the GPIO. Using a buffer will prevent damage to the GPIO - however, such a short would probably blow the buffer - but at least the buffer is inexpensive compared to replacing an MPU.
Also note that "most applications" is not the same as "any or all applications". Applications that allow external user patching can always be problematic if you "accidentally" plug into something that is inappropriate. Buffers are inexpensive and protect your gear, I would strongly advise using them. _________________ FPGA, dsPIC and Fatman Synth Stuff
Time flies like a banana. Fruit flies when you're having fun. BTW, Do these genes make my ass look fat? corruptio optimi pessima
|
|
Back to top
|
|
 |
elkayem
Joined: Jul 04, 2017 Posts: 33 Location: Santa Clara, CA
|
Posted: Tue Oct 24, 2017 8:57 pm Post subject:
|
 |
|
Ok, I've listened to the voices of wisdom and implemented buffers on all four DAC outputs. This takes care of the floating op amps and protects the DACs. Jovian, you are correct that "most" applications is not "all", and I see no indication on the data sheet that these DACs can tolerate a short to ground. (Though no indication they can't, either.) I have also increased the 300 ohm resistors on the clock/gate/trigger outputs to 1K, which should be sufficient when tying it to anything in the +/-12V range. (I know that buffers were recommended here too, but I'm willing to wager a $3 Nano clone on that, and willing to be proved wrong.) The soldering took all of 15 minutes, so no point in dragging my feet! GitHub repository is now updated.
Thanks all for the tips! One of these days I'll post my completed MFOS Ultimate and Expander, if I can ever finish it. Meanwhile, I'll be lurking around this site, hoping to glean some more useful knowledge... |
|
Back to top
|
|
 |
gabbagabi

Joined: Nov 29, 2008 Posts: 652 Location: Berlin by n8
Audio files: 23
|
Posted: Wed Oct 25, 2017 1:41 am Post subject:
|
 |
|
well done, also your expander is very good looking!
cheers, bb |
|
Back to top
|
|
 |
Sheer Kahn

Joined: May 07, 2007 Posts: 12 Location: Bottom Left, UK
|
Posted: Thu Oct 26, 2017 9:42 am Post subject:
|
 |
|
thanks a lot for this, exactly what I've been looking for, I will hopefully get to build it next week  |
|
Back to top
|
|
 |
Sheer Kahn

Joined: May 07, 2007 Posts: 12 Location: Bottom Left, UK
|
Posted: Sat Oct 28, 2017 12:50 pm Post subject:
|
 |
|
The DACs turned up faster than I expected, so I got this breadboarded today, worked first time and tracking very nicely (when I put my scope on the right setting ) .
Thanks a lot for sharing your work!
A couple of questions I have (sorry this is my first time using Arduino)
The pitchbend goes +1v, so that's +/-600cents (right?), is it fairy easy to get this to go a bit higher, even +2v, so I can have +/-1200cents. I'm looking at the lines of code:
Code: |
// Pitch bend output from 0 to 1023 mV. Left shift d2 by 4 to scale from 0 to 2047.
// With DAC gain = 1X, this will yield a range from 0 to 1023 mV.
setVoltage(DAC2, 0, 0, d2<<4); // DAC2, channel 0, gain = 1X |
is it simple as changing the 0 to 1 for the gain multiplier?
Also, if I play a note lower than C1, it locks up and requires a reset, is there an easy way to filter out notes below C1 or something like that?
Again, sorry for the noob questions, and thanks a lot for this, it's really made my weekend! |
|
Back to top
|
|
 |
elkayem
Joined: Jul 04, 2017 Posts: 33 Location: Santa Clara, CA
|
Posted: Wed Nov 29, 2017 9:24 am Post subject:
|
 |
|
Hi Sheer Kahn,
Apologies for the month delay, but I just saw your note this morning!
Sheer Kahn wrote: |
The pitchbend goes +1v, so that's +/-600cents (right?), is it fairy easy to get this to go a bit higher, even +2v, so I can have +/-1200cents. I'm looking at the lines of code:
Code: |
// Pitch bend output from 0 to 1023 mV. Left shift d2 by 4 to scale from 0 to 2047.
// With DAC gain = 1X, this will yield a range from 0 to 1023 mV.
setVoltage(DAC2, 0, 0, d2<<4); // DAC2, channel 0, gain = 1X |
is it simple as changing the 0 to 1 for the gain multiplier?
|
You got it! I'm guessing you have tried it already and found it to work.
Sheer Kahn wrote: |
Also, if I play a note lower than C1, it locks up and requires a reset, is there an easy way to filter out notes below C1 or something like that?
|
That is very strange. The microcontroller locks up? I can play all 88 keys on my keyboard, down to A0, with no issues. If you discover the cause of the problem you are encountering, I would be interested to find out what it is. |
|
Back to top
|
|
 |
elkayem
Joined: Jul 04, 2017 Posts: 33 Location: Santa Clara, CA
|
Posted: Wed Nov 29, 2017 9:31 am Post subject:
|
 |
|
Sheer Kahn wrote: |
is it simple as changing the 0 to 1 for the gain multiplier?
|
Alternatively, you could also bit shift by 5 instead of 4 to get the 2X gain you are looking for, i.e. setVoltage(DAC2, 0, 0, d2<<5); A combination of the gain multiplier and bit shift will give you the full 4V that the DAC can output. |
|
Back to top
|
|
 |
Sheer Kahn

Joined: May 07, 2007 Posts: 12 Location: Bottom Left, UK
|
Posted: Fri Dec 01, 2017 1:34 pm Post subject:
|
 |
|
No worries man! thanks for the reply, yeah I got it working great, nice one.
I didn't find the problem with the lockups, but for some reason it's stopped doing it at the moment, so I'll keep you posted on that one. |
|
Back to top
|
|
 |
elkayem
Joined: Jul 04, 2017 Posts: 33 Location: Santa Clara, CA
|
Posted: Thu Dec 07, 2017 10:36 pm Post subject:
|
 |
|
Sheer Kahn, I'm glad you got everything working! It has been an essential addition to my synth.
I reviewed the code, and have a good idea on why your device may have been locking up. I made the implicit assumption in the code that the MIDI note would always be between 21 (A0) and 108, which is the normal range of an 88 key keyboard. If it returned a note outside this range (e.g., below 21), the code would write to unallocated memory. Doh! In that case, anything might happen. Anyway, I've fixed it and pushed the fix.
Sheer Kahn wrote: | No worries man! thanks for the reply, yeah I got it working great, nice one.
I didn't find the problem with the lockups, but for some reason it's stopped doing it at the moment, so I'll keep you posted on that one. |
|
|
Back to top
|
|
 |
Sheer Kahn

Joined: May 07, 2007 Posts: 12 Location: Bottom Left, UK
|
Posted: Tue May 08, 2018 9:19 am Post subject:
|
 |
|
I am still using this, it's great. Thanks for the latest fix.
Is there an easy way to add MIDI clock out to it? |
|
Back to top
|
|
 |
Sheer Kahn

Joined: May 07, 2007 Posts: 12 Location: Bottom Left, UK
|
Posted: Thu May 10, 2018 3:50 pm Post subject:
|
 |
|
Yeah, I figured out that it already has MIDI clock.
You wouldn't have thought I'd been using it all this time and never realised. for some reason I didn't connect it up first time round.
Anyway, thanks again for the great project |
|
Back to top
|
|
 |
elkayem
Joined: Jul 04, 2017 Posts: 33 Location: Santa Clara, CA
|
Posted: Fri May 11, 2018 8:27 am Post subject:
|
 |
|
Sheer Kahn wrote: | Yeah, I figured out that it already has MIDI clock.
You wouldn't have thought I'd been using it all this time and never realised. for some reason I didn't connect it up first time round.
Anyway, thanks again for the great project |
Glad you found the clock output! And that you are continuing to find this design useful!
The code for this project is fairly simple and certainly could use a few more features. You might also borrow from my multi-channel version at https://github.com/elkayem/usbMIDI2CV_MC, which has a few more features. For example, the multichannel code has different options for note priority (e.g., highest note, lowest note, last note), which may be useful to you. |
|
Back to top
|
|
 |
hububalli
Joined: Feb 15, 2014 Posts: 41 Location: UK
|
Posted: Sun Apr 07, 2019 1:31 pm Post subject:
|
 |
|
Just built one of these Midi2CV and it is great.
I an trying to make an adjustment to the pitche bend. I would like it to shift just one tone in each direction. I have been messing around with the code but can't figure it out properly.
Thanks, |
|
Back to top
|
|
 |
elkayem
Joined: Jul 04, 2017 Posts: 33 Location: Santa Clara, CA
|
Posted: Sun Apr 07, 2019 11:13 pm Post subject:
|
 |
|
hububalli wrote: | Just built one of these Midi2CV and it is great.
I an trying to make an adjustment to the pitche bend. I would like it to shift just one tone in each direction. I have been messing around with the code but can't figure it out properly.
Thanks, |
Fantastic! I hope you are finding it useful.
From your note, I understand you want to modify the pitch channel to output plus or minus one tone (two semitones)? That would be a total range of four semitones, or 1/3 an octave. Presently, the code outputs a range of a full octave (+/-0.5 V) so all you need to do is rescale the output. Notice line 226:
Code: |
setVoltage(PITCH_DAC, PITCH_AB, 0, d2<<4);
|
The line d2<<4 multiplies d2 by 16. I think if you replace this by d2 * 5, you will get just about what you want. That maps the midi message 0 to 127 into a range of 0 to 0.32 volts, or up and down by a tone. If you wanted to be exact, you would need to do something like (int)(5.208f * d2), which will map the midi message into a 0.333 V range.
Keep in mind that this converter does not output negative voltages, so the pitch bend will always start at 0V for the negative end of the range. |
|
Back to top
|
|
 |
|