A MIDI Pedalboard Encoder
Home Up Other Publications Contact Me About the Author About this Website Prog Organ - a VPO Sitemap What they say

 

A MIDI Pedalboard Encoder

by Colin Pykett

 

Posted: January  2004

Last revised: 23 December 2009.

Copyright © C E Pykett

 

Abstract.  Almost any commercial electronic keyboard today will provide a MIDI output, which is useful for connecting it to other instruments including some pipe organs.  However MIDI pedalboards are much rarer, which among other things makes it difficult to put together a simple home practice facility.  Therefore this article  shows how the appropriate MIDI signals can be generated from the closure or opening of a simple key contact.  Full details are included for a MIDI encoder suitable for a standard 30 or 32 note pedalboard; the encoder uses only a handful of standard integrated circuits, thus removing the need to program microprocessors or read-only memories for which few have the knowledge or facilities.  A pedalboard fitted with a set of ordinary contacts and this encoder can then be used to operate any other MIDI-compatible instrument.  Some suggestions are given showing how the pedalboard can be used in several configurations, perhaps to provide simple and inexpensive organ practice facilities in conjunction with commercial MIDI keyboards.  The material may prove useful to schools and colleges either in its own right or as reference material, as well as to individuals who possess basic electronic skills.

 

Contents

(click on the headings below to access the desired section)

 

Introduction

 

MIDI Essentials

 

    Some Basic Definitions

    Basic Hardware Issues

    MIDI Messages

 

        Status Byte : Channel Number

        Status Byte : Message Type

        Data Bytes 1 and 2

 

    MIDI Modes

 

The MIDI Pedalboard Encoder - Principles of Operation

 

    Outline Description

    Detailed Description

 

        Circuit Details

        System Clock

        Keyboard Scanner

        Status Comparator

        Scan Clock Inhibit

        MIDI Code Generator Clock Enable

        MIDI Address Generator

        MIDI Code Generator

        Switch-selectable Options

        MIDI Output Circuit

        SRAM

        Memory Write Circuit

        Constructional Notes

        Debugging

 

Using the MIDI Pedalboard

 

Notes and References

 

 

Introduction

I decided to write a detailed article about a MIDI encoder for a pedal keyboard because the availability of such units seems to fluctuate – sometimes there are several alternatives on the market yet at others none.  Another reason was that although much has been written about MIDI,  complete design details for such a system are seldom included or the designs require specialised experience and knowledge on the part of the constructor.  This article also includes technical information about MIDI which makes it a companion to another on this website, which was written at a non-technical level for organists [7].

Without doubt, the most economical and flexible way to proceed is to use a microprocessor controlled system, and PIC microcontrollers [6] are particularly attractive on account of their low cost and ready availability.  However the use of PICs or similar devices requires some level of experience in their hardware and software aspects which, although not beyond the wit of man, is decidedly non-trivial.  Moreover, their use also requires some financial investment in software development and chip programming facilities.  Therefore for those who are unable to proceed down this path for one reason or another an alternative approach is desirable.  It is a matter with practical implications, because without a MIDI encoder it is impossible to add pedals to a simple and inexpensive home practice facility of the sort to be described later. 

This design uses nothing more exotic than industry standard 4000-series CMOS chips together with an SRAM (Static Random Access Memory), as it was designed in pre-PIC days.  Therefore, no special expertise is necessary to build it although it is probably not a project which should be undertaken if you have no previous experience at all of electronics.  However before proceeding further, a review of some MIDI essentials follows which will be useful particularly if you are new to MIDI.

 

  MIDI Essentials

This section canters through some aspects of MIDI to enable readers who may be unfamiliar with it to better comprehend the material later on.  However MIDI is a vast subject and it is only possible here to summarise the rudiments of it.  Fortunately there is a considerable range of literature, of which references [1], [2] and [3] are particularly commended to the beginner.  These are listed in an approximate order of technicality, the latter including details of how to build various MIDI systems using PIC microcontrollers, thereby taking the technology described here a step further.  

MIDI stands for Musical Instrument Digital Interface and it came into being in the early 1980’s when the major electronic musical instrument manufacturers got together to agree a common control standard for their products.  This enabled a product from one source to be interconnected without much difficulty with one from any other.  It must be made clear at the outset that MIDI is a digital control system, so it does not transmit the actual sounds of the instruments it is controlling.  This is a matter which causes confusion in view of the existence of a set of 128 "instruments" and effects inappropriately called General MIDI (GM) [4] which appear on virtually all electronic keyboards, synthesisers and computer sound cards.  These sounds are generated internally in the equipment mentioned and they differ in detail from one manufacturer to another, but MIDI itself only selects which of the instruments is heard when notes are keyed. 

Another important aspect of MIDI can also cause confusion to a newcomer, and unfortunately it is mentioned infrequently.  It is that no MIDI signals are sent unless something changes [8].  Thus while no notes are being played, no signals are sent.  This might seem obvious, but it is not true of many other non-MIDI multiplex transmission systems.  Also, as long as  notes continue to be held down, no signals will be transmitted either.  Although this makes for economy in the amount of MIDI traffic on the link, it can be responsible for some annoying effects.  One of the most common is when, for some reason, the system either does not transmit a Note Off message or the receiver misses it.  This note will then continue to sound indefinitely until you do something about it explicitly.  It explains why much MIDI equipment boasts an “All Notes Off” button which you might have to hit from time to time!  There are also other annoying features of MIDI which most users discover and come to terms with in due course.  They are simply aspects of the way the system was designed and they cannot be surmounted easily.

Some Basic Definitions

Definitions of a few MIDI terms follow which will be useful later.  It is by no means an exhaustive list.  The terms are explained in more detail later on:   

 

Preset (also called instruments, voices, patches or programs).

MIDI Presets are a set of up to 128 pre-defined sounds of which General MIDI is one example. 

   

 Bank

A Bank is a set of 128 Presets.  There can be up to 16384 different Banks.

   

 Channel  

