Hi everybody,
I started experimenting with MIDI.
I have a Roland electronic drum-kit and a Yamaha Clavinova E-Piano.
So I put together a circuit for interfacing the MIDI-Out of the E-Piano
I have taking this infos as the base to build a circuit
instead of a 6N138 I am using a 4N27 as the optocoupler.
I made a pre-test with feeding a 5V PWM signal into the inputside (the optocoupler-LED through a 220-Ohm resistor and checked the signal on the outputside with a 220 Ohm-resistor
The fototransistor of the 4N27 switches within 4 microseconds between LOW and HIGH
So after that pre-test I connected the optocoupler input to the MIDI-out-signal according to the picture between pin 4 and pin 5.
And then probed the output-signal of the optocoupler with a 5V power-supply
If I play on the E-piano I can see the signal jumping up/down with a period of around 32 microseconds which seems to be the 31250 baud of a MIDI-signal.
The signal has a pretty high DC-part. If I play on the piano I can see that the voltage changes between 5V and 3,9V.
It seems that the phototransistor is not properly switched.
So how can I improve the signal-quality?
Does the 6N138 with the photodiode and the darlington-transistor do the trick?
If I try to probe the signal on the inputside of the optocoupler.
If I try to probe the voltage between cathode of the internal LED and the MIDI-OUT-pin
with my digital storage oscilloscope the signal looks very very noisy
How much current can a MIDI-out deliver?
Is a 220-Ohm-resistor in series to the optocoupler-LED the correct value?
thank you very much in advance for tips and tricks
best regards Stefan
See the Current Transfer Ratio (CTR) of the optocoupler. With a 100% ratio and properly calculated resistor a single transistor is sufficient.
Your circuit is inverting the signal, not really useful. Also the Darlington circuit has a high voltage drop.
Hi @DrDiettrich,
thank you very much for answering.
Aha. Will do some research on how to do this.
If I use the given circuit and add an inverting schmitt-trigger with hysteresis
Then the signal should be double-inverted = non-inverted
best regards Stefan
I have the same question. For what device input was that circuit made? If nothing else you could try increasing the value, especially if you have a scope you can verify the signal with.
Yes I will experiment with that.
Though the MIDI-specs say 220 Ohm. And I have seen a lot of schematics each using a 220-Ohm resistor
IIRC the 4N27 is a legacy device, may not have much gain as pointed out above. Also the other one is a Darlington, that makes a huge difference in gain. Difference in specs and/or difference in type.
The circuit is fine. The resistor values are fine, but
The 4N27 will not cut it. About the only opto coupler that will work with MIDI speed signals is the 6N138.
Hi @Grumpy_Mike,
Yes you are right.
This is the description of the 6N138
6N138 / 6N139 Features
■ Low current – 0.5mA
■ Superior CTR-2000%
■ Superior CMR-10kV/µs
■ CTR guaranteed 0–70°C
■ U.L. recognized (File # E90700)
■ VDE recognized (File # 120915) Ordering option V,
e.g., 6N138V
■ Dual Channel – HCPL2730, HCPL2731
Applications
■ Digital logic ground isolation
■ Telephone ring detector
■ EIA-RS-232C line receiver
■ High common mode noise line receiver
■ µP bus isolation
■ Current loop receiver
I donwloaded the MIDI electrical specifications and they describe the MIDI-interface as
The standard MIDI circuit is a current-loop that drives an opto-isolator located in the receiver returning the current to the transmitter. From the viewpoint of the transmitter, the opto-isolator is electrically identical to an LED in series with a 220Ω resistor.
The opto-isolators found in some MIDI devices have an LED maximum forward voltage drop of 1.9V and can require up to 5mA typical1 current drive for normal operation. The actual required current is opto-isolator dependent. For example, the PC900V has a worst-case forward current requirement of 4mA when RD = 280Ω (see Figure 2) and VRX = 5V.
In order to supply 5mA to this circuit, the transmitter voltage must satisfy the following relationship:
VTX >= VRXDROP = .005*220 + 1.9
This reduces to:
VTX >= VRXDROP = 3.0V
It is required to have short-circuit current-limiting on the MIDI Output as well, which is achieved by series resistors on each of the two output pins. The series resistors are also subject to the IR voltage drop introduced by the 5 mA current, thus increasing the minimum transmitter voltage. The logical choice is +3.3V as a minimum transmitter voltage. The series resistor values should satisfy the following relationship:
(RA + RC) = (VTX – VRXDROP) / .005
Which results in 400 Ohm. With adding another 220 Ohm resistor
which means maximum current will be
(5V - 1.5V) / 620 = 5.6 mA
I will buy 6N138 optocouplers.
Though it is Good Friday and the Easter holidays are coming delivering will be next week wednesday / thursday.
In the meantime I will have fun to examine if I get it to work with the 4N27 in combination with an inverting comparator LM339 with hysteresis.
best regards Stefan
You don't need an inverter, the signal is the right way up already as it comes out of the opto.
I did not analyse the circuit myself (yet)
You are saying
So which circuit do you mean? There might be a difference between the 4N27 circuit and the 6N138-circuit
When testing the 4N27 I saw an inverted signal on the output on my DSO
What are you calling an inverted signal.
A MIDI signal is normally high and drops low when it is sending stuff. The way the transistor is connected to the serial input is that the signal is normally pulled up when no signal is present and pulled down when the MIDI signal light up the LED in the opto coupler.
Is the opposite of being correct.
A MIDI output signal driver.
2014 MIDI V1.1 Specification.pdf (240.2 KB)
I made some tests with the 4N27 optocoupler.
If I increase the resistance on the outputside the voltage drops down to almost 0V for the prize of rounded edges of the signal.
If I adjust to a resistance with which the voltage drops from 5V to approx. 2.5V the rising time is approx. 2 µseconds - which I guess is too much if the baudrate is 31250 which equals a time of 32.5 µseconds.
Enough testing for today.
Thank you all very much for your ideas and input.
best regards Stefan
or 6N136 but they need different wiring. I have both in my box, i have to be really careful to use the proper circuit for the optocoupler i use.
That's bad wording. High here means that no current flows, what normally means a low value.
I guess that this is a relic from TTL logic where an open input is almost high and sources current in low state.
I don't think you understand the evolution of serial communications and how that relates to computers. High here does not mean no current flows, and current where anyway?
In serial communications the proper word for the un-driven state of a line is the "mark" state of the line. The driven state of a line is known as the "space" state.
This is also known as a HIGH state when talking about any sort of digital logic. The fact that a TTL line floats High has no bearing on the issue at all. You would always use a pull up resistor, and that is what is needed with a MIDI signal. So that when the line is not driven it shows as a mark state.
Even in the TTL world you would never design a system that relied on the floating state of a line, because if you did then the time it takes to float high is way longer than it would be if you pulled it up. Therefore you could not get the signal to move fast enough.
The concept of current flowing only applied to teleprinters that were directly connected to each other. In fact most used an 80mA current loop driver that were actually bipolar and could go up to +/- 80 - 120V when open circuit. They would bite you.
When communicating over short wave radio each state was represented by an audio tone, one for mark and the other for space. So there was no concept of current flowing or not flowing, it was just two states of the line.
In fact some people used inverted tones in a small attempt to make communications a little more secure. This is easily circumvented with a change over switch at the receive end.
MIDI transport signals are just an extension of this protocol in the digital computer world.
There is absoloutly no requirement to use an inverter with an opto isolated buffer to the signal if you bias the output device (transistor) to pull high (the voltage signal of the processor). It comes out the right way up.
I have been playing about with teleprinters since before micro processors were a thing.
Hi @Grumpy_Mike,
interesting to know.
I googled for "mark" and "space" in serial communication.
Still it is not really clear to me what the relation between
inputside (the LED of the optocoupler) and the outputside respectively the voltage-level expected by the receiving microcontroller-input
LED lights up ==> phototransistor gets conductant but what voltage-level das the IO-pin of a microcontroller receiving a midi-signal expect ? is it 0,0V or is it 5V (or 3.3V) or whatever
LED goes off ==> phototransistor is non-conductant but what voltage-level das the IO-pin of a microcontroller expect ?
Of course the two voltage-levels have to be opposite. So naming one voltage-level determines automatically the other.
Still
If LED lights up ==> phototransistor gets conductant but what voltage-level das the IO-pin of a microcontroller receiving a MIDI-signal expect ?
If I know this relation:
LED is on - expected voltage-level on receiving IO-pin on the receiver-side.
I can measure it to check if it is correct.
The phototransistor opens up, Grounding out the input pin, so when the switching signal pin is GND and the other signal line is constantly 5v (which it should be), the receiving GPIO is GND.
Hence the pullup resistor on the opto-coupler (i have always just put one, but i have to admit that the internal pullup of the MCU should probably work just as well)
On the transmission side this actually is translated by the 5v being constantly connected, and the switching pin going from HIGH to LOW. So when the output pin is LOW, so will the input pin be on the other end.
Basically the system is 'active LOW' When the output pin is HIGH, there is no voltage difference between the 2 signal lines, therefore the LED in the Opto won't light up, leaving the pullup on the other side to make the GPIO HIGH.
This is actually also the normal polarity for Serial communication, 1 is LOW & 0 is HIGH (startbit is LOW, endbit(s) are HIGH)
The main thing to understand is that of the 2 wires lighting up the LED in the Opto, one is always 5v (not GND) and the other one is switching.
A logic one or high.
A logic zero or low. Just like any other form of asynchronous serial communication.
So you need to check that the MIDI input to the serial connector is one if there is no MIDI messages being sent and it dips down to zero when a MIDI message is being sent. Trigger on the falling edge of the signal into the processor to see this.
Can you give an example of this different wiring?
I am unsure if I undestand this correct.
I will write it in my own words to check if I understand it correct
If no MIDI-message is sent then - on the phototransistorside = the microcontroller-IO-pin the voltage-level has to be 5V = logic HIGH = a binary "1" ?
.
.
.
a MIDI-message is being sent. Well a complete MIDI-message contains multiple bytes with multiple bits that can not be all binary "1" nor they can't all be binary "0"
This means some bit-banging LOW/HIGH is happening.
Does this mean if the very very first bit that will be send as the begin of a MIDI-message-transmission the microcontroller-input-pin must "see" 0V = LOW?
Would you mind drawing a timing diagram that shows both
LED-side and phototransistor-microcontroller-inputpin-side
starting from idling no MIDI-message sent to MIDI-message starts?
best regards Stefan