Electronics are hard.

Sometimes, the easy way turns out to be a little bit harder than you thought.

As I will explain as soon as I get to the keyboard layout explanation post, there are some pairs of keys on the keyboard which play the same note. I had initially planned to connect the common pins of each pair of keys and have one connection on the circuit board, but I realized that I had missed something painfully obvious about that approach.

[more inside...]
This is explained in mostly elementary terms in order to be approachable to people who are unfamiliar with electronics concepts.

I previously discussed how SPDT switches can be used as inputs in digital logic circuits, by connecting V+ to one contact and ground to the other. In the case of my keyboard, the buttons would normally be connected to ground, and would connect to V+ when pressed. A problem arises, though, when two buttons are connected to the same input pin and only one is pressed: one of the switches connects the pin to 5 volts, and the other connects it to ground. One might, at first glance, assume that this would result in the input being 'confused' because of conflicting inputs, but the problem becomes more clear upon a second look.

When you trace the path from the 5v connection to the GND connection, there are no components in the way of the flow of electrons. As anyone who has taken a course dealing with electricity is aware, I = V/R where I represents current and V and R represent voltage and resistance, respectively. If there is nothing between 5v and GND in a circuit, the resistance is very small. When the denominator of a fraction is very small (effectively zero), the result is a very large number (approximately infinity). This is a Bad Thing.

To fix this, I need to electrically isolate each output, so that two buttons' outputs are not directly connected to each other. In order to do this, I can use logic gates (which, for those unfamiliar, are discrete versions of the things which do the comparing mentioned in the previous post). There are different types of logic gates that behave differently, so it's important to get the correct type. I have two inputs, and I want the output to be high when any of the inputs go high, so I need to use an OR gate. An OR gate looks at two input signals, and whenever at least one of the inputs is high, the output signal is high as well. Instead of connecting both of the buttons' outputs to the main input pin directly, I connect the output signal from each OR gate; this means that when I push either of a pair of buttons, the corresponding main input pin will go high, but if neither button is pressed, it will stay low.

The alternative approach would have been to use a basic open/close (SPST) switch and a "pull-down" resistor configuration. This configuration connects the main input pin to ground through a resistor, so that when a switch is open, the input pin is at ground potential. The switch is connected directly to the input pin, so when it's closed, the resistor prevents a short and allows the switch to drive the input pin high. If two switches are connected, there is still no problem, because there is no combination of open and closed switches which can result in a short.

No comments:

Post a Comment