There are 16 transmit channels available in MIDI and a commercial keyboard can be set to transmit on any of them.  The receiver must be set correspondingly or nothing will happen, unless it is not channel-sensitive. 

Basic Hardware Issues

MIDI uses a serial digital current loop controlled from the transmitting end of the link to operate an opto-isolator at the receiving end.  Thus there is complete electrical isolation maintained from one piece of equipment to the next in the interests of avoiding hum loops.  This isolation must never be compromised, and it is always prudent to check with an ohmmeter that there is no continuity between the screens of MIDI cables and any other equipment (including chassis, earth lines, audio inputs and outputs etc) in the system. 

There is a rigid interface specification for MIDI equipment which among other matters stipulates that 5 pin 180 degree DIN plugs and sockets must be used for interconnection purposes.  Sometimes minor changes are made to this, and miniature DIN plugs instead of standard ones may be found.  In these cases an interface lead is often provided so that the equipment will connect properly to ordinary MIDI cables.  Normally only three pins of the DIN connector need to be used, and these must be wired correctly because polarity is important for several reasons.  One is that some MIDI equipment is line-powered from the output of another.   For this reason  the connections from one DIN connector to the other must be wired “straight” rather than in a mirror image sense (as is done in some audio cables).  Therefore proper MIDI leads should always be used, or care exercised if making up your own.

Figure 1.  Standard MIDI Output Circuit

Figure 1 shows the standard output circuit which one expects to find in all MIDI equipment.  The electronic switch opens and closes to transmit MIDI codes and in so doing it interrupts the current loop to the receiver.  A straightforward twin screened cable is sufficient to interconnect the two pieces of equipment, and the screen is connected to pin 2 of the DIN socket.  It should be connected at both ends because of the need to use it sometimes as the return path for line powered equipment which draws its power from pin 4.

MIDI Messages

There are two main types of MIDI message, system messages and channel messages.  The former exist in a vast variety of forms, many of which are specific to particular manufacturers, and it is partly for this reason we shall not discuss them further here.  Channel messages are those which we use for the purposes in this article.  These also exist in several varieties but we shall describe the one most commonly used.  It consists of 3 data bytes (a byte is 8 bits) sent one after the other.  Each byte is preceded by a start bit and it ends with a stop bit.  Thus there are 30 bits in the message.  The system uses a variant of the RS232 serial interface protocol in which it sends bits at a rate of 31.25 kbaud (31.25 thousand bits per second).  Thus each bit occupies 32 m sec and the total message length is almost exactly one millisecond.  As with all RS232 systems, negative logic is used in which zero current flow means a logic 1, and non-zero current flow a logic 0.

 

Figure 2. MIDI 3-byte Message Structure

Figure 2  illustrates the bit stream for a 3-byte channel message.  Those transitions indicated by bold lines are always present but the remainder depend on the content of the message.  Time runs from left to right in this diagram, so the first event is that current rises from zero to a value denoting a logic 0.  This signals the start bit of the first byte to the receiving equipment.  Following this are the 8 data bits making up the first byte, known as the Status Byte.  Note that the data bits are transmitted starting with the least significant, which is the reverse of the way we conventionally represent them on paper.  For example, a byte with a value of  1 would be written in binary notation as 00000001, whereas this pattern would have to be reversed to fit into the bit positions of the diagram above.  Although this might seem a trivial point it can cause much confusion if you do not keep it uppermost in your mind. 

Status Byte:  Channel Number

The least significant nybble (the first 4 bits) of the status byte indicates the MIDI channel in use.  Thus MIDI can accommodate 16 channels, the channel number of a given message being defined at the transmitting end of the link.  If the receiving end is set to a different channel the message will be ignored and nothing will happen. Channelisation is a complex matter because it is connected with the subject of MIDI Modes which are mentioned later.  Whereas the channel is defined at the transmitting end of the link, the mode is defined by the receiver, and as just mentioned the transmitter and receiver have to be set appropriately to make things work.   

Status Byte: Message Type

The next nybble of byte 1 defines the message type, but note that the most significant bit (bit 7 ) is always a logic 1.  This differs from the MSB’s of the following bytes which are always 0.  This convention is said to facilitate the receiver distinguishing a status byte from any other sort, but from all other points of view it must be one of the daftest design decisions ever taken in electronics.  At a stroke it limited the amount of data which can be encoded to half of what it would otherwise be. 

The important message types for our purposes are in the table below.  There are other types but we make no use of them here. 

Message Type

Binary Code

Note On

1001

Note Off

1000

Program Change

1100

Control Change

1011

Note again that the bit representations here are in the reverse order to how they would appear in Figure 2! 

The “Note On” and “Note Off” messages are self-explanatory, but the system needs to know which note has been switched on or off.  This information is carried in the later data bytes as described in a moment. 

“Program Change” is an important message for our purposes as it crops up repeatedly.  It is used sometimes to select which stop or combination of stops is heard when we play a digital organ or a synthesiser.  In the latter case it selects an "instrument" to be played from the General MIDI set, for example.  Yet again, remember these bits only define the message type – the data defining the stop to be used follows in successive bytes. 

“Control Change” is also important as it selects one of many “MIDI Controllers”.  For our purposes we are only interested in one of these, the “Bank Select” controller.  MIDI Banks will also be described later. 

Data Bytes 1 and 2

The information carried by the two data bytes depends on which type of message is being transmitted, as follows:  

 

 Note On or Note Off

 

For either of these messages bits 0 – 6 of data byte 1 hold the number of the note in question,  from 0 to 127 (bit 7 is always 0).  Thus the MIDI system can accommodate 128 notes or about 10 ½ octaves.  0 represents the bottom note of this range;  127 the top note.   Conventionally, middle C is note number 60.

 

