Advertisement

piano

Not rated 19,836

#digital synthesis #keyboard input #music playback #memory storage #real-time processing #piano #audio processing #waveform generation
piano
piano

Description: Inspired by lab 3 on Digital Waveform Synthesis, a project is being developed to process and playback music. Some songs are pre-stored in memory and can be played back similarly to a piano keyboard. Users can also input songs using a simple keyboard that spans an octave. The playback occurs in real-time. Additionally, the user can request the 8051 microcontroller to transpose the song to different keys or to its parallel minor. This project is significant and beneficial as transposing keys is a fundamental aspect of music theory. The mechanical component of the project is the octave-long keyboard, which is designed using the top of a Tupperware container to facilitate the drilling process. This design inadvertently provides a pleasant tactile response for users.

The keyboard consists of sixteen momentary switches, twelve of which represent the keys in an octave (seven white keys and five black keys), while the remaining four are designated for user selections: "Play" for playback of the user-input song, "Transpose" for changing the key of the stored song, "Minor" for transposing the stored song from major to its parallel minor, and "Done" to indicate the completion of song input. Additionally, two regular on-off switches on the far right allow further selections: the upper switch toggles between "Twinkle, Twinkle, Little Star" and "Mary Had a Little Lamb," while the lower switch selects between stored song playback and user-input song mode.

The electrical connections for the momentary switches are designed similarly to a calculator keypad. The wiring for the sixteen momentary switches is depicted in Figure 2a, while Figure 2b illustrates the wiring for the two regular on-off switches. Each key press results in a specific column and row being shorted, enabling the key decoder to identify the pressed key accurately. This design ensures that all notes from the three utilized octaves can be played. The one-octave keyboard is decoded by a 74C922 key decoder, which connects to the first four pins of Port 1 on R31JP. Upon receiving a key press, the 8051 microcontroller performs the processing tasks, reading data from a sine table and sending a value to a Digital-to-Analog Converter (DAC) at regular intervals.

The analog voltage output from the DAC is then scaled, subtracted, and fed into an LM386 low-voltage audio power amplifier, which drives the speaker. While generating a sine wave corresponding to the user input in real-time, the 8051 also records information about each key press, including the frequency of the note and its duration. The frequency is determined during the real-time key press, while the duration is calculated using timer interrupts. When a note key is pressed, a timer initiates immediately, interrupting every 35.58 ms. Each timer overflow increments a dedicated register, R6, until the key is released, indicated by the clearing of bit P3.5. By counting the overflows, the elapsed time for the note is accurately tracked. A similar method is employed to measure rest times between notes. The note duration, rest times, and note frequencies are stored in memory, allowing the 8051 to "learn" the song. This approach necessitates four timers: one for generating the sine wave, another for displaying prompts on the computer screen, a third for counting until the end of the timer interval, and a fourth for counting down to retrieve the timer interval. Since the 8051 microcontroller has only two onboard timers, an 8254 CHMOS Programmable Interval Timer is utilized to generate a square wave with a frequency of 28.1 Hz. The setup of the 8254 employs two counters for this purpose.With the inspiration from lab 3, Digital Waveform Synthesis, I want to make a project that can process and playback music. Some songs are pre-stored in memory. They can be played back just like a real piano keyboard. Also the user can input a song on a simple keyboard that is an octave long. The song is played in real time. Later, the user can ask the 8051 to transpose the song to different keys, or to its parallel minor. This project is interesting and useful because transposing keys is a big part of music theory study. The octave long keyboard is the mechanical part of this project. The layout of the keyboard can be seen in figure 1. To make the hole drilling process easier, a tupperware container top is used as the base of the keyboard. It turned out to be a plus that it provides a bouncy feeling for the fingers. Sixteen momentary switches are the main components of this octave long keyboard. Twelve out of the sixteen switches are the keys in an octave (seven white keys and five black keys). The other four are for user selections (Play  plays back the song that was input by the user. Transpose  transposes the stored song to another key. Minor  transposes the stored song from major to its parallel minor. Done  should be pressed after the user is done inputting a song. ) There are two regular on-off switches on the far right side for selection purposes as well. (The upper one selects between twinkle, twinkle, little star, and Mary and a little lamb. The bottom one selects between playing the stored songs mode and user inputting songs mode). The electrical connections of the momentary switches are similar to the calculator keypad that is used in class.

Figure 2a shows the wiring of the sixteen momentary switches. Figure 2b shows the wiring of the two regular on-off switches. Figure 2a: The wiring of the sixteen momentary switches. A key hit results a column and a row shorted specifically, and thus the key decoder knows exactly which key is hit. This guarantees that we can play all the notes from the three octaves that we use most. The overall picture of the hardware part is shown in figure 3. The one-octave keyboard is decoded by the key decoder 74C922, which is connected to first four pins of Port 1 on R31JP.

After a key is received on the keyboard, the 8051 does all the brain work. It reads data from a sine table and sends a value to the DAC every period of time. Then the analog voltage value is scaled, and subtracted, and then fed into LM386, which is a low voltage audio power amplifier. The amplified audio signal is fed to the speaker. While the 8051 is making a sine wave corresponding to the user input in real time, it also stores all the information about each key press, aka, the frequency of the key and the duration the note lasts.

The frequency is already determined while the key press is echoed in real time. The duration is calculated using timer interrupt. Once the user hits a note key, a timer is started immediately. The timer is interrupted every 35. 58ms. Every time the timer overflows, a dedicated register, R6, will count up one, until the key is released, which is signaled by clearing of the bit P3. 5. By counting the number of times the timer overflows, we know exactly how much time it has elapsed for the note.

The same strategy is used for counting the rest time between notes. The duration of the note, the rest between notes, along with the frequency of the note, are all stored somewhere in memory. This is how 8051 learns a song. This strategy requires four timers. We need a timer to make sine wave, a timer to print prompt to the computer screen, a timer to count up until the end of the timer interval, and a timer to count down to retrieve the timer interval.

Since 8051 can only provide two timers, I used 8254, a CHMOS Programmable Interval Timer, to generate a square wave with a frequency of 28. 1Hz. (The set up of 8254 is to use two counters

Related Circuits