Internal adaptor PS/2 AT - Spectrum. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
In this document, we introduce an adaptor for the Sinclair ZX Spectrum (Plus version) to let it use a standard AT-class keyboard. The PCB is small enough to fit into the Spectrum Plus cabinet. It can be used instead of the original keyboard as it uses the original keyboard plugs. No ROM modifications required and it's 100% software compatible. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(C)2006-2008 Miguel Angel Rodríguez Jódar. Grupo de Robótica y Tecnología de los Computadores aplicada a la Rehabilitación. Dept. Arquitectura y Tecnología de Computadores. Universidad de Sevilla.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
DECRIPTION AND MAKING-OF After experimenting some time with an alternative to rebuild a rubber-version Spectrum keyboard membrane from scratch, I wanted to do the same with the Plus membrane. The philosophy is the same, but the making was too hard: the Plus membrane has not two, but four circuits and two inner layers to isolate them. This is necesary to be able to simulate the closing of two independent circuits with a single push. The Plus cabinet has enough room, at both sides, to fit small PCB's. Besides, the cabinet can be drilled to expose connectors to the outside. I took some measures and went to one of my department labs to take two microcontroller trainers: one from Microchip and another one from Silicon Labs. At first I were intented to use Micrchip's as the PIC is very popular in Spain. However, after taking a closer look at Silicon Labs specifications, I realize there was no place for comparisons: Silicon Labs medium-low class chips are almost equivalent to high-class PIC's. Low class Silicon Labs microcontrollers start with 12 MHz clock and high class reach 100 MHz.. Besides, the IDE and debugging facilities, with no waste of internal resources on the chip during debug sessions, and above all, the fact that many people in my lab were using the Silicon Labs chip and encouraged me to use it instead of Microchip's, helped me to take my final decision. Microchip's trainer contents . Silicon Labs trainer contents Another thing in favour of Silicon Labs is one leaflet, that you can see in the photo, behind the install CD, were you are guided in a few steps from nothing, to have a complete program up and running in less than five minutes. I learnt the basics of this MCU very quickly. Thus, the proposed interface is based on a model C8051F343 microcontroller from Silicon Labs, although the PCB is compatible with another one, the C8051F320. Both are 8051-core based, with 25 I/O lines, USB slave interface (which we will not use), and support for SPI, UART, timers, etc.. They work at 3.3 V, which makes it very suitable for interfacing with memories SD / MMC, and yet can manage TTL levels. The difference between the two is that the F343 can reach 48 MHz clock frequency, and has 4KB of XRAM, and the F320 reaches 25 MHz with 2KB of XRAM. The firmware written for this microcontroller uses only 256 bytes of XRAM, and a few positions of direct RAM. They have a built-in oscillator, so does not need quartz crystal to work at 25 or 48 MHz. In fact, the final design there's only one active component, the microcontroller, being the rest resistors and capacitors. The Silicon Labs development kit I was using to the date is based on a CAN bus enabled chip, which I don't use. The IDE allows assembler and C. Assuming I would have to deal with precisse timings, I chose assembler, and a home-made devkit based upon the F320. Original development kit ,featuring theF040 (bus CAN), home-made F320 dev kit, and PCB for the keyboard interface, with the F343. C8051F320 devkit and JTAG adapter, for program downloading and debugging. One of the advantages of F320 (and of F343 since both have the same pinout) is still being a 3.3 V device, they don't need a external voltage regulator to get it working. Instead, they can be fed with 5V, converting to 3.3V internally. This is because these micros are designed to be used in USB applications, which gives 5V over the USB wire to feed the device. The devkit used in the initial tests, in fact, is fed from the PC with a USB cable, which only used two pins for supply. First prototype. Note that there are only three lines that are used in the connector back Spectrum: 5V, ground, and the reset signal, we use because the uC has the ability to reset the Spectrum from the keyboard (yes, yes, with Control-Alt - Delete: D) Prior to the F343, and with the false asumption that the F320 would not be fast enough, I considered using the F352, which is somewhat faster than the F343 and with enough XRAM, but has two disadvantages: it only has 17 I/O pins, and it needs an external regulator. I even made a PCB for this uC, but couting with the F343, the whole thing becomes easier (and cheaper).
Silicon Labs C8051F352. F352 and the SIMD 3.3V external regulator. This is the schematic for the F343 version. The amazing thing is that you do not need anything else, just the uC and a few additional components: a small RC cricuit for the reset and the JTAG interface, filter capacitors, and pull-up resistors to the keyboard lines and ZX Spectrum address lines (half-rows). Schematic (clic to zoom) Half-row lines are configured as open collector pins (8 pin header), and data as push-pull pins (5 pin header). SV1 carries the three signals you have to wire on the ZX Spectrum PCB: 5V, ground and reset, the latter optional, only if you want to use the reset keyboard. The half-row lines go directly to the port 2 of 8051, and the column lines go to port 1. Port 0 is left to control signals, in this case, the two signals needed by the keyboard (clock and data) and an output signal directly to the Z80 reset pin. Clock signal go to one interrupt pin. The firmware in the 8051 ties an interrupt service routine, so it's run whenever a falling edge happens on clock line, reading one data bit everytime the interrupt service routine is invoked. The 8051 provides SPI, but the data format is not compatible with that used by the keyboard. As it's time to build the board, it may seem difficult to solder the microcontroller, which is a 32 pin QFP device. Actually it's not that hard, and it only requires a thin solder tip (1 mm). This is how the uC looks like one it is solded to the PCB.
The PCB almost completely populated:
It has two holes so you can screw the PCB to the Spectrum casing. One of them matches a mouting hole present in the Spectrum+ casing, that is not in use. The other one is not really a hole. It fits a screw present in the Spectrum+, near the loudspeaker. Simply raise that screw and use it to prevent the PCB from moving inwards when you push it while you plug-in the PS/2 keyboard. Deail showing one of the mounting screws, power LED, JTAG connector, and the three pins of SV1 connector (from top to bottom: +5V, RESET, GND) Detail showing the screw near the loudspeaker, which has been raised a little to fit the adapter PCB and prevent it to move. Once it's mounted at the right side of the case:
The 8 pin header at the side of the loudspeaker is tilted slightly upwards, so the connector with the 8 wires from the Spectrum doesn't clash with the speaker.
The other end of the column and half-row cables is a piece of strip pin.
So you can "plug" the strip on the correspoding keyboard connector at the Spectrum side.
Using the SV1 pins, we take power and ground to the adapter. At the right side we'll make a hole to reach the PS/2 connector from the outside.
It was easy to make the hole for the PS/2 connector, as the Spectrum+ case has a circle serigraphied at the same distance the hole has to be opened. The hole for the PS/2 connector is wider than the connector itself because some PS/2 jacks have a wider handle. Once it's programmed, the JTAG is of not use. We can freely close the Spectrum case and forget forever about the keyboard. Here you have it, with a wireless keyboard from Labtec.
For the next snapshot, these keys were typed at the wireless keyboard in sequence: 1 2 3 4 5 6 7 8 9 0 Q W E R T Y U I O P A S D F G H J K L Z X C V B N M , . - following the number keys (at the top of the keyboard) with shift pressed: ! " · (giving #) $ % & / ( ) = ? ¿ (giving !). This example comes from a spanish keyboard.
MODO DE OPERACION Al encender el Spectrum con el teclado, el microcontrolador lo resetea y para indicar que todo ha ido bien, deja encendida la luz de Bloq Num. A partir de ese momento, el teclado está listo para ser usado.
PROGRAMA INTERNO DEL MICROCONTROLADOR Esta sección aún no está documentada. La razón fundamental es que quiero pulir un poco más el programa y añadirle algunas funciones que me parecen interesantes. Entre las cosas a pulir, la más importante es soportar el scan mode 2, que es el más habitual. Ahora mismo sólo se soporta el scan mode 3, que es el más fácil de depurar. Entre las cosas menos importantes, hacer más robusta la función de enviar comandos al teclado y un fallejo intermitente cuando se conmuta de modo joystick a modo normal. Entre las cosas a añadir, pues la que tengo ahora en mente es la posibilidad de grabar y reproducir macros de teclado, que el propio programa almacenaría en flash para que no se pierdan cuando el micro se apague. De esa forma, podemos tener comandos directos, tales como LOAD "gens3" CODE 26000: RANDOMIZE USR 26000 en una sola tecla, o incluso pequeños programas escritos en BASIC, que el microcontrolador teclearía por nosotros. De todas formas, para los impacientes, se suministra la versión actual del programa, con las limitaciones expuestas. Hay un detalle técnico que tiene que ver con un comportamiento de la ULA que no conocía, que ha condicionado en buena medida el diseño del firmware. Lo comentaré en breve. LISTA DE MATERIALES Y COSTE ESTIMADO
El C8051F343 sale por $7,79 y se puede pedir directamente desde Mouser Electronics, a través de la página web de Silicon Labs. Los gastos de envío salen por unos $10,70 enviando por USPS, que es lo más barato. Llega a España en unos 5-6 días laborales. Una PCB del tamaño y disposición como la presentada aquí, sale en Futurlec por unos 7€ aproximadamente, dependiendo de si se incluye máscara de soldadura, serigrafía, etc. sale más caro. Si se la hace uno mismo, pues ya el coste estará en función de más factores. El resto de componentes son muy baratos. Quizás entre todos no lleguen ni a 6-7€. En total, el coste en componentes y placa ronda los 20-25€, que viene a ser además el precio que se pide hoy día por una membrana de Spectrum Plus en eBay. Hay cosas como las placas o los microcontroladores, que si se piden en cantidades, sale más barata la unidad al repartirse los gastos de envío. A modo de ejemplo, 4 microcontroladores C8051F343 costaron, gastos de envío incluidos, $41,86. Cada microcontrolador salió por tanto por $10,46, que vienen a ser 8,26€. ARCHIVOS
HISTORICO DE CAMBIOS
OTROS ADAPTADORES DE TECLADO PARA SPECTRUM
ENLACES DE INTERES Los he ido recopilando a medida que me ha hecho falta tal o cual información para desarrollar este proyecto.
AGRADECIMIENTOS A todos mis compañeros del grupo de investigación y en especial a:
A todo es.comp.sistemas.sinclair, ya que esto es esencialmente, para vosotros, para los que mantienen viva la "escene" del Spectrum. CONTACTO Por e-mail a la dirección: rodriguj@atc.us.es poniendo en el asunto "Sobre el adaptador PS/2 para Spectrum" |