One of the many reasons I ❤ PSoC!

GangedHWIO

This is a screen shot from the schematic editor inside of Cypress’ PSoC Creator IDE showing the hardware SPI block I’ve added for controlling a cool little OLED display.  Keep in mind, that everything you see here on this schematic is inside the chip.

I’m currently prototyping a design for a MIDI electronic drum interface on a breadboard and was having trouble getting a reliable SPI clock from the PSoC5 Prototyping Kit to the display due to the capacitance of the solderless breadboard.  PSoC came to the rescue with it’s internal FPGA-like logic and routing that let me connect the hardware SPI block’s clock directly to three GPIO pins and gang all of them together to give me the drive strength needed to get a more reliable clock at 50% higher speed than I could with a single GPIO.

With most other micros I would have had to slow the display way down, abandon the HW SPI and switch to a software SPI implementation, or rig up some external drive circuit with parts I didn’t have handy.  Instead it became a 10 minute hack to get me back to working on the real design.

Advertisements

Electronic Drum Interface – Part 1

Much to my lovely wife’s chagrin, an electronic drum set has found it’s way into our house.  It’s just a basic Alesis Nitro set but it’s a great set to start out on without breaking the bank.  Top of the line e-drums can run several thousand dollars, but after a bit of research, I think I can build a great hobbiest upgrade for FAR less than that.

There are basically three pieces to an electronic drum set:

  1. The drum pads or triggers that you hit with the drum sticks.
  2. The drum interface that gets the signal out of the triggers and detects which pad you hit and how hard
  3. The sound module that turns the numbers from the interface into sounds you can hear.

Most e-drum sets combine 2&3 into one unit called a drum module for convenience, however it’s fairly common to skip the built in sound module and instead use a computer to produce better sounds. For my setup I’m going to use an old laptop that will take in MIDI data over USB and produce the sounds using off-the shelf software.

My goal is to be able to build my own drum pads, but to do that I need an interface to sit between them and the computer.  Higher end drum modules have enough adjustments that you can tailor them to work well with DIY triggers, however I’m not confident I can get that working with the Nitro module, and if I were to fry it, there would be tears from the girls.  So I’m going to start by building a drum interface.

trigger_osc

When you hit a drum trigger you get a signal out that looks something like that.  The height of the biggest peak changes with how hard you hit the pad, so the trick is to capture the height of that peak accurately.  I could try and measure the signal directly, but a micro-controller can only sample every so often and that signal is fast, so its easy to miss the peak sometimes and catch it other times.  I’d end up with the same hit on the pad sometimes being loud and sometimes soft.  The faster you measure the signal, the more accurate it’ll be, but that micro-controller can only read so fast and needs to take turns measuring all the pads.  So what I need is a way to capture that peak value and hang on to it long enough for the micro-controller to come around and measure it.

I’ve also got to deal with the high AC voltage that comes out of the piezo sensor typically used in drum triggers.  This signal can easily swing -40V to +40V but the micro can only handle 0V to +5V.

This is the circuit I’ve put together to take the signal from the trigger and condition it for a micro-controller.  V5 simulates the 30V AC output of a trigger and V4 provides the simulated voltage everything runs on.  R12 & R11 are two halves of a potentiometer which is basically an adjustable divider for the voltage out of the trigger to get it down to the range the rest of the system can handle.  Currently it’s modeled at 1:10 ratio, so the 30V AC turns into 3V AC.  In the waveform, you can see the blue input from the trigger.

TriggerCircut

Next up, C3 and R9 keep any DC offset from sneaking through.  D4 is a diode that chops off the negative half of the 3V AC wave leaving only the positive peaks.  Since it’s only the height of the first peak we want to measure, losing the negative peaks isn’t a problem.  In the waveform, you can see the input from the trigger (blue) getting scaled down and chopped to produce the signal for the op-amp (red).

Now we get to the interesting bits.  U1 is a basic op-amp that together with R13, R14, D3 and C4 form a peak detector.  The output of this circuit at Out (green) will grow as long as the input from the trigger (red) is growing.  The divider formed by R13 and R14 mean the output (green) is 2x the opamp input (red).  Because D3 forms a one-way valve and the op-amp can’t discharge C4, as soon as the trigger reaches it’s peak, the output (green) will stop changing and hold it’s value even when the trigger goes back to zero.  This is exactly what we need to hold on to that peak value long enough to measure it!  R10 is a big resistor that is just there so that C4 will eventually discharge; it needs to be large so that the peak value stays around long enough to get measured.

PeakDetect

The last circuit of V6, R15, R16, Q3, and Q4 are just there for the simulation.  They act like the pin on the microcontroller driving Out back to zero to quickly discharge C4 after the measurement and resetting the peak detect circuit for the next hit.

TriggerRst

So far this has all been in simulation using the free version of LTSpice.  Next time I’ll build the circuit up and see how it works in the real world.