Data byte 2 holds the velocity of the note when there is a Note On message, and it is ignored by the receiver for a Note Off.  Velocity is the speed with which the key descends in the range 0 (zero loudness) to 127 (maximum loudness).  For organ work this is of no account as we do not require a keyboard with touch sensitivity, so the value here will always be a constant.  Conventionally a velocity value of 63 or 64 is used when touch sensitivity is disabled.

 

Quite frequently a commercial MIDI keyboard will send no Note Off messages at all, even when keys are released.  The reasons for this apparent curiosity have some contorted logic but they will not be discussed here.  When this convention is used, key release is signalled by using a Note On message but with zero velocity [9].

   

 Program Change

 

When this message is sent there is usually only one following data byte rather than two, and it holds the number of the desired “program”.  Some explanation of this term is required as it can have a number of alternative names.

   

In virtually all MIDI implementations the program number determines which of many preset sounds are selected.  Again the number range is from 0 to 127, enabling up to 128 sounds to be called up (in fact the actual number is vastly more than this if we invoke the concept of MIDI Banks as described shortly).  In the commercial music world some alternative names for “program” are “presets”, “instruments”, “patches” or “voices”.

 

 Control Change

 

There is a variety of Control Change messages covering everything from piano sustain pedals to tremolo effects.  However we are only concerned here with how to change MIDI Banks, and these will now be explained.

   

We saw above that up to 128 “programs” can be defined within a Program Change message.  In the MIDI system these all occupy what is called a Bank (i.e. a bank of 128 different presettable sounds).  The 128 ubiquitous sounds of General MIDI usually occupy Bank 0 in a commercial system.  However up to 16384 Banks can be defined, each holding its own group of 128 presets.   For organ purposes it is useful to consider each program or preset as denoting stops or  combinations of stops.  In the latter case we can go further and think of a combination of stops as equivalent to a general piston or a sequencer setting.  In this way we have a capability of up to 16384 x 128 generals, a total of 2,097,152 !  By transmitting Bank Select (i.e. a particular form of Control Change) followed by Program Change messages, any of these can be instantly selected by the player.

 

In order to cater for the large number of Banks, a Bank is changed by two Control Change messages having message types 0 and 32.  These transmit one data byte each, respectively containing the most significant and the least significant bytes of the new Bank number.  It is not recommended that you worry too much about the details of the Bank Select message structure in a MIDI system at this stage. 

MIDI Modes

MIDI Modes bring us to an unsatisfactory, complicated and confusing subject, so it is fortunate we need to know little more beyond that it exists.  The naming convention of the various modes goes back to the days of monophonic synthesisers, as some of the modes switch between monophonic and polyphonic operation.  Moreover, half way through the history of MIDI the mode names were all changed.  Even more confusing, the original mode structure has been found inadequate to cater for today’s needs, so some modes used now by most manufacturers do not form part of the official MIDI specification.

 

A good account of modes appears in [2] , and the bare minimum of basic facts appears below:

 

 Modes are defined by the receiver, not the transmitter.

 

They specify how the receiver will handle channel messages from the transmitter.

 

 A very important aspect concerns channelisation – a unit in mode 1 will respond to messages on any channel whereas in mode 3 it will respond only to those of a specific channel.  

 

The MIDI Pedalboard Encoder - Principle of Operation

Outline Description

The general principles of operation of the encoder are as follows.  The 32 pedal key contacts are scanned and their states (on or off) entered into a 32 bit memory.  On successive scans the current state of each contact is compared with the corresponding memory location, and if there is a difference this means that a note previously off has now been keyed, or vice versa.  When such a difference is detected a MIDI code is transmitted containing the address of the note in question and whether it has been switched on or off.  When the transmission is complete the memory location for this note is updated to reflect the new status of the note, and then the key scan continues. 

  Figure 3.  Block diagram of the MIDI encoder 

Detailed Description

A block diagram of the system is shown in Figure 3.  Before addressing the detail it is important to point out that the system must work at 5 volts.  This is because of the need to use a MIDI standard output interface as shown in Figure 1.  So if you decide to use other voltages for the logic inside the system you must ensure that only 5 volts appears at the output, otherwise MIDI receiving equipment could be damaged.  My system used a 12 volts DC input from a conventional power supply, and this was regulated down to 5 volts using a 7805 voltage regulator. 

First let us assume that no keys are pressed.  Under these conditions the clock generator supplies pulses at 3.9 kHz through the clk inhibit box to the keyboard scanner address generator (thus the clock is not in fact inhibited at this stage – this occurs later).  This repeatedly generates a cycle of addresses from 0 to 31 on a 5 bit bus, and these are supplied to the key contact scanner.  This distributes pulses in sequence to the 32 pedal contacts.  A scan frequency of 3.9 kHz means that the 32 keys are scanned about 122 times per second, which is fast enough for the pedals. 

The same address lines are also connected to an SRAM memory chip.  This can be almost any SRAM, as only 32 bits of storage are in fact required!  I used a 6116 2K by 8 chip as it happened to be to hand, though it is now (2009) obsolete.  However it can still be obtained from various sources, and several equivalents are obtainable [11].  Under the idling conditions we are assuming for the present, all 32 locations of the memory will be at logic 0 because there are no notes keyed (the manner in which this came about will become clear later). 

For each address, the status comparator compares the input from the key contact array on line B and the output from the memory on line A.  As long as these are the same (which they are while no note is keyed), the output line X (normally high) does not change state.  This is true whether A and B are both high or both low.  Only when a difference exists does the output line change state. 

Now consider what happens when a note is keyed.  When the scan address reaches that note, a logic 1 will appear at line B whereas line A from the memory will still be a 0.  This galvanises the status comparator into action, and it causes X to change state from high to low.  Simultaneously Z goes high, indicating a new Note On has been detected. 

