MIDI input works but not for all MIDI signals

I made this MIDI to CV box and for years it worked just fine receiving MIDI from my computer's M4UXL USB controlled 4 in / 4 out MIDI box. Then I decided to go back to my roots and use my Atari and the damn thing doesn't work with it, every fourth or fifth MIDI note seems to get through but the rest don't. I'm guessing this is something to do with the way I wired the MIDI input, I used an opto isolator and left the shield ground unconnected at the input as per the MIDI spec.

Any ideas why it would work for one MIDI generating device but not another?

What did you use for a pull-up resistor at the MIDI input? Lots of people use a popular schematic on the 'net that's not robust -- the resistor is too large. Your pullup resistor should be <1k, and something like 220ohms-330ohms is best. It could be the optoisolator is "on the edge" with respect to forward current on the LED side and the M4UXL just puts out more current than the Atari does, which shows up on the isolated side as marginal signals.

Just a theory.

-- The Flexible MIDI Shield: MIDI IN/OUT, stacking headers, your choice of I/O pins

Like this one I drew up yesterday?

Are you saying that the 1.8K resistor should be 330 ohms?

(edit) Fixed image to change 1.8K to 330 ohms.

(edit) Changed on 12th April 2012 to reflect discussion below. Optocoupler changed from TLP521-1 to one with 100% CTR (current transfer ratio) (4N35) and resistor changed from 1.8K to 560 ohms.

Yes. Here are the suggested schematics from the MIDI Manufacturer's Association (which suggests 280 ohms):

http://www.midi.org/techspecs/electrispec.php

I don't know why people keep rolling their own when this circuit has been around since 1985 :)

-- The Ruggeduino: compatible with Arduino UNO, 24V operation, all I/O's fused and protected

Well, I don't know if that was better ...

Here is a single bit, using 330 ohms in the circuit above:


And how it was before, with 1.8K:

It seems to me that the 1.8K gives a better looking bit.

(Cursor B was about a pixel out - it was supposed to be on 0V).

Now the other factors come into play. The MMA does not specify an optoisolator but its CTR (current transfer ratio) can be important. Your TLP521-1 has (in its least expensive rating) a 50% CTR. You may need to find one with a higher CTR. For example, an Avago 4N35-000E has a 100% CTR and will probably do much better.

You can test this theory by (temporarily) lowering the 220ohm resistor on the input side (could be dangerous if what's driving it can't handle the current), or driving the input side yourself with a controlled voltage source to see at what input current level the output starts looking nice again.

-- The QuadRAM shield: add 512 kilobytes of external RAM to your Arduino Mega/Mega2560

Just so I understand this, are you saying that with the 330 ohm resistor, the fact that the bit only goes "halfway down" is because the optcoupler is only driving it 50%?

And therefore, if connecting up a different MIDI device which puts out less current, it might not even go that far, and thus I would not get 0 bits when I expect them?

Correct. Either that or the device driving the input side of the optoisolator cannot supply enough current to sustain ~8mA of current through the LED.


The Aussie Shield: breakout all 28 pins to quick-connect terminals

From what I've been just reading the frequency response suffers on the higher CTR designs.

My local supplier doesn't have Avago 4N35-000E in stock, does this look like a reasonable alternative?

VISHAY - 4N35 - OPTO COUPLER

http://au.element14.com/vishay/4n35/opto-coupler/dp/1328375

Yes, that looks appropriate; it also has a 100% CTR though upon further reflection you might want something even stronger. I miscalculated the typical input current -- with 5V in, 3 220 ohm resistors (two on the MIDI OUT, one on the MIDI IN), and 1.4V LED voltage drop that gives about 5mA. It should be OK, but if you want to be super-safe how about this 200% CTR device:

http://www.digikey.com.au/product-detail/en/PS2501-1-L-A/PS2501-1-L-A-ND/990595

-- The Rugged Circuits Yellowjacket: 802.11 WiFi module with ATmega328P microcontroller, only 1.6" x 1.2", bootloader

Cheers Rugged, Nick. I was using the diagram off this post from way back when http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1187962258/ and you're right 3.3k is way higher than the MIDI spec, I'm soldering a new one in now. Hopefully that's it.

Hmm well I swapped it and just like Nick when I looked on the scope I didn't get a very low bit and it didn't work (with anything). It seems 1.5k is as low as it can go before the Arduino doesn't recognise the bit.

I checked the opto-isolator (it was a Vishay ILQ74 one that I picked up from Maplin purely because it was the only one they had) and it's CTR is 35% so maybe that's part of the problem.

http://www.datasheetcatalog.org/datasheet/vishay/83640.pdf

I'll try and find a better one...

I think for me, until I get better optoisolators, I have to go back to the earlier resistor. I'm going to order some others after Easter. In my particular case, it worked with the MIDI device on the bench, so there is no rush. But it sounds like the better isolator, and proper resistor, would give better and more reliable long-term results.

Yeah I'm going to go back to the 3.3k one till I can get a better one.

One more question though, when I use the Atari for input the bits still seem to go as low on the scope as they do for the other MIDI signals that do work. Does this rule out the current being too low from the Atari? Or could a low current cause some change in the rise and fall of the signal that screws with the UART?

Could it be some variation in baud rates that other gear is more lenient with (unlikely I know) or some extra junk data that the Atari's putting out (also probably unlikely).

If the bits go as low as necessary with the Atari then it's likely not an electrical problem. It could be a timing problem. The MIDI baud rate is 31250 bps, and that's not always exactly achievable using standard crystal frequencies and clock dividers.

Can you use your oscilloscope to measure the exact bit period?

-- The Gadget Shield: accelerometer, RGB LED, IR transmit/receive, speaker, microphone, light sensor, potentiometer, pushbuttons

crx091081gb: Then I decided to go back to my roots and use my Atari and the damn thing doesn't work with it, every fourth or fifth MIDI note seems to get through but the rest don't. I'm guessing this is something to do with the way I wired the MIDI input ...

It would be funny if this was a coding bug, after all the work we put into the electrical side (work not wasted mind you).

Maybe the Atari pumps out data faster, perhaps we should see the code.

The scope is a really old analogue one and it can't seem to trigger off the input making reading bit lengths pretty much impossible, I'm not much of a scope wizard so any tips are welcome on that front. I'm guessing I'd need to make it trigger off a falling voltage then I'd be able to get a stable reading. Hmmm

The code http://registeringdomainnamesismorefunthandoingrealwork.com/blogs/wp-content/uploads/2009/01/midi_dac_v11.pde

Thinking about it I should check if the Atari is sending any extra gumph (running status etc) down the line byte wise that my code isn't handling....

That's what I was getting at. My gadget sends a "timing" byte quite often. Maybe you aren't allowing for it, or it overflows your buffer or something.

I've checked and there are no status bytes or other gumph coming through. I've also stripped any redundant code in an effort to make sure that it doesn't complete it's main loop fast enough to pick up bytes. No joy.

Is it concievable that the baud rates on the Atari/Arduino are sufficiently different that it could be a bit length/timing issue?