Midi and the AVR.pdf

(296 KB) Pobierz
Microsoft Word - Midi and the AVR.doc
MIDI AND THE AVR
I N T R O T O U S I N G T H E A V R I N M I D I A P P L I C A T I O N S
PAUL M ADD OX
MARCH 2002
306548964.002.png
TABLE OF CONTENTS
Introduction .............................................................................................................................................2
MIDI, what is it? ......................................................................................................................................2
MIDI specs, a quick guide .....................................................................................................................3
MIDI; the hardware.................................................................................................................................4
MIDI gotcha's..........................................................................................................................................7
MIDI to CV conversion; a quick project ..............................................................................................10
Useful links ...........................................................................................................................................11
INTRO USING THE AVR IN MIDI APPLICATIONS, PAUL MADDOX - AVRFREAKS.NET
1
Introduction
This guide is intended to help you on the way to useing MIDI with the AVR range
of processors, explaining the concepts and protocols used to some of the gotchas
and common problems people face. Where possible I've tried to kept the guide as
processor independant as possible.
Assumptions
You need a certain amount of knowledge about serial communication, not much,
but a few basic concepts. Also a little understanding of the hardware involved,
AVR, opto-isolators, etc. Also a basic knowledge of what a MIDI system is, e.g.
Sequencer, synthesiser modules, keyboards.
Who is this bean?
My name is Paul Maddox and I'm a keen electronic/synth/micro enthusiast. That
is to say I do this for fun, not for a living, you can see my web site here
www.wavesynth.com as you can see from the site its a fairly major part of my
life. I wrote this as a guide to get people into useing AVRs for MIDI, Something
that very few people seem to use them for, perhaps they dont know how to? If
not, this will hopefully explain it.
MIDI, what is it?
So, what's all about?
A few years back, quite a few actually, people could see the need for a common
standard for communication between synthesizers. Many manufacturers had their
own standards (V/hz, V/Oct, DCB, PPG BUS, etc) none of which were easily
convertable to communicate with each other. With the increase of sequencers and
affordable computers it was decided to got for a digital system, offering better
accuracy and precision than the tradional CV/Gate type of interface. The standard
they decided on was called MIDI and it stands for 'Musical Instrument Digital
interface'. A webpage published by the organisation that was formed to control
the standard is available at Http://www.MIDI.org/ and is a very useful resource
for anything relating to MIDI.
There are two parts of the MIDI system to consider, the hardware interface and
the protocol used. The main bulk of the issues and problems with useing MIDI are
to related to the protocol, so this document focuses mostly on this, though the
hardware is mentioned.
Protocol
The MIDI system is based on the concept of the user being a keyboard player,
rather than say a wind instrument or guitar payer. In its simplest form MIDI is
the means by which note information is sent, e.g. when a 'key' on the keyboard is
pressed. The type of information that is sent is event information and not audio.
That is to say MIDI is used to describe when a note is pressed, which note it is,
how hard and for how long, but not the sound that is created by this action. MIDI
is also used for a whole host of other events, but the action of pressing a note is
the simplist to describe and emphasise the point at hand. The other thing to note
is that MIDI is a serial data stream and runs at 31250 baud.
Hardware
This is the physical means of connection. Data is sent via a current loop, and
INTRO USING THE AVR IN MIDI APPLICATIONS, PAUL MADDOX - AVRFREAKS.NET
2
therefore there is no electrical connection between one unit and another via the
midi cable. This prevents Ground loops and removes any chance of hum on the
output of the device. MIDI is a point to point method of connection, ie you can
only connect one device to one other. This can be increased with the use of a
MIDI thru box, which is explained later.
MIDI specs, a quick guide
This section will deal with the protocol standard and explain some of the problems
commonly encountered whilst developing MIDI interfaces.
A 'standard' MIDI word consists of three bytes, though depending on use it may
have more or less, generally though. the first is a Status byte, the second and
third are databytes .
So, with a stream of data comming in, how do you know which byte is which? and
which byte is for you? lets take the action of pressing a NOTE on the keyboard,
this is called a Note Event . Three bytes are sent; NOTE_ON , NOTE, VELOCITY
if we asssume we're working on Midi Channel one the data would look something
like this
0x90, 0x3C, 0x7F
lets go through the bytes one at a time.. first the statusbyte, 0x90 if we translate
this into binary we get ;- 10010000 The upper nybble (1001) shows we have a
NOTE_ON event, the lower nybble (0000) is the MIDI channel, MIDI device can
have a channel number between 1 and 16, because People work better with
numbers starting at 1 rather than 0, so simply subtract one from the channel
number to get the expected value here, e.g. if we wanted MIDI channel 8 we
would expect to see 0111 (7). The next byte is the NOTE value, in this case 0x3C
which is note 60, which is in fact middle C. The final byte is 0x7F , which is the
velocity ie how hard the key was pressed, in this case maximum.
Now, many of you will have noticed that I said the maximum velocity was 0x7F,
which in binary is 01111111. But surely, you ask, isnt the maximum 0xFF ie
11111111? The answer is not for MIDI, a Status byte is defined by the fact that it
has the MSB set, all other bytes that are data must NOT have the MSB set, so the
valid range is 0-127 for any data. This may seem very limiting at first but given
that this gives nearly 12 octaves of note data and also given that very few people
can press a note with an accuracy approaching seven bits, its not as bad as it
may seem. Remember we're just sending note information, not audio, so
resoloution isnt so much of an issue. This gives us the added advantage that
status byte are easily seperated from data bytes, how? Easy all status bytes have
the MSB set to 1, all data bytes have it set to 0. You can see this in the table
below.
So here is a list of the basic commands, first column is the Status byte, second
coloumn is the second byte and what it relates to,third coloumn the same,
thirdbyte and what its use is. The fourth column is a description.
STATUS
2nd Byte
3rd Byte
Description
1000cccc 0nnnnnnn
0vvvvvvv
Note off,'cccc' is channel, 'nnnnnnn' note
value''vvvvvvv' is velocity value
1001cccc 0nnnnnnn
0vvvvvvv
Note on, 'cccc' is channel, 'nnnnnnn' note
value''vvvvvvv' is velocity value
1011cccc 0nnnnnnn
0vvvvvvv
Control Change, 'cccc' is channel,'nnnnnnn' is
Controller Number,'vvvvvvv' is value
INTRO USING THE AVR IN MIDI APPLICATIONS, PAUL MADDOX - AVRFREAKS.NET
3
306548964.003.png 306548964.004.png
1110cccc 0LLLLLLL 0mmmmmmm
Pitch Wheel Change,'cccc' is channel, 'LLLLLLL' is LSB
of value 'mmmmmmm' is MSB of valuecenter (no pitch
change) is 0x2000
MIDI Clock pulse, 24 pulses per quarternote, 96 to the
bar (assuming 4/4 time)
11111000
none
none
11111010
none
none
Start,sent at start of sequence, followed by MIDI clock
pulses
11111011
none
none
Continue,sequence carries on from where it was
stopped
11111100
none
none
Stop,sent when sequence is stopped
11111110
none
none
Active sensing
This is a brief (very brief) list of the events, these are the events you will see
most of when useing MIDI data, there are more and there are some odd quirks
which I will explain. I've also shown some of the MIDI status bytes that are only
one byte long. MIDI clock for example, this ensures that if you have, say, a drum
machine and sequencer that they stay in time with each other. active sensing is
mentioned in the 'gotcha's' section of this guide, but its one you will see a lot of,
so its in this list. a full list of Status bytes and message can be found on the
midi.org page ;-) http://www.midi.org/about-midi/table1.htm
MIDI; the hardware
So, why use the AVR for MIDI?
Why not use any of the many other micros available?
There are some good solid reasons for my choice (and many others) of the AVR
when useing MIDI. Firstly, it has a built HARDWARE UART, this means no messing
with 'bit bashing' and constantly reading ports. Secondly, it's interupt driven! This
means the AVR can be doing other things, and not worry about MIDI data until it
arrives. Thirdly, it's quick! At 8MHz (on an 8515 for example) you can get nearly
8 MIPs. Processing of MIDI data can get quite complex, and with a large system
you can have an almost constant stream of data to work with, so it needs to be
quick and decide which bytes it wants to use and which it does not care about
(data on other channels for example).
Below is a schematic showing how to connect the AVR to various MIDI ports.
INTRO USING THE AVR IN MIDI APPLICATIONS, PAUL MADDOX - AVRFREAKS.NET
4
306548964.005.png 306548964.001.png
Zgłoś jeśli naruszono regulamin