Monday, October 13, 2014

Virtual Whammy Bar Part 5

At this point it might be easiest just to show you the full schematic and break it down.
And there we have it, nothing too crazy. And yes, I'm not showing bypass caps and such (well honestly, I still need to add them to the real thing, but I know they should be there). So let's get into the remaining parts.

The MIDI interface looks like a standard serial connection, but it's not quite. MIDI uses a current loop so our output has a send and return path for the signal (contacts 4 & 5). On the input side of whatever device we are controlling will be an optoisolator providing... well... isolation. If you visit MIDI.org Elec Spec you will see the complete electrical interface. You may wonder why I didn't use the two inverters they show on the spec and here is why: that circuit is dated 1985. I'm guessing that at the time there was concern about how much current an I/O pin could sink. Dunno, I was maybe two feet tall at the time. But given the resistors in the current loop as 220Ω each and a forward voltage drop across the optoisolator of about 1.3V we would have 5.6mA. For a short across contacts 4 & 5 there is still only 11.4mA. According to the PIC16F916 datasheet, any pin can sink up to 25mA so long as all the I/O combined do not sink a current in excess of 90mA. I think we're safe.

On the right hand side we have two buttons with a simple RC filter for debouncing. The filter the cutoff frequency just wants to be as low as possible while still being faster than the rate that the buttons are sampled. This should allow for quick transitions while smoothing out any noise. There are only two buttons because that is all I had at the time.


The ICSP header allows for programming and debugging the chip in circuit via a Microchip programming tool such as an ICD3 or PICkit3. Not much to say here, if you're interested just google it or head to Microchip's website.

Lastly we have the two 7 segment LED displays. Again, I only had two on hand, but that was enough. I used the entirety of Port B of the PIC16 as a single byte output to keep things simple. I didn't pay much attention to how they were wired to the microcontroller, so long as they were wired the same. Either way, I'd have to make a conversion table in software to display numbers or characters, so my table is just.... unique. Also, I switch between which display is being illuminated by means of the "Digit" signal. When "Digit" is high, the ONES display is active, and when "Digit" is low, it becomes the TENS display. All I do is switch back and forth between them around 100 times per second and they both appear constantly on. This is easily done by alternating every time I check the buttons or check the position sensor. You may notice that "Digit" only drives Q2, and that the base of Q1 is tied to Q2's collector. How does the TENS display work then?
If you look at the simplified circuit shown and make a few approximations this can be easily understood. We'll assume that SIGNAL is 5V, Q2 is off(ie, "Digit" is low), the voltage drop across each diode is the same, and that the current gain of Q1 is 100. Since no current flows into Q2, we can formulate the following equations (again based on approximations):

Vb = Vc
Va = 5-(Ir * R) = V(D2) + Vb = V(D1) + Vc
Ir = Ic + Ib
Ic = 100*Ib

Let's just consider the current formulas. Since Ic is 100 times larger than Ib (and that is the minimum spec'd gain of a 2n3904), very little current is diverted from illuminating the TENS segment to drive Q1. So if Ic is 1mA, Ib is only 10uA, which also explains why the ONES segment doesn't appear to illuminate. Kinda neat. Didn't even need to consider the rest of the equations. This was initially a breadboard mistake that I had to evaluate after the fact to determine why it worked. Of course the real operation varies slightly from the approximation. The voltage drop over D2 will likely be smaller than D1 since it won't be driven into saturation, subsequently making Vb larger than Vc. What does this change? Not enough to care about.

So that completes the hardware portion of things. Software is up next.