Often, radio amateurs are faced with the problem of creating a remote device control panel. If the number of buttons on it is large, then to reduce the number of wires in the connecting cable, the console is equipped with an encoder for the commands of the pressed buttons, and the device with a decoder. In this situation, the old joystick can help out, from the once popular game consoles «Dendy». The task of the radio amateur is greatly simplified, since the joystick has a good design and is equipped with a ready-made encoder for the keystroke commands.
What's inside the joystick?
The approximate scheme of the encoder used in the joysticks "Dendy" is shown in Fig.6 , at the end of the article. Information about the interface between the joystick and game console, a variant of the joystick circuit, as well as variants of the decoder circuits can be found on the pages of the magazine "Radio". [l] Information about the pressed buttons of the joystick is transmitted in a sequential format using the clock signal "Clock" from the controlled device. To synchronize with it, the joystick has an “Latch” input, which is supplied with a short pulse with a high logic level at the beginning of each cycle of receiving data from the joystick.
The device decoder and his work
The proposed device, electrical circuit diagram of which is shown in Fig.1 , is a decoder that converts joystick signals into discrete logic levels corresponding to the buttons pressed. It is based on the 74HC595N (DD3) chip, which is an 8-bit shift register with serial input and serial and parallel information output. Parallel information output is carried out through a buffer register with outputs that have three states. The information signal is fed to the SER input (pin 14), the write signal to the SCK input (pin 11), and the output signal (“snap”) to the RSK input (pin 12). This register receives a byte, which carries information about the pressed buttons, sequentially, and outputs the outputs Q0 - Q7 in parallel form. Thus, the state of each individual output, the output register of the microcircuit, will correspond to the button associated with it on the joystick. The correspondence between the register pins and the joystick buttons is shown in the table below . ')
On the DD2 microcircuit, the “Latch” clock shaper is assembled, necessary for fixing the state of the buttons on the joystick and outputting the high bit of data from the joystick to the “Data” output. This happens on the positive edge of the pulse. On the negative front of this pulse, the data byte reading cycle begins. This moment is designated as the “joystick survey cycle” (see Fig. 2 ). The next bits in order will be output on the “Data” output with the appearance of a positive clock edge, at the input of the “Clock” joystick. Also, the “Latch” clock pulse is fed to the RSK input of the shift register, this is necessary to “snap” the received byte in the output register and output it to the outputs Q0 - Q7 in parallel form. The “latching” of the received byte occurs along the positive edge of the pulse. This point in time is designated as the “information update cycle at the 74S595 register output” (see Fig. 2 ). With the arrival of each clock pulse, the information at the output of the register will be updated. On the chip DD1 assembled clock generator. The frequency of which is 100 kilohertz. Clock pulses are fed to the “Clock” input of the joystick and to the SCK input of the receiving register 74H595. Data on the state of the joystick buttons is output to the “Data” output in order, starting with the high-order bit - D7, D6 ... D0. This happens on the positive edge of the clock pulse at the input “Clock” of the joystick. The bits read from the “Data” output are fed to the input of the SER register 74HS595. Writing the received bit to the register also occurs on the positive front of the pulses of this generator.
- dude!You have the moment of updating the bit of information at the “Data” output combined with the moment of reading the set bit at the “Data” output! - yes ... that's for sure.But the joystick is rather “braking”, and the bit update, after the arrival of a positive clock edge, occurs 120 nC later.While the joystick is thinking, the smart 74HS595 manages to record the previous value of the “Data” output, for 20 nC. - uh, "Kulibin"!For the duration of the “Latch” impulse, garbage is written in your output register 74HS595 - two bits of D7 in a row! - Yes, I confess - quick work.But after the end of the cycle of recording the entire byte, the extra bits will "fall out" from the register to nowhere, and will not affect the accuracy of the received information.
SPI interface
And one more thing ... Many, looking at the picture ( Fig. 2 ), saw the similarity with the timing of the SPI communication interface. Yes, yes, yes ... with some differences, this is it! It is necessary to replace the names of the signals: “Latch” on CS or SS, the signal “Clock” on CSLK or CLK, the signal “Data” on MISO, SDO or SO (as you like more). The joystick can be polled using the SPI module integrated in the MC. To do this, you need to send bytes to the device, no matter what, for example FF.
True, if someone this byte can be useful, you can download the necessary information.For example, for the register with LEDs.Or do not download, and send the received information from the joystick to someone else.That is, pin MOSI can be used .
The received byte will contain information about the pressed buttons. The pressed button will correspond to a bit equal to zero, and not to a pressed unit. If no button is pressed on the joystick, then the FF byte will be received, if it manages to hold all the buttons at once, the received byte will contain 00. The SPI interface must be configured to work in Master mode, well, that is so clear ... while the synchronization mode is set to CPOL = 1, CPHA = 0 (Mode 2). In this situation, the data from the “Data” output (MISO for MK) will be read by the microcontroller by the negative differential of the CSLK clock signal, fed to the “Clock” input of the joystick. And the update of the information bit at the “Data” output of the joystick and at the MISO input of the microcontroller will occur on the positive front of the clock pulse. In the same way, the joystick can be connected to the Arduino board.
"Turbo A" and "Turbo B"
Early models of joysticks contained 8 buttons, later ten. Added two buttons "Turbo A" and "Turbo B". But on the data exchange protocol, it did not affect in any way - it remained the same. The added turbo buttons are equivalent to buttons "A" and "B" with the only difference that when you press the "Turbo A" button, the button "A" will be pressed, only at a speed of 12 and a half times a second. This is true for the buttons "Turbo B" and "B". The generator of the turbo keystrokes was added to the joystick itself (see Fig . 6 , highlighted in red). When you press the turbo button on the outputs Q6 and Q7 of the register DD3 there will be pulses with a period of 80 mS and a duty cycle of two.
There are joysticks with even more buttons, as well as smaller ones. Pressing additional buttons on such joysticks is equivalent to pressing two buttons on older models at once. When connecting to the decoder control LEDs, to understand the operation of the buttons "super joysticks" will not be difficult. (I think it was the joysticks from the Sega Mega Drive)
UPD: About SNES.
In the comments to the article it was fairly noted:
In the text we are talking about the generator of turbo clicks, and to it comes a picture with joysticks, where there is no such generator.Below it says “Pressing additional buttons on such joysticks is equivalent to pressing two buttons on old models at once,” but this is also unfair to SNES.
There is no generator of turbo taps in the SNES joysticks. That is, you will not see any pulses at the output of the decoder when you connect such a joystick. Moreover, the SNES protocol is not radically, but differs from the NES protocol. The difference is that it is 16 bit. Informative bits only - D15 - D4, bits D3 - D0 are always equal to one. When connecting such a joystick to the proposed decoder, you will receive information about the buttons: “B”, “Y”, “Select”, “Start”, “Up”, “Down”, “Left” and “Right”. Information about the buttons: “A”, “X”, “L” and “R” will be lost. The SNES connector is shown in fig.3 extreme right.
UPD: The benefit that gives us "Turbo"
Probably someone, reading about the pulses at the output of the decoder when you press the buttons "Turbo A" and "Turbo B" upset:
- Uh ... so the button "Turbo" can not be used, as a shame, two buttons are lost. - Not!They are not lost at all.
Let's imagine that when you control any device, you need to increment any parameter in the direction of increasing or decreasing it. If this requires a high resolution of the setting value, then you can be tired of squeezing the buttons "plus" and "minus", let it be buttons "A" and "B". This is where the turbo buttons come in handy. When using the joystick in conjunction with the microcontroller, you will be spared from writing an extra piece of software code, because you will no longer need to squeeze the advanced interface functionality into two buttons. He has already expanded to four, and is equipped with the logic of work.
Interface SNES, NES
In conjunction with the proposed decoder, you can use any joystick that has an SNES, NES or “Virtual Boy” interface. And also their numerous clones - “Dendy”, “Sega” and others. The differences are in the design and the connector connecting the joystick to the game console. The pin assignment of the connectors I know is shown in fig.3
Connecting devices to the decoder
The signals at the decoder output correspond to TTL levels. Pressed on the remote button corresponds to - high level, low - not pressed. If the device connected to the decoder is matched by TTL levels, then no additional measures need to be agreed.
If the output of the decoder requires inverse signal states (the button is pressed - zero, the button is not pressed - one), then the element DD1.4 ( Fig. 1 ) must be excluded from the scheme. In cases where devices connected to the decoder cannot be controlled by logic levels or electrical isolation is required for power, a relay or optocoupler should be used .4 a, b . If for control, something needs control signals of a static type (the button is pressed, the pair is turned on, pressed again, turned off), the device must be supplemented with a trigger. Applying a single chip K155TM2 (see Fig. 4 c ), the "Start" and "Select" buttons can be turned into switches. Perhaps there will be a bounce effect of contacts (if the suppression is not implemented in the joystick itself). In this case, it is necessary to reduce the frequency of the clock generator, for example, to 100 hertz. In this case, the joystick will be polled 10 times per second, and the bounce problem will be solved.
Device design
Most of the parts are mounted on a printed circuit board of one-sided foiled fiberglass 1… 1.5 mm thick, a drawing of a printed circuit board is shown in Fig.5 LEDs can be installed only at the configuration stage, for clarity. The device uses a resistor C2-23, MLT, a film capacitor C4 - C10-17, a ceramic capacitor C3 - KM-6, oxide capacitors C1, C2 - C50-35 or imported analogues of the types of parts listed. The XR1 connector is borrowed in a faulty DVD player. In the absence of the original connector, the device must be equipped with any other, suitable in design and overall dimensions. Feed the device from a power source of 12 V and a current of 50 mA. UPD: If someone comes in handy, then according to the "NATO" classification: DD2 - SN7493, DD1 - SN7400, it will be 155 series. Or SN74LSxx it will be 555 series, but in general put everything that you find, the main thing is to have the numbers 93, 00 and 74.