Midi In and Out - 3.3v ~ Let me know if I did it right

Status
Not open for further replies.
This is from the data sheet... but logic gate based stuff may need 5v...

Does the data pin have to be 5v tolerant to use a 5v coupler? Short of voltage dividing.

If so the tansistor-based couplers at least should be 3.3v supply friendly for a non-tolerant uC. :confused:
Alot depends on the uC's Tx pin drivers. With push-pull, two transistors either pull the pin high or push the pin low. So the pin is going between 0V and Vcc (5 or 3.3V). With open drain, when you output a 1, the pin is allowed to float, so if there is a pull up source somewhere out in the circuit the pin can go to the level of that, 3.3V or 5V.

So with Midi there is a loop between the Tx and Rx devices. The Tx device supplies a current source on one conductor out to the Rx device (LED in the opto coupler) and the other conductor is the return path. To send a Mark or Space, the Tx controller either allows current to flow, by pulling the return to GND; or blocking flow by actively driving a 1 into the return; as long as both the source and pin voltages are the same. If the 1 on the Tx pin = 3.3V and the loop is sourced by 5V, there is still a differential and current will still flow.

One way around this problem is to use open drain on the Tx pin, outputting a 1 = open and 0 = GND. To the current loop, there is no return path so no current flow. This would allow a 5v loop source and a 3.3V uC ( this is how IIC works and it allows more then one Master on the buss).

Even though the T3.2 has 5V tolerant inputs, it can't drive an output above 3.3V Vcc but IF it can (or does) setup the UART Tx pin as open drain then I don't have to have dual voltage to the midi board.

With a 5V tolerant device, an input Vcc above the 3.3V Vcc is clamped. And generally the 3.3V output from the device is enough to qualify as a valid 1 with most TTL gate inputs. So the device can work with 5V logic most of the time.
Yogi
 
Thanks but I'm still confused

There are so many versions of this out there... some powering at 3.3 v...
midi_schematic.png
...even with a 6N137 (which defiantly does say 4.5v min. supply)
midischem_33.png
...or at 5v supply but pulling up to 3.3...
KC9zW.png
While some just assume the Rx pin can take 5v.
 
OK the first schema:
It's a little confusing because of an added Midi Thru function on the Out DIN. This is not the norm. a Thru should be a 3rd DIN socket using pins 2, 4 and 5. Wired this way, you would need a special cable that separated the two midi loops. Atari STs were wired this way, and it was a bad idea back then too.

Starting from the left:
The two inverter gates connected to pin 3 form a buffer of the TTL Midi coming from the Midi In DIN. Pin 1 is the Current source for this loop.

The other two inverters gates and resister connected to pin 5, are buffering the TTL from the header, most times not needed but if the controller has very low output drive levels, the gates would provide higher drive. In this circuit the current source is connected thru a resister on pin 4. The reason for the two resisters on pins 4 and 5, is to limit current if either pin get connect to power or shorted to GND. The total resistance is selected for the loop current but using two Rs adds protection to each pin going to the outside world.

The use of two gates is to have a non-inverting buffer. This kind of shows what I had talked about before, when the gate outputs a 1, the pin is at Vcc, there would be a high on both sides of the LED in the opto at the far end, so no current flows. When the gate outputs a 0, the pin is at GND. Now the current flows from the source, out the cable on pin 4, across the LED, back on the cable pin 5 and to GND. This is Push-Pull active output.

On pin 2 GND is connected, this is just for shielding in the cable as it's never connected to the system GND on the other end. Even though there is a cable connecting two devices they are electrically isolated, this is to avoid GND loops that cause hum in audio.

The Midi In DIN:
DIN Pin 4 is the current source from the distant Midi Out. It flows thru the R and to the anode of the opto's LED. The LED's cathode connects to pin 5, the return path. The diode between DIN 4 and 5 is there for reverse voltage protection.

The other half of the opto is made up of a Light dependent gate and a transistor pair. When light hits the gate, it conducts and applies a bias voltage to the first Trans. This bias turns the junction on and current flows from it's collector to the emitter. This emitter voltage turns on the second Trans causing it's collector, the Rx line pin6, to be pulled to GND.
When these Trans are Off the Rx line is pulled to Vcc by R4.

R3 is there to improve switching by draining off the emitter voltage quickly.

The second Trans is 'open Collector' meaning it's collector is not directly connected to Vcc in the chip. The last schema shows the opto powered by 5V but the OC Rx line is pulled up to 3.3V. This would be needed with a controller that is not 5V tolerant.

The second schema:
This is wrong because there is only a single R for the Midi Out loop. As stated above, this may work but if there is a short on pin 5 it could kill the Tx pin of the controller. Also there is no Rev Polarity diode on the opto, so it's more prone to being destroyed.

Most of these circuits are based on Transistor Transistor Logic, and are current dependent. They may work at a lower voltage than they are rated for but would be switching slower and /or drawing higher current and over stressing the junctions. Meaning a shorter life.
As you've seen there are lots of different designs out there, some good, some bad. Stick with the tried and tested ones, where it's been used by many people. The design on the Teensey Midi page for example has been tested by alot of builders, it's a well tested and safe bet. I use the 6n138 design used by the MIDIbox community because it's well tested also and by sticking to a 'favorite' design it allows me to keep the standard parts on hand.

Anyways, have fun,
Yogi
 
Sorry Yogi.. I only meant I was confused about the supply voltage issue and that there is no clear consensus on how to power Rx for 3.3 volt microcontrollers (especially where the inputs pins are not 5 volt tolerant).

I will study your reply since you took the time (and there are a number of points here I didn't know).

Stick with the tried and tested ones, where it's been used by many people. The design on the Teensey Midi page for example has been tested by alot of builders, it's a well tested and safe bet. I use the 6n138 design used by the MIDIbox community because it's well tested also and by sticking to a 'favorite' design it allows me to keep the standard parts on hand.
I was going to write that Paul's comments on how to adjust the schematic for 3.3 volts were ambiguous on the issue but I just reread them and now I get it... he's clearly allowing for the pull up to be at 3.3 volt and the supply to be at 5 volt.

Until this thread I didn't know some opto-couplers are not spec'd to run at 3.3 volts and most schematics (but not Paul's!) show the supply and pull-up connected to the same supply point. For some reason I thought supplying the IC at 5 volts would not allow you to pull up to a lesser voltage... but I think I get it now.

Thanks for the lesson. :)
 
No need to be sorry, it's my pleasure if I can help at all. I know I can be long winded :) but read too many datasheets over the years....
Yogi
 
Quick question : to make two identical midi Out ports can I just use the same teensy port and split it to the second?
I suppose yes. thanks
 
One inverter can drive two others... This MIDI thru schematic shows how N+1 inverters can drier N MIDI ports.
midithrubox.gif

but attached to the Teensy pin instead of the MIDI in.

But since you would likely add an inverter IC with four or more units you don't need to skimp on their use ... but if you have a three left over somewhere else...

Of course you need lower resister values for 3.3v.

The other standard buffer is an AND gate with it's inputs tied:
Untitled.png
I think you would need two of these but they also come with 4 or 6 per chip.
 
Last edited:
Status
Not open for further replies.
Back
Top