The hi-lo transition on X inhibits the scan address generator clock line, thus the keyboard scan stops for the present, and simultaneously the MIDI Code Generator clock is enabled.  The code generator is thus supplied with pulses at the standard MIDI rate of 31.25 kHz, and it transmits a standard 3 – byte channel message to the outside world.  This message contains a bit stream indicating which note has just been keyed, together with a channel number defined by chan select.  The note address on lines A0 – A4 is added to a base address supplied from base addr select.  Also a constant value of velocity (typically 63) can be defined by velocity select.  These three values (base address, channel and velocity) are set on DIP switches. 

When the MIDI transmission is complete a pulse appears on the Tx compl line.  This is supplied to the memory write circuit which is also aware (via the high on B) that a Note On state has just been detected.  Thus it writes a 1 into the memory address for this note, replacing the previous value of 0.  As soon as this happens line A goes high (because the memory output is now high), and this means that the two lines A and B are both high.  (Until the contents of the memory was refreshed, A was low and B was high).  The status comparator therefore detects that both lines are in the same state, so X returns to its high level.  This re-starts the scan clock, and the keyboard scan commences again. 

Now consider what happens when the note is released.  As before, the status comparator will detect this and X goes low.  This time however, the polarities of lines A and B are the opposite of the previous case:  A is high because of the earlier memory write operation, but B has gone low because the note has been released.  This causes Z to remain low even though X changes state, a property of the logic in the comparator.  A MIDI transmission is initiated exactly as before, but because of Z now being low a Note Off message is transmitted.  All other bits in the message remain the same as previously. 

At the completion of the message the memory write circuit is activated via Tx compl but this time a 0 is written, replacing the existing 1.  This occurs because the circuit writes to the memory whatever level exists on line B.  Following the write, lines A and B are now the same (low in both cases) so X goes high again and the keyboard scan re-commences. 

It should now be clear how the memory contents is first written when the circuit is switched on.  At this instant the memory will in general contain some random bit pattern. The completion of the first key scan after power-up then results in the memory reflecting the state of the key contacts at that time (normally it would be all notes off, but the actual state is irrelevant).  During this initial scan there will therefore be some meaningless MIDI codes transmitted as the correct memory contents is established, but a time delay circuit in series with the output prevents them reaching the outside world.

Circuit Details

The circuit of the encoder appears in Figures 4 and 5.  Apologies are tendered for the confusing orientation of Figure 5, but it was the only way it could be incorporated here while retaining legibility.

The circuit uses 16 standard CMOS circuits together with an SRAM chip. Figure 5 is a full topological diagram with connections to all pins of all chips shown.  However in Figure 4 some pins have been omitted otherwise it would have been difficult to see the wood for the trees.  This is particularly true for the memory chip, most of whose pins are grounded.  However such details are completed later in this narrative.  Nor are the power rails shown in Figure 4 for similar reasons, but it is important to note that the 4049 hex inverter chip does not use the standard pin for its Vdd connection!

Figure 4.  MIDI Encoder circuit (1) - above

Figure 5.  MIDI Encoder circuit (2) - above  

System Clock (Figure 5)

The clock uses the convenient 4060 chip which is a combined oscillator and divider.  It is imperative that a crystal controlled clock is used to ensure that the MIDI receiver (which works asynchronously with respect to the transmitter) has a high probability of synchronising itself within one half of a clock period to an incoming transmission.  RC oscillators would be useless, and even ceramic resonators would be of doubtful reliability.  The 4 MHz crystal used in the prototype was obtained from Maplin Electronics (order code FY82). 

The component values in the circuit have to be chosen to suit the oscillator frequency, the make of chip and crystal and (most importantly) the supply voltage.  Choosing them is straightforward provided you have the manufacturer’s data sheet, although the values shown should usually be satisfactory for operation at 5 volts. 

The clock generates two frequencies: one at 3.9 kHz is used to drive the keyboard scanner.  The other at 31.25 kHz drives the MIDI code generator. 

Keyboard Scanner (Figure 4)

The scanner is driven at 3.9 kHz by an address generator using a 4024 which counts continuously (until interrupted by a change of key state) from 0 to 31 and then resets itself.  This arrangement accommodates up to 32 pedal notes.  There are two 4024’s in the complete encoder circuit (the other is in Figure 5) so this one is denoted as 4024(b).  The 5 bit address from the 4024 is used to scan the key contacts, to address the contents of the SRAM, and to provide an (inverted) note address to the MIDI code generator. 

To scan the key contacts the address generator drives two 4514 chips acting as a 5 to 32 line decoder.  Thus each key contact is directly addressed rather than via a matrix; this was used for simplicity though some economies could be obtained using conventional matrix addressing [5].   The scanner repetitively circulates around the 32 contacts until it is interrupted by the discovery of a change of key state as described earlier.  Each 5 bit address from the address generator identifies a particular contact, address 0 corresponding to bottom C on the pedal board and 31 to top G.  Chip 4514(a) addresses notes 0 to 15 and 4514(b) notes 16 to 31.  The connections to the two decoder chips are in the tables below: 

Keyboard Scanner – Connections for 4514(a)  

Pin no. of 4514(a)

11

9

10

8

7

6

5

4

18

17

20

19

14

13

16

15

MIDI Note Address

0

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

Note

C1

C#1

D1

D#1

E1

F1

F#1

G1

G#1

A1

A#1

B1

C2

C#2

D2

D#2

 

Keyboard Scanner – Connections for 4514(b) 

Pin no. of 4514(b)

11

9

10

8

7

6

5

4

18

17

20

19

14

13

16

15

MIDI Note Address

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

Note

E2

F2

F#2

G2

G#2

A2

A#2

B2

C3

C#3

D3

D#3

E3

F3

F#3

G3

  

The MIDI note address is inverted by the 4049 hex inverter because MIDI requires negative logic data.  The result is then supplied to the MIDI code generator in Figure 5.  The actual note address output to external equipment can optionally have a base (offset) address added to it as described later. 

Status Comparator (Figure 4)

