
                  'Paramid' parallel-port MIDI interface


                          Preliminary information


                           Dick Dixon July 1992


Introduction

      A lot more people have asked for information on my little interface than
I had expected.  I don't know if all of you intend to build it, but a few
words of advice before starting:

      First, if you are not already an electronics hacker, don't try to build
one of these as your first project.  I have only made one, and I haven't tried
to make the design foolproof.  There is a chance that an interface built to
this design will refuse to work as a result of adverse component tolerances
etc., and you will need to be able to work out the what and why of fixing it. 
There is also a chance that the circuit diagram contains the odd typo:  I have
been quite careful, but I am not infallible... THIS IS NOT A KIT, or even a
magazine article: I am prepared to help by e-mail if people get problems, but
you will need to be familiar with the techniques needed.

      Second, I have included no information on power supplies or power
connections to the chips.  You are expected to be able to rig up a 5 volt
regulator and smoothing capacitors, and run supplies to the correct pins on
all the chips, without any indication of this in the circuit diagram.  I would
recommend that, if you intend to use it with a portable, you make arrangements
to tap the portable's power supply to feed the interface - the additional
current drain won't make any impact.  I thought the best way to feed it was
to put a couple of paralleled sockets on the interface, of the same kind as
the PC uses, and make up a patch lead with a plug of the same type on each
end.  Then the portable's supply plugs into the interface, the patch lead
joins the interface to the PC, and everything works.  I used the power supply
on my synth (a Kawai K4), which was a mistake:  since the parallel port is
ground-referenced, the interface and the PC share a common ground; using the
synth power supply means that the synth is now ground-referenced as well, and
earth loops (and lots of hum) follow soon after...

      Third, there is no information on the mechanical construction.  I built
mine on two pieces of stripboard with lots of interconnect wires, and it
folded up into a box about 6 x 6 x 10 cm.  (It is quite difficult to get one-
off electronics very compact).  I always find the mechanical construction the
most difficult part, even having the tools to do a reasonable job: there never
seems to be enough room to fit all the parts in, even though they made such
a small heap on the table top.  I started with this thing assembled on a
prototyping board, by the way, and got it going there: it is quite within the
scope of the kind of plugboard that has a section for 0.3" and another for
0.6" ics.

      Fourth, make sure you have the right test equipment.  An absolute
minimum, if you are determined, is a decent multi-meter: digital or analogue
will do.  It would really be unwise to try to make this thing without access
to an oscilloscope (and a rough idea of how to use it): without a 'scope, you
are even in the dark about whether the oscillator is running, etc.  Being able
to get to a 'scope is good enough - it doesn't have to be hooked up for days
at a time.

Description - 1 - Output

      The clock oscillator (top right) runs a 4 MHz crystal with a couple of
LSTTL gates biased into linear mode.  The 100p capacitor protects the crystal
from the DC offset between the input and output of the circuit.  The 4MHz
crystal clock is divided down to 1 MHz by the two halves of a 4013 CMOS JK
flipflop, and applied to the clock inputs of the UART.

      The UART option pins (number of start/stop bits, parity etc.) are all
strapped permanently to the required configuration.  The data bits from the
parallel port are applied directly to the data inputs of the UART.  The pull-
up resistors are not essential, but they will help noise immunity.  The UART
is strobed by a signal derived, via a couple of schmitt-trigger inverters (to
sharpen up the strobe edge) from the control port bit zero.  Notice that
several of the control and status bits on the parallel port are inverted as
they appear in the outside world.  Bit zero is one of them, so that it has the
correct polarity to drive the UART (which expects a negative-going strobe). 

      The data output from the UART appears at pin 25, is inverted through the
40106 to give the correct polarity ('1' == no current in the MIDI loop) and
applied to a couple of paralleled 'LS7404 inverters which act as MIDI drivers
in the usual way.  The signal at the output of the 40106 is also picked off
to drive another gate with a time-constant at its input, which in turn drives
the 'output data' tell-tale LED.  The diode and resistors on the input of this
arrangement prevent it from loading down and upsetting the timing on the
outgoing MIDI data.

      This much of the circuit is enough to drive a synthesiser.  It can be
tested with a 'scope, by shorting the input for control bit zero to ground
momentarily, which should generate a stream of data at the MIDI output.  So
long as the clock is running, it should be easy to get this much to work.

Description - 2 - reset, interrupt and select logic

      Bits 1 (which is output inverted) and 2 of the control port are used for
several functions.  A table is given on the circuit diagram.  Normal operation
is with both bits set to zero, which will generate a logic 'high' on pin 14
and a 'low' on pin 16 of the interface.  These logic levels are applied
directly to two 'LS153 2 x 4 multiplexers, which select which status bits are
to be presented to the parallel port.  When the control bits are zeroes, the
multiplexers present the error bits OE and FE, the 'data available' signal DR,
and an interrupt signal to the status pins of the parallel port.  

      The interrupt is derived from the data ready signal by the 4093 schmitt
NAND gate: when DR turns on, both inputs of the NAND become high and the
output goes low.  The 560p capacitor discharges through the 1K5 resistor in
about 0.5 us, at which point the NAND gate output goes high again.  If the
interrupt is serviced, this is all that happens.  However, if the interrupt
is not serviced, DR will remain high and the capacitor will eventually
recharge through the 470K resistor (about 100 us), and another interrupt pulse
will be generated.  Hence the circuit generates a stream of interrupt pulses
until the DR status is removed.  Notice that the interrupt signal is passed
via the output multiplexers.

      The data bits presented by the UART are applied to the output
multiplexers, and selected by the setting of control port bits 1 and 2. When
control bit 2 is set, the UART DR status is simultaneously cleared: hence the
order of reading the two nybbles must be such that the low nybble is read
last.  Notice that there is a potential race condition here, in that if the
low nybble is not read promptly (within one character time), there is a
possibility that another incoming character could update the data register
after the multiplexer has been set and the original DR status cleared, but
before the original data has been read.  This is improbable, but can be
detected by software by checking that DR is clear after a read of the low
nybble: if not, a data collision has taken place.

      The reset circuitry is a simple transistor inverter: any general-purpose
PNP transistor will serve.  At power-on the 4u7 capacitor holds the base of
the transistor low for a few milliseconds, so that the UART is correctly
reset.  During operation, writing ones to control port bits 1 and 2 will turn
on the NAND gate and likewise reset the UART.  The 560p capacitor on the
transistor base avoids the generation of spurious reset signals if the control
port bits are written directly from '01' to '10'.

Description - 3- MIDI in and thru

      The MIDI input is a standard circuit using a CNY17 opto-isolator.  There
are others which will work in this application, but the device must be a high-
speed isolator.  Pinouts of other devices will vary.

      The output of the isolator is logically correct data (not inverted), and
is applied directly to the serial data in port of the UART.  At the same time,
it is applied to a MIDI output circuit of the same type as used on the UART
output, creating a MIDI thru port.

      The MIDI thru facility turns out not to be very useful on a computer
interface, but the tell-tale LED derived from it, indicating incoming data,
is very useful indeed.