Tuesday, August 12, 2014

Virtual Whammy Bar Part 4

I would like to quickly go over the power supply section. Though not shown on our basic layout, we have one, and it's a given that any project will need to consider how power will get to the circuit.
Didn't do anything special here, just a plain 7805 linear regulator. Almost straight off the datasheet. Again, used caps I had available. As an aside, my GND's aren't really grounds, but commons. The GND symbol is just really easy to grab in the schematic editor I'm using, and I figure we all understand functionally what is going on. But I didn't really want to talk about how this circuit is designed so much as I did the ramifications of the circuit.
Linear regulators are simply inefficient. In this setup using a 9V battery, 4V have to be dropped across the regulator in order to produce the 5V output (I am assuming an ideal battery for the sake of discussion). At the same time, the rest of the circuit for the project is going to need what current it needs. Knowing that Power = Volts x Amps, we can see that about 44% of the power delivered by the battery is dissipated across the regulator as heat for any given current draw. So 56% efficiency. Ouch. My initial design for the whole project only drew about 70mA, which I thought was pretty decent. But a quick search of the internet revealed that a typical 9V battery has around 565mAh (milli-amp hours) of life. My device would drain the battery in only 8 hours!
This is where switching regulators become really nice. Some are drop in replacements, and others require a few external components, but all are still simple enough to work with. And with efficiencies north of 90%, they are a very attractive option. Lets consider our 9V battery in terms of mWh instead of mAh. That means we have 5085mWh of life in the battery. Multiply by the 56% efficiency of the linear regulator and we have only 2848mWh remaining to power the circuit. The circuit itself draws 350mW. Again doing the math we see 8 hours of life. Let's consider a 91% efficiency switch regulator now. Only 9% of the power is lost regulating, leaving us with 4627mWh. Now the device can last 13 hours! Not great but still better.
At the end of the day what I really did was make the whole circuit more efficient. This was done through a combination of selecting better resistor values, and writing code to turn things on and off as needed to save on idle power draw. After several iterations of changes the current draw was reduced to <10mA. Now I could operate the device for at least 56 hours (again, ideally). I could take it a step further and add a switching regulator to eclipse 90 hours, but guess what? I don't have one of those lying around.....

Virtual Whammy Bar Part 3

