Prototyping a Midi to CV module with more functionality than existing offerings

Hi everyone,
The core of my Kosmo set up is nearly complete, but there is one thing my set-up is really missing: a Midi to CV module that does absolutely everything. I think we could all use a module like this. Building a customizable platform for midi/CV conversion will be a fair bit of work, but I think tons of people would benefit.

In the hopes of rallying some smart people to the cause, I’m going to lay out the shortcomings of the offerings currently on the market, as well as my wishlist of functionality, and my plan for getting there. I think the circuit should be pretty straightforward, but I’m going to need to learn a lot more C++ than I currently know, so I hope perhaps there will be others who are interested in contributing.

Issues with existing offerings:

  • Midimuso (what I’m currently using): Damn good option for the money, but I want more flexibility. It has 23 outputs, most of which sit empty because I can’t customize what it does, or change presets in a non-fiddly way. The outputs I do use go into a buffered multiple, taking up more rack space. Still, can’t go wrong for the money.

  • Erica Synths Black MIDI-CV V2: Costs $200 and has minimal functionality. No thanks.

  • Polyend Poly 2: Getting there, but it’s $400 friggin dollars and the community could probably design something better that could be built for $50.

  • This project: GitHub - elkayem/usbMIDI2CV_MC: A multichannel USB MIDI to CV converter using the Teensy 2.0 development board
    I’m very impressed by this project and I’m using it as the basis for my current prototype. I really love the oled + rotary encoder interface, since it only needs a total of 5 microcontroller pins to have a fully interactive menu system, and it looks badass. The project is open source, and I think expanding on Elkayem’s work is probably the way to go.

Wishlist of features:

  • 5 Pin midi and USB midi in
  • 5 pin midi through
  • No need for buffered multiple - every oscillator has its own CV output (at least 5 or 6)
  • Plenty of outputs for velocity/CC (10+?)
  • Plenty of Gate/Trig/Clock outputs
  • Every output will be freely configurable using the rotary encoder + oled menu. Every CV output can be set up as Volt-per-octave, or configured for CC/pitch bend, and can be assigned any midi channel. To drive 2 or more oscillators in unison, simply assign them all to the same midi channel. The reference project above already has implemented scaling adjustments to the volt-per-octave channels.
  • Volt Per Octave outputs have configurable high note, low note, last note response.
  • DAC chips are expensive, so naturally some of the outputs will be gate/trigger/clock pulse only. All “high/low” outputs can be configured with gate/trigger response, midi channel, or clock division.
  • Recallable pre-sets: This is a big one for me, and might merit a separate control to avoid mid-performance menu diving. I think this would be very useful for changing voicing structures on the fly. For example, my box contains 3 synth voices, consisting of 5 oscillators. There are several ways those voices could be grouped or broken up, and recallable presets would let me broaden my available sound-palette without swapping cables. I think every person would have their own use case.
  • The ability to assign multiple volt-per-octave outputs into a single polyphony or paraphony group. If I’ve got 3 oscillators going into a single filter, why not have pre-sets that allow them to play chords instead of unison?
  • Stretch goal - it would be fun to have a menu wherein the oled screen can display a tuner, but I suspect this would be difficult to implement.
  • Stretch goal - if there are a few spare digital output pins at the end of the project, it could be interesting to connect them to relays and have some automatic signal routing happen when pre-sets are recalled. This is by no means crucial.

The plan for getting there:
I am still working out exactly what hardware I would propose using, but here is a rough outline:
Screen:
http://www.diymalls.com/0.96-Inch-I2C-IIC-OLED-Display-Module?search=oled
These are cheap and look awesome. The yellow and blue is particularly fun.

Rotary encoder: Anything with 2 pins for the pushbutton and 3 pins for the rotary element is interchangeable. They are cheap.

DACs: These will be the most expensive part of the build. The example project above uses MCP4822s. At around $3.30 a whack, you could easily spend $30+ on them. The MCP4922 is a little cheaper but requires an external voltage reference. If anyone knows of a cheaper DAC or knows how to achieve the effect with pulses and capacitors as in the Midimuso, by all means, let me know.

Controller: The example project above uses a Teensy 2.0. I think we might need more pins, so I have a Teensy 3.2 and 3.6 at the ready.