For each note during the scan the status comparator compares the current state of the key contact (on or off) with that on the previous scan.  The data for the previous scan are held in the 32 bit SRAM.  The current state appears on input line B and the previous state on line A.  Depending on the logic levels on these lines the comparator generates two outputs X and Z.  X is a negative-logic output denoting by going low that a change of status has been detected (it does not matter whether a note has just been switched on or switched off), and Z indicates by going high when the change of state is a Note On.  (Z is then inverted by a 4049 section to suit the negative logic convention of MIDI).  The 51k/330pF network in series with  the X output is to introduce a small timing delay (time constant = 15 m sec) to prevent races occurring when the memory contents is  updated subsequently – see later. 

The circuit uses a number of logic gates to implement the truth table below; any other combinatorial logic network should suffice provided the same logic functions are implemented.  Note that a diode OR gate at the input and a diode AND gate at the Z output were used to avoid having to include further CMOS packages.  

Status Comparator – Truth Table  

A

B

X

Z

Description

0

0

1

0

No status change – note still Off

1

1

1

0

No status change – note still On

0

1

0

1

Status change – Note On detected

1

0

0

0

Status change – Note Off detected

 

Scan Clock Inhibit (Figure 4)

The X output from the status comparator feeds a clock inhibit circuit which interrupts the keyboard scan whenever a change of state is detected.  It consists simply of the AND gate N3. 

MIDI Code Generator Clock Enable (Figure 5)

The X output from the status comparator also feeds a 4098 monostable which generates a 5 m sec pulse when X goes lo.  In turn this enables the MIDI clock at 31.25 kHz to commence incrementing the MIDI Address Generator. 

MIDI Address Generator (Figure 5)

This uses a second 4024 chip to generate 32 addresses from 0 to 31 at a rate of 31.25 kHz on receipt of the 5 m sec pulse from the monostable.  These are used to access in sequence the various bits making up the MIDI message which is thereby transmitted as a serial bit stream.  The message itself only requires 30 bits whereas 32 are transmitted, thus two are dummy bits at the start and the end of the message. 

MIDI Code Generator (Figure 5)

At first sight the obvious choice for the code generator would have been a UART (Universal Asynchronous Receiver/Transmitter) chip such as the 6402, but in this application it was inappropriate.  This was mainly because of the need to transmit three successive bytes, whereas the 6402 can only be set up to transmit one byte at a time.  Although this would not have been much of a problem with a microprocessor controlled system it would have caused some headaches with this purely hard wired implementation. 

Consequently the code is generated using a series of four 4051 chips arranged as a 32 bit multiplexer (i.e. a 32 bit parallel to serial converter).  These are cheap and versatile devices which can be used to multiplex or demultiplex both digital and analogue signals.  In Figure 5 the four chips are designated 4051(1) – 4051(4).  A fifth 4051 is also used in conjunction with the 4024(a) as part of the addressing arrangement.  The fifth 4051 is called the chip selector because it selects which of the other 4051’s is used for a given bit address, and it is at the top right of the diagram. 

Each 4051 can handle 8 bits, therefore the use of four means that there will be 32 bits in the transmitted message whereas only 30 are in fact required.  Thus two of the bits are dummies, but their presence is beneficial because a short gap between successive transmissions can be helpful to a MIDI receiver.  In effect the 32 clock pulses from the MIDI Address Generator sequentially transmit the successive bits in the message at the MIDI bit rate of 31.25 kHz.  Each bit is defined by a high or low level at a specific pin on one of the 4051’s, so that by supplying the correct pattern of highs and lows to these pins the desired message will be sent.  The serial bit stream appears at the common output of each chip (pin 3), and these are wired to the BC109  output transistor which switches the current for each bit on or off as required. 

In the diagram the lines for each data byte have been brought together in the correct order for ease of comprehension.  For example, the bar surrounding the 8 wires for “byte 1” (the Status Byte) shows the 8 bits for that byte, with the least significant bit to the left.  This is the order in which they are transmitted and it corresponds to the bit ordering in Figure 2 .  The start and stop bits for each byte are not included in the corresponding groups. 

The chip number and pin number for each data bit in the message are shown in the table below: 

Relation of Data Bytes to 4051 Pins  

Chip

1

1

1

1

1

1

2

2

2

2

2

2

3

3

3

3

3

3

4

4

4

4

4

4

Pin

15

12

1

5

2

4

13

14

1

5

2

4

13

14

15

12

2

4

13

14

15

12

1

5

Bit

0

1

2

3

4

5

6

7

0

1

2

3

4

5

6

7

0

1

2

3

4

5

6

7

Byte

1

1

1

1

1

1

1

1

2

2

2

2

2

2

2

2

3

3

3

3

3

3

3

3

 The chip number and pin number for each start, stop and dummy bit in the message are shown in the table below: 

Relation of Start, Stop and Dummy bits to 4051 pins  

Chip

1

1

2

2

3

3

4

4

Pin

13

14

15

12

1

5

2

4

Start Bits (Note 1)

 

·

 

·

 

·

 

 

Stop bits (Note 2)

 

 

·

 

·

 

·

 

Byte

 

1

1

2

2

3

3

 

Dummy bits (Notes 2 & 3)

·

 

 

 

 

 

 

·

Notes:

1.      The start bits are set to the high current state (MIDI logic 0), i.e. the potential applied to these pins is 5 volts. 

2.      The stop and dummy bits are set to the low current state (MIDI logic 1), i.e. the potential applied to these pins is zero. 

3.      The idling condition (start of message and end of message) of the circuit is in the low current state, both of which correspond to a dummy bit. 

Switch-selectable Options (Figure 5)

As shown in Figure 3 there are three selectable options, which determine the base address of the note range, the channel on which the message is transmitted, and the notional velocity of a transmitted note.  In the prototype all these were selected using a total of 6 DIP switches and these are shown in Figure 5.  Further details are as follows: 

·        Transmit Channel   (1-16) is set by the four switches controlling the state of bits 0-3 of byte 1.  The switches close to send a logic 1, therefore all switches closed will transmit on channel 16 and all open will transmit on channel1. Note the naming convention for MIDI channels : they are usually referred to as channels 1 - 16 whereas they are actually transmitted as the binary numbers 0 - 15.

