+ All Categories
Home > Documents > Microcontroller-Based Ring Tone Player

Microcontroller-Based Ring Tone Player

Date post: 01-Dec-2015
Category:
Upload: jim-terence-colaco
View: 288 times
Download: 5 times
Share this document with a friend
Description:
ring tone player
Popular Tags:
5
Transcript
Page 1: Microcontroller-Based Ring Tone Player

3/9/13 Microcontroller-Based Ring Tone Player

www.electronicsforu.com/electronicsforu/circuitarchives/view_article.asp?sno=461&title = Microcontroller-Based+Ring+Tone+Player&id=4684&article_type=2… 1/5

Tech Discussions Circuits Videos Tech Focus Resources Interviews White Papers Application Notes Offers & Ads

Innovators Microcontrollers Test & Measurement Career Trends Raspberry Pi

ELECTRONICS ZONE Engineer's Corner Business Corner Daily News Yellow Pages Jobs eZines & Publications

Login | Register | Advertise | About Us | Contact Us

M I C R O C O N T R O L L E R S

Microcontroller-Based Ring Tone Player

Subhajit Roy

Mobile phone ring tones sound like real audio recordings. It’s not because of the way the melodies are composed, but

the protocol behind playing the melody. The ring tone text transfer language (RTTTL) is behind those wonderful lullabiesand songs you have on your mobile phone.

Basically, a ring tone is the sound made by a mobile phone to indicate an incoming call or text message. Here we present amicrocontroller-based ring tone generator.

The basics

The lowest resonant frequency of a vibrating object is called its fundamental frequency. Most vibrating objects have morethan one resonant frequency and those used in musical instruments typically vibrate at harmonics of the fundamental. Aharmonic is defined as an integer multiple of the fundamental frequency.

Fig.1:Fundamental frequency vibration in an open air column

A cylindrical air column with both ends open vibrates with a fundamental frequency. Each end of the column must be anantinode, with one node at the centre for the air motion. Therefore if ‘λ’ is the wavelength of the sound produced by anopen cylindrical air column, its length ‘L1’ will be:

L1 = λ/2 [(λ/4) + (λ/4 )]

So λ =2L1

Frequency n1 = V/λ (where ‘V’ is the velocity of sound)

By putting the value of ‘λ,’ we get:

n1 = V/2L1

If length is half, then:

Frequency n2 = V/L1

n1/n2 = (V/2L1) × (L1/V) = 1/2

or n1 = 2n2

Page 2: Microcontroller-Based Ring Tone Player

3/9/13 Microcontroller-Based Ring Tone Player

www.electronicsforu.com/electronicsforu/circuitarchives/view_article.asp?sno=461&title = Microcontroller-Based+Ring+Tone+Player&id=4684&article_type=2… 2/5

Fig.2: PWM signal, where Ts1, ts1 and D1 are the time period, half timeperiod and duration of note 1, while Ts2, ts2 and D2 arethe time period, halftime period and duration of note 2

Thus halving the length doubles the frequency, i.e., frequency n1 is created with one octave higher (2n1). If the length ismade quarter of the original, the frequency becomes 4n1, i.e., two octaves higher.

If n1 is octave 1, then n2 is octave 2, then n3 is octave 3, and so on.

If the length is doubled, the frequency is halved. That is, the frequency becomes n1/2, which is one octave lower.

In music, frequency n1 is called a note. The pitch of a piano key or guitar string is described by the note.

According to musical frequency conventions, there are twelve notes in all, namely, A, A#, B, C, C#, D, D#, E, F, F#, Gand G#, where ‘# ‘sign indicates a sharp note.

According to Nokia RTTTL specifications, note A with octave 5 has a frequency of 440 Hz (refer Table I):

A5 = 440 Hz

So we get:A6 = 880 Hz (A5x2)A7 = 1760 Hz (A6x2)

A7 = 1760 Hz (A6x2)

The space between two consecutive octaves like A5 and A6 is divided into eleven equally spaced parts on the logarithmicscale. Thus there are twelve equally spaced notes per octave: A5, A#5, B5, C5, C#5, D5, D#5, E5, F5, F#5, G5, G#5 andthen A6 starts.

