MIDI -- Input Demo


In this exercise, we get to see how to act upon incoming MIDI messages. For the demo, I have the PIC looking specifically for MIDI Stop, Continue and Start commands. A red, yellow or green LED is lit to indicate such, respectively. All other MIDI bytes are ignored.

The PIC configuration, both software and hardware, is rather interesting. First, here's the schematic:


As is usual for most MIDI circuits, a 6N138 optocoupler is used to isolate the bus current loop from the microcontroller. Notice how the optocoupler output feeds both the hardware serial input Port B.2 (pin 8 of the PIC), as well as the PIC's analog comparator input at pin 18. Thus, whenever MIDI bytes are flowing, the PIC's comparator is tripped via an interrupt, alerting it that the incoming message should be stored in the circular queue. Incidentally, R5 and R6 set the comparator threshold at 2.5V.

So, from the software side of things, you'll get to see how to configure the analog comparator, how to act upon interrupts, and how to implement a circular queue. Read over the source code carefully which is remarkably simple given all this activity.

I tested the unit using MIDI-OX, referred to in the previous exercise. Here's a screen shot of it in operation:


Clicking on the "play" button sends a MIDI Start code, illuminating the green LED. Clicking the "pause" button sends a Stop code, lighting the red LED. And clicking "play" again, sends the Continue command and lights the yellow LED. Clicking the "rewind" button resets the Start/Stop/Continue sequence.

Click to get the source code.
Click to get the schematic PDF.

Next Project: MIDI to Analog Synth

No comments:

Post a Comment