![]() |
|
Circuit design and electronicsI completed a 2-part assignment for this week. The first part was to build a sorta-random sound generator based on a schematic that Joe Paradiso made available. The second part was to build a circuit that could transmit MIDI messages - this will go towards my final project.Sound generatorThe description for this assignment is here.Electronics knowledge base from 2001 can be found here.
PDF of the circuit diagram Midi OutputMidi output (and probably input) is going to be important to my final project. For this reason I've decided that one important step between now and completing my final project is to learn how to emit (and receive) MIDI messages from a PIC. I've found several resources online that give directions on how this can be done. Here are several of the more useful ones:
So if I wanted to transmit the number 144 (this is the code for a NOTE-ON in MIDI), the bit-pattern would be:
what I want to tranmit: 10010000 I was doing some testing while I developed my circuit, and I was sending the following bytes down the MIDI line: 144 144 144 This sequence caused me a lot of headache, because I didn't realize for the longest time that IT'S NOT VALID MIDI. It's three control bytes in a row and no data bytes. So even when I had the hardward constructed correctly, the computer was still not registering any MIDI messages coming through. Be careful of that. Read my notes from this testing session here (note that in Hexidecimal format, 144 is 0x90) Since MIDI is really just serial data, it's pretty easy (in theory) to transmit it, since many microcontroller development languages have routines for transmitting and receiving serial built-in. The signaling in MIDI is based on current rather than voltage though, which means that in order to transmit a message, you have to have a certain amount of current flowing through the circuit. For longer MIDI cables, you'll need more current pushing through the circuit. Resting state on the line is when no current is flowing. This is actually a logical 1. So I think about it like this:
Note: my connection of +5v to pin 5 and the pin on my microcontroller to pin 4 is backwards from just about every diagram I've seen online. I can only imagine that they are thinking about the connector reversed from the way I'm thinking about it. If you want to use my diagram, think about my connector numbering as if you're looking at a frontal view of the female connector. So, I noted the following things about my setup (and using the rs232-sending routines in the CSC C compiler environment for the PIC):
- see http://www.camiresearch.com/Data_Com_Basics/RS232_standard.html The MAXIM MAX233 chip converts between "TTL levels" (0 to +5 volts) of the PIC and "RS232 levels" (+9 to -9 volts) of the serial line. The magic of the MAXIM chip is that it does this conversion with a single +5 V supply; oscillators and charge pumps internal to the chip generate the required + and - 9 volts.
Here's the diagram for another circuit that can probably push more
current through the wires, for longer distances: You can download a sample .c file (for the CCS PIC C compiler) here which shows how to transmit MIDI from pin B0 of a PIC microcontroller (used in conjunction with my handdrawn wiring diagram above, implemented on an IRX board) Craig Sapp also has some good diagrams about this:
Midi InputI'm still working on getting MIDI input working. One word of wisdom is that it's nice to have a chip that has an onboard UART (Universal Asynchronous Receiver Tranismitter). Sometimes they are called USART's too (add "Synchronous" to the acronym). Having a UART onboard allows the microcontroller to hand off the task of transmitting and receiving serial data to some dedicated hardware, rather than having to do all of the signalling and receiving in software (which ties up the chip's resources that could be in use for other things). The Asynchronous part is key - it means that in receiving the chip will take in several messages and buffer them before needing the attention of the rest of the chip. (For instance, in the PIC16F876 the USART can have received 2 bytes and be in the process of receiving a third all at the same time). However, that third byte will be dropped if neither of the buffered bytes have been read by the time it's fully in. |