Arduino based MIDI->CV

From circuitbending to homebrew stompboxes & synths, keep the DIY spirit alive!

Moderators: Kent, luketeaford, Joe.

User avatar
BTG
Super Deluxe Wiggler
Posts: 1178
Joined: Thu Jan 10, 2013 4:32 pm
Location: USA

Arduino based MIDI->CV

Post by BTG » Mon Jan 28, 2013 10:01 pm

I originally thought that doing an Arduino based MIDI->CV would be relatively easy, but as it turns out there are a lot of details that are making it less than straightforward.

1. The Arduino has PWM outputs, which is not what you want driving a modular's CV inputs. You want something much smoother, and even a simple LPF over it doesn't seem to be enough (from what I've read).

2. AnalogWrite() is limited to 8-bit resolution, which can result in noticeable stepping.

3. 12-bit DACs are holy-shit-OMG-expensive ($35+ in Q1). But they seem to solve the problem of resolution adequately.

4. Everything is oriented around a 0-5V scale, but for pitch you want 0-10V ideally...is this as simple as just a short amplifier stage after the DAC?

Any other suggestions/ideas? I'm currently prototyping with a Mega 2560 and SparkFun MIDI shield (waiting for both of these to arrive actually, so I can think about the rest of this stuff while I wait). My original thought would be to map MIDI CC values to straight up CV outputs and/or gate triggers.

Gates/triggers seem to be a non-issue since I believe most things will trigger at 5V, but if not then I'll need to apply gain to those signals as well, but at least it's a simple digitalWrite() call.
Last edited by BTG on Tue Jan 29, 2013 10:45 am, edited 1 time in total.

User avatar
Boogdish
Common Wiggler
Posts: 219
Joined: Sun Aug 19, 2012 4:31 pm
Location: Bloomington, IN

Post by Boogdish » Mon Jan 28, 2013 10:19 pm

http://www.mouser.com/ProductDetail/Mic ... m2oQGScGfw

That's a 12-bit DAC I've used in a couple designs that's not too expensive. As for whether low-passing a PWM is "good enough" that's for the individual to determine. I've done a couple of projects based on that where I was really happy with the results.

I'm not an Arduino guy, so sorry this isn't more specific.
I have DIY stuff and pre-made eurorack modules of my designs at: www.bartonmusicalcircuits.com

Ailurophilia
Learning to Wiggle
Posts: 50
Joined: Thu May 31, 2012 5:42 am
Location: Sydney, Australia

Post by Ailurophilia » Mon Jan 28, 2013 10:25 pm

3. 12-bit DAC's don't need to be expensive. The MCP4921 is available in DIP at small quantities for less than $3 a pop, and there are even cheaper varieties in surface mount packages. The MCP4921 is well supported by the arduino community, check out this for an example.

4. A simple op-amp amplifier stage is all that is required. All you need is 2x gain and your 5vpp signal becomes 10vpp.

I would make sure that your triggers are buffered (simple transistor), current limited (~1k resistor) and protected with a diode, to make sure a patch cable doesn't short 5v to ground (and take your arduino with it) or that 15v isnt applied to a UC pin.

User avatar
BTG
Super Deluxe Wiggler
Posts: 1178
Joined: Thu Jan 10, 2013 4:32 pm
Location: USA

Post by BTG » Mon Jan 28, 2013 10:57 pm

Thanks everyone, I'm going to try the MCP4921 and order a couple from Mouser to play with, thanks!

Ailurophilia: alright, sounds reasonable, i'll look into those suggestions. Are there any off the shelf circuit designs I can look at (I assume that this is a pretty standard bit of circuit)? I'm not much of a hardware guy and I'd rather now blow anything up...

User avatar
BTG
Super Deluxe Wiggler
Posts: 1178
Joined: Thu Jan 10, 2013 4:32 pm
Location: USA

Post by BTG » Mon Jan 28, 2013 11:11 pm


Ailurophilia
Learning to Wiggle
Posts: 50
Joined: Thu May 31, 2012 5:42 am
Location: Sydney, Australia

Post by Ailurophilia » Mon Jan 28, 2013 11:41 pm

Sure thing, here's a simple schematic for the Arduino output protection
Image

The 1k resistor ensures no more than 20mA of current (the safe limit) will flow out of the pin when it is shorted to ground (possible) or -15v (not very likely). The diode is just ensuring that big nasty voltages can't enter the pin if accidently patched into an output. A 1N4148 diode should be able to handle this job quite well.

Here's a schematic for the amplification. I'm just using a simple non-inverting amplifier. The gain of the circuit is given by 1 + (R1/R2).

Image

A 1k resistor is on the output for the same reason as above, to limit the current in a short situation. This may be omitted as some op-amps are happy to work in a short, but it's better to ensure nothing can go wrong.

Provided your circuit has a bi-polar power supply (+/-) then a TL072 would be a good op-amp to choose. Otherwise, you'll have to source a single-rail op-amp, such as the LM358.

User avatar
BTG
Super Deluxe Wiggler
Posts: 1178
Joined: Thu Jan 10, 2013 4:32 pm
Location: USA

Post by BTG » Tue Jan 29, 2013 12:11 am

Whoa, many thanks! If I wanted to combine the two to get gain + protection would I just combine the two circuits by put Arduino Pin where Voltage In is with the 2nd schematic, and the diode at the very end of (right before VOut) on the 2nd diagram?

It looks like there's a stereo MCP4921 (the MCP4922). With SPI that seems like I could drive 4 CV OUTs using only two digital pins, which would be a nice conservation of IO pins. This would potentially make this all work on a smaller Arduino than the Mega2560 (which is what I'll be prototyping with) such as the Uno. I'm not sure if 16MHz will cut it (only one way to find out...) but I'm also loathe to switch to the Due since its 3.3V reference isn't well supported yet.