·        Base Address is set by a single switch controlling bits 5 and 6 of byte 2.  If the switch is open the base address is zero (then the note range of the pedals is 0–31); with the switch closed it is 96 (then the note range becomes 96-127). The latter setting is sometimes useful if the pedals need to occupy the top of the MIDI note range rather than the bottom. 

·        Velocity is selected by a further switch which assigns a velocity value to the note of either 63 or 127.  If the switch is open the value is 63; if closed it is 127.  The 63 setting is recommended, partly because this is often used by other MIDI equipment in which touch sensitivity has been disabled, and partly because too high a setting of velocity can cause distortion in other equipment.  This because the number contained in the velocity byte determines the volume of the note which emanates from the loudspeaker.

MIDI Output Circuit (Figure 5)

The output circuit conforms to standard MIDI conventions as described earlier.  It is particularly important to ensure that the polarities of the voltages applied to the pins of the DIN socket are correct so that the receiving equipment will work properly.  A time delay circuit consisting of gate N2 and its associated components ensures that spurious MIDI codes are not transmitted for a short time following switch-on while the contents of the SRAM is set to the note status existing at that time. 

SRAM (Figure 4)

The static random access memory  can be virtually any SRAM chip [11].  Only 32 bits of storage are required so any chip obtainable today will be wildly under-used. 

Because most memory addresses are not used there are many unused pins not shown in Figure 4, and the actual pin connections for the 6116 chip used in the prototype were as  follows: 

6116 SRAM Connections  

Pin

1

2

3

4

5

6

7

8

9

10

11

12

Function

A7

A6

A5

A4

A3

A2

A1

A0

1/O1

I/O2

I/O3

GND

Connect to

GD

GD

GD

see cct

see cct

see cct

see cct

see cct

see cct

GD via 30k

GD via 30k

GD

 

Pin

13

14

15

16

17

18

19

20

21

22

23

24

Function

I/O4

I/O5

I/O6

I/O7

I/O8

CS

A10

OE

WE

A9

A8

Vcc

Connect to

GD via 30k

GD via 30k

GD via 30k

GD via 30k

GD via 30k

GD

GD

GD

see cct

GD

GD

+5V

 The 30k resistors are not critical and any reasonable value can be used. 

Memory Write Circuit (Figure 4)

Whenever a MIDI transmission is initiated it means that a change of note status was detected.  Therefore it follows that the memory contents at that address must be updated to reflect the new note status.  This is done after each transmission. 

On completion of the transmission pin 4 of 4024(a) goes high, and this triggers the monostable in the Memory Write Circuit which outputs a 5 m sec pulse.  This is gated with the current note status on line B, which is then written into memory because the pulse also activates the write enable (WE) pin of the SRAM.  Thus if the note is now on, a high is written to replace the previous low, and vice versa. 

Once this has been done, line X at the output of the status comparator reverts to a high state, enabling the key contact scan sequence to resume.  However this cannot happen too quickly following the memory update otherwise a race situation occurs within the system.  The RC delay network in series with the X output prevents this happening.

Constructional Notes

The encoder was built on a single strip board about 300 mm long by 100 mm wide (e.g. Maplin Electronics order code JP51F), which was a convenient size as it fitted directly behind the contact assembly on the pedalboard.  Some of the wiring was done by hand in order to fit all the chips onto the one board.  Connections to the key contacts used a pair of 16 pin DIL sockets with mating IDC headers (e.g. Maplin Electronics code JH36P).  These enabled two 16 way ribbon cables from the contacts to be connected rapidly to the unit. 

Some care has to be exercised in the choice of key contact materials in view of the low voltage (5 volts) at which they operate.  Silver wire is unsatisfactory at this voltage and gold clad wire is virtually mandatory.  Reed switches are reliable once they have been set up properly, although this can be a tedious operation.  A simple way to fit ordinary wire contact blocks and wipers to a pedalboard is to attach the contacts to a curved rail underneath the pedals, mounted at a point where the movement of the keys is about the same as that of manual keys.  This avoids having to use expensive pedal jacks at the front of the keys.  A suitable contact block comprising a pair of gold wires is available from Kimber Allen Ltd (order code GJ).  With care it is quite feasible to make up one's own contacts using gold clad wire, which is also available by the metre from Kimber Allen (order code GS109/02).  However, if this is attempted, care must be taken to prevent movement of the wires being transmitted to the soldered joints.  If this occurs the joints will fail rapidly through fatigue.  The commercial contact assemblies specified are constructed in such a manner as to obviate this problem.

Debugging

Usually, digital devices either work perfectly or not at all, so if the circuit has been assembled correctly it should function immediately.  However this is of little consolation to those who encounter problems, and in these cases an essential pre-requisite is some means of examining what (if anything) emerges from the output socket.  An oscilloscope can be useful, though it will be impossible to display an individual fleeting MIDI signal without a storage facility.  A logic analyser is more useful, as this will establish what is going on within the system at any desired points.  Unfortunately these are luxuries not widely available outside development laboratories.

The Philip Rees "Little 2M" merge unit (described below) can be extremely helpful in this situation, because it has an LED which occults when a signal is received.  More than this, the LED only flashes when the signal is a valid MIDI code.  When I had completed the prototype it did not work at first, and I restricted myself deliberately to fault-finding using only an oscilloscope and the merge unit.  I arranged for a simple external test circuit to open and close one of the key contacts repetitively at a rate of several hundred pulses per second, and monitored the output with the 'scope.  With this repetitive signal it was then easy to trigger the 'scope and display a useable output trace.  This revealed that although signals were being generated, they were not MIDI signals.  Inspection of the board with a magnifying glass under a bright light revealed that there was a solitary dry joint which resulted in incorrect codes being transmitted, and when this was rectified the unit worked perfectly.  Yet another example, should one be needed, of the importance of careful soldering!

