vsmGuy

Making a USB to MIDI Interface

40 posts in this topic

Hi Eduardo, thanks for explaining.

I am sorry that my English is very bad. :(

Hey, no problem. I have a lot of respect for multilinguialism. Actually, I used to teach English as a foreign language, and have some appreciation for what's involved. I'm (slowly) trying to learn Mandarin Chinese, and I am really terrible with that.

Cheers.

Share this post


Link to post
Share on other sites

oh madox, do i feel sorry for you mate.... i got quite a way with japanese and even that was childs play compared to chinese, when one of my friends said there was over 30 ways to pronounce the word "ma" in chinese i freaked!! when i did some and you ask how are you "li ho ma?" he pissed himself and told me it was wrong, i cant remember what it was i said but it wasnt right at all. rasing the tone and the length of the letters tone etc all mad stuff. and then to top it off you have mandarin and cantonese, also in other areas of china some pople speak a really older vision of chinese which is even harder.

my.. i really  feel for you!

Share this post


Link to post
Share on other sites

oh madox, do i feel sorry for you mate.... i got quite a way with japanese and even that was childs play compared to chinese, when one of my friends said there was over 30 ways to pronounce the word "ma" in chinese i freaked!! when i did some and you ask how are you "li ho ma?" he pissed himself and told me it was wrong, i cant remember what it was i said but it wasnt right at all. rasing the tone and the length of the letters tone etc all mad stuff. and then to top it off you have mandarin and cantonese, also in other areas of china some pople speak a really older vision of chinese which is even harder.

my.. i really  feel for you!

I used to speak a little Japanese. Learned some in high school. I rather like Jap language, and enjoy some of the cinema. I like their synths and toys too. However, my wife is Chinese. There are over 50 'dialects' in China. Really some of these are very separate languages, rather than dialects, methinks. I think the country is basically an empire of feudal states. Mandarin is the imposed common toungue, and that is what I learn (mostly). I know a few choice words of Cantonese though (learned that in high school too).

In some ways Mandarin makes more sense than English. I think English has an overly complicated grammatical system. Mandarin is simple in that regard. Of course, the more complicated tenses of English can be used to express temporal relationships more efficiently than in Mandarin.

The Chinese tones are tricky for me, though, particularly when superimposed with inflections for questions, etc. Mandarin is actually phonetically simple though, in that it uses quite a small set of basic sounds, compared to other languages. Those sounds are multiplied by the number of tones, to make the phonetic symbol set. Each phonetic symbol can have multiple meanings. A lot is inferred by context, and even native speakers of Mandarin will occasionally have to explain which meaning is being referred to.

Oh well, I digress...

Share this post


Link to post
Share on other sites

I have been doing a little bit of poking around with docs and have an idea in my head - MIDI is simply usual Serial transmission BUT at a Baud rate of 31250.

What if:

1. I located a MIDI driver/program that can read from a computer's serial port at say 38kbps - you guys know of some serial drivers? (Will CakeWalk/etc be able to do this?)

2. I made a AVR/PIC/8051 based convertor that reads from my synth at a Baud rate of 31250 and sends that data to my computer's serial port?

Would this not be exactly what I want?

Did anyone try something like this before?

Oh - and regarding the PIC EUSART silicon error - it seems it's fixed now.!

Share this post


Link to post
Share on other sites

Hi,

An RS232 MIDI interface is a little different from a USB interface. Many people prefer USB these days, as the old com ports are becoming less common, particularly on laptops. I think current Windows versions don't have such good timing performance for com port transfers though, due to the OS arbitrating the port. I haven't looked into this in detail though. I think for my com port chip programmer, I had to install a hack to allow direct read/write access to the hardware.

You can have a look at this Max MIDI interface design. It uses an older Atmel or 8051 based micro. I think this uses a custom driver, which is not compatible with current Windows versions though.

I'm sure you could do a very similar serial rate conversion based on the MIDIBox platform. PIC would certainly be fine for this. You would probably be using one hardware UART, and one software UART, similar to the MIDIMerger, or MIDIFilter (from memory). I'm guessing you would not have to wrap the data with additional framing, but can only guess here. I think the driver would be capable of reading the MIDI stream in its raw form. From memory, I think I actually tried to do this many years ago, but never tested my design.

Decent quality used commercial com port MIDI interfaces are dirt cheap now. I'm not sure about driver support though.

I think there have been a few DIY com port interfaces which use the Yamaha CBX driver. I think this is just a really basic serial pass through driver, with some hooks for applications to access the streams. Again, not sure about operation in current Windows versions.

Let us know how you go.

Share this post


Link to post
Share on other sites

Hi,

Just had a second glance over the maxmidi page. His interface/driver use handshaking for flow control. I seem to recall that the MBMerger uses buffers the streams in internal RAM, rather than halting I/O. It may be worth finding out how some other drivers work, or perhaps writing your own.

Share this post


Link to post
Share on other sites

CBX also supports multiple MIDI OUTs, though I think you can limit yourself to just one.

Share this post


Link to post
Share on other sites

I am happy now with the kind of discussions we are having :-)

