Monday, 29 February 2016

Guitar EQ on-the-neck

We've got our guitar neck LEDs lighting up, displaying chord charts, scale patterns and more. We even have a nice swooshy rainbow effect and the ability to display play-along-tab. The entire display can be updated by sending serial data in a very simplified format (to reduce data length for faster refresh times) and it probably has a-hundred-and-one other uses we haven't even thought about yet.

One use we did think about was a volume display - like those VU diplays that were all the rage on boomboxes in the late 80s.

In super-flash versions, the EQ/VU display also had a "peak" marker, which trailed behind the actual volume/EQ bar graph. Since we already had a massive LED matrix, it was only a short while before we had a working VU meter.

During testing, we simply send a command to set the volume to a value between  0-15.

So far so good - we now had a VU meter function in our firmware which would display the VU on our guitar neck. All we needed now was to feed the guitar signal into an analogue input, convert into a 4-bit value and send that value into our function.

A guitar pickup typically outputs at around +/-100mV to +/-500mV. Some really "hot" pickups, with super-strong magnets can go as high as 1V output, but - because of the detrimental effect the magnets have on the string resonance - this is every unusual.

Typically a microcontroller, such as a PIC or an AVR, use the supply voltage as a reference for their analogue to digital modules. This means we could measure between 0V and 5V on an analogue input pin. If the guitar were to play relatively loudly, we might measure 0.5V on the input pin or 10% of the total supply voltage.

So our max range for measuring the voltage from the guitar pickups would be 0%-10% (since negative voltages would be "clipped" to zero). Which means, on a 10-bit A2D module, that normally returns 0-1023, we could expect to see values from zero to about one hundred.

This actually is almost workable for us. Let's consider what would happen if we just used our guitar output on an Arduino analogue pin, for example, Our VU meter has 15 segments, and we let's say full volume is 1V. We can expect to see analogRead values of 0-200  (since we're operating in the bottom 1/5th of the range). So at absolute full whack, we'd get an analogRead value of 200 and we'd need to convert this to a value of 15 (since our VU meter has 15 segments).

This means that each segment represents a change in the analogue input value of 200/15 = 13 (give or take a smidge). Which is fine. Except the A2D module on most microcontrollers has a degree of "drift" or an acceptable error range; if we allowed for an error of +/- 5 on the A2D, that means we've only got a few values between each step in the VU meter, It's quite possible that, even with a perfectly decaying audio signal, our meter display might fluctuate, rather than display the actual output voltage.

Our initial idea to overcome this was to use an op-amp.
This would allow us to not only increase the voltage range to feed into our analogue input, but also to "offset" it. But there is another way:  luckily, the AVR Atmega328P has an internal reference voltage. And this reference voltage is 1.1V - just about the maximum voltage we can expect from the guitar pickups. So by simply adding a single line in firmware


We can put the entire volume range onto the analogue input pin.
If we hit the strings really, really hard, and generate more than one volt, it'll cause the  display to "max out" - which would be exactly the behaviour we want!

Here's our VU meter running, with the output from a guitar going straight into an analogue input pin:

Don't you just hate videos of people playing un-powered electric guitars that are slightly out-f-tune? We hate it too.