Buttons and Knobs
Last week, I introduced two inputs on karaoke: the power button and the door-closed switch. Those are simple buttons: one electrical line carries one digital signal.
This week, I’ll show how to put a lot of buttons on a few electrical lines and introduce some non-digital signals.
Karaoke Momentary Push Buttons
The momentary push buttons that control the music playback are standard through-hole parts. Each labeled plastic button corresponds to a button on the outside: repeat, program, skip-, skip+, and play/pause as shown in Figure 3-6.
If you try to measure the voltage across the music playback buttons the results are confusing. One side will read high, the other side will periodically change, switching between high and low (and probably so fast your DMM gives an average or rapidly changing value). And if you press a button, both sides will read a changing value. The reason for this is kind of neat.
To save on processor pins, karaoke cheats and reads two switches with only one input line. See Figure 3-7 for how. Normally the Input will read low (because of the resistor’s connection to ground, more on that soon). The processor will turn OutputA high for a little while. If ButtonA is pressed down, then Input will read high.
A little while later, the processor will turn OutputA low and OutputB high. If ButtonA is still pressed, then Input will still be low. But if ButtonB is pressed, then Input will be high. The processor switches back and forth between the output lines, reading the input each time to determine if a button is pressed.
This may not look amazing now, but we can add more switches. Sure, we have to add more inputs and outputs but fewer than you might expect. And while many processors have general purpose input output (GPIO) pins that can be configured as either inputs or outputs, chips like the karaoke one responsible for this circuit have input-only or output-only pins. Tracing out karaoke’s buttons with beep mode, I figured out the circuit for the music playback buttons (Figure 3-8).
I’m going to use the pin names from the controller chip but note that K1, K2, K3, and K4 are inputs; KS1 and KS2 are outputs.
- Program and Stop are both connected to the K2 input line to the controller on the board.
- Program is connected to the KS2 output from the controller.
- Stop is connected to the KS1 output.
The controller cycles the outputs on and off: KS1 is high for a little while, and then KS2 gets a turn. The button can only be read when its associated output line is low (KS1 or KS2). As long as the two outputs take turns quickly, the user never notices.
The Repeat and Play buttons are also connected together this way. See Table 3-1 to see how each button gets read.
Pressing both buttons at once means that the program won’t be sure about what it should do. For some systems, this is an error. For others, the device will do whichever button is highest priority (or comes first in the state machine that handles button presses, more on that in the next chapter).
Reusing inputs to support multiple buttons like this is called matrixing or key scanning. For karaoke, it provides a way to read six buttons with four inputs and two outputs. Note that the system could read up to eight buttons with only these six pins but the karaoke only has six buttons to read.
The controller chip on this board, the PT6312, is primarily for controlling LED displays. Since many things that have displays also have buttons, the controller also has 6x4 key scanning matrix. It can read up to 24 buttons using those 10 lines, cycling through each of the six output lines. For each output line’s turn, it reads the four input lines. It identifies the button down based on which output is on and which input is read.
Note: When this same matrix system is used to drive an array of LEDs, it is called charlieplexing. The methodology is very similar: LEDs are lit briefly, during their turn. As long as the turns are fast enough that human eyes can’t see the flickering, or don’t notice it very much, designers can use many more LEDs than they have GPIOs.
In Figure 3-8, there are schematic symbols that look like LEDs but they don’t have arrows pointing away from them. These are diodes (remember, LED stands for light emitting diode). A diode makes sure that current only travels in the direction it is pointing and blocks current from flowing backwards.
In the matrix circuit, if the user pressed both Program and Stop, then KS1 would be connected to KS2. Since one is high while the other is low, the signals would fight, leading to inconsistent results and possibly causing damage to the chip, letting out the magic smoke. The diode prevents this.
But wait, doesn’t pressing Stop connect a high KS1 to a K2 which is low? Yeeeesss. Good eye. There is a difference between pins that are driven (like KS1 and KS2) and pins that are pulled up or pulled down by a resistor (marked R108 in Figure 3-8).
Imagine that pullups (and pulldowns) are like weights on spring. When nobody is touching the weight (no voltage applied to the pin), the pullups will gently lift up your weight (connect it to voltage weakly). You can pull them where you need them to go, but when you let go they return to where they started, high or low. Driven pins are more like weights on a stick, they are stiff and go where commanded to go.
You can connect a driven pin to a pullup (or pulldown). And you can connect two pulled signals to each other (though you don’t usually, whichever has the smaller resistor wins). But two driven pins fight each other.
Back to the diodes on the matrix schematic: these prevent the driven pins from interacting because they only allow current to travel in one direction. Returning to my somewhat terrible analogy, the diode acts as a shield so the one driven pin doesn’t get hit by the stick of the other driven pin.
Karaoke Knobs
Karaoke also has knobs to control the volume, the amount of echo, the balance of left and right speakers, and the balance between the CD volume and the microphone volume.
On the board, most of these knobs have three connections as shown in Figure 3-9. I took the batteries out of the toy, set the DMM to beep mode, put one scope probe on the center pin of the echo knob, and one on the other (either, it doesn’t matter). If I turn the dial all the way to one side, the DMM beeps: continuity!
The knob controls what the center pin is connected to. Internally, the knob is sliding a wiper across a resistive surface. When the knob is all the way to one side, the wiper is connected to that side’s pin. (I can move the DMM probes to the other side’s pin, turn the knob all the way the other way and the DMM beeps again.)
Of course, in between the extremes, something else is happening. Up to this point everything I’ve talked about has been has been digital or binary: on or off, high or low, 1 or 0. But there is a lot more to the world than that. In the middle of the knob, the measurement is a partial value, varying between fully on and fully off. Most DMMs can shed more light on this (my $5 one doesn’t have the right mode but the $25 model does).
In Figure 3-10, I used resistance measuring mode (indicated by the Ω symbol on the dial) to measure how the knob’s resistance values changed between the center pin (2) and each of the outer ones (1 and 3). The resistance changes (relatively) linearly as I turn the echo knob.
The knob is a potentiometer, sometimes called a pot or rheostat. It is a variable resistor, so as you turn it, the resistance changes. On the top of Figure 3-9, there is another potentiometer with its selector knob removed (MIC-VOL). You can see the dark area covers 270°: exactly as much as the knob turns. That dark semicircle is the resistive material. Where the wiper contacts the semicircle leads to the resistance we can measure at the pins (and indicates why the pins are symmetric in their readings).
Why does volume have twice as many pins?
If you look closely in Figure 3-6, you may notice that the master volume knob has twice as many contacts as the echo or mic knobs. It is a dual potentiometer, used for stereo output. The two pots are in sync so that the resistance is the same for left and right volume control. That keeps the two speakers at the same volume (see Figure 3-11), at least until you change another knob, the balance knob, to play louder on the left or right speaker. The circuit uses a dual pot so that the right and left side sounds do not get mixed together.
Next week, to finish up chapter 3, I'll look at the quadcopters's really interesting joysticks!
This is a series. If you’d like to read them in order, check out the Taking Apart Toys index.