It’s nearly 2:00 AM so I need to stop typing, I will try to edit for coherence tomorrow. In any case, I’d love to hear feedback, gauge interest, or hear others’ ideas for how to make the ultimate midi to cv conversion platform that does everything for everybody. It can totally be done, it’s just a bit of an engineering challenge!

2 Likes

To dispense with DACs you can use PWM pins and external filters. If you look at @HAGIWO’s designs he uses two PWM pins for a single CV output, to get higher resolution, and a 2nd order passive filter. On the other hand the Kassutronics Quantizer uses only a single pin because for semitone resolution that’s all you need, but it uses a 4th order buffered passive filter; see the build docs, page 15. I sort of suspect the former design is too simplistic for accurate MIDI to CV and the latter is too low resolution if you want sub semitone accuracy (for microtones etc.) but both are worth studying for ideas.

You can get up to 16 bits resolution on a single PWM pin with some more involved programming, see Arduino & Advanced 16-bit PWM - Codrey Electronics and arduino uno - Increase PWM bit resolution - Arduino Stack Exchange . The 32 bit Teensys use a different microcontroller, though, so the details would be different.

2 Likes

Well, not really, because what you describe is a lot more functionality than I would use, at a cost of greater complexity, a somewhat convoluted user interface, and probably larger width than my MCVI, which admittedly is too simplistic even for my needs beyond the immediate short term, but it’s closer to what I want. (It’s also based on an Elkayem design.) Trying to design one module that’s everything to everyone is destined to fail. Design one that fills your needs.

You’ve got a pretty massive set of design goals there. If you can do it, great, but you might want to start smaller — often something that gets you about 85% of what you want is about 25% as difficult. Then you can take lessons learned from that and get to work on your ideal module.


Added: Ask yourself “how often would I want to do xxx”? If the answer is “frequently”, make it something you can do with your OLED/encoder. But if it’s some configuration you’d probably set just once, or once every few months, consider whether it wouldn’t be better to make it a software compilation option, to keep the menu system as simple and easy to use (and to program) as possible.


Also, to your list of “existing offerings” with available schematics you can add:

  • Erica Synths DIY MIDICV (though the firmware is closed source)
  • Befaco MIDI Thing
3 Likes

A grounded take as usual, analogoutput. I suppose with my current skills (and a lot of searching and fiddling) I could probably get 80% of the way there, but 100% would be a whole other animal. Thanks for the recommended reading, I’ll have a look at those links. Getting 16 bits of DAC without a DAC chip seems like a way to massively simplify the circuit and reduce cost, though it will probably be quite the coding challenge.

2 Likes

i would also experiment with an r2r resistor ladder dac. Havent done it with CV. However, i can get a good approx of a sine wave out of it, so its got to be good enough for cv.

Here is a 4-bit ladder example:

1 Like

For decent pitch resolution and linearity (a few cents out of several octaves), I think your resistors need to be matched at the level of somewhere around 0.025%. And you probably want 10 bits at minimum which is 21 resistors for each output (32 if you use all the same). Higher resolution if you want sub-semitone control. 8 bits with 1% resistors might give you a pretty good sine wave, but pitch is a whole different thing.

1 Like

That’s Mozzi’s “HIFI audio mode” which is the dual 7-bit PWM from this Open Music Labs article (the labs’ cert need fixing, but as long as you only read things you should be safe).

[…] for now we recommend either Dual 8 bit PWMs or Dual 7 bit PWMS with a 3.9k resistor on the high byte, and a 1M resistor for the low byte on the 8 bit version, and 499k for the 7 bit version. These resistors should be at least 1% accuracy.

(the “exceptional” variant there is quite snazzy, btw.)

1 Like

Oh, right, I’d forgotten about those pages. They have several on PWM DAC, starting with this one

https://www.openmusiclabs.com/learning/digital/pwm-dac.1.html

(you have to dig into the Learning >> Digital menu to find the others)

Add: The down side is needing two PWM pins for each output, and it sounds like you ( @WesleyV ) want something like 15 or 20 CV outputs. 30 to 40 PWM pins is at or above the number available on the Teensy 4.0 and 4.1, never mind the 3.x ones. (The 3.6 has 22 PWM pins.) Maybe it can be done using fewer pins and analog multiplexers? Could it be done fast enough to seem smooth? Or maybe you could use single pins with a Teensy, the documentation says it’s 16 bit PWM, though the openmusiclabs page @fredrik linked talked about advantages of dual pin over single pin. For a DAC solution, I would think 8 or 10 dual DAC chips could be driven direcly without digital multiplexing by a Teensy 3.6. Not that I’ve ever used a Teensy, so don’t quote me!

