Midi input circuit accuracy

Status
Not open for further replies.

pgi

Member
Hello,

I've built the midi circuit according to the schematic on the pjrc page : https://www.pjrc.com/teensy/td_libs_MIDI.html (the one designed for teensy 3.x) and connected it to a teensy 4.0.

When I test it with the code provided on the same page, the output circuit works fine but the input circuit provides incoherent MIDI messages when connected to another midi device ( for example, the teensy thinks it receive After touch message when it should receive note on message)

More specifically
- when I connect the teensy midi output to the teensy midi input (some kind of loop), the midi input receives the midi messages correctly. The circuit should be correctly built thus.
- it's only when I connect the input to another device (keyboard, sequencer) that the midi messages are incohérents

What do you think this issue comes from? And how can I fix it?

Thanks!
 
6N138 or 6N139? Did you try the 10k to groud on pin 7 as suggested?

Optocouplers alas have a great variation between devices, being opto electronic (variations in the emitter
and the photo receiver as well as in the optical pathway, I've seen some datasheets with a 10:1 spread given for
current transfer ratio.)

Maybe try changing the pull up resistor somewhat, or another optocoupler?

If you have the circuit standalone you can check the DC levels with the input driven from 5V via 470 ohm resistor, and not
driven. The output voltage on the pull-up should be properly low for the former and high for the latter when given 3.3V.
 
Hello MarkT

Thank you for your reply.

I tried to connect the 10k resistor from pin 7 of the octocoupler to the ground. And it seems to work properly know (I didn't see this remark initially on the pjrc page).

Thank you agin for your reply.

Best
 
Just been looking at this with the CRO so here's some pix.
Upper trace is TX pin. Lower trace is Pin 6 of 6N139 and we're looking at an actual Midi message.

No resistor is attached to pin 7.
DSC_0824.jpg

10k from pin 7 to 0v.
DSC_0825.jpg

1k from pin 7 to 0v.
DSC_0826.jpg

The issue is the slow risetime meeting the darlington. Can have poor supply-borne noise immunity. Had a dodgy opto and the CRO showed a much longer risetime, barely making it to +5v before being pulled low. Bursts of noise were output when the "rising edge" was at around 3.0v although varied with temperature. Adding the 1k cleaned it up but ultimately the opto failed.

I think that if adding this resistor seems to fix a 6N138 opto here then the chances are that it is dodgy in the first place so is probably a good idea to replace it and add the resistor for the sake of good engineering practice.
 
Just been looking at this with the CRO so here's some pix.
Its the classic darlington slowness(*). I built a MIDI in circuit a week back using a phototransistor
optocoupler from an old relay board, an 817C. C is the "gain" (current transfer ratio) band and it
turns out to be x2 to x4 for the C variety fortunately so it just worked - I've only just worked
out why I was lucky (non-binned versions of the 817 have a range from x0.5 to x6 CTR)

(*) If the intermediate connection from a darlington pair is brought out, its no longer a darlington
pair but a cascade of emitter followers (if suitably biased) or an emitter follower driving a common
emitter switching stage, an altogether superior arrangement :)
 
Datasheet of the 6N138 (http://www.farnell.com/datasheets/2046454.pdf) specifies a switching time of 2µs with a pull-up resistor of 2.2k, which should be OK regarding the MIDI baud rate.
Moreover the datasheet of the 6N139 specifies an even better switching time, between 0.6 and 1.5 µs.

What do you think of these alternative designs?:
1. replacing the pull-up resistor of the 6N138 by a 2.2k
2. replacing the 6N138 by a 6N139

Thanks
 
The turn off is always much the slowest edge due to charge storage, and smaller pullup resistor values
always switch faster on this edge as this clears the storage charge faster. This means a low-value pull
up resistor is required, 220 is a good choice, but that then requires the current transfer ratio to be
high to get enough on-current.

The 6N139 and 6N138 has a worst case turn-off of 7us at 12.5mA/270 ohms, though its not clear
what the bias terminal (pin 7) conditions are, probably open circuit.

So I think from the above graphs you should tie pin 7 to ground with about 5k for these devices, for the
extra performance.

I've just measured my 817C response, graph below, about 7.5us:
opto_midi.png

This is possibly borderline, but as its a 4-terminal opto I can't improve this.

I'd sum up by saying the original design chose the darlington devices for high current-transfer ratio to allow
low-value pullup resistors to be used, but forgot the importance of pin 7 for improving speed. Ultimately
this probably was to allow cheaper non-darlington optocouplers to be used instead? Otherwise there would
have been no issue using double the baudrate...
 
Datasheet of the 6N138 (http://www.farnell.com/datasheets/2046454.pdf) specifies a switching time of 2µs with a pull-up resistor of 2.2k, which should be OK regarding the MIDI baud rate.

Well, no it doesn't, it specifies 10µs worst-case, which is the only spec you should look at - 'typical' is marketing puff
from the point of view of engineering reliable circuits, unless you go down the select-on-test route, which is an extra
cost in commercial manufacture (but entirely reasonable for hobby use!). You really don't want a percentage of your
products returned because MIDI doesn't work... The fact 99% of your units work isn't going to count for you, the 1%
that fail will define your brand I'm afraid.

This big difference between typical and worse-case is a reflection of the large variation between devices I think.
 
Status
Not open for further replies.
Back
Top