RTTTL is a simple text-based format that you can use to create ring tones. An RTTTL file is made up of a single stringdivided into three sections separated by colons (:).

In the example of a Happy Birthday song given below:

d=4, o=5, b=125:16c, 32p, 32c, 32p, 8d, 32p, 8c, 32p, 8f, 32p, e, 16p, 16c, 32p, 32c, 32p, 8d, 32p, 8c, 32p, 8g, 32p, f,8p, 16c, 32p, 32c, 32p, 8c6, 32p, 8a, 32p, 8f, 32p, 8e, 32p, 8d, 32p, 16a#, 32p, 32a#, 32p, 8a, 32p, 8f, 32p, 8g, 32p

1. The first section is the name of the RTTTL melody, i.e., ‘Happy Birthday Song.’

2. The second section defines the default values for the file. There are three categories of default values: duration (d=4),octave (o=5) and beat per minute (b=125).

3. The third section describes the melody.

It is a set of notes separated by a comma. The notes are given in the following format:

Duration (dn) Note Octave

8 c 6

where ‘dn’ is the duration of the present note.

Page 3: Microcontroller-Based Ring Tone Player

3/9/13 Microcontroller-Based Ring Tone Player

www.electronicsforu.com/electronicsforu/circuitarchives/view_article.asp?sno=461&title = Microcontroller-Based+Ring+Tone+Player&id=4684&article_type=2… 3/5

If either the duration (dn) or octave is not specified for a particular note, the default values are assumed.

After getting the notes, you must calculate the duration for which a note is to be played:

Number of notes per second to be played (N) = 60/beats per minute (b) =60/125

So to play music, all you need to do is to get the RTTTL ring tone of the particular music, then read its note and generatethe frequency for the calculated duration (D).

“If the note is dotted; for example, ‘2b’ (here ‘b’ denotes note, not beats per second), the duration is made 1.5 times, sothat D=1.5D.”

Generation of PWM frequency.

Since we are dealing with digital systems, we need to generate PWM (pulse-width-modulated) signals from port pin P2.0 ofthe microcontroller. A PWM signal consists of ‘high’ time period calculation as follows:

1. Timer 0 for calculating the duration (D)

2. Timer 1 for calculating the half time period (ts)

The CPU takes certain number of clock cycles to execute an instruction. The simplest instruction takes a single byte ofcode and executes in one machine cycle. The standard 8051 machine cycle is equal to twelve oscillator cycles. We haveused a 11.0592MHz crystal.

So time period = 1/(11.0592×106) = 0.0904 μs

Time period of a machine cycle = 0.0905×12 = 1.085 μs

Timer 0. Timer 0 is a 16-bit timer that is used for duration ‘D.’ It is loaded with value DC00H. Therefore the number ofmachine cycles taken by the timer before it is reset=FFFF–DC00+1=2400H= 9216 in decimal.

Therefore time taken ‘t’ = 9216×1.085 μs

= 0.001 second

So after timer 0 is set, it will take 0.001 second to reset.

For 1-second duration, the timer needs to be set 1/0.001=100 times.

For duration ‘D,’ timer 0 needs to be set Dx100 times.

Timer 1. The half time period is ‘ts'.

Therefore the number of machine cycles needed = ts/1.085 μs

If the value of the timer is ‘x,’ then FFFF–x+1 = ts/(1.085x10-6)

From this equation, the value of ‘x’ can be calculated.

1’s and 0’s are continuously generated from port pin P2.0 at an interval of ‘ts’ seconds alternatively until duration ‘D’ (inseconds) completes (refer Table II).

Fig.3 shows the circuit diagram of the microcontroller- based ring tone generator

Page 4: Microcontroller-Based Ring Tone Player

3/9/13 Microcontroller-Based Ring Tone Player

www.electronicsforu.com/electronicsforu/circuitarchives/view_article.asp?sno=461&title = Microcontroller-Based+Ring+Tone+Player&id=4684&article_type=2… 4/5

Fig.3: Circuit of microcontroller based ringtone generator

Circuit description

