[sdiy] Detecting the presence of a receiving MIDI device through current sensing

Didrik Madheden nitro2k01 at gmail.com
Tue Jan 28 05:07:37 CET 2020


I had an idle thought about reducing power rail interference in audio
circuits by equalizing the currents that any given part of the circuit
draws at any given time. For example, a MIDI transmitter may use up to
5 mA when transmitting. If the circuit was also set to dump 5 mA into
a dummy resistor whenever it was NOT transmitting, that part of the
circuit would always draw exactly 5 mA, and no interference would be
injected into the power lines due to changes in load. Then I realized
that different MIDI implementations might draw slightly different
amounts of current depending on which optocoupler it's using, not to
mention what would happen if no MIDI device was connected, in which
case the circuit itself would inject the exact same amount of analog
noise it was supposed to prevent...

This is an absolutely silly consideration. At least in this context.
In secure digital devices, power analysis is actually a field of
security research, where digital devices have secrets that are never
supposed to leave the chip, but which can be recovered by measuring
fluctuations in current consumption due to different parts of the CPU
causing different amounts of power use. I've also once made a Gameboy
program that plays audio through power line interference by purposely
turning on and off the CPU's power save mode in well timed sequence.

But I digress. Normally, this is where my train of thought would end,
and I would go think about something else. This time, however I
remembered the discussions on this list about MIDI running status woes
where a device may get unconnected and reconnected. So I thought, hmm,
could the idea discussed above actually be useful?

Consider this: 5 pin MIDI is a 1-5 mA current loop that typically goes
through a 1.6 V optocoupler and three 220 ohm resistors. So, by
sensing the voltage after the 220 ohm resistor on the +5 V line, you
could deduce whether a device is present on the other side. If nothing
is connected, you're just seeing +5V through a 220 ohm resistor, which
should be close to rock solid. If it's transmitting, by Ohm's law
there will be at least a V=I*R=0.001*220=0.22 V voltage drop while
transmitting a byte. With a bit of margin, you could detect anything
below 4.9 V as the presence of another device. You could for example
detect this by sampling the voltage with an ADC in a suitable moment.
Or, you could use a comparator with one input set to a 0.98*Vcc
voltage divider.

A good time to check this would be when sending active sense commands,
which are meant for exactly this thing, just not exactly like this.

This approach would have several downsides. It can't detect if a
device has been powered off but is still connected. It can't detect
anything about thru-connected devices. It would probably fail to
produce any useful information on non-powered MIDI splitter devices.

What it *could* do, is to provide a basic heuristic for when a
transmitting device might suitably need to refresh the status byte, as
well as potentially resend CC's. Something that would nominally not
hurt anyway.

It's silly. It's crazy. But has something like this ever been done to
anyone's knowledge?

-- 
/Didrik



More information about the Synth-diy mailing list