Midi interface giving extra messages

balu027

Member
Hello,

I designed a customizable USB MIDI interface/MIDI controller with Teensy 4.0 based on the Teensy example (https://www.pjrc.com/teensy/td_libs_MIDI.html) for the MIDI hardware and this controller https://www.instructables.com/Teensy-MIDI-USB-foot-controller-for-controlling-Mo/ for the controller part. The controller works fine but I have a weird issue with the interface.

I connected the MIDI out and the MIDI in with a cable and sent a series of notes from Reaper while recording the input. It's clearly visible that I get a similar series as the output, but I get a lot of extra notes which I shouldn't get, it's like a noise but with MIDI messages. After the output sequence ends, the "noise" continues for a while. What annoys me is that I'm running out of ideas what could cause this. I checked the waveforms of the output and the input and they are identical, so I doubt it's caused by a transmission issue.

Here's a one channel stripped down version of the hardware:
schematic_1_channel.jpg

It's very similar to the Teensy examples, but I added an extra CD40106 hex-schmitt inverter as done here (https://calcium3000.wordpress.com/projects/teensy-midi-interface/) as buffer and as a 3.3V-5V interface.

The software is basically the interface_3x3 example from the Teensy examples with some serial prints.
View attachment Interface_3x3.ino

When this is the output:
midi output in reaper.jpg

I get this input:
midi input with output.JPG

When the output ends, this input remains:
midi input_just noise.JPG

Waveforms doesn't look suspicious. This is how it looks with the scope directly on the teensy legs (pin 2-3).
scope_in and out_directly on teensy.jpg

With CH1 on R4 and CH2 on the Teensy pin 3 it looks like this. Frequency seems good, voltage levels also.
scope_in_out_time.jpg

What should I check, what could cause this? I'm running out of ideas.
 
Looking at the CD40106's datasheet suggests that at Vdd +5v it is only capable of sinking 1 milliamp, not enough to light up the led in the receiver's optocoupler.
 
CD40106 datasheet from TI also says on page 6 the positive trigger threshold can be as high as 3.6 volts, though it will typically be 2.9 volts at room temperature.

The 1mA output low current on page 7 is also a typical spec at room temperature. The worst case at room temperature is only 0.51mA, and gets even worse at very high (but unlikely) temperatures.

You probably should use a chip like 74HCT14 which has much better specs for this application.
 
Looking at the CD40106's datasheet suggests that at Vdd +5v it is only capable of sinking 1 milliamp, not enough to light up the led in the receiver's optocoupler.

You're right about the current, but it shouldn't be a problem, the 6N138 has a minimal input current of 0.5mA.

I tried bridging the CD40106 but I couldn't get it working.
 
CD40106 datasheet from TI also says on page 6 the positive trigger threshold can be as high as 3.6 volts, though it will typically be 2.9 volts at room temperature.

The 1mA output low current on page 7 is also a typical spec at room temperature. The worst case at room temperature is only 0.51mA, and gets even worse at very high (but unlikely) temperatures.

You probably should use a chip like 74HCT14 which has much better specs for this application.

I'm a bit doubtful since it didn't work with the 40106 removed, but I'll look into it.
 
The 6N138's led may well have min current of .5ma but the Din Midi pathway is a current loop where we usually see 5ma and depending on the whims of manufacturers can be 7.5ma. So much for "standards".

As for the 6N138 itself, usually work more reliably with a 1k0 from pin 7 to V- and this may clean up a misbehaving (noisy) sub-spec device. As a repair tech, have needed to replace a few as well as many other open collector devices, just the nature of the beast. If the 1k0 changes it, replace the 6N138 and add the 1k0 anyway.
 
@balu027 i don't know how you have it routed on the pc/computer but are you inadvertedly setting up a midi loop? ie. Reaper>teensy>Reaper>teensy>Reaper etc. causing the extra notes?

cheers Paul
 
The 6N138's led may well have min current of .5ma but the Din Midi pathway is a current loop where we usually see 5ma and depending on the whims of manufacturers can be 7.5ma. So much for "standards".

As for the 6N138 itself, usually work more reliably with a 1k0 from pin 7 to V- and this may clean up a misbehaving (noisy) sub-spec device. As a repair tech, have needed to replace a few as well as many other open collector devices, just the nature of the beast. If the 1k0 changes it, replace the 6N138 and add the 1k0 anyway.

I did some testing. I changed the 40601 to 74HCT14 as @PaulStoffregen advised, changed the optional resistor at 6N138 pin 7 from 10k to 1k and used a brand new 6N138.

I connected it to the computer, opened MIDI-OX and without pushing any keys, this happened:

midi-ox.jpg

It started playing a constant stream of random notes. This happened before a few times before, I have no clue what casues it. The interesting thing is that when this happens, I have the notes on the input and the output as well. Usually they only appear at the output side.

The arduino code I posted above, gave things like this on the serial output:
Code:
18:42:22.316 -> USBMIDI read from PC: type: 176;  channel: 3;  data1: 0;  data2: 0
18:42:22.316 -> USBMIDI1 forward to device: mtype: 176;  channel: 3;  data1: 0;  data2: 0;  cable: 0
18:42:22.316 -> USBMIDI read from PC: type: 176;  channel: 3;  data1: 0;  data2: 0
18:42:22.316 -> USBMIDI1 forward to device: mtype: 176;  channel: 3;  data1: 0;  data2: 0;  cable: 0
18:42:22.316 -> MIDI 1 input: read type: 176;  channel: 3;  data1: 0;  data2: 0
18:42:22.316 -> MIDI 1 forward to PC: read type: 176;  channel: 3;  data1: 0;  data2: 0
18:42:22.316 -> MIDI 1 input: read type: 176;  channel: 3;  data1: 123;  data2: 123
18:42:22.316 -> MIDI 1 forward to PC: read type: 176;  channel: 3;  data1: 123;  data2: 123
18:42:22.316 -> USBMIDI read from PC: type: 176;  channel: 3;  data1: 0;  data2: 0
18:42:22.316 -> USBMIDI1 forward to device: mtype: 176;  channel: 3;  data1: 0;  data2: 0;  cable: 0
18:42:22.316 -> USBMIDI read from PC: type: 176;  channel: 3;  data1: 123;  data2: 123
18:42:22.316 -> USBMIDI1 forward to device: mtype: 176;  channel: 3;  data1: 123;  data2: 123;  cable: 0
18:42:22.316 -> MIDI 1 input: read type: 176;  channel: 3;  data1: 0;  data2: 123
18:42:22.316 -> MIDI 1 forward to PC: read type: 176;  channel: 3;  data1: 0;  data2: 123
18:42:22.316 -> MIDI 1 input: read type: 176;  channel: 3;  data1: 123;  data2: 0
18:42:22.316 -> MIDI 1 forward to PC: read type: 176;  channel: 3;  data1: 123;  data2: 0
18:42:22.316 -> USBMIDI read from PC: type: 176;  channel: 3;  data1: 0;  data2: 123
18:42:22.316 -> USBMIDI1 forward to device: mtype: 176;  channel: 3;  data1: 0;  data2: 123;  cable: 0
18:42:22.316 -> USBMIDI read from PC: type: 176;  channel: 3;  data1: 123;  data2: 0
18:42:22.316 -> USBMIDI1 forward to device: mtype: 176;  channel: 3;  data1: 123;  data2: 0;  cable: 0
18:42:22.316 -> MIDI 1 input: read type: 176;  channel: 3;  data1: 0;  data2: 0
18:42:22.316 -> MIDI 1 forward to PC: read type: 176;  channel: 3;  data1: 0;  data2: 0
18:42:22.316 -> MIDI 1 input: read type: 176;  channel: 3;  data1: 0;  data2: 123
18:42:22.316 -> MIDI 1 forward to PC: read type: 176;  channel: 3;  data1: 0;  data2: 123
18:42:22.316 -> USBMIDI read from PC: type: 176;  channel: 3;  data1: 0;  data2: 0
18:42:22.316 -> USBMIDI1 forward to device: mtype: 176;  channel: 3;  data1: 0;  data2: 0;  cable: 0
18:42:22.316 -> USBMIDI read from PC: type: 176;  channel: 3;  data1: 0;  data2: 123

This seem to correspond to the MIDI-OX data.

Here's how it looks when it not "bugging in" with the constant random notes.

midi-ox2.jpg

The notes I send on the keyboard are on the output side, but nothing on the input.

I also made some measurements with my oscilloscope. On the R4 I measure 1.88V, which means the output current from the buffer and input of the optocoupler is 8.5mA.




@balu027 i don't know how you have it routed on the pc/computer but are you inadvertedly setting up a midi loop? ie. Reaper>teensy>Reaper>teensy>Reaper etc. causing the extra notes?

cheers Paul

Sorry, I didn't see your reply. I had this thought as well, but I don't think so. I simply made a track which sends to teensy and a separate one that records from it, they should be independent. In my recent comment you can also see that it happens with midi-ox as well, which has a default setting.



By the way, is there a buffer for these messages? Because in the code I get the message from the PC side, forward it, that's for sure, I can see it on the serial. I can see voltage changes the Teensy side of R16 as well. It just doesn't seem to "understand" the message. Can it happen that it fails to read the message for some reason?

This is the serial comm for a single C# note:
Code:
19:47:45.030 -> USBMIDI read from PC: type: 144;  channel: 1;  data1: 49;  data2: 100
19:47:45.030 -> USBMIDI1 forward to device: mtype: 144;  channel: 1;  data1: 49;  data2: 100;  cable: 0
19:47:45.108 -> USBMIDI read from PC: type: 128;  channel: 1;  data1: 49;  data2: 64
19:47:45.108 -> USBMIDI1 forward to device: mtype: 128;  channel: 1;  data1: 49;  data2: 64;  cable: 0

It's sent, but the next read at the beginning of the loop doesn't catch it.
 
Last edited:
Okay. Looking at the EXACT example Interface_3x3.ino running on your hardware.

The Midi library instantiates with THRU turned on by default so anything received on MIDI1, MIDI2 and MIDI3 will be transmitted on MIDI1, MIDI2 and MIDI3 respectively as well as usbMIDI Cables 0 - 2.

MIDI2 and MIDI3's RX pins are floating and likely to be picking up garbage so whatever the library makes of it will be output both via respective TX and Cable. This may be a clue as to where output messages displayed by MidiOx don't seem to appear on any input.

Try enabling pullups on unused RX pins after MIDI2.begin() etc.
 
Okay. Looking at the EXACT example Interface_3x3.ino running on your hardware.

The Midi library instantiates with THRU turned on by default so anything received on MIDI1, MIDI2 and MIDI3 will be transmitted on MIDI1, MIDI2 and MIDI3 respectively as well as usbMIDI Cables 0 - 2.

MIDI2 and MIDI3's RX pins are floating and likely to be picking up garbage so whatever the library makes of it will be output both via respective TX and Cable. This may be a clue as to where output messages displayed by MidiOx don't seem to appear on any input.

Try enabling pullups on unused RX pins after MIDI2.begin() etc.

Good catch! I didn't know about this default thru behaviour. Since at the moment I don't have the other channel installed, I deleted those part and set MIDI1 thru to off. Now with MIDI-OX I still get repeating in and out, but this time only after I send a note. But it looks like i's MIDI-OX's fault, with Reaper it works well. I has a 0.005 second delay, but at least works. Thanks!
 
You're welcome, glad it's making sense now. Am puzzled about MidiOx's apparent behavior, not seen it after four years of extensive midi - bashing using Win 98, ME, XP, 7, 10 and 11.

Have seen odd Midi behavior on older (2017) desktop PC motherboard with Via usb host hardware.
 
Back
Top