Ailurophilia
Learning to Wiggle
Posts: 50
Joined: Thu May 31, 2012 5:42 am
Location: Sydney, Australia

Post by Ailurophilia » Tue Jan 29, 2013 12:45 am

Ah, I should have been more clear. The first circuit is all you need (unless you really try hard) to protect the Arduino's digital outputs (your gate signals). The second circuit I intended to be used with your DAC's output (MCP4921/4922) to provide the gain to change the range from 0..5v to 0..10v. However, if you wish to create a stronger gate signal, you definitely could use the other op-amp in the package to boost the gate signal. Most people would just use a transistor switch, but if you have a spare amp, why not?

You'd be surprised how much you can do with a 16mHz micro. The biggest bottleneck you'll have is the midi data rate. (31.25k baud) Even saturating the midi bus (~2000 note on/offs per second) gives you half a millisecond to respond, which is plenty to set an output (a few microseconds) and send a message over SPI.

If you plan to have multiple DAC's on the SPI bus, you'll have to hookup the CS (chip select) pins to the arduino. These pins (Active low) determine which chip will receive the messages you send. This mean's you'll require two pins for SPI, and two pins to control which chip is receiving.

User avatar
elmegil
Super Deluxe Wiggler
Posts: 3066
Joined: Sun Apr 29, 2012 2:57 pm
Location: Chicago

Post by elmegil » Tue Jan 29, 2013 12:45 am

I've actually used the MCP4922 (two outputs instead of just one) to make a couple of arduino->CV boards, though I have not yet done one with the necessary amplification to get 0-10 as well.

What I have done for power, BTW is to put a +15 / -15/ +5V header on the shield and feed the 5V line to the arduino. I can't have it plugged into USB and the power supply at the same time, of course....

Edit: I've done the short frying an arduino pin trick too :(. Definitely need the protection circuitry....

Edit 2 (I read and re-read and re-re-read and find things I miss....)

You'll need 4 digital pins to drive two MCP4922's as each of them has a chip select. And the data read into them is clocked by the chip select so you can't just toggle it and use a single pin and an inverter for two chips.