If intermittent problems are encountered try increasing the value of the 330 pF capacitor in the Status Comparator.  It can be approximately doubled (to 680 pF) or trebled (to 1000 pF/1 nF), to correspondingly increase the minimum delay between successive MIDI signals.  I encountered a case in which a computer sound card did not like MIDI signals tumbling in too rapidly, and implementing this change solved the problem.  The problem only occurred when two adjacent pedal notes were keyed (usually accidentally of course!).  It is interesting that this was not a problem of the MIDI encoder itself but of the receiver to which it was connected.  Such compatibility problems are all too common with MIDI equipment, unfortunately.

 

Using the MIDI pedalboard

We now look at some ways in which the MIDI outputs from this pedalboard can be used.  The emphasis is on facilitating the assembly of a range of simple and inexpensive instruments for organ practice, perhaps at home, school or college.  Once you have a MIDI-capable pedalboard, it is quite possible to put together a two manual and pedal practice console for no more than a few hundred pounds.  Often it will be much less than this.

Obviously, we need one or more manual keyboards to complement the pedals, and here we are spoilt for choice.  There is an enormous range of electronic keyboards available commercially, and the biggest problem is to select with care from the bewildering array on offer.  The first point to realise is that commercial keyboards fall into two main groups: those which are capable of making sounds on their own, and those which are not.  The latter have to be connected to other equipment before sounds can be heard, and the most common choice is the ubiquitous personal computer.  Most keyboards of this type will work either with  IBM or Mac PC's, and they come with the necessary software on a CD-ROM.  Some examples of the other type of keyboard can also work in this mode, because their inbuilt sounds can be switched off.

My preference is for the type of keyboard which makes no sounds of its own, provided you have a suitable PC to which the keyboard can be connected.  Such a keyboard is marketed by Evolution as their MK-261 or MK-361 offerings (see www.evolution.co.uk ).  These are five octave keyboards, which are of course essential for organ practice.  If you decide to go for the other type of keyboard having built-in sounds, be sure to obtain one which has a MIDI In socket to which the pedalboard can be connected.

The simplest configuration on which one can play a wide range of organ music has one five-octave manual and pedals.  With the type of keyboard having built-in sounds you merely connect the output from the MIDI pedalboard encoder to its MIDI In socket, and you have an instant digital organ.  Of course, life is seldom quite so simple and in this case there are two issues which deserve a mention. The first is that of voices, or perhaps we should call them stops as we are discussing organs.  With this type of minimal "organ" there are no physical stops of course, and not much choice in the type of sounds available either.  Usually you will have to select the most suitable sounds from the 128 General MIDI "instruments" which your keyboard will undoubtedly boast.  Actually this is not so restrictive as it might appear, because there is invariably a choice of five piano sounds if you discount the honky-tonk variety, and the Grand Piano is usually an acceptable simulation of the real thing on modern keyboards.  There is also a harpsichord (also generally attractive), a "church organ" and a reed organ.  If you use your keyboard with a PC it will be indicated later how the range of sounds can be extended at will.  Unless you deliberately decide not to do so, you also need to disable the touch sensitivity of the manual keys (the keyboard handbook should show how), although it can sometimes be a salutary experience to assess your articulation, phrasing and evenness of touch by occasionally playing an "organ" whose keys are touch sensitive. 

Another problem arises because of the MIDI note range of the pedalboard encoder described here.  It can only be set to operate either from MIDI note zero or MIDI note 96.  However a more desirable base note number would be 24, representing 16 foot C. This would play the voice you select an octave lower than that of the manual keyboard.  Unfortunately it is not easy to obtain this base address using the design described above (although it could be done), and this reflects the inflexibility of a hardware rather than a software-based method of generating the MIDI messages.  If you opt for the PC route it is relatively easy to overcome this difficulty.  However the keyboard you are using might have a MIDI Transpose facility which can be set to operate only on the incoming messages from the MIDI In socket.  In this case, set the pedal encoder to operate from a base address of zero and then select an upwards shift of two octaves from the transposer.  Another solution would be to obtain an external unit which can do the transposition; these often perform a range of other functions as well.  The unit would be connected in the lead running from the output of the pedalboard encoder to the MIDI In socket of the keyboard.

Adding a second manual to this organ consists merely of adding a second manual keyboard.  It requires no connections to the other keyboard or the pedals in the simplest configuration, although this would mean that no intermanual coupling would be possible.  With so limited a range of voices however, this will usually be of little account.  

When using a PC to generate the sounds, they actually arise from the sound card or the onboard sound chip in the computer - the software provided on the CD-ROM accompanying the keyboard is able to detect automatically the type of sound hardware available, and it configures itself accordingly.  Thereafter you will be able to access at least the General MIDI set of voices, plus others as well in most cases.  We shall touch on this later.  For the present a few words are necessary on how to connect two manuals and the pedals to the single MIDI In socket of your computer (which in many cases will be the game port connector).  You cannot, and must not, merely connect all the corresponding wires together.  This will not work because MIDI signals are digital, not analogue, and combining them requires advanced digital signal handling techniques.  Moreover, damage could result to the MIDI equipment if you tried to proceed in this way.  Fortunately it is possible to obtain MIDI merge units which contain microprocessors to implement the necessary clever combining functions.  An inexpensive and extremely effective unit is the "Little 2M" by Philip Rees, which has the decided advantage of requiring no power supply because it derives its miniscule power requirement from the MIDI system it is connected to [10].  Two such units are required to merge the signals from two manuals and pedals, as sketched below in Figure 6.  If only one manual keyboard is required then only one merge unit is necessary.

Figure 6.  Achieving a 3-way MIDI merge

