Hacker’s Haven Presents: ZX-81 (and 2068) MIDI Interface Project, Part 2

See all articles from Sinc-Link v7 n4
Author(s): Lou Champagne
Publication: Sinc-Link
Pub Details: Sinc-Link v7 n4 (Volume 7, Issue 4)
Date: July/August 1989
Pages: 20-23

HACKER’S HAVEN PRESENTS: PART 2 — ZX-81 ( AND 2068 ) MIDI INTERFACE PROJECT

In the next few issues I will be describing the design and construction of a ZX-81 computer interface to connect to MIDI equipped musical equipment. Hopefully some members will become involved in developing software and applications for this project.

In the last article I described the development of a MIDI interface using the Motorola 6850 ACIA chip. Since then, after some experimentation with the circuit concepts, and discussion with other Timex users some necessary changes become apparent.

Do not use the TIL-111 for the opto-isolator as the max frequency (and therefore the data throughput rate) varies from component to component too much and in some units was found to be too slow resulting in a poor waveform at the 6850 RXD input. I have switched to a 6N136 and now have excellent results.

The clock frequency of 2 Mhz is too much for the average 6850. I was using a 6850 “B” model which functioned properly at first but degraded somewhat after long periods of use. I believe this was thermal but never-the-less I figured wrongly that I could “push” the quoted spec. of 1.5 Mhz. So now the circuit contains a “divide by 4” on the oscillator output made out of a 74LS74 chip. It is also necessary to send a 55hex to the ACIA as the second setup byte in order to use the onboard “divide by 4” in the ACIA. The resultant clock frequency in the ACIA of 125Khz provides the necessary clock for 31.25 Kbaud which is MIDI.

The addressing must be changed for proper operation as well. To work with the Larken disk drive interface as well as to solve the 2068 interfacing problem. In addition early circuit tests revealed an interaction between the keyboard and the interface which has been fixed. To anyone who has experimented in building the interface I suggest the following become standard.

A0 is NOT to be used, this means the board can be accessed in the FAST and SLOW modes (ZX-81 users will have to subtract 1 from the address for SLOW mode M/L). I consulted Larry Kenny on the disk drive address interaction problem and have since decided to use these addresses…

   BINARY      6850     DECIMAL     HEX
---------------------------------------
0010 0111 CONT 39 27
0010 1111 STAT 47 2F
0011 0111 TXD 55 37
0011 1111 RXD 57 3F

Since A3 now controls RD/W and A4 operates the register select lines on the 6850 the scematic that has now evolved is this….

MIDI interface schematic: 6850 ACIA with 2 MHz oscillator (3 x 1/3 74LS04), divide by 4 (2 x 1/2 74LS74), address decoding (74LS04, 74LS11), MIDI OUT and 6N136 opto-isolated MIDI IN
MIDI interface schematic: 6850 ACIA with 2 MHz oscillator (3 x 1/3 74LS04), divide by 4 (2 x 1/2 74LS74), address decoding (74LS04, 74LS11), MIDI OUT and 6N136 opto-isolated MIDI IN

Incedently, Larry Kenny’s LDOS eprom has a routine on it to output data to any odd # port. From Basic POKE 12300, port # in decimal; POKE 12301,data byte value ; and then RAND USR 16374 to output the data.

The following are excerpts from the MIDI spec. 1.0

MIDI… serial interface at 31.25 Kbaud

8 bit data 1 start bit 1 stop bit no parity bit

multi byte format – most messages use at least 3 bytes

These messages are structured like this…

                 example of NOTE ON message
--------------------------
byte 1 byte 2 byte 3

1001 xxxx 0kkk kkkk 0vvv vvvv

xxxx= MIDI CHANNEL 0-15 kkk kkkk=KEY NUMBER vvv vvvv=VELOCITY
(represents 1-16) ( 0-127 ) ( 0-127 )

example of NOTE OFF message
---------------------------
byte 1 byte 2 byte 3

1000 xxxx 0kkk kkkk 0vvv vvvv

VELOCITY usually set to
0000 0000 except when
"RELEASE VELOCITY" is used

example of PITCH BENDER message
-------------------------------
byte 1 byte 2 byte 3

1110 xxxx 0ppp pppp 0ppp pppp

ppp pppp= PITCH BEND this second optional
(0 - 127) byte provides higher
resolution on some
where 64 is centre(normal) synth modules but is
ignored if not used

example of PROGRAM CHANGE message
---------------------------------
byte 1 byte 2

1100 xxxx 0nnn nnnn no 3rd byte

nnn nnnn=PRESET NUMBER for tone changing
(0-127

also there are some important messages that are only one byte long

1111 1000     MIDI CLOCK - received or transmitted to synch up to
---------- another devices time base - one of these
is sent every 24th of a beat of music
so in 4/4 time 96 are sent every bar
so at 120 beats per minute 48 of these
must be sent or received and processed
every second.

1111 1010 START - used to tell other sequencers to start
----- sent before MIDI CLOCK starts

1111 1100 STOP - used to stop all MIDI CLOCK controlled
---- devices

There are plenty more messages in the MIDI spec. 1.0 the curious should consider contacting THE INTERNATIONAL MIDI ASSOCIATION , 5316 WEST 57th Street, Los Angeles, California USA 90056.

HEX     DEC    ADDRESS      ASSEMBLER        COMMENT
-----------------------------------------------------------------
3E 62 16514 LD A, SETUP BYTE
03 03 5 03 -RESET
D3 211 6 OUT-A, OUTPUT IT
27 39 7 27 PORT 27H(CONT)
3E 62 8 LD A, #2 SETUP BYTE
55 85 9 55 #BITS CLOCKDIV PARITY
D3 211 20 OUT-A, OUTPUT IT
27 39 1 27 PORT 27H(CONT)
DB 219 2 IN A, INPUT FROM
2F 47 3 2F 2FH (STAT)
CB 203 4 BIT O, BIT CHECK ON
47 71 5 A STATUS TO FLAG
28 40 6 JRZ, LOOP IF
FA 250 7 FA NO BYTE IN RXD
DB 219 8 IN A, INPUT FROM
3F 57 9 3F 3FH (RXD)
D3 211 30 OUT-A, OUTPUT TO
37 55 1 37 37H (TXD)
C3 195 2 JMP JUMP TO
8A 138 3 8A- 408AH (16522)
40 64 4 40 TEST RXD
-----------------------------------------------------------------

This is some machine code that tests out the interface on a ZX-81. It is a illustration of how the ports are used as well as the decoding of the status byte. At any rate it tests a completed interface by passing MIDI IN data out through the MIDI OUT jack. Connect the MIDI OUT of the source device ( keyboard, sequencer,or drum pad etc. ) to MIDI IN of the interface. The MIDI OUT of the interface should go to MIDI IN of a controlled device such as a synth voice module.

TILL NEXT TIME HAPPY MIDI HACKING — HACKERS HAVEN LOGGING OFF BYE

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.