Updated 17th March 2011 (see Download section)
This unit provides 4 autonomous MIDI inputs and 1 MIDI output. Note this is a ‘proper’ MIDI Merger – all 4 MIDI inputs can be used at the same time, unlike other ‘designs’. The unit also provides an indication of the channel number being played, and has shown itself to be capable of expansion into a full-blown controller.
The PIC microcontroller I used – 18F4320 was being sold off cheap, at £1.00 each by Crownhill Associates, in Ely – but don’t pester them for any 18F4320’s at this give-away price, as I bought the rest of their stock!
It’s always worthwhile to take a glance at their website, as inevitably they have PICs at discounts you wouldn’t find anywhere else. A purchase I made this week, was 5 PIC18F6620s – a 64-pin TQFP monster PIC – at only £2.00 per pop!
The intention here is to provide details of the schematic and photographs/advice on construction. The PIC code will be discussed more fully on http://picprojects.info.(shortly) All source-code is provided in this post, together with Eagle project files for the printed circuit boards.
The schematic is below. Apart from the PIC and it’s crystal, the other main components are 4 6N138 opto-isolators, 5 on-board DIN sockets, a voltage regulator, and a few resistors. I mounted the LEDs on a separate interface/indicator board, and the schematic for this is shown later. The handful of pin headers are used to add a key matrix and FTDI USB-TTL lead, for upgrading the software, using an internal bootloader.
Following are some views of the PCB. Note these are not all to the same scale. The complete Eagle project for the PCB is available for download.
As shown in the main schematic, the unit functions as a MIDI-Merger and Indicator. With the addition of a keypad, extensions to this are easily added. I added the following, mainly because I find them useful.
- MIDI Minimum volume (set on a channel-by-channel basis)
- MIDI Channel re-assign – Re-assign any MIDI Channel to another
- Filter-out unwanted MIDI commands – Get rid of those pesky pitch-wheel messages from your MIDI Guitar Unit!
The front panel I have shown above – I created a separate user-interface board that incorporated a 16-key matrix, and duplicated the reset switch and LEDs.
The 4 resistors are 10K in value and the capacitor is 100nF. I used small TACT switches and extra-bright 3mm LED’s. I used 2- double-row pin headers to connect everything to the main board.
I’m going to be bold here and tell you to forget buidling electronics in the way that instructions are given with a self-build electronics kit – you know the ones that start by telling you to stuff the board in the strict order: Diodes, Resistors, Pin Headers, Capacitors, blah blah. You will no doubt have experienced disappointment when the gizmo didn’t work, and there followed a long tedious trail of fault-finding.
My method of constructing Microcontroller projects was borne out of the experience of developing both the schematic and the software, making fault-finding a complete nightmare unless a simple procedure is followed – iterative development, or if you prefer it creep before you walk.
Take a look at the photo below – yeah there ain’t much on the board yet – but we know the PIC is working, because we’ve made an LED light up with it. Take a look at the ‘main’ procedure in any of my software and you will find a simple LED turn-on, just to give me confidence that the oscillator is working – (crystals can be destroyed with excessive heat when you solder them) and my program works.
But even before we get here, you should have buzzed out every pin on the PIC socket to it’s neighbour, looking for shorts, then switched on the unit with only the regulator installed, and tested that you get 5 volts where it should be and nowhere else.
Note too, that I’ve connected up an FTDI USB-TTL cable to the main UART on the PIC. The 1st thing I always program onto my PIC’s is a bootloader, and that will be sufficient for you to test that the PIC is working and load up your ‘real’ software when you are ready.
Add components in a logical sequence – functionality is the key. In the case of this board, adding a MIDI input stages components, buzzing for shorts then live test is the order of the day, before moving on to the next.
Also, if you have the bootloader installed, and the board connected to your development PC, if there are problems, comment-in/out relevant sections of code to ascertain that your hardware is working. The flash memory is good for 10,000 updates – I promise you, you won’t need this many!
Oh, and there’s just one more thing – always start with a clean and uncluttered work-environment!
Below, I’ve posted an annotated waveform captured from the Merger whilst it was being developed. The Blue trace was captured with one probe of the ’scope on the collector of the opto-isolator darlington transistor. The red trace was generated by my code and was captured on PortB, bit 7.
BTW The picture is dumped direct from the PicoScope program. I annotated it using the excellent (and free) PhotoImpact 12, from ULEAD.
Also interesting is that the complete Note-On 3-byte sequence has been transmitted and received within 1ms – a credit to the UART on my keyboard (built in 2004 using a PIC16F876A), and the excellent response time of the INT0 edge interrupt on the 18F4320.
At the end of this post, I’ve given the part list for the main schematic generated from the Eagle project. A similar list can be generated for the User Interface board, so I won’t repeat this exercise. All parts, apart from the PIC, but including suitable PCB stock, are available from my favourite (and incredibly handy) electronics stockists ESR. Their prices are reasonable, there is no minimum quantity restrictions and they will deliver anywhere in the world. Their website is here: http://www.esr.co.uk
FTDI Shop sell the USB-TTL cables I use for uploading code to the PIC (and using TinyBld, debugging the code) These are available here: http://apple.clickandbuild.com/cnb/shop/ftdichip?op=catalogue-products-null&prodCategoryID=105&title=USB-TTL+0.1%94+Socket
Note that you should purchase the 5 volt version. (unless you are using the 3V3 low-power PIC)
The TinyBld PC PIC Bootloader is available free at: http://www.etc.ugal.ro/cchiculita/software/picbootloader.htm
and I’ve provided a modified Tinybld source file and MPLAB project specifically for this project as a zip here: TinyBld for PIC18F4320
Update: 9th August 2010: Added example Synth EDIT commands as follows: Program Change, SYSEX Select XG Mode, XG Bank Select
(see source-code for details of syntax etc.)
Important! Update 17th March 2011 The previously listed source code had the Watchdog Timer pragma set to ON, which was wrong! I apologize unreservedly for this, and extend a special apology and grateful thanks to Geert Boer for spotting my mistake. The WDT pragma in the bootloader Tinybld18f4320.zip above is correct.
Release3 Source and project file are here: http://joebrown.org.uk/images/MIDI Merger/NewMIDIMergerRel3.zip
The Eagle Project Files are here: MIDI Merger PCB Files
and I will post and date updates as they happen. Note you will need the C18 Microchip compiler to build the project. The free student version is perfectly adequate for this. The compiled hex file is included for those simply wishing to instal the firmware.
The source-code, with special emphasis on the implementation of the interrupt-driven software UARTs, will be discussed more fully at http://picprojects.info This will be done shortly.
The Front Designer project file is zipped here: Front Panel For MIDI Merger
An annotated hi-res Interface schematic is here: http://picprojects.info//MidiMergerInterface_Annotated.PNG showing links to port pins and resistors on the main board.
On this (and in the source-code) you will see that I have interfaced the key matrix as follows:
Which are the 2 pin headers next to the oscillator crystal.
Parts List for MIDI Merger/Indicator main schematic.
|IC1||PIC18F4320 (see text)|
|J1||2-pin 0.1″ pin header|
|J2||2-pin 0.1″ pin header|
|J3||2-pin 0.1″ pin header|
|J4||DCJ0202 DC power socket PCB mounting|
|S2||Small TACT switch|
|SV1||MA05-1 5-pin 0.1″ pin-header|
|SV3||MA04-1 4-pin 0.1″ pin-header|
|SV4||MA04-1 4-pin 0.1″ pin-header|
|SV6||MA05-1 5-pin 0.1″ pin-header|
|SV7||MA06-1 6-pin 0.1″ pin-header|
|SV9||MA03-1 3-pin 0.1″ pin-header|
|X1||MAB5SH PCB DIN Socket 5-pin 180degs|
|X2||MAB5SH PCB DIN Socket 5-pin 180degs|
|X3||MAB5SH PCB DIN Socket 5-pin 180degs|
|X4||MAB5SH PCB DIN Socket 5-pin 180degs|
|X5||MAB5SH PCB DIN Socket 5-pin 180degs|