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: 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 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.

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

1 COMMENT

SHARE YOUR THOUGHTS & COMMENTS

Please enter your comment!
Please enter your name here