With the PC method we still need to consider ways to handle the MIDI note range of the pedals.  In this case it might be convenient to set the pedalboard encoder to transmit from a base note address of 96 rather than zero, as it will then not overlap the manual key range except for the top note.  Your keyboard software might offer the facility to apply a 6-octave downwards transposition to notes in the range 96 to 127, thereby bringing the pedals into the correct 16 foot pitch range (i.e. starting at MIDI note 24).  Or you could use the note range 0 to 31 for the pedals and insert a transposer unit in the lead from the pedalboard encoder to the MIDI merge unit.  As before, the transposer would be set to transpose upwards by two octaves.

Yet another suggestion is to obtain  MidiOx software (available at www.midiox.com) which can apply several useful operations to MIDI signals.  Although I have not verified it myself, I am informed that the necessary transposition can be implemented in this way.

Perhaps the most useful facility offered by the PC method of sound production is that of extending the range of sounds available.  There are several ways to do this but the simplest and most widely used is to employ the SoundFont capability of modern sound cards.  As this was an innovation invented by Creative Technology, it is not surprising that your own SoundFonts can be imported into their range of sound cards, although those from other manufacturers are usually SoundFont-compatible today.  At the time of writing the Creative Labs Audigy 2 card is the one to go for; it comes in several variants of which the cheapest retails for well under £100. ( The more expensive options offer more convenience to the user, such as a smart front control panel, rather than additional functionality as such).  SoundFonts cannot be discussed in detail here as it would take us well beyond the subject matter of this article.  However it is certainly one way to go if you want your organ to have many authentic voices rather than being limited to the range of sounds in commercial MIDI Banks such as General MIDI.  Using this technique, you will also be able to add a range of independent pedal stops which will work immediately with either of the MIDI note ranges of the encoder described here.

The image below shows an absolutely minimalist two manual and pedal home practice instrument assembled as described in the foregoing.  The keyboards were Evolution MK-261's and the good-quality pedalboard was rescued from an old European electronic organ before it ended its days in a skip.  It was of standard dimensions and of 30 notes compass. It was also flat rather than concave, offering the opportunity to practice more easily the detaché toes-only technique preferred today by many students and teachers.  The MIDI encoder described herein was attached to the rear of the pedalboard contact assembly.  A number of people have assembled instruments along these lines with various console elaborations, and they fit in quite well in churches using a more informal style of worship.  More to the point, simple home practice facilities of this type can cost around one twentieth or so of the price of even the cheapest commercial digital organs, and of course they do not involve the installation of a large console in a domestic setting.  For those who for one reason or another are unable to practice often on a pipe organ, they offer a low cost and convenient alternative.

 

 

Notes and References

1. "Basic MIDI", Paul White, Sanctuary Publishing Ltd, London 1999. ISBN 1 86074 262 9

2. “A Beginner’s Guide to MIDI”, R A Penfold, Babani Publishing Ltd, London 1993.  ISBN 0 85934 331 6

3. “Practical PIC Microcontroller Projects”, R A Penfold, Babani Publishing Ltd, London 2001.  ISBN 0 85934 444 4

4. There are proprietary variants on the GM (General MIDI) set of "instruments",  marketed by manufacturers such as Roland and Yamaha, and they have names such as GS, XG, etc.  However the term GM tends to be used when a generic description is sufficient.

5. The reason for not using matrix addressing in the prototype was to do with practical issues such as the particular form of the key contacts on the pedal board which was used for the development work – it would have required too much manual re-working of PCB’s to accommodate a matrixed approach.

6.  "PIC" has become a generic term widely used  in microprocessor circles although it refers strictly to the particular products of one manufacturer.  The term is a trademark of Microchip Technology Inc of Arizona, USA and hardly anyone seems to know or care whether it is an acronym, and if so, what it stands for.  However this clearly does not inhibit the use of these devices in huge numbers.  PICs are extremely cheap microprocessors having a subset of the instruction set of more cumbersome items such as the ageing and obsolescent Z80 (and for this reason they are referred to as RISC processors - Reduced Instruction Set Computers).  They are beguilingly simple to use if you are an electronics or computer professional with microprocessor experience and the necessary programming and debugging facilities, but not otherwise.  Hence the justification for the hardware-only approach described in this article, for which the only mandatory skill is the ability to solder.

7.  "MIDI for Organists", C E Pykett, currently on this website.  (read)

8. The statement in the text which says that nothing is transmitted down a MIDI link unless the note status changes is not always strictly correct.  Some MIDI systems continue to transmit a special type of message under quiescent conditions to indicate that the physical wire link is still intact.  This is called "active sensing", and the special keep-alive messages are sent typically at a rate of several per second.  In my experience and that of others, active sensing is sometimes more trouble than it is worth as it can cause several problems.  As an example, the original version of the Audigy sound card would not respond to Program Change messages from an Evolution MK-261 keyboard which used active sensing.  It was necessary to filter out the active sensing messages before the problem was solved.  Fortunately, the "Little 2M" MIDI merge units mentioned later in the article have an in-built filter, and interposing this unit in the lead between keyboard and computer was a simple way to remove the difficulty.  (The Audigy 2 card does not appear to have this problem).

9. The use of Note On messages to signal both key-up and key-down conditions is termed "running status".

10. Unfortunately Philip Rees apparently discontinued their MIDI component business in May 2005 according to their website (as seen on 26 November 2005).  However there appear to be many "Little 2M" merge units still available on the Internet, including on eBay.  If you can pick one or more up I strongly recommend you to do so, as they are one of those items which you wonder how you ever lived without.  Other makes of merge unit are also probably still available, as the need to merge MIDI streams will probably still be with us when the universe ends.  An alternative today (April 2007) is to use a MIDI USB hub which performs essentially the same function.

11. Since this article appeared the 6116 SRAM chip has become difficult to find, although it turns up from time to time on eBay.  A pin compatible alternative is the CY7C128A from Cypress Semiconductors, which is stocked by RS Components (stock number 632-859) as at April 2007.  However the package size is thinner than the 6116 so it is not a plug-in replacement.  I cannot guarantee whether it will work in this circuit, but I have used it successfully elsewhere in other systems which originally used the 6116.