Thanks for the suggestions everyone. Based on what I’ve read, I think I’m not skilled enough to implement the DAC through PWM strategy. At the moment I have 9 of MCP4922 on my hands, so I plan to start with 6 of them since that’s what I feel I can realistically fit on my largest strip board. They are all 2 channel, so I’ll have a total of 12 analog outputs (no pun intended). It looks like Elkayem has less gain on the op-amps that process the CC outputs than the ones that process the volt-per-octave channels, presumably to make them less steppy. Unless I want to reinvent the wheel, I think I might have to just accept that I need to choose ahead of time which are for CC and which are for volt-per-octave. I’ll probably do 6 VPO and 6 CC.

Elkayem is also driving the trigger signals straight off the Teensy pins, which I don’t have a ton of faith in should I plug them into something weird by mistake, so I plan to buffer those (and add more of them, I’ll probably start with 6).

I also plan to change Elkayem’s original design by upgrading to a Teensy 3.2 and adding 5 pin midi in/through. I’m out of TL074’s, so I’m going to try to do this all with LM324N’s as in Elkayem’s design. I have no idea what the difference is, as a mere EE poseur.

My plan at the moment is to get the hardware configured, and then just get the bare minimum code running to make it useable, so I can slowly upgrade the firmware at my leisure (read “never fully finish the project”).

One quick question for the community - the MCP4922 requires an external voltage reference. I know I have a few VREF ICs around somewhere, but I’m not clear on whether all 6 DACs can be plugged into the same VREF, or if I need a separate voltage ref IC for each DAC. I’m also not clear on what effect different reference voltages will have on the DAC. Presumably it will scale the output up and down and I will need to adjust the gain resistors on the buffer stage to compensate? In conclusion, I shoulda just shelled out the extra money for the MCP4822s. Thanks for any insight y’all might have.

The LM324N is designed to be usable as a single supply op amp connected to +V and GND instead of +V and -V. In that case of course it means it would only output positive voltages, so for instance pitch bend would have to be something like 0 to 1 V centered on 0.5 V instead of -0.5 to +0.5 V centered on 0 V. But per the datasheet it can be used with dual supplies too.

One voltage reference can connect to all the MCP4922s. The voltage reference determines the output voltage range: Digital 0 gives 0 V and digital 4095 gives Vref.

Indeed Elkayem uses different (hardware) gains for the CC and V/oct output op amps, and also different modes of the DAC (selected by the software), to get the best resolution for the smaller CC voltages. But Befaco for instance does not, and their MIDI Thing can output V/oct or CC on the same output depending on the mode. They just eat the reduction in resolution. You can work out what the voltage steps would be if you took that approach and see if you think you need different hardware gains or not. (Another idea would be to use an analog switch to connect different resistors to change the output gain under software control.)

All great information, thank you analogoutput. Thank you. I’ve got some head scratching to do as to whether to buy more appropriate stuff, or work with what I’ve got. In any case, I think I’ve got the info I need to start breadboarding!

1 Like

Hi again all,
I’m looking for a handy solution to conveniently buffer six gate signals from my Arduino, and I think I might be onto something. I remembered I have some of these laying around:
The CD4050BE

I believe this chip was originally intended for logic level shifting, but if I’m not mistaken, I can literally just connect the chip to 5V and GND, connect the Arduino pins to the inputs, and get buffered signals at the output without so much as a resistor involved. This should also boost the level from 3.3v on the teensy 3.2 to 5v for the gate signal, and all six gates can be run through a single chip.

Is anyone familiar with this IC, or aware of a reason why this might be a good/bad idea? I saw in one demo that for some reason the chip was causing interference with the power rail, which did make me raise an eyebrow (here is the link: Drive LEDs Without Resistors - Hex Buffer CD4050B Has A Trick Up Its Sleeve - Simply Put - YouTube). For $0.62 a whack though, I could see this being a handy circuit building block for a lot of folks if it does what I think it ought to.

