a PIC16F648A with associated crystal, SRAM,
optocoupler input, and double-inverter output (or
equivalent).
The PIC16F648A
MIDI Controller — A
Very Demanding Boss
This chip has a very difficult job to do and
needs to work like greased lightning. Figure 11
provides an overview. In many systems, you would
expect the user interface to be the master, but
here this MIDI controller chip is the ‘boss’ out of
necessity.
The USART (Universal Asynchronous Receiver-Transmitter) receives and transmits MIDI data via
FIFO (First in First Out) buffers in internal RAM.
The ISR (Interrupt Service Routine) handles the
reading and writing to the buffers. Separate to this
is the main program loop that runs a variety of
tasks.
The thing that matters above all else in
our system is that we must never ever lose any
received data. The PIC16F648A has a one byte
receive register in the USART that receives the
MIDI data. As soon as this is filled, the byte must
be transferred to the receive buffer in RAM.
Otherwise, it will be overwritten.
Another essential is that any note messages are
handled accurately and promptly. If they are being
recorded, then they must be time-stamped ideally
within 10 milliseconds of the ‘real’ time to maintain
accuracy. If they are output (either echoed from
the input or played back from recorded data), this
must be fast to avoid noticeable delay. Technically
speaking, there’s a need for low jitter and low
latency.
All code has been carefully crafted and all
unnecessary steps eliminated while keeping overall
functionality. The ‘Pro’ (paid monthly) version of
compiler-optimization is used in MPLAB to ensure
maximum speed (and minimum code size). Tricks
such as bit-shifting instead of slower multiply
have been used. The PIC16F648A is driven at its
maximum operating frequency of 20 MHz.
It was decided to write all software in fully-optimized
C without any handwritten assembler. This was purely a
practical decision, realizing that highly optimized code can
still be extremely fast and much easier to write.
The MIDI protocol has a trick up its sleeve called
running status that lets you only send a status byte when
the status changes from the previous message. This means
that, for example, you can send a string of ‘note on’
messages but only send one status message to indicate
they are of type ‘note on.’ Running status can reduce note
data by a third, so is fully utilized in this design.
The MIDI controller PIC not only processes MIDI
messages, but also applies the logic of transposing,
tempo management, and playable ranges. It adjusts
recorded tempo using a timer1 pre-scalar lookup, plus
it communicates data with SRAM and interfaces to the
other microcontrollers! Because this chip is so busy and
Resources
History of multi-track recording
https://en.wikipedia.org/wiki/History_of_multitrack_recording
Bruce Springsteen’s Nebraska albums made on a four-track
Portastudio
http://tascam.com/news/display/226
Wiki’s comprehensive summary of MIDI
https://en.wikipedia.org/wiki/MIDI
SparkFun’s very readable summary of MIDI
https://learn.sparkfun.com/tutorials/midi-tutorial/all
Harmony Central’s fascinating history of MIDI
www.harmonycentral.com/articles/a-brief-history-of-midi
The MIDI Association’s summary of MIDI messages
https://www.midi.org/specifications-old/item/table-1-summary-of-
midi-message
A review of embedded scheduling techniques
https://www.embeddedrelated.com/showarticle/969.php
A general overview of memory management
https://en.wikipedia.org/wiki/Memory_management
A nice explanation of interfaces and ‘encapsulation’ that can be an
analogy of MIDI talking to all sorts of devices
www.eeng.dcu.ie/~ee553/ee402notes/html/ch01s04.html
Kaiser Chiefs MIDI Tech tells of ‘MIDI Madness’ during live
performance (at end of article)
https://www.soundonsound.com/people/roger-lyons-kaiser-chiefs-midi-tech
Hitachi HD44780 LCD controller
https://en.wikipedia.org/wiki/Hitachi_HD44780_LCD_controller
Overview of scheduling techniques
https://www.embeddedrelated.com/showarticle/969.php
Parallel and distributed computing
https://en.wikipedia.org/wiki/Distributed_computing#Parallel_and_
distributed_computing
A Statistical Response-Time Analysis of Real Time Embedded
Systems
https://ieeexplore.ieee.org/document/6424817
September/October 2018 31