At the heart of the circuit is microcontroller AT89C51. It is a low-power, high-performance, 8-bit microcontroller with 4kBFlash programmable and erasable read-only memory. It has 128 bytes of RAM, 32 input/output (I/O) lines, two 16-bittimers/counters, a five-vector two-level interrupt architecture, on-chip oscillator and clock circuitry.

The 11.0592MHz crystal provides the basic clock frequency to the microcontroller. Port pin P2.0 of the microcontrollerprovides the ringtone melody signal for speaker LS1. Transistor BC337 is used for amplification. The power-‘on’ reset signalfor the microcontroller is generated by the combination of capacitor C3 and resistor R2. Switch S1 provides manual resetto the microcontroller.

The 230V AC mains is stepped down by transformer X1 to deliver the secondary output of 9V, 500 mA. The transformeroutput is rectified by a full-wave bridge rectifier comprising diodes D1 through D4, filtered by capacitor C1 and regulate byIC 7805 (IC2). Capacitor C2 bypasses the ripples present in the regulated power supply. LED1 acts as the power-‘on’indicator and resistor R1 limits the current through LED1.

An actual-size, single-side PCB for the microcontroller-based ring tone generator is shown in Fig.4(View as PDF) and itscomponent layout in Fig.5(View as PDF).

Software

The program plays “happy birthday to you” in RTTTL ring tone format using the microcontroller AT89C51. The sourceprogram, written in Assembly language and assembled using assembler ASM51, is self-explanatory and easy to understand.

Initialise timer 0 and timer 1 as 16-bit timers with predetermined value. When you start timer 0, the data pointer register isloaded with memory address labeled as ‘SONG.’ After playing the current note, the control jumps to the next note and itstarts playing.

This process continues until the end of music data is reached. Thereafter, it starts playing the music from the beginning.

Page 5: Microcontroller-Based Ring Tone Player

3/9/13 Microcontroller-Based Ring Tone Player

www.electronicsforu.com/electronicsforu/circuitarchives/view_article.asp?sno=461&title = Microcontroller-Based+Ring+Tone+Player&id=4684&article_type=2… 5/5

0

5 1 0 Post Comment | 0 Comments

Nokia RTTTL ringtones can be downloaded from the following websites:

1. http://www.2thumbswap.com/members/tones/nokia/tones_nokia_latest.html

2. http://nokiatone.ifrance.com/nokiatone/rtttf.htm

3. http://ringtones.frostzone.com/index.htm

4. http://arcadetones.emuunlim.com/files.htm

RTTL ringtones can also be tested on the computer, the software for which can be downloaded from the link‘http://arcadetones.emuunlim.com/files/nokring_full.zip.’

(Refer “A Cell Phone Player Embedded in Microcontroller” by Manoel Gomes de Andrade for details.)

EFY note. The source code and other relevant files of this article are included in the link below:

www.efymag.com/admin/issuepdf/MICROCONTROLLER BASED RING TONE PLAYER.zip

Related Articles

Part 2 of 3 Using AVR Microcontroller for Projects Posting Date: February 19, 2013 | Views: 349

Part 2 of 3 Using AVR Microcontroller for Projects Posting Date: February 19, 2013 | Views: 349

Microcontroller-Based Clock Using DS1307 Posting Date: September 21, 2012 | Views: 34378

Microcontroller-Based Solar Charger Posting Date: February 10, 2012 | Views: 7848

RFID-based Security System Posting Date: February 08, 2012 | Views: 14796

Magazines

Electronics for YouLINUX for YouFacts for YouElectronics Bazaar

Portals

electronicsforu.comefytimes.combpotimes.comlinuxforu.com

Directories

Electronics AnnualGuide

Events

EFY EXPOEFY AwardsEduTech ExpoOSIWEEK Expo

News Verticals

ElectronicsInfotechLinux & OpenSourceConsumerElectronics

Science &TechnologyBPO

Educational Institute

EFY TechcenterKitsnspares.com

© Copyright 2012 EFY Enterprises Pvt. Ltd. All rights reserved.Reproduction in whole or in part in any form or medium without written permission is prohibited. Usage of the content from the web site is subjectT etor ms and Conditions

ShareShareShareShareMore


Recommended