
    RingPlay -  "A Cell Phone Player embedded in Microcontroller"

   
    Author: Manoel Gomes de Andrade (andrade.manoel@gmail.com)
    Processor: Microcontroller AT89S8252
    Compiler: sdcc
    Parmeters: -V --vc --no-xinit-opt  --use-stdout --model-small  --debug  

    to comiple type: sdcc -V --vc --no-xinit-opt  --use-stdout --model-small  --debug RingPlay.c [Enter]

    Date: 2006-08-11 (yyyy-dd-mm)
    License: Postcardware (see Disclains)



    

    Files enclosed in 
    
    RingPlay.c   (source code and schematic)
    RingPlay.ihx (ready to program on AT89S8252 Intel Hex file)
    RingPlay_Brazilian_flag.jpg  (could you put on OKR ;) 
    RingPaly_readme.txt 





    Description:

    This software interprets "RingTone Text Transfer Language" (RTTTL),
    wich was originally intended to Cell Phones, extracts frequency and 
    a time duration for a particular note and sends it to a speaker correctly
    attached to a pin port.   
    
    Timer 1 (TC1) is responsible for the square wave generation or the note sound.
    The principle is to load TH1,TL1 with a value so that the time to overflow 
    should be half the period of frequencys note and turn on and of the speaker
    at each overflow ocorrency.

                               speaker  on            off            on
                                    

                                        |--------------|             |--------
                                ________|              |_____________|

                                        |  half-period |
                                        
                                        |<--   full period of note -->      

    Timer 0 (TC0) manages the note duration. There is an Interrupt Service Routine
    for it to decrement a variable responsible by the duration and a flag that signal
    time is up (ended). For each iteration, where the square wave is generated, the flag
    is checked to see if it is time to get another note.

     
        


    Comments on RTTTL Specification  
    
  
     Expressing it in words,the RTTTL Specification, says that a music must have a name with a maximum
     of ten characters, followed by a colon. After that it may have an optional field containing default
     values for duration, scale and beats-per-minute. The absence of any default values are automatically
     filled by default values, i.e., preset values and so another colom ends this field.
     After the colom follows a sequency o notes separated by commas. For each note may be particullar
     inforation about its particular duration and scale but if there isnt the default are assumed.
     I must make a special comment about the relationship betweem beats-per-minute and duration found
     in the default field and the time-unit used in the entire music. Beats-per-miunute dictates
     the musics rithm  and must be converted to beats-per-second for more convinience.
  
                      beats-per-second = beats-per-minute / 60  (eq.1)

       Beats-per-second is a measure of frequency at wich notes occurs, so the time or period of notes is:

                       rithm-time = 60/beats-per-minute     (eq.2)

     Suppose "beats-per-minute=60" wich gives  "rithm-time = 1" or one note per second.
     But the  the duration that appears in the default field stablilishes the full time figure.
     For instance, if "def-note-duration" "d=4", when it appears a note without duration or even, redundantly,
     with d=4 it will sounds for a full time. Lets demonstrate it:
 
                      time-fraction = rthin-time * def-note-duration (eq.3)

     So "time-fraction = 4" or in words, duraton=4 is the full time or 1 second.

     From this point on, the interpreter can calculate the currente time for any note based on its particular 
     duration and "dotted" punctuation. 
     
     Below are shown the calculation for all possible durations when "beats-per-minute = 60" (too slow)
     and "def-note-duration = 4"

        duration = time-fraction / 1   =  4/1  =  4.000 s (seconds)                     
        duration = time-fraction / 2   =  4/2  =  2.000 s                     
        duration = time-fraction / 4   =  4/4  =  1.000 s                       
        duration = time-fraction / 8   =  4/8  =  0.500 s                     
        duration = time-fraction / 16  =  4/16 =  0.250 s
        duration = time-fraction / 32  =  4/32 =  0.125 s
                                                  
    
    when a "dotted" found duration is multiplied by 1.5.
   
    Thats all folks !     
    

    If you wants to contacte me:  e-mail: andrade.manoel@gmail.com   (subject: RTTTL)

    



   Hardware

  				I use a the 1/8 of ULN2803 (8 darlingtons with open collectors) to driver 
                to driver the speaker (8 Ohms 1/4 Watt) with an 33o Ohm resistor in series.
                You can 
                         Vcc =  +5V
                           ---
                            |
                             -/| Speaker
                             -\|
                            |
                            /
                            \
                            /  R = 330 Ohms
                            \
                            |
                            O (PIN 11 ULN 2803) 
                            |
                         |  /
                         |/
        AUDIO_OUTPUT O---|\    (1/8 ULN 2803)              O
         (PIN 8 ULN 2803)|  \                              |
                             } 
                             | (emmisor)          (PIN 10 ULN 2803 = Vcc )
                             |
                             O (PIN 9 ULN 2803)
                             |
                           ------ 
                            ---    (GND internally conected)
                             -
   References   
				1. RTTTL Specification: http://www.csoft.co.uk/ringtones/rtttl_rtx.htm (and others see google) 
				2. RTTTL Musics       : http://nokiatone.ifrance.com/nokiatone/        (guess ?)



   Disclains:  
   				1. All trademarks (MS-DOS, TURBO-C, RTTTL, and so on) 
                   belongs to its respective owners;
               
 				2. This is Postcardware, also called just cardware. 
                   The only condition to use this software or its ideas contained in it
                   is that users send the author a postcard to the following address.

                  				  Manoel Gomes de Andrade
                                  	
	                              Avenida Anisio Silva, 1196
	                              Jardim Soares
	                              CEP 14784-346
	                              Barretos - SP
	                              Brazil
                
                3. Sorry about the English

           		4. Be happy.
                
                5. There is a warning message but the object code is succesfully generated
                    " ../SDCC/include/malloc.h(46) : warning 187: ISO C90 does not support flexible array members"



  The End
