Print This Post Print This Post

My New MIDI Merger uses 10 MIPS £1.00 PIC Microcontroller!

Updated 17th March 2011 (see Download section)

Completed prototype MIDI Merger/Indicator

Completed prototype MIDI Merger/Indicator

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 front panel on the prototype - I used Front Designer

The front panel on the prototype - I used 'Front Designer'

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.

MIDI Merger/Indicator Schematic using PIC 18F4320

MIDI Merger/Indicator Schematic using PIC 18F4320

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.

Component size of printed circuit board. (I mounted my LEDs on a separate board)

Component size of printed circuit board. (I mounted my LEDs on a separate board)

Printed circuit bottom foil pattern

Printed circuit bottom foil pattern

Midi Merger PCB top showing links (or top foil)

Midi Merger PCB top showing links (or top foil)

The assembled prototype, together with user-interface.

The assembled prototype, together with user-interface.

View of the unit before front panel fitted.

View of the unit before front panel fitted.

Rear view of unit showing MIDI sockets and DC power socket

Rear view of unit showing MIDI sockets and DC power socket

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.

MIDI Merger User Interface Board Schematic

MIDI Merger User Interface Board Schematic

MIDI Merger User Interface Board - component side

MIDI Merger User Interface Board - component side

The MIDI Merger User Interface foil pattern

The MIDI Merger User Interface foil pattern

The MIDI Merger User Interface links (or top foil)

The MIDI Merger User Interface links (or top foil)

Photo showing match between front panel template and User Interface board.

Photo showing match between front panel template and User Interface board.

Construction

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!

Do a little at a time, then test, then another small step, then test -you got it?

Do a little at a time, then test, then another small step, then test -you got it?

Do (only) a little more, then test again.

Do (only) a little more, then test again.

Until its nearly complete.

Until it's nearly complete.

Oh, and there’s just one more thing – always start with a clean and uncluttered work-environment!

Always start with a clean and un-cluttered work environment.

Always start with a clean and un-cluttered 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.

Waveform of MIDI sequence 0x92, 0x30, 0x7f and sample points.

Waveform of MIDI sequence 0x92, 0x30, 0x7f and sample points.

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:

Columns (inputs)
Bit3 Bit2 Bit1 Bit0
RA5 RA4 RE1 RE0
Rows (outputs)
Bit3 Bit2 Bit1 Bit0
RE2 RC2 RC1 RC0

Which are the 2 pin headers next to the oscillator crystal.

Parts List for MIDI Merger/Indicator main schematic.

Part Value
   
B1 RB1A
C1 33p
C2 33p
C3 100n
C4 100n
C5 100n
C6 100n
C7 100n
C8 100n
C9 100n
C10 100n
C11 100n
C12 100n
C13 10uF
D1 1N4148
D2 1N4148
D3 1N4148
D4 1N4148
IC1 PIC18F4320 (see text)
IC2 7805
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
LED1 LED3MM
LED2 LED3MM
LED3 LED3MM
LED4 LED3MM
LED5 LED3MM
LED6 LED3MM
LED7 LED3MM
LED8 LED3MM
LED9 LED3MM
LED10 LED3MM
LED11 LED3MM
LED12 LED3MM
LED13 LED3MM
LED14 LED3MM
LED15 LED3MM
LED16 LED3MM
LED17 LED3MM
OK1 6N138
OK2 6N138
OK3 6N138
OK4 6N138
Q1 10MHZ
R1 220
R2 220
R3 220
R4 10K
R5 220
R6 220
R7 220
R8 220
R9 220
R10 220
R11 220
R12 220
R13 220
R14 220
R15 220
R16 220
R17 220
R18 220
R19 220
R20 220
R21 220
R22 220
R23 220
R24 330
R25 330
R26 330
R27 220
R28 330
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
Copy the code below to your web site.
x 
  • Share/Bookmark
Fax Online    Send article as PDF   

1 comment to My New MIDI Merger uses 10 MIPS £1.00 PIC Microcontroller!

  • admin

    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.

You must be logged in to post a comment.