MIDI ports are unidirectional .. am I right?

I am a little confised about "current loop" though.

MIDI seems to use an "active high" signal of 5mA. The question is - 5ma at WHAT voltage?

I am asking coz I want to add a current limiting resistor.

Similarly, when I do the MIDI out, what voltage do I send out the 5mA signal at (will I be able to use a resistor to limit the current drawn or do I need to make a complicated opamp based curren limiter circuit?)

I do not mind using two uC for RS232 communication - one for MIDI in and another for MIDI out.

There will be a third uC to send these data to a computer serial port.

Once I have this setup working, I will implement software UART in the uC to replace the 3rd uC.

What do you guys think?

I was suggesting USB not only because current systems dont have RS232 but also because there seems too be a ready-to-go USB-MIDI driver on all latest OS (whether that works with the approach I am telling is to be seen)

I think right now I need some tried and tested serial MIDI drivers - any suggestions?

Share this post


Link to post
Share on other sites

Hi,

I suggest you have a look at the MIDI merger design on the uCapps page. Actually, almost any MIDI interface uses very similar hardware, which is very simple.

MIDI output ports are transistors which sink current to indicate an on bit. The current source is a +5VDC rail, with a current limiting resistor (pull up resistor).

MIDI input ports are optoisolators, with protection diode, and another current limit resistor. The optoisolator (also opto couplers, or photo transistors, etc) can be thought of as an LED input, driving an optical receiver. When the MIDI output port switches on, it sinks current through the LED (via the MIDI cable), which is sourced from the +5VDC pullup of the output port. The isolator provides circuit protection for the input.

You can see all this on the schematic of the MIDI merger.

If look up DIY MIDI interfaces, you will find all this information.

Current sink (open collector, or open drain) outputs are very common in digital electronics. Another common type is CMOS. I believe the PIC actually has a CMOS output driver, but it is the current sink which is relevant here.

I'm pretty sure the PIC UART can handle full duplex MIDI I/O. One hardware UART can handle the MIDI in port, and the MIDI out port, simultaneously. A software UART (I/O pins and RAM buffers programmed to perform as a UART) can also handle full duplex serial I/O (with the computer, for example). A PIC can run at much higher clock rate than the serial Baud demands, so there is no real problem to keep up (the processor will be just looping, waiting for things to happen, most of the time).

I suggest you look at the merger design, as you should be able to change the PIC code to perform Baud conversion. I think you will also have to implement an additional UART output. There are other designs within the MIDIBox project domain which have multiple bidirectional serial coms, which may have more of the features you want, though are likely to be more complex programatically. I haven't had much to do with any of this, so I can't help you further. However, I have found the code here to be well structured, and readible.

I hope you don't mind me suggesting that you first buy a cheapo interface, to use for your music, and to accompany your synth, while you figure out the electronics and and coding? I expect you will end up spending a fair bit of time and money (for tools, etc) before you are able to make music with an interface of your own design. Sorry if this seems unwelcome advice, but you are re-inventing the wheel, as a learning exercise (all well and good, of course), which is a goal that needn't conflict with you putting together a working studio settup.

