Drum Machine prototype – schematic

I found some time to convert my hand drawn notes into a proper Eagle Cad schematic.

So here it is for your enjoyment. Eagle CAD schematic (Zipped). PNG. PDF.

The schematic is broken up into functional blocks, a couple of which are optional such as the speaker amplifier circuit, or the power supply that could be replaced by any other 3.3v source.

Here’s a quick tour of the more interesting bits of the schematic.


The PIC24hj128GP502 was chosen for it’s large program memory size (128kb) which allows for lots of samples and higher clock frequency of 40MHz which allows a higher frequency PWM output that is easier to filter. As a bonus this PIC can be programmed and debugged with either the pickit 2 or a pickit 3 via mplab or with the standalone pickit programmer tool.

I didn’t have a sample of this PIC or a pickit 3 when I started the project so I initially had it running on a PIC24FJ48GA002 which can also be programmed and debugged by the pickit 2 but doesn’t really have enough program memory to hold any samples once the main program is loaded (only 48kb).

So, as I had a sample lying around I built a version for a PIC24FJ64GA102 which has more prog-flash (64kb) but unfortunately can only be programmed via the standalone pickit 2 programmer application and can’t be debugged with a pickit 2 which was a bit of a pain.

So I decided to buy a pickit 3…
Then as I realised I needed more prog-flash I looked around other PICs that were available in the 28pin DIP package and found the PIC24hj128GP502.
I wanted to stay with the DIP package as I like the idea of the project being easy to assemble or build on a bread-board. But I must admit I am tempted by some 44 and 64 pin devices which would mean I could drop the LED driver and control the LEDs directly with the PIC.  But anyway…

The project code has defines in place to allow it to build with any of those 3 chips, just tell mplab which chip you are using and it should handle itself. But like I say the smaller chip has probably been outgrown, mostly due to adding the FAT library. You could always remove samples or reduce their length to save space. Or you could reduce the sample rate from 16khz down to 12 or 8khz to squeeze more samples in at the expense of quality.

Whilst each PIC has slightly different capabilities, and some differences in registers they should all work if you accept the limited program memory of the smaller pic.  They all share the same pin-out too barring some small differences so can be swapped in and out if you want to experiment.

Input matrix

Check out all those diodes!

This is a pretty standard circuit. It’s a 3 row by 8 column input matrix. I pull the rows low in turn and read the result on the columns.  A pressed button reads as low, an un-pressed button gets pulled high by the PICs internal pull-ups. All those diodes serve to isolate the buttons from each other so you don’t get phantom button presses. The joystick is just 5 more buttons as far as this circuit is concerned. I chose 3 by 8 as it makes scanning the input and storing it very easy as you’re always dealing with whole bytes.  I could have saved a I/O pin and gained one more button by going with 5 by 5 but that makes the software more complex. Lots more about input matrix design here.

Audio D/A output filter

This is a simple passive Low Pass Filter. It’s job is to remove the high frequency component of the PWM DAC, leaving us with just the audio frequency output. This is a really simplistic filter but actually works rather well and leaves no discernible PWM noise in the final output. My earlier prototypes using the PIC24FJ48GA002 and PIC24FJ64GA102 were limited to using a lower PWM period of 62kHz which was harder to filter and left some audible noise in the output. The PIC24hj128GP502 is a high-speed part can be run at 40MHz allowing a PWM period of 156kHz at 8bit resolution. This is much easier to filter being nearly 20 times higher than the highest frequency actually want to hear in our output and produces a much cleaner result with such a simple filter. There’s lots of really complex research and maths(PDF) surrounding the topic of filters. But in my case I stuck with some simpler examples and calculators I tried to avoid the maths… There’s a good intro to PWM by John Massa here. TI have a more detailed application note for using PWM as a DAC (PDF) on their TMS chips but the technique applies to any chip really. There’s an online filter calculator here.

LED Driver

Maxim MAX6957ANI 4-Wire-Interfaced, 2.5V to 5.5V, 20-Port LED Driver & I/O Expander

The MAX6957ANI is a really nice easy to use LED driver/ IO expander.  It’s an SPI bus part which is very handy as I was already using the SPI bus for the LCD and SD Card. Many I/O expanders seem to be i2c driven which for some reason… It comes in standard 28 pin PDIP format which is great for prototyping, but the next step down is a tiny SSOP with a 0.65mm pin pitch which is just a bit too tiny for me so I might have to look for an alternative if I want to fit all this onto Eagle CAD’s 100mm x 80mm PCB limit.

If you don’t have a MAX6957 LED driver you could always use another similar SPI driven LED driver or even a daisy-chain of standard shift registers and some resistors but you would need to write your own code for that and modify the application a little.

The speaker amplifier

TPA301 350mW mono power amplifier

The Texas TPA301 is a great little chip. It is single supply and will run happily at 3.3V.  The circuit here is pretty much straight out of the datasheet. You could leave this part out and just feed the filtered PWM Audio output via the headphone circuit into some PC speakers. Or use any other amp that you might have such as an op-amp.

The Nokia 5110 LCD

Nokia 5110 on breakout board from SparkFun

This LCD is really easy to use, it’s SPI driven and runs on almost no power if you don’t use the back-light. There’s lots of information to be found on the web. This is a really handy source of information. One great tip from that site is using a simple R/C circuit to provide the LCD with its reset signal which means one less pin to connect to the PIC.  There are lots of libraries out there, mostly for Arduino but they’re fairly easy to convert/reuse. I made my own library for the pic24 which you can download as part of the MPLABX project.  You can buy the LCD on a breakout board from lots of places, mine were from a Sparkfun distributor they cost almost nothing!

What’s left?

The remaining parts of the schematic are not particularly exciting. The PIC reset circuit is standard. The power supply circuit is straight out of the LM317 datasheet. The ISCP circuit uses the second set of ICSP pins but is otherwise nothing special. The SD card is on a breakout board and uses SPI mode. The card detect and write protect signals are not used.

I think that’s it for now.

6 thoughts on “Drum Machine prototype – schematic

  1. wow i am impressed,i have waiting for someone to do something like this.I wish i knew about pic programming.I have great ideas on making step drum machines,but lack the skills on programming.I would buy one of these.

    • Hi Pete.
      The code is available for download at the bottom of the previous post. here [https://catmacey.wordpress.com/2012/07/04/pic24-drum-machine-prototype]
      Have fun.


  2. I must say I’m quite impressed by this project,really good job!

    My question is:would it be possible to have all sound samples on the SD Card and use something like the VS1053 to decode each sample in realtime or is it needed to have the samples on the uC memory for speed reasons. I’m thinking as this as part of a drum module with built in sounds.

    Best regards!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s