Looks kind of like the CD4504 though with some differences in how the level shifting works. The 4504 is used in the 1007 Midimuso to level shift the PWM signals.

If you have a corporate or academic email address, you can access free samples of most of the Microchip products here. The website is a little tricky to navigate as you have to make an account, log in to the main website, then the samples website. The MCP4822 is under Data Converters/Analogue to Digital Converters/MCP4822. Click the tiny grey button next to the correct package(double check!) Then to increase the amount from 2 to 5 you have to go to manage cart/change amount to 5/update cart.
In the UK at least, it usually takes around 2 weeks to arrive.

I have a few of these; I tied the reference pin to the 5v rail with no issues.

Hope that made sense :grinning:

Interesting hack, Sonosus, I might give it a try at some point.

To anyone interested - I’m making some progress on this circuit, and I think I may have found a nice workaround for the loss of resolution when using volt-per-octave outputs for a midi CC. I noticed that the MCP4922 has an internal gain setting of 1 or 2, which I believe can be toggled any time by the Arduino. This means if I make proper use of the Vref and op-amp gain to get volt-per-octave at a gain of 2, I can simply toggle the DAC to unity gain to halve the range and double the resolution with no need to switch hardware. Should be quite handy, although I’m still figuring out how negative pitch bend voltages are going to work, or if I should even try.

1 Like

at 12 bit, I can hardly imagine that the “steppiness” in a control voltage other than v/oct would be perceivable. I would worry more about the pitch signals.

If you would want to cover a full 10 octave range, a 12 bit DAC gives you (10 oct * 12 semitones/oct * 100 cent/semitone) / (2^12 bit) = 3 cent resolution. I’d consider this on the verge of acceptable, anything above 5 cents will generally be perceived as ‘out of tune’.

This is, however, considering a perfect DAC. The MCP4922 has a maximum INL of 4*LSB, giving you a 12 cent difference at worst.

1 Like

Yes, and Elkayem’s earlier DIN MIDI to CV, which is what my MCVI is based on, does make use of that (that’s the “different modes of the DAC (selected by the software)” I mentioned) in addition to different output gains.

My understanding is that pitch differences of 3 cents are the limit of what a trained ear can distinguish, so I’d call it definitely acceptable. (Though even smaller pitch differences can lead to audible differences in beat frequencies between two notes played simultaneously; if you’re worried about that, then you need probably at least 16 bit resolution.)

Right, and there was some discussion of that elsewhere. In principle, you can map the nonlinearity of a particular DAC and correct for it in software. Something I want to consider for MCVII. (In fact you can even map and correct for the nonlinearity of a particular DAC/VCO combination, if you want — compensating for VCO nonlinearity too.)

Add: Also, as pointed out here, if you pick just the right voltage reference value for the DAC, it’s possible to get 0 cents maximum resolution error (for MIDI notes, not for arbitrary pitches)! You lose about half an octave of range if you do that, though. And it probably doesn’t work with nonzero nonlinearity. Not really worth it.

2 Likes

This is a lot to take in, but I really appreciate everyone weighing in. I’d probably be willing to tolerate a slight reduction in range to get better accuracy, but I think I need to get everything up and running before I worry about all that. After this build I’m gonna need a break from building to just play some music!

3 Likes

Hi all,
I’ve made a lot of progress on this project and I am ready to start posting some updates, but there is one problem I just can’t seem to track down - my 5 pin midi input circuit is just NOT working for some reason. Here is a snippet of my layout, specifically for the midi in circuit (Midi out works fine):
midi troubleshooter capture
The big long ICs are a stand-in for a Teensy 3.2.

Here is the circuit it is supposed to represent:
https://www.pjrc.com/teensy/td_libs_MIDI.html

A-49 is the Teensy 3.2 ground
B-49 is RX1
C-49 is TX1 (working fine)

A-55 is VIN (5 volt)
C-55 is regulated 3.3V out

I can’t think of any earthly reason why this doesn’t work, and I’m reasonably certain my real life circuit matches the layout I posted above. Would anyone with a fresh pair of eyes mind taking a peek to see if I am overlooking something silly?

Somehow this relatively simple step is the last bug to squash on a board with 12 DAC channels and 8 buffered gates - go figure. Thanks all.