Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Electronic 'piano' on a PS/2 keyboard

Status
Not open for further replies.

Vermes

Advanced Member level 4
Joined
Aug 2, 2011
Messages
1,163
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,316
Activity points
22,318


It's a very easy circuit based on ATMega microcontroller, capacitors, one speaker, PS/2 keyboard and a PS/2 socket. Some of the keyboard buttons need painting with a marker and some need to be removed in order to achieve the look of a piano.



Above there are pictures of an universal board with Mega32 and USB DIY – USBAsp. The speaker is taken from the computer housing.
Software is the crucial part of the project. It was written in C and compiled under AVR-GCC. Program is divided in two parts: the handling of PS/2 and the main program – the piano.
The PS/2 physical layer is very simple. Besides VCC and GND lines, it uses only DATA and CLK. When a button is pressed/released, the keyboard sends 11 bits (start, 8 bits data, parity and stop). In the same moment it generates a signal on CLK line. The time line is linked with the INT0 input of the microcontroller. The inner interruption is started then.
Data can be received by two ways. It is possible to receive all 11 bits in the moment when the interruption occurs or receive 1 bit after another during each interruption. Second option is better than first one, because there isn't any waste of time between each single bit. When receiving, the waiting time would be as long as all 11 bits are sent to the keyboard. It would be happening during the interruption, what would block other interruptions till the end of reading. It could be non-beneficial in case of other often occurring interruptions.
The big disadvantage of this method is a possibility of the loss of synchronization when on CLK line occurs an unwelcome element like a 'dead' signal, but it can be easily handled by calling the synchronization function from time to time.
After receiving 11th bit, the byte is sent to the queue on the keyboard – a structure with definable buffer dimensions and flags. The buffer makes it possible to separate the main circuit from the keyboard. It only needs to read from the keyboard buffer (if there is something to read). Moreover, this kind of method enables connection of two or more keyboards. It is only required to create an additional structure and modify the functions to operate on indicators instead of a global structure. Still the global structure seems more convenient and gives better performance.
About the piano algorithm. The microcontroller generates simple tones – square waves, by using a combined built hardware timer. When a sound is being generated, the related on the timing frequency is calculated into a suitable value, which is written in the time register. Practically, there are two registers because of the 2-bytes value. Then the output line should be changed by interruption.
The piano has its own keyes queue. The pressed keys are remembered and based on that, the tones are changed. Unfortunately, having only one channel, to gain a sound diversity, a small trick has to be made. The same solution as in old DOS games should be applied. In the moment when two keys are pressed, the frequency is switched from one tone to another (20-50ms). That gives at least the feeling like playing two tones at the same time. The two tone mode can be switched on/off by using the proper keys.
Another option is to record maximally four samples 65 tones long, when all tones/breaks are shorter than 4 sec. During the recording, events are saved in memory (pressing/releasing the N button) and the space from the previous event in resolution of about 16ms (1/64) – it takes 2B. Pressing and then releasing one button means one tone. 65*2*2B*4 samples makes 1040B of memory needed for the samples. They can be performed while playing the second line.

Link to original thread - "Pianino" z klawiatury komputerowej PS/2
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top