Alright, which section to figure out first? How about the sensor? If that doesn't work, the rest of the project is a bit of a moot point. It would just be cart without the horse.... or some other idiom.
My initial plan was to use some kind of capacitive sensor that would simply be a metal plate mounted to the body of the guitar. As a matter of fact, the idea of a capacitive sensor was what started this whole project. I don't exactly recall what got me started on it, I just thought it was a cool idea in need of a application.
So one afternoon I soldered a lead to a small piece of copper clad board about 2" x 2", added a few components, hooked up the probe scopes and started waving my hand about. And I really didn't get far. Couldn't really detect any affects on transients without physically touching the pad. After a host of small modifications and trying different things I decided this needed a little more research. Perhaps I'll get around to giving the idea more serious time in the future. And I'm pretty sure there are IC's I can buy for this purpose with app notes.
With the not so successful capacitive test I let the project sit for a little while. Then one day at RadioShack looking for a relay for my car's power antenna I spied an IR LED and detector combo. The photodetector option was one I had considered, but I had convinced myself not to go down that road. But I decided to part with my $2 (which was way overpriced of course) and shoved them in a drawer at home.
Eventually I got around to playing with the photodetector(PH1) and it was a pretty simple design process. Now I really didn't know anything about using a photodetector as I had never used one before, so it was off to the internets to do a little research (also note that as a Radioshack part, there was little info about the part). Many designs I found admittedly I didn't fully understand at the time, but it became apparent how the device could be used. So the trick was to reverse bias it in series with a resistor(R16) and think of the detector as a sort of light controlled pot or light controlled BJT... or something. For the initial tests I slapped probably a 1K or 10K resistor on the breadboard and fed it to an op-amp buffer circuit using an MCP601 ( a part I had lying around). Oh wait, I still need an IR source.
Luckily, the packaging for the parts did include some maximum ratings. The emitter(D1) had a peak forward current rating of 150mA and a typical forward voltage drop of 1.3V. This we can work with using Ohm's Law:
Plugging in the numbers, assuming Vcc = 5V, we roughly get R17 = 25Ω. Well I have 100Ω handy. And besides, we don't need to be redlining the little guy. We'll have a forward current of only 37mA, but that'll be plenty. Now it is time to build and test.
Success! Not perfect operation, but I was able to observe a small voltage swing on the output as I moved my had closer and further from the diodes. I did try inserting an object in between the diode lenses which had no effect so long as they were pointing in roughly the same direction. And according to the packaging, that should be the case as the detector only has an angle of sensitivity of 20 degrees. So about that small voltage swing? Easy, just put a larger resistor in series with the detector. Since the photodetector is going to allow a current to flow, the voltage seen at the input of the op-amp is going to be that current multiplied by the resistor. Bigger resistor, bigger voltage. I did have to try a few values before settling on the 1MΩ you see in the schematic. Now I could detect my hand from about 1 to 10 inches away.
Up to now, I've been quiet about Q3 and the Zero setting pot(R1). That is because these guys came into play after the whole design was done and working. For the time being, I'm just going to tell you that Q3 was added to turn the LED on only when needed in order to save power.
The potentiometer on the other hand, was somewhat of a design necessity. I did this little project over the course of a few days, sometimes working in the afternoon, and sometimes in the evening. In the afternoon everything worked great, the detector output was stable and repeatable. In the evening though, I was getting fluttering values when nothing was present above the detector. As it turned out, the lamp on the hutch above my desk was emitting enough IR and/or near IR light to introduce a sort of noise. If you look at a datasheet for a photodetector, you will see they have a peak sensitivity to a certain wavelength of light. However, they will have diminishing sensitivity to the surrounding wavelengths on either side of the peak. My lamp, producing both heat and light, was definitely polluting my results.
A feature of any ADC is that you can set the lower and upper voltage references to scale the conversion. In this case using the 10-bit ADC on the the PIC16F916, I had 1024 bits of resolution. But those 1024 bits could mean 0-5V, or 1-2V, or 2-5V, all depending on the reference voltages used by the ADC. I simply used the 5V supply as the upper reference, then added the pot to set the lower reference. So when my lamp is producing, say 600mV of noise, I set my pot for 700mV at the wiper. Now the ADC won't output a number above 0 until I move hand close enough to overcome the 700mV threshold. In practice you need not know the actual voltages, just trim until the detector appears to stop detecting (it doesn't, but the microcontroller acts as such).
Of course, by setting the zero point to a higher voltage, we've reduced our physical detection range. In engineering we make compromises. But realistically, we don't need that sort of range to simulate a whammy bar anyway. To further improve the performance of the detector, we can use some kind of fixture for the two diodes which will improve the directionality of incoming light and also includes a tinted lens filter to reduce the incoming power from wavelengths surrounding the one of interest.
Well that was quite a lengthy discussion for the hand detection circuit, but now we can move on knowing the crux of the project works.

Tuesday, August 5, 2014

Virtual Whammy Bar Part 2

OK, now it's time to start figuring this thing out. The overall goal is to take some sort of hand motion, quantify it, and send an appropriate MIDI message to some digital effect unit.
First we'll need some sort of sensor. We can go ahead and assume it will produce some sort of analog output. Now we need some sort of analog-to-digital converter (ADC) and something to manipulate the result and do all the work. I picked out the PIC16F916 microcontroller for this purpose (because I have them on hand!). This 8-bit device has a built in 10-bit ADC that can sample more than fast enough for our purposes. It also has a built in UART which can be configured for MIDI output. Even better, it has a built in oscillator which will give us a 2MHz effective instruction clock, again plenty quick for this project. Our basic design is pretty simple:

This isn't the definitive design, we'll want to add a few bells and whistles such as buttons and a couple 7 segment displays to control the device operation on the fly. But to start, this will do.

Saturday, August 2, 2014

Virtual Whammy Bar Part 1


Project Abstract
So I already have an effect pedal that can do the trick, what's the problem? Well maybe I want to use my hand to control the whammy function for a more natural feel as opposed to my foot on a pedal. And again in my case, I would also like to keep the expression pedal available for functions like volume and wah. With modern music equipment we do have an option: MIDI. Both my GT-8 and the Digitech Whammy provide MIDI (Musical Instrument Digital Interface) inputs for external control over the effects.
MIDI is a simple serial protocol (think PS/2, I2C, anything using RS-232, etc) that has been around since the early 80's for the real-time communication of musical information. For instance, if you hit a middle C on a MIDI keyboard, it will send a message to a synthesizer to play a note (a "Note On" command), what note (middle C in this case), and how hard you hit the key (referred to as "Velocity"). The synthesizer in turn takes this info and creates audio output based on its current instrument patch, such as piano or strings. Releasing the note on the keyboard then sends a similar command, but with a "Note Off" command instead.

Command ByteData Byte 1Data Byte 2
100100000011110000111111
Note On CommandMidi Channel = 0Note = 0x3C = 60, Middle C on a pianoVelocity = 0x3F = 63, about half volume

Shown above is the actual MIDI message to play a middle C. You can see that the first byte contains a four bit command and a four bit channel assignment. Logically we can see that there are 16 possible commands and 16 possible channels. The channels represent devices in the MIDI chain. An example could be a situation where you have one or more synthesizers each capable of playing several instruments at a time. The first synth might have a guitar, bass, and keyboard assigned to channels 0, 1, and 2. Now you can add a drum machine to the chain which responds to messages on channel 10, and then a reverb unit on channel 12 and so on. Depending on the command, the data bytes will have different meanings. These data values can range from 0x0 to 0x7F (0 to 127 in decimal). I'm not going to thoroughly explain MIDI here, more information can be obtained from MIDI.org.
The goal of this project will be to turn hand motions into MIDI messages that an effect pedal will respond to.

My First Project!

For my first project, I will be sharing my "Virtual Whammy Bar" with you. This is actually a project that I've already done much of the work on, so this is more recap for myself. So I guess I'll begin with a little background:

Background
Many of you may already know what a whammy bar is, but for everyone else, a whammy bar(also called tremolo) is essentially a handle mounted on the bridge of a guitar that allows you to bend the pitch of all the strings simultaneously. It also is capable of bending the notes being played down in pitch, whereas with the typical bending of the strings with your hand can only bend the notes up. There are many different resulting sounds that can be produced from subtle tremolos to a "Dive Bomb". Go and listen to Hendrix or Steve Vai and you will probably hear some whammy bar use. But one thing to be noted is that many, perhaps most, guitars are not equipped with a whammy bar. There are a host of reasons not to build every guitar with one, but I will not go into them here; we'll just leave it at there being many objective and subjective (and believe me, everything guitars is subjective) trade-offs and compromises.
So what if you want take your Gibson Les Paul and achieve the unique sounds of a whammy bar? Well fortunately we have effect pedals. A quick search of www.guitargeek.com shows both Joe Satriani and Johnny Greenwood of Radiohead as having used the Digitech foot pedal in their rigs at some point. I personally own a Boss GT-8 which is a multi-fx board that includes a pitch bending feature that be controlled via an expression pedal. Both of these are controlled using your foot to adjust an expression pedal, which will lead us into the project at hand.

Whammy Bar YouTube Clip

Digitech Whammy YouTube Clip

Unfortunately I couldn't find clips comparing similar uses of the whammy effect, but I would note that the pedal lends itself to more extreme uses. I had a difficult time finding a clip where the performer did not go from full off to full on. Perhaps another impetus for my project......