![]() |
| Design for: |
| Musical PS/2 Keyboard Gadget | ||
| The Musical PS/2 Keyboard is a demonstration project that shows how one can use tiny microcontrollers to accomplish sophisticated tasks, using very few pins in the process. It is based upon the Microchip PIC10F206 microcontroller, which offers only 6 pins, 512 words program memory and 16 storage locations. The impetus for this project was my six month old granddaughter's insistence to simultaneously type on the computer keyboard that I was using. Since we have loads of spare PS/2 keyboards and all sorts of microprocessor parts at our disposal, it was only natural that we would create a device that interacted musically with the young keyboard user. | ||
| What makes such a project using a microcontroller with only six pins viable is that it is being interfaced to a device that communicates over a single wire (not counting the clock, ground and power lines; we are only focusing on the essence of the problem to be solved). This seems to be a trend of late, relying on single wire communications in order to reduce production costs and simplify the physical connections between devices. In order to be successful at single wire communications, one has to be willing to substitute firmware for hardware, in order to reduce the amount of hardware being delivered. | ||
| The Musical PS/2 Keyboard firmware and schematics are being offered under open source license, so that it could be extended by the user as need be. It is also provided for educational purposes, to show how one can minimally interface to a PS/2 keyboard with a microcontroller, and use a six pin microcontroller to deploy a sophisticated real-time communications protocol. | ||
| If you are interested in having us build you a musical PS/2 keyboard, please let us know. Just send a message to us at sales@artige.com. | ||
| Available on this page: | Specifications | Hardware | Firmware | Downloads |
| Specifications | User Interface | |
| The user will need to provide an IBM compatible keyboard with a PS/2 connector. An AT keyboard could be used, as long as it is equipped with a PS/2 converter. Older IBM compatible keyboards, such as XT, are not supported whatsoever. USB keyboards can only be used if a PS/2 adapter is provided for separately. The Musical PS/2 Keyboard will provide two main functions: | ||
| 1- Rotating LEDs during idle | |||
| While the keyboard is not being used, the Num Lock, Caps Lock and Scroll Lock LEDS will be lighted one at a time for approximately one second each. | |||
| 2- Musical feedback on keypress | |||
| Each key press will result in a musical tone being played for a short time, played once the key is pressed. No tone will be played upon key release. All keys will have a tone played except for the "Pause" key. The default typematic rate will be invoked upon system startup, so maintaining a key press will result in multiple tones being generated. The tone will be dependent upon the scan code of the key pressed, and is in no manner associated with a musical scale. | |||
| Device | ||
| The device for the Musical PS/2 Keyboard project must meet the following criteria: | ||
| 1- Safe for children | ||
| 2- Portable | ||
| 3- Battery operated | ||
| 4- Based upon PIC10F206 microcontroller | ||
| 5- As few electronic components as feasible | ||
| 6- External interface consists of on/off switch, reset switch, PS/2 connector and battery compartment. | ||
| Hardware | Design | |
| The circuit needs to provide power to a PS/2 keyboard and handle its clock and data lines. Two of the microcontroller's I/O pins were dedicated to the keyboard communications. Those lines are bi-directional, and follows the PS/2 protocol when determining who can drive the lines. One I/O pin was allocated to driving a speaker through a capacitor. The last I/O pin was left as the default reset switch input. | ||
| The design includes discrete pull-up resistors for the PS/2 clock and data lines, even though the microcontroller provides weak pull-up resistors on-board. One will want to insure that the PS/2 device is not damaged, especially during power-up, so the discrete resistors are called for. This circuit should have provided protection diodes for the PS/2 device, but voltage drops were a concern for this proof of concept, so they were left off for now. | ||
| Schematic | ||
| A schematic for building a bare-bones Musical PS/2 Keyboard system is presented below: | ||
![]() |
||
| Note that certain details are left off the schematic, such as the power supply. One could run this system from 4 batteries, to generate 6 volts, and step it down using a regulator or even diodes. Main thing to keep in mind is that the PS/2 keyboard is a significant power drain, as it was never designed to operate from a battery. So you will need to use at least "C" batteries, if not "D" batteries. Running the circuit from four "AA" batteries lasts only about five minutes! It also assumes that the microcontroller has been programmed before being inserted into this device, as no provision for programming voltages exist in the schematic. You can also download the schematic from the PDF file listed below. | ||
| Not much to the circuit design. Amazing what you can do with electronic components nowadays! | ||
| Parts List | ||
| Below are listed the parts referenced by the schematic drawing above. These parts are all commodity items readily available from any electronics distributor, except for the microcontroller, which is a Microchip specific part. We got ours from Newark Electronics. You can also download the parts list from the PDF file listed below. | ||
| ID | Description | ||
| U1 | Microchip PIC10F206 microcontroller | ||
| R1 | Resistor, 2.2K Ohm | ||
| R2 | Resistor, 2.2K Ohm | ||
| R3 | Resistor, 10K Ohm | ||
| R4 | Resistor, 1.0K Ohm | ||
| R5 | Resistor, 100 Ohm | ||
| R6 | Resistor, 100 Ohm | ||
| R7 | Resistor, 47 Ohm | ||
| C1 | Capacitor, 0.1 microFarad | ||
| C2 | Capacitor, 100 microFarad, electrolytic | ||
| SP1 | Speaker, 0.5 to 2 Watt, minimally 8 Ohm | ||
| SW1 | Switch, Momentary NO pushbutton | ||
| CN1 | Connector, Female 6 pin mini-DIN | ||
| Note: all resistors are 5% 1/4 Watt | |||
| Open Items | ||
| This version of the Musical PS/2 Keyboard is not ready for use by children. As a proof of concept, it shows that one can interface a PIC10F206 microcontroller to a PS/2 keyboard. The end product still needs a few modifications to make it safer and more interesting. These modifications include: | ||
| 1- Protect the PS/2 interface, so that a child may unplug and plug the PS/2 cable into the device to their heart's content without electrically damaging the keyboard. | ||
| 2- Address power consumption; seems that the PS/2 keyboard consumes 100 mA on its own. | ||
| 3- Use a microcontroller with additional memory, so that a map can be created between the PS/2 scan codes and a musical scale. | ||
| Resources used for the design | ||
| Various documents referencing the PIC10F206 microcontroller were accessed from Microchip's website. Very useful documentation on the PS/2 interface were collected from Adam Chapweske's website. Also, one document from IBM is still available that describes a PS/2 interface. [Note: hyperlinks are to external documents not under Artige Company control]. | ||
| Firmware | Design | |
| Having only 512 words of program memory makes for a difficult task in interfacing with a PS/2 keyboard and still being able to communicate back to the user. Since the PIC10F206 has no interrupt capability, all tasks involve polling for new data from the keyboard, seeing if it is time to toggle the speaker, looking for a timeout on the internal timer. The internal timer was allocated to be the idle timer, to determine when the LEDs should be extinguished and the next one ignited. | ||
| The notes are generated by taking the "make" scan code of the pressed key, stripping of the top half of the byte, then rotating the lower half of the word to the top half. Thie resulting bytecode was used as a timer interval to determine which note was played. If space was available, a proper look up table would have been used to map musical notes to specific keys. Unfortunately, the PS/2 scan codes have no rhyme or reason to them, so an algorithm is impossible to code with the resources available in the microcontroller. The firmware also includes algorithms for generating error beep codes, which are the only way one can communicate debugging info without the use of an analyzer or in-circuit debugger. | ||
| Of course, the firmware is written in assembly language specific to the PIC family of microcontrollers. The program file can be downloaded from the links below, as well as the assembled "hex" file which is the machine code that is copied into the microcontroller memory. | ||
| Downloads | Prerequisites: | |
| 1- MPLAB IDE | ||
| >> Information available from here | ||
| Latest files | ||
| Schematic and parts list | This PDF file contains the schematic drawing and the parts list for a minimal Musical PS/2 Keyboard system. | ||
| Firmware code | This zip file contains assembly language program to run the Musical PS/2 Keyboard, and ready-to-use compiled machine code. |
| Return to open source page | Navigate to home page | ||
| All rights reserved. |
All site content copyright © 1997-2005 Artige Company
|
| Last updated: 9-July-2005 14:53z |