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 lullabies and 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 a microcontroller-based ring tone generator.

The basics

Fig.1:Fundamental frequency vibration in an open air column
Fig.1:Fundamental frequency vibration in an open air column
Explore Circuits and Projects Explore Videos and Tutorials

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

A cylindrical air column with both ends open vibrates with a fundamental frequency. Each end of the column must be an antinode, with one node at the centre for the air motion. Therefore if ‘λ’ is the wavelength of the sound produced by an open 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

Fig.2: PWM signal, where Ts1, ts1 and D1 are the time period, half time period and duration of note 1, while Ts2, ts2 and D2 are the time period, halftime period and duration of note 2
Fig.2: PWM signal, where Ts1, ts1 and D1 are the time period, half time period and duration of note 1, while Ts2, ts2 and D2 are the 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 is made 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#, G and G#, where ‘# ‘sign indicates a sharp note.

READ
Distance Counter

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

A39_march-2009-_-table-1

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 logarithmic scale. 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 and then 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 string divided 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.

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 generate the frequency for the calculated duration (D).

READ
Car Porch Guard

“If the note is dotted; for example, ‘2b’ (here ‘b’ denotes note, not beats per second), the duration is made 1.5 times, so that 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 of the 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 of code and executes in one machine cycle. The standard 8051 machine cycle is equal to twelve oscillator cycles. We have used 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 of machine 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.085×10-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’ (in seconds) completes (refer Table II).

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

548_march-2009-_-part-list

Circuit description

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

READ
Door Alert

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

The 230V AC mains is stepped down by transformer X1 to deliver the secondary output of 9V, 500 mA. The transformer output is rectified by a full-wave bridge rectifier comprising diodes D1 through D4, filtered by capacitor C1 and regulate by IC 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 its component layout in Fig.5(View as PDF).

Download PCB and component layout PDFs (Fig. 3, 4): click here

Software

The program plays “happy birthday to you” in RTTTL ring tone format using the microcontroller AT89C51. The source program, 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 is loaded with memory address labeled as ‘SONG.’ After playing the current note, the control jumps to the next note and it starts playing.

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

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: click here

LEAVE A REPLY