Share this post


Link to post
Share on other sites

madox, please stop sounding so apologetic  :-[

As I told you before, I am not "in" coz I want to play music on my synth patched to my lappy.

I am in this because I wanna build my own cable and then let GOD take it where it goes.

Back in 1999 a synth used to sound much sweeter than the MIDI files in a computer. Nowadays, the computer sounds sweeter.

Thanks for the references and the detailed writeup.

Would you be interested in contributing if I opened up the schematics?

It will not be available to everyone of course - ONLY to those who contribute ;-)

I do require you to have Proteus/Qux however...

Share this post


Link to post
Share on other sites

I am a little confised about "current loop" though.

MIDI seems to use an "active high" signal of 5mA. The question is - 5ma at WHAT voltage?

I am asking coz I want to add a current limiting resistor.

The answer is - enough voltage to get 5mA flowing at the given resistance. ;)  Have a look at http://www.midi.org/techspecs/electrispec.php for the MIDI electrical specification.  MIDI in has an optocoupler (typical voltage drop of 1.3V for a 6N138) and a 220? resistor.  So your MIDI out needs 2.4V to supply 5mA.  If your supply is higher, add more resistance to drop the voltage.  Eg an extra 120? if you're using a 3.3V part with a 3V minimum output high voltage or 380? if you've got a 5V part with a 4.3V minimum output high voltage.  In the MIDI spec example (and the MIDIbox), they've been cautious and used 2 220? resistors (also 380?  isn't a standard resistor value).  My MIDISPORT 2x2 has a single 470? registor has its output.

Speaking of which, the MIDISPORT 2x2 is a nice device to base a MIDI interface off.  It uses the Cypress AN2131SC (same as the MBHP USB), an 8051 based microcontroller with hardware USB support.  It downloads its firmware from the host computer so development cycles are fast.  The stock firmware isn't class-compliant and doesn't work with Vista 64-bit.  When i get some time i'll write new firmware for it, using the open source firmware for Linux (http://www.linux-usb.org/ezusb/) as a base.

Share this post


Link to post
Share on other sites

This so so cool. Thanks you guys  :D

I want to put up some stuff now ..

Should I upload schematics and software here?

I use KiCAD - is that OK?

Do you guys have some kind of VSM simulation software with you? (Proteus et al)

Share this post


Link to post
Share on other sites

Would you be interested in contributing if I opened up the schematics?

It will not be available to everyone of course - ONLY to those who contribute ;-)

the one thing you will find about being a member here or about this site in general is that nothing is not shared, all of the projects designed by either thorsten, nils, wilba or anyone here is always made freely available all the way down to the pcb drawings to have your own sets made. the main crux of this site is to share what you learn, its a way of giving back to the community and those who spent time helping others. since i have been here i have had help and i now offer help in return where i can.

just because someone doesnt contribute , it doesnt make them any less likely to learn from the project. not every member here is as technically minded as some, so things like this on the forum will only help educate them further, as have we helped you in this thread since you started it, we have not placed any conditions on sharing this information of which it is all available on ucapps and throughout this forums many thousands of threads.

just my 2 cents ;)

Share this post


Link to post
Share on other sites

Aww come on .. I was just pulling you guys leg.. otherwise why I keep on asking:

Should I upload schematics and software here?

I use KiCAD - is that OK?

Do you guys have some kind of VSM simulation software with you? (Proteus et al)

It's ME who needs all the help!

Share this post


Link to post
Share on other sites

I've not used Proteus. Is it good?

I have enough difficulty getting valid results from PSPICE as it is. I usually run into problems with limitations of the models. I think if you are simulating a well specified IC process, it may be fine, but trying to work with unknown models of a wide range of discrete parts is problematic as system complexity increases.

The only simulator I've used for micro code is MPSIM. I think test driven design is also popular.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now