News 8051 Projects
- ajay_bhargav
- Fri Nov 05 2010, 12:45 am
On the occasion of Indian festival Diwali, here is another plug and play library for musical tone generation using your 8051 microcontroller. The basic idea behind melody is to produce the correct musical note note.
Theory:
There are seven pitch classes which are represented by first seven letters of Latin alphabets (A, B, C, D, E, F and G). A musical note is represented by Pitch class and octave level, So according to pitch classes there are basic 7 notes and 8th note is represented with as same pitch class as first but double the frequency. The octave is used to differentiate between two notes and is a representation of frequency ratio of two.
Musical notes start from C0, c0#, D0, D0#,.... the lowest note frequency i.e. for C0 is 16.35Hz (based on center frequency A4, 440Hz). Another major component of musical note is duration. There are total 10 durations which are Quarter, Whole, Half, Eighth, Sixteenth, Thirty Two, Sixtyfour, six, twelve and twenty four. These durations vary depending on tempo (beats per minute) of the music/tone.
In music library we focused on notes from C5 to B6 as they coveres almost all variations for simple tone generation and octave level is produce good sound level on hardware (lower frequency means lower sound, higher the frequency higher the sound).
Implementation:
Generating a particular frequency is nothing but a square wave with desired time period. We can use one of the 8051's timer to generate a particular frequency. Lets say if you want to generate C5 note which has a frequency of 523.25Hz, the time period for C5 will be 1911.132µS. The output square wave with 50% duty cycle will have high and low time of 955.566µS (= 1911.132/2).
Lets say your controller running at 12Mhz oscillator will have one Machine cycle of 1µs. To generate 955.566µs we need 956 (~=955.566/1) machine cycles. We can load timer with a value of 64580 (65536-956) and toggle any I/O pin at that interval will give us the reqired frequency. Now this I/o pin can be connected to a speaker to produce sound for that note.
In the library provided we are using Timer2 in auto reload mode for square wave generation. You can use any timer i.e. timer0 or timer1 in 16bit mode for frequency generation. For your convenience I have provided an excel sheet that will generate timer values for a given crystal oscillator frequency.
You can also download the sample tone recorded and tested using this library:
Attachment
The sample program and hex file produces following tones:
1. Adam's Family
2. Looney Toons
3. Flintstones
4. Pink Panther
5. Beethoven Play
6. SaReGaMa (Basic Indian sound 7 tones in forward and reverse order).
Download: Musical Tone Library for 8051 Microcontroller
If you have any doubt regarding this library please make use of forum
Have a musical diwali
Submit comment
Downloads
- Automatic Railway Gate Control by: Sharanjit Singh in: 8051 Projects
Tue Oct 15 2019, 12:47 pm - Yet Another DTMF Controlled Robot by: Er. Sharanjit Singh in: 8051 Projects
Tue May 07 2019, 02:45 pm - Simple 3 Digit Temperature Meter by: Rakesh Suthar in: PIC Projects
Sat Jul 05 2014, 11:45 am - Electronic Voting machine with Managed Control Unit (Project Report Included) by: Shivani, Geetika Gupta, Vibhore Aggarwal, Megha Singh in: 8051 Projects
Sat May 17 2014, 07:46 pm - LED Scrolling message Display using 8051 by: Pratik Suthar in: 8051 Projects
Thu May 08 2014, 04:28 pm
Comments
- Pure Sine Wave Inverter Using Atmel 89S2051 by: Anthonyvab
Wed Apr 17 2024, 08:51 am - Pure Sine Wave Inverter Using Atmel 89S2051 by: Jerrydauck
Fri Mar 01 2024, 08:51 am - Pure Sine Wave Inverter Using Atmel 89S2051 by: DennisVatry
Thu Feb 22 2024, 10:04 pm - Pure Sine Wave Inverter Using Atmel 89S2051 by: DonaldPaids
Thu Feb 22 2024, 03:45 pm - Pure Sine Wave Inverter Using Atmel 89S2051 by: Victornwh
Mon Feb 19 2024, 12:01 pm
MnoioCoove
Tue May 21 2024, 02:06 am
PedroDug
Sun May 19 2024, 05:39 pm
JewelAmuck
Sun May 19 2024, 03:06 pm
Minniemus
Sun May 19 2024, 07:39 am
Andyhet
Sat May 18 2024, 07:28 am
BrettTibre
Fri May 17 2024, 06:14 pm
Gordonfax
Fri May 17 2024, 10:28 am
Davidspils
Fri May 17 2024, 10:19 am
Trending Topics
Switches and Keypads PIC projects keil The 8051 microcontroller ebook computer science ebooks Digital Code Lock dot matrix display logic WINAVR C programming DC motor interfacing ebooks on digital electronics microcontroller projects analog IC J2ME based home automation system middle border spam bots E107 FURL fat32 the 8051 microcontroller mazidi Process Engineering Design Using Visual Basic Programming using assembly language