An introduction to the MIDI interface

Scott Mackie
This is the first of two articles which aim to outline the basic ideas behind MIDI and its computer interface. These ideas will then be applied to a MIDI interface for AMPLE, allowing the Music 500(0) to run as a performance-oriented MIDI expander.
I appreciate that this technically-based project may not be of interest to every AMPLINEX member but it should at least provoke some discussion on interfacing AMPLE to the outside world.

MIDI - A General Introduction

To start with, I apologize to anyone who is familiar with MIDI and its uses if they find the following paragraphs a bit elementary (read on though!).
The Musical Instrument Digital Interface, to give it its full title, began life, officially, around 1983. The standard has become widespread and is universally accepted as THE means by which musical information can be transmitted between synthesisers.
The MIDI interface is serial, much like the RS232; however, it runs at a rate of 31.25 Kbaud. This speed allows data to be transferred without disrupting simultaneous musical events. Because this rate is at least three times faster than the maximum possible serial rate from the BBC microcomputer an external interface must be used.
The data transferred consists of a series of bytes (generally three for common applications): an ID byte followed by two bytes of data. This allows MIDI to accommodate new commands as and when they are needed, and should prolong its working life.

A MIDI interface for the BBC micro

A MIDI interface is usually connected to the 1MHz bus on the BBC micro as it requires the system clock and address lines, in addition to the data bus, to function. When I first set out to build an interface, I studied all the designs in the electronics magazines and was shocked at their simplicity!
All of the data handling is carried out by just one serial chip, so with the addition of some address decoding, clock generation for the data rate and an opto-isolator, a complete MIDI interface can be constructed.
To describe an interface design would be difficult using the text format of AMPLINEX, so instead I will list some of the published interface projects and then describe the possible problems along with my own comments on MIDI interface design.
All the interfaces here are based around the 6850 UART chip. This is widely available and is extremely easy to program and use. The interfaces are:
1. The ETI MIDI interface (Electronics Today International, April 1987): This is the interface I use. It has two 6850s to enable dual inputs and outputs and because of this is slightly more complex. It can, however, be run with just one port by omitting the second 6850 and opto-isolator - I do this, since I don't require the additional input and output right now.
This design does have a PCB available, which is an advantage, but it requires careful soldering due to a slightly sloppy board design. However, it does work reliably once constructed. The article on the project is a bit scrappy, and some other reference work would have to be consulted about the basics of MIDI operation.
2. The Maplin MIDI Interface (March/May 87): This project was designed as a general interface to Commodore computers and doesn't have a PCB available. It is, however, a very simple interface and appears easy to construct, even if Veroboard is used.
Because it uses the Commodore interface port, some additional address decoding must be used to allow interfacing to the 1MHz bus. Most hardened BBC micro home constructors could build this project, but some experience is required as a board has to be designed.
One small point about this design is that no mention is made of ANY interrupt interfacing, and a connection will have to be made from the IRQ output of the 6850 to one of the interrupt lines on the 1MHz bus (see my notes later about this). The article covering the interface is very clear and concise and is a reasonably useful basic guide to MIDI.
3. The E&MM interface (Electronics and Music Maker, June/July 1984): A rather ancient design this, but I'm told it works by colleagues who've built it. A very basic 6850 design, but very serviceable. One problem with this is that the back issues of the magazine have sold out, but I believe that photocopies are available for a small sum.
4. Making Music (Issues 1 and 2): Again, I'm not too familiar with this interface, but it appears to be standard. The only problem is that Making Music have sold out of these issues, but a letter to them may elicit a response. The designer was Andy Honeybone, so requests may be directed to him.
All of these interfaces use a similar design, the only difference being the addresses they're mapped on to in the 1MHz bus workspace.
The interface I use cost around £30 to build and get working, which is obviously a bit less than the £160 for Hybrid Technology's Music 2000 unit. Admittedly, they supply module code and three MIDI outs, but the price seems to me to be slightly excessive. I'm not sure what design Hybrid Technology use, although I'm almost certain it's based on 6850s.
A couple of design points need to be raised at this point about building a MIDI interface. These are:
1) Use a good quality opto-isolator. The isolator is required because MIDI is based on a 5mA current loop system, and as such the interface must be isolated from the data to prevent any current loss in the loop. The current loop principle allows many separate earth instruments to be connected without setting up earth-loops, i.e. conducting paths which act rather like a radio antenna except that they pick up mains hum.
A poor quality opto-isolator will prevent weak MIDI signals from being registered or may even be too slow (remember that it has to run at 31.25 Kbaud). The difference between a cheap opto-isolator and a good one is only a matter of a pound, so it's really a fool's economy to buy a cheap one. The opto-isolator I recommend, and use, is the 6N139. This is very fast, with good sensitivity and compatibility. Its cheaper partner, the 6N138 is slightly slower, but is still very good.
2) Make sure the interface is mapped on to page &FC in the 1MHz bus workspace. The Music 500(0) synthesiser hardware maps on to &FD30 to &FD3F and so these addresses must be left alone, along with &FCFF, which is the paging register for them. I page my board into &FCF0 and &FCF1 which is where the ETI design puts them.
3) Most designs connect the interrupt pinout on the 6850 to the IRQ input on the 1MHz bus. This means that a normal interrupt occurs when a data byte arrives at the 6850, in order to signal its presence. I tried this method to start with and spent three frustrating weeks trying to get the BBC to read the port reliably, without dropping bytes from the input stream. The problem was that the IRQ interrupt is vectored and takes a while to reach the IRQ2 vector and this causes a delay problem with the 6850.
Intercepting the higher priority IRQ1 vector proved to be slightly better but still not ideal. By chance, I noticed that Andy Honeybone in his Making Music articles used the NMI line on the 1MHz bus. I tried this and the interface has worked reliably ever since. This has the major advantage with AMPLE of not interfering with the extensive Hybrid interrupt routines which also claim IRQ1.
There are problems with this method though and these need to be pointed out. The NMI (or Non-Maskable Interrupt) line is normally used to allow filing systems to generate fast interrupts as the 6502 cannot ignore their action (hence the Non-Maskable title).
As the disc system, which is the main user, is not generally used while playing music, the MIDI interface can use the NMI interrupt for itself. When an NMI occurs, the 6502 jumps to &D00 and executes the code there.
Normally the disc system has its service code there, but if the MIDI service code is placed there, it will be executed on an NMI generated by the 6850.
This has great advantages in terms of speed, but does mean that the user has to be careful when accessing discs to ensure that no keys on the master keyboard are pressed while the 6850 IRQ is enabled or, alternatively, that the 6850 has it's interrupt enable flag cleared (I clear the interrupt enable flag before returning to AMPLE so the code next time is safe if used as it stands).
Most of the designs above require a small change to the PCB in order to get the interrupt connected to the NMI line. Just cut the track on the interface going to pin 8 of the 1MHz bus and connect it instead to pin 6 (i.e. just move it one pin to the closest end). A switch can be used if the user still wants to use the original setup.
This project may seem a bit daunting, but with some patience, a working interface can be constructed. However, I would recommend that the constructor has some kit-building and electronics knowledge as the interface involves quite a bit of delicate soldering; not the sort of project to learn on! All of the articles have information on the operation of the interface and I leave it to them to illustrate their own designs.
In view of the modifications to these designs that I have suggested I have drafted an example interface for the BBC micro that will run without ANY modifications having to be made to it. This will be available via AMPLINEX (see below for details).
If any AMPLINEX members have queries regarding this article then they should send their questions via AMPLINEX, or write to me at the address given below.
In the next issue of AMPLINEX, I'll supply, and document, the necessary code to enable the Music 500(0) to run as a MIDI expander and put many synthesisers currently available to shame! AMPLINEX members should note that this software only supports the MIDI In port, NOT the MIDI Out; i.e. it performs the exact opposite of the current Music 2000 software.

Some useful addresses:
Electronics Today International 1 Golden Square LONDON W1R 3AB
Maplin Electronic Supplies PO Box 3 Rayleigh ESSEX SS6 8LR
Making Music 40 Bowling Green Lane LONDON EC1R 0NE
Music Technology (formerly E&MM) Alexander House 1 Milton Road CAMBRIDGE CB4 1UY
and finally my own address:
Scott Mackie 48 Milford East Kilbride GLASGOW G75 9BU

A copy of Scott Mackie's MIDI interface design can be obtained by sending a stamped, self-addressed envelope to:
AMPLINEX, 26 Arbor Lane, Winnersh, Berks. RG11 5JD.
Important note: We must stress that this design has not been tested by AMPLINEX and we would emphasize that it is not suitable for beginners to electronics assembly.

Published in AMPLINEX 006, July 1988