The good news is that with some decoding circuitry those 4 pins could drive one more MCP4922 (or two if you dont' have *anything* else using the SPI bus, since one of them will be CS active at all times)

User avatar
elmegil
Super Deluxe Wiggler
Posts: 3066
Joined: Sun Apr 29, 2012 2:57 pm
Location: Chicago

Post by elmegil » Tue Jan 29, 2013 1:04 am

While we're at this one other thing that had occurred to me was that supply voltages CAN be variable. For example, my bench supply 5V is actually 4.95 and I believe my rack supply is a solid 5V.

This will cause you calibration troubles with your DACs, since they are usually referenced to their supply voltage (and you can't reference them HIGHER than your supply voltage, so some kind of 5V reference when the supply is 4.95 would be baaad.

I was looking into this and found the following discussion.... I haven't had a chance to try this out myself, but it's high on my list. Biggest problem is that if you were to want to do some kind of production run (as opposed to a one off for yourself) you'd have to figure out how to set the bandgap voltage for each individual arduino board. Nominally it's 1.1V and I've seen some examples that just assume that, but if you want real precision (say you want to drive V/Oct with it, such as MIDI note outputs....) you'll need to calibrate it for each board.

http://jeelabs.org/2012/05/04/measuring ... e-bandgap/
http://arduino.cc/forum/index.php/topic,38119.0.html

Ailurophilia
Learning to Wiggle
Posts: 50
Joined: Thu May 31, 2012 5:42 am
Location: Sydney, Australia

Post by Ailurophilia » Tue Jan 29, 2013 1:29 am

elmegil wrote:While we're at this one other thing that had occurred to me was that supply voltages CAN be variable. For example, my bench supply 5V is actually 4.95 and I believe my rack supply is a solid 5V.
This could be remedied by a local regulator in the module itself taking the positive supply down to 5v. Using an adjustable regulator (i.e. LM117,LM317) instead of a fixed (7805) will allow you to trim the voltage down to be perfectly precise. This regulator should feed both the arduino (straight into the 5v pin) and the DAC supply and reference. If even more precision is required, references can be purchased just for this kind of task.

User avatar
elmegil
Super Deluxe Wiggler
Posts: 3066
Joined: Sun Apr 29, 2012 2:57 pm
Location: Chicago

Post by elmegil » Tue Jan 29, 2013 8:49 am

I'm always leery of regulating down to 5V from 15, that's a lot of heat to dump. And you can't regulate a 5V supply to 5V.

Presumably, if you were going to use my method of power from a standard module connector, you could regulate the 5V down to 3.3 and use a gain of 3 instead of 2 though....

User avatar
BTG
Super Deluxe Wiggler
Posts: 1178
Joined: Thu Jan 10, 2013 4:32 pm
Location: USA

Post by BTG » Tue Jan 29, 2013 9:15 am

Ailurophilia wrote:Ah, I should have been more clear. The first circuit is all you need (unless you really try hard) to protect the Arduino's digital outputs (your gate signals). The second circuit I intended to be used with your DAC's output (MCP4921/4922) to provide the gain to change the range from 0..5v to 0..10v. However, if you wish to create a stronger gate signal, you definitely could use the other op-amp in the package to boost the gate signal.
Actually I was thinking of adding the additional protection (diode, etc.) you mentioned to the DAC output, since I assumed that any of the issues that could hit the digital IO could also hit the DAC (I don't know what kind of internal protection it or the amp would provide).

At this point I'll be happy to have any type of waveform output without blowing up my Arduino.

smrl
Wiggling with Experience
Posts: 429
Joined: Tue Feb 01, 2011 10:09 pm
Location: Milwaukee WI

Post by smrl » Tue Jan 29, 2013 2:15 pm

You could go with a cheap 8 bit dac like this
http://www.ti.com/product/tlc7226

I recently built a OSC to CV bridge for Raspberry pi using two of these - the trick is to run it off of a 15v supply with a 10.666v reference, then your 8-bit DAC is calibrated such that your LSB corresponds precisely to a quarter tone... You still will get stepping of course but your pitches will be correct and it should make coding much easier...

User avatar
J3RK
Super Deluxe Wiggler
Posts: 7083
Joined: Tue Dec 22, 2009 12:46 pm
Location: Seattle

Post by J3RK » Tue Jan 29, 2013 2:22 pm

I've picked up some decent 12-bit DACs from Maxim for not too bad a price. They're at Mouser, and have multiple supported interfaces. They're in multiple package types. I got DIP-16s if I remember correctly. They weren't too bad at all. I'll see if I can dig up the part.

Edit:

Something along these lines. Some get a bit pricey, but others not so bad. Many have several interface types to choose from.

http://www.mouser.com/Maxim-Integrated/ ... qoZ1yzoups

User avatar
BTG
Super Deluxe Wiggler
Posts: 1178
Joined: Thu Jan 10, 2013 4:32 pm
Location: USA

Post by BTG » Tue Jan 29, 2013 3:22 pm

Yeah, those Maxims are the ones I was originally looking at and were $35 in qty:1 for their 4-channel model. I'm going to try the MCP4921 first since it's so cheap and see how that goes.

I'm mostly just waiting for everything to show up at this point. :whistle:

User avatar
oootini
Super Deluxe Wiggler
Posts: 1115
Joined: Tue Mar 23, 2010 6:02 am
Location: Cork, Ireland

Post by oootini » Tue Jan 29, 2013 3:29 pm

really interested in attempting a project like this myself. i have a dream of an arduino box that i plug a monme into at one end and have it talking to the arduino and spitting out cv at the other end... :bacon:

not sure if it's even feasible though, it might be with an arduino due. the tricky part would be writing a serial decoder for the monome and having enough space left to create some kind of monome-esqe program to fire notes/sequences..

User avatar
oootini
Super Deluxe Wiggler
Posts: 1115
Joined: Tue Mar 23, 2010 6:02 am
Location: Cork, Ireland

Post by oootini » Tue Jan 29, 2013 3:29 pm

edit: double post

User avatar
BTG
Super Deluxe Wiggler
Posts: 1178
Joined: Thu Jan 10, 2013 4:32 pm
Location: USA

Post by BTG » Tue Jan 29, 2013 3:38 pm

That's effectively what I'm looking to do, but with a Livid Elements controller. The Livid stuff is pretty amazing, the only real downside is that it only sends 7-bit MIDI CC (argh!) so I'll have to interpolate (which creates some latency/portamento effects) to avoid zippering.

Another option would be to skip MIDI altogether and go over USB so you could hook up a USB oriented controller (like a Novation Launchpad) but that opens up a whole new can of worms since Arduino-as-USB-host seems to be a little hit or miss right now.

Ailurophilia
Learning to Wiggle
Posts: 50
Joined: Thu May 31, 2012 5:42 am
Location: Sydney, Australia

Post by Ailurophilia » Tue Jan 29, 2013 3:50 pm

BTG wrote:
Ailurophilia wrote:Ah, I should have been more clear. The first circuit is all you need (unless you really try hard) to protect the Arduino's digital outputs (your gate signals). The second circuit I intended to be used with your DAC's output (MCP4921/4922) to provide the gain to change the range from 0..5v to 0..10v. However, if you wish to create a stronger gate signal, you definitely could use the other op-amp in the package to boost the gate signal.
Actually I was thinking of adding the additional protection (diode, etc.) you mentioned to the DAC output, since I assumed that any of the issues that could hit the digital IO could also hit the DAC (I don't know what kind of internal protection it or the amp would provide).

At this point I'll be happy to have any type of waveform output without blowing up my Arduino.

Ah, I see. The diode, unfortunately, will drop 0.7v (or half that if schottky), which means you'll lose some range. This is also temperature dependant so it'll be very hard to fix in software. The 1k resistor should be more than adequate and is the solution used in the vast majority of modules (although at the expense of 'voltage-sag'). The op-amp will isolate the DAC from the outside world, too.

User avatar
oootini
Super Deluxe Wiggler
Posts: 1115
Joined: Tue Mar 23, 2010 6:02 am
Location: Cork, Ireland

Post by oootini » Tue Jan 29, 2013 4:28 pm

BTG wrote:That's effectively what I'm looking to do, but with a Livid Elements controller. The Livid stuff is pretty amazing, the only real downside is that it only sends 7-bit MIDI CC (argh!) so I'll have to interpolate (which creates some latency/portamento effects) to avoid zippering.

Another option would be to skip MIDI altogether and go over USB so you could hook up a USB oriented controller (like a Novation Launchpad) but that opens up a whole new can of worms since Arduino-as-USB-host seems to be a little hit or miss right now.
yeah ideally i'd skip midi altogether. just have the arduino sending and receiving serial data to the monome and cv out the other. as you say though, not sure if it's feasible.

http://arduino.cc/en/Reference/USBHost

User avatar
BTG
Super Deluxe Wiggler
Posts: 1178
Joined: Thu Jan 10, 2013 4:32 pm
Location: USA

Post by BTG » Tue Jan 29, 2013 4:38 pm

It looks like it's _potentially_ feasible depending on the Monome. I just watched the video of the guy hooking up his LPK25 and Guitar Hero guitar to his MIDI keyboard, so it's clearly feasible with those. That might be worth a shot and opens compatibility with a wealth of small and inexpensive USB devices.

User avatar
BTG
Super Deluxe Wiggler
Posts: 1178
Joined: Thu Jan 10, 2013 4:32 pm
Location: USA

Post by BTG » Mon Feb 04, 2013 4:32 pm

Ailurophilia, can you describe the main difference between your gain circuit and this one I found at Rugged Circuits?
Image
[/img]

User avatar
elmegil
Super Deluxe Wiggler
Posts: 3066
Joined: Sun Apr 29, 2012 2:57 pm
Location: Chicago

Post by elmegil » Mon Feb 04, 2013 5:30 pm

Ailurophilia can answer directly, but the way I read that is it's taking the Arduino PWM "analog" output, filtering it with the 10k resistor and 1uF cap to smooth it, and buffering the result with an op amp. I'm not sure about the reasons for using 10k's instead of 100k's but with a 1:1 ratio, it's still a gain of 2. It also assumes a 5V supply rather than a 3.3V supply, but that would be what I'd assume it would be anyway.

User avatar
BTG
Super Deluxe Wiggler
Posts: 1178
Joined: Thu Jan 10, 2013 4:32 pm
Location: USA

Post by BTG » Mon Feb 04, 2013 6:02 pm

Both are assuming availability of +/- 12V rails (are these missing from Ailurophilia's because they're implied?), but the Arduino doesn't have those, so it sounds like I'm going to need a separate power adapter?

Sorry for the noobness... :hide:

Post Reply

Return to “Music Tech DIY”