Musical Keyboard Using ATMEGA8 This article aims at developing a Monophonic (Single note) musical keyboard by generating the musical notes frequencies using a microcontroller (ATMEGA8). The project presented in this article is a 12 Key, Monophonic keyboard with the options To shift between the Higher and lower octaves Play the programmed tunes Record and save new tune in real-time Frequencies of Musical Notes Taking the Piano as a view point, every key of a Piano has a unique Frequency. The musical notes are named as: The frequencies of these notes on a Piano are provided in the following web page – https://en.wikipedia.org/wiki/Piano_key_frequencies . By knowing the frequency of a particular note from the frequency table, we can play the note using a microcontroller. There are 12 unique key notations as shown in the above image. The frequency of the note depends on the octave of the key pressed. There are 0 to 8 Octaves in a Piano. Generating a Desired Frequency using a Microcontroller By using a microcontroller with digital outputs, it is possible to generate square waves with the frequencies of musical notes. The 16-Bit Timer-counter of the microcontroller is utilized to generate a square wave with desired frequency. The timer counter is operated in CTC Mode (Clear Timer on Compare Match). Each time when a match occurs between the TCNT1 Value and the Output Compare Registers, the Output Compare 1A Pin is toggled. Every time when a key is pressed, the Output Compare Registers of the Timer1 are loaded with a value corresponding to the frequency of the pressed key. The register defined from the description of registers given in the datasheet:- http://www.atmel.com/Images/Atmel-2486-8-bit-AVR-microcontroller-ATmega8_L_datasheet.pdf In our application, the register values in hexadecimal format are given below, TCCR1A=0X40 TCCR1B=0X0B The timer is set to operate at a predefined frequency by selecting the prescaler value. Here, the internal 8 MHz RC oscillator is selected to reduce the external components as well as to have more number of I/O Pins. Now, the Fcpu=8 MHz and by selecting a prescaling value of 8 for the Timer the counting frequency becomes 1 MHz i.e.., it counts 10,00,000 in one second. Let a frequency of 100 Hz is required at the OC1A Pin. The frequency of 100 Hz corresponds to a timer count value of 10,000. As the waveform should be symmetric, the OC1A Pin stays at the High state for the first half of the time period and at Low state for the second half of the time period. As the frequency of 100 Hz corresponds to a timer count value of 10,000, the Compare Match Register is set to 5000. After the timer counter starts counting from zero, the OC1A Pin toggles (for example, OC1A goes Low) when the count value reaches 5000. The Counter value is reset to Zero by the CPU itself with the timer in running state. Again when the count value reaches 5000 the OC1A Pin toggles again (OC1A goes The High this time). Thus a cycle is completed. This continues until Stop timer command is received. As per the circuit operation, when a key is pressed the OCR1A (Output Compare Register) is loaded with a value corresponding to the pressed key frequency and the timer is started. When the key is released, the processor waits until the OC1A Pin goes low and then the timer is stopped. Otherwise, if the timer is stopped with the OCR1A Pin in the High state, the speaker draws current even in the silent state because the coil in the speaker acts as a load. Thus a note... read more
The post DIY: Musical Keyboard Using ATMEGA8 with Tune Record, Save & Playback Options appeared first on Electronic Circuits and Diagram-Electronics Projects and Design.
This post first appeared on Electronic Circuits And Diagram-Electronics Projec, please read the originial post: here